Skip to content

kujenga/rockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rockchain

Build Status Build Status

A blockchain written in Rust.

This project is aimed at furthering my personal understanding of Rust. The blockchain implementation is based on the following walkthrough, which was originally done in Python:

https://hackernoon.com/learn-blockchains-by-building-one-117428612f46

Many thanks to the original author!

Usage

The following command will start the blockchain server.

RUST_LOG=blockchain,iron,logger=info cargo run

View the blockchain in it's empty genesis state:

curl http://localhost:3000/chain | jq

Create a new transaction:

curl -XPOST http://localhost:3000/transactions/new -H 'Content-Type: application/json' --data '{
  "sender": "me",
  "recipient": "you",
  "amount": 123
}' | jq

Trigger mining, creating a new block:

curl http://localhost:3000/mine | jq

View the blockchain again, with the requested transaction now persisted within a block:

curl http://localhost:3000/chain | jq

Creating a network

The PORT environment variable can be used to set a custom port number. In another window, another node can be started with the following command.

RUST_LOG=blockchain,iron,logger=info PORT=3001 cargo run

To manually register this node with the original one, the following request can be performed:

curl -XPOST http://localhost:3001/nodes/register -H 'Content-Type: application/json' --data '{
  "nodes": [{
    "address": "http://localhost:3000"
  }]
}' | jq

Trigger the execution of the consensus protocol, bringing state of the new node up to date:

curl http://localhost:3001/nodes/resolve | jq

Status

  • Building a blockchain
  • Blockchain API
  • Distributed Consensus
  • More idiomatic error handling
  • Refactor blockchain and server into separate modules
  • Auto-register peers using CLI args
  • Move blockchain data types into library crate

About

A simple blockchain implementation in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages