@@ -29,6 +29,8 @@ pub enum Network {
2929 #[ cfg( not( feature = "liquid" ) ) ]
3030 Testnet ,
3131 #[ cfg( not( feature = "liquid" ) ) ]
32+ Testnet4 ,
33+ #[ cfg( not( feature = "liquid" ) ) ]
3234 Regtest ,
3335 #[ cfg( not( feature = "liquid" ) ) ]
3436 Signet ,
@@ -97,6 +99,7 @@ impl Network {
9799 return vec ! [
98100 "mainnet" . to_string( ) ,
99101 "testnet" . to_string( ) ,
102+ "testnet4" . to_string( ) ,
100103 "regtest" . to_string( ) ,
101104 "signet" . to_string( ) ,
102105 ] ;
@@ -110,6 +113,27 @@ impl Network {
110113 }
111114}
112115
116+ /// Because `rust-bitcoin` uses the `txid` function will cause a warning,
117+ /// Need to use `compute_txid` instead,
118+ /// So abstract a trait to handle the access of `txid`
119+ pub trait TxOperations {
120+ fn txid ( & self ) -> Txid ;
121+ }
122+
123+ #[ cfg( not( feature = "liquid" ) ) ]
124+ impl TxOperations for Transaction {
125+ fn txid ( & self ) -> Txid {
126+ self . compute_txid ( )
127+ }
128+ }
129+
130+ #[ cfg( feature = "liquid" ) ]
131+ impl TxOperations for Transaction {
132+ fn txid ( & self ) -> Txid {
133+ Transaction :: txid ( self )
134+ }
135+ }
136+
113137pub fn genesis_hash ( network : Network ) -> BlockHash {
114138 #[ cfg( not( feature = "liquid" ) ) ]
115139 return bitcoin_genesis_hash ( network. into ( ) ) ;
@@ -121,8 +145,12 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
121145 lazy_static ! {
122146 static ref BITCOIN_GENESIS : bitcoin:: BlockHash =
123147 genesis_block( BNetwork :: Bitcoin ) . block_hash( ) ;
148+ // TESTNET_GENESIS is BlockHash of testnet3
124149 static ref TESTNET_GENESIS : bitcoin:: BlockHash =
125150 genesis_block( BNetwork :: Testnet ) . block_hash( ) ;
151+ // TESTNET4_GENESIS is BlockHash of testnet4
152+ static ref TESTNET4_GENESIS : bitcoin:: BlockHash =
153+ genesis_block( BNetwork :: Testnet4 ) . block_hash( ) ;
126154 static ref REGTEST_GENESIS : bitcoin:: BlockHash =
127155 genesis_block( BNetwork :: Regtest ) . block_hash( ) ;
128156 static ref SIGNET_GENESIS : bitcoin:: BlockHash =
@@ -131,6 +159,7 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
131159 match network {
132160 BNetwork :: Bitcoin => * BITCOIN_GENESIS ,
133161 BNetwork :: Testnet => * TESTNET_GENESIS ,
162+ BNetwork :: Testnet4 => * TESTNET4_GENESIS ,
134163 BNetwork :: Regtest => * REGTEST_GENESIS ,
135164 BNetwork :: Signet => * SIGNET_GENESIS ,
136165 _ => panic ! ( "unknown network {:?}" , network) ,
@@ -165,6 +194,8 @@ impl From<&str> for Network {
165194 #[ cfg( not( feature = "liquid" ) ) ]
166195 "testnet" => Network :: Testnet ,
167196 #[ cfg( not( feature = "liquid" ) ) ]
197+ "testnet4" => Network :: Testnet4 ,
198+ #[ cfg( not( feature = "liquid" ) ) ]
168199 "regtest" => Network :: Regtest ,
169200 #[ cfg( not( feature = "liquid" ) ) ]
170201 "signet" => Network :: Signet ,
@@ -187,6 +218,7 @@ impl From<Network> for BNetwork {
187218 match network {
188219 Network :: Bitcoin => BNetwork :: Bitcoin ,
189220 Network :: Testnet => BNetwork :: Testnet ,
221+ Network :: Testnet4 => BNetwork :: Testnet4 ,
190222 Network :: Regtest => BNetwork :: Regtest ,
191223 Network :: Signet => BNetwork :: Signet ,
192224 }
@@ -199,9 +231,23 @@ impl From<BNetwork> for Network {
199231 match network {
200232 BNetwork :: Bitcoin => Network :: Bitcoin ,
201233 BNetwork :: Testnet => Network :: Testnet ,
234+ BNetwork :: Testnet4 => Network :: Testnet4 ,
202235 BNetwork :: Regtest => Network :: Regtest ,
203236 BNetwork :: Signet => Network :: Signet ,
204237 _ => panic ! ( "unknown network {:?}" , network) ,
205238 }
206239 }
207240}
241+
242+ #[ cfg( not( feature = "liquid" ) ) ]
243+ impl From < Network > for & ' static bitcoin:: params:: Params {
244+ fn from ( network : Network ) -> Self {
245+ match network {
246+ Network :: Bitcoin => & bitcoin:: params:: MAINNET ,
247+ Network :: Testnet => & bitcoin:: params:: TESTNET3 ,
248+ Network :: Testnet4 => & bitcoin:: params:: TESTNET4 ,
249+ Network :: Regtest => & bitcoin:: params:: REGTEST ,
250+ Network :: Signet => & bitcoin:: params:: SIGNET ,
251+ }
252+ }
253+ }
0 commit comments