Fabric启动网络日志和示例代码解析
一、启动第一个网络
./byfn.sh -m up -c testchannel -i 1.0.0
-i 参数指定版本,不指定默认latest,会自动拉取 fabric-tools、fabric-ccenv、fabric-orderer、fabric-peer的latest最新镜像
过程时间有点长。。。
[root@chow first-network]# ./byfn.sh -m up -c testchannel -i 1.0.0 Starting with channel 'testchannel' and CLI timeout of '10' Continue (y/n)? y proceeding ... /root/go/bin/cryptogen ########################################################## ##### Generate certificates using cryptogen tool ######### ########################################################## org1.example.com org2.example.com /root/go/bin/configtxgen ########################################################## ######### Generating Orderer Genesis block ############## ########################################################## 2020-04-15 11:19:57.094 CST [common/configtx/tool] main -> INFO 001 Loading configuration 2020-04-15 11:19:57.110 CST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block 2020-04-15 11:19:57.111 CST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block ################################################################# ### Generating channel configuration transaction 'channel.tx' ### ################################################################# 2020-04-15 11:19:57.119 CST [common/configtx/tool] main -> INFO 001 Loading configuration 2020-04-15 11:19:57.122 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx 2020-04-15 11:19:57.123 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx ################################################################# ####### Generating anchor peer update for Org1MSP ########## ################################################################# 2020-04-15 11:19:57.131 CST [common/configtx/tool] main -> INFO 001 Loading configuration 2020-04-15 11:19:57.136 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update 2020-04-15 11:19:57.136 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update ################################################################# ####### Generating anchor peer update for Org2MSP ########## ################################################################# 2020-04-15 11:19:57.144 CST [common/configtx/tool] main -> INFO 001 Loading configuration 2020-04-15 11:19:57.147 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update 2020-04-15 11:19:57.148 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update Creating network "net_byfn" with the default driver Creating volume "net_orderer.example.com" with default driver Creating volume "net_peer0.org1.example.com" with default driver Creating volume "net_peer1.org1.example.com" with default driver Creating volume "net_peer0.org2.example.com" with default driver Creating volume "net_peer1.org2.example.com" with default driver Creating peer1.org1.example.com ... done Creating peer0.org2.example.com ... done Creating peer1.org2.example.com ... done Creating peer0.org1.example.com ... done Creating orderer.example.com ... done Creating cli ... done # 这里网络已经启动起来了 ____ _____ _ ____ _____ / ___| |_ _| / \ | _ \ |_ _| \___ \ | | / _ \ | |_) | | | ___) | | | / ___ \ | _ < | | |____/ |_| /_/ \_\ |_| \_\ |_| Build your first network (BYFN) end-to-end test
# 创建通道 Channel name : testchannel Creating channel... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 2020-04-15 03:20:01.961 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:01.961 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:01.965 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:01.966 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP 2020-04-15 03:20:01.966 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity 2020-04-15 03:20:01.966 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP 2020-04-15 03:20:01.966 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity 2020-04-15 03:20:01.966 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A8C060A074F7267314D53501280062D...53616D706C65436F6E736F727469756D 2020-04-15 03:20:01.966 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: BEED1ABDD52A837CB3FC6E979BC200CFBC7BF706B07B5927FA585A0A3309DA81 2020-04-15 03:20:01.966 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP 2020-04-15 03:20:01.966 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity 2020-04-15 03:20:01.966 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP 2020-04-15 03:20:01.966 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity 2020-04-15 03:20:01.966 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC5060A1708021A0608E1FAD9F40522...26B9311913798C83AA429BC0664CFEDB 2020-04-15 03:20:01.966 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 88A5B3ABDFF60E74A44E41B22E844F9F80531F4E7A292554493F8E23B679A30B 2020-04-15 03:20:02.069 UTC [msp] GetLocalMSP -> DEBU 010 Returning existing local MSP 2020-04-15 03:20:02.069 UTC [msp] GetDefaultSigningIdentity -> DEBU 011 Obtaining default signing identity 2020-04-15 03:20:02.069 UTC [msp] GetLocalMSP -> DEBU 012 Returning existing local MSP 2020-04-15 03:20:02.069 UTC [msp] GetDefaultSigningIdentity -> DEBU 013 Obtaining default signing identity 2020-04-15 03:20:02.069 UTC [msp/identity] Sign -> DEBU 014 Sign: plaintext: 0AC5060A1708021A0608E2FAD9F40522...20B1BCA5820A12080A021A0012021A00 2020-04-15 03:20:02.069 UTC [msp/identity] Sign -> DEBU 015 Sign: digest: AA9D9813F45975C843787C627D7B22FE71DCAA18E85A3D7BAE386F1A9BE853BE 2020-04-15 03:20:02.072 UTC [channelCmd] readBlock -> DEBU 016 Got status:*orderer.DeliverResponse_Status 2020-04-15 03:20:02.072 UTC [msp] GetLocalMSP -> DEBU 017 Returning existing local MSP 2020-04-15 03:20:02.072 UTC [msp] GetDefaultSigningIdentity -> DEBU 018 Obtaining default signing identity 2020-04-15 03:20:02.113 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized 2020-04-15 03:20:02.314 UTC [msp] GetLocalMSP -> DEBU 01a Returning existing local MSP 2020-04-15 03:20:02.314 UTC [msp] GetDefaultSigningIdentity -> DEBU 01b Obtaining default signing identity 2020-04-15 03:20:02.314 UTC [msp] GetLocalMSP -> DEBU 01c Returning existing local MSP 2020-04-15 03:20:02.314 UTC [msp] GetDefaultSigningIdentity -> DEBU 01d Obtaining default signing identity 2020-04-15 03:20:02.314 UTC [msp/identity] Sign -> DEBU 01e Sign: plaintext: 0AC5060A1708021A0608E2FAD9F40522...FD4A4931750712080A021A0012021A00 2020-04-15 03:20:02.314 UTC [msp/identity] Sign -> DEBU 01f Sign: digest: 80EFBF9DEDB6B6ABA35CC0EF3FB55072831BDB346CFDEBF2FF6AD587D2864766 2020-04-15 03:20:02.319 UTC [channelCmd] readBlock -> DEBU 020 Received block:0 2020-04-15 03:20:02.319 UTC [main] main -> INFO 021 Exiting..... ===================== Channel "testchannel" is created successfully =====================
# 让所有的peer节点接入通道中 Having all peers join the channel...
# 组织一的peer0节点 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 2020-04-15 03:20:02.390 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:02.390 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:02.397 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:02.397 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C08E2FAD9F40510...62E6F682FBBC1A080A000A000A000A00 2020-04-15 03:20:02.397 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: CC19D64DD764B0F731FEEF966DAC12F5F166F7D67048FDDFAE3FC99A26C10087 2020-04-15 03:20:02.438 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel! 2020-04-15 03:20:02.438 UTC [main] main -> INFO 007 Exiting..... ===================== PEER0 joined on the channel "testchannel" =====================
# 组织一的peer1节点 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer1.org1.example.com:7051 2020-04-15 03:20:05.508 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:05.508 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:05.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:05.511 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C08E5FAD9F40510...62E6F682FBBC1A080A000A000A000A00 2020-04-15 03:20:05.512 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: C111FC3CFA742F9360346FA497F961F03ACDCADDC6DD0822F145FA6FB73F4803 2020-04-15 03:20:05.551 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel! 2020-04-15 03:20:05.551 UTC [main] main -> INFO 007 Exiting..... ===================== PEER1 joined on the channel "testchannel" =====================
# 组织二的peer0节点 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org2.example.com:7051 2020-04-15 03:20:08.619 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:08.620 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:08.623 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:08.623 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C08E8FAD9F40510...62E6F682FBBC1A080A000A000A000A00 2020-04-15 03:20:08.623 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 7A8119722275F216212A54E4FE5BFD7CC575935FFAD4AA12DFA5E4A74766231E 2020-04-15 03:20:08.642 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel! 2020-04-15 03:20:08.642 UTC [main] main -> INFO 007 Exiting..... ===================== PEER2 joined on the channel "testchannel" =====================
# 组织二的peer1节点 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer1.org2.example.com:7051 2020-04-15 03:20:11.707 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:11.707 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:11.710 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:11.711 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C08EBFAD9F40510...62E6F682FBBC1A080A000A000A000A00 2020-04-15 03:20:11.711 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: C2E76BC93FBAEEFDA61BC1F6609B52FE9DD6FDDBA7D7F2FBF513857F047A65C5 2020-04-15 03:20:11.733 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel! 2020-04-15 03:20:11.733 UTC [main] main -> INFO 007 Exiting.....
# 以上4个节点都已经成功加入了testchannel通道中 ===================== PEER3 joined on the channel "testchannel" =====================
# 更新组织一的锚节点信息 Updating anchor peers for org1... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # 组织一的锚节点信息设置的是peer0 2020-04-15 03:20:14.794 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:14.794 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:14.797 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:14.799 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP 2020-04-15 03:20:14.799 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity 2020-04-15 03:20:14.799 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP 2020-04-15 03:20:14.799 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity 2020-04-15 03:20:14.799 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A8C060A074F7267314D53501280062D...2A0641646D696E732A0641646D696E73 2020-04-15 03:20:14.799 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 28367A5EBD381DEA1199AB5A799EA6686A7ED1FBC0D1CF4C5194FBA946855AB7 2020-04-15 03:20:14.799 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP 2020-04-15 03:20:14.799 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity 2020-04-15 03:20:14.799 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP 2020-04-15 03:20:14.799 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity 2020-04-15 03:20:14.799 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC5060A1708021A0608EEFAD9F40522...4A982386A5E0D7F4AAF025E972A3FED2 2020-04-15 03:20:14.799 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 4D76BAEE68C0E9F348D4E5960F0A0A95F752569EE95128DAB6D43A78D23F2289 2020-04-15 03:20:14.821 UTC [main] main -> INFO 010 Exiting..... ===================== Anchor peers for org "Org1MSP" on "testchannel" is updated successfully =====================
# 更新组织二的锚节点信息 Updating anchor peers for org2... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org2.example.com:7051 # 组织二的锚节点设置的也是peer0 2020-04-15 03:20:17.879 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:17.879 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:17.882 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2020-04-15 03:20:17.883 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP 2020-04-15 03:20:17.883 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity 2020-04-15 03:20:17.883 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP 2020-04-15 03:20:17.883 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity 2020-04-15 03:20:17.883 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A8C060A074F7267324D53501280062D...2A0641646D696E732A0641646D696E73 2020-04-15 03:20:17.883 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 4CF729B0CA68D3F106B711E15A346818AA2EF47AF4E79C28D5795B3C1F0D3EF7 2020-04-15 03:20:17.883 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP 2020-04-15 03:20:17.883 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity 2020-04-15 03:20:17.883 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP 2020-04-15 03:20:17.883 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity 2020-04-15 03:20:17.883 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC5060A1708021A0608F1FAD9F40522...E4D2EB1BBD5C7751A9C21ED408A9C175 2020-04-15 03:20:17.883 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 37860D85F39D90AEA5A5705E21569E1837A8CF943ABE00FAE63115849AF25BD5 2020-04-15 03:20:17.900 UTC [main] main -> INFO 010 Exiting..... ===================== Anchor peers for org "Org2MSP" on "testchannel" is updated successfully =====================
#安装chaincode
# 1.在组织一的peer0上安装链码 Installing chaincode on org1/peer0... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 2020-04-15 03:20:20.968 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:20.968 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:20.968 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:20:20.968 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:20:21.145 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 2020-04-15 03:20:21.682 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package fmt 2020-04-15 03:20:21.682 UTC [golang-platform] func1 -> DEBU 007 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim 2020-04-15 03:20:21.682 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/protos/peer 2020-04-15 03:20:21.682 UTC [golang-platform] func1 -> DEBU 009 Discarding GOROOT package strconv 2020-04-15 03:20:21.682 UTC [golang-platform] GetDeploymentPayload -> DEBU 00a done 2020-04-15 03:20:21.683 UTC [msp/identity] Sign -> DEBU 00b Sign: plaintext: 0A8A070A5C08031A0C08F5FAD9F40510...5F74FD270000FFFFCEF44F9B002C0000 2020-04-15 03:20:21.683 UTC [msp/identity] Sign -> DEBU 00c Sign: digest: 6A9FA634FB45A50761363C097D13695D6D3A464D7E0697459EA9B0D61E224487 2020-04-15 03:20:21.686 UTC [chaincodeCmd] install -> DEBU 00d Installed remotely response:<status:200 payload:"OK" > 2020-04-15 03:20:21.686 UTC [main] main -> INFO 00e Exiting..... ===================== Chaincode is installed on remote peer PEER0 =====================
# 2.在组织二的peer0安装chaincode Install chaincode on org2/peer2... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org2.example.com:7051 2020-04-15 03:20:21.727 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:21.727 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:21.727 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:20:21.728 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:20:21.781 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 2020-04-15 03:20:21.917 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package fmt 2020-04-15 03:20:21.917 UTC [golang-platform] func1 -> DEBU 007 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim 2020-04-15 03:20:21.917 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/protos/peer 2020-04-15 03:20:21.917 UTC [golang-platform] func1 -> DEBU 009 Discarding GOROOT package strconv 2020-04-15 03:20:21.917 UTC [golang-platform] GetDeploymentPayload -> DEBU 00a done 2020-04-15 03:20:21.918 UTC [msp/identity] Sign -> DEBU 00b Sign: plaintext: 0A8A070A5C08031A0C08F5FAD9F40510...5F74FD270000FFFFCEF44F9B002C0000 2020-04-15 03:20:21.918 UTC [msp/identity] Sign -> DEBU 00c Sign: digest: 36691F9891F352C079072734A278CDFF3BF34AFE79DB54070A64F1CA0A7ABC3B 2020-04-15 03:20:21.921 UTC [chaincodeCmd] install -> DEBU 00d Installed remotely response:<status:200 payload:"OK" > 2020-04-15 03:20:21.921 UTC [main] main -> INFO 00e Exiting..... ===================== Chaincode is installed on remote peer PEER2 ===================== #### 接下来是对只能合约的初始化 (实例化链码) # 组织二的peer0上实例化链码
Instantiating chaincode on org2/peer2... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org2.example.com:7051 2020-04-15 03:20:21.963 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:21.963 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:21.966 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:20:21.966 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:20:21.966 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A97070A6908031A0C08F5FAD9F40510...324D53500A04657363630A0476736363 2020-04-15 03:20:21.966 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 9F5AC6F2A37D236AFEDD89FD4DE0273E2A6AEA96F8215269E8B7D19C79AFD27B 2020-04-15 03:20:54.608 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A97070A6908031A0C08F5FAD9F40510...FE2FC9C61115712ACBB8CBCA6D4C498C 2020-04-15 03:20:54.608 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: ABEDCCD914703BC70020549800B4CFF94A027C347C94A854342A33E16B1865B1 2020-04-15 03:20:54.627 UTC [main] main -> INFO 009 Exiting..... ===================== Chaincode Instantiation on PEER2 on channel 'testchannel' is successful =====================
# 安装完成后进行了一次查询操作 Querying chaincode on org1/peer0... ===================== Querying on PEER0 on channel 'testchannel'... ===================== 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 Attempting to Query PEER0 ...3 secs 2020-04-15 03:20:57.708 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:20:57.708 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:20:57.709 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:20:57.709 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:20:57.709 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A97070A6908031A0C0899FBD9F40510...6D7963631A0A0A0571756572790A0161 2020-04-15 03:20:57.709 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: A51EF02BAC4DB1F37FE8F91019C5F55DA2AA1949E050F5E4B43BAC6C0BF3408B # 查询结果是100
Query Result: 100 2020-04-15 03:21:18.027 UTC [main] main -> INFO 007 Exiting..... ===================== Query on PEER0 on channel 'testchannel' is successful ===================== # 做了一次交互(invoke)
Sending invoke transaction on org1/peer0... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org1MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer0.org1.example.com:7051 2020-04-15 03:21:18.118 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:21:18.118 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:21:18.158 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:21:18.158 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:21:18.158 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A96070A6808031A0B08AEFBD9F40510...696E766F6B650A01610A01620A023130 2020-04-15 03:21:18.158 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: A5087BAF3745F49BE8AB74DA7A272E473BE89945E2A5053E9E61C31F65EAB985 2020-04-15 03:21:18.166 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A96070A6808031A0B08AEFBD9F40510...063C1597715F71071E6689CB7CF56070 2020-04-15 03:21:18.166 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 82A71F269B43F875D374FFADEA5BD89DF497853836D5118F5603A75A1F43833E # 交互的返回结果
2020-04-15 03:21:18.170 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 009 ESCC invoke result: version:1 response:<status:200 message:"OK" > payload:"\n \261+\246\006\177\250\3769\262\213\242\337\363#$\325\325\327\005\307j\241\274@\001K\230\240V\351+\005\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement:<endorser:"\n\007Org1MSP\022\200\006-----BEGIN -----\nMIICGTCCAb+gAwIBAgIQa4kCpk2BEaXLLx29HRJBjzAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0yMDA0MTUwMzE0NTdaFw0zMDA0MTMwMzE0NTda\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVW0jkZs/4yAyVUh+yzgNboiDVkkqI9Nl\nRQvpn6KTSccStEDRukJ3QDrbEvOKXcK0AJn/FrRO1XC5oTBa/PuYkaNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgzCliw60dPP3X\nZm+Z2uNcolkEum/GEfscqbs8AGj2+TUwCgYIKoZIzj0EAwIDSAAwRQIhAITvG9FJ\nwWi1KcqCnFe8BW4YJI3VuoYvJs5/AIlkgVB1AiBRYptC+2MggENdbZhP5DjrUafz\ntjtNlBiMUR8dI8ODWQ==\n-----END -----\n" signature:"0D\002 B\342\212*\233\303\264Rh\256\300\333L4>T\206\005\301\204J/d`\261#\260*\270\310\316\017\002 \005w-1\022\245\312\202Im\036 0\364b\031\006<\025\227q_q\007\036f\211\313|\365`p" > 2020-04-15 03:21:18.170 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200 2020-04-15 03:21:18.170 UTC [main] main -> INFO 00b Exiting..... ===================== Invoke transaction on PEER0 on channel 'testchannel' is successful =====================
# 3.组织二的peer1上安装链码 Installing chaincode on org2/peer3... 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer1.org2.example.com:7051 2020-04-15 03:21:18.241 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:21:18.241 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:21:18.241 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:21:18.241 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:21:18.351 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 2020-04-15 03:21:18.629 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package fmt 2020-04-15 03:21:18.629 UTC [golang-platform] func1 -> DEBU 007 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim 2020-04-15 03:21:18.629 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/protos/peer 2020-04-15 03:21:18.629 UTC [golang-platform] func1 -> DEBU 009 Discarding GOROOT package strconv 2020-04-15 03:21:18.630 UTC [golang-platform] GetDeploymentPayload -> DEBU 00a done 2020-04-15 03:21:18.632 UTC [msp/identity] Sign -> DEBU 00b Sign: plaintext: 0A8A070A5C08031A0C08AEFBD9F40510...5F74FD270000FFFFCEF44F9B002C0000 2020-04-15 03:21:18.632 UTC [msp/identity] Sign -> DEBU 00c Sign: digest: 6F3BFF5DC883333C9BB05B0E54D923490D77524D80539EEB268844A62DD2680A 2020-04-15 03:21:18.646 UTC [chaincodeCmd] install -> DEBU 00d Installed remotely response:<status:200 payload:"OK" > 2020-04-15 03:21:18.646 UTC [main] main -> INFO 00e Exiting..... ===================== Chaincode is installed on remote peer PEER3 ===================== Querying chaincode on org2/peer3... ===================== Querying on PEER3 on channel 'testchannel'... ===================== 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 CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key CORE_PEER_LOCALMSPID=Org2MSP CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt CORE_PEER_TLS_ENABLED=true CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ID=cli CORE_LOGGING_LEVEL=DEBUG CORE_PEER_ADDRESS=peer1.org2.example.com:7051 Attempting to Query PEER3 ...3 secs 2020-04-15 03:21:21.721 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2020-04-15 03:21:21.721 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2020-04-15 03:21:21.721 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2020-04-15 03:21:21.722 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2020-04-15 03:21:21.722 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A97070A6908031A0C08B1FBD9F40510...6D7963631A0A0A0571756572790A0161 2020-04-15 03:21:21.722 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: C9C7EB93C9CC3951EB0C229D2DD37620DBFB11124016044B2CCAD20B09665CBB Query Result: 90 2020-04-15 03:21:43.064 UTC [main] main -> INFO 007 Exiting..... ===================== Query on PEER3 on channel 'testchannel' is successful ===================== ========= All GOOD, BYFN execution completed =========== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
二、启动网络生成的容器
1.启动网络生成的容器
docker ps -a
IMAGE COMMAND STATUS PORTS NAMES dev-peer1.org2.example.com-mycc-1.0 "chaincode -peer.add…" Up About an hour dev-peer1.org2.example.com-mycc-1.0 dev-peer0.org1.example.com-mycc-1.0 "chaincode -peer.add…" Up About an hour dev-peer0.org1.example.com-mycc-1.0 dev-peer0.org2.example.com-mycc-1.0 "chaincode -peer.add…" Up About an hour dev-peer0.org2.example.com-mycc-1.0 hyperledger/fabric-tools:x86_64-1.0.0 "/bin/bash -c './scr…" Exited (0) About an hour ago cli hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" Up About an hour 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com hyperledger/fabric-orderer:x86_64-1.0.0 "orderer" Up About an hour 0.0.0.0:7050->7050/tcp orderer.example.com hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" Up About an hour 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" Up About an hour 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com hyperledger/fabric-peer:x86_64-1.0.0 "peer node start" Up About an hour 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
2.容器说明
# orderer节点 orderer.example.com # 两个组织的4个peer节点 peer0.org1.example.com peer1.org1.example.com peer0.org2.example.com peer1.org2.example.com # 客户端,作用是远程连接到4个peer节点做一些链码安装、初始化等一些工作 cli # 三个链码,上面启动网络的时候,在这三个peer节点安装了链码 # Installing chaincode on org1/peer0... # Install chaincode on org2/peer2... # Installing chaincode on org2/peer3... dev-peer1.org2.example.com-mycc-1.0 dev-peer0.org1.example.com-mycc-1.0 dev-peer0.org2.example.com-mycc-1.0
3.链码生成的镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE dev-peer1.org2.example.com-mycc-1.0 latest 624cb0562a71 5 hours ago 173MB dev-peer0.org1.example.com-mycc-1.0 latest 3b5b98267854 5 hours ago 173MB dev-peer0.org2.example.com-mycc-1.0 latest bf2cb78b507d 5 hours ago 173MB
生成了三个镜像,虽然只有一个链码文件,但是在三个peer节点上安装了,因此生成三个镜像,因为这个网络是运行在同一台电脑上的,所以三个镜像都在这
链码名字:mycc
链码版本:1.0
4.链码文件的位置
fabric-samples/first-network/scripts/script.sh
installChaincode () { PEER=$1 setGlobals $PEER peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt res=$? cat log.txt verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed" echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== " echo }
位置:github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
进入cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
[root@chow chaincode_example02]# ll total 12 -rw-r--r--. 1 root root 5436 Apr 14 20:12 chaincode_example02.go -rw-r--r--. 1 root root 3165 Apr 14 20:12 chaincode_example02_test.go
5. chaincode_example02.go
[root@chow chaincode_example02]# cat chaincode_example02.go /* Copyright IBM Corp. 2016 All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main //WARNING - this chaincode's ID is hard-coded in chaincode_example04 to illustrate one way of //calling chaincode from a chaincode. If this example is modified, chaincode_example04.go has //to be modified as well with the new ID of chaincode_example02. //chaincode_example05 show's how chaincode ID can be passed in as a parameter instead of //hard-coding. import ( "fmt" "strconv" "github.com/hyperledger/fabric/core/chaincode/shim" pb "github.com/hyperledger/fabric/protos/peer" ) // SimpleChaincode example simple Chaincode implementation type SimpleChaincode struct { } # 初始化方法 func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { fmt.Println("ex02 Init")
# 获取参数 _, args := stub.GetFunctionAndParameters() var A, B string // Entities var Aval, Bval int // Asset holdings var err error # 如果参数个数不为4的话,报错 if len(args) != 4 { return shim.Error("Incorrect number of arguments. Expecting 4") } // Initialize the chaincode A = args[0] Aval, err = strconv.Atoi(args[1]) if err != nil { return shim.Error("Expecting integer value for asset holding") } B = args[2] Bval, err = strconv.Atoi(args[3]) if err != nil { return shim.Error("Expecting integer value for asset holding") } fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state to the ledger # 将A,B 的值存储到数据库中
err = stub.PutState(A, []byte(strconv.Itoa(Aval))) if err != nil { return shim.Error(err.Error()) } err = stub.PutState(B, []byte(strconv.Itoa(Bval))) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) } # invoke方法(交互) func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { fmt.Println("ex02 Invoke") function, args := stub.GetFunctionAndParameters()
# 设置了三个方法:invoke、delete、query if function == "invoke" { // Make payment of X units from A to B return t.invoke(stub, args) } else if function == "delete" { // Deletes an entity from its state return t.delete(stub, args) } else if function == "query" { // the old "Query" is now implemtned in invoke return t.query(stub, args) } return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"") } // Transaction makes payment of X units from A to B func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response { var A, B string // Entities var Aval, Bval int // Asset holdings var X int // Transaction value var err error # 接收3个参数 if len(args) != 3 { return shim.Error("Incorrect number of arguments. Expecting 3") } A = args[0] B = args[1] // Get the state from the ledger // TODO: will be nice to have a GetAllState call to ledger Avalbytes, err := stub.GetState(A) # 从数据库获取A的值 if err != nil { return shim.Error("Failed to get state") } if Avalbytes == nil { return shim.Error("Entity not found") } Aval, _ = strconv.Atoi(string(Avalbytes)) Bvalbytes, err := stub.GetState(B) # 从数据库获取B的值 if err != nil { return shim.Error("Failed to get state") } if Bvalbytes == nil { return shim.Error("Entity not found") } Bval, _ = strconv.Atoi(string(Bvalbytes)) // Perform the execution X, err = strconv.Atoi(args[2]) if err != nil { return shim.Error("Invalid transaction amount, expecting a integer value") } # 下面2行意思是 从A转账X给B
Aval = Aval - X Bval = Bval + X fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) // Write the state back to the ledger # 更新A和B在数据库中的值
err = stub.PutState(A, []byte(strconv.Itoa(Aval))) if err != nil { return shim.Error(err.Error()) } err = stub.PutState(B, []byte(strconv.Itoa(Bval))) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) } // Deletes an entity from state func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting 1") } # 接收一个值 A := args[0] // Delete the key from the state in ledger # 从数据库删掉
err := stub.DelState(A) if err != nil { return shim.Error("Failed to delete state") } return shim.Success(nil) } // query callback representing the query of a chaincode func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response { var A string // Entities var err error if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting name of the person to query") } A = args[0] // Get the state from the ledger Avalbytes, err := stub.GetState(A) if err != nil { jsonResp := "{\"Error\":\"Failed to get state for " + A + "\"}" return shim.Error(jsonResp) } if Avalbytes == nil { jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}" return shim.Error(jsonResp) } # 以json的形式返回 jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" fmt.Printf("Query Response:%s\n", jsonResp) return shim.Success(Avalbytes) } func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { fmt.Printf("Error starting Simple chaincode: %s", err) } }
init方法和invoke方法是编写链码的接口,只要实现了这两个接口,就代表了这是一个fabric智能合约,也就是链码