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
+ 15
7
Compare changes
  • Side-by-side
  • Inline
+ 15
7
@@ -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);
@@ -543,7 +557,7 @@ export class DataHandler {
// Distribute UD to each member
for (const identity of memberIdentities) {
await this.handleUniversalDividend(ctx, await ctx.store.getOrFail(Event, event.id), identity, BigInt(amount));
await this.updateAccountBalance(ctx, identity.account!.id, amount); // we are sure that a non-removed identity has non-null account
}
this.data.universalDividend.push(new UniversalDividend({
@@ -741,10 +755,4 @@ export class DataHandler {
account.balance = (account.balance || 0n) + amount;
this.data.accounts.set(accountId, account);
}
async handleUniversalDividend(ctx: Ctx, event: Event, identity: Identity, amount: bigint): Promise<void> {
if (identity.account) {
await this.updateAccountBalance(ctx, identity.account.id, amount);
}
}
}
Loading