项目作者: iluu

项目描述 :
Udacity Nanodegree - Blockchain Developer Project
高级语言: JavaScript
项目地址: git://github.com/iluu/blockchain_nanodegree.git
创建时间: 2018-12-20T23:11:03Z
项目社区:https://github.com/iluu/blockchain_nanodegree

开源协议:

下载


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:

  1. $ docker pull node:8.11.3
  2. $ docker run -p 8000:8000/tcp -d -it --name devtest -v "$(pwd)":/home node:8.9.0
  3. $ 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.

  1. $ curl -v http://localhost:8000/requestValidation \
  2. -H 'Content-Type: application/json' \
  3. -H 'cache-control: no-cache' \
  4. -d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs"}'

Response:

json { "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.

  1. $ curl -v http://localhost:8000/message-signature/validate \
  2. -H 'Content-Type: application/json' \
  3. -H 'cache-control: no-cache' \
  4. -d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs", "signature":"valid signature"}'

Response:

json { "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.

  1. curl -v http://localhost:8000/block \
  2. -H 'Content-Type: application/json' \
  3. -H 'cache-control: no-cache' \
  4. -d '{"address":"1EauidThcsXuEAXoWxT3DG5D9Y8KvM2CDs",
  5. "star": {
  6. "dec": "68° 52 56.9",
  7. "ra":"16h 29m 1.0s",
  8. "story":"Found star using https://www.google.com/sky/"
  9. }
  10. }'

Response

json { "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

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

GET /stars/address:[ADDRESS]

Returns a block by given wallet address

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

GET /block/[HEIGHT]

Returns a block of given height

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

GET /status

Returns validation status together with chain height

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

Response:

json { "chainHeight": 2, "valid": true }

Resources

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