HyperLedgr deployment, initializing the network.

Keywords: Blockchain network Docker Javascript

start

Check the prerequisites of the platform in order to successfully develop blockchain products. Installation prerequisites, click the link: Precondition. For more details, click: more details.

List of prerequisites

  • The latest version of git

  • The latest version of curl

  • Any version of wget

  • Docker and docker compose
    docker --version requires

  • Go environment settings

  • Node.js environment settings (including npm)

  • Python

Install sample, binary, and Docker images

Download the source file according to the script and store it in bin folder. Finally, the script will download the latest Hyperledger Fabric Docker from Docker Hub and mirror it to the local Docker registry

Test the correctness of the installation environment

Before the start

Confirm the success of the installation example in the second chapter

Start test network

cd fabric-samples/test-network
Enable. / network.sh -h to view the usage of test network build script

1.Usage:
2.  network.sh <Mode> [Flags]
3.    <Mode>
4.      - 'up' - bring up fabric orderer and peer nodes. No channel is created
5.      - 'up createChannel' - bring up fabric network with one channel
6.      - 'createChannel' - create and join a channel after the network is created
7.      - 'deployCC' - deploy the fabcar chaincode on the channel
8.      - 'down' - clear the network with docker-compose down
9.      - 'restart' - restart the network
10.
11.    Flags:
12.    -ca <use CAs> -  create Certificate Authorities to generate the crypto material
13.    -c <channel name> - channel name to use (defaults to "mychannel")
14.    -s <dbtype> - the database backend to use: goleveldb (default) or couchdb
15.    -r <max retry> - CLI times out after certain number of attempts (defaults to 5)
16.    -d <delay> - delay duration in seconds (defaults to 3)
17.    -l <language> - the programming language of the chaincode to deploy: go (default), javascript, or java
18.    -v <version>  - chaincode version. Must be a round number, 1, 2, 3, etc
19.    -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
20.    -verbose - verbose mode
21.  network.sh -h (print this message)
22.
23. Possible Mode and flags
24.  network.sh up -ca -c -r -d -s -i -verbose
25.  network.sh up createChannel -ca -c -r -d -s -i -verbose
26.  network.sh createChannel -c -r -d -verbose
27.  network.sh deployCC -l -v -r -d -verbose
28.
29. Taking all defaults:
30.    network.sh up
31.
32. Examples:
33.  network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0-beta
34.  network.sh createChannel -c channelName
35.  network.sh deployCC -l javascript

When using this script network.sh up, no one channel will be generated (only two organizations and one sorting node will be created)
The docker ps -a command displays several nodes created on the current computer (3)

Create channel

Use scripts to create Fabric channels for transactions between Org1 and Org2. Different channels have different ledger books;. / neteork.sh createChannel -c channelName

Deployment chain code

./network.sh deployCC -l javascript
init will initialize the smart contract content and call the chain code to write the initialized data into the ledger

  • Query all account information
    The environment variable configuration of Org1 needs to be changed when querying the environment configuration of Org2
1.# Environment variables for Org1
2.
3.export CORE_PEER_TLS_ENABLED=true
4.# Change Org2MSP
5.export CORE_PEER_LOCALMSPID="Org1MSP"
6.# change org2.example.com && peer0.org2.example.com
7.export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
8.# change org2.example.com && Admin@org1.example.com
9.export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
10.export CORE_PEER_ADDRESS=localhost:7051

peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'

  • Change of capital on account
    peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls true --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"changeCarOwner","Args":["CAR9","Dave"]}'
    --Peeraddress localhost: 7051 indicates the address of Org1
    --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt indicates the private key address of Org1
    --Peeraddress localhost: 9051 indicates the address of Org2
    --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt indicates the private key address of Org2
    "The command is too long. Please use the sdk in fabcar to edit the code change."

  • Close the network
    . / network.sh down this command will stop and delete nodes, chain code containers, organization keys, chain code images, channels, and dock volumes in the Docker registry.

Starting the network with a certification authority

The Hyperledger structure uses the public key infrastructure (PKI). Before creating peer-to-peer nodes and sorting nodes, all the encryption materials needed to deploy and operate the network must be created: nodes, network administrators, and users who submit transactions need public certificates and private keys to verify their identities.
By default, the certificate and key are created by using the Crptogen tool. The creation process is as follows

/Usr/fabric-samples/test-network/../bin/cryptogen
##########################################################
############ Create Org1 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
+ set +x
##########################################################
############ Create Org2 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
+ set +x
##########################################################
############ Create Orderer Org Identities ###############
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
+ set +x

summary

  • certificate
    organizations/cryptogen do not know how to use CA in production environment

  • Genesis block
    configtx/configtx.yaml is the configuration file of the creation block

  • Create channel
    configtx.yaml is the configuration file of the channel

Posted by VagabondKites on Sun, 23 Feb 2020 23:52:41 -0800