Skip to content

Commit

Permalink
added strategy to scrap internal transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
peersky committed Apr 4, 2024
1 parent cb53e0b commit e576b81
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions plugins/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand Down

0 comments on commit e576b81

Please sign in to comment.