func (cc *MyChaincode) PutValue(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 2 { return shim.Error("Incorrect number of arguments. Expecting key and value") } err := stub.PutState(args[0], []byte(args[1])) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) }
func (cc *MyChaincode) GetValue(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting key") } value, err := stub.GetState(args[0]) if err != nil { return shim.Error("Failed to get value for key " + args[0]) } return shim.Success(value) } func (cc *MyChaincode) UpdateValue(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 2 { return shim.Error("Incorrect number of arguments. Expecting key and value") } err := stub.PutState(args[0], []byte(args[1])) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) }The GetValue function takes in a key argument and returns the value associated with that key from the state database using the stub, while the UpdateValue function takes in a key and a new value, and updates the value associated with the key in the state database using the stub. The library is part of the Hyperledger Fabric project and provides a set of tools and libraries for building blockchain applications on the Fabric network.