Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CONTRACT_ADDRESS=
# ─── Chain: Bitcoin (env_prefix=BTC) ───────────────────────
# node = local Bitcoin node | lightweight = Blockstream API (no node required)
BTC_MODE=lightweight
# mainnet | testnet (auto-detected from RPC URL in node mode)
# mainnet | testnet | testnet4 (auto-detected from RPC URL in node mode)
BTC_NETWORK=mainnet
# Required for BTC_MODE=node only
BTC_RPC_URL=
Expand Down
11 changes: 8 additions & 3 deletions allways/chain_providers/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def __init__(self):
self.rpc_user = os.environ.get('BTC_RPC_USER', '')
self.rpc_pass = os.environ.get('BTC_RPC_PASS', '')
if not self.network:
if any(p in self.rpc_url for p in [':18332', ':18443', 'testnet']):
if ':48332' in self.rpc_url:
self.network = 'testnet4'
elif any(p in self.rpc_url for p in [':18332', ':18443', 'testnet']):
self.network = 'testnet'
else:
self.network = 'mainnet'
Expand Down Expand Up @@ -398,7 +400,10 @@ def btc_api_bases(self) -> list[tuple[str, Optional[dict]]]:
"""
if self.esplora_bases:
return self.esplora_bases
if self.network == 'testnet':
if self.network == 'testnet4':
# Blockstream serves no testnet4 API; mempool.space is the only public Esplora.
defaults = ('https://mempool.space/testnet4/api',)
elif self.network == 'testnet':
defaults = ('https://blockstream.info/testnet/api', 'https://mempool.space/testnet/api')
else:
defaults = ('https://blockstream.info/api', 'https://mempool.space/api')
Expand Down Expand Up @@ -620,7 +625,7 @@ def send_amount_lightweight(
return None

try:
network = NETWORKS['test'] if self.network == 'testnet' else NETWORKS['main']
network = NETWORKS['test'] if self.network in ('testnet', 'testnet4') else NETWORKS['main']
privkey = EmbitPrivateKey.from_wif(wif)
pubkey = privkey.get_public_key()
segwit_script = p2wpkh(pubkey)
Expand Down
Loading