@@ -14,8 +14,8 @@ pub use {
1414 } ,
1515} ;
1616
17- use bitcoin:: blockdata:: constants:: genesis_block;
1817pub use bitcoin:: network:: Network as BNetwork ;
18+ use bitcoin:: { blockdata:: constants:: genesis_block, TestnetVersion as BTestnetVersion } ;
1919
2020#[ cfg( not( feature = "liquid" ) ) ]
2121pub type Value = u64 ;
@@ -27,7 +27,7 @@ pub enum Network {
2727 #[ cfg( not( feature = "liquid" ) ) ]
2828 Bitcoin ,
2929 #[ cfg( not( feature = "liquid" ) ) ]
30- Testnet ,
30+ Testnet ( TestnetVersion ) ,
3131 #[ cfg( not( feature = "liquid" ) ) ]
3232 Regtest ,
3333 #[ cfg( not( feature = "liquid" ) ) ]
@@ -41,6 +41,15 @@ pub enum Network {
4141 LiquidRegtest ,
4242}
4343
44+ #[ derive( Debug , Copy , Clone , PartialEq , Hash , Serialize , Ord , PartialOrd , Eq ) ]
45+ pub enum TestnetVersion {
46+ /// Testnet version 3.
47+ V3 ,
48+ /// Testnet version 4.
49+ /// This is the latest testnet version.
50+ V4 ,
51+ }
52+
4453impl Network {
4554 #[ cfg( not( feature = "liquid" ) ) ]
4655 pub fn magic ( self ) -> u32 {
@@ -97,6 +106,7 @@ impl Network {
97106 return vec ! [
98107 "mainnet" . to_string( ) ,
99108 "testnet" . to_string( ) ,
109+ "testnet4" . to_string( ) ,
100110 "regtest" . to_string( ) ,
101111 "signet" . to_string( ) ,
102112 ] ;
@@ -121,16 +131,21 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
121131 lazy_static ! {
122132 static ref BITCOIN_GENESIS : bitcoin:: BlockHash =
123133 genesis_block( BNetwork :: Bitcoin ) . block_hash( ) ;
134+ // TESTNET_GENESIS is BlockHash of testnet3
124135 static ref TESTNET_GENESIS : bitcoin:: BlockHash =
125- genesis_block( BNetwork :: Testnet ) . block_hash( ) ;
136+ genesis_block( BNetwork :: Testnet ( BTestnetVersion :: V3 ) ) . block_hash( ) ;
137+ // TESTNET4_GENESIS is BlockHash of testnet4
138+ static ref TESTNET4_GENESIS : bitcoin:: BlockHash =
139+ genesis_block( BNetwork :: Testnet ( BTestnetVersion :: V4 ) ) . block_hash( ) ;
126140 static ref REGTEST_GENESIS : bitcoin:: BlockHash =
127141 genesis_block( BNetwork :: Regtest ) . block_hash( ) ;
128142 static ref SIGNET_GENESIS : bitcoin:: BlockHash =
129143 genesis_block( BNetwork :: Signet ) . block_hash( ) ;
130144 }
131145 match network {
132146 BNetwork :: Bitcoin => * BITCOIN_GENESIS ,
133- BNetwork :: Testnet => * TESTNET_GENESIS ,
147+ BNetwork :: Testnet ( BTestnetVersion :: V3 ) => * TESTNET_GENESIS ,
148+ BNetwork :: Testnet ( BTestnetVersion :: V4 ) => * TESTNET4_GENESIS ,
134149 BNetwork :: Regtest => * REGTEST_GENESIS ,
135150 BNetwork :: Signet => * SIGNET_GENESIS ,
136151 _ => panic ! ( "unknown network {:?}" , network) ,
@@ -163,7 +178,9 @@ impl From<&str> for Network {
163178 #[ cfg( not( feature = "liquid" ) ) ]
164179 "mainnet" => Network :: Bitcoin ,
165180 #[ cfg( not( feature = "liquid" ) ) ]
166- "testnet" => Network :: Testnet ,
181+ "testnet" => Network :: Testnet ( TestnetVersion :: V3 ) ,
182+ #[ cfg( not( feature = "liquid" ) ) ]
183+ "testnet4" => Network :: Testnet ( TestnetVersion :: V4 ) ,
167184 #[ cfg( not( feature = "liquid" ) ) ]
168185 "regtest" => Network :: Regtest ,
169186 #[ cfg( not( feature = "liquid" ) ) ]
@@ -186,7 +203,8 @@ impl From<Network> for BNetwork {
186203 fn from ( network : Network ) -> Self {
187204 match network {
188205 Network :: Bitcoin => BNetwork :: Bitcoin ,
189- Network :: Testnet => BNetwork :: Testnet ,
206+ Network :: Testnet ( TestnetVersion :: V3 ) => BNetwork :: Testnet ( BTestnetVersion :: V3 ) ,
207+ Network :: Testnet ( TestnetVersion :: V4 ) => BNetwork :: Testnet ( BTestnetVersion :: V4 ) ,
190208 Network :: Regtest => BNetwork :: Regtest ,
191209 Network :: Signet => BNetwork :: Signet ,
192210 }
@@ -198,10 +216,24 @@ impl From<BNetwork> for Network {
198216 fn from ( network : BNetwork ) -> Self {
199217 match network {
200218 BNetwork :: Bitcoin => Network :: Bitcoin ,
201- BNetwork :: Testnet => Network :: Testnet ,
219+ BNetwork :: Testnet ( BTestnetVersion :: V3 ) => Network :: Testnet ( TestnetVersion :: V3 ) ,
220+ BNetwork :: Testnet ( BTestnetVersion :: V4 ) => Network :: Testnet ( TestnetVersion :: V4 ) ,
202221 BNetwork :: Regtest => Network :: Regtest ,
203222 BNetwork :: Signet => Network :: Signet ,
204223 _ => panic ! ( "unknown network {:?}" , network) ,
205224 }
206225 }
207226}
227+
228+ #[ cfg( not( feature = "liquid" ) ) ]
229+ impl From < Network > for & ' static bitcoin:: params:: Params {
230+ fn from ( network : Network ) -> Self {
231+ match network {
232+ Network :: Bitcoin => & bitcoin:: params:: MAINNET ,
233+ Network :: Testnet ( TestnetVersion :: V3 ) => & bitcoin:: params:: TESTNET ,
234+ Network :: Testnet ( TestnetVersion :: V4 ) => & bitcoin:: params:: TESTNET4 ,
235+ Network :: Regtest => & bitcoin:: params:: REGTEST ,
236+ Network :: Signet => & bitcoin:: params:: SIGNET ,
237+ }
238+ }
239+ }
0 commit comments