Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,18 @@ jest.mock('@metamask/eth-query', () =>
},
getTransactionReceipt: (_hash: any, callback: any) => {
const txs: any = [
{ transactionHash: '1337', gasUsed: '0x5208', status: '0x1' },
{ transactionHash: '1111', gasUsed: '0x1108', status: '0x0' },
{
transactionHash: '1337',
gasUsed: '0x5208',
status: '0x1',
transactionIndex: 1337,
},
{
transactionHash: '1111',
gasUsed: '0x1108',
status: '0x0',
transactionIndex: 1111,
},
];
const tx: any = txs.find(
(element: any) => element.transactionHash === _hash,
Expand Down Expand Up @@ -1258,6 +1268,7 @@ describe('TransactionController', () => {
const transactionMeta = controller.state.transactions[0];
expect(transactionMeta.verifiedOnBlockchain).toBe(true);
expect(transactionMeta.transaction.gasUsed).toBe('0x5208');
expect(transactionMeta.txReceipt?.transactionIndex).toBe(1337);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ export class TransactionController extends BaseController<

meta.verifiedOnBlockchain = true;
meta.transaction.gasUsed = txReceipt.gasUsed;
meta.txReceipt = txReceipt;

// According to the Web3 docs:
// TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.
Expand Down
61 changes: 61 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { Hex } from '@metamask/utils';
* @property time - Timestamp associated with this transaction
* @property toSmartContract - Whether transaction recipient is a smart contract
* @property transaction - Underlying Transaction object
* @property txReceipt - Transaction receipt
* @property transactionHash - Hash of a successful transaction
* @property blockNumber - Number of the block where the transaction has been included
*/
Expand Down Expand Up @@ -42,6 +43,7 @@ type TransactionMetaBase = {
blockNumber?: string;
deviceConfirmedOn?: WalletDevice;
verifiedOnBlockchain?: boolean;
txReceipt?: TransactionReceipt;
};

/**
Expand Down Expand Up @@ -99,6 +101,65 @@ export interface Transaction {
estimateGasError?: string;
}

/**
* Standard data concerning a transaction processed by the blockchain.
*/
export interface TransactionReceipt {
/**
* The block hash of the block that this transaction was included in.
*/
blockHash?: string;

/**
* The block number of the block that this transaction was included in.
*/
blockNumber?: string;

/**
* Effective gas price the transaction was charged at.
*/
effectiveGasPrice?: string;

/**
* Gas used in the transaction.
*/
gasUsed?: string;

/**
* Total used gas in hex.
*/
l1Fee?: string;

/**
* All the logs emitted by this transaction.
*/
logs?: Log[];

/**
* The status of the transaction.
*/
status?: string;

/**
* The index of this transaction in the list of transactions included in the block this transaction was mined in.
*/
transactionIndex?: number;
}

/**
* Represents an event that has been included in a transaction using the EVM `LOG` opcode.
*/
export interface Log {
/**
* Address of the contract that generated log.
*/
address?: string;
/**
* List of topics for log.
*/
topics?: string;
}

/**
* The configuration required to fetch transaction data from a RemoteTransactionSource.
*/
Expand Down