Code Monkey home page Code Monkey logo

gorestledger's Introduction

gorestledger

GitHub last commit GitHub language count GitHub top language

N|Solid

GoRestLedger is a REST based API implementation written in Go language to demonstrate the Hyperledger Fabric Blockchain framework. The project repo has been designed to upload employee records into the blockchain and also has the functionality to update, delete the record stored securely in the Hyperledger framework.

However, this explanation guide does not explain how Hyperledger Fabric works, so for the information, you can follow at Hyperledger.

Installation

Employeeledger requires Docker & Go to run.

Docker

$ sudo apt install docker.io
$ sudo apt install docker-compose

Go

Installation

$ sudo apt-get update
$ sudo apt-get install golang-go

Set your Go path as environmental variable

add these following variable into the profile
$ export GOPATH=$HOME/go
$ export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
then
$ source ~/.profile
$ go version
$ go version go1.11 linux/amd64

Build Your Network

This sample Hyperledger Fabric blockchain network is built on a single organization consisting of two peer nodes. There are few prerequisites to follow to set up and install a blockchain network in the docker container.

Prerequisites
You can choose any of the following link based on you operating system and hardware architecture of your system.
Arch
Linux AMD 64
Linux s390x
Linux PPC64le
Windows AMD 64
Darwin AMD 64
Configuration

There are few configuration files is written, which composed of various configuration details of a network like Certificate Authority (CA), Peer , Orderer , CouchDB.

crypto-config.yaml

This configuration file will generate few certificates and key for the organization and it’s related entities like peers, admin, orderer. The cryptogen binary will take the config file as input and after execution, it will create a crypto-config folder in the config directory, which will contains all the generated certificates and key.

./bin/cryptogen generate --config=./crypto-config.yaml
configtx.yaml

This config file will contains complete details of a channel related to an organization. It will create three artifacts for a network.

  • orderer.genesis.block : This will initialize the Fabric’s orderer
      ./bin/configtxgen -profile GoRestLedger -outputBlock ./artifacts/orderer.genesis.block
    
  • gorestledger.channel.tx : Channel is a private network between peers to communicate in a network
      ./bin/configtxgen -profile GoRestLedger -outputCreateChannelTx ./artifacts/gorestledger.channel.tx -channelID gorestledger
    
  • org1.employeeledger.anchors.tx : This artifact will allow the peers to interact with each other in a network.
      ./bin/configtxgen -profile GoRestLedger -outputAnchorPeersUpdate ./artifacts/org1.gorestledger.anchors.tx -channelID gorestledger -asOrg GoRestLedgerOrganization1
    
You can find a shell script "config.sh" in the fixtures folder, it will generate all the prerequisites configurations of a network. So, you can directly execute script to skip all the manual steps.
Docker-Compose

Now, we need to deploy the configuration details into a docker container, so we need to use Docker Compose. There will docker-compose.yaml configuration file, which will contain all config details for Orderer, Certificate Authority, Peer, Couch DB.

  • The compose file can be deploy into a network, by executing following command

     docker-compose up -d // the docker-compose.yaml has to be located at same command location
    
And also replace the newly generated CA key, which can be found at crypto-config/peerOrganizations/org1.employee.ledger.com/ca/some random generated sk file, at the docker-compose.yaml : line 44, 50 & 55

So, all done , your blockchain network is now deployed into a docker container.

You can check by executing following command

docker ps

Dependency Issues

  1. Hyperledger fabric-sdk-go is still in development. If you do dep ensure for each Gopkg.toml in gorestledger and Chaincode, it will download the govendor folder for each module but it will have some compilation issues while building the project. I have corrected the error for both gorestledger and Chaincode folder.
  2. Please download the vendor folder and add it in your project repo.

    gorestledger - https://www.dropbox.com/s/ry1jmw0y9xliose/vendor.zip?dl=0

    Chaincode - https://www.dropbox.com/s/31nnqflpqwaywoa/vendor.zip?dl=0

  3. Add vendor folders at the location where Gopkg.toml file is located.

Run the application

  • As you have sucssefully deployed your blockchain network. Now you can run the application.
  • There is a master Makefile , you can find in the project root directory.
  • Just type “make” in the command line and it will take few minuetes to start the server.
  • If all goes well, you can see server running at port 4000
  • Now, you can use postman to test the APIs at http://localhost:6000

REST APIs end points

/api/user_register

POST

Request
{
    "name": "Alice McDonnell",
    "email": "[email protected]",
    "password": "Hello@123",
    "company": "Apple",
    "occupation": "Architect",
    "salary": "85,000",
    "userType": "Admin"
}
Response
{
    "id": "eDUwOTo6Q049YW5zaHVtYW4ucGF0dG5haWs1MjRAZ21haWwuY29tLE9VPXVzZXIrT1U9b3JnMTo6Q049Y2Eub3JnMS5nby5yZXN0LmxlZGdlci5jb20sTz1vcmcxLmdvLnJlc3QubGVkZ2VyLmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT",
    "name": "Alice McDonnell",
    "email": "[email protected]",
    "company": "Apple",
    "occupation": "Architect",
    "salary": "85,000",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE1NjExNTU5OTIsInVzZXIiOiJhbnNodW1hbi5wYXR0bmFpazUyNEBnbWFpbC5jb20ifQ.dIpTAgxnh-4lw06IQwX_bT4fhpvCUrwSZ7EnGVs46EE",
    "userType": "Admin"
}

/api/user_login

POST

Request
{
 "email": "[email protected]",
 "password": "Hello@456"
}
Response
{
    "id": "eDUwOTo6Q049YW5zaHVtYW4ucGF0dG5haWs1MjRAZ21haWwuY29tLE9VPXVzZXIrT1U9b3JnMTo6Q049Y2Eub3JnMS5nby5yZXN0LmxlZGdlci5jb20sTz1vcmcxLmdvLnJlc3QubGVkZ2VyLmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT",
    "name": "Alice McDonnell",
    "email": "[email protected]",
    "company": "Apple",
    "occupation": "Architect",
    "salary": "85,000",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE1NjExNTU5OTIsInVzZXIiOiJhbnNodW1hbi5wYXR0bmFpazUyNEBnbWFpbC5jb20ifQ.dIpTAgxnh-4lw06IQwX_bT4fhpvCUrwSZ7EnGVs46EE",
    "userType": "Admin"
}

/api/get_users

GET

Headers - (Token : token_value)
Response
list of user records 

/api/get_user

GET

Headers - (Token : token_value)
Request
{
    "email": "[email protected]"
}
Response
{
    "id": "eDUwOTo6Q049YW5zaHVtYW4ucGF0dG5haWs1MjRAZ21haWwuY29tLE9VPXVzZXIrT1U9b3JnMTo6Q049Y2Eub3JnMS5nby5yZXN0LmxlZGdlci5jb20sTz1vcmcxLmdvLnJlc3QubGVkZ2VyLmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT",
    "name": "Alice McDonnell",
    "email": "[email protected]",
    "company": "Apple",
    "occupation": "Architect",
    "salary": "85,000",
    "userType": "Admin"
}

/api/update_user

PUT

Headers - (Token : token_value)
Request
{
    "name": "Alice Wrick",
    "company": "Apple Computer",
    "occupation": "Architect Solution",
    "salary": "85,000",
    "userType": "Admin"
}
Response
{
    "id": "eDUwOTo6Q049YW5zaHVtYW4ucGF0dG5haWs1MjRAZ21haWwuY29tLE9VPXVzZXIrT1U9b3JnMTo6Q049Y2Eub3JnMS5nby5yZXN0LmxlZGdlci5jb20sTz1vcmcxLmdvLnJlc3QubGVkZ2VyLmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT",
    "name": "Alice Wrick",
    "email": "[email protected]",
    "company": "Apple Computer",
    "occupation": "Architect Solution",
    "salary": "85,000",
    "userType": "Admin"
}

/api/delete_user

DELETE

Headers - (Token : token_value)
Request
{
  "email": "[email protected]"
}
Response
{
    "success": "Succesfully delete the user with email - [email protected]"
}

/api/change_password

POST

Headers - (Token : token_value)
Request
{
    "email": "[email protected]",
    "userType": "User",
    "oldPassword": "Hello@123",
    "password": "Hello@456"
}
Response
{
    "success": "Password successfully changed for - [email protected]"
}

License

This project is licensed under the MIT License

gorestledger's People

Contributors

deeptiman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cyberjon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.