From e34e09495cccf38ead1cbea73410b9e4c3135259 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Tue, 24 Sep 2024 14:04:20 +0700 Subject: [PATCH] refactor: review --- migrations/evm/20240923064605_erc20_contract_no_action.ts | 6 +++--- src/models/erc20_contract.ts | 2 +- src/services/evm/erc20_handler.ts | 7 +++---- test/unit/services/evm/erc20.spec.ts | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/migrations/evm/20240923064605_erc20_contract_no_action.ts b/migrations/evm/20240923064605_erc20_contract_no_action.ts index 57f3f30d1..7dc850de1 100644 --- a/migrations/evm/20240923064605_erc20_contract_no_action.ts +++ b/migrations/evm/20240923064605_erc20_contract_no_action.ts @@ -5,7 +5,7 @@ import _ from 'lodash'; export async function up(knex: Knex): Promise { 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] = @@ -60,13 +60,13 @@ export async function up(knex: Knex): Promise { ) .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 { await knex.schema.alterTable('erc20_contract', (table) => { - table.dropColumn('no_action'); + table.dropColumn('total_actions'); }); } diff --git a/src/models/erc20_contract.ts b/src/models/erc20_contract.ts index 4304288c6..afcab11b0 100644 --- a/src/models/erc20_contract.ts +++ b/src/models/erc20_contract.ts @@ -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'; diff --git a/src/services/evm/erc20_handler.ts b/src/services/evm/erc20_handler.ts index 1d673af97..9b550ea93 100644 --- a/src/services/evm/erc20_handler.ts +++ b/src/services/evm/erc20_handler.ts @@ -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; }); } diff --git a/test/unit/services/evm/erc20.spec.ts b/test/unit/services/evm/erc20.spec.ts index 48b2a9f42..2587e84bd 100644 --- a/test/unit/services/evm/erc20.spec.ts +++ b/test/unit/services/evm/erc20.spec.ts @@ -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, }); @@ -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, });