zenoxygen / blockchain

A basic blockchain for educational purposes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

blockchain Build Status

A basic blockchain for educational purposes.

Overview

  1. Create a genesis block with one transaction where:
  • Alice receives 50 coins and Bob receives 25 coins
  1. Mine that block
  2. Add it to the blockchain
  3. Create a new block with two transactions where:
  • Charlie receives 5 coins
  • Alice sends 30 coins to herself and sends 20 coins to Bob
  1. Mine that block
  2. Add it to the blockchain

Dependencies

  • hex, for encoding/decoding data into/from hexadecimal representation
  • crypto-hash, for cryptographic hash functions

Run

cargo run

More details

Block hashing

  1. Concatenate together all the bytes composing the block's fields (aside from the hash field)
  2. Generate unique data fingerprint: the hash

Difficulty

Difficulty is expressed in this way:

  • The first n bytes of the hash that must be zero
  • The number of bits or bytes as the beginning of the hash that must be zero

Mining

  1. Generate new nonce (an arbitrary number that can be used just once)
  2. Hash bytes (computationally heavy step)
  3. Check hash against difficulty
  • Insufficient? Go back to step 1
  • Sufficient? Continue to step 4
  1. Add block to the blockchain

About

A basic blockchain for educational purposes.


Languages

Language:Rust 100.0%