Demo of Multi-Channel Network in Hyperledger Fabric

Our commands will later be issued on Terminal.Those files created in Step 3.1 (in crypto-config directory) are copied to the corresponding containers.Those files created in Step 3.2 (in channel-artifacts directory) are copied to containers, and they are used for configure channel.Prepare Multiple TerminalsWe designate the three new terminals for Org1, Org2 and Org3.For Org1 (default)$ docker exec -it cli bashFor Org2 (specifying the environment variables for Org2)$ docker exec -e “CORE_PEER_LOCALMSPID=Org2MSP” -e “CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt” -e “CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp” -e “CORE_PEER_ADDRESS=peer0.org2.example.com:7051” -it cli bashFor Org3 (specifying the environment variables for Org3)$ docker exec -e “CORE_PEER_LOCALMSPID=Org3MSP” -e “CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt” -e “CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp” -e “CORE_PEER_ADDRESS=peer0.org3.example.com:7051” -it cli bashFor easy access, export this parameter ORDERER_CA in all three terminals.# export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pemHere are the three terminals, from top to bottom, for Org1, Org2 and Org3.Flow of Configuring ChannelsStep 5.1 ChannelAllCreate the channel block file (any Terminal)# peer channel create -o orderer.example.com:7050 -c channelall -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/channelall.tx — tls — cafile $ORDERER_CANow a file channelall.block is created.Join the three peers to this channel and update the anchor peer for each peer.Org1 Terminal# peer channel join -b channelall.block — tls — cafile $ORDERER_CA# peer channel update -o orderer.example.com:7050 -c channelall -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/Org1MSPanchors_channelall.tx — tls — cafile $ORDERER_CAOrg2 Terminal# peer channel join -b channelall.block — tls — cafile $ORDERER_CA# peer channel update -o orderer.example.com:7050 -c channelall -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/Org2MSPanchors_channelall.tx — tls — cafile $ORDERER_CAOrg3 Terminal# peer channel join -b channelall.block — tls — cafile $ORDERER_CA# peer channel update -o orderer.example.com:7050 -c channelall -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/Org3MSPanchors_channelall.tx — tls — cafile $ORDERER_CAStep 5.2: Channel12Create the channel block file (any Terminal)# peer channel create -o orderer.example.com:7050 -c channel12 -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/channel12.tx — tls — cafile $ORDERER_CANow a file channel12.block is created.Join the two peers to this channel and update the anchor peer for each peer.Org1 Terminal# peer channel join -b channel12.block — tls — cafile $ORDERER_CA# peer channel update -o orderer.example.com:7050 -c channel12 -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/Org1MSPanchors_channel12.tx — tls — cafile $ORDERER_CAOrg2 Terminal# peer channel join -b channel12.block — tls — cafile $ORDERER_CA# peer channel update -o orderer.example.com:7050 -c channel12 -f /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/Org2MSPanchors_channel12.tx — tls — cafile $ORDERER_CAStep 6: Install Simple Asset Chaincode (SACC)Now our network is up and running, ready for deploying chaincode.We are using the SACC coming with in the fabric-samples..Here is the chaincode:The logic of this chaincode is quite straight forward.When chaincode is instantiated, the Init() is executed..Two arguments are expected, which corresponding to a “key” and a “value”.This key/value pair is stored in the ledger (using PutState).After instantiated, transactions are handled by Invoke()..The parameter is composed of a function (or command) and argument(s).If function = set, two arguments are expected..it is either a brand-new key/value, or overrides the value if key exists..Function set() is called, and the result is stored in the ledger (using PutState)If function = anything (e.g. get), one argument is expected as key..Function get() is called..GetState is used to obtain the state from the ledger..If key exists then the value is returned..Otherwise it is shown “Asset not found”.By installing the chaincode, it loads the chaincode onto each peer..Note that chaincode is not yet useable until it is being instantiated.To install the chaincode, on each terminal,# peer chaincode install -n sacc -p github.com/chaincode/sacc -v 1.0We should see the last message as:Now all the the nodes have the chaincode installed..We are ready for instantiating this chaincode.Step 7: Instantiate and Interact with Chaincode on ChannelAllWe will first focus on ChannelAll.On Org1 Terminal, we instantiate the code on ChannelAll.# peer chaincode instantiate -o orderer.example.com:7050 — tls — cafile $ORDERER_CA -C channelall -c ‘{“Args”:[“a”, “100”]}’ -n sacc -v 1.0 -P “OR(‘Org1MSP.peer’, ‘Org2MSP.peer’, ‘Org3MSP.peer’)”We have set the initial key/value pair as a/100.. More details

Leave a Reply