Hyperledger Fabric V1.4.6 (a) manually Network Fabric structures (based on first-network)

  If you do not have a complete environment Hyperledger Fabric, refer to: Hyperledger Fabric (a) V2.0 base environment to build (the same applies to version V1.4, note the replacement Fabric binary image and the version number, see the bottom of this document). Fabric current latest version V2.0 bate Beta, if you want to build the latest version of Fabric network, please refer https:////www.cnblogs.com/always-kaixuan/p/12416157.html . Please note that the current version is still in beta V2.0, try by individuals, found that the deployment of java chain code has been given to try to resolve unsuccessful, so before the official version 2.0 has not been announced, it is recommended to deploy V1.4 + version. After have a basic environment, you can deploy the work of Fabric network. You can refer to the official website of the document on the part of first-network tutorials, script files using the supplied Quick Start block chain network. But in order to build a custom Fabric network, you need to understand the specific operation performed by the script.


first-network tutorial byfn.sh scripts as follows:

Usage:
byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-a] [-n] [-v]
<mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'
- 'up' - bring up the network with docker-compose up
- 'down' - clear the network with docker-compose down
- 'restart' - restart the network
- 'generate' - generate required certificates and genesis block
- 'upgrade' - upgrade the network from version 1.3.x to 1.4.0
-c <channel name> - channel name to use (defaults to "mychannel")
-t <timeout> - CLI timeout duration in seconds (defaults to 10)
-d <delay> - delay duration in seconds (defaults to 3)
-f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)
-s <dbtype> - the database backend to use: goleveldb (default) or couchdb
-l <language> - the chaincode language: golang (default) or node
-o <consensus-type> - the consensus-type of the ordering service: solo (default), kafka, or etcdraft
-i <imagetag> - the tag to be used to launch the network (defaults to "latest")
-a - launch certificate authorities (no certificate authorities are launched by default)
-n - do not deploy chaincode (abstore chaincode is deployed by default)
-v - verbose mode
byfn.sh -h (print this message)

Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:

byfn.sh generate -c mychannel
byfn.sh up -c mychannel -s couchdb
byfn.sh up -c mychannel -s couchdb -i 1.4.0
byfn.sh up -l node
byfn.sh down -c mychannel
byfn.sh upgrade -c mychannel

Taking all defaults:
byfn.sh generate
byfn.sh up
byfn.sh down

 

Use a script to start the network operates as follows:

① into the first-network directory

cd fabric-samples/first-network   

② network starts (the process comprising: starting container, to create a channel, the channel is added, updated node tissue anchor, chain code packing, installation chain code, instantiation chain code, call chain code)

./byfn.sh up -l node -o etcdraft -s couchdb # install node-language version of chaincode_example02 chain code, use the Raft ordering services rather than solo, enable couchdb database (supports rich query)

# ./Byfn.sh up -n -a -o etcdraft -s couchdb # chaincode_example02 chain code is not installed, enabled CA service, enable Raft ordering services rather than solo, enable couchdb database (supports rich query)

 

Equivalent manner as manual deployment Fabric network (enabled CAs, used couchdb):

Ⅰ use cryptogen generate a certificate and a key, placed under directory crypto-config

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

Use Ⅱ configtxgen tool assembly configured to generate 4 (genesis.block, channel.tx, Org1MSPanchors.tx, Org2MSPanchors.tx), placed under the directory channel-artifacts

① export FABRIC_CFG_PATH=$PWD

② configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block # generation system creation block, using the default sort solo, channelID is the name of the channel system

# Configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block # use Raft ordering service

③ export CHANNEL_NAME = mychannel # channels provided by the environment variable name

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $ CHANNEL_NAME # Create a channel configuration transaction channel.tx

Transaction Org1MSPanchors.tx anchor nodes ④ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $ CHANNEL_NAME -asOrg Org1MSP # Org1 create an update on the organization channel

Transaction Org2MSPanchors.tx Org2 anchor nodes configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $ CHANNEL_NAME -asOrg Org2MSP # Creating an update on the organization channel

Creating Ⅲ channel, the peer node joins the channel, and update the organization's anchor node

① docker-compose -f docker-compose-cli.yaml up -d   #不启用CA,不启动couchDB
#docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml up -d   启用couchdb

② docker exec -it cli bash # container into the CLI

Configure the environment variables, such that the container as a CLI peer0.org1.example.com Run node, subsequent operations require a lot of constantly switching the set environment variables to a different peer node to perform related operations, node peer0.org1.example.com environment variables default configuration cli container, peer0.org1.example.com environment variable as follows,

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

For ease of viewing, this node is given first while peer0.org2.example.com environment variables:

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS = peer0.org2.example.com: 9051
CORE_PEER_LOCALMSPID = "Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE = / opt / GOPATH / the src / github.com / hyperledger / Fabric / Use the peer / Crypto / peerOrganizations / org2.example.com / peers / peer0.org2.example.com / TLS / in ca.crt

③ the order transmission channel configuration transaction to the node to create channels

export CHANNEL_NAME = mychannel # Set the channel name in the form of environment variables for the command

peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

④ switching environment variables, repeatedly executing the following command will be added to all nodes channels

peer channel join -b mychannel.block

⑤ switching environment variables, repeatedly execute the following command to update the tissue anchor node

peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Ⅲ installation, examples of chain code (instantiation, node and java takes longer performed initor other transaction to cause actuation chain code of the container), to chain code chaincode_example02 Example

① switching environment variables, command repeatedly, the different nodes in the chain code installed

peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/ #Golang

peer chaincode install -n mycc -v 1.0 -l node -p /opt/gopath/src/github.com/chaincode/chaincode_example02/node/ #Node.js

peer chaincode install -n mycc -v 1.0 -l java -p /opt/gopath/src/github.com/chaincode/chaincode_example02/java/ #Java

②  switching environment variables, command repeatedly, examples of the chain code in different nodes

peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')" #Golang

peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -l node -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')" #Node.js

peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -l java -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')" #Java

③ inquiry key 'a' Value in the state database

peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

④ call 'invoke' function, a transfer to a 10 b

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'

Fabric default database for levelDB, levelDB support only to query the data by KEY, and couchdb support the use of rich queries, you can query based on an attribute of Value, marbles02 case chain code demonstrates how to use the rich query in this pair marbles02 case chain code test (using docker compose web container, add the yaml couchdb file corresponding to the remaining steps the same as above)

docker exec -it cli bash # container into the CLI

export CHANNEL_NAME = mychannel # channel name

① installation, examples of chain code (-l herein by mounting node and node instantiation chain code language version, default to go and go -p version chain code need only specify the relative path github.com/chaincode/marbles02/go) ( the endorsement policy designated "OR ( 'Org1MSP.peer', 'Org2MSP.peer')", so the installation and only in peer0.org1.example.com examples of chain code can)

peer chaincode install -n marbles -l node -v 1.0 -p /opt/gopath/src/github.com/chaincode/marbles02/node

peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -l node -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

② create some marbles and transferred them (you can enter in the browser http: // localhost: 5984 / _utils view couchdb database state)

peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}' peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["initMarble","marble2","red","50","tom"]}' peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["initMarble","marble3","blue","70","tom"]}' peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["transferMarble","marble2","jerry"]}' peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["transferMarblesBasedOnColor","blue","jerry"]}' peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n marbles -c '{"Args":["delete","marble1"]}'

③ inquiry

peer chaincode query -C $ CHANNEL_NAME -n marbles -c '{ "Args": [ "readMarble", "marble2"]}' # marbles by name query marble2

peer chaincode query -C $ CHANNEL_NAME -n marbles -c '{ "Args": [ "getHistoryForMarble", "marble1"]}' # specific search history marbles

peer chaincode query -C $ CHANNEL_NAME -n marbles -c '{ "Args": [ "queryMarblesByOwner", "jerry"]}' # may also perform queries on the data-rich content, such as queries by owner marbles

 

other:

① chain code upgrade: modified version, installed on the node chain code again:

peer chaincode install -n elecData -l node -v 1.1 -p /opt/gopath/src/github.com/chaincode/always/ElecData

Update command and instantiation commands substantially the same, simply to upgrade instantiate

peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n elecData -l node -v 1.1 -c '{"Args":["instantiate"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

 ② view the log:

docker logs -f cli # view the transaction information network through cli container logs

docker logs container chain code # View log command chain code format

③ FabricV1.4 JS chain code official website

https://hyperledger.github.io/fabric-chaincode-node/release-1.4/api/
https://github.com/hyperledger/fabric-chaincode-node/tree/v1.4.5
https://hyperledger.github.io/fabric-chaincode-node/

④ Fabric JS SDK1.4 official website
https://github.com/hyperledger/fabric-sdk-node
https://hyperledger.github.io/fabric-sdk-node/release-1.4/index.html

⑤ fabric-samples address: https: //github.com/hyperledger/fabric-samples

⑥ V1.4 binary files and image installation script command: curl -sSL http://bit.ly/2ysbOFE | bash -s - 1.4.6 1.4.6 0.4.18

Simple curl -sSL http://bit.ly/2ysbOFE | bash -s current version is always installed by default, so you need to specify a version number of 1.4

 

 

 

 

Guess you like

Origin www.cnblogs.com/always-kaixuan/p/12468374.html