Skip to content

Commit 7f0e140

Browse files
committed
Fix transaction.index not being populated on some backends (#4591).
1 parent 3a1d175 commit 7f0e140

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src.ts/_tests/blockchain-data.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface TestBlockchainTransaction {
3939
hash: string,
4040
blockHash: string,
4141
blockNumber: number,
42-
// index: number,
42+
index: number,
4343
type: number,
4444
from: string,
4545
gasPrice: bigint,
@@ -297,7 +297,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
297297
hash: "0xccc90ab97a74c952fb3376c4a3efb566a58a10df62eb4d44a61e106fcf10ec61",
298298
blockHash: "0x9653f180a5720f3634816eb945a6d722adee52cc47526f6357ac10adaf368135",
299299
blockNumber: 4097745,
300-
// index: 18,
300+
index: 18,
301301
type: 0,
302302
from: "0x32DEF047DeFd076DB21A2D759aff2A591c972248",
303303
gasPrice: BigInt("0x4a817c800"),
@@ -321,7 +321,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
321321
hash: "0x8ff41d0ba5d239acc8c123ff12451a2c15721c838f657e583d355999af4a4349",
322322
blockHash: '0x9d4c3bef68e119841281105da96beb1c7252f357340d7a3355236b3332b197b0',
323323
blockNumber: 12966000,
324-
// index: 185,
324+
index: 185,
325325
type: 2,
326326
from: '0x5afFBa12E9332bbc0E221c8E7BEf7CB7cfB3F281',
327327
to: '0x2258CcD34ae29E6B199b6CD64eb2aEF157df7CdE',
@@ -352,7 +352,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
352352
hash: "0x6c4aef4c26410b1fcbf24d0148e3d66a10cb3e9ad4ca10a71782489688cdd45a",
353353
blockHash: '0xa76eb2ed547798d6010f599902788136f0cd289e2c6df5bbf5242e36e356124d',
354354
blockNumber: 5198187,
355-
// index: 185,
355+
index: 24,
356356
type: 3,
357357
from: '0x1803c760451DC8da8935c7B7E47e1c60910E6986',
358358
to: '0x4f56fFC63c28b72F79b02E91F11a4707bac4043C',

src.ts/providers/format.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
201201
const result = object({
202202
hash: formatHash,
203203

204+
// Some nodes do not return this, usually test nodes (like Ganache)
205+
index: allowNull(getNumber, undefined),
206+
204207
type: (value: any) => {
205208
if (value === "0x" || value == null) { return 0; }
206209
return getNumber(value);
@@ -212,8 +215,6 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
212215
blockNumber: allowNull(getNumber, null),
213216
transactionIndex: allowNull(getNumber, null),
214217

215-
//confirmations: allowNull(getNumber, null),
216-
217218
from: getAddress,
218219

219220
// either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas) must be set
@@ -233,7 +234,8 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
233234
chainId: allowNull(getBigInt, null)
234235
}, {
235236
data: [ "input" ],
236-
gasLimit: [ "gas" ]
237+
gasLimit: [ "gas" ],
238+
index: [ "transactionIndex" ]
237239
})(value);
238240

239241
// If to and creates are empty, populate the creates from the value

0 commit comments

Comments
 (0)