January 2019
Beginner to intermediate
372 pages
11h 17m
English
A transaction is a collection of valid transaction inputs and outputs, as shown here:
class Transaction:
def __init__(self, tx_ins, tx_outs, tx_id=None):
self.tx_ins = tx_ins
self.tx_outs = tx_outs
self.id = tx_id if tx_id else get_transaction_id(self)
A transaction ID is derived from the digest of the entire transaction. The SHA256 hash function is used to calculate the digest of the concatenated transaction input and output contents, as shown here:
def get_transaction_id(transaction): tx_in_content = reduce(lambda a, b : a + b, map( (lambda tx_in: str(tx_in.tx_out_id) + str(tx_in.tx_out_index)), transaction.tx_ins), '') tx_out_content = reduce(lambda a, b : a + b, map( (lambda tx_out: str(tx_out.address) + str(tx_out.amount)), ...