背书者实例化具有错误“找不到包"的链码. [英] Endorsers Instantiate Chaincode with error "cannot find package"
问题描述
我创建了一个链码,并向其中导入了一个包.
I created a chaincode and I imported a package to it.
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"golang.org/x/crypto/bcrypt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer")
我可以将该链码安装到所有背书人.但是当我将其实例化给所有背书人时,它遇到了错误:
I can install that chaincode to all endorsers. But when I instantiated it to all endorsers, it faced the error:
endorser failed with error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "/chaincode/input/src/github.com/marbles02/marbles_chaincode.go:85:2: cannot find package "golang.org/x/crypto/bcrypt" in any of:
/usr/local/go/src/golang.org/x/crypto/bcrypt (from $GOROOT)
/chaincode/input/src/golang.org/x/crypto/bcrypt (from $GOPATH)
/go/src/golang.org/x/crypto/bcrypt
我试图将golang.org/x/crypto/bcrypt
程序包复制到根目录中的/usr/local/go/src/
,但是它具有相同的错误.
I tried to copy golang.org/x/crypto/bcrypt
package to the /usr/local/go/src/
in the root directory, but it has the same error.
推荐答案
尝试使用以下命令在chaincode目录中安装依赖项:
Try Installing the dependencies in the chaincode directory using below commands:
-
go mod init
将创建go.mod
和go.sum
文件. -
go mod vendor
用于创建vendor
目录.
go mod init
will creatego.mod
andgo.sum
files.go mod vendor
for creating avendor
directory.
此外,如果使用fabric:v2.X.X
,则shim
和peer
程序包将移至其他库.
因此,将chainc.go文件中的peer
和shim
软件包更改为下面的内容.
Also if using fabric:v2.X.X
then shim
and peer
packages moved to different libraries.
so change the peer
and shim
packages to below in the chaincode.go file.
-
peer
->github.com/hyperledger/fabric-protos-go/peer
. -
shim
->github.com/hyperledger/fabric-chaincode-go/shim
peer
-->github.com/hyperledger/fabric-protos-go/peer
.shim
-->github.com/hyperledger/fabric-chaincode-go/shim
在运行go mod init
命令之前,请确保添加peer
和shim
更改,或者如果您已经具有vendor
目录,请尝试依次按go mod tidy
和go mod vendor
命令来更新软件包.
Make sure to add peer
and shim
changes before running go mod init
command OR if you are already have a vendor
directory then try go mod tidy
and then go mod vendor
commands to update the packages.
这篇关于背书者实例化具有错误“找不到包"的链码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!