src.transaction

Defines transactions and their inputs and outputs.

Functions

Classes

Transaction(inputs, targets[, signatures, iv]) A transaction as it was received from the network or a block.
TransactionInput One transaction input (pointer to ‘coin’).
TransactionTarget(recipient_pk, amount) The recipient of a transaction (‘coin’).
class src.transaction.TransactionTarget(recipient_pk, amount)

The recipient of a transaction (‘coin’).

Variables:
amount

Alias for field number 1

recipient_pk

Alias for field number 0

class src.transaction.TransactionInput

One transaction input (pointer to ‘coin’).

Variables:
  • transaction_hash (bytes) – The hash of the transaction that sent money to the sender.
  • output_idx (int) – The index into Transaction.targets of the transaction_hash.
classmethod from_json_compatible(obj)

Creates a new object of this class, from a JSON-serializable representation.

to_json_compatible()

Returns a JSON-serializable representation of this object.

class src.transaction.Transaction(inputs, targets, signatures=None, iv=None)

A transaction as it was received from the network or a block. To check that this transaction is valid on top of a block chain and in combination with a set of different transactions (from the same block), you can call the verify method.

Variables:
  • inputs (List[TransactionInput]) – The inputs of this transaction. Empty in the case of block reward transactions.
  • targets (List[TransactionTarget]) – The targets of this transaction.
  • signatures (List[bytes]) – Signatures for each input. Must be in the same order as inputs. Filled by sign().
  • iv (bytes) – The IV is used to differentiate block reward transactions. These have no inputs and therefore would otherwise hash to the same value, when the target is identical. Reuse of IVs leads to inaccessible coins.
classmethod from_json_compatible(obj)

Creates a new object of this class, from a JSON-serializable representation.

get_hash()

Hash this transaction. Returns raw bytes.

Return type:bytes
get_transaction_fee(chain)

Computes the transaction fees this transaction provides.

sign(private_keys)

Sign this transaction with the given private keys. The private keys need to be in the same order as the inputs.

to_json_compatible()

Returns a JSON-serializable representation of this object.

verify(chain, other_trans)

Verifies that this transaction is completely valid.

Return type:bool