github.com/josetom/go-chain

A simple blockchain on go built with inspiration from geth


Keywords
golang, blockchain
License
MIT
Install
go get github.com/josetom/go-chain

Documentation

Go Chain !

A simple blockchain built with inspiration from geth

API Reference Go Report Card CI

Story

Supported

  • Genesis
    • Initializes blockchain from genesis.json
    • creates block 0 from genesis.json data
  • State
  • Transactions
  • Hashing
  • Blocks
    • Validate blocks
    • Mine blocks
  • Http Server
  • Node
    • Peers
    • Sync
  • Wallets
  • LevelDB
    • Stores the blocks against hash
    • Has an index to point block number against hash. Iterator is run on this index

Todo

  • Websockets
  • GRPC
  • Concurrency checks
  • Proof of stake
  • Incoming longer block
  • Persist State
  • Misc items
    • Transactions
      • Block txn from zero address
      • Increment txn nonce for signer
    • Wallet
      • Import private key
    • Signer
      • Implement better way to sign the transactions
    • Node
      • Node Version
      • Sync should happen only after the blocks are synced first time
    • Miner
      • Isolate miner from regular nodes
  • ...??
  • Fix TODO comments

Development

go build ./cmd/go-chain/...
./go-chain --help

Testing

go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
go tool cover -func coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}'

Quick hacks

If you want to view database files

mkdir .database
cd ~/Libaray
ln -s ../../pet-project/blockchain/.database go-chain

Demo

Run console

./go-chain run

Create Wallet

./go-chain wallet new-account
./go-chain wallet print-pk --address="0xdd6b4d532aad2814bf5ea2bcc5e8939294857e6c"

Add Txn

Chain console should be running when transaction commands are called

./go-chain  tx add --from="0xdd6b4d532aad2814bf5ea2bcc5e8939294857e6c" --to="0x054b08ac0c3233efe965a6f24071de1353955e59" --value=50 --data="test"