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

Method InitLedger

11_app_dev/chaincode_example03.go:53–64  ·  view source on GitHub ↗

InitLedger creates the central bank and its initial issued balance.

(ctx contractapi.TransactionContextInterface, name string, total string)

Source from the content-addressed store, hash-verified

51
52// InitLedger creates the central bank and its initial issued balance.
53func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface, name string, total string) (*CenterBank, error) {
54 amount, err := parsePositiveAmount(total)
55 if err != nil {
56 return nil, err
57 }
58
59 centerBank := &CenterBank{Name: name, TotalNumber: amount, RestNumber: amount}
60 if err := putJSON(ctx, centerBankKey, centerBank); err != nil {
61 return nil, err
62 }
63 return centerBank, nil
64}
65
66// CreateBank registers a commercial bank.
67func (s *SmartContract) CreateBank(ctx contractapi.TransactionContextInterface, name string) (*Bank, error) {

Callers

nothing calls this directly

Calls 2

parsePositiveAmountFunction · 0.70
putJSONFunction · 0.70

Tested by

no test coverage detected