teos.carrier

class Carrier(btc_connect_params)[source]

Bases: object

The Carrier is in charge of interacting with bitcoind to send/get transactions. It uses Receipt objects to report about the sending outcome.

Parameters

btc_connect_params (dict) – a dictionary with the parameters to connect to bitcoind (rpc user, rpc password, host and port).

logger

The logger for this component.

Type

Logger

issued_receipts

A dictionary of issued receipts to prevent resending the same transaction over and over. It should periodically be reset to prevent it from growing unbounded.

Type

dict

get_transaction(txid)[source]

Queries transaction data to bitcoind given a transaction id.

Parameters

txid (str) – a 32-byte hex-formatted string representing the transaction id.

Returns

A dictionary with the transaction data if the transaction can be found on the chain. None otherwise.

Return type

dict or None

send_transaction(rawtx, txid)[source]

Tries to send a given raw transaction to the Bitcoin network using bitcoind.

Parameters
  • rawtx (str) – a (potentially) signed raw transaction ready to be broadcast.

  • txid (str) – the transaction id corresponding to rawtx.

Returns

A receipt reporting whether the transaction was successfully delivered or not and why.

Return type

Receipt

class Receipt(delivered, confirmations=0, reason=None)[source]

Bases: object

The Receipt class represent the interaction between the Carrier and bitcoind when broadcasting transactions. It is used to signal whether or not a transaction has been successfully broadcast and why.

Parameters
  • delivered (bool) – whether or not the transaction has been successfully broadcast.

  • confirmations (int) – the number of confirmations of the transaction to broadcast. In certain situations the Carrier may fail to broadcast a transaction because it was already in the blockchain. This attribute signals those situations.

  • reason (int) – an error code describing why the transaction broadcast failed.

Returns

A receipt describing whether or not the transaction was delivered. Notice that transactions that are already on chain are flagged as delivered with a confirmations > 0 whereas new transactions are so with confirmations = 0.

Return type

Receipt