cashscript_py.helpers.transaction module

Provides functionality for transaction serialization.

exception OutputAddressInvalid(address: str)[source]

Bases: Exception

Raised when an output address cannot be parsed.

exception OutputSatoshisNonPositiveError(amount: int)[source]

Bases: Exception

Raised when an output amount is zero or negative.

exception OutputSatoshisTooSmallError(amount: int, minimum: int)[source]

Bases: Exception

Raised when an output amount is below the dust threshold.

exception OutputTokenAmountTooSmallError(amount: int)[source]

Bases: Exception

Raised when a token amount is negative.

exception TokensToNonTokenAddressError(address: str)[source]

Bases: Exception

Raised when attempting to send CashTokens to a non-token-aware address.

calculate_dust(output: Output) int[source]

Compute dust minimum for a given output.

create_op_return_output(op_return_data: list[str]) Output[source]

Create an OP_RETURN output from a list of UTF-8 or hex (0x-prefixed) chunks.

create_preimage(tx: Transaction, source_outputs: list[Output], input_index: int, covered_bytecode: bytes, hash_type: int) bytes[source]

Build the sighash preimage for a given input.

Parameters:
  • tx – Transaction template.

  • source_outputs – Source outputs for inputs (used for SIGHASH_UTXOS).

  • input_index – Index of the input being signed.

  • covered_bytecode – Locking script being covered by the signature.

  • hash_type – Full hashtype flags.

Returns:

The serialized preimage bytes.

get_output_size(output: Output) int[source]

Return the serialized size (bytes) of an output.

serialize_input(unlockable_utxo: UnlockableUtxo, tx: Transaction, source_outputs: list[Output], input_index: int) bytes[source]

Serialize a single input for a transaction.

serialize_output(output: Output) bytes[source]

Serialize a single output to bytes for transaction use.

serialize_transaction(tx: Transaction) bytes[source]

Encodes a transaction object into a byte string suitable for transmission or signing.

validate_output(output: Output) None[source]

Validate an Output (address parsing, dust threshold, token rules).