Skip to content

Commit b13f57c

Browse files
committed
transaction: use better error typing for pegin destructuring
We should redo the error types here as well at some point.
1 parent 787486d commit b13f57c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/transaction.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::collections::HashMap;
2020
use std::convert::TryFrom;
2121

2222
use bitcoin::{self, VarInt};
23+
use internals::slice::SliceExt;
2324
use crate::hashes::Hash;
2425

2526
use crate::{confidential, ContractHash};
@@ -432,12 +433,12 @@ impl<'tx> PeginData<'tx> {
432433
pegin_witness: &'tx [Vec<u8>],
433434
prevout: bitcoin::OutPoint,
434435
) -> Result<PeginData<'tx>, &'static str> {
435-
if pegin_witness.len() != 6 {
436+
let Ok(pegin_witness) = <&[Vec<u8>; 6]>::try_from(pegin_witness) else {
436437
return Err("size not 6");
437-
}
438-
if pegin_witness[5].len() < 80 {
438+
};
439+
let Some((block_header, _)) = SliceExt::split_first_chunk::<80>(pegin_witness[5].as_slice()) else {
439440
return Err("merkle proof too short");
440-
}
441+
};
441442

442443
Ok(PeginData {
443444
outpoint: prevout,
@@ -448,7 +449,7 @@ impl<'tx> PeginData<'tx> {
448449
claim_script: &pegin_witness[3],
449450
tx: &pegin_witness[4],
450451
merkle_proof: &pegin_witness[5],
451-
referenced_block: bitcoin::BlockHash::hash(&pegin_witness[5][0..80]),
452+
referenced_block: bitcoin::BlockHash::hash(block_header),
452453
})
453454
}
454455

0 commit comments

Comments
 (0)