Skip to content

Commit

Permalink
refactor: review
Browse files Browse the repository at this point in the history
  • Loading branch information
phamphong9981 committed Sep 24, 2024
1 parent dafa384 commit e34e094
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions migrations/evm/20240923064605_erc20_contract_no_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('erc20_contract', (table) => {
table.jsonb('no_action').defaultTo('{}');
table.jsonb('total_actions').defaultTo('{}');
});
await knex.raw(`set statement_timeout to 0`);
const [totalTransfer, totalApproval, totalDeposit, totalWithdrawal] =
Expand Down Expand Up @@ -60,13 +60,13 @@ export async function up(knex: Knex): Promise<void> {
)
.join(',');
await knex.raw(
`UPDATE erc20_contract SET no_action = temp.no_action from (VALUES ${stringListUpdates}) as temp(address, no_action) where temp.address = erc20_contract.address`
`UPDATE erc20_contract SET total_actions = temp.total_actions from (VALUES ${stringListUpdates}) as temp(address, total_actions) where temp.address = erc20_contract.address`
);
}
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('erc20_contract', (table) => {
table.dropColumn('no_action');
table.dropColumn('total_actions');
});
}
2 changes: 1 addition & 1 deletion src/models/erc20_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Erc20Contract extends BaseModel {

last_updated_height!: number;

no_action!: any;
total_actions!: any;

static get tableName() {
return 'erc20_contract';
Expand Down
7 changes: 3 additions & 4 deletions src/services/evm/erc20_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ export class Erc20Handler {
) {
this.handlerErc20Transfer(erc20Activity);
}
this.erc20Contracts[erc20Activity.erc20_contract_address].no_action[
this.erc20Contracts[erc20Activity.erc20_contract_address].total_actions[
erc20Activity.action
] =
(this.erc20Contracts[erc20Activity.erc20_contract_address].no_action[
erc20Activity.action
] || 0) + 1;
(this.erc20Contracts[erc20Activity.erc20_contract_address]
.total_actions[erc20Activity.action] || 0) + 1;
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/services/evm/erc20.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class Erc20Test {
.where('address', this.evmSmartContract.address)
.first()
.throwIfNotFound();
expect(erc20Contract.no_action).toEqual({
expect(erc20Contract.total_actions).toEqual({
transfer: erc20Activities.length - 1,
approval: 1,
});
Expand Down Expand Up @@ -370,7 +370,7 @@ export class Erc20Test {
.where('address', this.evmSmartContract.address)
.first()
.throwIfNotFound();
expect(erc20Contract.no_action).toEqual({
expect(erc20Contract.total_actions).toEqual({
transfer: erc20Activities.length + 2,
approval: 1,
});
Expand Down

0 comments on commit e34e094

Please sign in to comment.