我使用的是Hyperledger Fabric 1.4.8
我已经使用以下命令部署了一个链码:
peer chaincode install -n davidcodeEndorseAnd -v vAlfaBeta1 -p github.com/chaincode/chaincode_example02/go/
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 mychannel -n davidcodeEndorseAnd -v vAlfaBeta1 -c '{"Args":["init","a","0","b","10000"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
背书参数:AND ('Org1MSP.peer','Org2MSP.peer').
当我尝试使用以下命令调用chaincode时,我得到一个200响应,但值没有更新:
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C mychannel -n davidcodeEndorseAnd -c '{"Args":["invoke","a","b","900"]}
执行输出:
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","a"]}'
0
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C mychannel -n davidcodeEndorseAnd -c '{"Args":["invoke","b","a","900"]}'
2021-07-28 19:55:55.757 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","a"]}'
0
注意:我正在使用织物样品的链码样品:/fabric-samples/chaincode/chaincode_example02/go
我尝试了以下调用命令,但没有成功:
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n davidcodeEndorseAnd --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles "/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --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","100"]}'
执行输出:
Error: error sending transaction for invoke: could not send: EOF - proposal response: version:1 response:<status:200 > payload:"n 14IU 17b3633522260301%347+ 32sv264s256232 04z 17251210 16347273354357356353 22221 01ng 22@n 23davidcodeEndorseAnd 22)n 07n 01a 22 02 10 16n 07n 01b 22 02 10 16 32tn 01a 32 04-100 32nn 01b 32 0510100 22#n 04lscc 22 33n 31n 23davidcodeEndorseAnd 22 02 10 16 32 03 10310 01"! 22 23davidcodeEndorseAnd 32nvAlfaBeta1" endorsement:<endorser:"n 07Org1MSP 22252 06-----BEGIN CERTIFICATE-----nMIICKDCCAc6gAwIBAgIQWdbqnSydfjum3L3K+6YISTAKBggqhkjOPQQDAjBzMQswnCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZynYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eunb3JnMS5leGFtcGxlLmNvbTAeFw0yMTA3MjgxNzU2MDBaFw0zMTA3MjYxNzU2MDBanMGoxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TnYW4gRnJhbmNpc2NvMQ0wCwYDVQQLEwRwZWVyMR8wHQYDVQQDExZwZWVyMC5vcmcxnLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkcU5Enp3gweinAM4r7IHPbIjaEI+AH+tM2teIZDHGJGDjeBtjA/vLSH2ngb/9H9DiG2agKmTHJsifnHxppCcUuJqNNMEswDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jnBCQwIoAgnaRyyHIgBgevWkF1kAgjunZH1joAPFpRTZ2gy+X2RLIwCgYIKoZIzj0EnAwIDSAAwRQIhAOyZZ+sdZg+S+HgyRqg7lO716OYc59/Yc9Iuabvs+h7ZAiBFIN2Jn3894dwxHteNaD9+FF6HNklKt9tWPnKdJ4szuOQ==n-----END CERTIFICATE-----n" signature:"0D 02 :252206j`345 217362:233330262313325201367245q331 14264 17Z3037 22J2762455n 02 t9227AW-M311 24200324242E300 26w 00enJN340253vR316*2042309Z202" >
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer#
我已经成功地更新了分类帐:
Org1下的执行输出:
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","a"]}'
-10
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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 mychannel -n davidcodeEndorseAnd --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","b","a","100"]}'
2021-07-28 20:17:56.431 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","a"]}'
90
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer#
Query Execution under Org2:
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","a"]}'
90
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n davidcodeEndorseAnd -c '{"Args":["query","b"]}'
9910
root@50179e3b3e32:/opt/gopath/src/github.com/hyperledger/fabric/peer#
问题是我错过了调用命令排序的以下参数:
--cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem