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
30
Compare changes
  • Side-by-side
  • Inline
+ 14
30
@@ -78,7 +78,7 @@ export class DataHandler {
balance: 0n
});
this.data.accounts.set(accountevt.address, newAccount);
ctx.log.info(`Added account ${accountevt}`);
ctx.log.info(`Added account ${accountevt.address} at block ${accountevt.blockNumber}`);
}
// Process killed accounts
@@ -145,28 +145,6 @@ export class DataHandler {
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(
@@ -175,6 +153,9 @@ export class DataHandler {
await this.updateAccountBalance(ctx, slashed.address, -slashed.amount);
}
// We don't need to process endowed accounts and dust lost accounts
// because they are handled in common transfers and removed accounts
// Process comments
for (const commentEvt of newData.comments) {
const sender = await this.getAccountByAddressOrFail(ctx, commentEvt.sender);
@@ -291,6 +272,8 @@ export class DataHandler {
idty.lastChangeOn = idtyChange.blockNumber;
this.data.identities.set(idtyChange.index, idty);
ctx.log.info(`Identity ${idtyChange.index} owner key changed to ${idtyChange.accountId}`);
// Related to https://git.duniter.org/nodes/rust/duniter-v2s/-/issues/245.
// An account can be dissociated from an identity even if the validator is online.
// To circumvent this problem, we keep a mapping between the account and the last
@@ -652,25 +635,26 @@ export class DataHandler {
// Process ud claims
for (const claim of newData.udsClaimed) {
ctx.log.info(`udsClaimed: Claiming UD for ${claim.who}`);
// Find identity that owns this account
const identity = await ctx.store.findOneOrFail(Identity, {
const identityStorage = await ctx.store.findOneOrFail(Identity, {
relations: { account: true },
where: { account: { id: claim.who } }
});
// Try to get identity from cache, if not found, get it from storage
const identity = await this.getIdtyByIndexOrFail(ctx, identityStorage.index);
// Update firstEligibleUd based on the current UD index
const currentUd = await ctx.store.findOneOrFail(UniversalDividend, {
where: {},
order: { index: 'DESC' }
});
ctx.log.info(`udsClaimed: Current UD index for ${identity.index}: ${currentUd.index}`);
ctx.log.info(`udsClaimed: Claiming UD for ${claim.who} at block ${claim.blockNumber} with count ${claim.count} and total ${claim.total}`);
ctx.log.info(`udsClaimed: Current UD index: ${currentUd.index} with amount ${currentUd.amount}`);
if (currentUd) {
identity.firstEligibleUd = currentUd.index;
this.data.identities.set(identity.index, identity);
}
identity.firstEligibleUd = currentUd.index;
this.data.identities.set(identity.index, identity);
}
}
Loading