Project created as an assignment for Udacity BlockChain Developer Nanodegree Program - Project 4. RESTful API using the Hapi.js Node.js framework which interfaces with the private blockchain. The package JOI was used to support input validation and Boom was used for http code handling.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
To run locally, this software requires node (version 8 or above) up and running
A step by step to get it running
Clone the project from github
git clone https://github.com/bsgiovanini/private_block_chain.git
Install nodemon global module
npm install -g nodemon
Install all dependencies of npm
npm install
Run this command on bash and a server will start at port 8000 with 10 blocks already added to the chain.
npm start
To validate the request, access it via the POST method (using Postman or Curl), specifying a text as a raw payload. If payload is not informed, a message of "Invalid Input" will be returned from the POST request. Use the URL for the endpoint:
http://localhost:8000/requestValidation
Example of a valid request payload:
{ "address":"19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL" }
To validate the signature, access it via the POST method (using Postman or Curl), specifying a text as a raw payload. If payload is not informed, a message of "Invalid Input" will be returned from the POST request. Use the URL for the endpoint:
http://localhost:8000/message-signature/validate
Example of a valid request payload:
{
"address":"19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL",
"signature":"H8K4+1MvyJo9tcr2YN2KejwvX1oqneyCH+fsUL1z1WBdWmswB9bijeFfOfMqK68kQ5RO6ZxhomoXQG3fkLaBl+Q="
}
After validation It is possible to post a block. Access it via the POST method (using Postman or Curl), specifying a text as a raw payload. If payload is not informed or its address was not validated, an error message will be returned from the POST request
http://localhost:8000/block/
Valid payload example
{
"address": "19xaiMqayaNrn3x7AjV5cU4Mk5f5prRVpL",
"star": {
"dec": "68° 52' 56.9",
"ra": "16h 29m 1.0s",
"story": "Found star using https://www.google.com/sky/"
}
}
Use the URL:
http://localhost:8000/stars/hash:{HASH}
Example:
http://localhost:8000/stars/hash:4639e23e3027a287a3512d6c86bb43191634d8083c1ae2e458fc45dd3987feac
Use the URL:
http://localhost:8000/stars/address:{ADDRESS}
Example:
http://localhost:8000/stars/address:1J2vezczmV3U7rdzG9XdmQjfzUFpWg6zfJ
To get a specific block, access it via the GET method
http://localhost:8000/block/{height}
Example
http://localhost:8000/block/3