@metamask-previews/transaction-controller 10.0.0-preview.f0f357a → 11.0.0-preview.56ca173
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 +27 -1
- package/dist/EtherscanRemoteTransactionSource.d.ts +2 -2
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +41 -18
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/IncomingTransactionHelper.js +22 -11
- package/dist/IncomingTransactionHelper.js.map +1 -1
- package/dist/TransactionController.d.ts +50 -22
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +135 -65
- package/dist/TransactionController.js.map +1 -1
- package/dist/etherscan.d.ts +5 -6
- package/dist/etherscan.d.ts.map +1 -1
- package/dist/etherscan.js +6 -17
- package/dist/etherscan.js.map +1 -1
- package/dist/external-transactions.js +5 -5
- package/dist/external-transactions.js.map +1 -1
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +63 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -10
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +34 -34
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -23,6 +23,7 @@ const eth_method_registry_1 = __importDefault(require("eth-method-registry"));
|
|
|
23
23
|
const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
24
24
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
25
25
|
const events_1 = require("events");
|
|
26
|
+
const lodash_1 = require("lodash");
|
|
26
27
|
const nonce_tracker_1 = __importDefault(require("nonce-tracker"));
|
|
27
28
|
const uuid_1 = require("uuid");
|
|
28
29
|
const EtherscanRemoteTransactionSource_1 = require("./EtherscanRemoteTransactionSource");
|
|
@@ -58,7 +59,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
58
59
|
* @param options.getNetworkState - Gets the state of the network controller.
|
|
59
60
|
* @param options.getSelectedAddress - Gets the address of the currently selected account.
|
|
60
61
|
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
61
|
-
* @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
|
|
62
62
|
* @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
|
|
63
63
|
* @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
|
|
64
64
|
* @param options.incomingTransactions.queryEntireHistory - Whether to initially query the entire transaction history or only recent blocks.
|
|
@@ -111,7 +111,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
111
111
|
isEnabled: incomingTransactions.isEnabled,
|
|
112
112
|
queryEntireHistory: incomingTransactions.queryEntireHistory,
|
|
113
113
|
remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
|
|
114
|
-
apiKey: incomingTransactions.apiKey,
|
|
115
114
|
includeTokenTransfers: incomingTransactions.includeTokenTransfers,
|
|
116
115
|
}),
|
|
117
116
|
transactionLimit: this.config.txHistoryLimit,
|
|
@@ -183,7 +182,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
183
182
|
* unique transaction id will be generated, and gas and gasPrice will be calculated
|
|
184
183
|
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
185
184
|
*
|
|
186
|
-
* @param
|
|
185
|
+
* @param txParams - Standard parameters for an Ethereum transaction.
|
|
187
186
|
* @param opts - Additional options to control how the transaction is added.
|
|
188
187
|
* @param opts.actionId - Unique ID to prevent duplicate requests.
|
|
189
188
|
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
@@ -193,13 +192,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
193
192
|
* @param opts.sendFlowHistory - The sendFlowHistory entries to add.
|
|
194
193
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
195
194
|
*/
|
|
196
|
-
addTransaction(
|
|
195
|
+
addTransaction(txParams, { actionId, deviceConfirmedOn, origin, requireApproval, securityAlertResponse, sendFlowHistory, } = {}) {
|
|
197
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
197
|
const { chainId, networkId } = this.getChainAndNetworkId();
|
|
199
198
|
const { transactions } = this.state;
|
|
200
|
-
|
|
201
|
-
(0, utils_1.
|
|
202
|
-
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(
|
|
199
|
+
txParams = (0, utils_1.normalizeTxParams)(txParams);
|
|
200
|
+
(0, utils_1.validateTxParams)(txParams);
|
|
201
|
+
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
|
|
203
202
|
const existingTransactionMeta = this.getTransactionWithActionId(actionId);
|
|
204
203
|
// If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
|
|
205
204
|
const transactionMeta = existingTransactionMeta || {
|
|
@@ -214,13 +213,14 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
214
213
|
securityAlertResponse,
|
|
215
214
|
status: types_1.TransactionStatus.unapproved,
|
|
216
215
|
time: Date.now(),
|
|
217
|
-
|
|
216
|
+
txParams,
|
|
217
|
+
userEditedGasLimit: false,
|
|
218
218
|
verifiedOnBlockchain: false,
|
|
219
219
|
};
|
|
220
220
|
try {
|
|
221
|
-
const { gas, estimateGasError } = yield this.estimateGas(
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
const { gas, estimateGasError } = yield this.estimateGas(txParams);
|
|
222
|
+
txParams.gas = gas;
|
|
223
|
+
txParams.estimateGasError = estimateGasError;
|
|
224
224
|
transactionMeta.originalGasEstimate = gas;
|
|
225
225
|
}
|
|
226
226
|
catch (error) {
|
|
@@ -282,18 +282,18 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
282
282
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
283
283
|
* and emitting a `<tx.id>:finished` hub event.
|
|
284
284
|
*
|
|
285
|
-
* @param
|
|
285
|
+
* @param transactionId - The ID of the transaction to cancel.
|
|
286
286
|
* @param gasValues - The gas values to use for the cancellation transaction.
|
|
287
287
|
* @param options - The options for the cancellation transaction.
|
|
288
288
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
289
289
|
*/
|
|
290
|
-
stopTransaction(
|
|
290
|
+
stopTransaction(transactionId, gasValues, { estimatedBaseFee } = {}) {
|
|
291
291
|
var _a, _b;
|
|
292
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
293
293
|
if (gasValues) {
|
|
294
294
|
(0, utils_1.validateGasValues)(gasValues);
|
|
295
295
|
}
|
|
296
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
296
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionId);
|
|
297
297
|
if (!transactionMeta) {
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
@@ -301,20 +301,20 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
301
301
|
throw new Error('No sign method defined.');
|
|
302
302
|
}
|
|
303
303
|
// gasPrice (legacy non EIP1559)
|
|
304
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.
|
|
304
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.CANCEL_RATE);
|
|
305
305
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
306
306
|
const newGasPrice = (gasPriceFromValues &&
|
|
307
307
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
308
308
|
minGasPrice;
|
|
309
309
|
// maxFeePerGas (EIP1559)
|
|
310
|
-
const existingMaxFeePerGas = (_a = transactionMeta.
|
|
310
|
+
const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
311
311
|
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.CANCEL_RATE);
|
|
312
312
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
313
313
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
314
314
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
315
315
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
316
316
|
// maxPriorityFeePerGas (EIP1559)
|
|
317
|
-
const existingMaxPriorityFeePerGas = (_b = transactionMeta.
|
|
317
|
+
const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
318
318
|
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.CANCEL_RATE);
|
|
319
319
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
320
320
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
@@ -322,25 +322,26 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
322
322
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
323
323
|
const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
324
324
|
? {
|
|
325
|
-
from: transactionMeta.
|
|
326
|
-
gasLimit: transactionMeta.
|
|
325
|
+
from: transactionMeta.txParams.from,
|
|
326
|
+
gasLimit: transactionMeta.txParams.gas,
|
|
327
327
|
maxFeePerGas: newMaxFeePerGas,
|
|
328
328
|
maxPriorityFeePerGas: newMaxPriorityFeePerGas,
|
|
329
329
|
type: 2,
|
|
330
|
-
nonce: transactionMeta.
|
|
331
|
-
to: transactionMeta.
|
|
330
|
+
nonce: transactionMeta.txParams.nonce,
|
|
331
|
+
to: transactionMeta.txParams.from,
|
|
332
332
|
value: '0x0',
|
|
333
333
|
}
|
|
334
334
|
: {
|
|
335
|
-
from: transactionMeta.
|
|
336
|
-
gasLimit: transactionMeta.
|
|
335
|
+
from: transactionMeta.txParams.from,
|
|
336
|
+
gasLimit: transactionMeta.txParams.gas,
|
|
337
337
|
gasPrice: newGasPrice,
|
|
338
|
-
nonce: transactionMeta.
|
|
339
|
-
to: transactionMeta.
|
|
338
|
+
nonce: transactionMeta.txParams.nonce,
|
|
339
|
+
to: transactionMeta.txParams.from,
|
|
340
340
|
value: '0x0',
|
|
341
341
|
};
|
|
342
342
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
343
|
-
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.
|
|
343
|
+
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
|
|
344
|
+
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
344
345
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
345
346
|
yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
346
347
|
transactionMeta.estimatedBaseFee = estimatedBaseFee;
|
|
@@ -351,13 +352,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
351
352
|
/**
|
|
352
353
|
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
353
354
|
*
|
|
354
|
-
* @param
|
|
355
|
+
* @param transactionId - The ID of the transaction to speed up.
|
|
355
356
|
* @param gasValues - The gas values to use for the speed up transaction.
|
|
356
357
|
* @param options - The options for the speed up transaction.
|
|
357
358
|
* @param options.actionId - Unique ID to prevent duplicate requests
|
|
358
359
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
359
360
|
*/
|
|
360
|
-
speedUpTransaction(
|
|
361
|
+
speedUpTransaction(transactionId, gasValues, { actionId, estimatedBaseFee, } = {}) {
|
|
361
362
|
var _a, _b;
|
|
362
363
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
364
|
// If transaction is found for same action id, do not create a new speed up transaction.
|
|
@@ -367,7 +368,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
367
368
|
if (gasValues) {
|
|
368
369
|
(0, utils_1.validateGasValues)(gasValues);
|
|
369
370
|
}
|
|
370
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
371
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionId);
|
|
371
372
|
/* istanbul ignore next */
|
|
372
373
|
if (!transactionMeta) {
|
|
373
374
|
return;
|
|
@@ -378,35 +379,36 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
378
379
|
}
|
|
379
380
|
const { transactions } = this.state;
|
|
380
381
|
// gasPrice (legacy non EIP1559)
|
|
381
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.
|
|
382
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.SPEED_UP_RATE);
|
|
382
383
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
383
384
|
const newGasPrice = (gasPriceFromValues &&
|
|
384
385
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
385
386
|
minGasPrice;
|
|
386
387
|
// maxFeePerGas (EIP1559)
|
|
387
|
-
const existingMaxFeePerGas = (_a = transactionMeta.
|
|
388
|
+
const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
388
389
|
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.SPEED_UP_RATE);
|
|
389
390
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
390
391
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
391
392
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
392
393
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
393
394
|
// maxPriorityFeePerGas (EIP1559)
|
|
394
|
-
const existingMaxPriorityFeePerGas = (_b = transactionMeta.
|
|
395
|
+
const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
395
396
|
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.SPEED_UP_RATE);
|
|
396
397
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
397
398
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
398
399
|
(0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
|
|
399
400
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
400
401
|
const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
401
|
-
? Object.assign(Object.assign({}, transactionMeta.
|
|
402
|
+
? Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas, type: 2 }) : Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, gasPrice: newGasPrice });
|
|
402
403
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
403
|
-
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.
|
|
404
|
+
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
|
|
405
|
+
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
404
406
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
405
407
|
const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
406
408
|
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
|
|
407
|
-
actionId, originalGasEstimate: transactionMeta.
|
|
409
|
+
actionId, originalGasEstimate: transactionMeta.txParams.gas });
|
|
408
410
|
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
409
|
-
? Object.assign(Object.assign({}, baseTransactionMeta), {
|
|
411
|
+
? Object.assign(Object.assign({}, baseTransactionMeta), { txParams: Object.assign(Object.assign({}, transactionMeta.txParams), { maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas }) }) : Object.assign(Object.assign({}, baseTransactionMeta), { txParams: Object.assign(Object.assign({}, transactionMeta.txParams), { gasPrice: newGasPrice }) });
|
|
410
412
|
transactions.push(newTransactionMeta);
|
|
411
413
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
412
414
|
this.hub.emit(`${transactionMeta.id}:speedup`, newTransactionMeta);
|
|
@@ -521,8 +523,8 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
521
523
|
*/
|
|
522
524
|
updateTransaction(transactionMeta, note) {
|
|
523
525
|
const { transactions } = this.state;
|
|
524
|
-
transactionMeta.
|
|
525
|
-
(0, utils_1.
|
|
526
|
+
transactionMeta.txParams = (0, utils_1.normalizeTxParams)(transactionMeta.txParams);
|
|
527
|
+
(0, utils_1.validateTxParams)(transactionMeta.txParams);
|
|
526
528
|
if (!this.isHistoryDisabled) {
|
|
527
529
|
(0, history_1.updateTransactionHistory)(transactionMeta, note);
|
|
528
530
|
}
|
|
@@ -545,7 +547,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
545
547
|
return;
|
|
546
548
|
}
|
|
547
549
|
const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
|
|
548
|
-
const newTransactions = this.state.transactions.filter(({ networkID, chainId,
|
|
550
|
+
const newTransactions = this.state.transactions.filter(({ networkID, chainId, txParams }) => {
|
|
549
551
|
var _a;
|
|
550
552
|
// Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.
|
|
551
553
|
const isMatchingNetwork = ignoreNetwork ||
|
|
@@ -554,7 +556,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
554
556
|
if (!isMatchingNetwork) {
|
|
555
557
|
return true;
|
|
556
558
|
}
|
|
557
|
-
const isMatchingAddress = !address || ((_a =
|
|
559
|
+
const isMatchingAddress = !address || ((_a = txParams.from) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase();
|
|
558
560
|
return !isMatchingAddress;
|
|
559
561
|
});
|
|
560
562
|
this.update({
|
|
@@ -624,6 +626,53 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
624
626
|
}
|
|
625
627
|
return this.getTransaction(transactionID);
|
|
626
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* Update the gas values of a transaction.
|
|
631
|
+
*
|
|
632
|
+
* @param transactionId - The ID of the transaction to update.
|
|
633
|
+
* @param gasValues - Gas values to update.
|
|
634
|
+
* @param gasValues.gas - Same as transaction.gasLimit.
|
|
635
|
+
* @param gasValues.gasLimit - Maxmimum number of units of gas to use for this transaction.
|
|
636
|
+
* @param gasValues.gasPrice - Price per gas for legacy transactions.
|
|
637
|
+
* @param gasValues.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.
|
|
638
|
+
* @param gasValues.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.
|
|
639
|
+
* @param gasValues.estimateUsed - Which estimate level was used.
|
|
640
|
+
* @param gasValues.estimateSuggested - Which estimate level that the API suggested.
|
|
641
|
+
* @param gasValues.defaultGasEstimates - The default estimate for gas.
|
|
642
|
+
* @param gasValues.originalGasEstimate - Original estimate for gas.
|
|
643
|
+
* @param gasValues.userEditedGasLimit - The gas limit supplied by user.
|
|
644
|
+
* @param gasValues.userFeeLevel - Estimate level user selected.
|
|
645
|
+
* @returns The updated transactionMeta.
|
|
646
|
+
*/
|
|
647
|
+
updateTransactionGasFees(transactionId, { defaultGasEstimates, estimateUsed, estimateSuggested, gas, gasLimit, gasPrice, maxPriorityFeePerGas, maxFeePerGas, originalGasEstimate, userEditedGasLimit, userFeeLevel, }) {
|
|
648
|
+
const transactionMeta = this.getTransaction(transactionId);
|
|
649
|
+
if (!transactionMeta) {
|
|
650
|
+
throw new Error(`Cannot update transaction as no transaction metadata found`);
|
|
651
|
+
}
|
|
652
|
+
(0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateTransactionGasFees');
|
|
653
|
+
let transactionGasFees = {
|
|
654
|
+
txParams: {
|
|
655
|
+
gas,
|
|
656
|
+
gasLimit,
|
|
657
|
+
gasPrice,
|
|
658
|
+
maxPriorityFeePerGas,
|
|
659
|
+
maxFeePerGas,
|
|
660
|
+
},
|
|
661
|
+
defaultGasEstimates,
|
|
662
|
+
estimateUsed,
|
|
663
|
+
estimateSuggested,
|
|
664
|
+
originalGasEstimate,
|
|
665
|
+
userEditedGasLimit,
|
|
666
|
+
userFeeLevel,
|
|
667
|
+
};
|
|
668
|
+
// only update what is defined
|
|
669
|
+
transactionGasFees.txParams = (0, lodash_1.pickBy)(transactionGasFees.txParams);
|
|
670
|
+
transactionGasFees = (0, lodash_1.pickBy)(transactionGasFees);
|
|
671
|
+
// merge updated gas values with existing transaction meta
|
|
672
|
+
const updatedMeta = (0, lodash_1.merge)(transactionMeta, transactionGasFees);
|
|
673
|
+
this.updateTransaction(updatedMeta, 'TransactionController:updateTransactionGasFees - gas values updated');
|
|
674
|
+
return this.getTransaction(transactionId);
|
|
675
|
+
}
|
|
627
676
|
processApproval(transactionMeta, { isExisting = false, requireApproval, shouldShowRequest = true, }) {
|
|
628
677
|
return __awaiter(this, void 0, void 0, function* () {
|
|
629
678
|
const transactionId = transactionMeta.id;
|
|
@@ -683,16 +732,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
683
732
|
* using the sign configuration property, then published to the blockchain.
|
|
684
733
|
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
685
734
|
*
|
|
686
|
-
* @param
|
|
735
|
+
* @param transactionId - The ID of the transaction to approve.
|
|
687
736
|
*/
|
|
688
|
-
approveTransaction(
|
|
737
|
+
approveTransaction(transactionId) {
|
|
689
738
|
return __awaiter(this, void 0, void 0, function* () {
|
|
690
739
|
const { transactions } = this.state;
|
|
691
740
|
const releaseLock = yield this.mutex.acquire();
|
|
692
741
|
const { chainId } = this.getChainAndNetworkId();
|
|
693
|
-
const index = transactions.findIndex(({ id }) =>
|
|
742
|
+
const index = transactions.findIndex(({ id }) => transactionId === id);
|
|
694
743
|
const transactionMeta = transactions[index];
|
|
695
|
-
const {
|
|
744
|
+
const { txParams: { nonce, from }, } = transactionMeta;
|
|
696
745
|
let nonceLock;
|
|
697
746
|
try {
|
|
698
747
|
if (!this.sign) {
|
|
@@ -714,12 +763,12 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
714
763
|
nonceToUse = (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16));
|
|
715
764
|
}
|
|
716
765
|
transactionMeta.status = status;
|
|
717
|
-
transactionMeta.
|
|
718
|
-
transactionMeta.
|
|
719
|
-
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.
|
|
720
|
-
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.
|
|
766
|
+
transactionMeta.txParams.nonce = nonceToUse;
|
|
767
|
+
transactionMeta.txParams.chainId = chainId;
|
|
768
|
+
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas });
|
|
769
|
+
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.txParams);
|
|
721
770
|
const txParams = isEIP1559
|
|
722
|
-
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.
|
|
771
|
+
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.txParams.maxFeePerGas, maxPriorityFeePerGas: transactionMeta.txParams.maxPriorityFeePerGas, estimatedBaseFee: transactionMeta.txParams.estimatedBaseFee,
|
|
723
772
|
// specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set
|
|
724
773
|
type: 2 }) : baseTxParams;
|
|
725
774
|
// delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set
|
|
@@ -728,6 +777,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
728
777
|
}
|
|
729
778
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
730
779
|
const signedTx = yield this.sign(unsignedEthTx, from);
|
|
780
|
+
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
731
781
|
transactionMeta.status = types_1.TransactionStatus.signed;
|
|
732
782
|
this.updateTransaction(transactionMeta, 'TransactionController#approveTransaction - Transaction signed');
|
|
733
783
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
@@ -756,16 +806,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
756
806
|
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
757
807
|
* and emitting a `<tx.id>:finished` hub event.
|
|
758
808
|
*
|
|
759
|
-
* @param
|
|
809
|
+
* @param transactionId - The ID of the transaction to cancel.
|
|
760
810
|
*/
|
|
761
|
-
cancelTransaction(
|
|
762
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
811
|
+
cancelTransaction(transactionId) {
|
|
812
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionId);
|
|
763
813
|
if (!transactionMeta) {
|
|
764
814
|
return;
|
|
765
815
|
}
|
|
766
816
|
transactionMeta.status = types_1.TransactionStatus.rejected;
|
|
767
817
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
768
|
-
const transactions = this.state.transactions.filter(({ id }) => id !==
|
|
818
|
+
const transactions = this.state.transactions.filter(({ id }) => id !== transactionId);
|
|
769
819
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
770
820
|
}
|
|
771
821
|
/**
|
|
@@ -787,9 +837,9 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
787
837
|
const txsToKeep = transactions
|
|
788
838
|
.sort((a, b) => (a.time > b.time ? -1 : 1)) // Descending time order
|
|
789
839
|
.filter((tx) => {
|
|
790
|
-
const { chainId, networkID, status,
|
|
791
|
-
if (
|
|
792
|
-
const key = `${
|
|
840
|
+
const { chainId, networkID, status, txParams, time } = tx;
|
|
841
|
+
if (txParams) {
|
|
842
|
+
const key = `${txParams.nonce}-${chainId ? (0, controller_utils_1.convertHexToDecimal)(chainId) : networkID}-${new Date(time).toDateString()}`;
|
|
793
843
|
if (nonceNetworkSet.has(key)) {
|
|
794
844
|
return true;
|
|
795
845
|
}
|
|
@@ -852,7 +902,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
852
902
|
txReceipt.blockHash,
|
|
853
903
|
]);
|
|
854
904
|
meta.verifiedOnBlockchain = true;
|
|
855
|
-
meta.
|
|
905
|
+
meta.txParams.gasUsed = txReceipt.gasUsed;
|
|
856
906
|
meta.txReceipt = txReceipt;
|
|
857
907
|
meta.baseFeePerGas = txBlock === null || txBlock === void 0 ? void 0 : txBlock.baseFeePerGas;
|
|
858
908
|
meta.blockTimestamp = txBlock === null || txBlock === void 0 ? void 0 : txBlock.timestamp;
|
|
@@ -992,11 +1042,11 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
992
1042
|
this.update({ lastFetchedBlockNumbers });
|
|
993
1043
|
this.hub.emit('incomingTransactionBlock', blockNumber);
|
|
994
1044
|
}
|
|
995
|
-
generateDappSuggestedGasFees(
|
|
1045
|
+
generateDappSuggestedGasFees(txParams, origin) {
|
|
996
1046
|
if (!origin || origin === controller_utils_1.ORIGIN_METAMASK) {
|
|
997
1047
|
return undefined;
|
|
998
1048
|
}
|
|
999
|
-
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } =
|
|
1049
|
+
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = txParams;
|
|
1000
1050
|
if (gasPrice === undefined &&
|
|
1001
1051
|
maxFeePerGas === undefined &&
|
|
1002
1052
|
maxPriorityFeePerGas === undefined &&
|
|
@@ -1027,8 +1077,8 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1027
1077
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1028
1078
|
const { networkId, chainId } = this.getChainAndNetworkId();
|
|
1029
1079
|
const { transactions } = this.state;
|
|
1030
|
-
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1031
|
-
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.
|
|
1080
|
+
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.from;
|
|
1081
|
+
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.txParams.from === fromAddress &&
|
|
1032
1082
|
(0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
|
|
1033
1083
|
const confirmedTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.confirmed);
|
|
1034
1084
|
const pendingTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.submitted);
|
|
@@ -1055,10 +1105,10 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1055
1105
|
var _a, _b;
|
|
1056
1106
|
const { networkId, chainId } = this.getChainAndNetworkId();
|
|
1057
1107
|
const transactionMeta = this.getTransaction(transactionId);
|
|
1058
|
-
const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1059
|
-
const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1060
|
-
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.
|
|
1061
|
-
transaction.
|
|
1108
|
+
const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
|
|
1109
|
+
const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
|
|
1110
|
+
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.txParams.from === from &&
|
|
1111
|
+
transaction.txParams.nonce === nonce &&
|
|
1062
1112
|
(0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
|
|
1063
1113
|
if (!sameNonceTxs.length) {
|
|
1064
1114
|
return;
|
|
@@ -1103,6 +1153,26 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1103
1153
|
});
|
|
1104
1154
|
});
|
|
1105
1155
|
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Updates the r, s, and v properties of a TransactionMeta object
|
|
1158
|
+
* with values from a signed transaction.
|
|
1159
|
+
*
|
|
1160
|
+
* @param transactionMeta - The TransactionMeta object to update.
|
|
1161
|
+
* @param signedTx - The encompassing type for all transaction types containing r, s, and v values.
|
|
1162
|
+
*/
|
|
1163
|
+
updateTransactionMetaRSV(transactionMeta, signedTx) {
|
|
1164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1165
|
+
if (signedTx.r) {
|
|
1166
|
+
transactionMeta.r = (0, ethereumjs_util_1.addHexPrefix)(signedTx.r.toString(16));
|
|
1167
|
+
}
|
|
1168
|
+
if (signedTx.s) {
|
|
1169
|
+
transactionMeta.s = (0, ethereumjs_util_1.addHexPrefix)(signedTx.s.toString(16));
|
|
1170
|
+
}
|
|
1171
|
+
if (signedTx.v) {
|
|
1172
|
+
transactionMeta.v = (0, ethereumjs_util_1.addHexPrefix)(signedTx.v.toString(16));
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1106
1176
|
}
|
|
1107
1177
|
exports.TransactionController = TransactionController;
|
|
1108
1178
|
exports.default = TransactionController;
|