From e576b81ef943c0e13255e32a9fbcc1e6e841d2eb Mon Sep 17 00:00:00 2001 From: peersky Date: Thu, 4 Apr 2024 20:53:37 +0800 Subject: [PATCH 1/2] added strategy to scrap internal transactions --- plugins/import/import.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/import/import.ts b/plugins/import/import.ts index 34c2109c0..7fc918924 100644 --- a/plugins/import/import.ts +++ b/plugins/import/import.ts @@ -104,13 +104,13 @@ function paramString(params: { [k: string]: string | number }) { return Object.entries(params).map(([k,v]) => `${k}=${v}`).join('&'); } -async function pullFirstTransactionForContract(network: string, address: string) { +async function pullFirstTransactionForContract (network: string, address: string, startblock = 0, endblock=99999999) { const params = { module: 'account', action: 'txlist', address, - startblock: 0, - endblock: 99999999, + startblock: startblock, + endblock: endblock, page: 1, offset: 10, sort: 'asc', @@ -129,10 +129,32 @@ async function pullFirstTransactionForContract(network: string, address: string) return contractCreationCode.slice(2); } +async function pullFirstInternalTransactionForContract(network: string, address: string,startblock = 0, endblock=99999999) { + const params = { + module: 'account', + action: 'txlistinternal', + address, + startblock: startblock, + endblock: endblock, + page: 1, + offset: 10, + sort: 'asc', + apikey: getEtherscanApiKey(network) + }; + const url = `${getEtherscanApiUrl(network)}?${paramString(params)}`; + const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]'}})}`; + debug(`Attempting to pull Contract Creation code from first internal tx at ${debugUrl}`); + const response = await get(url, {}); + return response.result.find(tx => tx.isError == "0") +} + + + async function getContractCreationCode(network: string, address: string) { const strategies = [ scrapeContractCreationCodeFromEtherscan, - pullFirstTransactionForContract + pullFirstTransactionForContract, + pullFirstInternalTransactionForContract ]; let errors = []; for (const strategy of strategies) { From 5a82cc306fedb728694e6d6264dd395159cc01c5 Mon Sep 17 00:00:00 2001 From: Peersky <61459744+peersky@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:26:40 +0800 Subject: [PATCH 2/2] Update import.ts --- plugins/import/import.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/import/import.ts b/plugins/import/import.ts index ece7e2b97..7e08ec5f2 100644 --- a/plugins/import/import.ts +++ b/plugins/import/import.ts @@ -169,7 +169,7 @@ async function pullFirstInternalTransactionForContract(network: string, address: const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]'}})}`; debug(`Attempting to pull Contract Creation code from first internal tx at ${debugUrl}`); const response = await get(url, {}); - return response.result.find(tx => tx.isError == "0") + return response.result.find(tx => tx.isError == "0").input }