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

Function nextID

11_app_dev/chaincode_example05.go:267–276  ·  view source on GitHub ↗
(ctx contractapi.TransactionContextInterface, counterKey string)

Source from the content-addressed store, hash-verified

265}
266
267func nextID(ctx contractapi.TransactionContextInterface, counterKey string) (int, error) {
268 id, err := currentID(ctx, counterKey)
269 if err != nil {
270 return 0, err
271 }
272 if err := ctx.GetStub().PutState(counterKey, []byte(strconv.Itoa(id+1))); err != nil {
273 return 0, fmt.Errorf("failed to update counter %s: %w", counterKey, err)
274 }
275 return id, nil
276}
277
278func currentID(ctx contractapi.TransactionContextInterface, counterKey string) (int, error) {
279 data, err := ctx.GetStub().GetState(counterKey)

Callers 2

CreateUserMethod · 0.70
BuyByAddressMethod · 0.70

Calls 1

currentIDFunction · 0.70

Tested by

no test coverage detected