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
The following is my write method in hyperledger fabric i have assigned the keys = 1
2) Always my method is making the keys = 1 so i should get the key from fabric and assign it to keys variable can anyone help me with this ISSUE or provide any documention how to do that
You should retun error with version 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
}