@metamask-previews/transaction-controller 21.1.0-preview.d392f46 → 21.2.0-preview.280e51c7
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 +9 -1
- package/dist/TransactionController.d.ts +118 -109
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +335 -188
- package/dist/TransactionController.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.js +28 -8
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts +17 -3
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.js +17 -14
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts +72 -0
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +292 -0
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -0
- package/dist/helpers/PendingTransactionTracker.d.ts +13 -7
- package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.js +43 -23
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/etherscan.d.ts +7 -0
- package/dist/utils/etherscan.d.ts.map +1 -1
- package/dist/utils/etherscan.js +17 -6
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/gas-fees.d.ts +4 -3
- package/dist/utils/gas-fees.d.ts.map +1 -1
- package/dist/utils/gas-fees.js +6 -2
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas.d.ts +3 -2
- package/dist/utils/gas.d.ts.map +1 -1
- package/dist/utils/gas.js +4 -5
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/nonce.d.ts +3 -3
- package/dist/utils/nonce.d.ts.map +1 -1
- package/dist/utils/nonce.js +3 -3
- package/dist/utils/nonce.js.map +1 -1
- package/package.json +7 -6
|
@@ -8,9 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
25
|
+
var _TransactionController_instances, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_multichainTrackingHelper, _TransactionController_createNonceTracker, _TransactionController_createIncomingTransactionHelper, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_removeIncomingTransactionHelperListeners, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions;
|
|
14
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
27
|
exports.TransactionController = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.HARDFORK = void 0;
|
|
16
28
|
const common_1 = require("@ethereumjs/common");
|
|
@@ -18,6 +30,7 @@ const tx_1 = require("@ethereumjs/tx");
|
|
|
18
30
|
const base_controller_1 = require("@metamask/base-controller");
|
|
19
31
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
20
32
|
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
33
|
+
const network_controller_1 = require("@metamask/network-controller");
|
|
21
34
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
22
35
|
const async_mutex_1 = require("async-mutex");
|
|
23
36
|
const eth_method_registry_1 = require("eth-method-registry");
|
|
@@ -28,6 +41,7 @@ const nonce_tracker_1 = require("nonce-tracker");
|
|
|
28
41
|
const uuid_1 = require("uuid");
|
|
29
42
|
const EtherscanRemoteTransactionSource_1 = require("./helpers/EtherscanRemoteTransactionSource");
|
|
30
43
|
const IncomingTransactionHelper_1 = require("./helpers/IncomingTransactionHelper");
|
|
44
|
+
const MultichainTrackingHelper_1 = require("./helpers/MultichainTrackingHelper");
|
|
31
45
|
const PendingTransactionTracker_1 = require("./helpers/PendingTransactionTracker");
|
|
32
46
|
const logger_1 = require("./logger");
|
|
33
47
|
const types_1 = require("./types");
|
|
@@ -44,7 +58,7 @@ exports.HARDFORK = common_1.Hardfork.London;
|
|
|
44
58
|
/**
|
|
45
59
|
* Multiplier used to determine a transaction's increased gas fee during cancellation
|
|
46
60
|
*/
|
|
47
|
-
exports.CANCEL_RATE = 1.
|
|
61
|
+
exports.CANCEL_RATE = 1.1;
|
|
48
62
|
/**
|
|
49
63
|
* Multiplier used to determine a transaction's increased gas fee during speed up
|
|
50
64
|
*/
|
|
@@ -57,50 +71,16 @@ const controllerName = 'TransactionController';
|
|
|
57
71
|
* Controller responsible for submitting and managing transactions.
|
|
58
72
|
*/
|
|
59
73
|
class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @param options - The controller options.
|
|
64
|
-
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
65
|
-
* @param options.cancelMultiplier - Multiplier used to determine a transaction's increased gas fee during cancellation.
|
|
66
|
-
* @param options.disableHistory - Whether to disable storing history in transaction metadata.
|
|
67
|
-
* @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
|
|
68
|
-
* @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
|
|
69
|
-
* @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
|
|
70
|
-
* @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
|
|
71
|
-
* @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
|
|
72
|
-
* @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
|
|
73
|
-
* @param options.getNetworkState - Gets the state of the network controller.
|
|
74
|
-
* @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
|
|
75
|
-
* @param options.getSavedGasFees - Gets the saved gas fee config.
|
|
76
|
-
* @param options.getSelectedAddress - Gets the address of the currently selected account.
|
|
77
|
-
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
78
|
-
* @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
|
|
79
|
-
* @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
|
|
80
|
-
* @param options.incomingTransactions.queryEntireHistory - Whether to initially query the entire transaction history or only recent blocks.
|
|
81
|
-
* @param options.incomingTransactions.updateTransactions - Whether to update local transactions using remote transaction data.
|
|
82
|
-
* @param options.messenger - The controller messenger.
|
|
83
|
-
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
84
|
-
* @param options.pendingTransactions - Configuration options for pending transaction support.
|
|
85
|
-
* @param options.pendingTransactions.isResubmitEnabled - Whether transaction publishing is automatically retried.
|
|
86
|
-
* @param options.provider - The provider used to create the underlying EthQuery instance.
|
|
87
|
-
* @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
|
|
88
|
-
* @param options.speedUpMultiplier - Multiplier used to determine a transaction's increased gas fee during speed up.
|
|
89
|
-
* @param options.hooks - The controller hooks.
|
|
90
|
-
* @param options.hooks.afterSign - Additional logic to execute after signing a transaction. Return false to not change the status to signed.
|
|
91
|
-
* @param options.hooks.beforeApproveOnInit - Additional logic to execute before starting an approval flow for a transaction during initialization. Return false to skip the transaction.
|
|
92
|
-
* @param options.hooks.beforeCheckPendingTransaction - Additional logic to execute before checking pending transactions. Return false to prevent the broadcast of the transaction.
|
|
93
|
-
* @param options.hooks.beforePublish - Additional logic to execute before publishing a transaction. Return false to prevent the broadcast of the transaction.
|
|
94
|
-
* @param options.hooks.getAdditionalSignArguments - Returns additional arguments required to sign a transaction.
|
|
95
|
-
* @param config - Initial options used to configure this controller.
|
|
96
|
-
* @param state - Initial state to set on this controller.
|
|
97
|
-
*/
|
|
98
|
-
constructor({ blockTracker, cancelMultiplier, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, speedUpMultiplier, hooks = {}, }, config, state) {
|
|
99
|
-
var _a, _b, _c, _d, _e;
|
|
74
|
+
constructor({ blockTracker, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkState, getPermittedAccounts, getSavedGasFees, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, getNetworkClientRegistry, isMultichainEnabled = false, hooks, }, config, state) {
|
|
75
|
+
var _a, _b, _c, _d, _e, _f;
|
|
100
76
|
super(config, state);
|
|
77
|
+
_TransactionController_instances.add(this);
|
|
101
78
|
this.inProcessOfSigning = new Set();
|
|
102
79
|
this.mutex = new async_mutex_1.Mutex();
|
|
80
|
+
_TransactionController_incomingTransactionOptions.set(this, void 0);
|
|
81
|
+
_TransactionController_pendingTransactionOptions.set(this, void 0);
|
|
103
82
|
this.signAbortCallbacks = new Map();
|
|
83
|
+
_TransactionController_multichainTrackingHelper.set(this, void 0);
|
|
104
84
|
/**
|
|
105
85
|
* EventEmitter instance used to listen to specific transactional events
|
|
106
86
|
*/
|
|
@@ -109,6 +89,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
109
89
|
* Name of this controller used during composition
|
|
110
90
|
*/
|
|
111
91
|
this.name = 'TransactionController';
|
|
92
|
+
_TransactionController_checkForPendingTransactionAndStartPolling.set(this, () => {
|
|
93
|
+
// PendingTransactionTracker reads state through its getTransactions hook
|
|
94
|
+
this.pendingTransactionTracker.startIfPendingTransactions();
|
|
95
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").checkForPendingTransactionAndStartPolling();
|
|
96
|
+
});
|
|
112
97
|
this.defaultConfig = {
|
|
113
98
|
txHistoryLimit: 40,
|
|
114
99
|
};
|
|
@@ -118,10 +103,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
118
103
|
lastFetchedBlockNumbers: {},
|
|
119
104
|
};
|
|
120
105
|
this.initialize();
|
|
121
|
-
this.provider = provider;
|
|
122
106
|
this.messagingSystem = messenger;
|
|
123
107
|
this.getNetworkState = getNetworkState;
|
|
124
|
-
this.ethQuery = new eth_query_1.default(provider);
|
|
125
108
|
this.isSendFlowHistoryDisabled = disableSendFlowHistory !== null && disableSendFlowHistory !== void 0 ? disableSendFlowHistory : false;
|
|
126
109
|
this.isHistoryDisabled = disableHistory !== null && disableHistory !== void 0 ? disableHistory : false;
|
|
127
110
|
this.isSwapsDisabled = disableSwaps !== null && disableSwaps !== void 0 ? disableSwaps : false;
|
|
@@ -139,8 +122,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
139
122
|
this.getExternalPendingTransactions =
|
|
140
123
|
getExternalPendingTransactions !== null && getExternalPendingTransactions !== void 0 ? getExternalPendingTransactions : (() => []);
|
|
141
124
|
this.securityProviderRequest = securityProviderRequest;
|
|
142
|
-
this
|
|
143
|
-
this
|
|
125
|
+
__classPrivateFieldSet(this, _TransactionController_incomingTransactionOptions, incomingTransactions, "f");
|
|
126
|
+
__classPrivateFieldSet(this, _TransactionController_pendingTransactionOptions, pendingTransactions, "f");
|
|
144
127
|
this.afterSign = (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterSign) !== null && _a !== void 0 ? _a : (() => true);
|
|
145
128
|
this.beforeApproveOnInit = (_b = hooks === null || hooks === void 0 ? void 0 : hooks.beforeApproveOnInit) !== null && _b !== void 0 ? _b : (() => true);
|
|
146
129
|
this.beforeCheckPendingTransaction =
|
|
@@ -150,50 +133,53 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
150
133
|
this.beforePublish = (_d = hooks === null || hooks === void 0 ? void 0 : hooks.beforePublish) !== null && _d !== void 0 ? _d : (() => true);
|
|
151
134
|
this.getAdditionalSignArguments =
|
|
152
135
|
(_e = hooks === null || hooks === void 0 ? void 0 : hooks.getAdditionalSignArguments) !== null && _e !== void 0 ? _e : (() => []);
|
|
153
|
-
this.
|
|
154
|
-
|
|
136
|
+
this.publish =
|
|
137
|
+
(_f = hooks === null || hooks === void 0 ? void 0 : hooks.publish) !== null && _f !== void 0 ? _f : (() => Promise.resolve({ transactionHash: undefined }));
|
|
138
|
+
this.nonceTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).call(this, {
|
|
155
139
|
provider,
|
|
156
140
|
blockTracker,
|
|
157
|
-
getPendingTransactions: this.getNonceTrackerPendingTransactions.bind(this),
|
|
158
|
-
getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
|
|
159
141
|
});
|
|
160
|
-
this
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
|
|
164
|
-
getNetworkState,
|
|
165
|
-
isEnabled: incomingTransactions.isEnabled,
|
|
166
|
-
queryEntireHistory: incomingTransactions.queryEntireHistory,
|
|
167
|
-
remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
|
|
168
|
-
includeTokenTransfers: incomingTransactions.includeTokenTransfers,
|
|
169
|
-
}),
|
|
170
|
-
transactionLimit: this.config.txHistoryLimit,
|
|
171
|
-
updateTransactions: incomingTransactions.updateTransactions,
|
|
172
|
-
});
|
|
173
|
-
this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
|
|
174
|
-
this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
|
|
175
|
-
this.pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
|
|
176
|
-
approveTransaction: this.approveTransaction.bind(this),
|
|
177
|
-
blockTracker,
|
|
178
|
-
getChainId: this.getChainId.bind(this),
|
|
179
|
-
getEthQuery: () => this.ethQuery,
|
|
180
|
-
getTransactions: () => this.state.transactions,
|
|
181
|
-
isResubmitEnabled: pendingTransactions.isResubmitEnabled,
|
|
142
|
+
__classPrivateFieldSet(this, _TransactionController_multichainTrackingHelper, new MultichainTrackingHelper_1.MultichainTrackingHelper({
|
|
143
|
+
isMultichainEnabled,
|
|
144
|
+
provider,
|
|
182
145
|
nonceTracker: this.nonceTracker,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
listener();
|
|
146
|
+
incomingTransactionOptions: incomingTransactions,
|
|
147
|
+
findNetworkClientIdByChainId: (chainId) => {
|
|
148
|
+
return this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, chainId);
|
|
187
149
|
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
150
|
+
getNetworkClientById: ((networkClientId) => {
|
|
151
|
+
return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId);
|
|
152
|
+
}),
|
|
153
|
+
getNetworkClientRegistry,
|
|
154
|
+
removeIncomingTransactionHelperListeners: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removeIncomingTransactionHelperListeners).bind(this),
|
|
155
|
+
removePendingTransactionTrackerListeners: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removePendingTransactionTrackerListeners).bind(this),
|
|
156
|
+
createNonceTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).bind(this),
|
|
157
|
+
createIncomingTransactionHelper: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).bind(this),
|
|
158
|
+
createPendingTransactionTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).bind(this),
|
|
159
|
+
onNetworkStateChange: (listener) => {
|
|
160
|
+
this.messagingSystem.subscribe('NetworkController:stateChange', listener);
|
|
192
161
|
},
|
|
162
|
+
}), "f");
|
|
163
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").initialize();
|
|
164
|
+
const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
|
|
165
|
+
includeTokenTransfers: incomingTransactions.includeTokenTransfers,
|
|
166
|
+
});
|
|
167
|
+
this.incomingTransactionHelper = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).call(this, {
|
|
168
|
+
blockTracker,
|
|
169
|
+
etherscanRemoteTransactionSource,
|
|
170
|
+
});
|
|
171
|
+
this.pendingTransactionTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).call(this, {
|
|
172
|
+
provider,
|
|
173
|
+
blockTracker,
|
|
193
174
|
});
|
|
194
|
-
|
|
175
|
+
// when transactionsController state changes
|
|
176
|
+
// check for pending transactions and start polling if there are any
|
|
177
|
+
this.subscribe(__classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
|
|
178
|
+
// TODO once v2 is merged make sure this only runs when
|
|
179
|
+
// selectedNetworkClientId changes
|
|
195
180
|
onNetworkStateChange(() => {
|
|
196
181
|
(0, logger_1.projectLogger)('Detected network change', this.getChainId());
|
|
182
|
+
this.pendingTransactionTracker.startIfPendingTransactions();
|
|
197
183
|
this.onBootCleanup();
|
|
198
184
|
});
|
|
199
185
|
this.onBootCleanup();
|
|
@@ -216,6 +202,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
216
202
|
return { registryMethod, parsedRegistryMethod };
|
|
217
203
|
});
|
|
218
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Stops polling and removes listeners to prepare the controller for garbage collection.
|
|
207
|
+
*/
|
|
208
|
+
destroy() {
|
|
209
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_stopAllTracking).call(this);
|
|
210
|
+
}
|
|
219
211
|
/**
|
|
220
212
|
* Handle new method data request.
|
|
221
213
|
*
|
|
@@ -260,21 +252,30 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
260
252
|
* @param opts.swaps - Options for swaps transactions.
|
|
261
253
|
* @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
|
|
262
254
|
* @param opts.swaps.meta - Metadata for swap transaction.
|
|
255
|
+
* @param opts.networkClientId - The id of the network client for this transaction.
|
|
263
256
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
264
257
|
*/
|
|
265
|
-
addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, } = {}) {
|
|
258
|
+
addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, type, networkClientId, } = {}) {
|
|
266
259
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
260
|
(0, logger_1.projectLogger)('Adding transaction', txParams);
|
|
268
261
|
txParams = (0, utils_1.normalizeTxParams)(txParams);
|
|
269
|
-
|
|
262
|
+
if (networkClientId &&
|
|
263
|
+
!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
|
|
264
|
+
throw new Error('The networkClientId for this transaction could not be found');
|
|
265
|
+
}
|
|
266
|
+
const isEIP1559Compatible = yield this.getEIP1559Compatibility(networkClientId);
|
|
270
267
|
(0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
|
|
271
268
|
if (origin) {
|
|
272
269
|
yield (0, validation_1.validateTransactionOrigin)(yield this.getPermittedAccounts(origin), this.getSelectedAddress(), txParams.from, origin);
|
|
273
270
|
}
|
|
274
271
|
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
|
|
275
|
-
const
|
|
272
|
+
const chainId = this.getChainId(networkClientId);
|
|
273
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
274
|
+
networkClientId,
|
|
275
|
+
chainId,
|
|
276
|
+
});
|
|
277
|
+
const transactionType = type !== null && type !== void 0 ? type : (yield (0, transaction_type_1.determineTransactionType)(txParams, ethQuery)).type;
|
|
276
278
|
const existingTransactionMeta = this.getTransactionWithActionId(actionId);
|
|
277
|
-
const chainId = this.getChainId();
|
|
278
279
|
// If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
|
|
279
280
|
const transactionMeta = existingTransactionMeta || {
|
|
280
281
|
// Add actionId to txMeta to check if same actionId is seen again
|
|
@@ -291,6 +292,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
291
292
|
userEditedGasLimit: false,
|
|
292
293
|
verifiedOnBlockchain: false,
|
|
293
294
|
type: transactionType,
|
|
295
|
+
networkClientId,
|
|
294
296
|
};
|
|
295
297
|
yield this.updateGasProperties(transactionMeta);
|
|
296
298
|
// Checks if a transaction already exists with a given actionId
|
|
@@ -327,15 +329,31 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
327
329
|
};
|
|
328
330
|
});
|
|
329
331
|
}
|
|
330
|
-
startIncomingTransactionPolling() {
|
|
331
|
-
|
|
332
|
+
startIncomingTransactionPolling(networkClientIds = []) {
|
|
333
|
+
if (networkClientIds.length === 0) {
|
|
334
|
+
this.incomingTransactionHelper.start();
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").startIncomingTransactionPolling(networkClientIds);
|
|
338
|
+
}
|
|
339
|
+
stopIncomingTransactionPolling(networkClientIds = []) {
|
|
340
|
+
if (networkClientIds.length === 0) {
|
|
341
|
+
this.incomingTransactionHelper.stop();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopIncomingTransactionPolling(networkClientIds);
|
|
332
345
|
}
|
|
333
|
-
|
|
346
|
+
stopAllIncomingTransactionPolling() {
|
|
334
347
|
this.incomingTransactionHelper.stop();
|
|
348
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllIncomingTransactionPolling();
|
|
335
349
|
}
|
|
336
|
-
updateIncomingTransactions() {
|
|
350
|
+
updateIncomingTransactions(networkClientIds = []) {
|
|
337
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
338
|
-
|
|
352
|
+
if (networkClientIds.length === 0) {
|
|
353
|
+
yield this.incomingTransactionHelper.update();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
yield __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").updateIncomingTransactions(networkClientIds);
|
|
339
357
|
});
|
|
340
358
|
}
|
|
341
359
|
/**
|
|
@@ -369,21 +387,21 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
369
387
|
throw new Error('No sign method defined.');
|
|
370
388
|
}
|
|
371
389
|
// gasPrice (legacy non EIP1559)
|
|
372
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice,
|
|
390
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.CANCEL_RATE);
|
|
373
391
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
374
392
|
const newGasPrice = (gasPriceFromValues &&
|
|
375
393
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
376
394
|
minGasPrice;
|
|
377
395
|
// maxFeePerGas (EIP1559)
|
|
378
396
|
const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
379
|
-
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas,
|
|
397
|
+
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.CANCEL_RATE);
|
|
380
398
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
381
399
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
382
400
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
383
401
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
384
402
|
// maxPriorityFeePerGas (EIP1559)
|
|
385
403
|
const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
386
|
-
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas,
|
|
404
|
+
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.CANCEL_RATE);
|
|
387
405
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
388
406
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
389
407
|
(0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
|
|
@@ -407,7 +425,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
407
425
|
to: transactionMeta.txParams.from,
|
|
408
426
|
value: '0x0',
|
|
409
427
|
};
|
|
410
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(newTxParams);
|
|
428
|
+
const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, newTxParams);
|
|
411
429
|
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
|
|
412
430
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
413
431
|
const newFee = (_c = newTxParams.maxFeePerGas) !== null && _c !== void 0 ? _c : newTxParams.gasPrice;
|
|
@@ -419,10 +437,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
419
437
|
newFee,
|
|
420
438
|
txParams: newTxParams,
|
|
421
439
|
});
|
|
422
|
-
const
|
|
440
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
441
|
+
networkClientId: transactionMeta.networkClientId,
|
|
442
|
+
chainId: transactionMeta.chainId,
|
|
443
|
+
});
|
|
444
|
+
const hash = yield this.publishTransactionForRetry(ethQuery, rawTx, transactionMeta);
|
|
423
445
|
const cancelTransactionMeta = {
|
|
424
446
|
actionId,
|
|
425
447
|
chainId: transactionMeta.chainId,
|
|
448
|
+
networkClientId: transactionMeta.networkClientId,
|
|
426
449
|
estimatedBaseFee,
|
|
427
450
|
hash,
|
|
428
451
|
id: (0, uuid_1.v1)(),
|
|
@@ -477,28 +500,28 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
477
500
|
throw new Error('No sign method defined.');
|
|
478
501
|
}
|
|
479
502
|
// gasPrice (legacy non EIP1559)
|
|
480
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice,
|
|
503
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.txParams.gasPrice, exports.SPEED_UP_RATE);
|
|
481
504
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
482
505
|
const newGasPrice = (gasPriceFromValues &&
|
|
483
506
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
484
507
|
minGasPrice;
|
|
485
508
|
// maxFeePerGas (EIP1559)
|
|
486
509
|
const existingMaxFeePerGas = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
487
|
-
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas,
|
|
510
|
+
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.SPEED_UP_RATE);
|
|
488
511
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
489
512
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
490
513
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
491
514
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
492
515
|
// maxPriorityFeePerGas (EIP1559)
|
|
493
516
|
const existingMaxPriorityFeePerGas = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
494
|
-
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas,
|
|
517
|
+
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.SPEED_UP_RATE);
|
|
495
518
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
496
519
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
497
520
|
(0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
|
|
498
521
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
499
522
|
const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
500
523
|
? Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas, type: types_1.TransactionEnvelopeType.feeMarket }) : Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas, gasPrice: newGasPrice });
|
|
501
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
524
|
+
const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
|
|
502
525
|
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.txParams.from);
|
|
503
526
|
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
504
527
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
@@ -507,7 +530,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
507
530
|
? transactionMeta.txParams.maxFeePerGas
|
|
508
531
|
: transactionMeta.txParams.gasPrice;
|
|
509
532
|
(0, logger_1.projectLogger)('Submitting speed up transaction', { oldFee, newFee, txParams });
|
|
510
|
-
const
|
|
533
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
534
|
+
networkClientId: transactionMeta.networkClientId,
|
|
535
|
+
chainId: transactionMeta.chainId,
|
|
536
|
+
});
|
|
537
|
+
const hash = yield this.publishTransactionForRetry(ethQuery, rawTx, transactionMeta);
|
|
511
538
|
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
|
|
512
539
|
actionId, originalGasEstimate: transactionMeta.txParams.gas, type: types_1.TransactionType.retry, originalType: transactionMeta.type });
|
|
513
540
|
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
@@ -529,11 +556,15 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
529
556
|
* Estimates required gas for a given transaction.
|
|
530
557
|
*
|
|
531
558
|
* @param transaction - The transaction to estimate gas for.
|
|
559
|
+
* @param networkClientId - The network client id to use for the estimate.
|
|
532
560
|
* @returns The gas and gas price.
|
|
533
561
|
*/
|
|
534
|
-
estimateGas(transaction) {
|
|
562
|
+
estimateGas(transaction, networkClientId) {
|
|
535
563
|
return __awaiter(this, void 0, void 0, function* () {
|
|
536
|
-
const
|
|
564
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
565
|
+
networkClientId,
|
|
566
|
+
});
|
|
567
|
+
const { estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
|
|
537
568
|
return { gas: estimatedGas, simulationFails };
|
|
538
569
|
});
|
|
539
570
|
}
|
|
@@ -542,10 +573,14 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
542
573
|
*
|
|
543
574
|
* @param transaction - The transaction params to estimate gas for.
|
|
544
575
|
* @param multiplier - The multiplier to use for the gas buffer.
|
|
576
|
+
* @param networkClientId - The network client id to use for the estimate.
|
|
545
577
|
*/
|
|
546
|
-
estimateGasBuffered(transaction, multiplier) {
|
|
578
|
+
estimateGasBuffered(transaction, multiplier, networkClientId) {
|
|
547
579
|
return __awaiter(this, void 0, void 0, function* () {
|
|
548
|
-
const
|
|
580
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
581
|
+
networkClientId,
|
|
582
|
+
});
|
|
583
|
+
const { blockGasLimit, estimatedGas, simulationFails } = yield (0, gas_1.estimateGas)(transaction, ethQuery);
|
|
549
584
|
const gas = (0, gas_1.addGasBuffer)(estimatedGas, blockGasLimit, multiplier);
|
|
550
585
|
return {
|
|
551
586
|
gas,
|
|
@@ -615,12 +650,6 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
615
650
|
transactions: this.trimTransactionsForState(newTransactions),
|
|
616
651
|
});
|
|
617
652
|
}
|
|
618
|
-
startIncomingTransactionProcessing() {
|
|
619
|
-
this.incomingTransactionHelper.start();
|
|
620
|
-
}
|
|
621
|
-
stopIncomingTransactionProcessing() {
|
|
622
|
-
this.incomingTransactionHelper.stop();
|
|
623
|
-
}
|
|
624
653
|
/**
|
|
625
654
|
* Adds external provided transaction to state as confirmed transaction.
|
|
626
655
|
*
|
|
@@ -766,16 +795,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
766
795
|
this.updateTransaction(updatedMeta, 'TransactionController:updatePreviousGasParams - Previous gas values updated');
|
|
767
796
|
return this.getTransaction(transactionId);
|
|
768
797
|
}
|
|
769
|
-
|
|
770
|
-
* Gets the next nonce according to the nonce-tracker.
|
|
771
|
-
* Ensure `releaseLock` is called once processing of the `nonce` value is complete.
|
|
772
|
-
*
|
|
773
|
-
* @param address - The hex string address for the transaction.
|
|
774
|
-
* @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.
|
|
775
|
-
*/
|
|
776
|
-
getNonceLock(address) {
|
|
798
|
+
getNonceLock(address, networkClientId) {
|
|
777
799
|
return __awaiter(this, void 0, void 0, function* () {
|
|
778
|
-
return this.
|
|
800
|
+
return __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNonceLock(address, networkClientId);
|
|
779
801
|
});
|
|
780
802
|
}
|
|
781
803
|
/**
|
|
@@ -810,7 +832,10 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
810
832
|
};
|
|
811
833
|
editableParams.txParams = (0, lodash_1.pickBy)(editableParams.txParams);
|
|
812
834
|
const updatedTransaction = (0, lodash_1.merge)(transactionMeta, editableParams);
|
|
813
|
-
const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, this.
|
|
835
|
+
const { type } = yield (0, transaction_type_1.determineTransactionType)(updatedTransaction.txParams, __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
836
|
+
networkClientId: transactionMeta.networkClientId,
|
|
837
|
+
chainId: transactionMeta.chainId,
|
|
838
|
+
}));
|
|
814
839
|
updatedTransaction.type = type;
|
|
815
840
|
this.updateTransaction(updatedTransaction, `Update Editable Params for ${txId}`);
|
|
816
841
|
return this.getTransaction(txId);
|
|
@@ -820,9 +845,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
820
845
|
* Signs and returns the raw transaction data for provided transaction params list.
|
|
821
846
|
*
|
|
822
847
|
* @param listOfTxParams - The list of transaction params to approve.
|
|
848
|
+
* @param opts - Options bag.
|
|
849
|
+
* @param opts.hasNonce - Whether the transactions already have a nonce.
|
|
823
850
|
* @returns The raw transactions.
|
|
824
851
|
*/
|
|
825
|
-
approveTransactionsWithSameNonce(listOfTxParams = []) {
|
|
852
|
+
approveTransactionsWithSameNonce(listOfTxParams = [], { hasNonce } = {}) {
|
|
826
853
|
return __awaiter(this, void 0, void 0, function* () {
|
|
827
854
|
(0, logger_1.projectLogger)('Approving transactions with same nonce', {
|
|
828
855
|
transactions: listOfTxParams,
|
|
@@ -831,7 +858,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
831
858
|
return '';
|
|
832
859
|
}
|
|
833
860
|
const initialTx = listOfTxParams[0];
|
|
834
|
-
const common = this.getCommonConfiguration();
|
|
861
|
+
const common = this.getCommonConfiguration(initialTx.chainId);
|
|
862
|
+
// We need to ensure we get the nonce using the the NonceTracker on the chain matching
|
|
863
|
+
// the txParams. In this context we only have chainId available to us, but the
|
|
864
|
+
// NonceTrackers are keyed by networkClientId. To workaround this, we attempt to find
|
|
865
|
+
// a networkClientId that matches the chainId. As a fallback, the globally selected
|
|
866
|
+
// network's NonceTracker will be used instead.
|
|
867
|
+
let networkClientId;
|
|
868
|
+
try {
|
|
869
|
+
networkClientId = this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, initialTx.chainId);
|
|
870
|
+
}
|
|
871
|
+
catch (err) {
|
|
872
|
+
(0, logger_1.projectLogger)('failed to find networkClientId from chainId', err);
|
|
873
|
+
}
|
|
835
874
|
const initialTxAsEthTx = tx_1.TransactionFactory.fromTxData(initialTx, {
|
|
836
875
|
common,
|
|
837
876
|
});
|
|
@@ -844,12 +883,19 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
844
883
|
try {
|
|
845
884
|
// TODO: we should add a check to verify that all transactions have the same from address
|
|
846
885
|
const fromAddress = initialTx.from;
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
886
|
+
const requiresNonce = hasNonce !== true;
|
|
887
|
+
nonceLock = requiresNonce
|
|
888
|
+
? yield this.getNonceLock(fromAddress, networkClientId)
|
|
889
|
+
: undefined;
|
|
890
|
+
const nonce = nonceLock
|
|
891
|
+
? (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16))
|
|
892
|
+
: initialTx.nonce;
|
|
893
|
+
if (nonceLock) {
|
|
894
|
+
(0, logger_1.projectLogger)('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
|
|
895
|
+
}
|
|
850
896
|
rawTransactions = yield Promise.all(listOfTxParams.map((txParams) => {
|
|
851
|
-
txParams.nonce =
|
|
852
|
-
return this.signExternalTransaction(txParams);
|
|
897
|
+
txParams.nonce = nonce;
|
|
898
|
+
return this.signExternalTransaction(txParams.chainId, txParams);
|
|
853
899
|
}));
|
|
854
900
|
}
|
|
855
901
|
catch (err) {
|
|
@@ -859,9 +905,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
859
905
|
throw err;
|
|
860
906
|
}
|
|
861
907
|
finally {
|
|
862
|
-
|
|
863
|
-
nonceLock.releaseLock();
|
|
864
|
-
}
|
|
908
|
+
nonceLock === null || nonceLock === void 0 ? void 0 : nonceLock.releaseLock();
|
|
865
909
|
this.inProcessOfSigning.delete(initialTxAsSerializedHex);
|
|
866
910
|
}
|
|
867
911
|
return rawTransactions;
|
|
@@ -1009,19 +1053,18 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1009
1053
|
}
|
|
1010
1054
|
return filteredTransactions;
|
|
1011
1055
|
}
|
|
1012
|
-
signExternalTransaction(transactionParams) {
|
|
1056
|
+
signExternalTransaction(chainId, transactionParams) {
|
|
1013
1057
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1014
1058
|
if (!this.sign) {
|
|
1015
1059
|
throw new Error('No sign method defined.');
|
|
1016
1060
|
}
|
|
1017
1061
|
const normalizedTransactionParams = (0, utils_1.normalizeTxParams)(transactionParams);
|
|
1018
|
-
const chainId = this.getChainId();
|
|
1019
1062
|
const type = (0, utils_1.isEIP1559Transaction)(normalizedTransactionParams)
|
|
1020
1063
|
? types_1.TransactionEnvelopeType.feeMarket
|
|
1021
1064
|
: types_1.TransactionEnvelopeType.legacy;
|
|
1022
1065
|
const updatedTransactionParams = Object.assign(Object.assign({}, normalizedTransactionParams), { type, gasLimit: normalizedTransactionParams.gas, chainId });
|
|
1023
1066
|
const { from } = updatedTransactionParams;
|
|
1024
|
-
const common = this.getCommonConfiguration();
|
|
1067
|
+
const common = this.getCommonConfiguration(chainId);
|
|
1025
1068
|
const unsignedTransaction = tx_1.TransactionFactory.fromTxData(updatedTransactionParams, { common });
|
|
1026
1069
|
const signedTransaction = yield this.sign(unsignedTransaction, from);
|
|
1027
1070
|
const rawTransaction = (0, ethereumjs_util_1.bufferToHex)(signedTransaction.serialize());
|
|
@@ -1059,35 +1102,41 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1059
1102
|
}
|
|
1060
1103
|
updateGasProperties(transactionMeta) {
|
|
1061
1104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1062
|
-
const isEIP1559Compatible = (yield this.getEIP1559Compatibility()) &&
|
|
1105
|
+
const isEIP1559Compatible = (yield this.getEIP1559Compatibility(transactionMeta.networkClientId)) &&
|
|
1063
1106
|
transactionMeta.txParams.type !== types_1.TransactionEnvelopeType.legacy;
|
|
1064
|
-
const chainId =
|
|
1107
|
+
const { networkClientId, chainId } = transactionMeta;
|
|
1108
|
+
const isCustomNetwork = networkClientId
|
|
1109
|
+
? this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.type === network_controller_1.NetworkClientType.Custom
|
|
1110
|
+
: this.getNetworkState().providerConfig.type === controller_utils_1.NetworkType.rpc;
|
|
1065
1111
|
yield (0, gas_1.updateGas)({
|
|
1066
|
-
ethQuery: this.
|
|
1067
|
-
|
|
1112
|
+
ethQuery: __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
1113
|
+
networkClientId,
|
|
1114
|
+
chainId,
|
|
1115
|
+
}),
|
|
1116
|
+
chainId,
|
|
1117
|
+
isCustomNetwork,
|
|
1068
1118
|
txMeta: transactionMeta,
|
|
1069
1119
|
});
|
|
1070
1120
|
yield (0, gas_fees_1.updateGasFees)({
|
|
1071
1121
|
eip1559: isEIP1559Compatible,
|
|
1072
|
-
ethQuery: this.
|
|
1073
|
-
|
|
1122
|
+
ethQuery: __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
1123
|
+
networkClientId,
|
|
1124
|
+
chainId,
|
|
1125
|
+
}),
|
|
1126
|
+
getSavedGasFees: this.getSavedGasFees.bind(this),
|
|
1074
1127
|
getGasFeeEstimates: this.getGasFeeEstimates.bind(this),
|
|
1075
1128
|
txMeta: transactionMeta,
|
|
1076
1129
|
});
|
|
1077
1130
|
});
|
|
1078
1131
|
}
|
|
1079
|
-
getCurrentChainTransactionsByStatus(status) {
|
|
1080
|
-
const chainId = this.getChainId();
|
|
1081
|
-
return this.state.transactions.filter((transaction) => transaction.status === status && transaction.chainId === chainId);
|
|
1082
|
-
}
|
|
1083
1132
|
onBootCleanup() {
|
|
1084
1133
|
this.submitApprovedTransactions();
|
|
1085
1134
|
}
|
|
1086
1135
|
/**
|
|
1087
|
-
* Force
|
|
1136
|
+
* Force submit approved transactions for all chains.
|
|
1088
1137
|
*/
|
|
1089
1138
|
submitApprovedTransactions() {
|
|
1090
|
-
const approvedTransactions = this.
|
|
1139
|
+
const approvedTransactions = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.approved);
|
|
1091
1140
|
for (const transactionMeta of approvedTransactions) {
|
|
1092
1141
|
if (this.beforeApproveOnInit(transactionMeta)) {
|
|
1093
1142
|
this.approveTransaction(transactionMeta.id).catch((error) => {
|
|
@@ -1181,10 +1230,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1181
1230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1182
1231
|
const { transactions } = this.state;
|
|
1183
1232
|
const releaseLock = yield this.mutex.acquire();
|
|
1184
|
-
const chainId = this.getChainId();
|
|
1185
1233
|
const index = transactions.findIndex(({ id }) => transactionId === id);
|
|
1186
1234
|
const transactionMeta = transactions[index];
|
|
1187
|
-
const { txParams: { from }, } = transactionMeta;
|
|
1235
|
+
const { txParams: { from }, networkClientId, } = transactionMeta;
|
|
1188
1236
|
let releaseNonceLock;
|
|
1189
1237
|
try {
|
|
1190
1238
|
if (!this.sign) {
|
|
@@ -1192,7 +1240,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1192
1240
|
this.failTransaction(transactionMeta, new Error('No sign method defined.'));
|
|
1193
1241
|
return;
|
|
1194
1242
|
}
|
|
1195
|
-
else if (!chainId) {
|
|
1243
|
+
else if (!transactionMeta.chainId) {
|
|
1196
1244
|
releaseLock();
|
|
1197
1245
|
this.failTransaction(transactionMeta, new Error('No chainId defined.'));
|
|
1198
1246
|
return;
|
|
@@ -1201,11 +1249,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1201
1249
|
(0, logger_1.projectLogger)('Skipping approval as signing in progress', transactionId);
|
|
1202
1250
|
return;
|
|
1203
1251
|
}
|
|
1204
|
-
const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, this.
|
|
1252
|
+
const [nonce, releaseNonce] = yield (0, nonce_1.getNextNonce)(transactionMeta, (address) => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNonceLock(address, networkClientId));
|
|
1205
1253
|
releaseNonceLock = releaseNonce;
|
|
1206
1254
|
transactionMeta.status = types_1.TransactionStatus.approved;
|
|
1207
1255
|
transactionMeta.txParams.nonce = nonce;
|
|
1208
|
-
transactionMeta.txParams.chainId = chainId;
|
|
1256
|
+
transactionMeta.txParams.chainId = transactionMeta.chainId;
|
|
1209
1257
|
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.txParams), { gasLimit: transactionMeta.txParams.gas });
|
|
1210
1258
|
this.updateTransaction(transactionMeta, 'TransactionController#approveTransaction - Transaction approved');
|
|
1211
1259
|
this.onTransactionStatusChange(transactionMeta);
|
|
@@ -1221,14 +1269,21 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1221
1269
|
if (!rawTx) {
|
|
1222
1270
|
return;
|
|
1223
1271
|
}
|
|
1272
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
1273
|
+
networkClientId: transactionMeta.networkClientId,
|
|
1274
|
+
chainId: transactionMeta.chainId,
|
|
1275
|
+
});
|
|
1224
1276
|
if (transactionMeta.type === types_1.TransactionType.swap) {
|
|
1225
1277
|
(0, logger_1.projectLogger)('Determining pre-transaction balance');
|
|
1226
|
-
const preTxBalance = yield (0, controller_utils_1.query)(
|
|
1278
|
+
const preTxBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [from]);
|
|
1227
1279
|
transactionMeta.preTxBalance = preTxBalance;
|
|
1228
1280
|
(0, logger_1.projectLogger)('Updated pre-transaction balance', transactionMeta.preTxBalance);
|
|
1229
1281
|
}
|
|
1230
1282
|
(0, logger_1.projectLogger)('Publishing transaction', txParams);
|
|
1231
|
-
|
|
1283
|
+
let { transactionHash: hash } = yield this.publish(transactionMeta, rawTx);
|
|
1284
|
+
if (hash === undefined) {
|
|
1285
|
+
hash = yield this.publishTransaction(ethQuery, rawTx);
|
|
1286
|
+
}
|
|
1232
1287
|
(0, logger_1.projectLogger)('Publish successful', hash);
|
|
1233
1288
|
transactionMeta.hash = hash;
|
|
1234
1289
|
transactionMeta.status = types_1.TransactionStatus.submitted;
|
|
@@ -1253,9 +1308,9 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1253
1308
|
}
|
|
1254
1309
|
});
|
|
1255
1310
|
}
|
|
1256
|
-
publishTransaction(rawTransaction) {
|
|
1311
|
+
publishTransaction(ethQuery, rawTransaction) {
|
|
1257
1312
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1258
|
-
return yield (0, controller_utils_1.query)(
|
|
1313
|
+
return yield (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [rawTransaction]);
|
|
1259
1314
|
});
|
|
1260
1315
|
}
|
|
1261
1316
|
/**
|
|
@@ -1371,14 +1426,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1371
1426
|
const isCompleted = this.isLocalFinalState(transaction.status);
|
|
1372
1427
|
return { meta: transaction, isCompleted };
|
|
1373
1428
|
}
|
|
1374
|
-
getChainId() {
|
|
1429
|
+
getChainId(networkClientId) {
|
|
1430
|
+
if (networkClientId) {
|
|
1431
|
+
return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.chainId;
|
|
1432
|
+
}
|
|
1375
1433
|
const { providerConfig } = this.getNetworkState();
|
|
1376
1434
|
return providerConfig.chainId;
|
|
1377
1435
|
}
|
|
1378
|
-
prepareUnsignedEthTx(txParams) {
|
|
1436
|
+
prepareUnsignedEthTx(chainId, txParams) {
|
|
1379
1437
|
return tx_1.TransactionFactory.fromTxData(txParams, {
|
|
1380
|
-
common: this.getCommonConfiguration(),
|
|
1381
1438
|
freeze: false,
|
|
1439
|
+
common: this.getCommonConfiguration(chainId),
|
|
1382
1440
|
});
|
|
1383
1441
|
}
|
|
1384
1442
|
/**
|
|
@@ -1388,17 +1446,11 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1388
1446
|
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
1389
1447
|
* transaction type to use.
|
|
1390
1448
|
*
|
|
1449
|
+
* @param chainId - The chainId to use for the configuration.
|
|
1391
1450
|
* @returns common configuration object
|
|
1392
1451
|
*/
|
|
1393
|
-
getCommonConfiguration() {
|
|
1394
|
-
const { providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
|
|
1395
|
-
if (chain !== controller_utils_1.RPC &&
|
|
1396
|
-
chain !== controller_utils_1.NetworkType['linea-goerli'] &&
|
|
1397
|
-
chain !== controller_utils_1.NetworkType['linea-mainnet']) {
|
|
1398
|
-
return new common_1.Common({ chain, hardfork: exports.HARDFORK });
|
|
1399
|
-
}
|
|
1452
|
+
getCommonConfiguration(chainId) {
|
|
1400
1453
|
const customChainParams = {
|
|
1401
|
-
name,
|
|
1402
1454
|
chainId: parseInt(chainId, 16),
|
|
1403
1455
|
defaultHardfork: exports.HARDFORK,
|
|
1404
1456
|
};
|
|
@@ -1453,7 +1505,7 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1453
1505
|
*/
|
|
1454
1506
|
addExternalTransaction(transactionMeta) {
|
|
1455
1507
|
var _a, _b;
|
|
1456
|
-
const chainId =
|
|
1508
|
+
const { chainId } = transactionMeta;
|
|
1457
1509
|
const { transactions } = this.state;
|
|
1458
1510
|
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.from;
|
|
1459
1511
|
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.txParams.from === fromAddress &&
|
|
@@ -1480,10 +1532,13 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1480
1532
|
*/
|
|
1481
1533
|
markNonceDuplicatesDropped(transactionId) {
|
|
1482
1534
|
var _a, _b;
|
|
1483
|
-
const chainId = this.getChainId();
|
|
1484
1535
|
const transactionMeta = this.getTransaction(transactionId);
|
|
1485
|
-
|
|
1486
|
-
|
|
1536
|
+
if (!transactionMeta) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
const nonce = (_a = transactionMeta.txParams) === null || _a === void 0 ? void 0 : _a.nonce;
|
|
1540
|
+
const from = (_b = transactionMeta.txParams) === null || _b === void 0 ? void 0 : _b.from;
|
|
1541
|
+
const { chainId } = transactionMeta;
|
|
1487
1542
|
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.id !== transactionId &&
|
|
1488
1543
|
transaction.txParams.from === from &&
|
|
1489
1544
|
transaction.txParams.nonce === nonce &&
|
|
@@ -1494,8 +1549,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1494
1549
|
}
|
|
1495
1550
|
// Mark all same nonce transactions as dropped and give it a replacedBy hash
|
|
1496
1551
|
for (const transaction of sameNonceTxs) {
|
|
1497
|
-
transaction.replacedBy = transactionMeta
|
|
1498
|
-
transaction.replacedById = transactionMeta
|
|
1552
|
+
transaction.replacedBy = transactionMeta.hash;
|
|
1553
|
+
transaction.replacedById = transactionMeta.id;
|
|
1499
1554
|
// Drop any transaction that wasn't previously failed (off chain failure)
|
|
1500
1555
|
if (transaction.status !== types_1.TransactionStatus.failed) {
|
|
1501
1556
|
this.setTransactionStatusDropped(transaction);
|
|
@@ -1551,23 +1606,17 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1551
1606
|
}
|
|
1552
1607
|
});
|
|
1553
1608
|
}
|
|
1554
|
-
getEIP1559Compatibility() {
|
|
1609
|
+
getEIP1559Compatibility(networkClientId) {
|
|
1555
1610
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1556
|
-
const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility();
|
|
1611
|
+
const currentNetworkIsEIP1559Compatible = yield this.getCurrentNetworkEIP1559Compatibility(networkClientId);
|
|
1557
1612
|
const currentAccountIsEIP1559Compatible = yield this.getCurrentAccountEIP1559Compatibility();
|
|
1558
1613
|
return (currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible);
|
|
1559
1614
|
});
|
|
1560
1615
|
}
|
|
1561
|
-
addPendingTransactionTrackerListeners() {
|
|
1562
|
-
this.pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
|
|
1563
|
-
this.pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
|
|
1564
|
-
this.pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
|
|
1565
|
-
this.pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
|
|
1566
|
-
}
|
|
1567
1616
|
signTransaction(transactionMeta, txParams) {
|
|
1568
1617
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1569
1618
|
(0, logger_1.projectLogger)('Signing transaction', txParams);
|
|
1570
|
-
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
1619
|
+
const unsignedEthTx = this.prepareUnsignedEthTx(transactionMeta.chainId, txParams);
|
|
1571
1620
|
this.inProcessOfSigning.add(transactionMeta.id);
|
|
1572
1621
|
const signedTx = yield new Promise((resolve, reject) => {
|
|
1573
1622
|
var _a;
|
|
@@ -1597,14 +1646,8 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1597
1646
|
onTransactionStatusChange(transactionMeta) {
|
|
1598
1647
|
this.hub.emit('transaction-status-update', { transactionMeta });
|
|
1599
1648
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
const externalPendingTransactions = this.getExternalPendingTransactions(address);
|
|
1603
|
-
return [...standardPendingTransactions, ...externalPendingTransactions];
|
|
1604
|
-
}
|
|
1605
|
-
getNonceTrackerTransactions(status, address) {
|
|
1606
|
-
const currentChainId = this.getChainId();
|
|
1607
|
-
return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(currentChainId, address, status, this.state.transactions);
|
|
1649
|
+
getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
|
|
1650
|
+
return (0, nonce_1.getAndFormatTransactionsForNonceTracker)(chainId, address, status, this.state.transactions);
|
|
1608
1651
|
}
|
|
1609
1652
|
onConfirmedTransaction(transactionMeta) {
|
|
1610
1653
|
(0, logger_1.projectLogger)('Processing confirmed transaction', transactionMeta.id);
|
|
@@ -1622,8 +1665,12 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1622
1665
|
if (transactionMeta.type !== types_1.TransactionType.swap) {
|
|
1623
1666
|
return;
|
|
1624
1667
|
}
|
|
1668
|
+
const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
|
|
1669
|
+
networkClientId: transactionMeta.networkClientId,
|
|
1670
|
+
chainId: transactionMeta.chainId,
|
|
1671
|
+
});
|
|
1625
1672
|
const { updatedTransactionMeta, approvalTransactionMeta } = yield (0, swaps_1.updatePostTransactionBalance)(transactionMeta, {
|
|
1626
|
-
ethQuery
|
|
1673
|
+
ethQuery,
|
|
1627
1674
|
getTransaction: this.getTransaction.bind(this),
|
|
1628
1675
|
updateTransaction: this.updateTransaction.bind(this),
|
|
1629
1676
|
});
|
|
@@ -1638,6 +1685,106 @@ class TransactionController extends base_controller_1.BaseControllerV1 {
|
|
|
1638
1685
|
}
|
|
1639
1686
|
});
|
|
1640
1687
|
}
|
|
1688
|
+
publishTransactionForRetry(ethQuery, rawTx, transactionMeta) {
|
|
1689
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1690
|
+
try {
|
|
1691
|
+
const hash = yield this.publishTransaction(ethQuery, rawTx);
|
|
1692
|
+
return hash;
|
|
1693
|
+
}
|
|
1694
|
+
catch (error) {
|
|
1695
|
+
if (this.isTransactionAlreadyConfirmedError(error)) {
|
|
1696
|
+
yield this.pendingTransactionTracker.forceCheckTransaction(transactionMeta);
|
|
1697
|
+
throw new Error('Previous transaction is already confirmed');
|
|
1698
|
+
}
|
|
1699
|
+
throw error;
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Ensures that error is a nonce issue
|
|
1705
|
+
*
|
|
1706
|
+
* @param error - The error to check
|
|
1707
|
+
* @returns Whether or not the error is a nonce issue
|
|
1708
|
+
*/
|
|
1709
|
+
// TODO: Replace `any` with type
|
|
1710
|
+
// Some networks are returning original error in the data field
|
|
1711
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1712
|
+
isTransactionAlreadyConfirmedError(error) {
|
|
1713
|
+
var _a, _b, _c;
|
|
1714
|
+
return (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('nonce too low')) ||
|
|
1715
|
+
((_c = (_b = error === null || error === void 0 ? void 0 : error.data) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.includes('nonce too low')));
|
|
1716
|
+
}
|
|
1641
1717
|
}
|
|
1642
1718
|
exports.TransactionController = TransactionController;
|
|
1719
|
+
_TransactionController_incomingTransactionOptions = new WeakMap(), _TransactionController_pendingTransactionOptions = new WeakMap(), _TransactionController_multichainTrackingHelper = new WeakMap(), _TransactionController_checkForPendingTransactionAndStartPolling = new WeakMap(), _TransactionController_instances = new WeakSet(), _TransactionController_createNonceTracker = function _TransactionController_createNonceTracker({ provider, blockTracker, chainId, }) {
|
|
1720
|
+
return new nonce_tracker_1.NonceTracker({
|
|
1721
|
+
// TODO: Replace `any` with type
|
|
1722
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1723
|
+
provider: provider,
|
|
1724
|
+
blockTracker,
|
|
1725
|
+
getPendingTransactions: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNonceTrackerPendingTransactions).bind(this, chainId),
|
|
1726
|
+
getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, types_1.TransactionStatus.confirmed),
|
|
1727
|
+
});
|
|
1728
|
+
}, _TransactionController_createIncomingTransactionHelper = function _TransactionController_createIncomingTransactionHelper({ blockTracker, etherscanRemoteTransactionSource, chainId, }) {
|
|
1729
|
+
const incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
|
|
1730
|
+
blockTracker,
|
|
1731
|
+
getCurrentAccount: this.getSelectedAddress,
|
|
1732
|
+
getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
|
|
1733
|
+
getChainId: chainId ? () => chainId : this.getChainId.bind(this),
|
|
1734
|
+
isEnabled: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").isEnabled,
|
|
1735
|
+
queryEntireHistory: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").queryEntireHistory,
|
|
1736
|
+
remoteTransactionSource: etherscanRemoteTransactionSource,
|
|
1737
|
+
transactionLimit: this.config.txHistoryLimit,
|
|
1738
|
+
updateTransactions: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").updateTransactions,
|
|
1739
|
+
});
|
|
1740
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addIncomingTransactionHelperListeners).call(this, incomingTransactionHelper);
|
|
1741
|
+
return incomingTransactionHelper;
|
|
1742
|
+
}, _TransactionController_createPendingTransactionTracker = function _TransactionController_createPendingTransactionTracker({ provider, blockTracker, chainId, }) {
|
|
1743
|
+
const ethQuery = new eth_query_1.default(provider);
|
|
1744
|
+
const getChainId = chainId ? () => chainId : this.getChainId.bind(this);
|
|
1745
|
+
const pendingTransactionTracker = new PendingTransactionTracker_1.PendingTransactionTracker({
|
|
1746
|
+
approveTransaction: this.approveTransaction.bind(this),
|
|
1747
|
+
blockTracker,
|
|
1748
|
+
getChainId,
|
|
1749
|
+
getEthQuery: () => ethQuery,
|
|
1750
|
+
getTransactions: () => this.state.transactions,
|
|
1751
|
+
isResubmitEnabled: __classPrivateFieldGet(this, _TransactionController_pendingTransactionOptions, "f").isResubmitEnabled,
|
|
1752
|
+
getGlobalLock: () => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").acquireNonceLockForChainIdKey({
|
|
1753
|
+
chainId: getChainId(),
|
|
1754
|
+
}),
|
|
1755
|
+
publishTransaction: this.publishTransaction.bind(this),
|
|
1756
|
+
hooks: {
|
|
1757
|
+
beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
|
|
1758
|
+
beforePublish: this.beforePublish.bind(this),
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);
|
|
1762
|
+
return pendingTransactionTracker;
|
|
1763
|
+
}, _TransactionController_stopAllTracking = function _TransactionController_stopAllTracking() {
|
|
1764
|
+
this.pendingTransactionTracker.stop();
|
|
1765
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removePendingTransactionTrackerListeners).call(this, this.pendingTransactionTracker);
|
|
1766
|
+
this.incomingTransactionHelper.stop();
|
|
1767
|
+
__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removeIncomingTransactionHelperListeners).call(this, this.incomingTransactionHelper);
|
|
1768
|
+
__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllTracking();
|
|
1769
|
+
}, _TransactionController_removeIncomingTransactionHelperListeners = function _TransactionController_removeIncomingTransactionHelperListeners(incomingTransactionHelper) {
|
|
1770
|
+
incomingTransactionHelper.hub.removeAllListeners('transactions');
|
|
1771
|
+
incomingTransactionHelper.hub.removeAllListeners('updatedLastFetchedBlockNumbers');
|
|
1772
|
+
}, _TransactionController_addIncomingTransactionHelperListeners = function _TransactionController_addIncomingTransactionHelperListeners(incomingTransactionHelper) {
|
|
1773
|
+
incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
|
|
1774
|
+
incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
|
|
1775
|
+
}, _TransactionController_removePendingTransactionTrackerListeners = function _TransactionController_removePendingTransactionTrackerListeners(pendingTransactionTracker) {
|
|
1776
|
+
pendingTransactionTracker.hub.removeAllListeners('transaction-confirmed');
|
|
1777
|
+
pendingTransactionTracker.hub.removeAllListeners('transaction-dropped');
|
|
1778
|
+
pendingTransactionTracker.hub.removeAllListeners('transaction-failed');
|
|
1779
|
+
pendingTransactionTracker.hub.removeAllListeners('transaction-updated');
|
|
1780
|
+
}, _TransactionController_addPendingTransactionTrackerListeners = function _TransactionController_addPendingTransactionTrackerListeners(pendingTransactionTracker) {
|
|
1781
|
+
pendingTransactionTracker.hub.on('transaction-confirmed', this.onConfirmedTransaction.bind(this));
|
|
1782
|
+
pendingTransactionTracker.hub.on('transaction-dropped', this.setTransactionStatusDropped.bind(this));
|
|
1783
|
+
pendingTransactionTracker.hub.on('transaction-failed', this.failTransaction.bind(this));
|
|
1784
|
+
pendingTransactionTracker.hub.on('transaction-updated', this.updateTransaction.bind(this));
|
|
1785
|
+
}, _TransactionController_getNonceTrackerPendingTransactions = function _TransactionController_getNonceTrackerPendingTransactions(chainId, address) {
|
|
1786
|
+
const standardPendingTransactions = this.getNonceTrackerTransactions(types_1.TransactionStatus.submitted, address, chainId);
|
|
1787
|
+
const externalPendingTransactions = this.getExternalPendingTransactions(address, chainId);
|
|
1788
|
+
return [...standardPendingTransactions, ...externalPendingTransactions];
|
|
1789
|
+
};
|
|
1643
1790
|
//# sourceMappingURL=TransactionController.js.map
|