Skip to content
Snippets Groups Projects

add balance to accounts

Open poka requested to merge account-balance into main
Compare and Show latest version
1 file
+ 14
0
Compare changes
  • Side-by-side
  • Inline
+ 14
0
@@ -94,6 +94,20 @@ export class DataHandler {
ctx.log.info(
`New transaction: ${transfer.from} to ${transfer.to} of ${transfer.amount} tokens`
);
// should never fail because source of transfer must be an existing account
const fromAccount = await this.getAccountByAddressOrFail(ctx, transfer.from);
// shoud never fail because destination of transfer must be existing account or raise System.NewAccount
const toAccount = await this.getAccountByAddressOrFail(ctx, transfer.to);
const newTransfer = new Transfer({
id: transfer.id,
blockNumber: transfer.blockNumber,
timestamp: transfer.timestamp,
from: fromAccount,
to: toAccount,
amount: transfer.amount,
});
this.data.transfers.set(transfer.id, newTransfer);
// Update balances
await this.updateAccountBalance(ctx, transfer.from, -transfer.amount);
await this.updateAccountBalance(ctx, transfer.to, transfer.amount);
Loading