From eb30d28965cfaf091a18c8804480122862a39a34 Mon Sep 17 00:00:00 2001 From: Chad Date: Wed, 28 Aug 2024 21:21:21 -0500 Subject: [PATCH] support native segwit regtest addresses (#148) --- buidl/script.py | 7 +++++++ buidl/test/test_script.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/buidl/script.py b/buidl/script.py index 0952b1e..e86d9fe 100644 --- a/buidl/script.py +++ b/buidl/script.py @@ -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}") diff --git a/buidl/test/test_script.py b/buidl/test/test_script.py index c0c8de4..3e5c34a 100644 --- a/buidl/test/test_script.py +++ b/buidl/test/test_script.py @@ -225,6 +225,16 @@ def test_addr_to_script_pubkey(self): "tb1qlrjv2ek09g9aplga83j9mfvelnt6qymen9gd49kpezdz2g5pgwnsfmrucp", "testnet", ), + ( + P2WSHScriptPubKey, + "bcrt1qy0jn7qnt6tkmqq0yfhf00vr8yv4vf4y2232ppycaz29z7wjr23zq5m3kls", + "regtest", + ), + ( + P2WPKHScriptPubKey, + "bcrt1qp58z6zvu64v8ntd3hpjl6eag40fjel0zkdfajs", + "regtest", + ), ( P2WSHScriptPubKey, "bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej",