Fix transaction.index not being populated on some backends (#4591).

This commit is contained in:
Richard Moore 2024-02-14 12:23:48 -05:00
parent 3a1d175c20
commit 7f0e140d5e
2 changed files with 9 additions and 7 deletions

@ -39,7 +39,7 @@ export interface TestBlockchainTransaction {
hash: string,
blockHash: string,
blockNumber: number,
// index: number,
index: number,
type: number,
from: string,
gasPrice: bigint,
@ -297,7 +297,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
hash: "0xccc90ab97a74c952fb3376c4a3efb566a58a10df62eb4d44a61e106fcf10ec61",
blockHash: "0x9653f180a5720f3634816eb945a6d722adee52cc47526f6357ac10adaf368135",
blockNumber: 4097745,
// index: 18,
index: 18,
type: 0,
from: "0x32DEF047DeFd076DB21A2D759aff2A591c972248",
gasPrice: BigInt("0x4a817c800"),
@ -321,7 +321,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
hash: "0x8ff41d0ba5d239acc8c123ff12451a2c15721c838f657e583d355999af4a4349",
blockHash: '0x9d4c3bef68e119841281105da96beb1c7252f357340d7a3355236b3332b197b0',
blockNumber: 12966000,
// index: 185,
index: 185,
type: 2,
from: '0x5afFBa12E9332bbc0E221c8E7BEf7CB7cfB3F281',
to: '0x2258CcD34ae29E6B199b6CD64eb2aEF157df7CdE',
@ -352,7 +352,7 @@ export const testTransaction: Record<TestBlockchainNetwork, Array<TestBlockchain
hash: "0x6c4aef4c26410b1fcbf24d0148e3d66a10cb3e9ad4ca10a71782489688cdd45a",
blockHash: '0xa76eb2ed547798d6010f599902788136f0cd289e2c6df5bbf5242e36e356124d',
blockNumber: 5198187,
// index: 185,
index: 24,
type: 3,
from: '0x1803c760451DC8da8935c7B7E47e1c60910E6986',
to: '0x4f56fFC63c28b72F79b02E91F11a4707bac4043C',

@ -201,6 +201,9 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
const result = object({
hash: formatHash,
// Some nodes do not return this, usually test nodes (like Ganache)
index: allowNull(getNumber, undefined),
type: (value: any) => {
if (value === "0x" || value == null) { return 0; }
return getNumber(value);
@ -212,8 +215,6 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
blockNumber: allowNull(getNumber, null),
transactionIndex: allowNull(getNumber, null),
//confirmations: allowNull(getNumber, null),
from: getAddress,
// either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas) must be set
@ -233,7 +234,8 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
chainId: allowNull(getBigInt, null)
}, {
data: [ "input" ],
gasLimit: [ "gas" ]
gasLimit: [ "gas" ],
index: [ "transactionIndex" ]
})(value);
// If to and creates are empty, populate the creates from the value