From 2ebf4b3e4265d73b36dbc7d429698ffd3859063d Mon Sep 17 00:00:00 2001 From: fibonacci998 Date: Mon, 22 Jul 2024 16:17:10 +0700 Subject: [PATCH 1/2] fix: keep order when insert erc20 activity --- src/services/evm/erc20.service.ts | 7 ++++++- src/services/evm/erc20_handler.ts | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/evm/erc20.service.ts b/src/services/evm/erc20.service.ts index 2b82fb959..afece69c0 100644 --- a/src/services/evm/erc20.service.ts +++ b/src/services/evm/erc20.service.ts @@ -180,10 +180,15 @@ export default class Erc20Service extends BullableService { erc20Activities )}` ); + const sortedErc20Activities = erc20Activities.sort( + (a, b) => + a.cosmos_tx_id - b.cosmos_tx_id || a.evm_event_id - b.evm_event_id + ); + this.logger.info(sortedErc20Activities); await knex .batchInsert( 'erc20_activity', - erc20Activities, + sortedErc20Activities, config.erc20.chunkSizeInsert ) .transacting(trx); diff --git a/src/services/evm/erc20_handler.ts b/src/services/evm/erc20_handler.ts index c17251997..125b72978 100644 --- a/src/services/evm/erc20_handler.ts +++ b/src/services/evm/erc20_handler.ts @@ -147,6 +147,7 @@ export class Erc20Handler { height: e.block_height, tx_hash: e.tx_hash, evm_tx_id: e.evm_tx_id, + cosmos_tx_id: e.tx_id, }); } catch (e) { logger.error(e); @@ -247,6 +248,7 @@ export class Erc20Handler { height: e.block_height, tx_hash: e.tx_hash, evm_tx_id: e.evm_tx_id, + cosmos_tx_id: e.tx_id, }); } catch (e) { logger.error(e); @@ -289,6 +291,7 @@ export class Erc20Handler { height: e.block_height, tx_hash: e.tx_hash, evm_tx_id: e.evm_tx_id, + cosmos_tx_id: e.tx_id, }); } catch (e) { logger.error(e); @@ -316,6 +319,7 @@ export class Erc20Handler { height: e.block_height, tx_hash: e.tx_hash, evm_tx_id: e.evm_tx_id, + cosmos_tx_id: e.tx_id, }); } catch (e) { logger.error(e); From cda44c53f1ae451467a8325df859b5a01fa58aca Mon Sep 17 00:00:00 2001 From: fibonacci998 Date: Mon, 22 Jul 2024 16:18:40 +0700 Subject: [PATCH 2/2] fix: remove log sortedErc20Activities --- src/services/evm/erc20.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/evm/erc20.service.ts b/src/services/evm/erc20.service.ts index afece69c0..f742e38b8 100644 --- a/src/services/evm/erc20.service.ts +++ b/src/services/evm/erc20.service.ts @@ -184,7 +184,6 @@ export default class Erc20Service extends BullableService { (a, b) => a.cosmos_tx_id - b.cosmos_tx_id || a.evm_event_id - b.evm_event_id ); - this.logger.info(sortedErc20Activities); await knex .batchInsert( 'erc20_activity',