项目作者: zornx

项目描述 :
Tutorial for Hyperledger Fabric Network using Hyperledger Composer and Hyperledger Explorer
高级语言:
项目地址: git://github.com/zornx/blockchain-hyperledger.git
创建时间: 2019-02-28T12:08:31Z
项目社区:https://github.com/zornx/blockchain-hyperledger

开源协议:

下载


Blockchain Hyperledger

Tutorial for Hyperledger Fabric Network (v1.3) using Hyperledger Composer (v2.0) and Hyperledger Explorer (v0.3.4)

Requirements

  • VirtualBox
  • Docker
  • Docker Compose
  • Node.js
  • NPM
  • GIT
  • Python

Notes

If installing Hyperledger Composer using Linux, be aware of the following advice:

  • Login as a normal user, rather than root.
  • Do not su to root.
  • When installing prerequisites, use curl, then unzip using sudo.
  • Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it’s actions are required to be run as root.
  • Do not use npm with sudo or su to root to use it.
  • Avoid installing node globally as root.**

Examples

  • config.json - Hyperledger Explorer config example
  • config_v0.3.4.json - Hyperledger Explorer config example (v0.3.4)
  • model.cto - Network models example

Instructions

Setup Environment

  1. $ sudo apt update && sudo apt upgrade
  2. $ sudo apt install git make gcc g++ libltdl-dev curl python pkg-config
  3. $ sudo apt update && sudo apt upgrade
  4. $ sudo apt install apt-transport-https ca-certificates curl software-properties-common
  5. $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  6. $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  7. $ sudo apt update
  8. $ sudo apt install docker-ce
  9. $ sudo systemctl status docker
  10. $ docker -v
  11. $ sudo su
  12. $ sudo groupadd docker
  13. $ sudo usermod -aG docker $USER
  14. $ su $USER
  15. $ sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  16. $ sudo chmod +x /usr/local/bin/docker-compose
  17. $ docker-compose -v
  18. $ wget https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz
  19. $ tar -xf node-v8.11.2-linux-x64.tar.xz
  20. $ mv node-v8.11.2-linux-x64/ node/
  21. $ echo 'export PATH=~/node/bin:$PATH' >> ~/.profile
  22. $ source .profile
  23. $ npm install -g npm
  24. $ npm install -g grpc
  25. $ node -v
  26. $ npm -v

Setup Hyperledger Composer

  1. $ npm install -g composer-cli@0.20
  2. $ npm install -g composer-rest-server@0.20
  3. $ npm install -g generator-hyperledger-composer@0.20
  4. $ npm install -g yo
  5. $ npm install -g composer-playground@0.20

Install Hyperledger Fabric Dev Servers

  1. $ mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers
  2. $ curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
  3. $ tar -xvf fabric-dev-servers.tar.gz
  4. $ cd ~/fabric-dev-servers
  5. $ export FABRIC_VERSION=hlfv12
  6. $ ./downloadFabric.sh

Install Hyperledger Fabric Binaries

  1. $ git clone https://github.com/hyperledger/fabric-samples.git
  2. $ cd fabric-samples
  3. $ curl -sSL http://bit.ly/2ysbOFE | bash -s 1.3.0
  4. $ echo 'export PATH=~/fabric-samples/bin:$PATH' >> ~/.profile
  5. $ source ~/.profile

Controlling your Dev Environment

  1. $ cd ~/fabric-dev-servers
  2. $ export FABRIC_VERSION=hlfv12 (Old version hlfv11)
  3. $ ./startFabric.sh
  4. $ docker ps
  5. $ ./createPeerAdminCard.sh
  6. $ ~/fabric-dev-servers/startFabric.sh

Check CouchDB: http://localhost:5984/_utils/#

Start the web app (“Playground”)

  1. $ composer-playground

Check Composer Playground: http://localhost:8080/login

Composer Setup Network

  1. $ yo hyperledger-composer:businessnetwork

Network Configuration:

  • Network Name: tutorial-network
  • License: Apache-2.0
  • Namespace: org.example.mynetwork
  • Empty Network: No
    Defining a business network
  • Modelling network (.cto file)
  • Defining JavaScript transaction logic (logic.js file)
  • Defining access control (permissions.acl)

Generate a business network archive

  1. $ cd tutorial-network
  2. $ composer archive create -t dir -n .

Deploying the business network

Note: Fabric network should be running (./startFabric.sh)

  1. $ cd tutorial-network
  2. $ composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna
  3. $ composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card
  4. $ composer card import --file networkadmin.card
  5. $ composer network ping --card admin@tutorial-network

Start Composer Playground

  1. $ composer-playground

Check Composer Playground: http://localhost:8080

Generating a REST server

  1. $ cd tutorial-network
  2. $ composer-rest-server

REST Server Configuration:

  • Card Name: admin@tutorial-network
  • Namespaces: Never Use
  • Secure the generated API with API Key: No
  • Enable authenticatio using Passport: No
  • Enable explorer test interface: Yes
  • Enable dynamic logging: No
  • Enable event publication over WebSockets: Yes
  • Enable TLS security: No
    Check REST API: http://localhost:3000/explorer/

Generating an Angular application

  1. $ cd tutorial-network
  2. $ yo hyperledger-composer:angular

Application Configuration (Change)

  • Connect to running business network: Yes
  • Enter standard package.json questions
  • Business network card: admin@tutorial-network
  • Select: Connect to an existing REST API
  • REST Server address: http://localhost
  • Server port: 3000
  • Select: Namespaces are not usednom

Run the application

Note: REST Server should be running

  1. $ cd angular-app
  2. $ npm start

Check Angular App: http://localhost:4200
Fix Error message: Invalid Host header

  • In node_modules/webpack-dev-server/lib/Server.js change:
    • “if(this.disableHostCheck) return true;” to “return true;”

Setup Hyperledger Explorer

Versions tested:

  • Latest - Not working
  • v0.3.7.1 - Not working
  • v0.3.7 - Not working
  • v0.3.6 - Not working
  • v0.3.5.1 - Working (Tests failed)
  • v0.3.5 - Working (Tests failed)
  • v0.3.4 - Working (Current used)
  • v0.3.3 - Working
  1. $ sudo apt update && sudo apt upgrade
  2. $ git clone --branch v0.3.4 https://github.com/hyperledger/blockchain-explorer.git

Install JQ (v1.5) (v1.6 not working)

  1. $ wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
  2. $ tar -xvzf jq-1.5.tar.gz
  3. $ cd jq-1.5
  4. $ ./configure && make && sudo make install
  5. $ jq --version

Install PostgreSQL

  1. $ sudo apt install postgresql postgresql-contrib
  2. $ sudo pg_createcluster 10 main --start
  3. $ psql --version

Start Hyperledger Fabric Network

  1. $ cd ~/fabric-dev-servers
  2. $ ./startFabric.sh

Configure PostgreSQL DB

  1. $ sudo -u postgres psql
  2. $ \i app/persistence/postgreSQL/db/explorerpg.sql
  3. $ \i app/persistence/postgreSQL/db/updatepg.sql
  4. $ \l
  5. $ \d
  6. $ \q

Configure Explorer

Save backup:

  1. $ cd blockchain-explorer/app/platform/fabric
  2. $ cp config.json config_backup.json

Check info:

  1. $ nano ~/fabric-dev-servers/DevServer_connection.json

Change on:

  1. $ cd blockchain-explorer/app/platform/fabric
  2. $ nano config.json

Add:
“channel”: “mychannel”,
“pg”: {
“host”: “127.0.0.1”,
“port”: “5432”,
“database”: “fabricexplorer”,
“username”: “hppoc”,
“passwd”: “password”
}

Run Explorer tests

Save backup:

  1. $ cd blockchain-explorer
  2. $ npm install
  3. $ npm audit fix
  4. $ cd app/test
  5. $ npm install
  6. $ npm audit fix
  7. $ npm run test
  8. $ cd ../../client
  9. $ npm install
  10. $ npm audit fix
  11. $ npm test -- -u --coverage

Fix error: getBlockActivity is not a function

Start/Stop Explorer

Save backup:

  1. $ cd blockchain-explorer
  2. $ ./start.sh
  3. $ ./stop.sh

Check Explorer: http://localhost:8080

References

https://hyperledger-fabric.readthedocs.io/en/release-1.4/

https://hyperledger.github.io/composer/latest/introduction/introduction.html

https://github.com/hyperledger/blockchain-explorer