我正在尝试使用rpi作为超级边缘结构网络中的对等体来控制LED . 我的网络(PC和RPI)如下:

  • 证书颁发机构(CA) - PC1

  • Orrrer - PC1

  • 1 PEER(peer0)on - PC1

  • 1 PEER(peer1)on - RP

  • CLI on - RPI

我成功设置了上述网络,我能够运行hyperledger fabric(安装,查询,调用)提供的链代码示例2 . 我开发了自己的链码,可以用来打开和关闭连接到区块链的rpi的LED . 问题是我得到以下错误(超时):

错误:错误支持链代码:rpc错误:代码=未知desc =超时启动时链代码mychaincode:1.0

这是我的链码:

package main
import (
    "fmt"
    "strconv"
    "os"
    "github.com/stianeikeland/go-rpio" //To Map GPIO of RPI
    "github.com/hyperledger/fabric/core/chaincode/shim"
    pb "github.com/hyperledger/fabric/protos/peer"
)
var (
        pin = rpio.Pin(3)
)

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {


}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
    fmt.Println("LED ON")
    _, args := stub.GetFunctionAndParameters()
    var A string    // Entities
    var Aval int // Asset holdings
    var err error

    if len(args) != 2 {
        return shim.Error("Incorrect number of arguments. Expecting 2")
    }
    if err := rpio.Open(); err != nil {
        fmt.Println(err)
        os.Exit(1)
     }
    A = args[0]
    Aval, err = strconv.Atoi(args[1])
    if err != nil {
        return shim.Error("Expecting integer value for asset holding")
    }

    fmt.Printf("Aval = %d", Aval)
    if Aval == 1{
     pin.High() //turn on
    } else {
     pin.Low() //turn off
    }
    // Write the state to the ledger
    err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
    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 string    // Entities
    var Aval int // Asset holdings
    var X int          // Transaction value
    var err error

    if len(args) != 2 {
        return shim.Error("Incorrect number of arguments. Expecting 2")
    }

    A = args[0]

    // 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))


    // Perform the execution
    X, err = strconv.Atoi(args[1])
    if err != nil {
        return shim.Error("Invalid transaction amount, expecting a integer value")
    }
    Aval = X
    fmt.Printf("Aval = %d", Aval)
    if Aval == 1{
     pin.High()
    } else {
     pin.Low()
    }
    // Write the state back to the ledger
    err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
    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)
    }
}

我怎么能解决这个问题,因为根本没有语法错误?