Skip to content

Commit 2fd677b

Browse files
committed
refactor: using new BitcoinAddress::from_string supporting regtest hrp, #6250
1 parent db9e9b9 commit 2fd677b

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

stacks-node/src/burnchains/rpc/bitcoin_rpc_client/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ where
180180
D: Deserializer<'de>,
181181
{
182182
let addr_str: String = Deserialize::deserialize(deserializer)?;
183-
if addr_str.starts_with("bcrt") {
184-
//Currently BitcoinAddress doesn't manage Regtest HRP
185-
return Err(serde::de::Error::custom(
186-
"BitcoinAddress cannot manage Regtest HRP ('bcrt')",
187-
));
188-
}
189-
190183
if let Some(addr) = BitcoinAddress::from_string(&addr_str) {
191184
Ok(addr)
192185
} else {

stacks-node/src/burnchains/rpc/bitcoin_rpc_client/test_utils.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ impl<'de> Deserialize<'de> for GetNewAddressResponse {
123123
D: Deserializer<'de>,
124124
{
125125
let addr_str: String = Deserialize::deserialize(deserializer)?;
126-
if addr_str.starts_with("bcrt") {
127-
//Currently BitcoinAddress doesn't manage Regtest HRP
128-
return Err(serde::de::Error::custom(
129-
"BitcoinAddress cannot manage Regtest HRP ('bcrt')",
130-
));
131-
}
132-
133126
if let Some(addr) = BitcoinAddress::from_string(&addr_str) {
134127
Ok(GetNewAddressResponse(addr))
135128
} else {

stacks-node/src/tests/bitcoin_rpc_integrations.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,16 @@ fn test_get_new_address_for_each_address_type() {
259259
let client = BitcoinRpcClient::from_stx_config(&config).expect("Client creation ok!");
260260
client.create_wallet("my_wallet", Some(false)).expect("OK");
261261

262-
//Check Legacy type OK
263-
let legacy = client
262+
// Check Legacy p2pkh type OK
263+
let p2pkh = client
264264
.get_new_address(None, Some(AddressType::Legacy))
265-
.expect("legacy address ok!");
265+
.expect("p2pkh address ok!");
266266
assert_eq!(
267267
LegacyBitcoinAddressType::PublicKeyHash,
268-
legacy.expect_legacy().addrtype
268+
p2pkh.expect_legacy().addrtype
269269
);
270270

271-
//Check Legacy p2sh type OK
271+
// Check Legacy p2sh type OK
272272
let p2sh = client
273273
.get_new_address(None, Some(AddressType::P2shSegwit))
274274
.expect("p2sh address ok!");
@@ -277,20 +277,23 @@ fn test_get_new_address_for_each_address_type() {
277277
p2sh.expect_legacy().addrtype
278278
);
279279

280-
//Bech32 currently failing due to BitcoinAddress not supporting Regtest HRP
281-
client
280+
// Check Bech32 p2wpkh OK
281+
let p2wpkh = client
282282
.get_new_address(None, Some(AddressType::Bech32))
283-
.expect_err("bech32 should fail!");
283+
.expect("p2wpkh address ok!");
284+
assert!(p2wpkh.expect_segwit().is_p2wpkh());
284285

285-
//Bech32m currently failing due to BitcoinAddress not supporting Regtest HRP
286-
client
286+
// Check Bech32m p2tr OK
287+
let p2tr = client
287288
.get_new_address(None, Some(AddressType::Bech32m))
288-
.expect_err("bech32m should fail!");
289+
.expect("p2tr address ok!");
290+
assert!(p2tr.expect_segwit().is_p2tr());
289291

290-
//None defaults to bech32 so fails as well
291-
client
292+
// Check default to be bech32 p2wpkh
293+
let default = client
292294
.get_new_address(None, None)
293-
.expect_err("default (bech32) should fail!");
295+
.expect("default address ok!");
296+
assert!(default.expect_segwit().is_p2wpkh());
294297
}
295298

296299
#[ignore]

0 commit comments

Comments
 (0)