Fix ERC-20 transfers showing as 0 ETH due to dedup bug
All checks were successful
check / check (push) Successful in 14s
All checks were successful
check / check (push) Successful in 14s
When sending an ERC-20 token, Blockscout returns the same tx hash from both the /transactions endpoint (as a 0 ETH contract call) and the /token-transfers endpoint (as the actual token transfer with amount and symbol). The old dedup logic kept the 0 ETH version and skipped the token transfer. Now token transfers replace normal transactions with the same hash, since the token transfer has the real amount, symbol, and contract address.
This commit is contained in:
@@ -94,19 +94,22 @@ async function fetchRecentTransactions(address, blockscoutUrl, count = 25) {
|
||||
const txJson = txResp.ok ? await txResp.json() : {};
|
||||
const ttJson = ttResp.ok ? await ttResp.json() : {};
|
||||
|
||||
const txs = [];
|
||||
const txsByHash = new Map();
|
||||
|
||||
for (const tx of txJson.items || []) {
|
||||
txs.push(parseTx(tx, addrLower));
|
||||
txsByHash.set(tx.hash, parseTx(tx, addrLower));
|
||||
}
|
||||
|
||||
// Deduplicate: skip token transfers whose tx hash is already present
|
||||
const seenHashes = new Set(txs.map((t) => t.hash));
|
||||
// When a token transfer shares a hash with a normal tx, the normal tx
|
||||
// is the contract call (0 ETH) and the token transfer has the real
|
||||
// amount and symbol. Replace the normal tx with the token transfer.
|
||||
for (const tt of ttJson.items || []) {
|
||||
if (seenHashes.has(tt.transaction_hash)) continue;
|
||||
txs.push(parseTokenTransfer(tt, addrLower));
|
||||
const parsed = parseTokenTransfer(tt, addrLower);
|
||||
txsByHash.set(parsed.hash, parsed);
|
||||
}
|
||||
|
||||
const txs = [...txsByHash.values()];
|
||||
|
||||
txs.sort((a, b) => b.blockNumber - a.blockNumber);
|
||||
const result = txs.slice(0, count);
|
||||
log.debugf("fetchRecentTransactions done, count:", result.length);
|
||||
|
||||
Reference in New Issue
Block a user