Skip to content

Udacity Nanodegree - Blockchain Developer Project

Notifications You must be signed in to change notification settings

iluu/blockchain_nanodegree

Repository files navigation

Project 4 - Private Blockchain Star Notary Service

Changes:

  • v1.0.2 - implemented star notary service
  • v1.0.1 - added REST API with HapiJS that allows adding new blocks and inspecting blockchain
  • v1.0.0 - simple private blockchain implementation with LevelDB

Setup project for Review

To setup the project for review do the following:

  1. Run npm install to install project dependencies
  2. Run npm test to run all functional tests
  3. Run npm start to run server with default configuration
  4. [Optional] Run scripts/apitest.sh to run a small client shell script (assumes jq is installed)

Alternatively, you could use Docker setup:

$ docker pull node:8.11.3
$ docker run -p 8000:8000/tcp -d -it --name devtest -v "$(pwd)":/home node:8.9.0
$ docker exec -it devtest /bin/bash

When in docker console, cd home and install project dependencies. Run tests and start the project using npm commands above.

Note: By default project is configured to run on localhost, but this does not work when using docker, change host to 0.0.0.0 in BlockApi.js file.

API Docs

POST /requestValidation

Creates a validation request for given wallet address. Returns message to be signed. Validation request expires after 5 minutes.

$ curl -v http://localhost:8000/requestValidation \
 -H 'Content-Type: application/json' \
 -H 'cache-control: no-cache' \
 -d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs"}'
Response:
{
  "walletAddress": "1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs",
  "requestTimeStamp": "1549489009",
  "message": "1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs:1549489009:starRegistry",
  "validationWindow": 300
}

POST /message-signature/validate

Allows to confirm ownership of the address by sending message signature. If signature is correct, user is allowed to register a star for a given address.

$ curl -v http://localhost:8000/message-signature/validate \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs", "signature":"valid signature"}'
Response:
{
  "registerStar": true,
  "status": {
    "address": "1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs",
    "requestTimeStamp": "1549489582",
    "message": "1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs:1549489582:starRegistry",
    "validationWindow": 276,
    "messageSignature": true
  }
}

POST /block

If wallet address was validated correctly, this method allows registering a single star entry. Returns newly created block as a confirmation.

curl -v http://localhost:8000/block \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs", 
     "star": {
         "dec": "68° 52 56.9",
         "ra":"16h 29m 1.0s",
         "story":"Found star using https://www.google.com/sky/"
         }
    }'
Response
{
  "hash": "7db2d65f888b51836d54ce9b81425cb1d8b43753ec1b8032010ac79a01dbdf63",
  "height": 1,
  "body": {
      "address": "1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs",
      "star": {
          "ra": "16h 29m 1.0s",
          "dec": "68° 52 56.9",
          "story": "466f756e642073746172207573696e672068747470733a2f2f7777772e676f6f676c652e636f6d2f736b792f"
      }
  },
  "time": "1549489959",
  "previousBlockHash": "e516c8a3872849dafa636b596e53456eb82bf048b8ce1e38fbde2d1ba6c0677c"
}

GET /stars/hash:[HASH]

Returns a block by given hash

$ curl -v http://localhost:8000/stars/hash:[HASH]

GET /stars/address:[ADDRESS]

Returns a block by given wallet address

$ curl -v http://localhost:8000/stars/address:[ADDRESS]

GET /block/[HEIGHT]

Returns a block of given height

$ curl -v http://localhost:8000/block/[HEIGHT]

GET /status

Returns validation status together with chain height

$ curl -v http://localhost:8000/block/[HEIGHT]
Response:
{
  "chainHeight": 2,
  "valid": true
}

Resources

  1. HapiJS
  2. Boom
  3. Joi
  4. HapiBook
  5. Testing Hapi
  6. Fake Timers in tests with Lolex

About

Udacity Nanodegree - Blockchain Developer Project

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published