我尝试在Hyperledger结构上创建应用。我在GO中编写了智能合约,并尝试使用nodejs脚本调用它。但要低于错误。
我遵循本教程:https://hyperledger-fabric.readthedocs.io/en/release-1.1/write_first_app.html#
node invoke.js
Store path:/home/vagrant/hyperledger/kyc-hyperledger/kyc-app/hfc-key-store
Successfully loaded user1 from persistence
Assigning transaction_id: bbad72223a50793f012bd76bd902a816807bde759e639dc6805db70aec41df4e
error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: 2 UNKNOWN: chaincode error (status: 500, message: Invalid Smart Contract function name.)
at new createStatusError (/home/vagrant/hyperledger/kyc-hyperledger/kyc-app/node_modules/fabric-client/node_modules/grpc/src/client.js:64:15)
at /home/vagrant/hyperledger/kyc-hyperledger/kyc-app/node_modules/fabric-client/node_modules/grpc/src/client.js:583:15
Transaction proposal was bad
Failed to send Proposal or receive valid response. Response null or status is not 200. exiting...
Failed to invoke successfully :: Error: Failed to send Proposal or receive valid response. Response null or status is not 200. exiting...
来自对等方的错误日志:
2018-05-16 15:52:31.399 UTC [endorser] ProcessProposal -> ERRO 03f [kyc-channel][bbad7222] simulateProposal() resulted in chaincode name:"kyc" response status 500 for txid: bbad72223a50793f012bd76bd902a816807bde759e639dc6805db70aec41df4e
来自invoke.js的请求
var request = {
//targets: let default to the peer assigned to the client
chaincodeId: 'kyc',
fcn: 'updateUser',
args: ['USER1','bengaluru'],
chainId: 'kyc-channel',
txId: tx_id
};
调用智能合约的功能:
if function == "queryUser" {
return s.queryUser(APIstub, args)
} else if function == "initLedger" {
return s.initLedger(APIstub)
}else if function == "updateUser" {
return s.updateUser(APIstub, args)
}
return shim.Error("Please provide valid SmartContract name")
}
任何人都可以帮助显示无效的智能合约功能名称。 我能够成功调用queryUser和initLedger函数。
当我试图直接从cli-container执行链码时,低于错误。
vagrant@fabric:~/hyperledger/kyc-hyperledger/kyc-app$ docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.abc.com/users/Admin@org1.abc.com/msp" cli peer chaincode query -C kyc-channel -n kyc -c '{"Args":["updateUser","USER1","bengaluru"]}'
2018-05-16 16:09:56.488 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-05-16 16:09:56.488 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-05-16 16:09:56.489 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-05-16 16:09:56.489 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-05-16 16:09:56.489 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-05-16 16:09:56.489 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0A9C070A6808031A0C08D4AFF1D70510...55534552310A0962656E67616C757275
2018-05-16 16:09:56.489 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 883983F39536F25CBD155CC2493328839EF5406F717A1B7F1632EE3515DE29EA
Error: Error endorsing query: rpc error: code = Unknown desc = chaincode error (status: 500, message: Invalid Smart Contract function name.) - <nil>
Usage:
peer chaincode query [flags]
Flags:
-C, --channelID string The channel on which this command should be executed
-c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
-x, --hex If true, output the query value byte array in hexadecimal. Incompatible with --raw
-n, --name string Name of the chaincode
-r, --raw If true, output the query value as raw bytes, otherwise format as a printable string
-t, --tid string Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64
Global Flags:
--cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
--certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
--clientauth Use mutual TLS when communicating with the orderer endpoint
--keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
--logging-level string Default logging level and overrides, see core.yaml for full syntax
-o, --orderer string Ordering service endpoint
--ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer.
--tls Use TLS when communicating with the orderer endpoint
--transient string Transient map of arguments in JSON encoding
-v, --version Display current version of fabric peer server
但是initLedger函数可以正常工作。
vagrant@fabric:~$ docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.abc.com/users/Admin@org1.abc.com/msp" cli peer chaincode query -C kyc-channel -n kyc -c '{"Args":["initLedger"]}'
2018-05-16 16:31:06.974 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-05-16 16:31:06.974 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-05-16 16:31:06.974 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-05-16 16:31:06.974 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-05-16 16:31:06.974 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-05-16 16:31:06.975 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0A9C070A6808031A0C08CAB9F1D70510...79631A0C0A0A696E69744C6564676572
2018-05-16 16:31:06.975 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 36456570541FBB5AD1BBAC6F4B732398D7600FEE43BBD792E028BC6C8095F0E0
Query Result:
2018-05-16 16:31:06.982 UTC [main] main -> INFO 008 Exiting.....
答案 0 :(得分:0)
问题得到了解决。
fabric正在使用旧的chaincode docker图像。 我不得不删除以前生成的chaincode docker图像。没有updateUser函数。
另一种方法是更新版本或更改链码的名称。
:有关信息,请参阅此答案。 Hyperledger Fabric altering fabcar example