无法调用链码名称:“ lscc”,错误:事务返回失败:名为

时间:2019-08-06 10:27:55

标签: java hyperledger-fabric hyperledger-chaincode

我正在尝试从fabric-samples安装facar的java chaincode,但出现错误。

https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode/fabcar/java

在链码上方,我正在尝试&在链码实例化期间出错

有人可以帮助我吗,非常感谢和感谢。

我正在使用基本的网络文件夹和以下脚本进行网络创建和安装,实例化和调用链码。

#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Exit on first error, print all commands.
set -ev

# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1

docker-compose -f docker-compose.yml down

docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb
docker ps -a

# wait for Hyperledger Fabric to start
# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>
export FABRIC_START_TIMEOUT=10
#echo ${FABRIC_START_TIMEOUT}
sleep ${FABRIC_START_TIMEOUT}

# Create the channel
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
# Join peer0.org1.example.com to the channel.
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block

docker-compose -f docker-compose.yml up -d cli
sleep 5

#install chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n mycc -v 1.0 -p /opt/gopath/src/github.com/fabcar/java -l java

#instantiate chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -l java -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

sleep 5

#invoke chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051"  -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc -c '{"function":"initLedger","Args":[""]}'

下面给出的docker日志peer0.org1.example.com命令的输出

  

2019-08-06 09:54:26.150 UTC [endorser] SimulateProposal-> ERRO 043   [mychannel] [e0746cf6]无法调用链码名称:“ lscc”,错误:   事务返回失败:未定义的合同方法称为

     

docker日志的输出dev-peer0.org1.example.com-mycc-1.0命令   如下

09:54:26:142 SEVERE  org.hyperledger.fabric.Logger error                                              Undefined contract method
     

namedorg.hyperledger.fabric.shim.ChaincodeException:未定义   合约方法称为               在org.hyperledger.fabric.contract.ContractInterface.unknownTransaction(ContractInterface.java:76)               在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处               在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)               在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)               在java.lang.reflect.Method.invoke(Method.java:498)               在org.hyperledger.fabric.contract.execution.impl.ContractExecutionService.executeRequest(ContractExecutionService.java:57)               在org.hyperledger.fabric.contract.ContractRouter.processRequest(ContractRouter.java:87)               在org.hyperledger.fabric.contract.ContractRouter.init(ContractRouter.java:103)               在org.hyperledger.fabric.shim.impl.Handler.lambda $ handleInit $ 0(Handler.java:280)               在java.lang.Thread.run(Thread.java:748)

:54:26:147 SEVERE  org.hyperledger.fabric.shim.impl.Handler lambda$handleInit$0                     [e0746cf6] Init failed.
     

发送错误

3 个答案:

答案 0 :(得分:0)

  

未定义的合同方法称为

在代码的前几行中。这意味着传递给调用的函数在链码中不存在,您可以检查链码并查看initLedger是否存在吗?或是否存在任何拼写错误。 希望这是有用的。

答案 1 :(得分:0)

如果在实例化链代码时遇到此问题,则可以使用自定义实现覆盖 ContractInterface 中给出的以下方法。

/**
 * Invoked for any transaction that does not exist.
 *
 * This will throw an exception. If you wish to alter the exception thrown or 
 * if you wish to consider requests for transactions that don't exist as not an
 * error, subclass this method.
 *
 * @param ctx the context as created by {@link #createContext(ChaincodeStub)}.
 */
default void unknownTransaction(Context ctx) {
    throw new ChaincodeException("Undefined contract method called");
}

否则,如果在调用现有事务时发生问题,那么请确保注释@Transaction()出现在事务方法中。

答案 2 :(得分:0)

也许您忘记了 @Default 装饰器

@Contract(name = "MyContract",
        info = @Info(
                title = "My Contract",
                description = "",
                version = "0.0.1"
        )
)
@Default
public class MyContract implements ContractInterface {