@@ -214,9 +214,11 @@ export async function fetchAddressHistoryData(params: {
214214 chainId : number
215215 searchParams : HistoryRequestParameters
216216 maxLimit ?: number | undefined
217+ includeKnownEvents ?: boolean | undefined
217218} ) : Promise < HistoryResponse > {
218219 const { address, chainId, searchParams } = params
219220 const maxLimit = params . maxLimit ?? MAX_LIMIT
221+ const includeKnownEvents = params . includeKnownEvents ?? true
220222 const config = getWagmiConfig ( )
221223
222224 const include =
@@ -426,6 +428,65 @@ export async function fetchAddressHistoryData(params: {
426428 }
427429 }
428430
431+ const finalHashValues = finalHashes . map ( ( entry ) => entry . hash )
432+
433+ const [ receiptRows , txRows ] = await Promise . all ( [
434+ txOnlyPageResult
435+ ? Promise . resolve ( txOnlyPageResult . receiptRows )
436+ : fetchAddressReceiptRowsByHashes ( chainId , finalHashValues ) ,
437+ txOnlyPageResult
438+ ? Promise . resolve ( txOnlyPageResult . txRows )
439+ : fetchAddressHistoryTxDetailsByHashes ( chainId , finalHashValues ) ,
440+ ] )
441+
442+ const receiptMap = new Map (
443+ receiptRows . map ( ( row ) => [ row . tx_hash , row ] as const ) ,
444+ )
445+ const txMap = new Map ( txRows . map ( ( row ) => [ row . hash , row ] as const ) )
446+
447+ if ( ! includeKnownEvents ) {
448+ const transactions = finalHashes . map ( ( hashEntry ) => {
449+ const receipt = receiptMap . get ( hashEntry . hash )
450+ const tx = txMap . get ( hashEntry . hash )
451+
452+ const fromSource = tx ?. from ?? hashEntry . from ?? receipt ?. from ?? address
453+ const toSource = tx ?. to ?? hashEntry . to ?? receipt ?. to ?? null
454+ const valueSource = tx ?. value ?? hashEntry . value ?? 0n
455+ const blockNumberSource =
456+ receipt ?. block_num ?? tx ?. block_num ?? hashEntry . block_num
457+ const timestampSource =
458+ receipt ?. block_timestamp ?? tx ?. block_timestamp ?? 0
459+ const status = toHistoryStatus ( receipt ?. status )
460+
461+ return {
462+ hash : hashEntry . hash ,
463+ blockNumber : toHexQuantity ( blockNumberSource ) ,
464+ timestamp : toFiniteTimestamp ( timestampSource ) ,
465+ from : Address . checksum ( fromSource as Address . Address ) ,
466+ to : toSource ? Address . checksum ( toSource as Address . Address ) : null ,
467+ value : toHexQuantity ( valueSource ) ,
468+ status,
469+ gasUsed : toHexQuantity ( receipt ?. gas_used ) ,
470+ effectiveGasPrice : toHexQuantity ( receipt ?. effective_gas_price ) ,
471+ knownEvents : [ ] ,
472+ }
473+ } )
474+
475+ const finalTransactions = after
476+ ? transactions . filter ( ( transaction ) => transaction . timestamp >= after )
477+ : transactions
478+
479+ return {
480+ transactions : finalTransactions ,
481+ total : after ? finalTransactions . length : totalCount ,
482+ offset,
483+ limit,
484+ hasMore : after ? false : hasMore ,
485+ countCapped : after ? false : countCapped ,
486+ error : null ,
487+ }
488+ }
489+
429490 if ( isTxOnlySource ) {
430491 if ( ! txOnlyPageResult ) {
431492 throw new Error ( 'Missing tx-only history page result' )
@@ -434,8 +495,8 @@ export async function fetchAddressHistoryData(params: {
434495 const transactions = await buildTxOnlyTransactions ( {
435496 address,
436497 hashes : finalHashes ,
437- txRows : txOnlyPageResult . txRows ,
438- receiptRows : txOnlyPageResult . receiptRows ,
498+ txRows,
499+ receiptRows,
439500 logRows : txOnlyPageResult . logRows ,
440501 } )
441502
@@ -450,19 +511,11 @@ export async function fetchAddressHistoryData(params: {
450511 }
451512 }
452513
453- const finalHashValues = finalHashes . map ( ( entry ) => entry . hash )
454-
455- const [ receiptRows , txRows , logRows , transferRows ] = await Promise . all ( [
456- fetchAddressReceiptRowsByHashes ( chainId , finalHashValues ) ,
457- fetchAddressHistoryTxDetailsByHashes ( chainId , finalHashValues ) ,
514+ const [ logRows , transferRows ] = await Promise . all ( [
458515 fetchAddressLogRowsByTxHashes ( chainId , finalHashValues ) ,
459516 fetchAddressTransferRowsByTxHashes ( chainId , finalHashValues ) ,
460517 ] )
461518
462- const receiptMap = new Map (
463- receiptRows . map ( ( row ) => [ row . tx_hash , row ] as const ) ,
464- )
465- const txMap = new Map ( txRows . map ( ( row ) => [ row . hash , row ] as const ) )
466519 const logsByHash = new Map < Hex . Hex , Log [ ] > ( )
467520
468521 for ( const row of logRows ) {
@@ -658,6 +711,7 @@ export async function fetchAddressHistoryExportRows(params: {
658711 limit : pageLimit ,
659712 } ,
660713 maxLimit : CSV_EXPORT_PAGE_SIZE ,
714+ includeKnownEvents : false ,
661715 } )
662716
663717 if ( page . transactions . length === 0 ) break
0 commit comments