解决fabric2.0中Chaincode installation on peer0.org1 has failed问题

it2023-07-07  76

在fabric2.0版本安装之后,使用first-network搭建一个测试网络,在搭建过程中,向peer0Org1安装链码的时候报错,提示Chaincode installation on peer0.org1 has failed。详细报错信息如下:

Error: error getting chaincode deployment spec for mycc: error getting chaincode package bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric/core/chaincode/shim !!!!!!!!!!!!!!! Chaincode installation on peer0.org1 has failed !!!!!!!!!!!!!!!! ========= ERROR !!! FAILED to execute End-2-End Scenario ===========

ERROR !!!! Test failed 根据提示可以看出,出错的原因是找不到安装包github.com/hyperledger/fabric/core/chaincode/shim

复制该链接在浏览器打开,发现链接不存在,也就是说,这个错误确实是因为根据已知路径无法找到相应包引起的。

这个问题是由于fabric2.0中,github网站更改了shim的层级目录,现正确路径应该是:

github.com/hyperledger/fabric-chaincode-go/shim

于是我们在fabric-samples文件夹下,找到chaincode文件夹,再进入chaincode_example02,再go

列出go文件夹内文件,可以看到有一个chaincode_example02.go文件

第一步:

sudo vim chaincode_example02.go

修改文档开头处import部分如下:

原:

"github.com/hyperledger/fabric/core/chaincode/shim" pb "github.com/hyperledger/fabric/protos/peer"

改:

"github.com/hyperledger/fabric-chaincode-go/shim" pb "github.com/hyperledger/fabric-protos-go/peer"

保存退出。

第二步:

$ touch go.mod

$ sudo vim go.mod

在统计目录下创建go.mod文件,并编辑,写入以下内容:

module github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/chaincode_example02/go go 1.14 require ( github.com/hyperledger/fabric-chaincode-go v0.0.0-20200128192331-2d899240a7ed github.com/hyperledger/fabric-protos-go v0.0.0-20200124220212-e9cfc186ba7b golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect golang.org/x/text v0.3.2 // indirect google.golang.org/genproto v0.0.0-20200218151345-dad8c97a84f5 // indirect )

最后更新依赖:

go mod vendor

第三步:

重启网络

先关闭:./byfn.sh down

再开启:./byfn.sh up

问题解决

参考链接:https://www.bcskill.com/index.php/archives/925.html

 

 

 

 

最新回复(0)