IssueCoinToBank transfers issued currency from the central bank to a commercial bank.
(ctx contractapi.TransactionContextInterface, bankID string, amount string)
| 110 | |
| 111 | // IssueCoinToBank transfers issued currency from the central bank to a commercial bank. |
| 112 | func (s *SmartContract) IssueCoinToBank(ctx contractapi.TransactionContextInterface, bankID string, amount string) (*Transaction, error) { |
| 113 | id, value, err := parseIDAndAmount(bankID, amount) |
| 114 | if err != nil { |
| 115 | return nil, err |
| 116 | } |
| 117 | |
| 118 | centerBank, err := readCenterBank(ctx) |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | if centerBank.RestNumber < value { |
| 123 | return nil, fmt.Errorf("central bank balance is insufficient") |
| 124 | } |
| 125 | bank, err := readBank(ctx, id) |
| 126 | if err != nil { |
| 127 | return nil, err |
| 128 | } |
| 129 | |
| 130 | centerBank.RestNumber -= value |
| 131 | bank.TotalNumber += value |
| 132 | bank.RestNumber += value |
| 133 | |
| 134 | if err := putJSON(ctx, centerBankKey, centerBank); err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | if err := putJSON(ctx, bankKey(id), bank); err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | return recordTransaction(ctx, 0, 0, 1, id, value) |
| 141 | } |
| 142 | |
| 143 | // IssueCoinToCompany transfers currency from a bank to a company. |
| 144 | func (s *SmartContract) IssueCoinToCompany(ctx contractapi.TransactionContextInterface, bankID string, companyID string, amount string) (*Transaction, error) { |
nothing calls this directly
no test coverage detected