Skip to content

Commit

Permalink
Fix transaction.index not being populated on some backends (#4591).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 14, 2024
1 parent 3a1d175 commit 7f0e140
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src.ts/_tests/blockchain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface TestBlockchainTransaction {
hash: string,
blockHash: string,
blockNumber: number,
// index: number,
index: number,
type: number,
from: string,
gasPrice: bigint,
Expand Down Expand Up @@ -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"),
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 5 additions & 3 deletions src.ts/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7f0e140

Please sign in to comment.