无法在Fabric v1.4上使用客户端身份链码库实例化Go链码

问题描述

我正在尝试实例化已实现客户端身份链码库(docs)的链码。我在CLI窗格中遇到的错误是以下

> peer chaincode instantiate -o ord1.orderers.org1.com:7050 -C mychannel -n mychaincode -v 1.1 -c '{"Args":[]}' --tls --cafile /var/hyperledger/msp/tlscacerts/tlsca.orderers.org1.com-cert.pem
2020-11-03 13:52:36.121 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-11-03 13:52:36.121 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Error: Could not assemble transaction,err proposal response was not successful,error code 500,msg error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/github.com/chaincode/vendor/github.com/hyperledger/fabric-chaincode-go/pkg/attrmgr/attrmgr.go:17:2: cannot find package "github.com/hyperledger/fabric-protos-go/msp" in any of:
        /chaincode/input/src/github.com/chaincode/vendor/github.com/hyperledger/fabric-protos-go/msp (vendor tree)
        /opt/go/src/github.com/hyperledger/fabric-protos-go/msp (from $GOROOT)
        /chaincode/input/src/github.com/hyperledger/fabric-protos-go/msp (from $GOPATH)
        /opt/gopath/src/github.com/hyperledger/fabric-protos-go/msp

我最初的Go版本是1.12.x,我在fabric-sdk-go文档中发现它需要1.14.x及更高版本,因此我升级到“ go版本go1.15.2 linux / amd64”。最奇怪的是目录“ /opt/gopath/src/github.com/hyperledger/fabric-protos-go/msp”存在,而github repo的相同路径中存在所有3个文件,但找不到它

我已附上$ GOPATH目录结构

gopath directory structure

预先感谢!

解决方法

这取决于您同行的go版本。

如果在这种情况下使用go的早期版本,则必须手动将软件包放入受尊重的目录中。因此,对于客户端身份库,您可以下载供应商文件夹。 教程链接:https://www.youtube.com/watch?v=m2ksemtAB10

您还可以编写bash文件并将依赖项安装到受关注的文件夹中。喜欢:

#!/bin/bash
# Initialize
echo "Initializing ..."
govendor init
govendor add +external


echo "Adding dependencies ... please wait"
#For older setup
# govendor add github.com/hyperledger/fabric/core/chaincode/shim
# govendor add github.com/hyperledger/fabric/protos/peer
# govendor add github.com/hyperledger/fabric/core/chaincode/lib/cid

# For newer setup with Fabric 2.0
govendor add github.com/hyperledger/fabric-chaincode-go/shim
govendor add github.com/hyperledger/fabric-chaincode-go/shim/internal
govendor add github.com/hyperledger/fabric-protos-go/peer
govendor add github.com/hyperledger/fabric-chaincode-go/pkg/cid 

对于较新的go版本,您也可以使用它。

# before packaging Golang chaincode,vendoring Go dependencies is required like the following commands.
cd /opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abstore/go
GO111MODULE=on go mod vendor
cd -

链接:https://hyperledger-fabric.readthedocs.io/en/release-2.0/build_network.html#install-and-define-a-chaincode

我以cid为例,而attrmgr也是如此。