Skip to content

Instantly share code, notes, and snippets.

@tina1998612
Created July 18, 2021 11:06
Show Gist options
  • Save tina1998612/5a3cd9e90279360bdaab1f790720f8fb to your computer and use it in GitHub Desktop.
Save tina1998612/5a3cd9e90279360bdaab1f790720f8fb to your computer and use it in GitHub Desktop.
func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, owner string, appraisedValue int) error {
exists, err := s.AssetExists(ctx, id)
if err != nil {
return err
}
if exists {
return fmt.Errorf("the asset %s already exists", id)
}
asset := Asset{
ID: id,
Color: color,
Size: size,
Owner: owner,
AppraisedValue: appraisedValue,
}
assetJSON, err := json.Marshal(asset)
if err != nil {
return err
}
return ctx.GetStub().PutState(id, assetJSON)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment