cashscript_py.network.network_provider module

Network provider interfaces and enums.

exception BroadcastFailed(error: Exception | str)[source]

Bases: RuntimeError

Raised when a network broadcast attempt fails.

class Network(*values)[source]

Bases: StrEnum

Supported Bitcoin Cash networks (network and address prefixes).

CHIPNET = 'chipnet'
MAINNET = 'mainnet'
MOCKNET = 'mocknet'
REGTEST = 'regtest'
TESTNET3 = 'testnet3'
TESTNET4 = 'testnet4'
class NetworkProvider[source]

Bases: ABC

Abstract 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:
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:
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.

abstract property network: Network

Return the network this provider connects to.

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.

exception RequestFailed(error: Exception)[source]

Bases: RuntimeError

Raised when a network request fails.

exception UnexpectedResponse(response: Any)[source]

Bases: RuntimeError

Raised when a network response has an unexpected format or type.