Skip to content
Snippets Groups Projects

add balance to accounts

Open poka requested to merge account-balance into main
Compare and Show latest version
3 files
+ 1
246
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 0
63
@@ -113,68 +113,6 @@ export class DataHandler {
await this.updateAccountBalance(ctx, transfer.to, transfer.amount);
}
// Process deposits
for (const deposit of newData.deposits) {
ctx.log.info(
`New deposit: ${deposit.address} received ${deposit.amount} tokens`
);
await this.updateAccountBalance(ctx, deposit.address, deposit.amount);
}
// Process withdraws
for (const withdraw of newData.withdraws) {
ctx.log.info(
`New withdraw: ${withdraw.address} withdrew ${withdraw.amount} tokens`
);
await this.updateAccountBalance(ctx, withdraw.address, -withdraw.amount);
}
// Process reserved amounts
for (const reserved of newData.reserved) {
ctx.log.info(
`New reserve: ${reserved.address} reserved ${reserved.amount} tokens`
);
await this.updateAccountBalance(ctx, reserved.address, -reserved.amount);
}
// Process unreserved amounts
for (const unreserved of newData.unreserved) {
ctx.log.info(
`New unreserve: ${unreserved.address} unreserved ${unreserved.amount} tokens`
);
await this.updateAccountBalance(ctx, unreserved.address, unreserved.amount);
}
// Process endowed accounts
for (const endowed of newData.endowed) {
ctx.log.info(
`New endowed account: ${endowed.address} received initial balance of ${endowed.amount} tokens`
);
const account = await this.getOrCreateAccount(ctx, endowed.address);
account.createdOn = endowed.blockNumber;
account.balance = endowed.amount;
this.data.accounts.set(endowed.address, account);
}
// Process dust lost accounts
for (const dustLost of newData.dustLost) {
ctx.log.info(
`Dust lost: ${dustLost.address} lost ${dustLost.amount} tokens due to falling below existential deposit`
);
const account = await this.getAccountByAddressOrFail(ctx, dustLost.address);
account.balance = 0n;
account.isActive = false;
this.data.accounts.set(dustLost.address, account);
}
// Process slashed accounts
for (const slashed of newData.slashed) {
ctx.log.info(
`Account slashed: ${slashed.address} lost ${slashed.amount} tokens due to misbehavior`
);
await this.updateAccountBalance(ctx, slashed.address, -slashed.amount);
}
// Process comments
for (const commentEvt of newData.comments) {
const sender = await this.getAccountByAddressOrFail(ctx, commentEvt.sender);
@@ -749,7 +687,6 @@ export class DataHandler {
// we need to create it
account = new Account({
id,
createdOn: ctx.blocks[0].header.height,
isActive: true,
balance: 0n
});
Loading