问题
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
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.
回答1:
Try Installing the dependencies in the chaincode directory using below commands:
go mod init
will creatego.mod
andgo.sum
files.go mod vendor
for creating avendor
directory.
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
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.
来源:https://stackoverflow.com/questions/62320288/endorsers-instantiate-chaincode-with-error-cannot-find-package