From 1354692e64e74d5c667c62303a85c51f3fdb0ba7 Mon Sep 17 00:00:00 2001 From: Bob McElrath Date: Thu, 28 Aug 2025 12:51:48 -0400 Subject: [PATCH] Use CPUNet-modified bech32 library --- bitcoin/Cargo.toml | 2 +- bitcoin/src/address/mod.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index 834e88cda8..e366603685 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -26,7 +26,7 @@ arbitrary = ["dep:arbitrary", "units/arbitrary", "primitives/arbitrary"] [dependencies] base58 = { package = "base58ck", path = "../base58", default-features = false, features = ["alloc"] } -bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] } +bech32 = { git = "https://github.com/braidpool/rust-bech32.git", branch = "cpunet", default-features = false, features = ["alloc"] } hashes = { package = "bitcoin_hashes", path = "../hashes", default-features = false, features = ["alloc", "hex"] } hex = { package = "hex-conservative", version = "0.3.0", default-features = false, features = ["alloc"] } internals = { package = "bitcoin-internals", path = "../internals", features = ["alloc", "hex"] } diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 5594a53a9b..189e8fad31 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -236,6 +236,8 @@ pub enum KnownHrp { Testnets, /// The regtest network. Regtest, + /// The CPUNet test network. + CPUNet } impl KnownHrp { @@ -245,8 +247,9 @@ impl KnownHrp { match network { Bitcoin => Self::Mainnet, - Testnet(_) | Signet | CPUNet => Self::Testnets, + Testnet(_) | Signet => Self::Testnets, Regtest => Self::Regtest, + CPUNet => Self::CPUNet } } @@ -258,6 +261,8 @@ impl KnownHrp { Ok(Self::Testnets) } else if hrp == bech32::hrp::BCRT { Ok(Self::Regtest) + } else if hrp == bech32::hrp::TC { + Ok(Self::CPUNet) } else { Err(UnknownHrpError(hrp.to_lowercase())) } @@ -269,6 +274,7 @@ impl KnownHrp { Self::Mainnet => bech32::hrp::BC, Self::Testnets => bech32::hrp::TB, Self::Regtest => bech32::hrp::BCRT, + Self::CPUNet => bech32::hrp::TC } } } @@ -283,6 +289,7 @@ impl From for NetworkKind { KnownHrp::Mainnet => NetworkKind::Main, KnownHrp::Testnets => NetworkKind::Test, KnownHrp::Regtest => NetworkKind::Test, + KnownHrp::CPUNet => NetworkKind::Test, } } } @@ -990,7 +997,7 @@ impl FromStr for Address { type Err = ParseError; fn from_str(s: &str) -> Result { - if ["bc1", "bcrt1", "tb1"].iter().any(|&prefix| s.to_lowercase().starts_with(prefix)) { + if ["bc1", "bcrt1", "tb1", "tc1"].iter().any(|&prefix| s.to_lowercase().starts_with(prefix)) { let address = Address::from_bech32_str(s)?; // We know that `U` is only ever `NetworkUnchecked` but the compiler does not. Ok(Address::from_inner(address.into_inner()))