Skip to content

Instantly share code, notes, and snippets.

@vitiko
Last active February 20, 2019 05:23
Show Gist options
  • Save vitiko/d3101db7d5954122ccd6f6ba68f5bdca to your computer and use it in GitHub Desktop.
Save vitiko/d3101db7d5954122ccd6f6ba68f5bdca to your computer and use it in GitHub Desktop.
Working with chaincode state using ChaincodeStubeInterface
ct := ContractType{}
err := json.Unmarshal([]byte(args[0]), &req)
if err != nil {
return shim.Error(err.Error())
}
key, err := stub.CreateCompositeKey(prefixContractType, []string{req.UUID})
if err != nil {
return shim.Error(err.Error())
}
valAsBytes, err := stub.GetState(key)
if err != nil {
return shim.Error(err.Error())
}
if len(valAsBytes) == 0 {
return shim.Error("Contract Type could not be found")
}
err = json.Unmarshal(valAsBytes, &ct)
if err != nil {
return shim.Error(err.Error())
}
ct.Active = req.Active
valAsBytes, err = json.Marshal(ct)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(key, valAsBytes)
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment