Last active
February 20, 2019 05:23
-
-
Save vitiko/d3101db7d5954122ccd6f6ba68f5bdca to your computer and use it in GitHub Desktop.
Working with chaincode state using ChaincodeStubeInterface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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