@@ -29,6 +29,8 @@ pub enum Network {
29
29
#[ cfg( not( feature = "liquid" ) ) ]
30
30
Testnet ,
31
31
#[ cfg( not( feature = "liquid" ) ) ]
32
+ Testnet4 ,
33
+ #[ cfg( not( feature = "liquid" ) ) ]
32
34
Regtest ,
33
35
#[ cfg( not( feature = "liquid" ) ) ]
34
36
Signet ,
@@ -97,6 +99,7 @@ impl Network {
97
99
return vec ! [
98
100
"mainnet" . to_string( ) ,
99
101
"testnet" . to_string( ) ,
102
+ "testnet4" . to_string( ) ,
100
103
"regtest" . to_string( ) ,
101
104
"signet" . to_string( ) ,
102
105
] ;
@@ -110,6 +113,27 @@ impl Network {
110
113
}
111
114
}
112
115
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
+
113
137
pub fn genesis_hash ( network : Network ) -> BlockHash {
114
138
#[ cfg( not( feature = "liquid" ) ) ]
115
139
return bitcoin_genesis_hash ( network. into ( ) ) ;
@@ -121,8 +145,12 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
121
145
lazy_static ! {
122
146
static ref BITCOIN_GENESIS : bitcoin:: BlockHash =
123
147
genesis_block( BNetwork :: Bitcoin ) . block_hash( ) ;
148
+ // TESTNET_GENESIS is BlockHash of testnet3
124
149
static ref TESTNET_GENESIS : bitcoin:: BlockHash =
125
150
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( ) ;
126
154
static ref REGTEST_GENESIS : bitcoin:: BlockHash =
127
155
genesis_block( BNetwork :: Regtest ) . block_hash( ) ;
128
156
static ref SIGNET_GENESIS : bitcoin:: BlockHash =
@@ -131,6 +159,7 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
131
159
match network {
132
160
BNetwork :: Bitcoin => * BITCOIN_GENESIS ,
133
161
BNetwork :: Testnet => * TESTNET_GENESIS ,
162
+ BNetwork :: Testnet4 => * TESTNET4_GENESIS ,
134
163
BNetwork :: Regtest => * REGTEST_GENESIS ,
135
164
BNetwork :: Signet => * SIGNET_GENESIS ,
136
165
_ => panic ! ( "unknown network {:?}" , network) ,
@@ -165,6 +194,8 @@ impl From<&str> for Network {
165
194
#[ cfg( not( feature = "liquid" ) ) ]
166
195
"testnet" => Network :: Testnet ,
167
196
#[ cfg( not( feature = "liquid" ) ) ]
197
+ "testnet4" => Network :: Testnet4 ,
198
+ #[ cfg( not( feature = "liquid" ) ) ]
168
199
"regtest" => Network :: Regtest ,
169
200
#[ cfg( not( feature = "liquid" ) ) ]
170
201
"signet" => Network :: Signet ,
@@ -187,6 +218,7 @@ impl From<Network> for BNetwork {
187
218
match network {
188
219
Network :: Bitcoin => BNetwork :: Bitcoin ,
189
220
Network :: Testnet => BNetwork :: Testnet ,
221
+ Network :: Testnet4 => BNetwork :: Testnet4 ,
190
222
Network :: Regtest => BNetwork :: Regtest ,
191
223
Network :: Signet => BNetwork :: Signet ,
192
224
}
@@ -199,9 +231,23 @@ impl From<BNetwork> for Network {
199
231
match network {
200
232
BNetwork :: Bitcoin => Network :: Bitcoin ,
201
233
BNetwork :: Testnet => Network :: Testnet ,
234
+ BNetwork :: Testnet4 => Network :: Testnet4 ,
202
235
BNetwork :: Regtest => Network :: Regtest ,
203
236
BNetwork :: Signet => Network :: Signet ,
204
237
_ => panic ! ( "unknown network {:?}" , network) ,
205
238
}
206
239
}
207
240
}
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