From 462bd1e37102855a3ce41e77816e3619e6776190 Mon Sep 17 00:00:00 2001 From: Tuan Phan Anh <38557844+fibonacci998@users.noreply.github.com> Date: Fri, 16 Aug 2024 13:56:25 +0700 Subject: [PATCH] fix: proxy contract not found (#885) * fix: remove foreign key proxy_contract in proxy_history * fix: check proxy contract exists or not * fix: search proxy_contract only --- .../evm/crawl_evm_proxy_history.service.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/services/evm/crawl_evm_proxy_history.service.ts b/src/services/evm/crawl_evm_proxy_history.service.ts index cdebeb57f..2920371e0 100644 --- a/src/services/evm/crawl_evm_proxy_history.service.ts +++ b/src/services/evm/crawl_evm_proxy_history.service.ts @@ -139,10 +139,27 @@ export default class CrawlProxyContractEVMService extends BullableService { newProxyHistories.push(EvmProxyHistory.fromJson(newJSONProxy)); } - const newProxyContractsToSave = _.filter( - newProxyHistories, - (proxyContract) => proxyContract.implementation_contract !== null + // check evm_smart_contract if proxy_contract is existed + const foundContractsInDB = _.keyBy( + await EVMSmartContract.query().whereIn( + 'address', + newProxyHistories.map((e) => e.proxy_contract) + ), + 'address' ); + const newProxyContractsToSave: EvmProxyHistory[] = []; + newProxyHistories.forEach((proxyHistory) => { + if ( + proxyHistory.implementation_contract !== null && + foundContractsInDB[proxyHistory.proxy_contract] !== null + ) { + newProxyContractsToSave.push(proxyHistory); + } else { + this.logger.warn( + `This contract address ${proxyHistory.proxy_contract} is not proxy, at tx hash ${proxyHistory.tx_hash}` + ); + } + }); const newProxyContracts: EvmProxyHistory[] = []; await knex.transaction(async (trx) => { if (newProxyContractsToSave.length > 0) {