@metamask/transaction-controller 8.0.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -1
- package/dist/EtherscanRemoteTransactionSource.d.ts +6 -6
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +25 -13
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/IncomingTransactionHelper.d.ts +16 -15
- package/dist/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/IncomingTransactionHelper.js +144 -100
- package/dist/IncomingTransactionHelper.js.map +1 -1
- package/dist/TransactionController.d.ts +56 -29
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +165 -76
- package/dist/TransactionController.js.map +1 -1
- package/dist/constants.d.ts +119 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +124 -0
- package/dist/constants.js.map +1 -0
- package/dist/etherscan.d.ts +10 -11
- package/dist/etherscan.d.ts.map +1 -1
- package/dist/etherscan.js +29 -27
- package/dist/etherscan.js.map +1 -1
- package/dist/types.d.ts +173 -47
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Hardfork
|
|
2
|
+
import { Hardfork } from '@ethereumjs/common';
|
|
3
3
|
import type { TypedTransaction } from '@ethereumjs/tx';
|
|
4
4
|
import type { AddApprovalRequest } from '@metamask/approval-controller';
|
|
5
5
|
import type { BaseConfig, BaseState, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
@@ -69,6 +69,9 @@ export interface TransactionState extends BaseState {
|
|
|
69
69
|
methodData: {
|
|
70
70
|
[key: string]: MethodData;
|
|
71
71
|
};
|
|
72
|
+
lastFetchedBlockNumbers: {
|
|
73
|
+
[key: string]: number;
|
|
74
|
+
};
|
|
72
75
|
}
|
|
73
76
|
/**
|
|
74
77
|
* Multiplier used to determine a transaction's increased gas fee during cancellation
|
|
@@ -121,20 +124,33 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
121
124
|
* Creates a TransactionController instance.
|
|
122
125
|
*
|
|
123
126
|
* @param options - The controller options.
|
|
127
|
+
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
124
128
|
* @param options.getNetworkState - Gets the state of the network controller.
|
|
129
|
+
* @param options.getSelectedAddress - Gets the address of the currently selected account.
|
|
130
|
+
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
131
|
+
* @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
|
|
132
|
+
* @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
|
|
133
|
+
* @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
|
|
134
|
+
* @param options.incomingTransactions.updateTransactions - Whether or not to update local transactions using remote transaction data.
|
|
135
|
+
* @param options.messenger - The controller messenger.
|
|
125
136
|
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
126
137
|
* @param options.provider - The provider used to create the underlying EthQuery instance.
|
|
127
|
-
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
128
|
-
* @param options.messenger - The controller messenger.
|
|
129
138
|
* @param config - Initial options used to configure this controller.
|
|
130
139
|
* @param state - Initial state to set on this controller.
|
|
131
140
|
*/
|
|
132
|
-
constructor({
|
|
141
|
+
constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions, messenger, onNetworkStateChange, provider, }: {
|
|
142
|
+
blockTracker: BlockTracker;
|
|
133
143
|
getNetworkState: () => NetworkState;
|
|
144
|
+
getSelectedAddress: () => string;
|
|
145
|
+
incomingTransactions: {
|
|
146
|
+
apiKey?: string;
|
|
147
|
+
includeTokenTransfers?: boolean;
|
|
148
|
+
isEnabled?: () => boolean;
|
|
149
|
+
updateTransactions?: boolean;
|
|
150
|
+
};
|
|
151
|
+
messenger: TransactionControllerMessenger;
|
|
134
152
|
onNetworkStateChange: (listener: (state: NetworkState) => void) => void;
|
|
135
153
|
provider: Provider;
|
|
136
|
-
blockTracker: BlockTracker;
|
|
137
|
-
messenger: TransactionControllerMessenger;
|
|
138
154
|
}, config?: Partial<TransactionConfig>, state?: Partial<TransactionState>);
|
|
139
155
|
/**
|
|
140
156
|
* Starts a new polling interval.
|
|
@@ -155,22 +171,24 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
155
171
|
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
156
172
|
*
|
|
157
173
|
* @param transaction - The transaction object to add.
|
|
158
|
-
* @param
|
|
159
|
-
* @param deviceConfirmedOn - An enum to indicate what device
|
|
174
|
+
* @param opts - Additional options to control how the transaction is added.
|
|
175
|
+
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
176
|
+
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
177
|
+
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
160
178
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
161
179
|
*/
|
|
162
|
-
addTransaction(transaction: Transaction, origin
|
|
163
|
-
|
|
180
|
+
addTransaction(transaction: Transaction, { deviceConfirmedOn, origin, requireApproval, }?: {
|
|
181
|
+
deviceConfirmedOn?: WalletDevice;
|
|
182
|
+
origin?: string;
|
|
183
|
+
requireApproval?: boolean | undefined;
|
|
184
|
+
}): Promise<Result>;
|
|
185
|
+
startIncomingTransactionPolling(): void;
|
|
186
|
+
stopIncomingTransactionPolling(): void;
|
|
187
|
+
updateIncomingTransactions(): Promise<void>;
|
|
164
188
|
/**
|
|
165
|
-
*
|
|
166
|
-
* specifying which chain, network, hardfork and EIPs to support for
|
|
167
|
-
* a transaction. By referencing this configuration, and analyzing the fields
|
|
168
|
-
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
169
|
-
* transaction type to use.
|
|
170
|
-
*
|
|
171
|
-
* @returns {Common} common configuration object
|
|
189
|
+
* Creates approvals for all unapproved transactions persisted.
|
|
172
190
|
*/
|
|
173
|
-
|
|
191
|
+
initApprovals(): void;
|
|
174
192
|
/**
|
|
175
193
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
176
194
|
* and emitting a `<tx.id>:finished` hub event.
|
|
@@ -217,18 +235,12 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
217
235
|
*
|
|
218
236
|
* @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
|
|
219
237
|
* current network. If `true`, all transactions are wiped.
|
|
238
|
+
* @param address - If specified, only transactions originating from this address will be
|
|
239
|
+
* wiped on current network.
|
|
220
240
|
*/
|
|
221
|
-
wipeTransactions(ignoreNetwork?: boolean): void;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
* returned, but the `fromBlock` option can be given to filter just for transactions from a
|
|
225
|
-
* specific block onward.
|
|
226
|
-
*
|
|
227
|
-
* @param address - The address to fetch the transactions for.
|
|
228
|
-
* @param opt - Object containing optional data, fromBlock and Etherscan API key.
|
|
229
|
-
* @returns The block number of the latest incoming transaction.
|
|
230
|
-
*/
|
|
231
|
-
fetchAll(address: string, opt?: FetchAllOptions): Promise<string | void>;
|
|
241
|
+
wipeTransactions(ignoreNetwork?: boolean, address?: string): void;
|
|
242
|
+
startIncomingTransactionProcessing(): void;
|
|
243
|
+
stopIncomingTransactionProcessing(): void;
|
|
232
244
|
private processApproval;
|
|
233
245
|
/**
|
|
234
246
|
* Approves a transaction and updates it's status in state. If this is not a
|
|
@@ -296,6 +308,21 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
296
308
|
private getTransaction;
|
|
297
309
|
private getApprovalId;
|
|
298
310
|
private isTransactionCompleted;
|
|
311
|
+
private getChainAndNetworkId;
|
|
312
|
+
private prepareUnsignedEthTx;
|
|
313
|
+
/**
|
|
314
|
+
* `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
|
|
315
|
+
* specifying which chain, network, hardfork and EIPs to support for
|
|
316
|
+
* a transaction. By referencing this configuration, and analyzing the fields
|
|
317
|
+
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
318
|
+
* transaction type to use.
|
|
319
|
+
*
|
|
320
|
+
* @returns common configuration object
|
|
321
|
+
*/
|
|
322
|
+
private getCommonConfiguration;
|
|
323
|
+
private onIncomingTransactions;
|
|
324
|
+
private onUpdatedLastFetchedBlockNumbers;
|
|
325
|
+
private generateDappSuggestedGasFees;
|
|
299
326
|
}
|
|
300
327
|
export default TransactionController;
|
|
301
328
|
//# sourceMappingURL=TransactionController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAc3D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,YAAY,EAEb,MAAM,SAAS,CAAC;AAgBj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Aa,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;IAgC1D,kCAAkC;IAIlC,iCAAiC;YAInB,eAAe;IAyE7B;;;;;;;OAOG;YACW,kBAAkB;IAuFhC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAezB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,wBAAwB;IA0BhC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;YACW,oCAAoC;IAkElD;;;;;;;;OAQG;YACW,4BAA4B;YAa5B,eAAe;IAsB7B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,oBAAoB;IAS5B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,sBAAsB;IA0B9B,OAAO,CAAC,gCAAgC;IAaxC,OAAO,CAAC,4BAA4B;CAqCrC;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -50,15 +50,21 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
50
50
|
* Creates a TransactionController instance.
|
|
51
51
|
*
|
|
52
52
|
* @param options - The controller options.
|
|
53
|
+
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
53
54
|
* @param options.getNetworkState - Gets the state of the network controller.
|
|
55
|
+
* @param options.getSelectedAddress - Gets the address of the currently selected account.
|
|
56
|
+
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
57
|
+
* @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
|
|
58
|
+
* @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
|
|
59
|
+
* @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
|
|
60
|
+
* @param options.incomingTransactions.updateTransactions - Whether or not to update local transactions using remote transaction data.
|
|
61
|
+
* @param options.messenger - The controller messenger.
|
|
54
62
|
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
55
63
|
* @param options.provider - The provider used to create the underlying EthQuery instance.
|
|
56
|
-
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
57
|
-
* @param options.messenger - The controller messenger.
|
|
58
64
|
* @param config - Initial options used to configure this controller.
|
|
59
65
|
* @param state - Initial state to set on this controller.
|
|
60
66
|
*/
|
|
61
|
-
constructor({
|
|
67
|
+
constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, provider, }, config, state) {
|
|
62
68
|
super(config, state);
|
|
63
69
|
this.mutex = new async_mutex_1.Mutex();
|
|
64
70
|
/**
|
|
@@ -76,6 +82,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
76
82
|
this.defaultState = {
|
|
77
83
|
methodData: {},
|
|
78
84
|
transactions: [],
|
|
85
|
+
lastFetchedBlockNumbers: {},
|
|
79
86
|
};
|
|
80
87
|
this.initialize();
|
|
81
88
|
this.provider = provider;
|
|
@@ -90,11 +97,19 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
90
97
|
getConfirmedTransactions: (address) => (0, utils_1.getAndFormatTransactionsForNonceTracker)(address, types_1.TransactionStatus.confirmed, this.state.transactions),
|
|
91
98
|
});
|
|
92
99
|
this.incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
|
|
100
|
+
blockTracker,
|
|
101
|
+
getCurrentAccount: getSelectedAddress,
|
|
93
102
|
getNetworkState,
|
|
94
|
-
|
|
103
|
+
isEnabled: incomingTransactions.isEnabled,
|
|
104
|
+
remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
|
|
105
|
+
apiKey: incomingTransactions.apiKey,
|
|
106
|
+
includeTokenTransfers: incomingTransactions.includeTokenTransfers,
|
|
107
|
+
}),
|
|
95
108
|
transactionLimit: this.config.txHistoryLimit,
|
|
96
|
-
|
|
109
|
+
updateTransactions: incomingTransactions.updateTransactions,
|
|
97
110
|
});
|
|
111
|
+
this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
|
|
112
|
+
this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
|
|
98
113
|
onNetworkStateChange(() => {
|
|
99
114
|
this.ethQuery = new eth_query_1.default(this.provider);
|
|
100
115
|
this.registry = new eth_method_registry_1.default({ provider: this.provider });
|
|
@@ -160,26 +175,30 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
160
175
|
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
161
176
|
*
|
|
162
177
|
* @param transaction - The transaction object to add.
|
|
163
|
-
* @param
|
|
164
|
-
* @param deviceConfirmedOn - An enum to indicate what device
|
|
178
|
+
* @param opts - Additional options to control how the transaction is added.
|
|
179
|
+
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
180
|
+
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
181
|
+
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
165
182
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
166
183
|
*/
|
|
167
|
-
addTransaction(transaction, origin,
|
|
184
|
+
addTransaction(transaction, { deviceConfirmedOn, origin, requireApproval, } = {}) {
|
|
168
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
const {
|
|
186
|
+
const { chainId, networkId } = this.getChainAndNetworkId();
|
|
170
187
|
const { transactions } = this.state;
|
|
171
188
|
transaction = (0, utils_1.normalizeTransaction)(transaction);
|
|
172
189
|
(0, utils_1.validateTransaction)(transaction);
|
|
190
|
+
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(transaction, origin);
|
|
173
191
|
const transactionMeta = {
|
|
174
192
|
id: (0, uuid_1.v1)(),
|
|
175
193
|
networkID: networkId !== null && networkId !== void 0 ? networkId : undefined,
|
|
176
|
-
chainId
|
|
194
|
+
chainId,
|
|
177
195
|
origin,
|
|
178
196
|
status: types_1.TransactionStatus.unapproved,
|
|
179
197
|
time: Date.now(),
|
|
180
198
|
transaction,
|
|
181
199
|
deviceConfirmedOn,
|
|
182
200
|
verifiedOnBlockchain: false,
|
|
201
|
+
dappSuggestedGasFees,
|
|
183
202
|
};
|
|
184
203
|
try {
|
|
185
204
|
const { gas, estimateGasError } = yield this.estimateGas(transaction);
|
|
@@ -194,40 +213,39 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
194
213
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
195
214
|
this.hub.emit(`unapprovedTransaction`, transactionMeta);
|
|
196
215
|
return {
|
|
197
|
-
result: this.processApproval(transactionMeta
|
|
216
|
+
result: this.processApproval(transactionMeta, {
|
|
217
|
+
requireApproval,
|
|
218
|
+
}),
|
|
198
219
|
transactionMeta,
|
|
199
220
|
};
|
|
200
221
|
});
|
|
201
222
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
223
|
+
startIncomingTransactionPolling() {
|
|
224
|
+
this.incomingTransactionHelper.start();
|
|
225
|
+
}
|
|
226
|
+
stopIncomingTransactionPolling() {
|
|
227
|
+
this.incomingTransactionHelper.stop();
|
|
228
|
+
}
|
|
229
|
+
updateIncomingTransactions() {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
yield this.incomingTransactionHelper.update();
|
|
206
232
|
});
|
|
207
233
|
}
|
|
208
234
|
/**
|
|
209
|
-
*
|
|
210
|
-
* specifying which chain, network, hardfork and EIPs to support for
|
|
211
|
-
* a transaction. By referencing this configuration, and analyzing the fields
|
|
212
|
-
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
213
|
-
* transaction type to use.
|
|
214
|
-
*
|
|
215
|
-
* @returns {Common} common configuration object
|
|
235
|
+
* Creates approvals for all unapproved transactions persisted.
|
|
216
236
|
*/
|
|
217
|
-
|
|
218
|
-
const { networkId,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
237
|
+
initApprovals() {
|
|
238
|
+
const { networkId, chainId } = this.getChainAndNetworkId();
|
|
239
|
+
const unapprovedTxs = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.unapproved &&
|
|
240
|
+
(0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
|
|
241
|
+
for (const txMeta of unapprovedTxs) {
|
|
242
|
+
this.processApproval(txMeta, {
|
|
243
|
+
shouldShowRequest: false,
|
|
244
|
+
}).catch((error) => {
|
|
245
|
+
/* istanbul ignore next */
|
|
246
|
+
console.error('Error during persisted transaction approval', error);
|
|
247
|
+
});
|
|
223
248
|
}
|
|
224
|
-
const customChainParams = {
|
|
225
|
-
name,
|
|
226
|
-
chainId: parseInt(chainId, 16),
|
|
227
|
-
networkId: networkId === null ? NaN : parseInt(networkId, undefined),
|
|
228
|
-
defaultHardfork: exports.HARDFORK,
|
|
229
|
-
};
|
|
230
|
-
return common_1.Common.custom(customChainParams);
|
|
231
249
|
}
|
|
232
250
|
/**
|
|
233
251
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
@@ -432,8 +450,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
432
450
|
queryTransactionStatuses() {
|
|
433
451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
434
452
|
const { transactions } = this.state;
|
|
435
|
-
const {
|
|
436
|
-
const { chainId: currentChainId } = providerConfig;
|
|
453
|
+
const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
|
|
437
454
|
let gotUpdates = false;
|
|
438
455
|
yield (0, controller_utils_1.safelyExecute)(() => Promise.all(transactions.map((meta, index) => __awaiter(this, void 0, void 0, function* () {
|
|
439
456
|
// Using fallback to networkID only when there is no chainId present.
|
|
@@ -474,58 +491,49 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
474
491
|
*
|
|
475
492
|
* @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
|
|
476
493
|
* current network. If `true`, all transactions are wiped.
|
|
494
|
+
* @param address - If specified, only transactions originating from this address will be
|
|
495
|
+
* wiped on current network.
|
|
477
496
|
*/
|
|
478
|
-
wipeTransactions(ignoreNetwork) {
|
|
497
|
+
wipeTransactions(ignoreNetwork, address) {
|
|
479
498
|
/* istanbul ignore next */
|
|
480
|
-
if (ignoreNetwork) {
|
|
499
|
+
if (ignoreNetwork && !address) {
|
|
481
500
|
this.update({ transactions: [] });
|
|
482
501
|
return;
|
|
483
502
|
}
|
|
484
|
-
const {
|
|
485
|
-
const { chainId
|
|
486
|
-
|
|
503
|
+
const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
|
|
504
|
+
const newTransactions = this.state.transactions.filter(({ networkID, chainId, transaction }) => {
|
|
505
|
+
var _a;
|
|
487
506
|
// Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.
|
|
488
|
-
const
|
|
507
|
+
const isMatchingNetwork = ignoreNetwork ||
|
|
508
|
+
chainId === currentChainId ||
|
|
489
509
|
(!chainId && networkID === currentNetworkID);
|
|
490
|
-
|
|
510
|
+
if (!isMatchingNetwork) {
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
const isMatchingAddress = !address || ((_a = transaction.from) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase();
|
|
514
|
+
return !isMatchingAddress;
|
|
491
515
|
});
|
|
492
516
|
this.update({
|
|
493
517
|
transactions: this.trimTransactionsForState(newTransactions),
|
|
494
518
|
});
|
|
495
519
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
* @param address - The address to fetch the transactions for.
|
|
502
|
-
* @param opt - Object containing optional data, fromBlock and Etherscan API key.
|
|
503
|
-
* @returns The block number of the latest incoming transaction.
|
|
504
|
-
*/
|
|
505
|
-
fetchAll(address, opt) {
|
|
506
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
-
const { transactions: localTransactions } = this.state;
|
|
508
|
-
const { updateRequired, transactions, latestBlockNumber } = yield this.incomingTransactionHelper.reconcile({
|
|
509
|
-
address,
|
|
510
|
-
localTransactions,
|
|
511
|
-
fromBlock: opt === null || opt === void 0 ? void 0 : opt.fromBlock,
|
|
512
|
-
apiKey: opt === null || opt === void 0 ? void 0 : opt.etherscanApiKey,
|
|
513
|
-
});
|
|
514
|
-
if (updateRequired) {
|
|
515
|
-
this.update({
|
|
516
|
-
transactions: this.trimTransactionsForState(transactions),
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
return latestBlockNumber;
|
|
520
|
-
});
|
|
520
|
+
startIncomingTransactionProcessing() {
|
|
521
|
+
this.incomingTransactionHelper.start();
|
|
522
|
+
}
|
|
523
|
+
stopIncomingTransactionProcessing() {
|
|
524
|
+
this.incomingTransactionHelper.stop();
|
|
521
525
|
}
|
|
522
|
-
processApproval(transactionMeta) {
|
|
526
|
+
processApproval(transactionMeta, { requireApproval, shouldShowRequest = true, }) {
|
|
523
527
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
528
|
const transactionId = transactionMeta.id;
|
|
525
529
|
let resultCallbacks;
|
|
526
530
|
try {
|
|
527
|
-
|
|
528
|
-
|
|
531
|
+
if (requireApproval !== false) {
|
|
532
|
+
const acceptResult = yield this.requestApproval(transactionMeta, {
|
|
533
|
+
shouldShowRequest,
|
|
534
|
+
});
|
|
535
|
+
resultCallbacks = acceptResult.resultCallbacks;
|
|
536
|
+
}
|
|
529
537
|
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
530
538
|
if (meta && !isCompleted) {
|
|
531
539
|
yield this.approveTransaction(transactionId);
|
|
@@ -574,8 +582,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
574
582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
575
583
|
const { transactions } = this.state;
|
|
576
584
|
const releaseLock = yield this.mutex.acquire();
|
|
577
|
-
const {
|
|
578
|
-
const { chainId } = providerConfig;
|
|
585
|
+
const { chainId } = this.getChainAndNetworkId();
|
|
579
586
|
const index = transactions.findIndex(({ id }) => transactionID === id);
|
|
580
587
|
const transactionMeta = transactions[index];
|
|
581
588
|
const { transaction: { nonce, from }, } = transactionMeta;
|
|
@@ -733,8 +740,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
733
740
|
if (!txReceipt) {
|
|
734
741
|
return [meta, false];
|
|
735
742
|
}
|
|
743
|
+
const txBlock = yield (0, controller_utils_1.query)(this.ethQuery, 'getBlockByHash', [
|
|
744
|
+
txReceipt.blockHash,
|
|
745
|
+
]);
|
|
736
746
|
meta.verifiedOnBlockchain = true;
|
|
737
747
|
meta.transaction.gasUsed = txReceipt.gasUsed;
|
|
748
|
+
meta.txReceipt = txReceipt;
|
|
749
|
+
meta.baseFeePerGas = txBlock === null || txBlock === void 0 ? void 0 : txBlock.baseFeePerGas;
|
|
738
750
|
// According to the Web3 docs:
|
|
739
751
|
// TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.
|
|
740
752
|
if (Number(txReceipt.status) === 0) {
|
|
@@ -789,7 +801,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
789
801
|
return Number(txReceipt.status) === 0;
|
|
790
802
|
});
|
|
791
803
|
}
|
|
792
|
-
requestApproval(txMeta) {
|
|
804
|
+
requestApproval(txMeta, { shouldShowRequest }) {
|
|
793
805
|
return __awaiter(this, void 0, void 0, function* () {
|
|
794
806
|
const id = this.getApprovalId(txMeta);
|
|
795
807
|
const { origin } = txMeta;
|
|
@@ -801,7 +813,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
801
813
|
type,
|
|
802
814
|
requestData,
|
|
803
815
|
expectsResult: true,
|
|
804
|
-
},
|
|
816
|
+
}, shouldShowRequest));
|
|
805
817
|
});
|
|
806
818
|
}
|
|
807
819
|
getTransaction(transactionID) {
|
|
@@ -819,6 +831,83 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
819
831
|
const isCompleted = this.isLocalFinalState(transaction.status);
|
|
820
832
|
return { meta: transaction, isCompleted };
|
|
821
833
|
}
|
|
834
|
+
getChainAndNetworkId() {
|
|
835
|
+
const { networkId, providerConfig } = this.getNetworkState();
|
|
836
|
+
const chainId = providerConfig === null || providerConfig === void 0 ? void 0 : providerConfig.chainId;
|
|
837
|
+
return { networkId, chainId };
|
|
838
|
+
}
|
|
839
|
+
prepareUnsignedEthTx(txParams) {
|
|
840
|
+
return tx_1.TransactionFactory.fromTxData(txParams, {
|
|
841
|
+
common: this.getCommonConfiguration(),
|
|
842
|
+
freeze: false,
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
|
|
847
|
+
* specifying which chain, network, hardfork and EIPs to support for
|
|
848
|
+
* a transaction. By referencing this configuration, and analyzing the fields
|
|
849
|
+
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
850
|
+
* transaction type to use.
|
|
851
|
+
*
|
|
852
|
+
* @returns common configuration object
|
|
853
|
+
*/
|
|
854
|
+
getCommonConfiguration() {
|
|
855
|
+
const { networkId, providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
|
|
856
|
+
if (chain !== controller_utils_1.RPC &&
|
|
857
|
+
chain !== controller_utils_1.NetworkType['linea-goerli'] &&
|
|
858
|
+
chain !== controller_utils_1.NetworkType['linea-mainnet']) {
|
|
859
|
+
return new common_1.Common({ chain, hardfork: exports.HARDFORK });
|
|
860
|
+
}
|
|
861
|
+
const customChainParams = {
|
|
862
|
+
name,
|
|
863
|
+
chainId: parseInt(chainId, 16),
|
|
864
|
+
networkId: networkId === null ? NaN : parseInt(networkId, undefined),
|
|
865
|
+
defaultHardfork: exports.HARDFORK,
|
|
866
|
+
};
|
|
867
|
+
return common_1.Common.custom(customChainParams);
|
|
868
|
+
}
|
|
869
|
+
onIncomingTransactions({ added, updated, }) {
|
|
870
|
+
const { transactions: currentTransactions } = this.state;
|
|
871
|
+
const updatedTransactions = [
|
|
872
|
+
...added,
|
|
873
|
+
...currentTransactions.map((originalTransaction) => {
|
|
874
|
+
const updatedTransaction = updated.find(({ transactionHash }) => transactionHash === originalTransaction.transactionHash);
|
|
875
|
+
return updatedTransaction !== null && updatedTransaction !== void 0 ? updatedTransaction : originalTransaction;
|
|
876
|
+
}),
|
|
877
|
+
];
|
|
878
|
+
this.update({
|
|
879
|
+
transactions: this.trimTransactionsForState(updatedTransactions),
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
onUpdatedLastFetchedBlockNumbers({ lastFetchedBlockNumbers, blockNumber, }) {
|
|
883
|
+
this.update({ lastFetchedBlockNumbers });
|
|
884
|
+
this.hub.emit('incomingTransactionBlock', blockNumber);
|
|
885
|
+
}
|
|
886
|
+
generateDappSuggestedGasFees(transaction, origin) {
|
|
887
|
+
if (!origin || origin === controller_utils_1.ORIGIN_METAMASK) {
|
|
888
|
+
return undefined;
|
|
889
|
+
}
|
|
890
|
+
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = transaction;
|
|
891
|
+
if (gasPrice === undefined &&
|
|
892
|
+
maxFeePerGas === undefined &&
|
|
893
|
+
maxPriorityFeePerGas === undefined &&
|
|
894
|
+
gas === undefined) {
|
|
895
|
+
return undefined;
|
|
896
|
+
}
|
|
897
|
+
const dappSuggestedGasFees = {};
|
|
898
|
+
if (gasPrice !== undefined) {
|
|
899
|
+
dappSuggestedGasFees.gasPrice = gasPrice;
|
|
900
|
+
}
|
|
901
|
+
else if (maxFeePerGas !== undefined ||
|
|
902
|
+
maxPriorityFeePerGas !== undefined) {
|
|
903
|
+
dappSuggestedGasFees.maxFeePerGas = maxFeePerGas;
|
|
904
|
+
dappSuggestedGasFees.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
905
|
+
}
|
|
906
|
+
if (gas !== undefined) {
|
|
907
|
+
dappSuggestedGasFees.gas = gas;
|
|
908
|
+
}
|
|
909
|
+
return dappSuggestedGasFees;
|
|
910
|
+
}
|
|
822
911
|
}
|
|
823
912
|
exports.TransactionController = TransactionController;
|
|
824
913
|
exports.default = TransactionController;
|