@metamask-previews/transaction-controller 10.0.0-preview.d5e3b8e → 10.0.0-preview.dbee2e4
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/dist/EtherscanRemoteTransactionSource.d.ts +2 -2
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +18 -41
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/IncomingTransactionHelper.js +11 -22
- package/dist/IncomingTransactionHelper.js.map +1 -1
- package/dist/TransactionController.d.ts +24 -70
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +80 -201
- package/dist/TransactionController.js.map +1 -1
- package/dist/etherscan.d.ts +6 -5
- package/dist/etherscan.d.ts.map +1 -1
- package/dist/etherscan.js +17 -6
- package/dist/etherscan.js.map +1 -1
- package/dist/external-transactions.js +5 -5
- package/dist/external-transactions.js.map +1 -1
- package/dist/types.d.ts +15 -103
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -19
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +34 -49
- package/dist/utils.js.map +1 -1
- package/package.json +1 -3
- package/dist/history.d.ts +0 -15
- package/dist/history.d.ts.map +0 -1
- package/dist/history.js +0 -75
- package/dist/history.js.map +0 -1
- package/dist/logger.d.ts +0 -6
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -8
- package/dist/logger.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,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c_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");
|
|
27
26
|
const nonce_tracker_1 = __importDefault(require("nonce-tracker"));
|
|
28
27
|
const uuid_1 = require("uuid");
|
|
29
28
|
const EtherscanRemoteTransactionSource_1 = require("./EtherscanRemoteTransactionSource");
|
|
30
29
|
const external_transactions_1 = require("./external-transactions");
|
|
31
|
-
const history_1 = require("./history");
|
|
32
30
|
const IncomingTransactionHelper_1 = require("./IncomingTransactionHelper");
|
|
33
31
|
const types_1 = require("./types");
|
|
34
32
|
const utils_1 = require("./utils");
|
|
@@ -54,11 +52,10 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
54
52
|
*
|
|
55
53
|
* @param options - The controller options.
|
|
56
54
|
* @param options.blockTracker - The block tracker used to poll for new blocks data.
|
|
57
|
-
* @param options.disableHistory - Whether to disable storing history in transaction metadata.
|
|
58
|
-
* @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
|
|
59
55
|
* @param options.getNetworkState - Gets the state of the network controller.
|
|
60
56
|
* @param options.getSelectedAddress - Gets the address of the currently selected account.
|
|
61
57
|
* @param options.incomingTransactions - Configuration options for incoming transaction support.
|
|
58
|
+
* @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
|
|
62
59
|
* @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
|
|
63
60
|
* @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
|
|
64
61
|
* @param options.incomingTransactions.queryEntireHistory - Whether to initially query the entire transaction history or only recent blocks.
|
|
@@ -69,7 +66,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
69
66
|
* @param config - Initial options used to configure this controller.
|
|
70
67
|
* @param state - Initial state to set on this controller.
|
|
71
68
|
*/
|
|
72
|
-
constructor({ blockTracker,
|
|
69
|
+
constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, provider, }, config, state) {
|
|
73
70
|
super(config, state);
|
|
74
71
|
this.mutex = new async_mutex_1.Mutex();
|
|
75
72
|
/**
|
|
@@ -94,8 +91,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
94
91
|
this.messagingSystem = messenger;
|
|
95
92
|
this.getNetworkState = getNetworkState;
|
|
96
93
|
this.ethQuery = new eth_query_1.default(provider);
|
|
97
|
-
this.isSendFlowHistoryDisabled = disableSendFlowHistory !== null && disableSendFlowHistory !== void 0 ? disableSendFlowHistory : false;
|
|
98
|
-
this.isHistoryDisabled = disableHistory !== null && disableHistory !== void 0 ? disableHistory : false;
|
|
99
94
|
this.registry = new eth_method_registry_1.default({ provider });
|
|
100
95
|
this.nonceTracker = new nonce_tracker_1.default({
|
|
101
96
|
provider,
|
|
@@ -111,6 +106,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
111
106
|
isEnabled: incomingTransactions.isEnabled,
|
|
112
107
|
queryEntireHistory: incomingTransactions.queryEntireHistory,
|
|
113
108
|
remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
|
|
109
|
+
apiKey: incomingTransactions.apiKey,
|
|
114
110
|
includeTokenTransfers: incomingTransactions.includeTokenTransfers,
|
|
115
111
|
}),
|
|
116
112
|
transactionLimit: this.config.txHistoryLimit,
|
|
@@ -126,7 +122,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
126
122
|
}
|
|
127
123
|
failTransaction(transactionMeta, error) {
|
|
128
124
|
const newTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { error, status: types_1.TransactionStatus.failed });
|
|
129
|
-
this.updateTransaction(newTransactionMeta
|
|
125
|
+
this.updateTransaction(newTransactionMeta);
|
|
130
126
|
this.hub.emit(`${transactionMeta.id}:finished`, newTransactionMeta);
|
|
131
127
|
}
|
|
132
128
|
registryLookup(fourBytePrefix) {
|
|
@@ -182,45 +178,43 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
182
178
|
* unique transaction id will be generated, and gas and gasPrice will be calculated
|
|
183
179
|
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
184
180
|
*
|
|
185
|
-
* @param
|
|
181
|
+
* @param transaction - The transaction object to add.
|
|
186
182
|
* @param opts - Additional options to control how the transaction is added.
|
|
187
183
|
* @param opts.actionId - Unique ID to prevent duplicate requests.
|
|
188
184
|
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
189
185
|
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
190
186
|
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
191
187
|
* @param opts.securityAlertResponse - Response from security validator.
|
|
192
|
-
* @param opts.sendFlowHistory - The sendFlowHistory entries to add.
|
|
193
188
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
194
189
|
*/
|
|
195
|
-
addTransaction(
|
|
190
|
+
addTransaction(transaction, { actionId, deviceConfirmedOn, origin, requireApproval, securityAlertResponse, } = {}) {
|
|
196
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
192
|
const { chainId, networkId } = this.getChainAndNetworkId();
|
|
198
193
|
const { transactions } = this.state;
|
|
199
|
-
|
|
200
|
-
(0, utils_1.
|
|
201
|
-
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(
|
|
194
|
+
transaction = (0, utils_1.normalizeTransaction)(transaction);
|
|
195
|
+
(0, utils_1.validateTransaction)(transaction);
|
|
196
|
+
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(transaction, origin);
|
|
202
197
|
const existingTransactionMeta = this.getTransactionWithActionId(actionId);
|
|
203
198
|
// If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
|
|
204
199
|
const transactionMeta = existingTransactionMeta || {
|
|
205
|
-
// Add actionId to txMeta to check if same actionId is seen again
|
|
206
|
-
actionId,
|
|
207
|
-
chainId,
|
|
208
|
-
dappSuggestedGasFees,
|
|
209
|
-
deviceConfirmedOn,
|
|
210
200
|
id: (0, uuid_1.v1)(),
|
|
211
201
|
networkID: networkId !== null && networkId !== void 0 ? networkId : undefined,
|
|
202
|
+
chainId,
|
|
212
203
|
origin,
|
|
213
|
-
securityAlertResponse,
|
|
214
204
|
status: types_1.TransactionStatus.unapproved,
|
|
215
205
|
time: Date.now(),
|
|
216
|
-
|
|
217
|
-
|
|
206
|
+
transaction,
|
|
207
|
+
deviceConfirmedOn,
|
|
218
208
|
verifiedOnBlockchain: false,
|
|
209
|
+
dappSuggestedGasFees,
|
|
210
|
+
securityAlertResponse,
|
|
211
|
+
// Add actionId to txMeta to check if same actionId is seen again
|
|
212
|
+
actionId,
|
|
219
213
|
};
|
|
220
214
|
try {
|
|
221
|
-
const { gas, estimateGasError } = yield this.estimateGas(
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
const { gas, estimateGasError } = yield this.estimateGas(transaction);
|
|
216
|
+
transaction.gas = gas;
|
|
217
|
+
transaction.estimateGasError = estimateGasError;
|
|
224
218
|
transactionMeta.originalGasEstimate = gas;
|
|
225
219
|
}
|
|
226
220
|
catch (error) {
|
|
@@ -229,13 +223,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
229
223
|
}
|
|
230
224
|
// Checks if a transaction already exists with a given actionId
|
|
231
225
|
if (!existingTransactionMeta) {
|
|
232
|
-
if (!this.isSendFlowHistoryDisabled) {
|
|
233
|
-
transactionMeta.sendFlowHistory = sendFlowHistory !== null && sendFlowHistory !== void 0 ? sendFlowHistory : [];
|
|
234
|
-
}
|
|
235
|
-
// Initial history push
|
|
236
|
-
if (!this.isHistoryDisabled) {
|
|
237
|
-
(0, history_1.addInitialHistorySnapshot)(transactionMeta);
|
|
238
|
-
}
|
|
239
226
|
transactions.push(transactionMeta);
|
|
240
227
|
this.update({
|
|
241
228
|
transactions: this.trimTransactionsForState(transactions),
|
|
@@ -282,18 +269,18 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
282
269
|
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
283
270
|
* and emitting a `<tx.id>:finished` hub event.
|
|
284
271
|
*
|
|
285
|
-
* @param
|
|
272
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
286
273
|
* @param gasValues - The gas values to use for the cancellation transaction.
|
|
287
274
|
* @param options - The options for the cancellation transaction.
|
|
288
275
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
289
276
|
*/
|
|
290
|
-
stopTransaction(
|
|
277
|
+
stopTransaction(transactionID, gasValues, { estimatedBaseFee } = {}) {
|
|
291
278
|
var _a, _b;
|
|
292
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
293
280
|
if (gasValues) {
|
|
294
281
|
(0, utils_1.validateGasValues)(gasValues);
|
|
295
282
|
}
|
|
296
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
283
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionID);
|
|
297
284
|
if (!transactionMeta) {
|
|
298
285
|
return;
|
|
299
286
|
}
|
|
@@ -301,20 +288,20 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
301
288
|
throw new Error('No sign method defined.');
|
|
302
289
|
}
|
|
303
290
|
// gasPrice (legacy non EIP1559)
|
|
304
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.
|
|
291
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.transaction.gasPrice, exports.CANCEL_RATE);
|
|
305
292
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
306
293
|
const newGasPrice = (gasPriceFromValues &&
|
|
307
294
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
308
295
|
minGasPrice;
|
|
309
296
|
// maxFeePerGas (EIP1559)
|
|
310
|
-
const existingMaxFeePerGas = (_a = transactionMeta.
|
|
297
|
+
const existingMaxFeePerGas = (_a = transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
311
298
|
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.CANCEL_RATE);
|
|
312
299
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
313
300
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
314
301
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
315
302
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
316
303
|
// maxPriorityFeePerGas (EIP1559)
|
|
317
|
-
const existingMaxPriorityFeePerGas = (_b = transactionMeta.
|
|
304
|
+
const existingMaxPriorityFeePerGas = (_b = transactionMeta.transaction) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
318
305
|
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.CANCEL_RATE);
|
|
319
306
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
320
307
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
@@ -322,26 +309,25 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
322
309
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
323
310
|
const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
324
311
|
? {
|
|
325
|
-
from: transactionMeta.
|
|
326
|
-
gasLimit: transactionMeta.
|
|
312
|
+
from: transactionMeta.transaction.from,
|
|
313
|
+
gasLimit: transactionMeta.transaction.gas,
|
|
327
314
|
maxFeePerGas: newMaxFeePerGas,
|
|
328
315
|
maxPriorityFeePerGas: newMaxPriorityFeePerGas,
|
|
329
316
|
type: 2,
|
|
330
|
-
nonce: transactionMeta.
|
|
331
|
-
to: transactionMeta.
|
|
317
|
+
nonce: transactionMeta.transaction.nonce,
|
|
318
|
+
to: transactionMeta.transaction.from,
|
|
332
319
|
value: '0x0',
|
|
333
320
|
}
|
|
334
321
|
: {
|
|
335
|
-
from: transactionMeta.
|
|
336
|
-
gasLimit: transactionMeta.
|
|
322
|
+
from: transactionMeta.transaction.from,
|
|
323
|
+
gasLimit: transactionMeta.transaction.gas,
|
|
337
324
|
gasPrice: newGasPrice,
|
|
338
|
-
nonce: transactionMeta.
|
|
339
|
-
to: transactionMeta.
|
|
325
|
+
nonce: transactionMeta.transaction.nonce,
|
|
326
|
+
to: transactionMeta.transaction.from,
|
|
340
327
|
value: '0x0',
|
|
341
328
|
};
|
|
342
329
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
343
|
-
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.
|
|
344
|
-
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
330
|
+
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.transaction.from);
|
|
345
331
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
346
332
|
yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
347
333
|
transactionMeta.estimatedBaseFee = estimatedBaseFee;
|
|
@@ -352,13 +338,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
352
338
|
/**
|
|
353
339
|
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
354
340
|
*
|
|
355
|
-
* @param
|
|
341
|
+
* @param transactionID - The ID of the transaction to speed up.
|
|
356
342
|
* @param gasValues - The gas values to use for the speed up transaction.
|
|
357
343
|
* @param options - The options for the speed up transaction.
|
|
358
344
|
* @param options.actionId - Unique ID to prevent duplicate requests
|
|
359
345
|
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
360
346
|
*/
|
|
361
|
-
speedUpTransaction(
|
|
347
|
+
speedUpTransaction(transactionID, gasValues, { actionId, estimatedBaseFee, } = {}) {
|
|
362
348
|
var _a, _b;
|
|
363
349
|
return __awaiter(this, void 0, void 0, function* () {
|
|
364
350
|
// If transaction is found for same action id, do not create a new speed up transaction.
|
|
@@ -368,7 +354,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
368
354
|
if (gasValues) {
|
|
369
355
|
(0, utils_1.validateGasValues)(gasValues);
|
|
370
356
|
}
|
|
371
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
357
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionID);
|
|
372
358
|
/* istanbul ignore next */
|
|
373
359
|
if (!transactionMeta) {
|
|
374
360
|
return;
|
|
@@ -379,36 +365,35 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
379
365
|
}
|
|
380
366
|
const { transactions } = this.state;
|
|
381
367
|
// gasPrice (legacy non EIP1559)
|
|
382
|
-
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.
|
|
368
|
+
const minGasPrice = (0, utils_1.getIncreasedPriceFromExisting)(transactionMeta.transaction.gasPrice, exports.SPEED_UP_RATE);
|
|
383
369
|
const gasPriceFromValues = (0, utils_1.isGasPriceValue)(gasValues) && gasValues.gasPrice;
|
|
384
370
|
const newGasPrice = (gasPriceFromValues &&
|
|
385
371
|
(0, utils_1.validateMinimumIncrease)(gasPriceFromValues, minGasPrice)) ||
|
|
386
372
|
minGasPrice;
|
|
387
373
|
// maxFeePerGas (EIP1559)
|
|
388
|
-
const existingMaxFeePerGas = (_a = transactionMeta.
|
|
374
|
+
const existingMaxFeePerGas = (_a = transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.maxFeePerGas;
|
|
389
375
|
const minMaxFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxFeePerGas, exports.SPEED_UP_RATE);
|
|
390
376
|
const maxFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxFeePerGas;
|
|
391
377
|
const newMaxFeePerGas = (maxFeePerGasValues &&
|
|
392
378
|
(0, utils_1.validateMinimumIncrease)(maxFeePerGasValues, minMaxFeePerGas)) ||
|
|
393
379
|
(existingMaxFeePerGas && minMaxFeePerGas);
|
|
394
380
|
// maxPriorityFeePerGas (EIP1559)
|
|
395
|
-
const existingMaxPriorityFeePerGas = (_b = transactionMeta.
|
|
381
|
+
const existingMaxPriorityFeePerGas = (_b = transactionMeta.transaction) === null || _b === void 0 ? void 0 : _b.maxPriorityFeePerGas;
|
|
396
382
|
const minMaxPriorityFeePerGas = (0, utils_1.getIncreasedPriceFromExisting)(existingMaxPriorityFeePerGas, exports.SPEED_UP_RATE);
|
|
397
383
|
const maxPriorityFeePerGasValues = (0, utils_1.isFeeMarketEIP1559Values)(gasValues) && gasValues.maxPriorityFeePerGas;
|
|
398
384
|
const newMaxPriorityFeePerGas = (maxPriorityFeePerGasValues &&
|
|
399
385
|
(0, utils_1.validateMinimumIncrease)(maxPriorityFeePerGasValues, minMaxPriorityFeePerGas)) ||
|
|
400
386
|
(existingMaxPriorityFeePerGas && minMaxPriorityFeePerGas);
|
|
401
387
|
const txParams = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
402
|
-
? Object.assign(Object.assign({}, transactionMeta.
|
|
388
|
+
? Object.assign(Object.assign({}, transactionMeta.transaction), { gasLimit: transactionMeta.transaction.gas, maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas, type: 2 }) : Object.assign(Object.assign({}, transactionMeta.transaction), { gasLimit: transactionMeta.transaction.gas, gasPrice: newGasPrice });
|
|
403
389
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
404
|
-
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.
|
|
405
|
-
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
390
|
+
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.transaction.from);
|
|
406
391
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
407
392
|
const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
408
393
|
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), hash,
|
|
409
|
-
actionId, originalGasEstimate: transactionMeta.
|
|
394
|
+
actionId, originalGasEstimate: transactionMeta.transaction.gas });
|
|
410
395
|
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
411
|
-
? Object.assign(Object.assign({}, baseTransactionMeta), {
|
|
396
|
+
? Object.assign(Object.assign({}, baseTransactionMeta), { transaction: Object.assign(Object.assign({}, transactionMeta.transaction), { maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas }) }) : Object.assign(Object.assign({}, baseTransactionMeta), { transaction: Object.assign(Object.assign({}, transactionMeta.transaction), { gasPrice: newGasPrice }) });
|
|
412
397
|
transactions.push(newTransactionMeta);
|
|
413
398
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
414
399
|
this.hub.emit(`${transactionMeta.id}:speedup`, newTransactionMeta);
|
|
@@ -519,15 +504,11 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
519
504
|
* Updates an existing transaction in state.
|
|
520
505
|
*
|
|
521
506
|
* @param transactionMeta - The new transaction to store in state.
|
|
522
|
-
* @param note - A note or update reason to include in the transaction history.
|
|
523
507
|
*/
|
|
524
|
-
updateTransaction(transactionMeta
|
|
508
|
+
updateTransaction(transactionMeta) {
|
|
525
509
|
const { transactions } = this.state;
|
|
526
|
-
transactionMeta.
|
|
527
|
-
(0, utils_1.
|
|
528
|
-
if (!this.isHistoryDisabled) {
|
|
529
|
-
(0, history_1.updateTransactionHistory)(transactionMeta, note);
|
|
530
|
-
}
|
|
510
|
+
transactionMeta.transaction = (0, utils_1.normalizeTransaction)(transactionMeta.transaction);
|
|
511
|
+
(0, utils_1.validateTransaction)(transactionMeta.transaction);
|
|
531
512
|
const index = transactions.findIndex(({ id }) => transactionMeta.id === id);
|
|
532
513
|
transactions[index] = transactionMeta;
|
|
533
514
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
@@ -547,7 +528,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
547
528
|
return;
|
|
548
529
|
}
|
|
549
530
|
const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
|
|
550
|
-
const newTransactions = this.state.transactions.filter(({ networkID, chainId,
|
|
531
|
+
const newTransactions = this.state.transactions.filter(({ networkID, chainId, transaction }) => {
|
|
551
532
|
var _a;
|
|
552
533
|
// Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.
|
|
553
534
|
const isMatchingNetwork = ignoreNetwork ||
|
|
@@ -556,7 +537,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
556
537
|
if (!isMatchingNetwork) {
|
|
557
538
|
return true;
|
|
558
539
|
}
|
|
559
|
-
const isMatchingAddress = !address || ((_a =
|
|
540
|
+
const isMatchingAddress = !address || ((_a = transaction.from) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase();
|
|
560
541
|
return !isMatchingAddress;
|
|
561
542
|
});
|
|
562
543
|
this.update({
|
|
@@ -591,88 +572,13 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
591
572
|
// Update same nonce local transactions as dropped and define replacedBy properties.
|
|
592
573
|
this.markNonceDuplicatesDropped(transactionId);
|
|
593
574
|
// Update external provided transaction with updated gas values and confirmed status.
|
|
594
|
-
this.updateTransaction(transactionMeta
|
|
575
|
+
this.updateTransaction(transactionMeta);
|
|
595
576
|
}
|
|
596
577
|
catch (error) {
|
|
597
578
|
console.error(error);
|
|
598
579
|
}
|
|
599
580
|
});
|
|
600
581
|
}
|
|
601
|
-
/**
|
|
602
|
-
* Append new send flow history to a transaction.
|
|
603
|
-
*
|
|
604
|
-
* @param transactionID - The ID of the transaction to update.
|
|
605
|
-
* @param currentSendFlowHistoryLength - The length of the current sendFlowHistory array.
|
|
606
|
-
* @param sendFlowHistoryToAdd - The sendFlowHistory entries to add.
|
|
607
|
-
* @returns The updated transactionMeta.
|
|
608
|
-
*/
|
|
609
|
-
updateTransactionSendFlowHistory(transactionID, currentSendFlowHistoryLength, sendFlowHistoryToAdd) {
|
|
610
|
-
var _a, _b;
|
|
611
|
-
if (this.isSendFlowHistoryDisabled) {
|
|
612
|
-
throw new Error('Send flow history is disabled for the current transaction controller');
|
|
613
|
-
}
|
|
614
|
-
const transactionMeta = this.getTransaction(transactionID);
|
|
615
|
-
if (!transactionMeta) {
|
|
616
|
-
throw new Error(`Cannot update send flow history as no transaction metadata found`);
|
|
617
|
-
}
|
|
618
|
-
(0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateTransactionSendFlowHistory');
|
|
619
|
-
if (currentSendFlowHistoryLength ===
|
|
620
|
-
(((_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.sendFlowHistory) === null || _a === void 0 ? void 0 : _a.length) || 0)) {
|
|
621
|
-
transactionMeta.sendFlowHistory = [
|
|
622
|
-
...((_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.sendFlowHistory) !== null && _b !== void 0 ? _b : []),
|
|
623
|
-
...sendFlowHistoryToAdd,
|
|
624
|
-
];
|
|
625
|
-
this.updateTransaction(transactionMeta, 'TransactionController:updateTransactionSendFlowHistory - sendFlowHistory updated');
|
|
626
|
-
}
|
|
627
|
-
return this.getTransaction(transactionID);
|
|
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
|
-
}
|
|
676
582
|
processApproval(transactionMeta, { isExisting = false, requireApproval, shouldShowRequest = true, }) {
|
|
677
583
|
return __awaiter(this, void 0, void 0, function* () {
|
|
678
584
|
const transactionId = transactionMeta.id;
|
|
@@ -732,16 +638,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
732
638
|
* using the sign configuration property, then published to the blockchain.
|
|
733
639
|
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
734
640
|
*
|
|
735
|
-
* @param
|
|
641
|
+
* @param transactionID - The ID of the transaction to approve.
|
|
736
642
|
*/
|
|
737
|
-
approveTransaction(
|
|
643
|
+
approveTransaction(transactionID) {
|
|
738
644
|
return __awaiter(this, void 0, void 0, function* () {
|
|
739
645
|
const { transactions } = this.state;
|
|
740
646
|
const releaseLock = yield this.mutex.acquire();
|
|
741
647
|
const { chainId } = this.getChainAndNetworkId();
|
|
742
|
-
const index = transactions.findIndex(({ id }) =>
|
|
648
|
+
const index = transactions.findIndex(({ id }) => transactionID === id);
|
|
743
649
|
const transactionMeta = transactions[index];
|
|
744
|
-
const {
|
|
650
|
+
const { transaction: { nonce, from }, } = transactionMeta;
|
|
745
651
|
let nonceLock;
|
|
746
652
|
try {
|
|
747
653
|
if (!this.sign) {
|
|
@@ -763,12 +669,12 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
763
669
|
nonceToUse = (0, ethereumjs_util_1.addHexPrefix)(nonceLock.nextNonce.toString(16));
|
|
764
670
|
}
|
|
765
671
|
transactionMeta.status = status;
|
|
766
|
-
transactionMeta.
|
|
767
|
-
transactionMeta.
|
|
768
|
-
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.
|
|
769
|
-
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.
|
|
672
|
+
transactionMeta.transaction.nonce = nonceToUse;
|
|
673
|
+
transactionMeta.transaction.chainId = chainId;
|
|
674
|
+
const baseTxParams = Object.assign(Object.assign({}, transactionMeta.transaction), { gasLimit: transactionMeta.transaction.gas });
|
|
675
|
+
const isEIP1559 = (0, utils_1.isEIP1559Transaction)(transactionMeta.transaction);
|
|
770
676
|
const txParams = isEIP1559
|
|
771
|
-
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.
|
|
677
|
+
? Object.assign(Object.assign({}, baseTxParams), { maxFeePerGas: transactionMeta.transaction.maxFeePerGas, maxPriorityFeePerGas: transactionMeta.transaction.maxPriorityFeePerGas, estimatedBaseFee: transactionMeta.transaction.estimatedBaseFee,
|
|
772
678
|
// specify type 2 if maxFeePerGas and maxPriorityFeePerGas are set
|
|
773
679
|
type: 2 }) : baseTxParams;
|
|
774
680
|
// delete gasPrice if maxFeePerGas and maxPriorityFeePerGas are set
|
|
@@ -777,17 +683,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
777
683
|
}
|
|
778
684
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
779
685
|
const signedTx = yield this.sign(unsignedEthTx, from);
|
|
780
|
-
yield this.updateTransactionMetaRSV(transactionMeta, signedTx);
|
|
781
686
|
transactionMeta.status = types_1.TransactionStatus.signed;
|
|
782
|
-
this.updateTransaction(transactionMeta
|
|
687
|
+
this.updateTransaction(transactionMeta);
|
|
783
688
|
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
784
689
|
transactionMeta.rawTx = rawTx;
|
|
785
|
-
this.updateTransaction(transactionMeta
|
|
690
|
+
this.updateTransaction(transactionMeta);
|
|
786
691
|
const hash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
787
692
|
transactionMeta.hash = hash;
|
|
788
693
|
transactionMeta.status = types_1.TransactionStatus.submitted;
|
|
789
694
|
transactionMeta.submittedTime = new Date().getTime();
|
|
790
|
-
this.updateTransaction(transactionMeta
|
|
695
|
+
this.updateTransaction(transactionMeta);
|
|
791
696
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
792
697
|
}
|
|
793
698
|
catch (error) {
|
|
@@ -806,16 +711,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
806
711
|
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
807
712
|
* and emitting a `<tx.id>:finished` hub event.
|
|
808
713
|
*
|
|
809
|
-
* @param
|
|
714
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
810
715
|
*/
|
|
811
|
-
cancelTransaction(
|
|
812
|
-
const transactionMeta = this.state.transactions.find(({ id }) => id ===
|
|
716
|
+
cancelTransaction(transactionID) {
|
|
717
|
+
const transactionMeta = this.state.transactions.find(({ id }) => id === transactionID);
|
|
813
718
|
if (!transactionMeta) {
|
|
814
719
|
return;
|
|
815
720
|
}
|
|
816
721
|
transactionMeta.status = types_1.TransactionStatus.rejected;
|
|
817
722
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
818
|
-
const transactions = this.state.transactions.filter(({ id }) => id !==
|
|
723
|
+
const transactions = this.state.transactions.filter(({ id }) => id !== transactionID);
|
|
819
724
|
this.update({ transactions: this.trimTransactionsForState(transactions) });
|
|
820
725
|
}
|
|
821
726
|
/**
|
|
@@ -837,9 +742,9 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
837
742
|
const txsToKeep = transactions
|
|
838
743
|
.sort((a, b) => (a.time > b.time ? -1 : 1)) // Descending time order
|
|
839
744
|
.filter((tx) => {
|
|
840
|
-
const { chainId, networkID, status,
|
|
841
|
-
if (
|
|
842
|
-
const key = `${
|
|
745
|
+
const { chainId, networkID, status, transaction, time } = tx;
|
|
746
|
+
if (transaction) {
|
|
747
|
+
const key = `${transaction.nonce}-${chainId ? (0, controller_utils_1.convertHexToDecimal)(chainId) : networkID}-${new Date(time).toDateString()}`;
|
|
843
748
|
if (nonceNetworkSet.has(key)) {
|
|
844
749
|
return true;
|
|
845
750
|
}
|
|
@@ -902,7 +807,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
902
807
|
txReceipt.blockHash,
|
|
903
808
|
]);
|
|
904
809
|
meta.verifiedOnBlockchain = true;
|
|
905
|
-
meta.
|
|
810
|
+
meta.transaction.gasUsed = txReceipt.gasUsed;
|
|
906
811
|
meta.txReceipt = txReceipt;
|
|
907
812
|
meta.baseFeePerGas = txBlock === null || txBlock === void 0 ? void 0 : txBlock.baseFeePerGas;
|
|
908
813
|
meta.blockTimestamp = txBlock === null || txBlock === void 0 ? void 0 : txBlock.timestamp;
|
|
@@ -1042,11 +947,11 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1042
947
|
this.update({ lastFetchedBlockNumbers });
|
|
1043
948
|
this.hub.emit('incomingTransactionBlock', blockNumber);
|
|
1044
949
|
}
|
|
1045
|
-
generateDappSuggestedGasFees(
|
|
950
|
+
generateDappSuggestedGasFees(transaction, origin) {
|
|
1046
951
|
if (!origin || origin === controller_utils_1.ORIGIN_METAMASK) {
|
|
1047
952
|
return undefined;
|
|
1048
953
|
}
|
|
1049
|
-
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } =
|
|
954
|
+
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = transaction;
|
|
1050
955
|
if (gasPrice === undefined &&
|
|
1051
956
|
maxFeePerGas === undefined &&
|
|
1052
957
|
maxPriorityFeePerGas === undefined &&
|
|
@@ -1073,22 +978,16 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1073
978
|
* @param transactionMeta - Nominated external transaction to be added to state.
|
|
1074
979
|
*/
|
|
1075
980
|
addExternalTransaction(transactionMeta) {
|
|
1076
|
-
var _a
|
|
981
|
+
var _a;
|
|
1077
982
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1078
983
|
const { networkId, chainId } = this.getChainAndNetworkId();
|
|
1079
984
|
const { transactions } = this.state;
|
|
1080
|
-
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1081
|
-
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.
|
|
985
|
+
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.from;
|
|
986
|
+
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.transaction.from === fromAddress &&
|
|
1082
987
|
(0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
|
|
1083
988
|
const confirmedTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.confirmed);
|
|
1084
989
|
const pendingTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.submitted);
|
|
1085
990
|
(0, external_transactions_1.validateConfirmedExternalTransaction)(transactionMeta, confirmedTxs, pendingTxs);
|
|
1086
|
-
// Make sure provided external transaction has non empty history array
|
|
1087
|
-
if (!((_b = transactionMeta.history) !== null && _b !== void 0 ? _b : []).length) {
|
|
1088
|
-
if (!this.isHistoryDisabled) {
|
|
1089
|
-
(0, history_1.addInitialHistorySnapshot)(transactionMeta);
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
991
|
const updatedTransactions = [...transactions, transactionMeta];
|
|
1093
992
|
this.update({
|
|
1094
993
|
transactions: this.trimTransactionsForState(updatedTransactions),
|
|
@@ -1105,10 +1004,10 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1105
1004
|
var _a, _b;
|
|
1106
1005
|
const { networkId, chainId } = this.getChainAndNetworkId();
|
|
1107
1006
|
const transactionMeta = this.getTransaction(transactionId);
|
|
1108
|
-
const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1109
|
-
const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.
|
|
1110
|
-
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.
|
|
1111
|
-
transaction.
|
|
1007
|
+
const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.nonce;
|
|
1008
|
+
const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _b === void 0 ? void 0 : _b.from;
|
|
1009
|
+
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.transaction.from === from &&
|
|
1010
|
+
transaction.transaction.nonce === nonce &&
|
|
1112
1011
|
(0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
|
|
1113
1012
|
if (!sameNonceTxs.length) {
|
|
1114
1013
|
return;
|
|
@@ -1133,7 +1032,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1133
1032
|
*/
|
|
1134
1033
|
setTransactionStatusDropped(transactionMeta) {
|
|
1135
1034
|
transactionMeta.status = types_1.TransactionStatus.dropped;
|
|
1136
|
-
this.updateTransaction(transactionMeta
|
|
1035
|
+
this.updateTransaction(transactionMeta);
|
|
1137
1036
|
}
|
|
1138
1037
|
/**
|
|
1139
1038
|
* Get transaction with provided actionId.
|
|
@@ -1153,26 +1052,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
1153
1052
|
});
|
|
1154
1053
|
});
|
|
1155
1054
|
}
|
|
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
|
-
}
|
|
1176
1055
|
}
|
|
1177
1056
|
exports.TransactionController = TransactionController;
|
|
1178
1057
|
exports.default = TransactionController;
|