Giter VIP home page Giter VIP logo

g-coin's Introduction

G Coin

A simple implementation of Blockchain for understanding easily.

It includes only basic concepts.

  • Block and Hash
  • Transaction and Balance
  • Mining with Proof of Work
  • Chain validation and consensus conflicts

Articles (Korean)

Modules

bold is core function.

  • blockchain : chain structure /w blocks
    • new_block: make block /w hash of previous block and current proof
    • valid: validate chain rules of all chain
  • block : block structure
    • hash: hash itself
  • proof : proof of work
    • find_proof
    • valid_proof
  • miner : Mining new block and get rewards
  • transaction : data object
  • book : book of transactions
    • check_balance /w transaction history of sender account
  • node
    • consensus_with_neighbor

Endpoints

  • /transaction : Add a transaction and get pending transactions.
  • /mine : Mining. Find proof and make block with rewards.
  • /node : Add a node as a neighbor node
  • /chain : Get full chain to validate.
  • /chain/valid : Valid chain
  • /chain/consensus : Consensus conflicts

Basic Flow

  • /transaction: Add trasaction for sending coin.
    • Check balance and add to blockchain
    • Use '0' as a sender id at the first time. It's the genesis wallet.
  • /mine: Mining for making block.
    • Find proof with previous proof
    • Add a reward to transactions
    • Make a new block with proof and hash of previous block
    • Add the block to chain of blocks
    • Clear current transactions
  • /chain/consensus: Consensus conflicts with neighbor nodes.
    • Fetch blockchain from all neighbor nodes.
    • Check which has the longest chain and valiates it's chain.
    • Add neighbor nodes before do this using /node

Try using Insomnia

  • Download Insomnia
  • Import from insomnia.json

Mining practice

python app.py --port 5000
  • First try
    • POST /transaction
      • /w {sender: '0', recipient: 'golbin', amount: 10}
    • GET /transaction
    • GET /chain
    • POST /mine
    • GET /chain
    • GET /transaction
  • Second try
    • POST /transaction
      • /w {sender: 'golbin', recipient: 'bluecat', amount: 10}
    • POST /transaction
      • /w {sender: 'golbin', recipient: 'bluecat', amount: 10}
    • POST /mine
    • GET /chain

Consensus practice

python app.py --port 5000
python app.py --port 5001
  • POST /node
    • to 127.0.0.1:5000 /w {address: '127.0.0.1:5001'}
  • POST /node
    • to 127.0.0.1: 5001 /w {address: '127.0.0.1:5000'}
  • Try several mining
  • GET /chain/valid
  • POST /chain/consensus

Requirements

  • Python >= 3.6
  • Flask >= 0.12
  • Requests >= 2.18

TODO

  • Merkle root implementation
  • Check balance in transactions in next blocks
  • Fix balance of genesis account
  • Broadcast transactions
  • Use DB

References

g-coin's People

Contributors

golbin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.