@metamask-previews/transaction-controller 9.0.0-preview.3dbf14f → 9.2.0-preview.a8d97a1
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 +19 -1
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +1 -0
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/TransactionController.d.ts +55 -5
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +186 -44
- package/dist/TransactionController.js.map +1 -1
- package/dist/constants.d.ts +0 -19
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +1 -1
- package/dist/external-transactions.d.ts +10 -0
- package/dist/external-transactions.d.ts.map +1 -0
- package/dist/external-transactions.js +36 -0
- package/dist/external-transactions.js.map +1 -0
- package/dist/types.d.ts +41 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +11 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [9.2.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Persist `estimatedBaseFee` in `stopTransaction` and `speedUpTransaction` ([#1621](https://github.com/MetaMask/core/pull/1621))
|
|
12
|
+
- Add `securityAlertResponse` to `addTransaction` `opts` argument ([#1636](https://github.com/MetaMask/core/pull/1636))
|
|
13
|
+
|
|
14
|
+
## [9.1.0]
|
|
15
|
+
### Added
|
|
16
|
+
- Add `blockTimestamp` to `TransactionMetaBase` type ([#1616](https://github.com/MetaMask/core/pull/1616))
|
|
17
|
+
- Update `queryTransactionStatuses` to populate `blockTimestamp` on each transaction when it is verified ([#1616](https://github.com/MetaMask/core/pull/1616))
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Bump dependency and peer dependency on `@metamask/approval-controller` to ^3.5.1
|
|
21
|
+
- Bump dependency on `@metamask/base-controller` to ^3.2.1
|
|
22
|
+
- Bump dependency on `@metamask/controller-utils` to ^4.3.2
|
|
23
|
+
- Bump dependency and peer dependency on `@metamask/network-controller` to ^12.1.2
|
|
24
|
+
|
|
9
25
|
## [9.0.0]
|
|
10
26
|
### Added
|
|
11
27
|
- Add `baseFeePerGas` to transaction metadata ([#1590](https://github.com/MetaMask/core/pull/1590))
|
|
@@ -135,7 +151,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
135
151
|
|
|
136
152
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
137
153
|
|
|
138
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@9.
|
|
154
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@9.2.0...HEAD
|
|
155
|
+
[9.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@9.1.0...@metamask/transaction-controller@9.2.0
|
|
156
|
+
[9.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@9.0.0...@metamask/transaction-controller@9.1.0
|
|
139
157
|
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@8.0.1...@metamask/transaction-controller@9.0.0
|
|
140
158
|
[8.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@8.0.0...@metamask/transaction-controller@8.0.1
|
|
141
159
|
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@7.1.0...@metamask/transaction-controller@8.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EtherscanRemoteTransactionSource.d.ts","sourceRoot":"","sources":["../src/EtherscanRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAgB3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC9B,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,qBAAa,gCACX,YAAW,uBAAuB;;gBAMtB,EACV,MAAM,EACN,qBAAqB,GACtB,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAAO;IAK5D,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAInC,iBAAiB,CACrB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"EtherscanRemoteTransactionSource.d.ts","sourceRoot":"","sources":["../src/EtherscanRemoteTransactionSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAgB3C,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC9B,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,qBAAa,gCACX,YAAW,uBAAuB;;gBAMtB,EACV,MAAM,EACN,qBAAqB,GACtB,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAAO;IAK5D,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAInC,iBAAiB,CACrB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,eAAe,EAAE,CAAC;CA6F9B"}
|
|
@@ -83,6 +83,7 @@ _EtherscanRemoteTransactionSource_apiKey = new WeakMap(), _EtherscanRemoteTransa
|
|
|
83
83
|
status: types_1.TransactionStatus.confirmed,
|
|
84
84
|
time,
|
|
85
85
|
transaction: {
|
|
86
|
+
chainId: currentChainId,
|
|
86
87
|
from: txMeta.from,
|
|
87
88
|
gas: (0, controller_utils_1.BNToHex)(new ethereumjs_util_1.BN(txMeta.gas)),
|
|
88
89
|
gasPrice: (0, controller_utils_1.BNToHex)(new ethereumjs_util_1.BN(txMeta.gasPrice)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EtherscanRemoteTransactionSource.js","sourceRoot":"","sources":["../src/EtherscanRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAqD;AAErD,qDAAqC;AACrC,+BAAoC;AAEpC,2CAA2D;AAQ3D,2CAGqB;AAMrB,mCAA4C;AAE5C;;GAEG;AACH,MAAa,gCAAgC;IAO3C,YAAY,EACV,MAAM,EACN,qBAAqB,MACmC,EAAE;;QAP5D,2DAAiB;QAEjB,0EAAgC;QAM9B,uBAAA,IAAI,4CAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2DAA0B,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,IAAI,MAAA,CAAC;IAC9D,CAAC;IAED,kBAAkB,CAAC,OAAY;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,wCAA4B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IAEK,iBAAiB,CACrB,OAAuC;;YAEvC,MAAM,gBAAgB,mCACjB,OAAO,KACV,MAAM,EAAE,uBAAA,IAAI,gDAAQ,EACpB,OAAO,EAAE,OAAO,CAAC,cAAc,GAChC,CAAC;YAEF,MAAM,kBAAkB,GAAG,IAAA,sCAA0B,EAAC,gBAAgB,CAAC,CAAC;YAExE,MAAM,uBAAuB,GAAG,uBAAA,IAAI,+DAAuB;gBACzD,CAAC,CAAC,IAAA,2CAA+B,EAAC,gBAAgB,CAAC;gBACnD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;oBACd,MAAM,EAAE,EAAqC;iBACiB,CAAC,CAAC;YAEtE,MAAM,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,GACvD,MAAM,OA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AAE,EAAE,MAAM,CAAC,EAAE;YACb,KAAK,EAAE,IAAA,0BAAO,EAAC,IAAI,oBAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACrC;QACD,eAAe,EAAE,MAAM,CAAC,IAAI;QAC5B,oBAAoB,EAAE,KAAK;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { BN } from 'ethereumjs-util';\nimport { v1 as random } from 'uuid';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from './constants';\nimport type {\n EtherscanTokenTransactionMeta,\n EtherscanTransactionMeta,\n EtherscanTransactionMetaBase,\n EtherscanTransactionRequest,\n EtherscanTransactionResponse,\n} from './etherscan';\nimport {\n fetchEtherscanTokenTransactions,\n fetchEtherscanTransactions,\n} from './etherscan';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionMeta,\n} from './types';\nimport { TransactionStatus } from './types';\n\n/**\n * A RemoteTransactionSource that fetches transaction data from Etherscan.\n */\nexport class EtherscanRemoteTransactionSource\n implements RemoteTransactionSource\n{\n #apiKey?: string;\n\n #includeTokenTransfers: boolean;\n\n constructor({\n apiKey,\n includeTokenTransfers,\n }: { apiKey?: string; includeTokenTransfers?: boolean } = {}) {\n this.#apiKey = apiKey;\n this.#includeTokenTransfers = includeTokenTransfers ?? true;\n }\n\n isSupportedNetwork(chainId: Hex): boolean {\n return Object.keys(ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const etherscanRequest: EtherscanTransactionRequest = {\n ...request,\n apiKey: this.#apiKey,\n chainId: request.currentChainId,\n };\n\n const transactionPromise = fetchEtherscanTransactions(etherscanRequest);\n\n const tokenTransactionPromise = this.#includeTokenTransfers\n ? fetchEtherscanTokenTransactions(etherscanRequest)\n : Promise.resolve({\n result: [] as EtherscanTokenTransactionMeta[],\n } as EtherscanTransactionResponse<EtherscanTokenTransactionMeta>);\n\n const [etherscanTransactions, etherscanTokenTransactions] =\n await Promise.all([transactionPromise, tokenTransactionPromise]);\n\n const transactions = etherscanTransactions.result.map((tx) =>\n this.#normalizeTransaction(tx, request.currentChainId),\n );\n\n const tokenTransactions = etherscanTokenTransactions.result.map((tx) =>\n this.#normalizeTokenTransaction(tx, request.currentChainId),\n );\n\n return [...transactions, ...tokenTransactions];\n }\n\n #normalizeTransaction(\n txMeta: EtherscanTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n transaction: {\n ...base.transaction,\n data: txMeta.input,\n },\n ...(txMeta.isError === '0'\n ? { status: TransactionStatus.confirmed }\n : {\n error: new Error('Transaction failed'),\n status: TransactionStatus.failed,\n }),\n };\n }\n\n #normalizeTokenTransaction(\n txMeta: EtherscanTokenTransactionMeta,\n currentChainId: Hex,\n ): TransactionMeta {\n const base = this.#normalizeTransactionBase(txMeta, currentChainId);\n\n return {\n ...base,\n isTransfer: true,\n transferInformation: {\n contractAddress: txMeta.contractAddress,\n decimals: Number(txMeta.tokenDecimal),\n symbol: txMeta.tokenSymbol,\n },\n };\n }\n\n #normalizeTransactionBase(\n txMeta: EtherscanTransactionMetaBase,\n currentChainId: Hex,\n ): TransactionMeta {\n const time = parseInt(txMeta.timeStamp, 10) * 1000;\n\n return {\n blockNumber: txMeta.blockNumber,\n chainId: currentChainId,\n id: random({ msecs: time }),\n status: TransactionStatus.confirmed,\n time,\n transaction: {\n chainId: currentChainId,\n from: txMeta.from,\n gas: BNToHex(new BN(txMeta.gas)),\n gasPrice: BNToHex(new BN(txMeta.gasPrice)),\n gasUsed: BNToHex(new BN(txMeta.gasUsed)),\n nonce: BNToHex(new BN(txMeta.nonce)),\n to: txMeta.to,\n value: BNToHex(new BN(txMeta.value)),\n },\n transactionHash: txMeta.hash,\n verifiedOnBlockchain: false,\n };\n }\n}\n"]}
|
|
@@ -5,8 +5,9 @@ import type { AddApprovalRequest } from '@metamask/approval-controller';
|
|
|
5
5
|
import type { BaseConfig, BaseState, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
6
6
|
import { BaseController } from '@metamask/base-controller';
|
|
7
7
|
import type { BlockTracker, NetworkState, Provider } from '@metamask/network-controller';
|
|
8
|
+
import type { Hex } from '@metamask/utils';
|
|
8
9
|
import { EventEmitter } from 'events';
|
|
9
|
-
import type { Transaction, TransactionMeta, WalletDevice } from './types';
|
|
10
|
+
import type { Transaction, TransactionMeta, TransactionReceipt, WalletDevice } from './types';
|
|
10
11
|
export declare const HARDFORK = Hardfork.London;
|
|
11
12
|
/**
|
|
12
13
|
* @type Result
|
|
@@ -172,15 +173,19 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
172
173
|
*
|
|
173
174
|
* @param transaction - The transaction object to add.
|
|
174
175
|
* @param opts - Additional options to control how the transaction is added.
|
|
176
|
+
* @param opts.actionId - Unique ID to prevent duplicate requests.
|
|
175
177
|
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
176
178
|
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
177
179
|
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
180
|
+
* @param opts.securityAlertResponse - Response from security validator.
|
|
178
181
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
179
182
|
*/
|
|
180
|
-
addTransaction(transaction: Transaction, { deviceConfirmedOn, origin, requireApproval, }?: {
|
|
183
|
+
addTransaction(transaction: Transaction, { actionId, deviceConfirmedOn, origin, requireApproval, securityAlertResponse, }?: {
|
|
184
|
+
actionId?: string;
|
|
181
185
|
deviceConfirmedOn?: WalletDevice;
|
|
182
186
|
origin?: string;
|
|
183
187
|
requireApproval?: boolean | undefined;
|
|
188
|
+
securityAlertResponse?: Record<string, unknown>;
|
|
184
189
|
}): Promise<Result>;
|
|
185
190
|
startIncomingTransactionPolling(): void;
|
|
186
191
|
stopIncomingTransactionPolling(): void;
|
|
@@ -195,15 +200,25 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
195
200
|
*
|
|
196
201
|
* @param transactionID - The ID of the transaction to cancel.
|
|
197
202
|
* @param gasValues - The gas values to use for the cancellation transaction.
|
|
203
|
+
* @param options - The options for the cancellation transaction.
|
|
204
|
+
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
198
205
|
*/
|
|
199
|
-
stopTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values
|
|
206
|
+
stopTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values, { estimatedBaseFee }?: {
|
|
207
|
+
estimatedBaseFee?: string;
|
|
208
|
+
}): Promise<void>;
|
|
200
209
|
/**
|
|
201
210
|
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
202
211
|
*
|
|
203
212
|
* @param transactionID - The ID of the transaction to speed up.
|
|
204
|
-
* @param gasValues - The gas values to use for the speed up
|
|
213
|
+
* @param gasValues - The gas values to use for the speed up transaction.
|
|
214
|
+
* @param options - The options for the speed up transaction.
|
|
215
|
+
* @param options.actionId - Unique ID to prevent duplicate requests
|
|
216
|
+
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
205
217
|
*/
|
|
206
|
-
speedUpTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values
|
|
218
|
+
speedUpTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values, { actionId, estimatedBaseFee, }?: {
|
|
219
|
+
actionId?: string;
|
|
220
|
+
estimatedBaseFee?: string;
|
|
221
|
+
}): Promise<void>;
|
|
207
222
|
/**
|
|
208
223
|
* Estimates required gas for a given transaction.
|
|
209
224
|
*
|
|
@@ -241,6 +256,14 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
241
256
|
wipeTransactions(ignoreNetwork?: boolean, address?: string): void;
|
|
242
257
|
startIncomingTransactionProcessing(): void;
|
|
243
258
|
stopIncomingTransactionProcessing(): void;
|
|
259
|
+
/**
|
|
260
|
+
* Adds external provided transaction to state as confirmed transaction.
|
|
261
|
+
*
|
|
262
|
+
* @param transactionMeta - TransactionMeta to add transactions.
|
|
263
|
+
* @param transactionReceipt - TransactionReceipt of the external transaction.
|
|
264
|
+
* @param baseFeePerGas - Base fee per gas of the external transaction.
|
|
265
|
+
*/
|
|
266
|
+
confirmExternalTransaction(transactionMeta: TransactionMeta, transactionReceipt: TransactionReceipt, baseFeePerGas: Hex): Promise<void>;
|
|
244
267
|
private processApproval;
|
|
245
268
|
/**
|
|
246
269
|
* Approves a transaction and updates it's status in state. If this is not a
|
|
@@ -323,6 +346,33 @@ export declare class TransactionController extends BaseController<TransactionCon
|
|
|
323
346
|
private onIncomingTransactions;
|
|
324
347
|
private onUpdatedLastFetchedBlockNumbers;
|
|
325
348
|
private generateDappSuggestedGasFees;
|
|
349
|
+
/**
|
|
350
|
+
* Validates and adds external provided transaction to state.
|
|
351
|
+
*
|
|
352
|
+
* @param transactionMeta - Nominated external transaction to be added to state.
|
|
353
|
+
*/
|
|
354
|
+
private addExternalTransaction;
|
|
355
|
+
/**
|
|
356
|
+
* Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions
|
|
357
|
+
* in the transactions have the same nonce.
|
|
358
|
+
*
|
|
359
|
+
* @param transactionId - Used to identify original transaction.
|
|
360
|
+
*/
|
|
361
|
+
private markNonceDuplicatesDropped;
|
|
362
|
+
/**
|
|
363
|
+
* Method to set transaction status to dropped.
|
|
364
|
+
*
|
|
365
|
+
* @param transactionMeta - TransactionMeta of transaction to be marked as dropped.
|
|
366
|
+
*/
|
|
367
|
+
private setTransactionStatusDropped;
|
|
368
|
+
/**
|
|
369
|
+
* Get transaction with provided actionId.
|
|
370
|
+
*
|
|
371
|
+
* @param actionId - Unique ID to prevent duplicate requests
|
|
372
|
+
* @returns the filtered transaction
|
|
373
|
+
*/
|
|
374
|
+
private getTransactionWithActionId;
|
|
375
|
+
private waitForTransactionFinished;
|
|
326
376
|
}
|
|
327
377
|
export default TransactionController;
|
|
328
378
|
//# sourceMappingURL=TransactionController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAa3D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAa3D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAK3C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAOtC,OAAO,KAAK,EAEV,WAAW,EACX,eAAe,EACf,kBAAkB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BlC;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAKnC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;YAMpB,0BAA0B;CASzC;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -26,6 +26,7 @@ const events_1 = require("events");
|
|
|
26
26
|
const nonce_tracker_1 = __importDefault(require("nonce-tracker"));
|
|
27
27
|
const uuid_1 = require("uuid");
|
|
28
28
|
const EtherscanRemoteTransactionSource_1 = require("./EtherscanRemoteTransactionSource");
|
|
29
|
+
const external_transactions_1 = require("./external-transactions");
|
|
29
30
|
const IncomingTransactionHelper_1 = require("./IncomingTransactionHelper");
|
|
30
31
|
const types_1 = require("./types");
|
|
31
32
|
const utils_1 = require("./utils");
|
|
@@ -176,19 +177,23 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
176
177
|
*
|
|
177
178
|
* @param transaction - The transaction object to add.
|
|
178
179
|
* @param opts - Additional options to control how the transaction is added.
|
|
180
|
+
* @param opts.actionId - Unique ID to prevent duplicate requests.
|
|
179
181
|
* @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
|
|
180
182
|
* @param opts.origin - The origin of the transaction request, such as a dApp hostname.
|
|
181
183
|
* @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
|
|
184
|
+
* @param opts.securityAlertResponse - Response from security validator.
|
|
182
185
|
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
183
186
|
*/
|
|
184
|
-
addTransaction(transaction, { deviceConfirmedOn, origin, requireApproval, } = {}) {
|
|
187
|
+
addTransaction(transaction, { actionId, deviceConfirmedOn, origin, requireApproval, securityAlertResponse, } = {}) {
|
|
185
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
189
|
const chainId = this.getChainId();
|
|
187
190
|
const { transactions } = this.state;
|
|
188
191
|
transaction = (0, utils_1.normalizeTransaction)(transaction);
|
|
189
192
|
(0, utils_1.validateTransaction)(transaction);
|
|
190
193
|
const dappSuggestedGasFees = this.generateDappSuggestedGasFees(transaction, origin);
|
|
191
|
-
const
|
|
194
|
+
const existingTransactionMeta = this.getTransactionWithActionId(actionId);
|
|
195
|
+
// If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
|
|
196
|
+
const transactionMeta = existingTransactionMeta || {
|
|
192
197
|
id: (0, uuid_1.v1)(),
|
|
193
198
|
chainId,
|
|
194
199
|
origin,
|
|
@@ -198,6 +203,9 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
198
203
|
deviceConfirmedOn,
|
|
199
204
|
verifiedOnBlockchain: false,
|
|
200
205
|
dappSuggestedGasFees,
|
|
206
|
+
securityAlertResponse,
|
|
207
|
+
// Add actionId to txMeta to check if same actionId is seen again
|
|
208
|
+
actionId,
|
|
201
209
|
};
|
|
202
210
|
try {
|
|
203
211
|
const { gas, estimateGasError } = yield this.estimateGas(transaction);
|
|
@@ -208,11 +216,17 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
208
216
|
this.failTransaction(transactionMeta, error);
|
|
209
217
|
return Promise.reject(error);
|
|
210
218
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
// Checks if a transaction already exists with a given actionId
|
|
220
|
+
if (!existingTransactionMeta) {
|
|
221
|
+
transactions.push(transactionMeta);
|
|
222
|
+
this.update({
|
|
223
|
+
transactions: this.trimTransactionsForState(transactions),
|
|
224
|
+
});
|
|
225
|
+
this.hub.emit(`unapprovedTransaction`, transactionMeta);
|
|
226
|
+
}
|
|
214
227
|
return {
|
|
215
228
|
result: this.processApproval(transactionMeta, {
|
|
229
|
+
isExisting: Boolean(existingTransactionMeta),
|
|
216
230
|
requireApproval,
|
|
217
231
|
}),
|
|
218
232
|
transactionMeta,
|
|
@@ -236,7 +250,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
236
250
|
initApprovals() {
|
|
237
251
|
const chainId = this.getChainId();
|
|
238
252
|
const unapprovedTxs = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.unapproved &&
|
|
239
|
-
transaction
|
|
253
|
+
(0, utils_1.transactionMatchesChainId)(transaction, chainId));
|
|
240
254
|
for (const txMeta of unapprovedTxs) {
|
|
241
255
|
this.processApproval(txMeta, {
|
|
242
256
|
shouldShowRequest: false,
|
|
@@ -252,8 +266,10 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
252
266
|
*
|
|
253
267
|
* @param transactionID - The ID of the transaction to cancel.
|
|
254
268
|
* @param gasValues - The gas values to use for the cancellation transaction.
|
|
269
|
+
* @param options - The options for the cancellation transaction.
|
|
270
|
+
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
255
271
|
*/
|
|
256
|
-
stopTransaction(transactionID, gasValues) {
|
|
272
|
+
stopTransaction(transactionID, gasValues, { estimatedBaseFee } = {}) {
|
|
257
273
|
var _a, _b;
|
|
258
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
275
|
if (gasValues) {
|
|
@@ -307,8 +323,9 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
307
323
|
};
|
|
308
324
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
309
325
|
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.transaction.from);
|
|
310
|
-
const
|
|
311
|
-
yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [
|
|
326
|
+
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
327
|
+
yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [rawTx]);
|
|
328
|
+
transactionMeta.estimatedBaseFee = estimatedBaseFee;
|
|
312
329
|
transactionMeta.status = types_1.TransactionStatus.cancelled;
|
|
313
330
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
314
331
|
});
|
|
@@ -317,11 +334,18 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
317
334
|
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
318
335
|
*
|
|
319
336
|
* @param transactionID - The ID of the transaction to speed up.
|
|
320
|
-
* @param gasValues - The gas values to use for the speed up
|
|
337
|
+
* @param gasValues - The gas values to use for the speed up transaction.
|
|
338
|
+
* @param options - The options for the speed up transaction.
|
|
339
|
+
* @param options.actionId - Unique ID to prevent duplicate requests
|
|
340
|
+
* @param options.estimatedBaseFee - The estimated base fee of the transaction.
|
|
321
341
|
*/
|
|
322
|
-
speedUpTransaction(transactionID, gasValues) {
|
|
342
|
+
speedUpTransaction(transactionID, gasValues, { actionId, estimatedBaseFee, } = {}) {
|
|
323
343
|
var _a, _b;
|
|
324
344
|
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
// If transaction is found for same action id, do not create a new speed up transaction.
|
|
346
|
+
if (this.getTransactionWithActionId(actionId)) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
325
349
|
if (gasValues) {
|
|
326
350
|
(0, utils_1.validateGasValues)(gasValues);
|
|
327
351
|
}
|
|
@@ -359,11 +383,12 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
359
383
|
? 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 });
|
|
360
384
|
const unsignedEthTx = this.prepareUnsignedEthTx(txParams);
|
|
361
385
|
const signedTx = yield this.sign(unsignedEthTx, transactionMeta.transaction.from);
|
|
362
|
-
const
|
|
386
|
+
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
363
387
|
const transactionHash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [
|
|
364
|
-
|
|
388
|
+
rawTx,
|
|
365
389
|
]);
|
|
366
|
-
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { id: (0, uuid_1.v1)(), time: Date.now(), transactionHash
|
|
390
|
+
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { estimatedBaseFee, id: (0, uuid_1.v1)(), time: Date.now(), transactionHash,
|
|
391
|
+
actionId });
|
|
367
392
|
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
|
|
368
393
|
? 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 }) });
|
|
369
394
|
transactions.push(newTransactionMeta);
|
|
@@ -452,7 +477,8 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
452
477
|
const currentChainId = this.getChainId();
|
|
453
478
|
let gotUpdates = false;
|
|
454
479
|
yield (0, controller_utils_1.safelyExecute)(() => Promise.all(transactions.map((meta, index) => __awaiter(this, void 0, void 0, function* () {
|
|
455
|
-
if (!meta.verifiedOnBlockchain &&
|
|
480
|
+
if (!meta.verifiedOnBlockchain &&
|
|
481
|
+
(0, utils_1.transactionMatchesChainId)(meta, currentChainId)) {
|
|
456
482
|
const [reconciledTx, updateRequired] = yield this.blockchainTransactionStateReconciler(meta);
|
|
457
483
|
if (updateRequired) {
|
|
458
484
|
transactions[index] = reconciledTx;
|
|
@@ -515,35 +541,70 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
515
541
|
stopIncomingTransactionProcessing() {
|
|
516
542
|
this.incomingTransactionHelper.stop();
|
|
517
543
|
}
|
|
518
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Adds external provided transaction to state as confirmed transaction.
|
|
546
|
+
*
|
|
547
|
+
* @param transactionMeta - TransactionMeta to add transactions.
|
|
548
|
+
* @param transactionReceipt - TransactionReceipt of the external transaction.
|
|
549
|
+
* @param baseFeePerGas - Base fee per gas of the external transaction.
|
|
550
|
+
*/
|
|
551
|
+
confirmExternalTransaction(transactionMeta, transactionReceipt, baseFeePerGas) {
|
|
519
552
|
return __awaiter(this, void 0, void 0, function* () {
|
|
520
|
-
|
|
521
|
-
|
|
553
|
+
// Run validation and add external transaction to state.
|
|
554
|
+
this.addExternalTransaction(transactionMeta);
|
|
522
555
|
try {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
530
|
-
if (meta && !isCompleted) {
|
|
531
|
-
yield this.approveTransaction(transactionId);
|
|
556
|
+
const transactionId = transactionMeta.id;
|
|
557
|
+
// Make sure status is confirmed and define gasUsed as in receipt.
|
|
558
|
+
transactionMeta.status = types_1.TransactionStatus.confirmed;
|
|
559
|
+
transactionMeta.txReceipt = transactionReceipt;
|
|
560
|
+
if (baseFeePerGas) {
|
|
561
|
+
transactionMeta.baseFeePerGas = baseFeePerGas;
|
|
532
562
|
}
|
|
563
|
+
// Update same nonce local transactions as dropped and define replacedBy properties.
|
|
564
|
+
this.markNonceDuplicatesDropped(transactionId);
|
|
565
|
+
// Update external provided transaction with updated gas values and confirmed status.
|
|
566
|
+
this.updateTransaction(transactionMeta);
|
|
533
567
|
}
|
|
534
568
|
catch (error) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
569
|
+
console.error(error);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
processApproval(transactionMeta, { isExisting = false, requireApproval, shouldShowRequest = true, }) {
|
|
574
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
575
|
+
const transactionId = transactionMeta.id;
|
|
576
|
+
let resultCallbacks;
|
|
577
|
+
const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
|
|
578
|
+
const finishedPromise = isCompleted
|
|
579
|
+
? Promise.resolve(meta)
|
|
580
|
+
: this.waitForTransactionFinished(transactionId);
|
|
581
|
+
if (meta && !isExisting && !isCompleted) {
|
|
582
|
+
try {
|
|
583
|
+
if (requireApproval !== false) {
|
|
584
|
+
const acceptResult = yield this.requestApproval(transactionMeta, {
|
|
585
|
+
shouldShowRequest,
|
|
586
|
+
});
|
|
587
|
+
resultCallbacks = acceptResult.resultCallbacks;
|
|
540
588
|
}
|
|
541
|
-
|
|
542
|
-
|
|
589
|
+
const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
|
|
590
|
+
if (!isTxCompleted) {
|
|
591
|
+
yield this.approveTransaction(transactionId);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
|
|
596
|
+
if (!isTxCompleted) {
|
|
597
|
+
if (error.code === eth_rpc_errors_1.errorCodes.provider.userRejectedRequest) {
|
|
598
|
+
this.cancelTransaction(transactionId);
|
|
599
|
+
throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest('User rejected the transaction');
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
this.failTransaction(meta, error);
|
|
603
|
+
}
|
|
543
604
|
}
|
|
544
605
|
}
|
|
545
606
|
}
|
|
546
|
-
const finalMeta =
|
|
607
|
+
const finalMeta = yield finishedPromise;
|
|
547
608
|
switch (finalMeta === null || finalMeta === void 0 ? void 0 : finalMeta.status) {
|
|
548
609
|
case types_1.TransactionStatus.failed:
|
|
549
610
|
resultCallbacks === null || resultCallbacks === void 0 ? void 0 : resultCallbacks.error(finalMeta.error);
|
|
@@ -615,14 +676,15 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
615
676
|
const signedTx = yield this.sign(unsignedEthTx, from);
|
|
616
677
|
transactionMeta.status = types_1.TransactionStatus.signed;
|
|
617
678
|
this.updateTransaction(transactionMeta);
|
|
618
|
-
const
|
|
619
|
-
transactionMeta.
|
|
679
|
+
const rawTx = (0, ethereumjs_util_1.bufferToHex)(signedTx.serialize());
|
|
680
|
+
transactionMeta.rawTx = rawTx;
|
|
620
681
|
this.updateTransaction(transactionMeta);
|
|
621
682
|
const transactionHash = yield (0, controller_utils_1.query)(this.ethQuery, 'sendRawTransaction', [
|
|
622
|
-
|
|
683
|
+
rawTx,
|
|
623
684
|
]);
|
|
624
685
|
transactionMeta.transactionHash = transactionHash;
|
|
625
686
|
transactionMeta.status = types_1.TransactionStatus.submitted;
|
|
687
|
+
transactionMeta.submittedTime = new Date().getTime();
|
|
626
688
|
this.updateTransaction(transactionMeta);
|
|
627
689
|
this.hub.emit(`${transactionMeta.id}:finished`, transactionMeta);
|
|
628
690
|
}
|
|
@@ -739,6 +801,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
739
801
|
meta.transaction.gasUsed = txReceipt.gasUsed;
|
|
740
802
|
meta.txReceipt = txReceipt;
|
|
741
803
|
meta.baseFeePerGas = txBlock === null || txBlock === void 0 ? void 0 : txBlock.baseFeePerGas;
|
|
804
|
+
meta.blockTimestamp = txBlock === null || txBlock === void 0 ? void 0 : txBlock.timestamp;
|
|
742
805
|
// According to the Web3 docs:
|
|
743
806
|
// TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.
|
|
744
807
|
if (Number(txReceipt.status) === 0) {
|
|
@@ -808,15 +871,15 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
808
871
|
}, shouldShowRequest));
|
|
809
872
|
});
|
|
810
873
|
}
|
|
811
|
-
getTransaction(
|
|
874
|
+
getTransaction(transactionId) {
|
|
812
875
|
const { transactions } = this.state;
|
|
813
|
-
return transactions.find(({ id }) => id ===
|
|
876
|
+
return transactions.find(({ id }) => id === transactionId);
|
|
814
877
|
}
|
|
815
878
|
getApprovalId(txMeta) {
|
|
816
879
|
return String(txMeta.id);
|
|
817
880
|
}
|
|
818
|
-
isTransactionCompleted(
|
|
819
|
-
const transaction = this.getTransaction(
|
|
881
|
+
isTransactionCompleted(transactionId) {
|
|
882
|
+
const transaction = this.getTransaction(transactionId);
|
|
820
883
|
if (!transaction) {
|
|
821
884
|
return { meta: undefined, isCompleted: false };
|
|
822
885
|
}
|
|
@@ -825,7 +888,7 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
825
888
|
}
|
|
826
889
|
getChainId() {
|
|
827
890
|
const { providerConfig } = this.getNetworkState();
|
|
828
|
-
return providerConfig
|
|
891
|
+
return providerConfig.chainId;
|
|
829
892
|
}
|
|
830
893
|
prepareUnsignedEthTx(txParams) {
|
|
831
894
|
return tx_1.TransactionFactory.fromTxData(txParams, {
|
|
@@ -852,7 +915,6 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
852
915
|
const customChainParams = {
|
|
853
916
|
name,
|
|
854
917
|
chainId: parseInt(chainId, 16),
|
|
855
|
-
// networkId: networkId === null ? NaN : parseInt(networkId, undefined),
|
|
856
918
|
defaultHardfork: exports.HARDFORK,
|
|
857
919
|
};
|
|
858
920
|
return common_1.Common.custom(customChainParams);
|
|
@@ -899,6 +961,86 @@ class TransactionController extends base_controller_1.BaseController {
|
|
|
899
961
|
}
|
|
900
962
|
return dappSuggestedGasFees;
|
|
901
963
|
}
|
|
964
|
+
/**
|
|
965
|
+
* Validates and adds external provided transaction to state.
|
|
966
|
+
*
|
|
967
|
+
* @param transactionMeta - Nominated external transaction to be added to state.
|
|
968
|
+
*/
|
|
969
|
+
addExternalTransaction(transactionMeta) {
|
|
970
|
+
var _a;
|
|
971
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
972
|
+
const chainId = this.getChainId();
|
|
973
|
+
const { transactions } = this.state;
|
|
974
|
+
const fromAddress = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.from;
|
|
975
|
+
const sameFromAndNetworkTransactions = transactions.filter((transaction) => transaction.transaction.from === fromAddress &&
|
|
976
|
+
(0, utils_1.transactionMatchesChainId)(transaction, chainId));
|
|
977
|
+
const confirmedTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.confirmed);
|
|
978
|
+
const pendingTxs = sameFromAndNetworkTransactions.filter((transaction) => transaction.status === types_1.TransactionStatus.submitted);
|
|
979
|
+
(0, external_transactions_1.validateConfirmedExternalTransaction)(transactionMeta, confirmedTxs, pendingTxs);
|
|
980
|
+
const updatedTransactions = [...transactions, transactionMeta];
|
|
981
|
+
this.update({
|
|
982
|
+
transactions: this.trimTransactionsForState(updatedTransactions),
|
|
983
|
+
});
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions
|
|
988
|
+
* in the transactions have the same nonce.
|
|
989
|
+
*
|
|
990
|
+
* @param transactionId - Used to identify original transaction.
|
|
991
|
+
*/
|
|
992
|
+
markNonceDuplicatesDropped(transactionId) {
|
|
993
|
+
var _a, _b;
|
|
994
|
+
const chainId = this.getChainId();
|
|
995
|
+
const transactionMeta = this.getTransaction(transactionId);
|
|
996
|
+
const nonce = (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _a === void 0 ? void 0 : _a.nonce;
|
|
997
|
+
const from = (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.transaction) === null || _b === void 0 ? void 0 : _b.from;
|
|
998
|
+
const sameNonceTxs = this.state.transactions.filter((transaction) => transaction.transaction.from === from &&
|
|
999
|
+
transaction.transaction.nonce === nonce &&
|
|
1000
|
+
(0, utils_1.transactionMatchesChainId)(transaction, chainId));
|
|
1001
|
+
if (!sameNonceTxs.length) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
// Mark all same nonce transactions as dropped and give it a replacedBy hash
|
|
1005
|
+
for (const transaction of sameNonceTxs) {
|
|
1006
|
+
if (transaction.id === transactionId) {
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
transaction.replacedBy = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.hash;
|
|
1010
|
+
transaction.replacedById = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.id;
|
|
1011
|
+
// Drop any transaction that wasn't previously failed (off chain failure)
|
|
1012
|
+
if (transaction.status !== types_1.TransactionStatus.failed) {
|
|
1013
|
+
this.setTransactionStatusDropped(transaction);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Method to set transaction status to dropped.
|
|
1019
|
+
*
|
|
1020
|
+
* @param transactionMeta - TransactionMeta of transaction to be marked as dropped.
|
|
1021
|
+
*/
|
|
1022
|
+
setTransactionStatusDropped(transactionMeta) {
|
|
1023
|
+
transactionMeta.status = types_1.TransactionStatus.dropped;
|
|
1024
|
+
this.updateTransaction(transactionMeta);
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Get transaction with provided actionId.
|
|
1028
|
+
*
|
|
1029
|
+
* @param actionId - Unique ID to prevent duplicate requests
|
|
1030
|
+
* @returns the filtered transaction
|
|
1031
|
+
*/
|
|
1032
|
+
getTransactionWithActionId(actionId) {
|
|
1033
|
+
return this.state.transactions.find((transaction) => actionId && transaction.actionId === actionId);
|
|
1034
|
+
}
|
|
1035
|
+
waitForTransactionFinished(transactionId) {
|
|
1036
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1037
|
+
return new Promise((resolve) => {
|
|
1038
|
+
this.hub.once(`${transactionId}:finished`, (txMeta) => {
|
|
1039
|
+
resolve(txMeta);
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
902
1044
|
}
|
|
903
1045
|
exports.TransactionController = TransactionController;
|
|
904
1046
|
exports.default = TransactionController;
|