Bluemix:错误:无法启动链代码规范(无法获取

时间:2017-02-06 21:10:33

标签: ibm-cloud blockchain

我试图让IBM的chaincode_example02工作,但我正在努力解决一些问题。

我与Bluemix启动器网络连接。我等了很长时间才查询,但没有任何成功。现在,我正在阅读对等日志,我有以下问题:

  1. 我是否需要在本地go工作目录中添加/导入peer和shim?

  2. launchAndWaitForRegister failed Error starting container: API error (500)是什么意思?

  3.   

    OUT - 20:45:56.877 [共识/ pbft] ProcessEvent - >信息1ca [0m   副本0批处理计时器到期OUT - 20:45:56.877 [共识/ pbft]   sendBatch - > INFO 1cb [0m创建具有1个请求OUT的批次 -   20:45:56.879 [共识/ pbft] executeOne - > INFO 1cc [0m副本0   执行/提交请求批处理视图= 0 / seqNo = 31和摘要   YrYAFLUeCUaZSwV85WOvOzd8rDHIeryEt5612Tck8gjf + jVU + Xh1y + 3Oe时+ rpz08VPPSbbwt7vR0wsrU1NzvXoA ==   OUT - [31m20:45:58.930 [dockercontroller] deployImage - > ERRO 1cd [0m   构建映像时出错:命令' / bin / sh -c go install   构建链码&& CP   SRC /积聚chaincode /供应商/ github.com / hyperledger /织物/对等体/ core.yaml   $ GOPATH / bin&& mv $ GOPATH / bin / build-chaincode   $ GOPATH /斌/ 8482db43feb10640d37c343bf6d50feb29ba21da196075a721d6489eb1fab616'   返回非零代码:1

         

    OUT - [31m20:45:58.930 [dockercontroller] deployImage - > ERRO 1ce [0m   图像输出:OUT - ******************** OUT - 步骤1:FROM   hyperledger / fabric-baseimage OUT - ---> 21cb00fb27f4 OUT - 步骤2:   复制。 $ GOPATH / src / build-chaincode / OUT - --->使用缓存OUT -   ---> f4e8d401945d OUT - 步骤3:WORKDIR $ GOPATH OUT - --->使用缓存OUT - ---> 4cb1d635a080 OUT - 步骤4:运行安装   构建链码&& CP   SRC /积聚chaincode /供应商/ github.com / hyperledger /织物/对等体/ core.yaml   $ GOPATH / bin&& mv $ GOPATH / bin / build-chaincode   $ GOPATH /斌/ 8482db43feb10640d37c343bf6d50feb29ba21da196075a721d6489eb1fab616   OUT - --->在85da9ebe80f0中运行

         

    OUT - [91msrc / build-chaincode / chaincode_example02.go:30:2:不能   找到包" github.com/hyperledger/fabric/protos/peer"在任何一个:   OUT - /opt/go/src/github.com/hyperledger/fabric/protos/peer(来自   $ GOROOT)OUT -     /opt/gopath/src/github.com/hyperledger/fabric/protos/peer(来自   $ GOPATH)OUT - [0m OUT - ******************** OUT - [31m20:45:59.688   [dockercontroller]开始 - > ERRO 1cf [0m start - 无法重新创建   容器API错误(500):错误:图像   库/ 8b01ce9efeff42d48ce02c3c53356c1d-vp0-8482db43feb10640d37c343bf6d50feb29ba21da196075a721d6489eb1fab616:最新   找不到

         

    OUT - [31m20:45:59.688 [chaincode] Launch - > ERRO 1d0 [0m   launchAndWaitForRegister failed启动容器错误:API错误   (500):错误:图像   库/ 8b01ce9efeff42d48ce02c3c53356c1d-vp0-8482db43feb10640d37c343bf6d50feb29ba21da196075a721d6489eb1fab616:最新   未找到OUT - 20:45:59.689 [共识/ pbft] execDoneSync - >信息   1d1 [0m副本0完成执行31,尝试下一个OUT -   20:47:56.546 [共识/ pbft] ProcessEvent - > INFO 1d2 [0m副本0   批量计时器到期OUT - 20:47:56.547 [共识/ pbft] sendBatch - >   INFO 1d3 [0m创建具有1个请求的批处理OUT - 20:47:56.548   [共识/ pbft] executeOne - >信息1d4 [0m副本0   执行/提交请求批处理视图= 0 / seqNo = 32和摘要   HfK1r9YKy8VyEKJPyWbRITJalorskEzDb9xuxqsLvBQNWw1ePsH6W4NZtBHmm + Wgo5Q2TgumvLpApyPSvD5xWQ ==   OUT - 20:47:56.549 [共识/ pbft] execDoneSync - >信息1d5 [0m   副本0完成执行32,尝试下一步

    链码

    /*
    Copyright IBM Corp. 2016 All Rights Reserved.
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
             http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    */
    
    package main
    
    //WARNING - this chaincode's ID is hard-coded in chaincode_example04 to illustrate one way of
    //calling chaincode from a chaincode. If this example is modified, chaincode_example04.go has
    //to be modified as well with the new ID of chaincode_example02.
    //chaincode_example05 show's how chaincode ID can be passed in as a parameter instead of
    //hard-coding.
    
    import (
        "fmt"
        "strconv"
    
        "github.com/hyperledger/fabric/core/chaincode/shim"
        pb "github.com/hyperledger/fabric/protos/peer"
    )
    
    // SimpleChaincode example simple Chaincode implementation
    type SimpleChaincode struct {
    }
    
    func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
        fmt.Println("ex02 Init")
        _, args := stub.GetFunctionAndParameters()
        var A, B string    // Entities
        var Aval, Bval int // Asset holdings
        var err error
    
        if len(args) != 4 {
            return shim.Error("Incorrect number of arguments. Expecting 4")
        }
    
        // Initialize the chaincode
        A = args[0]
        Aval, err = strconv.Atoi(args[1])
        if err != nil {
            return shim.Error("Expecting integer value for asset holding")
        }
        B = args[2]
        Bval, err = strconv.Atoi(args[3])
        if err != nil {
            return shim.Error("Expecting integer value for asset holding")
        }
        fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
    
        // Write the state to the ledger
        err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
        if err != nil {
            return shim.Error(err.Error())
        }
    
        err = stub.PutState(B, []byte(strconv.Itoa(Bval)))
        if err != nil {
            return shim.Error(err.Error())
        }
    
        return shim.Success(nil)
    }
    
    func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
        fmt.Println("ex02 Invoke")
        function, args := stub.GetFunctionAndParameters()
        if function == "invoke" {
            // Make payment of X units from A to B
            return t.invoke(stub, args)
        } else if function == "delete" {
            // Deletes an entity from its state
            return t.delete(stub, args)
        } else if function == "query" {
            // the old "Query" is now implemtned in invoke
            return t.query(stub, args)
        }
    
        return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"")
    }
    
    // Transaction makes payment of X units from A to B
    func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response {
        var A, B string    // Entities
        var Aval, Bval int // Asset holdings
        var X int          // Transaction value
        var err error
    
        if len(args) != 3 {
            return shim.Error("Incorrect number of arguments. Expecting 3")
        }
    
        A = args[0]
        B = args[1]
    
        // Get the state from the ledger
        // TODO: will be nice to have a GetAllState call to ledger
        Avalbytes, err := stub.GetState(A)
        if err != nil {
            return shim.Error("Failed to get state")
        }
        if Avalbytes == nil {
            return shim.Error("Entity not found")
        }
        Aval, _ = strconv.Atoi(string(Avalbytes))
    
        Bvalbytes, err := stub.GetState(B)
        if err != nil {
            return shim.Error("Failed to get state")
        }
        if Bvalbytes == nil {
            return shim.Error("Entity not found")
        }
        Bval, _ = strconv.Atoi(string(Bvalbytes))
    
        // Perform the execution
        X, err = strconv.Atoi(args[2])
        if err != nil {
            return shim.Error("Invalid transaction amount, expecting a integer value")
        }
        Aval = Aval - X
        Bval = Bval + X
        fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval)
    
        // Write the state back to the ledger
        err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
        if err != nil {
            return shim.Error(err.Error())
        }
    
        err = stub.PutState(B, []byte(strconv.Itoa(Bval)))
        if err != nil {
            return shim.Error(err.Error())
        }
    
        return shim.Success(nil)
    }
    
    // Deletes an entity from state
    func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response {
        if len(args) != 1 {
            return shim.Error("Incorrect number of arguments. Expecting 1")
        }
    
        A := args[0]
    
        // Delete the key from the state in ledger
        err := stub.DelState(A)
        if err != nil {
            return shim.Error("Failed to delete state")
        }
    
        return shim.Success(nil)
    }
    
    // query callback representing the query of a chaincode
    func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response {
        var A string // Entities
        var err error
    
        if len(args) != 1 {
            return shim.Error("Incorrect number of arguments. Expecting name of the person to query")
        }
    
        A = args[0]
    
        // Get the state from the ledger
        Avalbytes, err := stub.GetState(A)
        if err != nil {
            jsonResp := "{\"Error\":\"Failed to get state for " + A + "\"}"
            return shim.Error(jsonResp)
        }
    
        if Avalbytes == nil {
            jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}"
            return shim.Error(jsonResp)
        }
    
        jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
        fmt.Printf("Query Response:%s\n", jsonResp)
        return shim.Success(Avalbytes)
    }
    
    func main() {
        err := shim.Start(new(SimpleChaincode))
        if err != nil {
            fmt.Printf("Error starting Simple chaincode: %s", err)
        }
    }
    

1 个答案:

答案 0 :(得分:0)

  1. 我假设您正在使用SDK(HFC)客户端来部署您的链代码。您不需要从本地go工作目录导入peer和shim代码,但是你需要有一个带有代码的/ vendor文件夹。 应该看起来像这样==> vendor structure
  2. 供应商文件夹内容如下所示:

    ./vendor
    ./vendor/github.com
    ./vendor/github.com/hyperledger
    ./vendor/github.com/hyperledger/fabric
    ./vendor/github.com/hyperledger/fabric/consensus
    ./vendor/github.com/hyperledger/fabric/consensus/controller
    ./vendor/github.com/hyperledger/fabric/consensus/executor
    ./vendor/github.com/hyperledger/fabric/consensus/helper
    ./vendor/github.com/hyperledger/fabric/consensus/helper/persist
    ./vendor/github.com/hyperledger/fabric/consensus/noops
    ./vendor/github.com/hyperledger/fabric/consensus/pbft
    ./vendor/github.com/hyperledger/fabric/consensus/util
    

    ........继续.....(基本上是对等和填充码都在这里)

    部署将使用chaincode.go + vendor文件夹创建用于链代码执行的docker容器。

    您收到的错误是因为找不到构建链代码容器所需的代码。

    1. " launchAndWaitForRegister失败错误启动容器:API错误(500)"错误只是告诉您部署请求无法正确构建链代码容器。
    2. 希望这有帮助!