pyrxd.transaction — Transaction building

Transaction building, signing, and serialization for Radiant.

exception pyrxd.transaction.InsufficientFunds[source]

Bases: ValueError

class pyrxd.transaction.Transaction[source]

Bases: object

__init__(tx_inputs=None, tx_outputs=None, version=1, locktime=0, merkle_path=None, **kwargs)[source]
Parameters:
add_input(tx_input)[source]
Parameters:

tx_input (TransactionInput)

Return type:

Transaction

add_inputs(tx_inputs)[source]
Parameters:

tx_inputs (list[TransactionInput])

Return type:

Transaction

add_output(tx_output)[source]
Parameters:

tx_output (TransactionOutput)

Return type:

Transaction

add_outputs(tx_outputs)[source]
Parameters:

tx_outputs (list[TransactionOutput])

Return type:

Transaction

byte_length()[source]
Returns:

actual byte length of this transaction under the current state

Return type:

int

estimated_byte_length()[source]
Returns:

estimated byte length of this transaction after signing

Return type:

int

if transaction has already signed, it will return the same value as function byte_length

estimated_size()
Returns:

estimated byte length of this transaction after signing

Return type:

int

if transaction has already signed, it will return the same value as function byte_length

fee(model_or_fee=None, change_distribution='equal')[source]

Computes the fee for the transaction and adjusts the change outputs accordingly.

Parameters:
  • model_or_fee – Fee model or fee amount. Defaults to SatoshisPerKilobyte with value 10 if not provided.

  • change_distribution – Method of change distribution (‘equal’ or ‘random’). Defaults to ‘equal’.

classmethod from_beef(stream)[source]
Parameters:

stream (str | bytes | Reader)

Return type:

Transaction

classmethod from_hex(stream)[source]
Parameters:

stream (str | bytes | Reader)

Return type:

Transaction | None

classmethod from_reader(reader)[source]
Parameters:

reader (Reader)

Return type:

Transaction

get_fee()[source]
Returns:

actual fee paid of this transaction under the current state

Return type:

int

hash()[source]
Return type:

bytes

hex()[source]
Return type:

str

is_coinbase()[source]
Return type:

bool

classmethod parse_script_offsets(octets)[source]

Since the validation of blockchain data is atomically transaction data validation, any application seeking to validate data in output scripts must store the entire transaction as well. Since the transaction data includes the output script data, saving a second copy of potentially large scripts can bloat application storage requirements.

This function efficiently parses binary transaction data to determine the offsets and lengths of each script. This supports the efficient retrieval of script data from transaction data.

@param octets: binary transaction data or hex string @returns: {

inputs: { vin: number, offset: number, length: number }[] outputs: { vout: number, offset: number, length: number }[]

}

Parameters:

octets (bytes | str)

Return type:

dict[str, list[dict[str, int]]]

preimage(index)[source]
Returns:

digest of the input specified by index

Parameters:

index (int)

Return type:

bytes

raw()
Return type:

str

serialize()[source]
Return type:

bytes

sign(bypass=True)[source]
Bypass:

if True then ONLY sign inputs which unlocking script is None, otherwise sign all the inputs

Parameters:

bypass (bool)

Return type:

Transaction

sign all inputs according to their script type

size()
Returns:

actual byte length of this transaction under the current state

Return type:

int

to_beef()[source]
Return type:

bytes

to_ef()[source]
Return type:

bytes

total_value_in()[source]
Return type:

int

total_value_out()[source]
Return type:

int

txid()[source]
Return type:

str

class pyrxd.transaction.TransactionInput[source]

Bases: object

__init__(source_transaction=None, source_txid=None, source_output_index=0, unlocking_script=None, unlocking_script_template=None, sequence=4294967295, sighash=SIGHASH.ALL_FORKID)[source]
Parameters:
  • source_txid (str | None)

  • source_output_index (int)

  • unlocking_script (Script | None)

  • unlocking_script_template (UnlockingScriptTemplate)

  • sequence (int)

  • sighash (SIGHASH)

classmethod from_hex(stream)[source]
Parameters:

stream (str | bytes | Reader)

Return type:

TransactionInput | None

serialize()[source]
Return type:

bytes

class pyrxd.transaction.TransactionOutput[source]

Bases: object

__init__(locking_script, satoshis=None, change=False)[source]
Parameters:
classmethod from_hex(stream)[source]
Parameters:

stream (str | bytes | Reader)

Return type:

TransactionOutput | None

serialize()[source]
Return type:

bytes