英文:
cannot run hyperledger chaincode from my own github on Ubuntu terminal
问题
我可以从以下官方路径运行链码:
https://github.com/ibm-blockchain/learn-chaincode/finished
github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
# peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
但是无法从自己的github路径运行链码:
https://github.com/jeffyxia/hyperledger/trade
# peer chaincode deploy -p https://github.com/jeffyxia/hyperledger/trade -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
错误信息如下:
Error: Error building chaincode: rpc error: code = 2 desc = Error getting
chaincode package bytes: Error getting code 'go get' failed with error: "exit status 2"
# github.com/jeffyxia/hyperledger/hello_world
/go/_usercode_/519629987/src/github.com/jeffyxia/hyperledger/hello_world/chaincode_example01.go:31: cannot use new(SimpleChaincode) (type *SimpleChaincode) as type shim.Chaincode in argument to shim.Start:
*SimpleChaincode does not implement shim.Chaincode (wrong type for Init method)
have Init(*shim.ChaincodeStub, string, []string) ([]byte, error)
want Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)
补充信息:
Ubuntu 16.04 没有安装go语言环境,使用PBFT算法。
如何解决这个问题,谢谢。
英文:
I can run the chaincode from the following official path:
https://github.com/ibm-blockchain/learn-chaincode/finished
github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
# peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
but cannot run chainncode from my own github path:
https://github.com/jeffyxia/hyperledger/trade
# peer chaincode deploy -p https://github.com/jeffyxia/hyperledger/trade -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
the error info is:
Error: Error building chaincode: rpc error: code = 2 desc = Error getting
chaincode package bytes: Error getting code 'go get' failed with error: "exit status 2"
# github.com/jeffyxia/hyperledger/hello_world
/go/_usercode_/519629987/src/github.com/jeffyxia/hyperledger/hello_world/chaincode_example01.go:31: cannot use new(SimpleChaincode) (type *SimpleChaincode) as type shim.Chaincode in argument to shim.Start:
*SimpleChaincode does not implement shim.Chaincode (wrong type for Init method)
have Init(*shim.ChaincodeStub, string, []string) ([]byte, error)
want Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)
supplement info:
Ubuntu 16.04 without go language environment, use PBFT algrithm.
how to fix this problem, thx.
答案1
得分: 1
首先,您可能希望从官方存储库中使用最新版本的Fabric。
其次,错误是不言自明的,
*SimpleChaincode未实现shim.Chaincode(Init方法类型错误)
具有Init(*shim.ChaincodeStub,string,[]string)([]byte,error)
要求Init(shim.ChaincodeStubInterface,string,[]string)([]byte,error)
您需要在您的go文件中的所有位置将stub *shim.ChaincodeStub
替换为stub shim.ChaincodeStubInterface
。请阅读这个链接,https://github.com/IBM-Blockchain/ibm-blockchain-issues/issues/29
英文:
First of all, you may want to use the latest version of fabric from its official repository.
Secondly, the error is self-explanatory,
*SimpleChaincode does not implement shim.Chaincode (wrong type for Init method)
have Init(*shim.ChaincodeStub, string, []string) ([]byte, error)
want Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)
You need to replace stub *shim.ChaincodeStub
with stub shim.ChaincodeStubInterface
everywhere in your go file. Please read this as well, https://github.com/IBM-Blockchain/ibm-blockchain-issues/issues/29
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论