Add regtest address support to address_to_script_pubkey#166
Merged
Conversation
- Handle bcrt1q (P2WPKH len 44, P2WSH len 64) and bcrt1p (P2TR len 64) prefixes in address_to_script_pubkey() - TxFetcher.get_url() now raises a clear ValueError for regtest instead of an unhelpful KeyError - Add tests for regtest P2WPKH, P2WSH, and P2TR address roundtrips - Add test for TxFetcher regtest error message Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
address_to_script_pubkey()now handles regtest bech32 addresses (bcrt1qfor P2WPKH/P2WSH,bcrt1pfor P2TR)TxFetcher.get_url()raises a clearValueErrorfor regtest instead of an unhelpfulKeyErrorNetwork parameter audit
Every function/method that takes
networkas a parameter was reviewed. Here is the full analysis:Dict lookup (regtest key exists in dict)
bech32.py:172encode_bech32_checksum()PREFIX.get(network)PREFIXhas"regtest": "bcrt"network.py:43GenericMessage.__init__()network.py:52GenericMessage.parse()MAGIC[network]MAGIChas regtestnetwork.py:306SimpleNode.__init__()PORT[network]PORThas regtesthd.py:141HDPrivateKey.from_seed()XPRV[network]XPRVhas regtesttx.py:53TxFetcher.get_url()URL[network]ValueErrortx.py:62TxFetcher.fetch()get_url(network)get_urltx.py:97TxFetcher.sendrawtransaction()get_url(network)get_urlPassthrough (stores or forwards
network, no branching)cecc.py:368PrivateKey.__init__()self.networkpecc.py:538PrivateKey.__init__()self.networkcecc.py:215S256Point.address()p2pkh_script().address(network)cecc.py:219S256Point.p2wpkh_address()p2wpkh_script().address(network)cecc.py:223S256Point.p2sh_p2wpkh_address()p2wpkh_script().p2sh_address(network)cecc.py:227S256Point.p2tr_address()p2tr_script().address(network)pecc.py:339-351S256Pointscript.py:428RedeemScript.address()script_pubkey().address(network)script.py:511P2WPKHScriptPubKey.p2sh_address()redeem_script().address(network)script.py:579WitnessScript.p2sh_address()redeem_script().address(network)tx.py:164-237Tx.parse_hex/parse/parse_legacy/parse_segwitself.networktx.py:864-878TxIn.fetch_tx/value/script_pubkeyTxFetcher.fetch(network)psbt.py(6 methods)parse()methodspath_network()as fallbackhd.py:273,695raw_parse()Branching on
network == "mainnet"(else = all non-mainnet including regtest)script.py:386P2PKHScriptPubKey.address()0x00, else →0x6f0x6fscript.py:405P2SHScriptPubKey.address()0x05, else →0xc40xc4script.py:504P2WPKHScriptPubKey.address()encode_bech32_checksum(network)script.py:545P2WSHScriptPubKey.address()encode_bech32_checksum(network)script.py:572P2TRScriptPubKey.address()encode_bech32_checksum(network)All mainnet-vs-else branches are correct for regtest because regtest shares testnet's base58 version bytes, and bech32 functions use the
PREFIXdict which already includes regtest.Inherent protocol limitations (not bugs)
cecc.py:493,pecc.py:693): WIF prefix0xEFis shared by testnet/signet/regtest — the format cannot distinguish them.pecc.pydocuments this explicitly.path_network()(helper.py:360): BIP32 paths use coin1'for all non-mainnet networks — cannot distinguish testnet/signet/regtest. PSBT callers allow explicitnetworkoverride.Test plan
bcrt1q..., len 44) parses and roundtripsbcrt1q..., len 64) parses and roundtripsbcrt1p..., len 64) parses and roundtripsTxFetcher.get_url("regtest")raisesValueErrorwith clear message🤖 Generated with Claude Code