MCPcopy
hub / github.com/yeasy/blockchain_guide / readJSON

Function readJSON

11_app_dev/chaincode_example05.go:289–301  ·  view source on GitHub ↗
(ctx contractapi.TransactionContextInterface, key string, target interface{})

Source from the content-addressed store, hash-verified

287}
288
289func readJSON(ctx contractapi.TransactionContextInterface, key string, target interface{}) error {
290 data, err := ctx.GetStub().GetState(key)
291 if err != nil {
292 return fmt.Errorf("failed to read %s: %w", key, err)
293 }
294 if data == nil {
295 return fmt.Errorf("state %s does not exist", key)
296 }
297 if err := json.Unmarshal(data, target); err != nil {
298 return fmt.Errorf("failed to decode %s: %w", key, err)
299 }
300 return nil
301}
302
303func putJSON(ctx contractapi.TransactionContextInterface, key string, value interface{}) error {
304 data, err := json.Marshal(value)

Callers 2

GetTransactionByIDMethod · 0.70
readHomeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected