I have created a struct to store some data and i want to implement an update mechanism to it where the data in
the struct is update. I have tried the following code but its not working. How can i do it?
type Customer struct {
UID string
Name string
Address struct {
StreetNo string
Country string
}
}
func (t *SimpleChaincode) update(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting name of the key to query")
}
//args[0] to get the UID of customer whose details to be updated
//args[1] data that needs to be updated
data,err:= stub.GetState(ars[0])
if err != nil {
return nil, err
}
json.Unmarshal(data, &uid)
//append
data.Country= append(data.Country,args[1])
fmt.Printf("Risk Fag set for UID %s",data)
raw, err := json.Marshal(data)
if err != nil {
return nil, err
}
stub.PutState(data.UID, raw)
return nil,nil
}