Server on Golang

Server is running on http://localhost:8080/ and has 4 end-points:

  • GET / - shows all blocks
  • GET /all_data - shows all data (all records)
  • POST /add_data - adds data in json { data: "string of data" }
  • GET /last_blocks/{blockId} - shows 'blockId' count of last blocks

Data (record) structure

{
  data: "string of data"
}

Block structure

Block is forming when server gets 5 records:

{
  // string of previous block hash or '0' for the first block
  previous_block_hash: '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08',
  // array of 5 records data
  rows: ['data1','data2','data3','data4','data5'],
  // current timestamp
  timestamp: 12123889,
  // string of SHA256 of previous 3 fields of this block
  block_hash: '1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014'
}

Install and run

Install Go lang.

Build project:

go build

Run on http://localhost:8080/:

./go_server

Add new data from console:

curl -H "Content-Type: application/json" -d '{"data":"New data"}' http://localhost:8080/add_data