@@ -20,6 +20,7 @@ use std::collections::HashMap;
2020use std:: convert:: TryFrom ;
2121
2222use bitcoin:: { self , VarInt } ;
23+ use internals:: slice:: SliceExt ;
2324use crate :: hashes:: Hash ;
2425
2526use 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