cashscript_py.network.network_provider module
Network provider interfaces and enums.
- exception BroadcastFailed(error: Exception | str)[source]
Bases:
RuntimeErrorRaised when a network broadcast attempt fails.
- class Network(*values)[source]
Bases:
StrEnumSupported Bitcoin Cash networks (network and address prefixes).
- CHIPNET = 'chipnet'
- MAINNET = 'mainnet'
- MOCKNET = 'mocknet'
- REGTEST = 'regtest'
- TESTNET3 = 'testnet3'
- TESTNET4 = 'testnet4'
- class NetworkProvider[source]
Bases:
ABCAbstract base class for providers connecting to BCH networks.
Implementations must support querying UTXOs, block height, raw transactions, and broadcasting.
- abstractmethod async get_block_height() int[source]
Return the current block height.
- Raises:
RequestFailed – If the provider returns an error.
UnexpectedResponse – If the provider returns a malformed response.
- abstractmethod async get_raw_transaction(txid: str) str[source]
Retrieve the raw transaction hex for a txid.
- Parameters:
txid – Transaction ID (hex).
- Returns:
Raw transaction hex.
- Raises:
RequestFailed – If the provider returns an error.
UnexpectedResponse – If the provider returns a malformed response.
- abstractmethod async get_utxos(address: str) list[Utxo][source]
Retrieve UTXOs for a given CashAddress.
- Parameters:
address – The CashAddress for which UTXOs are requested.
- Returns:
A list of spendable UTXOs.
- abstractmethod async send_raw_transaction(tx_hex: str) str[source]
Broadcast a raw transaction to the network.
- Parameters:
tx_hex – Hex-encoded transaction.
- Returns:
Transaction ID computed for the broadcast transaction.
- Raises:
BroadcastFailed – If the transaction was not accepted by the network.