Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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