btc_networks
Bitcoin Network Configuration Module
Provides configurations for Bitcoin mainnet and testnet, including API endpoints for balance and transaction queries.
- class btc_networks.BTCNetworkConfig(name, network_name, is_testnet, api_base_url, api_backup_url=None, explorer_url=None)[source]
Bases:
objectImmutable description of a single Bitcoin network and its block-explorer APIs.
Bundles the human-readable name, the canonical
network_nameunderstood bybitcoinlib(e.g.bitcoin,testnet,signet), a testnet flag, and the REST/explorer endpoints used to query balances, UTXOs, and transactions. Instances are declared once in the module-levelBTC_NETWORKSregistry and looked up by alias viaget_btc_network; theis_testnetflag andnetwork_namethen steer BIP84 coin-type selection (0'vs1') inBTCWalletManagerand the base URL drives HTTP calls intools/btc_wallet_tools.py.This is a frozen-by-convention config object with no behavior beyond
to_dict; it touches no Redis, network, or filesystem state itself.- Parameters:
name (
str) – Human-readable network label (e.g.Bitcoin Mainnet).network_name (
str) – Canonical network identifier passed tobitcoinlib.is_testnet (
bool) – Whether this is a test/dev network (testnet/signet).api_base_url (
str) – Base URL for the primary REST API used for queries.api_backup_url (
Optional[str]) – Optional secondary REST API URL.explorer_url (
Optional[str]) – Optional human-facing block-explorer URL.
- to_dict()[source]
Return a JSON-serializable view of this network config for API responses.
Flattens the public fields (name, network_name, is_testnet, api_base_url, explorer_url) into a plain dict suitable for embedding in tool output or serializing to JSON; the
api_backup_urlis deliberately omitted as an internal failover detail. Performs no I/O and mutates nothing. No in-repo callers reference this method directly; it is a helper kept for serializing a config when surfacing network details.
- btc_networks.get_btc_network(network_name='bitcoin')[source]
Look up a Bitcoin network config by name or alias from the static registry.
Normalizes the supplied name (lowercased and stripped) and resolves it against the module-level
BTC_NETWORKSmapping, which accepts several aliases per network (bitcoin,btc,mainnetall map to mainnet;testnet,btc_testnet;signet). This is the single entry point used to translate a user-facing network string into the explorer endpoints and BIP84 coin-type behavior the wallet code relies on. Pure in-memory lookup with no I/O.Called by
BTCWalletManagermethods (create_wallet,import_wif,derive_address,get_private_keyinbtc_wallet_manager.py) and by the tool handlers intools/btc_wallet_tools.pyto validate and resolve the requested network before any wallet or HTTP operation.- Parameters:
network_name (
str) – Network name or alias; case-insensitive and whitespace is trimmed. Defaults tobitcoin.- Returns:
The matching config, or
Noneif the name is not a recognized alias.- Return type:
- btc_networks.list_btc_networks(include_testnets=True)[source]
Enumerate the distinct supported Bitcoin networks, de-duplicating aliases.
Walks the
BTC_NETWORKSregistry and collapses the multiple aliases that point at the same network down to one entry pernetwork_name, optionally filtering out test networks. Results are sorted so production (mainnet) appears before testnets and then alphabetically by display name, giving a stable list suitable for presenting available networks to a user. Pure in-memory operation with no I/O.No in-repo callers reference this helper directly; it is available for tools or surfaces that need to advertise the supported network set.