【问题标题】:Unable to instantiate Go chaincode with Client Identity Chaincode Library on Fabric v1.4无法在 Fabric v1.4 上使用客户端身份链代码库实例化 Go 链代码
【发布时间】:2020-11-10 13:02:43
【问题描述】:

我正在尝试实例化一个已实现客户端身份链代码库 (docs) 的链代码。我在 CLI pod 中遇到的错误如下

> 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 version go1.15.2 linux/amd64”。最奇怪的是目录“/opt/gopath/src/github.com/hyperledger/fabric-protos-go/msp”与所有3个文件都存在于github repo的相同路径中但它无法找到它.

我附上了$GOPATH目录结构 提前致谢!

【问题讨论】:

    标签: hyperledger-fabric hyperledger hyperledger-chaincode


    【解决方案1】:

    这取决于你同行的 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 也是如此。

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 2019-04-07
      相关资源
      最近更新 更多