Skip to content

Commit

Permalink
support native segwit regtest addresses (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadchapnick committed Oct 29, 2024
1 parent c0b7d57 commit eb30d28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions buidl/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ def address_to_script_pubkey(s):
elif len(s) == 62:
# p2wskh
return P2WSHScriptPubKey(decode_bech32(s)[2])
elif s[:6] == "bcrt1q":
if len(s) == 44:
# p2wpkh
return P2WPKHScriptPubKey(decode_bech32(s)[2])
elif len(s) == 64:
# p2wsh
return P2WSHScriptPubKey(decode_bech32(s)[2])
elif s[:4] in ("bc1p", "tb1p"):
if len(s) != 62:
raise RuntimeError(f"unknown type of address: {s}")
Expand Down
10 changes: 10 additions & 0 deletions buidl/test/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def test_addr_to_script_pubkey(self):
"tb1qlrjv2ek09g9aplga83j9mfvelnt6qymen9gd49kpezdz2g5pgwnsfmrucp",
"testnet",
),
(
P2WSHScriptPubKey,
"bcrt1qy0jn7qnt6tkmqq0yfhf00vr8yv4vf4y2232ppycaz29z7wjr23zq5m3kls",
"regtest",
),
(
P2WPKHScriptPubKey,
"bcrt1qp58z6zvu64v8ntd3hpjl6eag40fjel0zkdfajs",
"regtest",
),
(
P2WSHScriptPubKey,
"bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej",
Expand Down

0 comments on commit eb30d28

Please sign in to comment.