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:
tx_inputs (list[TransactionInput] | None)
tx_outputs (list[TransactionOutput] | None)
version (int)
locktime (int)
merkle_path (MerklePath | None)
- add_input(tx_input)[source]¶
- Parameters:
tx_input (TransactionInput)
- Return type:
- add_inputs(tx_inputs)[source]¶
- Parameters:
tx_inputs (list[TransactionInput])
- Return type:
- add_output(tx_output)[source]¶
- Parameters:
tx_output (TransactionOutput)
- Return type:
- add_outputs(tx_outputs)[source]¶
- Parameters:
tx_outputs (list[TransactionOutput])
- Return type:
- byte_length()[source]¶
- Returns:
actual byte length of this transaction under the current state
- Return type:
- estimated_byte_length()[source]¶
- Returns:
estimated byte length of this transaction after signing
- Return type:
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:
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(TRANSACTION_FEE_RATE), i.e. Radiant’s effective minimum relay rate of 10_000_000 photons/kB. The old default of 5 photons/kB was a Bitcoin-shaped inheritance that produced transactions 2_000_000x under the floor AcceptToMemoryPool enforces; every one of them was unrelayable. Preferpyrxd.fee_sizingfor anything that must provably clear the floor at its FINAL serialised size — this method sizes against the estimate, not the signed bytes.change_distribution – Method of change distribution (‘equal’ or ‘random’). Defaults to ‘equal’.
- classmethod from_hex(stream)[source]¶
Deserialize a transaction.
Given a whole buffer (
str/bytes) the parse must consume ALL of it. An input whose script-length varint over-claims does not run off the end of a transaction — it steals bytes from the fields that follow, and the field boundaries slide until the tail comes up short. The result parsed “successfully” into a different transaction: a 63-byte blob re-serialized to 56 bytes, sotxid()returned the id of a transaction those bytes do not encode. Requiring the reader to finish at EOF is what makesfrom_hex->serializean identity instead of a rewrite.Given a
Reader, the caller is streaming (from_beefreads a sequence of transactions from one buffer) and owns the remaining bytes, so no EOF check applies.- Parameters:
- Return type:
Transaction | None
- get_fee()[source]¶
- Returns:
actual fee paid of this transaction under the current state
- Return type:
- 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 }[]
}
- 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]¶
- classmethod from_hex(stream)[source]¶
- Parameters:
- Return type:
TransactionInput | None