Created
July 18, 2021 11:06
-
-
Save tina1998612/5a3cd9e90279360bdaab1f790720f8fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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