dptsivmg82908 2018-04-28 16:02
浏览 336

建立用go编写的链码时出错

When I try to modify the example described in this hyperledger example I get some error when adding this external library in order to get the History of the chaincode state.
Why does that happen?

I add the library with govendor, but when I run this command:

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n $CC_NAME -l "$LANGUAGE" -v 1.0 -c $INIT_STR -P "OR ('Org1MSP.member','Org2MSP.member')"

I get this error:

Error: Error endorsing chaincode:
rpc error: code = Unknown desc = error starting container: Failed to generate platform-specific docker build: Error returned from build: 2 "# firstExample chaincode/input/src/firstExample/firstStep.go:104:11: cannot assign *"github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification to kM (type *"firstExample/vendor/github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification) in multiple assignment chaincode/input/src/firstExample/firstStep.go:146:11: cannot assign *"github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification to kM (type *"firstExample/vendor/github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification) in multiple assignment chaincode/input/src/firstExample/firstStep.go:156:11: cannot assign *"github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification to kM (type *"firstExample/vendor/github.com/hyperledger/fabric/protos/ledger/queryresult".KeyModification) in multiple assignment

I have some troubles with this. I'm sure that the library is imported because if I build the chaincode written in go with the command:

go build 

I get no errors.
Please help me!

  • 写回答

1条回答 默认 最新

  • dp7311 2018-04-30 07:59
    关注

    It's very hard to guess without seeing actual code which cause the compilation error, while it seems that you are not taking care of the second parameter which returned by HistoryQueryIteratorInterface#Next() API or even ChaincodeStubInterface#GetHistoryForKey(). Please see example of how to use those APIs correctly:

    // GetPreviousValue reads previous value of given key
    func (pm *personManagement) GetPreviousValue(params []string, stub shim.ChaincodeStubInterface) peer.Response {
        historyIer, err := stub.GetHistoryForKey(params[0])
    
        if err != nil {
            errMsg := fmt.Sprintf("[ERROR] cannot retrieve history of key <%s>, due to %s", params[0], err)
            fmt.Println(errMsg)
            return shim.Error(errMsg)
        }
    
        if historyIer.HasNext() {
            modification, err := historyIer.Next()
            if err != nil {
                errMsg := fmt.Sprintf("[ERROR] cannot read key record modification, key <%s>, due to %s", params[0], err)
                fmt.Println(errMsg)
                return shim.Error(errMsg)
            }
            fmt.Println("Returning information about", string(modification.Value))
            return shim.Success(modification.Value)
        }
    
    
        fmt.Printf("No history found for key %s
    ", params[0])
        return shim.Success([]byte(fmt.Sprintf("No history for key %s", params[0])))
    }
    

    NOTE: Please pay attention that historyIer.Next() returns history value and the error.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog