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

Function readJSON

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

Source from the content-addressed store, hash-verified

386}
387
388func readJSON(ctx contractapi.TransactionContextInterface, key string, target interface{}) error {
389 data, err := ctx.GetStub().GetState(key)
390 if err != nil {
391 return fmt.Errorf("failed to read %s: %w", key, err)
392 }
393 if data == nil {
394 return fmt.Errorf("state %s does not exist", key)
395 }
396 if err := json.Unmarshal(data, target); err != nil {
397 return fmt.Errorf("failed to decode %s: %w", key, err)
398 }
399 return nil
400}
401
402func putJSON(ctx contractapi.TransactionContextInterface, key string, value interface{}) error {
403 data, err := json.Marshal(value)

Callers 4

readCenterBankFunction · 0.70
readBankFunction · 0.70
readCompanyFunction · 0.70
readTransactionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected