Skip to content

Commit eb30d28

Browse files
committed
support native segwit regtest addresses (#148)
1 parent c0b7d57 commit eb30d28

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

buidl/script.py

+7
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,13 @@ def address_to_script_pubkey(s):
620620
elif len(s) == 62:
621621
# p2wskh
622622
return P2WSHScriptPubKey(decode_bech32(s)[2])
623+
elif s[:6] == "bcrt1q":
624+
if len(s) == 44:
625+
# p2wpkh
626+
return P2WPKHScriptPubKey(decode_bech32(s)[2])
627+
elif len(s) == 64:
628+
# p2wsh
629+
return P2WSHScriptPubKey(decode_bech32(s)[2])
623630
elif s[:4] in ("bc1p", "tb1p"):
624631
if len(s) != 62:
625632
raise RuntimeError(f"unknown type of address: {s}")

buidl/test/test_script.py

+10
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ def test_addr_to_script_pubkey(self):
225225
"tb1qlrjv2ek09g9aplga83j9mfvelnt6qymen9gd49kpezdz2g5pgwnsfmrucp",
226226
"testnet",
227227
),
228+
(
229+
P2WSHScriptPubKey,
230+
"bcrt1qy0jn7qnt6tkmqq0yfhf00vr8yv4vf4y2232ppycaz29z7wjr23zq5m3kls",
231+
"regtest",
232+
),
233+
(
234+
P2WPKHScriptPubKey,
235+
"bcrt1qp58z6zvu64v8ntd3hpjl6eag40fjel0zkdfajs",
236+
"regtest",
237+
),
228238
(
229239
P2WSHScriptPubKey,
230240
"bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej",

0 commit comments

Comments
 (0)