Hyperledger fabric 链码错误(状态:500,消息:智能合约功能名称无效

Hyperledger fabric 链码错误(状态:500,消息:智能合约功能名称无效,hyperledger-fabric,blockchain,hyperledger,smartcontracts,Hyperledger Fabric,Blockchain,Hyperledger,Smartcontracts,我正在尝试在Hyperledger结构上创建一个应用程序。我已经在GO中编写了智能合约,并尝试使用nodejs脚本调用它。但下面是一个错误 我将遵循本教程: 来自对等方的错误日志: 2018-05-16 15:52:31.399 UTC [endorser] ProcessProposal -> ERRO 03f [kyc-channel][bbad7222] simulateProposal() resulted in chaincode name:"kyc" response sta

我正在尝试在Hyperledger结构上创建一个应用程序。我已经在GO中编写了智能合约,并尝试使用nodejs脚本调用它。但下面是一个错误

我将遵循本教程:

来自对等方的错误日志:

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容器执行链码时出现以下错误

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

问题解决了

fabric使用的是旧链码docker图像。 我必须删除以前生成的链码docker映像,它没有updateUser函数

另一种方法是更新chaincode的版本或更改其名称

:有关信息,请参阅此答案。

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
  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.....