Skip to content

Latest commit

 

History

History
80 lines (58 loc) · 5.63 KB

L2.4 Blockchain Data.md

File metadata and controls

80 lines (58 loc) · 5.63 KB

L2.4 Blockchain Data

Blockchain Data Models Overview

Block Header

  • Previous Block's Hash - The hash value for the block that comes directly before a given block in the chain. This is what links blocks in the blockchain together.
  • Time - The time the block was created is also held in the header
  • Merkle Root - The merkle root is a hash that represents every transaction included inside the block. To get the merkle root, pairs of transactions within a block are repeatedly hashed together. Each pair results in a single hash. Then the hash of 2 pairs of transactions are again hashed together, over and over again until you are left with a single hash value. Given that final hash value, known as the merkle root, you can now use the hash to search the original transactions or hash values that created them. This searching allows you to find the original transactions that made up the block when starting from this single hash value.
  • Nonce - A nonce (stands for “number only used once") is a number used in bitcoin mining. The blockchain miners are solving for the nonce what when added to a hashed block, and those 2 values are rehashed, will solve the mining puzzle.

Transactions - Inputs and Outputs

Summary

Transactions encode the transfer of value between participants in the system. In more detail, a transaction is a data structure that encodes a transfer of value from a source of funds called an “input” to a destination called an “output”.

Inputs in one transaction are just the unspent outputs from another transaction. All inputs reference back to an output. Unspent Outputs is sometimes short-handed to UTXO.

Sum(Inputs) - Sum(Outputs) = Transaction Fees

Data models

Bitcoin Scripts

Script A list of instructions recorded in each transaction that when executed determines if the transaction is valid and the bitcoins can be spent.

  • Stack-based language
  • Stores Numbers (Data Constants)
  • Uses Opcodes
    • Push (Add)
    • Pop (Remove)
    • Etc.
  • Executes from Left to Right

Scripting Language A simple, lightweight language designed to be limited in scope and executable on a range of hardware.

A breakdown of the Raw Transaction

Raw transaction:

0100000001f3f6a909f8521adb57d898d2985834e632374e770fd9e2b98656f1bf1fdfd427010000006b48304502203a776322ebf8eb8b58cc6ced4f2574f4c73aa664edce0b0022690f2f6f47c521022100b82353305988cb0ebd443089a173ceec93fe4dbfe98d74419ecc84a6a698e31d012103c5c1bc61f60ce3d6223a63cedbece03b12ef9f0068f2f3c4a7e7f06c523c3664ffffffff0260e31600000000001976a914977ae6e32349b99b72196cb62b5ef37329ed81b488ac063d1000000000001976a914f76bc4190f3d8e2315e5c11c59cfc8be9df747e388ac00000000

Breakdown Components

  • Version - All transactions include information about the Bitcoin Version number so we know which rules this transaction follows.
  • Input Count - Which is how many inputs were used for this transaction

Data stored in Input information:

  • Previous output hash - All inputs reference back to an output (UTXO). This points back to the transaction containing the UTXO that will be spend in this input. The hash value of this UTXO is saved in a reverse ordered here.
  • Previous output index - The transaction may have more than one UTXO which are referenced by their index number. The first index is 0.
  • Unlocking Script Size - This is the size of the Unlocking Script in bytes.
  • Unlocking Script - This is the hash of the Unlocking Script that fulfills the conditions of the UTXO Locking Script.
  • Sequence Number - This s a deprecated feature of bitcoin Currently set to ffffffff by default.

Output Count - which tells us how many outputs were produced from this transaction.

Data stored in Output Information:

  • Amount - The amount of Bitcoin outputted in Satoshis (the smallest bitcoin unit). 10^8 Satoshis = 1 Bitcoin.
  • Locking Script Size - This is the size of the Locking Script in bytes.
  • Locking Script - This is the hash of the Locking Script that specifies the conditions that must be met to spend this output.

Locktime - The locktime field indicates the earliest time or the earliest block a transaction can be added to the blockchain. If the locktime is non-zero and less than 500 million, it is interpreted as a block height and miners have to wait until that block height is reached before attempting to add it to a block. If the locktime is above 500 million, it is read as a unix timestamp which means the number of seconds since the date January 1st 1970. It is usually 0 which means confirm as soon as possible.

Unlocking script and Locking script For a transaction to be valid, the unlocking script will solve the locking script. Locking script is like a puzzle that specifies the conditions that must be met before the Bitcoins can be spent. The unlocking script contains the correct solution that solves the puzzle and evaluates the locking script to “true”.

Raw Transaction Review

Bitcoin Transaction Hash

SHA256(SHA256(Raw Transaction)) = Transaction Hash
This means the raw transaction was put through SHA256 twice to get the Transaction hash we see on the blockchain.

Input information

Output information