Skip to content

Commit 126fcac

Browse files
Feat: add tx index in innerBlock (#160)
1 parent 3888d00 commit 126fcac

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/external/Collector.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ class Collector extends BaseExternal {
350350
})
351351

352352
if (txResponse.data.success && txResponse.data.transactions) {
353-
resultBlock.transactions = txResponse.data.transactions.map((tx: any) => this.decodeTransaction(tx))
353+
resultBlock.transactions = txResponse.data.transactions.map((tx: any, index: number) => {
354+
const decodedTx = this.decodeTransaction(tx, index)
355+
return decodedTx
356+
})
357+
354358
resultBlock.gasUsed = calculateBlockGasUsed(txResponse.data.transactions)
355359

356360
// Extract transaction hash array
@@ -492,7 +496,7 @@ class Collector extends BaseExternal {
492496
return `${apiUrl}${queryParams.length > 0 ? `?${queryParams.join('&')}` : ''}`
493497
}
494498

495-
decodeTransaction(tx: any): readableTransaction {
499+
decodeTransaction(tx: any, index?: number): readableTransaction {
496500
const readableReceipt = tx.wrappedEVMAccount.readableReceipt
497501
nestedCountersInstance.countEvent('collector', 'decodeTransaction')
498502
let result: any = null
@@ -503,7 +507,7 @@ class Collector extends BaseExternal {
503507
} catch (e) {
504508
// fallback to collectors readable receipt
505509
// v, r, s are not available in readableReceipt
506-
return {
510+
const txResult = {
507511
hash: readableReceipt.transactionHash,
508512
blockHash: readableReceipt.blockHash,
509513
blockNumber: readableReceipt.blockNumber,
@@ -516,11 +520,12 @@ class Collector extends BaseExternal {
516520
input: readableReceipt.input,
517521
gasPrice: readableReceipt.gasPrice,
518522
chainId: '0x' + CONFIG.chainId.toString(16),
519-
transactionIndex: readableReceipt.transactionIndex,
523+
transactionIndex: index !== undefined ? '0x' + index.toString(16) : readableReceipt.transactionIndex,
520524
v: '0x',
521525
r: '0x',
522526
s: '0x',
523527
} as readableLegacyTransaction
528+
return txResult
524529
}
525530

526531
if (CONFIG.verbose) console.log(txObj)
@@ -538,7 +543,7 @@ class Collector extends BaseExternal {
538543
input: '0x' + txObj.data.toString('hex'),
539544
gasPrice: readableReceipt.gasPrice,
540545
chainId: '0x' + CONFIG.chainId.toString(16),
541-
transactionIndex: readableReceipt.transactionIndex,
546+
transactionIndex: index !== undefined ? '0x' + index.toString(16) : readableReceipt.transactionIndex,
542547
v: '0x' + txObj.v?.toString('hex'),
543548
r: '0x' + txObj.r?.toString('hex'),
544549
s: '0x' + txObj.s?.toString('hex'),

0 commit comments

Comments
 (0)