Exposed a hash-based API for accessing blocks

Also corrects a few panics, which shouldn't have been present, and unnecessary
Cursor uses.
This commit is contained in:
Luke Parker
2023-01-07 04:00:12 -05:00
parent 814a9a8d35
commit 1d6df0099c
4 changed files with 45 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
use core::ops::BitXor;
use std::io::{self, Read, Write, Cursor};
use std::io::{self, Read, Write};
use zeroize::Zeroize;
@@ -127,7 +127,7 @@ impl Extra {
pub(crate) fn payment_id(&self) -> Option<PaymentId> {
for field in &self.0 {
if let ExtraField::Nonce(data) = field {
return PaymentId::deserialize(&mut Cursor::new(data)).ok();
return PaymentId::deserialize::<&[u8]>(&mut data.as_ref()).ok();
}
}
None

View File

@@ -1,5 +1,3 @@
use std::io::Cursor;
use zeroize::{Zeroize, ZeroizeOnDrop};
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwards::EdwardsPoint};
@@ -232,7 +230,7 @@ impl<O: Clone + Zeroize> Timelocked<O> {
impl Scanner {
/// Scan a transaction to discover the received outputs.
pub fn scan_transaction(&mut self, tx: &Transaction) -> Timelocked<ReceivedOutput> {
let extra = Extra::deserialize(&mut Cursor::new(&tx.prefix.extra));
let extra = Extra::deserialize::<&[u8]>(&mut tx.prefix.extra.as_ref());
let keys;
let extra = if let Ok(extra) = extra {
keys = extra.keys();