我是Hyperledger的新手。我正在使用docker来运行Hyperledger。从Docker中心拉出hyperledger/fabric-peer:latest
能够在我的Chaincode中运行stub.CreateTable()
,stub.GetRows()
,stub.InsertRows()
和其他一些功能。但是当我试图运行时
stub.GetHistoryKeys() or stub.GetCompositeKeys() ...etc
它报告错误
stub.GetHistoryForKey undefined (type shim.ChaincodeStubInterface has no field
or method GetHistoryForKey)
我发现在我的interface.go文件中没有这样的功能。用Google搜索但没有发现任何内容。任何人都可以告诉正确的hyperledger/fabric-peer
图像,以便上述函数可以在Chaincode中运行。
答案 0 :(得分:0)
最后,我能够弄明白,以获得超级图像以支持我的链码。
答案 1 :(得分:0)
请下载最新版的面料图片,( hyperledger / fabric-peer x86_64-1.1.0)。它可以从hyperledger官方网站上提到的脚本下载(安装二进制)=> (https://hyperledger-fabric.readthedocs.io/en/latest/install.html。由于堆叠流量策略问题,无法粘贴网址)。一旦你拥有它。创建一个go代码。只需在一个键添加上添加一个json记录,然后尝试添加一些更改某些json字段并再次添加到相同的键。完成后,触发以下代码获取gethistory:=>
func(s * SmartContract)getAllTransactionForid(APIstub shim.ChaincodeStubInterface,args [] string)sc.Response { fmt.Println(" getAllTransactionForNumber名为") id:= args [0]
resultsIterator, err := APIstub.GetHistoryForKey(id)
if err != nil {
return shim.Error(err.Error())
}
defer resultsIterator.Close()
// buffer is a JSON array containing historic values for the number
var buffer bytes.Buffer
buffer.WriteString("[")
bArrayMemberAlreadyWritten := false
for resultsIterator.HasNext() {
response, err := resultsIterator.Next()
if err != nil {
return shim.Error(err.Error())
}
// Add a comma before array members, suppress it for the first array member
if bArrayMemberAlreadyWritten == true {
buffer.WriteString(",")
}
buffer.WriteString("{\"TxId\":")
buffer.WriteString("\"")
buffer.WriteString(response.TxId)
buffer.WriteString("\"")
buffer.WriteString(", \"Value\":")
// if it was a delete operation on given key, then we need to set the
//corresponding value null. Else, we will write the response.Value
//as-is (as the Value itself a JSON marble)
if response.IsDelete {
buffer.WriteString("null")
} else {
buffer.WriteString(string(response.Value))
}
buffer.WriteString(", \"Timestamp\":")
buffer.WriteString("\"")
buffer.WriteString(time.Unix(response.Timestamp.Seconds, int64(response.Timestamp.Nanos)).String())
buffer.WriteString("\"")
buffer.WriteString(", \"IsDelete\":")
buffer.WriteString("\"")
buffer.WriteString(strconv.FormatBool(response.IsDelete))
buffer.WriteString("\"")
buffer.WriteString("}")
bArrayMemberAlreadyWritten = true
}
if !bArrayMemberAlreadyWritten {
buffer.WriteString("No record found")
}
buffer.WriteString("]")
fmt.Printf("- getAllTransactionForNumber returning:\n%s\n", buffer.String())
return shim.Success(buffer.Bytes())
}
如果仍有疑问,请恢复原状。我将为您提供完整的源代码以使其正常工作。但我希望这会让你的问题消失: - )