Skip to content

Commit 1354692

Browse files
committed
Use CPUNet-modified bech32 library
1 parent 7d32028 commit 1354692

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

bitcoin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ arbitrary = ["dep:arbitrary", "units/arbitrary", "primitives/arbitrary"]
2626

2727
[dependencies]
2828
base58 = { package = "base58ck", path = "../base58", default-features = false, features = ["alloc"] }
29-
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
29+
bech32 = { git = "https://github.com/braidpool/rust-bech32.git", branch = "cpunet", default-features = false, features = ["alloc"] }
3030
hashes = { package = "bitcoin_hashes", path = "../hashes", default-features = false, features = ["alloc", "hex"] }
3131
hex = { package = "hex-conservative", version = "0.3.0", default-features = false, features = ["alloc"] }
3232
internals = { package = "bitcoin-internals", path = "../internals", features = ["alloc", "hex"] }

bitcoin/src/address/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ pub enum KnownHrp {
236236
Testnets,
237237
/// The regtest network.
238238
Regtest,
239+
/// The CPUNet test network.
240+
CPUNet
239241
}
240242

241243
impl KnownHrp {
@@ -245,8 +247,9 @@ impl KnownHrp {
245247

246248
match network {
247249
Bitcoin => Self::Mainnet,
248-
Testnet(_) | Signet | CPUNet => Self::Testnets,
250+
Testnet(_) | Signet => Self::Testnets,
249251
Regtest => Self::Regtest,
252+
CPUNet => Self::CPUNet
250253
}
251254
}
252255

@@ -258,6 +261,8 @@ impl KnownHrp {
258261
Ok(Self::Testnets)
259262
} else if hrp == bech32::hrp::BCRT {
260263
Ok(Self::Regtest)
264+
} else if hrp == bech32::hrp::TC {
265+
Ok(Self::CPUNet)
261266
} else {
262267
Err(UnknownHrpError(hrp.to_lowercase()))
263268
}
@@ -269,6 +274,7 @@ impl KnownHrp {
269274
Self::Mainnet => bech32::hrp::BC,
270275
Self::Testnets => bech32::hrp::TB,
271276
Self::Regtest => bech32::hrp::BCRT,
277+
Self::CPUNet => bech32::hrp::TC
272278
}
273279
}
274280
}
@@ -283,6 +289,7 @@ impl From<KnownHrp> for NetworkKind {
283289
KnownHrp::Mainnet => NetworkKind::Main,
284290
KnownHrp::Testnets => NetworkKind::Test,
285291
KnownHrp::Regtest => NetworkKind::Test,
292+
KnownHrp::CPUNet => NetworkKind::Test,
286293
}
287294
}
288295
}
@@ -990,7 +997,7 @@ impl<U: NetworkValidationUnchecked> FromStr for Address<U> {
990997
type Err = ParseError;
991998

992999
fn from_str(s: &str) -> Result<Self, ParseError> {
993-
if ["bc1", "bcrt1", "tb1"].iter().any(|&prefix| s.to_lowercase().starts_with(prefix)) {
1000+
if ["bc1", "bcrt1", "tb1", "tc1"].iter().any(|&prefix| s.to_lowercase().starts_with(prefix)) {
9941001
let address = Address::from_bech32_str(s)?;
9951002
// We know that `U` is only ever `NetworkUnchecked` but the compiler does not.
9961003
Ok(Address::from_inner(address.into_inner()))

0 commit comments

Comments
 (0)