Endorsers Instantiate Chaincode with error “cannot find package”

好久不见. 提交于 2020-12-08 02:18:40

问题


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:

  1. go mod init will create go.mod and go.sum files.
  2. go mod vendor for creating a vendor 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.

  1. peer --> github.com/hyperledger/fabric-protos-go/peer.
  2. shim --> github.com/hyperledger/fabric-chaincode-go/shim

Make sure to add peerand shim changes before running go mod initcommand 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!