项目作者: jsbravoc

项目描述 :
Express.js API to manage a cryptocurrency inside a consortium or private blockchain using Hyperledger Sawtooth
高级语言: JavaScript
项目地址: git://github.com/jsbravoc/cryptocurrency.git
创建时间: 2021-02-23T17:49:01Z
项目社区:https://github.com/jsbravoc/cryptocurrency

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Cryptocurrency



GitHub Repo stars
Build status
Coverage
License
Docker build


Screenshots









Swagger UI API Swagger UI API



Hyperledger Sawtooth blockchain application to handle a private cryptocurrency, featuring:

  • Transaction input validation to keep the cryptocurrency flow coherent (All non-coinbase transactions must be supported by another transaction).
  • Pending transactions, such as a money transfer request from one user to another.
  • User roles and permissions to use the cryptocurrency. For instance, coinbase permission to allow the creation of a coinbase (no input) transaction.
  • Transaction tracking. Any transaction with corresponding input can be tracked down till the coinbase transaction. (Used to understand the flow and provenance of the cryptocurrency, thus avoiding its misuse).
  • Transaction security. The API verifies the transaction & users’ signatures in order to verify integrity and non-repudiation.

Components

This projects contains the following components, required to launch the application.

  • crypto-api - Express.js application which provides HTTP(S) JSON API to manage the cryptocurrency.

  • crypto-tp - Node.js application that handles the logic of the transactions between crypto-api and Hyperledger Sawtooth’s REST API.

Requirements

This project requires git, Docker, npm, and Node.js <=10.23.3*.

* Both crypto-api & crypto-tp projects use sawtooth-sdk^1.0.5, which internally uses zeromq^4.2.1. Unfortunately, zeromq^4.2.1 breaks on Node.js 11+.

Installation & Usage

This application uses Docker, used to simplify the installation and deployment of the whole application. Although the application can be started by using Node.js (i.e node index.js), Sawtooth’s components (the validator, the REST API, etc) are started using Docker directly.

Alternative 1: Using Docker directly

In order to start the project using Docker, you will need to download the docker-compose.yaml file available at the root of the repository. You can also clone the repository and access the document.

  1. git clone https://github.com/jsbravoc/cryptocurrency.git
  2. cd cryptocurrency

1) Starting the application

To start the whole application, you need to start the containers and dependencies of the docker-compose.yaml file, by executing:

  1. docker-compose up #Use -d flag to start it detached

Then, the application will be started at the port mapped in the docker-compose.yaml file, by default http://localhost:3000.

2) Stopping the application

To pause the execution of the application, you need to execute the following command:

  1. docker-compose pause

Please note that if you paused the application on Docker, the correct way to start it up again is:

  1. docker-compose unpause

Moreover, if you want to stop the project and delete all of its contents, you can execute:

  1. docker-compose down

Alternative 2: Cloning the project

1) Downloading the project

In order to download the project and start it locally, you need to clone this repository and go to the root directory of the project:

  1. git clone https://github.com/jsbravoc/cryptocurrency.git
  2. cd cryptocurrency

2) Starting up the application

Once Docker is installed and you’ve cloned this repo, navigate to the root directory of the project and run:

  1. cd blockchain_network/docker-compose-dev/sawtooth
  2. docker-compose up

Then, you need to install transaction_processor node dependencies and start it:

  1. cd build/app/transaction_processor
  2. npm install
  3. npm start # or pm2 start

Finally, you need to install backend node dependencies and start it:

  1. cd build/app/backend
  2. npm install
  3. npm start # or pm2 start if using PM2

Optionally, if you want to see the API definitions, make sure to go to localhost:3000/api-docs or to the URL of where the application was started.

3) Stopping the application

In order to stop the application you need to send SIGINT to the running processes. Therefore, you should use ^C (Ctrl + C) on the terminals running any component of the application. If you are using PM2, then run:

  1. pm2 stop crypto-api
  2. pm2 stop crypto-tp

To pause the blockchain network on Docker, execute the following command:

  1. cd blockchain_network/docker-compose-dev/sawtooth
  2. docker-compose pause

Please note that if you paused the blockchain network on Docker, the correct way to start it up again is:

  1. cd blockchain_network/docker-compose-dev/sawtooth
  2. docker-compose unpause

Moreover, if you want to stop the blockchain network and delete all of its contents, you can execute:

  1. cd blockchain_network/docker-compose-dev/sawtooth
  2. docker-compose down

Development & Testing

Front-end integration:

This application has been tested successfully with a front-end project that uses Metamask in order to sign the transactions with the public/private key pair. However, if you want to use it without Metamask, be sure to read Metamask’s signature implementation (namely Ethereum’s eth_sign function) (See getSignature function in test/cryptocurrency) and sign the transactions in the same manner.

Recommended readings:

Development:

In order to understand the functions used inside the backend component, please access to localhost:3000/docs or to the URL of where the application was started. There you will find the JS documentation of all the code.

Testing:

Recommendation: Avoid integrity errors by editing .env file, setting DISABLE_INTEGRITY_VALIDATION=true. By doing this, the transaction’s signature will not be validated. Note that if the variable is set to false, transactions’ signatures must be verifiable with the corresponding user’s public_key.

Also, if you want to test the application directly, please go to localhost:3000/api-docs or to the URL of where the application was started. There, you will find a Swagger UI application to test the API and see the API definitions.

Contributing:

In order to develop and contribute to this repository, make sure to run the tests of the API before creating a pull request:

1) Start the blockchain network:

  1. cd blockchain_network/docker-compose-dev/sawtooth
  2. docker-compose up #Use -d flag to start it detached

2) Start the transaction processor:

  1. cd src/app/transaction_processor
  2. npm start # or pm2 start if using PM2

3) Run the tests:

  1. cd src/app/backend
  2. npm test

Contributors

Juan Sebastián Bravo

License

BSD-3-Clause License © Juan Sebastián Bravo

  1. BSD 3-Clause License
  2. Copyright (c) 2021, Juan Sebastián Bravo Castelo
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice, this
  7. list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. 3. Neither the name of the copyright holder nor the names of its
  12. contributors may be used to endorse or promote products derived from
  13. this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  18. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  20. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.