Skip to content

An implementation of the blockchain datastructure using Ruby

License

Notifications You must be signed in to change notification settings

wzwietering/blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blockchain

This project contains a blockchain with an API and support for multiple nodes. The blockchain code has validations mechanisms to verify blocks, transactions and the entire chain. Every block hash starts with four zeros. Transactions are validated using a Merkle Tree.

Setup

Install ruby and the bundler gem. Run bundle.

Usage

Enter ruby app.rb in your favorite terminal to start the server. The application can be accessed via localhost:4567. The server can do the following requests:

  • GET /mine mines the current block
  • GET /chain returns the full chain in JSON
  • GET /chain/valid tells you whether the current chain is valid
  • POST /chain/index to get the block on a certain index. The format is:
{
  "index": 1
}
  • POST /chain/range to get a range of blocks. When you omit the 'to' parameter you will get the chain to the end. The 'from' parameter is required. The format is:
{
  "from": 1,
  "to": 4
}
  • GET /load loads the previous used blockchain
  • GET /transactions/current show the transactions which are not yet placed in a block
  • POST /transactions/new to create a new transaction. The format is:
{
  "sender": "your hash",
  "recipient": "the other hash",
  "amount": 123
}
  • POST /block/valid validates a block for you. The required format is:
{
  "index": 0,
  "timestamp": 0,
  "transactions": [],
  "previous_hash": "0",
  "merkle_root": "0",
  "proof": 0
}

For multiple nodes you can use the following requests:

  • GET /nodes/resolve to resolve conflicts
  • POST /nodes/register to add a list of new nodes using the following format:
{
  "nodes": ["An ip adress or website"]
}

Sources

About

An implementation of the blockchain datastructure using Ruby

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages