@metamask/transaction-controller 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/TransactionController.d.ts +466 -0
- package/dist/TransactionController.js +927 -0
- package/dist/TransactionController.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/mocks/txsMock.d.ts +63 -0
- package/dist/mocks/txsMock.js +515 -0
- package/dist/mocks/txsMock.js.map +1 -0
- package/dist/utils.d.ts +60 -0
- package/dist/utils.js +206 -0
- package/dist/utils.js.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.0.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/controllers/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/controllers/tree/v33.0.0), namely:
|
|
13
|
+
- Everything in `src/transaction`
|
|
14
|
+
- Transaction-related functions from `src/util.ts` and accompanying tests
|
|
15
|
+
|
|
16
|
+
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
17
|
+
|
|
18
|
+
[Unreleased]: https://github.com/MetaMask/controllers/compare/@metamask/transaction-controller@1.0.0...HEAD
|
|
19
|
+
[1.0.0]: https://github.com/MetaMask/controllers/releases/tag/@metamask/transaction-controller@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@metamask/transaction-controller`
|
|
2
|
+
|
|
3
|
+
Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/transaction-controller`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/transaction-controller`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/controllers#readme).
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import Common from '@ethereumjs/common';
|
|
4
|
+
import { TypedTransaction } from '@ethereumjs/tx';
|
|
5
|
+
import { BaseController, BaseConfig, BaseState } from '@metamask/base-controller';
|
|
6
|
+
import type { NetworkState, NetworkController } from '@metamask/network-controller';
|
|
7
|
+
/**
|
|
8
|
+
* @type Result
|
|
9
|
+
* @property result - Promise resolving to a new transaction hash
|
|
10
|
+
* @property transactionMeta - Meta information about this new transaction
|
|
11
|
+
*/
|
|
12
|
+
export interface Result {
|
|
13
|
+
result: Promise<string>;
|
|
14
|
+
transactionMeta: TransactionMeta;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @type Fetch All Options
|
|
18
|
+
* @property fromBlock - String containing a specific block decimal number
|
|
19
|
+
* @property etherscanApiKey - API key to be used to fetch token transactions
|
|
20
|
+
*/
|
|
21
|
+
export interface FetchAllOptions {
|
|
22
|
+
fromBlock?: string;
|
|
23
|
+
etherscanApiKey?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @type Transaction
|
|
27
|
+
*
|
|
28
|
+
* Transaction representation
|
|
29
|
+
* @property chainId - Network ID as per EIP-155
|
|
30
|
+
* @property data - Data to pass with this transaction
|
|
31
|
+
* @property from - Address to send this transaction from
|
|
32
|
+
* @property gas - Gas to send with this transaction
|
|
33
|
+
* @property gasPrice - Price of gas with this transaction
|
|
34
|
+
* @property gasUsed - Gas used in the transaction
|
|
35
|
+
* @property nonce - Unique number to prevent replay attacks
|
|
36
|
+
* @property to - Address to send this transaction to
|
|
37
|
+
* @property value - Value associated with this transaction
|
|
38
|
+
*/
|
|
39
|
+
export interface Transaction {
|
|
40
|
+
chainId?: number;
|
|
41
|
+
data?: string;
|
|
42
|
+
from: string;
|
|
43
|
+
gas?: string;
|
|
44
|
+
gasPrice?: string;
|
|
45
|
+
gasUsed?: string;
|
|
46
|
+
nonce?: string;
|
|
47
|
+
to?: string;
|
|
48
|
+
value?: string;
|
|
49
|
+
maxFeePerGas?: string;
|
|
50
|
+
maxPriorityFeePerGas?: string;
|
|
51
|
+
estimatedBaseFee?: string;
|
|
52
|
+
estimateGasError?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface GasPriceValue {
|
|
55
|
+
gasPrice: string;
|
|
56
|
+
}
|
|
57
|
+
export interface FeeMarketEIP1559Values {
|
|
58
|
+
maxFeePerGas: string;
|
|
59
|
+
maxPriorityFeePerGas: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The status of the transaction. Each status represents the state of the transaction internally
|
|
63
|
+
* in the wallet. Some of these correspond with the state of the transaction on the network, but
|
|
64
|
+
* some are wallet-specific.
|
|
65
|
+
*/
|
|
66
|
+
export declare enum TransactionStatus {
|
|
67
|
+
approved = "approved",
|
|
68
|
+
cancelled = "cancelled",
|
|
69
|
+
confirmed = "confirmed",
|
|
70
|
+
failed = "failed",
|
|
71
|
+
rejected = "rejected",
|
|
72
|
+
signed = "signed",
|
|
73
|
+
submitted = "submitted",
|
|
74
|
+
unapproved = "unapproved"
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Options for wallet device.
|
|
78
|
+
*/
|
|
79
|
+
export declare enum WalletDevice {
|
|
80
|
+
MM_MOBILE = "metamask_mobile",
|
|
81
|
+
MM_EXTENSION = "metamask_extension",
|
|
82
|
+
OTHER = "other_device"
|
|
83
|
+
}
|
|
84
|
+
declare type TransactionMetaBase = {
|
|
85
|
+
isTransfer?: boolean;
|
|
86
|
+
transferInformation?: {
|
|
87
|
+
symbol: string;
|
|
88
|
+
contractAddress: string;
|
|
89
|
+
decimals: number;
|
|
90
|
+
};
|
|
91
|
+
id: string;
|
|
92
|
+
networkID?: string;
|
|
93
|
+
chainId?: string;
|
|
94
|
+
origin?: string;
|
|
95
|
+
rawTransaction?: string;
|
|
96
|
+
time: number;
|
|
97
|
+
toSmartContract?: boolean;
|
|
98
|
+
transaction: Transaction;
|
|
99
|
+
transactionHash?: string;
|
|
100
|
+
blockNumber?: string;
|
|
101
|
+
deviceConfirmedOn?: WalletDevice;
|
|
102
|
+
verifiedOnBlockchain?: boolean;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* @type TransactionMeta
|
|
106
|
+
*
|
|
107
|
+
* TransactionMeta representation
|
|
108
|
+
* @property error - Synthesized error information for failed transactions
|
|
109
|
+
* @property id - Generated UUID associated with this transaction
|
|
110
|
+
* @property networkID - Network code as per EIP-155 for this transaction
|
|
111
|
+
* @property origin - Origin this transaction was sent from
|
|
112
|
+
* @property deviceConfirmedOn - string to indicate what device the transaction was confirmed
|
|
113
|
+
* @property rawTransaction - Hex representation of the underlying transaction
|
|
114
|
+
* @property status - String status of this transaction
|
|
115
|
+
* @property time - Timestamp associated with this transaction
|
|
116
|
+
* @property toSmartContract - Whether transaction recipient is a smart contract
|
|
117
|
+
* @property transaction - Underlying Transaction object
|
|
118
|
+
* @property transactionHash - Hash of a successful transaction
|
|
119
|
+
* @property blockNumber - Number of the block where the transaction has been included
|
|
120
|
+
*/
|
|
121
|
+
export declare type TransactionMeta = ({
|
|
122
|
+
status: Exclude<TransactionStatus, TransactionStatus.failed>;
|
|
123
|
+
} & TransactionMetaBase) | ({
|
|
124
|
+
status: TransactionStatus.failed;
|
|
125
|
+
error: Error;
|
|
126
|
+
} & TransactionMetaBase);
|
|
127
|
+
/**
|
|
128
|
+
* @type EtherscanTransactionMeta
|
|
129
|
+
*
|
|
130
|
+
* EtherscanTransactionMeta representation
|
|
131
|
+
* @property blockNumber - Number of the block where the transaction has been included
|
|
132
|
+
* @property timeStamp - Timestamp associated with this transaction
|
|
133
|
+
* @property hash - Hash of a successful transaction
|
|
134
|
+
* @property nonce - Nonce of the transaction
|
|
135
|
+
* @property blockHash - Hash of the block where the transaction has been included
|
|
136
|
+
* @property transactionIndex - Etherscan internal index for this transaction
|
|
137
|
+
* @property from - Address to send this transaction from
|
|
138
|
+
* @property to - Address to send this transaction to
|
|
139
|
+
* @property gas - Gas to send with this transaction
|
|
140
|
+
* @property gasPrice - Price of gas with this transaction
|
|
141
|
+
* @property isError - Synthesized error information for failed transactions
|
|
142
|
+
* @property txreceipt_status - Receipt status for this transaction
|
|
143
|
+
* @property input - input of the transaction
|
|
144
|
+
* @property contractAddress - Address of the contract
|
|
145
|
+
* @property cumulativeGasUsed - Amount of gas used
|
|
146
|
+
* @property confirmations - Number of confirmations
|
|
147
|
+
*/
|
|
148
|
+
export interface EtherscanTransactionMeta {
|
|
149
|
+
blockNumber: string;
|
|
150
|
+
timeStamp: string;
|
|
151
|
+
hash: string;
|
|
152
|
+
nonce: string;
|
|
153
|
+
blockHash: string;
|
|
154
|
+
transactionIndex: string;
|
|
155
|
+
from: string;
|
|
156
|
+
to: string;
|
|
157
|
+
value: string;
|
|
158
|
+
gas: string;
|
|
159
|
+
gasPrice: string;
|
|
160
|
+
cumulativeGasUsed: string;
|
|
161
|
+
gasUsed: string;
|
|
162
|
+
isError: string;
|
|
163
|
+
txreceipt_status: string;
|
|
164
|
+
input: string;
|
|
165
|
+
contractAddress: string;
|
|
166
|
+
confirmations: string;
|
|
167
|
+
tokenDecimal: string;
|
|
168
|
+
tokenSymbol: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @type TransactionConfig
|
|
172
|
+
*
|
|
173
|
+
* Transaction controller configuration
|
|
174
|
+
* @property interval - Polling interval used to fetch new currency rate
|
|
175
|
+
* @property provider - Provider used to create a new underlying EthQuery instance
|
|
176
|
+
* @property sign - Method used to sign transactions
|
|
177
|
+
*/
|
|
178
|
+
export interface TransactionConfig extends BaseConfig {
|
|
179
|
+
interval: number;
|
|
180
|
+
sign?: (transaction: Transaction, from: string) => Promise<any>;
|
|
181
|
+
txHistoryLimit: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @type MethodData
|
|
185
|
+
*
|
|
186
|
+
* Method data registry object
|
|
187
|
+
* @property registryMethod - Registry method raw string
|
|
188
|
+
* @property parsedRegistryMethod - Registry method object, containing name and method arguments
|
|
189
|
+
*/
|
|
190
|
+
export interface MethodData {
|
|
191
|
+
registryMethod: string;
|
|
192
|
+
parsedRegistryMethod: Record<string, unknown>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @type TransactionState
|
|
196
|
+
*
|
|
197
|
+
* Transaction controller state
|
|
198
|
+
* @property transactions - A list of TransactionMeta objects
|
|
199
|
+
* @property methodData - Object containing all known method data information
|
|
200
|
+
*/
|
|
201
|
+
export interface TransactionState extends BaseState {
|
|
202
|
+
transactions: TransactionMeta[];
|
|
203
|
+
methodData: {
|
|
204
|
+
[key: string]: MethodData;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Multiplier used to determine a transaction's increased gas fee during cancellation
|
|
209
|
+
*/
|
|
210
|
+
export declare const CANCEL_RATE = 1.5;
|
|
211
|
+
/**
|
|
212
|
+
* Multiplier used to determine a transaction's increased gas fee during speed up
|
|
213
|
+
*/
|
|
214
|
+
export declare const SPEED_UP_RATE = 1.1;
|
|
215
|
+
/**
|
|
216
|
+
* Controller responsible for submitting and managing transactions.
|
|
217
|
+
*/
|
|
218
|
+
export declare class TransactionController extends BaseController<TransactionConfig, TransactionState> {
|
|
219
|
+
private ethQuery;
|
|
220
|
+
private registry;
|
|
221
|
+
private handle?;
|
|
222
|
+
private mutex;
|
|
223
|
+
private getNetworkState;
|
|
224
|
+
private failTransaction;
|
|
225
|
+
private registryLookup;
|
|
226
|
+
/**
|
|
227
|
+
* Normalizes the transaction information from etherscan
|
|
228
|
+
* to be compatible with the TransactionMeta interface.
|
|
229
|
+
*
|
|
230
|
+
* @param txMeta - The transaction.
|
|
231
|
+
* @param currentNetworkID - The current network ID.
|
|
232
|
+
* @param currentChainId - The current chain ID.
|
|
233
|
+
* @returns The normalized transaction.
|
|
234
|
+
*/
|
|
235
|
+
private normalizeTx;
|
|
236
|
+
private normalizeTokenTx;
|
|
237
|
+
/**
|
|
238
|
+
* EventEmitter instance used to listen to specific transactional events
|
|
239
|
+
*/
|
|
240
|
+
hub: EventEmitter;
|
|
241
|
+
/**
|
|
242
|
+
* Name of this controller used during composition
|
|
243
|
+
*/
|
|
244
|
+
name: string;
|
|
245
|
+
/**
|
|
246
|
+
* Method used to sign transactions
|
|
247
|
+
*/
|
|
248
|
+
sign?: (transaction: TypedTransaction, from: string) => Promise<TypedTransaction>;
|
|
249
|
+
/**
|
|
250
|
+
* Creates a TransactionController instance.
|
|
251
|
+
*
|
|
252
|
+
* @param options - The controller options.
|
|
253
|
+
* @param options.getNetworkState - Gets the state of the network controller.
|
|
254
|
+
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
255
|
+
* @param options.getProvider - Returns a provider for the current network.
|
|
256
|
+
* @param config - Initial options used to configure this controller.
|
|
257
|
+
* @param state - Initial state to set on this controller.
|
|
258
|
+
*/
|
|
259
|
+
constructor({ getNetworkState, onNetworkStateChange, getProvider, }: {
|
|
260
|
+
getNetworkState: () => NetworkState;
|
|
261
|
+
onNetworkStateChange: (listener: (state: NetworkState) => void) => void;
|
|
262
|
+
getProvider: () => NetworkController['provider'];
|
|
263
|
+
}, config?: Partial<TransactionConfig>, state?: Partial<TransactionState>);
|
|
264
|
+
/**
|
|
265
|
+
* Starts a new polling interval.
|
|
266
|
+
*
|
|
267
|
+
* @param interval - The polling interval used to fetch new transaction statuses.
|
|
268
|
+
*/
|
|
269
|
+
poll(interval?: number): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Handle new method data request.
|
|
272
|
+
*
|
|
273
|
+
* @param fourBytePrefix - The method prefix.
|
|
274
|
+
* @returns The method data object corresponding to the given signature prefix.
|
|
275
|
+
*/
|
|
276
|
+
handleMethodData(fourBytePrefix: string): Promise<MethodData>;
|
|
277
|
+
/**
|
|
278
|
+
* Add a new unapproved transaction to state. Parameters will be validated, a
|
|
279
|
+
* unique transaction id will be generated, and gas and gasPrice will be calculated
|
|
280
|
+
* if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
|
|
281
|
+
*
|
|
282
|
+
* @param transaction - The transaction object to add.
|
|
283
|
+
* @param origin - The domain origin to append to the generated TransactionMeta.
|
|
284
|
+
* @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.
|
|
285
|
+
* @returns Object containing a promise resolving to the transaction hash if approved.
|
|
286
|
+
*/
|
|
287
|
+
addTransaction(transaction: Transaction, origin?: string, deviceConfirmedOn?: WalletDevice): Promise<Result>;
|
|
288
|
+
prepareUnsignedEthTx(txParams: Record<string, unknown>): TypedTransaction;
|
|
289
|
+
/**
|
|
290
|
+
* `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
|
|
291
|
+
* specifying which chain, network, hardfork and EIPs to support for
|
|
292
|
+
* a transaction. By referencing this configuration, and analyzing the fields
|
|
293
|
+
* specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
|
|
294
|
+
* transaction type to use.
|
|
295
|
+
*
|
|
296
|
+
* @returns {Common} common configuration object
|
|
297
|
+
*/
|
|
298
|
+
getCommonConfiguration(): Common;
|
|
299
|
+
/**
|
|
300
|
+
* Approves a transaction and updates it's status in state. If this is not a
|
|
301
|
+
* retry transaction, a nonce will be generated. The transaction is signed
|
|
302
|
+
* using the sign configuration property, then published to the blockchain.
|
|
303
|
+
* A `<tx.id>:finished` hub event is fired after success or failure.
|
|
304
|
+
*
|
|
305
|
+
* @param transactionID - The ID of the transaction to approve.
|
|
306
|
+
*/
|
|
307
|
+
approveTransaction(transactionID: string): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Cancels a transaction based on its ID by setting its status to "rejected"
|
|
310
|
+
* and emitting a `<tx.id>:finished` hub event.
|
|
311
|
+
*
|
|
312
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
313
|
+
*/
|
|
314
|
+
cancelTransaction(transactionID: string): void;
|
|
315
|
+
/**
|
|
316
|
+
* Attempts to cancel a transaction based on its ID by setting its status to "rejected"
|
|
317
|
+
* and emitting a `<tx.id>:finished` hub event.
|
|
318
|
+
*
|
|
319
|
+
* @param transactionID - The ID of the transaction to cancel.
|
|
320
|
+
* @param gasValues - The gas values to use for the cancellation transation.
|
|
321
|
+
*/
|
|
322
|
+
stopTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
|
|
325
|
+
*
|
|
326
|
+
* @param transactionID - The ID of the transaction to speed up.
|
|
327
|
+
* @param gasValues - The gas values to use for the speed up transation.
|
|
328
|
+
*/
|
|
329
|
+
speedUpTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values): Promise<void>;
|
|
330
|
+
/**
|
|
331
|
+
* Estimates required gas for a given transaction.
|
|
332
|
+
*
|
|
333
|
+
* @param transaction - The transaction to estimate gas for.
|
|
334
|
+
* @returns The gas and gas price.
|
|
335
|
+
*/
|
|
336
|
+
estimateGas(transaction: Transaction): Promise<{
|
|
337
|
+
gas: string;
|
|
338
|
+
gasPrice: any;
|
|
339
|
+
estimateGasError?: undefined;
|
|
340
|
+
} | {
|
|
341
|
+
gas: string;
|
|
342
|
+
gasPrice: any;
|
|
343
|
+
estimateGasError: string | undefined;
|
|
344
|
+
}>;
|
|
345
|
+
/**
|
|
346
|
+
* Check the status of submitted transactions on the network to determine whether they have
|
|
347
|
+
* been included in a block. Any that have been included in a block are marked as confirmed.
|
|
348
|
+
*/
|
|
349
|
+
queryTransactionStatuses(): Promise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Updates an existing transaction in state.
|
|
352
|
+
*
|
|
353
|
+
* @param transactionMeta - The new transaction to store in state.
|
|
354
|
+
*/
|
|
355
|
+
updateTransaction(transactionMeta: TransactionMeta): void;
|
|
356
|
+
/**
|
|
357
|
+
* Removes all transactions from state, optionally based on the current network.
|
|
358
|
+
*
|
|
359
|
+
* @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
|
|
360
|
+
* current network. If `true`, all transactions are wiped.
|
|
361
|
+
*/
|
|
362
|
+
wipeTransactions(ignoreNetwork?: boolean): void;
|
|
363
|
+
/**
|
|
364
|
+
* Get transactions from Etherscan for the given address. By default all transactions are
|
|
365
|
+
* returned, but the `fromBlock` option can be given to filter just for transactions from a
|
|
366
|
+
* specific block onward.
|
|
367
|
+
*
|
|
368
|
+
* @param address - The address to fetch the transactions for.
|
|
369
|
+
* @param opt - Object containing optional data, fromBlock and Etherscan API key.
|
|
370
|
+
* @returns The block number of the latest incoming transaction.
|
|
371
|
+
*/
|
|
372
|
+
fetchAll(address: string, opt?: FetchAllOptions): Promise<string | void>;
|
|
373
|
+
/**
|
|
374
|
+
* Trim the amount of transactions that are set on the state. Checks
|
|
375
|
+
* if the length of the tx history is longer then desired persistence
|
|
376
|
+
* limit and then if it is removes the oldest confirmed or rejected tx.
|
|
377
|
+
* Pending or unapproved transactions will not be removed by this
|
|
378
|
+
* operation. For safety of presenting a fully functional transaction UI
|
|
379
|
+
* representation, this function will not break apart transactions with the
|
|
380
|
+
* same nonce, created on the same day, per network. Not accounting for transactions of the same
|
|
381
|
+
* nonce, same day and network combo can result in confusing or broken experiences
|
|
382
|
+
* in the UI. The transactions are then updated using the BaseController update.
|
|
383
|
+
*
|
|
384
|
+
* @param transactions - The transactions to be applied to the state.
|
|
385
|
+
* @returns The trimmed list of transactions.
|
|
386
|
+
*/
|
|
387
|
+
private trimTransactionsForState;
|
|
388
|
+
/**
|
|
389
|
+
* Determines if the transaction is in a final state.
|
|
390
|
+
*
|
|
391
|
+
* @param status - The transaction status.
|
|
392
|
+
* @returns Whether the transaction is in a final state.
|
|
393
|
+
*/
|
|
394
|
+
private isFinalState;
|
|
395
|
+
/**
|
|
396
|
+
* Method to verify the state of a transaction using the Blockchain as a source of truth.
|
|
397
|
+
*
|
|
398
|
+
* @param meta - The local transaction to verify on the blockchain.
|
|
399
|
+
* @returns A tuple containing the updated transaction, and whether or not an update was required.
|
|
400
|
+
*/
|
|
401
|
+
private blockchainTransactionStateReconciler;
|
|
402
|
+
/**
|
|
403
|
+
* Method to check if a tx has failed according to their receipt
|
|
404
|
+
* According to the Web3 docs:
|
|
405
|
+
* TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.
|
|
406
|
+
* The receipt is not available for pending transactions and returns null.
|
|
407
|
+
*
|
|
408
|
+
* @param txHash - The transaction hash.
|
|
409
|
+
* @returns Whether the transaction has failed.
|
|
410
|
+
*/
|
|
411
|
+
private checkTxReceiptStatusIsFailed;
|
|
412
|
+
/**
|
|
413
|
+
* Method to verify the state of transactions using Etherscan as a source of truth.
|
|
414
|
+
*
|
|
415
|
+
* @param remoteTxs - Transactions to reconcile that are from a remote source.
|
|
416
|
+
* @param localTxs - Transactions to reconcile that are local.
|
|
417
|
+
* @returns A tuple containing a boolean indicating whether or not an update was required, and the updated transaction.
|
|
418
|
+
*/
|
|
419
|
+
private etherscanTransactionStateReconciler;
|
|
420
|
+
/**
|
|
421
|
+
* Get all transactions that are in the remote transactions array
|
|
422
|
+
* but not in the local transactions array.
|
|
423
|
+
*
|
|
424
|
+
* @param remoteTxs - Array of transactions from remote source.
|
|
425
|
+
* @param localTxs - Array of transactions stored locally.
|
|
426
|
+
* @returns The new transactions.
|
|
427
|
+
*/
|
|
428
|
+
private getNewTransactions;
|
|
429
|
+
/**
|
|
430
|
+
* Get all the transactions that are locally outdated with respect
|
|
431
|
+
* to a remote source (etherscan or blockchain). The returned array
|
|
432
|
+
* contains the transactions with the updated data.
|
|
433
|
+
*
|
|
434
|
+
* @param remoteTxs - Array of transactions from remote source.
|
|
435
|
+
* @param localTxs - Array of transactions stored locally.
|
|
436
|
+
* @returns The updated transactions.
|
|
437
|
+
*/
|
|
438
|
+
private getUpdatedTransactions;
|
|
439
|
+
/**
|
|
440
|
+
* Verifies if a local transaction is outdated with respect to the remote transaction.
|
|
441
|
+
*
|
|
442
|
+
* @param remoteTx - The remote transaction from Etherscan.
|
|
443
|
+
* @param localTx - The local transaction.
|
|
444
|
+
* @returns Whether the transaction is outdated.
|
|
445
|
+
*/
|
|
446
|
+
private isTransactionOutdated;
|
|
447
|
+
/**
|
|
448
|
+
* Verifies if the status of a local transaction is outdated with respect to the remote transaction.
|
|
449
|
+
*
|
|
450
|
+
* @param remoteTxHash - Remote transaction hash.
|
|
451
|
+
* @param localTxHash - Local transaction hash.
|
|
452
|
+
* @param remoteTxStatus - Remote transaction status.
|
|
453
|
+
* @param localTxStatus - Local transaction status.
|
|
454
|
+
* @returns Whether the status is outdated.
|
|
455
|
+
*/
|
|
456
|
+
private isStatusOutdated;
|
|
457
|
+
/**
|
|
458
|
+
* Verifies if the gas data of a local transaction is outdated with respect to the remote transaction.
|
|
459
|
+
*
|
|
460
|
+
* @param remoteGasUsed - Remote gas used in the transaction.
|
|
461
|
+
* @param localGasUsed - Local gas used in the transaction.
|
|
462
|
+
* @returns Whether the gas data is outdated.
|
|
463
|
+
*/
|
|
464
|
+
private isGasDataOutdated;
|
|
465
|
+
}
|
|
466
|
+
export default TransactionController;
|