如何从hyperledgerfabric分类帐中获取数据并进行更新

时间:2018-06-18 07:12:47

标签: go hyperledger-fabric hyperledger

package main

import (

    "fmt"
    "encoding/json"
    "strconv"
    "github.com/hyperledger/fabric/core/chaincode/shim"
    pb "github.com/hyperledger/fabric/protos/peer"
)

// ============================================================================================================================
// write() - genric write variable into ledger
//
// Shows Off PutState() - writting a key/value into the ledger
//
// Inputs - Array of strings
//    0   ,    1
//   key  ,  value
//  "abc" , "test"
// ============================================================================================================================
func write(stub shim.ChaincodeStubInterface, args []string) pb.Response {
    var value,key string
    var err error
    var keys  = 1

以下是我在hyperledger结构中的写方法,我已经分配了键= 1

2)总是我的方法是使密钥= 1所以我应该从结构中获取密钥并将其分配给密钥变量任何人都可以帮助我解决这个问题或提供任何文档如何做到这一点

1 个答案:

答案 0 :(得分:1)

您应该使用版本0.6 fabric chaincode重新调整错误。

func (t *SimpleChaincode) write(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
logger.Debug("Entering chaincode")

if len(args) < 2 {
    logger.Error("Invalid number of args")
    return nil, errors.New("Expected atleast two arguments")
}
someObj := ObjectGet{}
err = json.Unmarshal([]byte(Input1), &someObj)
s1, _ := json.Marshal(someObj)
err = stub.PutState(variable1, []byte(s1))
if err != nil {
    logger.Error("Could not save record to ledger", err)
    return nil, err
}


return nil, nil
}