Skip to content

Commit

Permalink
catch parsing of bad json for eth txs
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Oct 9, 2023
1 parent 3fb7c1f commit c1499ab
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,46 +93,50 @@ const getERC20DepositsForVaults = async (vaults, tokens, wallet, provider) => {
};

const allTransactionsFor = async vault => {
try {
const url = `https://api.arbiscan.io/api?module=account&action=txlist&address=${vault}&startblock=${startBlock}&endBlock=${endBlock}&sort=asc&apikey=${process.env.ARBISCAN_KEY}`;
return new Promise(resolve => {
https.get(url, res => {
let json = '';
const url = `https://api.arbiscan.io/api?module=account&action=txlist&address=${vault}&startblock=${startBlock}&endBlock=${endBlock}&sort=asc&apikey=${process.env.ARBISCAN_KEY}`;
return new Promise((resolve, reject) => {
https.get(url, res => {
let json = '';

res.on('data', data => {
json += data;
});
res.on('data', data => {
json += data;
});

res.on('end', _ => {
res.on('end', _ => {
try {
resolve(JSON.parse(json));
});
} catch(e) {
reject(e);
}
});
});
});
};

const vaultEthDeposits = async (vault) => {
try {
const allTransactions = await allTransactionsFor(vault);
const ethDeposits = allTransactions.result.filter(tx => tx.value !== '0');
return ethDeposits.map(tx => {
const deposit = tx.to.toLowerCase() === vault.toLowerCase();
return {
type: deposit ? 'deposit' : 'withdrawal',
txHash: tx.hash.toLowerCase(),
blockNumber: parseInt(tx.blockNumber),
asset: 'ETH',
vaultAddress: vault.toLowerCase(),
amount: tx.value,
assetDec: 18,
timestamp: tx.timeStamp
};
});
} catch (e) {
console.log(e);
console.log(`retrying eth deposits ${vault}`);
return await allTransactionsFor(vault);
return await vaultEthDeposits(vault)
}
};

const vaultEthDeposits = async (vault) => {
const allTransactions = await allTransactionsFor(vault);
const ethDeposits = allTransactions.result.filter(tx => tx.value !== '0');
return ethDeposits.map(tx => {
const deposit = tx.to.toLowerCase() === vault.toLowerCase();
return {
type: deposit ? 'deposit' : 'withdrawal',
txHash: tx.hash.toLowerCase(),
blockNumber: parseInt(tx.blockNumber),
asset: 'ETH',
vaultAddress: vault.toLowerCase(),
amount: tx.value,
assetDec: 18,
timestamp: tx.timeStamp
};
});
};

const requestRateLimit = async ms => {
return new Promise(resolve => {
setTimeout(() => resolve(), ms);
Expand Down

0 comments on commit c1499ab

Please sign in to comment.