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

Function nextID

11_app_dev/chaincode_example03.go:366–375  ·  view source on GitHub ↗
(ctx contractapi.TransactionContextInterface, counterKey string)

Source from the content-addressed store, hash-verified

364}
365
366func nextID(ctx contractapi.TransactionContextInterface, counterKey string) (int, error) {
367 id, err := currentID(ctx, counterKey)
368 if err != nil {
369 return 0, err
370 }
371 if err := ctx.GetStub().PutState(counterKey, []byte(strconv.Itoa(id+1))); err != nil {
372 return 0, fmt.Errorf("failed to update counter %s: %w", counterKey, err)
373 }
374 return id, nil
375}
376
377func currentID(ctx contractapi.TransactionContextInterface, counterKey string) (int, error) {
378 data, err := ctx.GetStub().GetState(counterKey)

Callers 3

CreateBankMethod · 0.70
CreateCompanyMethod · 0.70
recordTransactionFunction · 0.70

Calls 1

currentIDFunction · 0.70

Tested by

no test coverage detected