@@ -19,7 +19,6 @@ use secp256k1_zkp::Tweak;
1919use crate :: hashes:: { sha256, sha256d, Hash , HashEngine } ;
2020use crate :: opcodes:: all:: OP_RETURN ;
2121use crate :: opcodes:: OP_TRUE ;
22- use crate :: pset:: serialize:: Serialize ;
2322use crate :: { confidential, script, AssetId , Block , BlockExtData , BlockHash , BlockHeader , LockTime , Script , Sequence , Transaction , TxIn , TxInWitness , TxOut , TxOutWitness } ;
2423use crate :: { AssetIssuance , ContractHash , OutPoint , Txid } ;
2524use crate :: confidential:: Nonce ;
@@ -89,12 +88,18 @@ impl NetworkParams {
8988}
9089
9190/// Hash commitment of network parameters for a given Network
92- pub fn commit_to_custom_network_parameters ( params : & NetworkParams ) -> Vec < u8 > {
91+ pub fn commit_to_custom_network_parameters ( params : & NetworkParams ) -> sha256:: Hash {
92+ use hex:: { BytesToHexIter , Case } ;
93+
9394 let mut eng = sha256:: Hash :: engine ( ) ;
9495 eng. input ( params. network_id . clone ( ) . as_bytes ( ) ) ;
95- eng. input ( format ! ( "{:x}" , params. fedpeg_script) . as_bytes ( ) ) ;
96- eng. input ( format ! ( "{:x}" , params. sign_block_script) . as_bytes ( ) ) ;
97- sha256:: Hash :: from_engine ( eng) . serialize ( )
96+ for ch in BytesToHexIter :: new ( params. fedpeg_script [ ..] . iter ( ) , Case :: Lower ) . flatten ( ) {
97+ eng. input ( & [ ch. into ( ) ] ) ;
98+ }
99+ for ch in BytesToHexIter :: new ( params. sign_block_script [ ..] . iter ( ) , Case :: Lower ) . flatten ( ) {
100+ eng. input ( & [ ch. into ( ) ] ) ;
101+ }
102+ sha256:: Hash :: from_engine ( eng)
98103}
99104
100105/// Produce the genesis transaction for a given elements Network
@@ -105,7 +110,7 @@ fn liquid_genesis_tx(network_params: &NetworkParams) -> Transaction {
105110 previous_output : OutPoint :: default ( ) ,
106111 is_pegin : false ,
107112 script_sig : script:: Builder :: new ( )
108- . push_slice ( commit. as_slice ( ) )
113+ . push_slice ( commit. as_byte_array ( ) )
109114 . into_script ( ) ,
110115 sequence : Sequence :: default ( ) ,
111116 asset_issuance : AssetIssuance :: default ( ) ,
@@ -135,7 +140,7 @@ fn liquid_genesis_asset_tx(network_params: &NetworkParams) -> Option<Transaction
135140 if asset_amount == 0 {
136141 return None ;
137142 }
138- let asset_outpoint = OutPoint :: new ( Txid :: from_slice ( commit. as_slice ( ) ) . expect ( "txid" ) , 0 ) ;
143+ let asset_outpoint = OutPoint :: new ( Txid :: from_byte_array ( commit. to_byte_array ( ) ) , 0 ) ;
139144 let contract_hash = ContractHash :: from_byte_array ( [ 0u8 ; 32 ] ) ;
140145 let asset_entropy = AssetId :: generate_asset_entropy ( asset_outpoint, contract_hash) ;
141146 let asset_id = AssetId :: from_entropy ( asset_entropy) ;
@@ -183,8 +188,8 @@ pub fn genesis_block(params: &NetworkParams) -> Block {
183188 let merkle_root: sha256d:: Hash =
184189 if let Some ( asset_tx) = liquid_genesis_asset_tx ( params) {
185190 txdata. push ( asset_tx. clone ( ) ) ;
186- let tx_hashes = vec ! [ tx. txid( ) . to_raw_hash( ) , asset_tx. txid( ) . to_raw_hash( ) ] ;
187- bitcoin:: merkle_tree:: calculate_root ( tx_hashes. into_iter ( ) )
191+ let tx_hashes = [ tx. txid ( ) . to_raw_hash ( ) , asset_tx. txid ( ) . to_raw_hash ( ) ] ;
192+ bitcoin:: merkle_tree:: calculate_root ( tx_hashes. iter ( ) . copied ( ) )
188193 . expect ( "merkle root" )
189194 } else {
190195 tx. txid ( ) . to_raw_hash ( )
0 commit comments