PoW Blockchain implementation in Rust.
General idea was to fully understand technical blockchain mechanism by implementing one from scratch.
- main.rs : running basic tasks of the blockchain
- lib.rs : basic bytes functions needed in the program
- hashable.rs : computing data before hashing
- block.rs : main implementation, blockchain characteritics
- blockchain.rs : blockchain implentation and security mecanism defined in BlockValidationErr
- transactions.rs : transactions implementation based on UTXOs (Bitcoin based)
Install rust : https://www.rust-lang.org/
git clone https://github.com/ClementCauffet/Blockchain-from-Scratch.git
cd blockchain-from-scratch
cargo run
- Generate Nonce
- Hash bytes (SHA-256)
- Check against difficulty
- Not enought -> back to 1.
- Enought -> Move on to 4.
- Add block to chain
- Submit to peers
- Actual index == stored index value
- Correlation of the difficulty (just gonna trust difficulty atm -> dangerous for production applications)
- Time continuously increasing
- Actual previous block hash == stored prev_block_hash value (except genesis block)
- Where did the money come from ?
- Is the money available ?
- Who owns the money and who is sending it ?
- (WIP) more to cover later on cf -> https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages
Transactions are composed of inputs and outputs. As a matter of fact, outputs are inputs from other transactions (UTXO-like).
Thanks to both Blockchain and Rust communities for information provided online :
Rust Language : https://www.rust-lang.org/
Algorithm Architecture : https://geeklaunch.net/blog/
!! This repository is still in progress. Do not use non-audited code for professionnal applications !!