Skip to Content
Foundations of Blockchain
book

Foundations of Blockchain

by Koshik Raj
January 2019
Beginner to intermediate
372 pages
11h 17m
English
Packt Publishing
Content preview from Foundations of Blockchain

Transaction structure

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)), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Blockchain Basics

Blockchain Basics

Daniel Drescher
What Is Blockchain?

What Is Blockchain?

Sir John Hargrave, Evan Karnoupakis
Mastering Blockchain

Mastering Blockchain

Lorne Lantz, Daniel Cawrey

Publisher Resources

ISBN: 9781789139396Supplemental Content