Skip to content

Commit 25a891d

Browse files
committed
feat: testnet4 is supported with the latest rust-bitcoin
1 parent e11cd56 commit 25a891d

File tree

15 files changed

+290
-57
lines changed

15 files changed

+290
-57
lines changed

Cargo.lock

Lines changed: 107 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ arraydeque = "0.5.1"
2020
arrayref = "0.3.6"
2121
base64 = "0.22"
2222
bincode = "1.3.1"
23-
bitcoin = { version = "0.31", features = [ "serde" ] }
23+
bitcoin = { version = "0.32.0-rc1", features = [ "serde" ] }
24+
bitcoin-io = "0.1.2"
2425
clap = "2.33.3"
2526
crossbeam-channel = "0.5.0"
2627
dirs = "5.0.1"
2728
elements = { version = "0.24", features = [ "serde" ], optional = true }
2829
error-chain = "0.12.4"
2930
glob = "0.3"
30-
hex = { package = "hex-conservative", version = "0.1.1" }
31+
hex = { package = "hex-conservative", version = "0.2.1" }
3132
itertools = "0.12"
3233
lazy_static = "1.3.0"
3334
libc = "0.2.81"
@@ -77,3 +78,19 @@ rev = "d3792352992a539afffbe11501d1aff9fd5b919d" # add-peer branch
7778
[patch.crates-io.electrumd]
7879
git = "https://github.com/shesek/electrumd"
7980
rev = "996fe2a8e563bc1bde6bbc2e0c2a2f4421abcdbc"
81+
82+
[patch.crates-io.bitcoin]
83+
git = "https://github.com/rust-bitcoin/rust-bitcoin.git"
84+
rev = "refs/pull/2945/head"
85+
86+
[patch.crates-io.bitcoin-units]
87+
git = "https://github.com/rust-bitcoin/rust-bitcoin.git"
88+
rev = "refs/pull/2945/head"
89+
90+
[patch.crates-io.bitcoin_hashes]
91+
git = "https://github.com/rust-bitcoin/rust-bitcoin.git"
92+
rev = "refs/pull/2945/head"
93+
94+
[patch.crates-io.bitcoin-internals]
95+
git = "https://github.com/rust-bitcoin/rust-bitcoin.git"
96+
rev = "refs/pull/2945/head"

src/bin/tx-fingerprint-stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
}
6262

6363
let tx: Transaction = deserialize(&value).expect("failed to parse Transaction");
64-
let txid = tx.txid();
64+
let txid = tx.compute_txid();
6565

6666
iter.next();
6767

src/chain.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub use {
1414
},
1515
};
1616

17-
use bitcoin::blockdata::constants::genesis_block;
1817
pub use bitcoin::network::Network as BNetwork;
18+
use bitcoin::{blockdata::constants::genesis_block, TestnetVersion as BTestnetVersion};
1919

2020
#[cfg(not(feature = "liquid"))]
2121
pub 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+
4453
impl 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

Comments
 (0)