Naivechain is a Ruby implementation of Blockchain in ~160 lines.
Blockchain is a distributed peer-to-peer, non-functional$ implementation that can be used in a lot of cases where intermediaries exist. Blockchain attempts to disintermediate the world using publicly transparent chains of block spread over nodes.
This implementation takes inspiration from Naivechain excepts:
- It used HTTP for all communication
- It has proof of work mechanism albeit very simple
- It is written in an object-oriented fashion:
Block
andChain
class.
$: Non-functional requirement: a requirement specifying the how part of a system, e.g.: how the system will work that is, it will work by involving a Blockchain, Merkle tree, and so on. On the other hand, making a borderless transaction is a functional requirement.
Start the server:
rackup ./server.ru -p 9292
Start the client tool:
ruby client.rb
Blockchain client
Specify the port: 9292
9292> hi there
You may spawn as many server and client instances as you please.
Endpoint | Purpose |
---|---|
/peers | Listing all peers |
/chain | Showing the chain, including the blocks |
/chain/blocks | Showing the blocks in the chain |
/peers/register/:port | Adding a peer in this node, and vice-versa |
/chain/add | Convenient endpoint to add a new block with text data |
/chain/mine | Endpoint for peer-to-peer communications |