@metamask/transaction-controller 23.1.0 → 25.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 +134 -1
- package/dist/TransactionController.js +38 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +39 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2K7J3EY3.mjs +170 -0
- package/dist/chunk-2K7J3EY3.mjs.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-6MYNWYJK.mjs +158 -0
- package/dist/chunk-6MYNWYJK.mjs.map +1 -0
- package/dist/chunk-7APMBUKB.js +158 -0
- package/dist/chunk-7APMBUKB.js.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7MZ57ILQ.mjs +62 -0
- package/dist/chunk-7MZ57ILQ.mjs.map +1 -0
- package/dist/chunk-BJEESIBE.js +2313 -0
- package/dist/chunk-BJEESIBE.js.map +1 -0
- package/dist/chunk-C67QD5PV.mjs +320 -0
- package/dist/chunk-C67QD5PV.mjs.map +1 -0
- package/dist/chunk-DE3MZYVY.mjs +2313 -0
- package/dist/chunk-DE3MZYVY.mjs.map +1 -0
- package/dist/chunk-DEKM6PVG.mjs +46 -0
- package/dist/chunk-DEKM6PVG.mjs.map +1 -0
- package/dist/chunk-DQP6X25N.mjs +208 -0
- package/dist/chunk-DQP6X25N.mjs.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTEDYRTL.js +242 -0
- package/dist/chunk-DTEDYRTL.js.map +1 -0
- package/dist/chunk-EQ3RRHB7.mjs +211 -0
- package/dist/chunk-EQ3RRHB7.mjs.map +1 -0
- package/dist/chunk-FDJPXQTF.js +46 -0
- package/dist/chunk-FDJPXQTF.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-FS7FRO7B.mjs +90 -0
- package/dist/chunk-FS7FRO7B.mjs.map +1 -0
- package/dist/chunk-GKTIFXPN.js +170 -0
- package/dist/chunk-GKTIFXPN.js.map +1 -0
- package/dist/chunk-H4M66BA3.js +62 -0
- package/dist/chunk-H4M66BA3.js.map +1 -0
- package/dist/chunk-HPNXIKFY.js +76 -0
- package/dist/chunk-HPNXIKFY.js.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-I5YZ7QUK.js +121 -0
- package/dist/chunk-I5YZ7QUK.js.map +1 -0
- package/dist/chunk-IC233ZQS.js +211 -0
- package/dist/chunk-IC233ZQS.js.map +1 -0
- package/dist/chunk-IUBAETUH.js +137 -0
- package/dist/chunk-IUBAETUH.js.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JR6HDRNV.mjs +242 -0
- package/dist/chunk-JR6HDRNV.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-LM4NUNMT.mjs +76 -0
- package/dist/chunk-LM4NUNMT.mjs.map +1 -0
- package/dist/chunk-M7455RU7.js +320 -0
- package/dist/chunk-M7455RU7.js.map +1 -0
- package/dist/chunk-MHM5LRRF.mjs +122 -0
- package/dist/chunk-MHM5LRRF.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NUOBUW7C.js +85 -0
- package/dist/chunk-NUOBUW7C.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-RI6MVJJN.js +122 -0
- package/dist/chunk-RI6MVJJN.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UKYY2RVS.mjs +137 -0
- package/dist/chunk-UKYY2RVS.mjs.map +1 -0
- package/dist/chunk-UM4ORJ5B.mjs +121 -0
- package/dist/chunk-UM4ORJ5B.mjs.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y734U4V6.mjs +85 -0
- package/dist/chunk-Y734U4V6.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZCQRDZ36.js +208 -0
- package/dist/chunk-ZCQRDZ36.js.map +1 -0
- package/dist/chunk-ZJLZSFOZ.js +90 -0
- package/dist/chunk-ZJLZSFOZ.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +10 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +11 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +56 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +235 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +8 -3
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +63 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/{utils → types/utils}/utils.d.ts +9 -1
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -146
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +21 -9
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
|
@@ -1,146 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _EtherscanRemoteTransactionSource_instances, _EtherscanRemoteTransactionSource_includeTokenTransfers, _EtherscanRemoteTransactionSource_isTokenRequestPending, _EtherscanRemoteTransactionSource_mutex, _EtherscanRemoteTransactionSource_releaseLockAfterInterval, _EtherscanRemoteTransactionSource_fetchNormalTransactions, _EtherscanRemoteTransactionSource_fetchTokenTransactions, _EtherscanRemoteTransactionSource_getResponseTransactions, _EtherscanRemoteTransactionSource_normalizeTransaction, _EtherscanRemoteTransactionSource_normalizeTokenTransaction, _EtherscanRemoteTransactionSource_normalizeTransactionBase;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.EtherscanRemoteTransactionSource = void 0;
|
|
28
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
29
|
-
const async_mutex_1 = require("async-mutex");
|
|
30
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
31
|
-
const uuid_1 = require("uuid");
|
|
32
|
-
const constants_1 = require("../constants");
|
|
33
|
-
const logger_1 = require("../logger");
|
|
34
|
-
const types_1 = require("../types");
|
|
35
|
-
const etherscan_1 = require("../utils/etherscan");
|
|
36
|
-
const ETHERSCAN_RATE_LIMIT_INTERVAL = 5000;
|
|
37
|
-
/**
|
|
38
|
-
* A RemoteTransactionSource that fetches transaction data from Etherscan.
|
|
39
|
-
*/
|
|
40
|
-
class EtherscanRemoteTransactionSource {
|
|
41
|
-
constructor({ includeTokenTransfers, } = {}) {
|
|
42
|
-
_EtherscanRemoteTransactionSource_instances.add(this);
|
|
43
|
-
_EtherscanRemoteTransactionSource_includeTokenTransfers.set(this, void 0);
|
|
44
|
-
_EtherscanRemoteTransactionSource_isTokenRequestPending.set(this, void 0);
|
|
45
|
-
_EtherscanRemoteTransactionSource_mutex.set(this, new async_mutex_1.Mutex());
|
|
46
|
-
_EtherscanRemoteTransactionSource_fetchNormalTransactions.set(this, (request, etherscanRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { currentChainId } = request;
|
|
48
|
-
const etherscanTransactions = yield (0, etherscan_1.fetchEtherscanTransactions)(etherscanRequest);
|
|
49
|
-
return __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_getResponseTransactions).call(this, etherscanTransactions).map((tx) => __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_normalizeTransaction).call(this, tx, currentChainId));
|
|
50
|
-
}));
|
|
51
|
-
_EtherscanRemoteTransactionSource_fetchTokenTransactions.set(this, (request, etherscanRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const { currentChainId } = request;
|
|
53
|
-
const etherscanTransactions = yield (0, etherscan_1.fetchEtherscanTokenTransactions)(etherscanRequest);
|
|
54
|
-
return __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_getResponseTransactions).call(this, etherscanTransactions).map((tx) => __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_normalizeTokenTransaction).call(this, tx, currentChainId));
|
|
55
|
-
}));
|
|
56
|
-
__classPrivateFieldSet(this, _EtherscanRemoteTransactionSource_includeTokenTransfers, includeTokenTransfers !== null && includeTokenTransfers !== void 0 ? includeTokenTransfers : true, "f");
|
|
57
|
-
__classPrivateFieldSet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, false, "f");
|
|
58
|
-
}
|
|
59
|
-
isSupportedNetwork(chainId) {
|
|
60
|
-
return Object.keys(constants_1.ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);
|
|
61
|
-
}
|
|
62
|
-
getLastBlockVariations() {
|
|
63
|
-
return [__classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, "f") ? 'token' : 'normal'];
|
|
64
|
-
}
|
|
65
|
-
fetchTransactions(request) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const releaseLock = yield __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_mutex, "f").acquire();
|
|
68
|
-
const acquiredTime = Date.now();
|
|
69
|
-
const etherscanRequest = Object.assign(Object.assign({}, request), { chainId: request.currentChainId });
|
|
70
|
-
try {
|
|
71
|
-
const transactions = __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, "f")
|
|
72
|
-
? yield __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_fetchTokenTransactions, "f").call(this, request, etherscanRequest)
|
|
73
|
-
: yield __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_fetchNormalTransactions, "f").call(this, request, etherscanRequest);
|
|
74
|
-
if (__classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_includeTokenTransfers, "f")) {
|
|
75
|
-
__classPrivateFieldSet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, !__classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, "f"), "f");
|
|
76
|
-
}
|
|
77
|
-
return transactions;
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
__classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_releaseLockAfterInterval).call(this, acquiredTime, releaseLock);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.EtherscanRemoteTransactionSource = EtherscanRemoteTransactionSource;
|
|
86
|
-
_EtherscanRemoteTransactionSource_includeTokenTransfers = new WeakMap(), _EtherscanRemoteTransactionSource_isTokenRequestPending = new WeakMap(), _EtherscanRemoteTransactionSource_mutex = new WeakMap(), _EtherscanRemoteTransactionSource_fetchNormalTransactions = new WeakMap(), _EtherscanRemoteTransactionSource_fetchTokenTransactions = new WeakMap(), _EtherscanRemoteTransactionSource_instances = new WeakSet(), _EtherscanRemoteTransactionSource_releaseLockAfterInterval = function _EtherscanRemoteTransactionSource_releaseLockAfterInterval(acquireTime, releaseLock) {
|
|
87
|
-
const elapsedTime = Date.now() - acquireTime;
|
|
88
|
-
const remainingTime = Math.max(0, ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime);
|
|
89
|
-
// Wait for the remaining time if it hasn't been 5 seconds yet
|
|
90
|
-
if (remainingTime > 0) {
|
|
91
|
-
setTimeout(releaseLock, remainingTime);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
releaseLock();
|
|
95
|
-
}
|
|
96
|
-
}, _EtherscanRemoteTransactionSource_getResponseTransactions = function _EtherscanRemoteTransactionSource_getResponseTransactions(response) {
|
|
97
|
-
let result = response.result;
|
|
98
|
-
if (response.status === '0') {
|
|
99
|
-
result = [];
|
|
100
|
-
if (response.result.length) {
|
|
101
|
-
(0, logger_1.incomingTransactionsLogger)('Ignored Etherscan request error', {
|
|
102
|
-
message: response.result,
|
|
103
|
-
type: __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_isTokenRequestPending, "f") ? 'token' : 'normal',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return result;
|
|
108
|
-
}, _EtherscanRemoteTransactionSource_normalizeTransaction = function _EtherscanRemoteTransactionSource_normalizeTransaction(txMeta, currentChainId) {
|
|
109
|
-
const base = __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_normalizeTransactionBase).call(this, txMeta, currentChainId);
|
|
110
|
-
return Object.assign(Object.assign(Object.assign({}, base), { txParams: Object.assign(Object.assign({}, base.txParams), { data: txMeta.input }) }), (txMeta.isError === '0'
|
|
111
|
-
? { status: types_1.TransactionStatus.confirmed }
|
|
112
|
-
: {
|
|
113
|
-
error: new Error('Transaction failed'),
|
|
114
|
-
status: types_1.TransactionStatus.failed,
|
|
115
|
-
}));
|
|
116
|
-
}, _EtherscanRemoteTransactionSource_normalizeTokenTransaction = function _EtherscanRemoteTransactionSource_normalizeTokenTransaction(txMeta, currentChainId) {
|
|
117
|
-
const base = __classPrivateFieldGet(this, _EtherscanRemoteTransactionSource_instances, "m", _EtherscanRemoteTransactionSource_normalizeTransactionBase).call(this, txMeta, currentChainId);
|
|
118
|
-
return Object.assign(Object.assign({}, base), { isTransfer: true, transferInformation: {
|
|
119
|
-
contractAddress: txMeta.contractAddress,
|
|
120
|
-
decimals: Number(txMeta.tokenDecimal),
|
|
121
|
-
symbol: txMeta.tokenSymbol,
|
|
122
|
-
} });
|
|
123
|
-
}, _EtherscanRemoteTransactionSource_normalizeTransactionBase = function _EtherscanRemoteTransactionSource_normalizeTransactionBase(txMeta, currentChainId) {
|
|
124
|
-
const time = parseInt(txMeta.timeStamp, 10) * 1000;
|
|
125
|
-
return {
|
|
126
|
-
blockNumber: txMeta.blockNumber,
|
|
127
|
-
chainId: currentChainId,
|
|
128
|
-
hash: txMeta.hash,
|
|
129
|
-
id: (0, uuid_1.v1)({ msecs: time }),
|
|
130
|
-
status: types_1.TransactionStatus.confirmed,
|
|
131
|
-
time,
|
|
132
|
-
txParams: {
|
|
133
|
-
chainId: currentChainId,
|
|
134
|
-
from: txMeta.from,
|
|
135
|
-
gas: (0, controller_utils_1.BNToHex)(new bn_js_1.default(txMeta.gas)),
|
|
136
|
-
gasPrice: (0, controller_utils_1.BNToHex)(new bn_js_1.default(txMeta.gasPrice)),
|
|
137
|
-
gasUsed: (0, controller_utils_1.BNToHex)(new bn_js_1.default(txMeta.gasUsed)),
|
|
138
|
-
nonce: (0, controller_utils_1.BNToHex)(new bn_js_1.default(txMeta.nonce)),
|
|
139
|
-
to: txMeta.to,
|
|
140
|
-
value: (0, controller_utils_1.BNToHex)(new bn_js_1.default(txMeta.value)),
|
|
141
|
-
},
|
|
142
|
-
type: types_1.TransactionType.incoming,
|
|
143
|
-
verifiedOnBlockchain: false,
|
|
144
|
-
};
|
|
145
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkGKTIFXPNjs = require('../chunk-GKTIFXPN.js');
|
|
4
|
+
require('../chunk-NUOBUW7C.js');
|
|
5
|
+
require('../chunk-RI6MVJJN.js');
|
|
6
|
+
require('../chunk-S6VGOPUY.js');
|
|
7
|
+
require('../chunk-HPNXIKFY.js');
|
|
8
|
+
require('../chunk-Z4BLTVTB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.EtherscanRemoteTransactionSource = _chunkGKTIFXPNjs.EtherscanRemoteTransactionSource;
|
|
146
12
|
//# sourceMappingURL=EtherscanRemoteTransactionSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EtherscanRemoteTransactionSource.js","sourceRoot":"","sources":["../../src/helpers/EtherscanRemoteTransactionSource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAqD;AAErD,6CAAoC;AACpC,kDAAuB;AACvB,+BAAoC;AAEpC,4CAA4D;AAC5D,sCAA8D;AAM9D,oCAA8D;AAC9D,kDAG4B;AAS5B,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAC3C;;GAEG;AACH,MAAa,gCAAgC;IAS3C,YAAY,EACV,qBAAqB,MACkB,EAAE;;QAR3C,0EAAgC;QAEhC,0EAAgC;QAEhC,kDAAS,IAAI,mBAAK,EAAE,EAAC;QAyDrB,oEAA2B,CACzB,OAAuC,EACvC,gBAA6C,EAC7C,EAAE;YACF,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;YAEnC,MAAM,qBAAqB,GAAG,MAAM,IAAA,sCAA0B,EAC5D,gBAAgB,CACjB,CAAC;YAEF,OAAO,uBAAA,IAAI,8GAAyB,MAA7B,IAAI,EAA0B,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACrE,uBAAA,IAAI,2GAAsB,MAA1B,IAAI,EAAuB,EAAE,EAAE,cAAc,CAAC,CAC/C,CAAC;QACJ,CAAC,CAAA,EAAC;QAEF,mEAA0B,CACxB,OAAuC,EACvC,gBAA6C,EAC7C,EAAE;YACF,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;YAEnC,MAAM,qBAAqB,GAAG,MAAM,IAAA,2CAA+B,EACjE,gBAAgB,CACjB,CAAC;YAEF,OAAO,uBAAA,IAAI,8GAAyB,MAA7B,IAAI,EAA0B,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACrE,uBAAA,IAAI,gHAA2B,MAA/B,IAAI,EAA4B,EAAE,EAAE,cAAc,CAAC,CACpD,CAAC;QACJ,CAAC,CAAA,EAAC;QAhFA,uBAAA,IAAI,2DAA0B,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,IAAI,MAAA,CAAC;QAC5D,uBAAA,IAAI,2DAA0B,KAAK,MAAA,CAAC;IACtC,CAAC;IAED,kBAAkB,CAAC,OAAY;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,wCAA4B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,sBAAsB;QACpB,OAAO,CAAC,uBAAA,IAAI,+DAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAEK,iBAAiB,CACrB,OAAuC;;YAEvC,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,+CAAO,CAAC,OAAO,EAAE,CAAC;YAChD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAEhC,MAAM,gBAAgB,mCACjB,OAAO,KACV,OAAO,EAAE,OAAO,CAAC,cAAc,GAChC,CAAC;YAEF,IAAI;gBACF,MAAM,YAAY,GAAG,uBAAA,IAAI,+DAAuB;oBAC9C,CAAC,CAAC,MAAM,uBAAA,IAAI,gEAAwB,MAA5B,IAAI,EAAyB,OAAO,EAAE,gBAAgB,CAAC;oBAC/D,CAAC,CAAC,MAAM,uBAAA,IAAI,iEAAyB,MAA7B,IAAI,EAA0B,OAAO,EAAE,gBAAgB,CAAC,CAAC;gBAEnE,IAAI,uBAAA,IAAI,+DAAuB,EAAE;oBAC/B,uBAAA,IAAI,2DAA0B,CAAC,uBAAA,IAAI,+DAAuB,MAAA,CAAC;iBAC5D;gBAED,OAAO,YAAY,CAAC;aACrB;oBAAS;gBACR,uBAAA,IAAI,+GAA0B,MAA9B,IAAI,EAA2B,YAAY,EAAE,WAAW,CAAC,CAAC;aAC3D;QACH,CAAC;KAAA;CAkIF;AAlLD,4EAkLC;8hBAhI2B,WAAmB,EAAE,WAAuB;IACpE,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC;IAC7C,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAC5B,CAAC,EACD,6BAA6B,GAAG,WAAW,CAC5C,CAAC;IACF,8DAA8D;IAC9D,IAAI,aAAa,GAAG,CAAC,EAAE;QACrB,UAAU,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;KACxC;SAAM;QACL,WAAW,EAAE,CAAC;KACf;AACH,CAAC,iIAiCC,QAAyC;IAEzC,IAAI,MAAM,GAAG,QAAQ,CAAC,MAAa,CAAC;IAEpC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;QAC3B,MAAM,GAAG,EAAE,CAAC;QAEZ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;YAC1B,IAAA,mCAAG,EAAC,iCAAiC,EAAE;gBACrC,OAAO,EAAE,QAAQ,CAAC,MAAM;gBACxB,IAAI,EAAE,uBAAA,IAAI,+DAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;aACvD,CAAC,CAAC;SACJ;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,2HAGC,MAAgC,EAChC,cAAmB;IAEnB,MAAM,IAAI,GAAG,uBAAA,IAAI,+GAA0B,MAA9B,IAAI,EAA2B,MAAM,EAAE,cAAc,CAAC,CAAC;IAEpE,qDACK,IAAI,KACP,QAAQ,kCACH,IAAI,CAAC,QAAQ,KAChB,IAAI,EAAE,MAAM,CAAC,KAAK,QAEjB,CAAC,MAAM,CAAC,OAAO,KAAK,GAAG;QACxB,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAiB,CAAC,SAAS,EAAE;QACzC,CAAC,CAAC;YACE,KAAK,EAAE,IAAI,KAAK,CAAC,oBAAoB,CAAC;YACtC,MAAM,EAAE,yBAAiB,CAAC,MAAM;SACjC,CAAC,EACN;AACJ,CAAC,qIAGC,MAAqC,EACrC,cAAmB;IAEnB,MAAM,IAAI,GAAG,uBAAA,IAAI,+GAA0B,MAA9B,IAAI,EAA2B,MAAM,EAAE,cAAc,CAAC,CAAC;IAEpE,uCACK,IAAI,KACP,UAAU,EAAE,IAAI,EAChB,mBAAmB,EAAE;YACnB,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;YACrC,MAAM,EAAE,MAAM,CAAC,WAAW;SAC3B,IACD;AACJ,CAAC,mIAGC,MAAoC,EACpC,cAAmB;IAEnB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;IAEnD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,cAAc;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,EAAE,EAAE,IAAA,SAAM,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC3B,MAAM,EAAE,yBAAiB,CAAC,SAAS;QACnC,IAAI;QACJ,QAAQ,EAAE;YACR,OAAO,EAAE,cAAc;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,GAAG,EAAE,IAAA,0BAAO,EAAC,IAAI,eAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,QAAQ,EAAE,IAAA,0BAAO,EAAC,IAAI,eAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1C,OAAO,EAAE,IAAA,0BAAO,EAAC,IAAI,eAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxC,KAAK,EAAE,IAAA,0BAAO,EAAC,IAAI,eAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,KAAK,EAAE,IAAA,0BAAO,EAAC,IAAI,eAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACrC;QACD,IAAI,EAAE,uBAAe,CAAC,QAAQ;QAC9B,oBAAoB,EAAE,KAAK;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["import { BNToHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { v1 as random } from 'uuid';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from '../constants';\nimport { incomingTransactionsLogger as log } from '../logger';\nimport type {\n RemoteTransactionSource,\n RemoteTransactionSourceRequest,\n TransactionMeta,\n} from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport {\n fetchEtherscanTokenTransactions,\n fetchEtherscanTransactions,\n} from '../utils/etherscan';\nimport type {\n EtherscanTokenTransactionMeta,\n EtherscanTransactionMeta,\n EtherscanTransactionMetaBase,\n EtherscanTransactionRequest,\n EtherscanTransactionResponse,\n} from '../utils/etherscan';\n\nconst ETHERSCAN_RATE_LIMIT_INTERVAL = 5000;\n/**\n * A RemoteTransactionSource that fetches transaction data from Etherscan.\n */\nexport class EtherscanRemoteTransactionSource\n implements RemoteTransactionSource\n{\n #includeTokenTransfers: boolean;\n\n #isTokenRequestPending: boolean;\n\n #mutex = new Mutex();\n\n constructor({\n includeTokenTransfers,\n }: { includeTokenTransfers?: boolean } = {}) {\n this.#includeTokenTransfers = includeTokenTransfers ?? true;\n this.#isTokenRequestPending = false;\n }\n\n isSupportedNetwork(chainId: Hex): boolean {\n return Object.keys(ETHERSCAN_SUPPORTED_NETWORKS).includes(chainId);\n }\n\n getLastBlockVariations(): string[] {\n return [this.#isTokenRequestPending ? 'token' : 'normal'];\n }\n\n async fetchTransactions(\n request: RemoteTransactionSourceRequest,\n ): Promise<TransactionMeta[]> {\n const releaseLock = await this.#mutex.acquire();\n const acquiredTime = Date.now();\n\n const etherscanRequest: EtherscanTransactionRequest = {\n ...request,\n chainId: request.currentChainId,\n };\n\n try {\n const transactions = this.#isTokenRequestPending\n ? await this.#fetchTokenTransactions(request, etherscanRequest)\n : await this.#fetchNormalTransactions(request, etherscanRequest);\n\n if (this.#includeTokenTransfers) {\n this.#isTokenRequestPending = !this.#isTokenRequestPending;\n }\n\n return transactions;\n } finally {\n this.#releaseLockAfterInterval(acquiredTime, releaseLock);\n }\n }\n\n #releaseLockAfterInterval(acquireTime: number, releaseLock: () => void) {\n const elapsedTime = Date.now() - acquireTime;\n const remainingTime = Math.max(\n 0,\n ETHERSCAN_RATE_LIMIT_INTERVAL - elapsedTime,\n );\n // Wait for the remaining time if it hasn't been 5 seconds yet\n if (remainingTime > 0) {\n setTimeout(releaseLock, remainingTime);\n } else {\n releaseLock();\n }\n }\n\n #fetchNormalTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTransaction(tx, currentChainId),\n );\n };\n\n #fetchTokenTransactions = async (\n request: RemoteTransactionSourceRequest,\n etherscanRequest: EtherscanTransactionRequest,\n ) => {\n const { currentChainId } = request;\n\n const etherscanTransactions = await fetchEtherscanTokenTransactions(\n etherscanRequest,\n );\n\n return this.#getResponseTransactions(etherscanTransactions).map((tx) =>\n this.#normalizeTokenTransaction(tx, currentChainId),\n );\n };\n\n #getResponseTransactions<T extends EtherscanTransactionMetaBase>(\n response: EtherscanTransactionResponse<T>,\n ): T[] {\n let result = response.result as T[];\n\n if (response.status === '0') {\n result = [];\n\n if (response.result.length) {\n log('Ignored Etherscan request error', {\n message: response.result,\n type: this.#isTokenRequestPending ? 'token' : 'normal',\n });\n }\n }\n\n return result;\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 txParams: {\n ...base.txParams,\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 hash: txMeta.hash,\n id: random({ msecs: time }),\n status: TransactionStatus.confirmed,\n time,\n txParams: {\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 type: TransactionType.incoming,\n verifiedOnBlockchain: false,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EtherscanRemoteTransactionSource
|
|
3
|
+
} from "../chunk-2K7J3EY3.mjs";
|
|
4
|
+
import "../chunk-Y734U4V6.mjs";
|
|
5
|
+
import "../chunk-MHM5LRRF.mjs";
|
|
6
|
+
import "../chunk-UQQWZT6C.mjs";
|
|
7
|
+
import "../chunk-LM4NUNMT.mjs";
|
|
8
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
9
|
+
export {
|
|
10
|
+
EtherscanRemoteTransactionSource
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=EtherscanRemoteTransactionSource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,144 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _GasFeePoller_instances, _GasFeePoller_gasFeeFlows, _GasFeePoller_getEthQuery, _GasFeePoller_getGasFeeControllerEstimates, _GasFeePoller_getTransactions, _GasFeePoller_timeout, _GasFeePoller_running, _GasFeePoller_start, _GasFeePoller_stop, _GasFeePoller_onTimeout, _GasFeePoller_updateUnapprovedTransactions, _GasFeePoller_updateTransactionSuggestedFees, _GasFeePoller_getUnapprovedTransactions;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.GasFeePoller = void 0;
|
|
28
|
-
const utils_1 = require("@metamask/utils");
|
|
29
|
-
const events_1 = __importDefault(require("events"));
|
|
30
|
-
const logger_1 = require("../logger");
|
|
31
|
-
const types_1 = require("../types");
|
|
32
|
-
const gas_flow_1 = require("../utils/gas-flow");
|
|
33
|
-
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'gas-fee-poller');
|
|
34
|
-
const INTERVAL_MILLISECONDS = 10000;
|
|
35
|
-
/**
|
|
36
|
-
* Automatically polls and updates suggested gas fees on unapproved transactions.
|
|
37
|
-
*/
|
|
38
|
-
class GasFeePoller {
|
|
39
|
-
/**
|
|
40
|
-
* Constructs a new instance of the GasFeePoller.
|
|
41
|
-
* @param options - The options for this instance.
|
|
42
|
-
* @param options.gasFeeFlows - The gas fee flows to use to obtain suitable gas fees.
|
|
43
|
-
* @param options.getEthQuery - Callback to obtain an EthQuery instance.
|
|
44
|
-
* @param options.getGasFeeControllerEstimates - Callback to obtain the default fee estimates.
|
|
45
|
-
* @param options.getTransactions - Callback to obtain the transaction data.
|
|
46
|
-
* @param options.onStateChange - Callback to register a listener for controller state changes.
|
|
47
|
-
*/
|
|
48
|
-
constructor({ gasFeeFlows, getEthQuery, getGasFeeControllerEstimates, getTransactions, onStateChange, }) {
|
|
49
|
-
_GasFeePoller_instances.add(this);
|
|
50
|
-
this.hub = new events_1.default();
|
|
51
|
-
_GasFeePoller_gasFeeFlows.set(this, void 0);
|
|
52
|
-
_GasFeePoller_getEthQuery.set(this, void 0);
|
|
53
|
-
_GasFeePoller_getGasFeeControllerEstimates.set(this, void 0);
|
|
54
|
-
_GasFeePoller_getTransactions.set(this, void 0);
|
|
55
|
-
_GasFeePoller_timeout.set(this, void 0);
|
|
56
|
-
_GasFeePoller_running.set(this, false);
|
|
57
|
-
__classPrivateFieldSet(this, _GasFeePoller_gasFeeFlows, gasFeeFlows, "f");
|
|
58
|
-
__classPrivateFieldSet(this, _GasFeePoller_getEthQuery, getEthQuery, "f");
|
|
59
|
-
__classPrivateFieldSet(this, _GasFeePoller_getGasFeeControllerEstimates, getGasFeeControllerEstimates, "f");
|
|
60
|
-
__classPrivateFieldSet(this, _GasFeePoller_getTransactions, getTransactions, "f");
|
|
61
|
-
onStateChange(() => {
|
|
62
|
-
const unapprovedTransactions = __classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_getUnapprovedTransactions).call(this);
|
|
63
|
-
if (unapprovedTransactions.length) {
|
|
64
|
-
__classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_start).call(this);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
__classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_stop).call(this);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.GasFeePoller = GasFeePoller;
|
|
73
|
-
_GasFeePoller_gasFeeFlows = new WeakMap(), _GasFeePoller_getEthQuery = new WeakMap(), _GasFeePoller_getGasFeeControllerEstimates = new WeakMap(), _GasFeePoller_getTransactions = new WeakMap(), _GasFeePoller_timeout = new WeakMap(), _GasFeePoller_running = new WeakMap(), _GasFeePoller_instances = new WeakSet(), _GasFeePoller_start = function _GasFeePoller_start() {
|
|
74
|
-
if (__classPrivateFieldGet(this, _GasFeePoller_running, "f")) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// Intentionally not awaiting since this starts the timeout chain.
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
79
|
-
__classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_onTimeout).call(this);
|
|
80
|
-
__classPrivateFieldSet(this, _GasFeePoller_running, true, "f");
|
|
81
|
-
log('Started polling');
|
|
82
|
-
}, _GasFeePoller_stop = function _GasFeePoller_stop() {
|
|
83
|
-
if (!__classPrivateFieldGet(this, _GasFeePoller_running, "f")) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
clearTimeout(__classPrivateFieldGet(this, _GasFeePoller_timeout, "f"));
|
|
87
|
-
__classPrivateFieldSet(this, _GasFeePoller_timeout, undefined, "f");
|
|
88
|
-
__classPrivateFieldSet(this, _GasFeePoller_running, false, "f");
|
|
89
|
-
log('Stopped polling');
|
|
90
|
-
}, _GasFeePoller_onTimeout = function _GasFeePoller_onTimeout() {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
yield __classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_updateUnapprovedTransactions).call(this);
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
94
|
-
__classPrivateFieldSet(this, _GasFeePoller_timeout, setTimeout(() => __classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_onTimeout).call(this), INTERVAL_MILLISECONDS), "f");
|
|
95
|
-
});
|
|
96
|
-
}, _GasFeePoller_updateUnapprovedTransactions = function _GasFeePoller_updateUnapprovedTransactions() {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const unapprovedTransactions = __classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_getUnapprovedTransactions).call(this);
|
|
99
|
-
log('Found unapproved transactions', {
|
|
100
|
-
count: unapprovedTransactions.length,
|
|
101
|
-
});
|
|
102
|
-
yield Promise.all(unapprovedTransactions.map((tx) => __classPrivateFieldGet(this, _GasFeePoller_instances, "m", _GasFeePoller_updateTransactionSuggestedFees).call(this, tx)));
|
|
103
|
-
});
|
|
104
|
-
}, _GasFeePoller_updateTransactionSuggestedFees = function _GasFeePoller_updateTransactionSuggestedFees(transactionMeta) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const { chainId, networkClientId } = transactionMeta;
|
|
107
|
-
const ethQuery = __classPrivateFieldGet(this, _GasFeePoller_getEthQuery, "f").call(this, chainId, networkClientId);
|
|
108
|
-
const gasFeeFlow = (0, gas_flow_1.getGasFeeFlow)(transactionMeta, __classPrivateFieldGet(this, _GasFeePoller_gasFeeFlows, "f"));
|
|
109
|
-
if (!gasFeeFlow) {
|
|
110
|
-
log('No gas fee flow found', transactionMeta.id);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
log('Found gas fee flow', gasFeeFlow.constructor.name, transactionMeta.id);
|
|
114
|
-
}
|
|
115
|
-
const request = {
|
|
116
|
-
ethQuery,
|
|
117
|
-
getGasFeeControllerEstimates: __classPrivateFieldGet(this, _GasFeePoller_getGasFeeControllerEstimates, "f"),
|
|
118
|
-
transactionMeta,
|
|
119
|
-
};
|
|
120
|
-
let gasFeeEstimates;
|
|
121
|
-
if (gasFeeFlow) {
|
|
122
|
-
try {
|
|
123
|
-
const response = yield gasFeeFlow.getGasFees(request);
|
|
124
|
-
gasFeeEstimates = response.estimates;
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
log('Failed to get suggested gas fees', transactionMeta.id, error);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (!gasFeeEstimates && transactionMeta.gasFeeEstimatesLoaded) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
transactionMeta.gasFeeEstimates = gasFeeEstimates;
|
|
134
|
-
transactionMeta.gasFeeEstimatesLoaded = true;
|
|
135
|
-
this.hub.emit('transaction-updated', transactionMeta);
|
|
136
|
-
log('Updated suggested gas fees', {
|
|
137
|
-
gasFeeEstimates: transactionMeta.gasFeeEstimates,
|
|
138
|
-
transaction: transactionMeta.id,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}, _GasFeePoller_getUnapprovedTransactions = function _GasFeePoller_getUnapprovedTransactions() {
|
|
142
|
-
return __classPrivateFieldGet(this, _GasFeePoller_getTransactions, "f").call(this).filter((tx) => tx.status === types_1.TransactionStatus.unapproved);
|
|
143
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk7APMBUKBjs = require('../chunk-7APMBUKB.js');
|
|
4
|
+
require('../chunk-H4M66BA3.js');
|
|
5
|
+
require('../chunk-S6VGOPUY.js');
|
|
6
|
+
require('../chunk-HPNXIKFY.js');
|
|
7
|
+
require('../chunk-Z4BLTVTB.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.GasFeePoller = _chunk7APMBUKBjs.GasFeePoller;
|
|
144
11
|
//# sourceMappingURL=GasFeePoller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GasFeePoller
|
|
3
|
+
} from "../chunk-6MYNWYJK.mjs";
|
|
4
|
+
import "../chunk-7MZ57ILQ.mjs";
|
|
5
|
+
import "../chunk-UQQWZT6C.mjs";
|
|
6
|
+
import "../chunk-LM4NUNMT.mjs";
|
|
7
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
8
|
+
export {
|
|
9
|
+
GasFeePoller
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=GasFeePoller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,206 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _IncomingTransactionHelper_instances, _IncomingTransactionHelper_blockTracker, _IncomingTransactionHelper_getCurrentAccount, _IncomingTransactionHelper_getLastFetchedBlockNumbers, _IncomingTransactionHelper_getLocalTransactions, _IncomingTransactionHelper_getChainId, _IncomingTransactionHelper_isEnabled, _IncomingTransactionHelper_isRunning, _IncomingTransactionHelper_mutex, _IncomingTransactionHelper_onLatestBlock, _IncomingTransactionHelper_queryEntireHistory, _IncomingTransactionHelper_remoteTransactionSource, _IncomingTransactionHelper_transactionLimit, _IncomingTransactionHelper_updateTransactions, _IncomingTransactionHelper_sortTransactionsByTime, _IncomingTransactionHelper_getNewTransactions, _IncomingTransactionHelper_getUpdatedTransactions, _IncomingTransactionHelper_isTransactionOutdated, _IncomingTransactionHelper_getLastFetchedBlockNumberDec, _IncomingTransactionHelper_getFromBlock, _IncomingTransactionHelper_updateLastFetchedBlockNumber, _IncomingTransactionHelper_getBlockNumberKey, _IncomingTransactionHelper_canStart;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.IncomingTransactionHelper = void 0;
|
|
28
|
-
const async_mutex_1 = require("async-mutex");
|
|
29
|
-
const events_1 = __importDefault(require("events"));
|
|
30
|
-
const logger_1 = require("../logger");
|
|
31
|
-
const RECENT_HISTORY_BLOCK_RANGE = 10;
|
|
32
|
-
// TODO: Replace `any` with type
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
const UPDATE_CHECKS = [
|
|
35
|
-
(txMeta) => txMeta.status,
|
|
36
|
-
(txMeta) => txMeta.txParams.gasUsed,
|
|
37
|
-
];
|
|
38
|
-
class IncomingTransactionHelper {
|
|
39
|
-
constructor({ blockTracker, getCurrentAccount, getLastFetchedBlockNumbers, getLocalTransactions, getChainId, isEnabled, queryEntireHistory, remoteTransactionSource, transactionLimit, updateTransactions, }) {
|
|
40
|
-
_IncomingTransactionHelper_instances.add(this);
|
|
41
|
-
_IncomingTransactionHelper_blockTracker.set(this, void 0);
|
|
42
|
-
_IncomingTransactionHelper_getCurrentAccount.set(this, void 0);
|
|
43
|
-
_IncomingTransactionHelper_getLastFetchedBlockNumbers.set(this, void 0);
|
|
44
|
-
_IncomingTransactionHelper_getLocalTransactions.set(this, void 0);
|
|
45
|
-
_IncomingTransactionHelper_getChainId.set(this, void 0);
|
|
46
|
-
_IncomingTransactionHelper_isEnabled.set(this, void 0);
|
|
47
|
-
_IncomingTransactionHelper_isRunning.set(this, void 0);
|
|
48
|
-
_IncomingTransactionHelper_mutex.set(this, new async_mutex_1.Mutex());
|
|
49
|
-
_IncomingTransactionHelper_onLatestBlock.set(this, void 0);
|
|
50
|
-
_IncomingTransactionHelper_queryEntireHistory.set(this, void 0);
|
|
51
|
-
_IncomingTransactionHelper_remoteTransactionSource.set(this, void 0);
|
|
52
|
-
_IncomingTransactionHelper_transactionLimit.set(this, void 0);
|
|
53
|
-
_IncomingTransactionHelper_updateTransactions.set(this, void 0);
|
|
54
|
-
this.hub = new events_1.default();
|
|
55
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_blockTracker, blockTracker, "f");
|
|
56
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_getCurrentAccount, getCurrentAccount, "f");
|
|
57
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_getLastFetchedBlockNumbers, getLastFetchedBlockNumbers, "f");
|
|
58
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_getLocalTransactions, getLocalTransactions || (() => []), "f");
|
|
59
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_getChainId, getChainId, "f");
|
|
60
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_isEnabled, isEnabled !== null && isEnabled !== void 0 ? isEnabled : (() => true), "f");
|
|
61
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, false, "f");
|
|
62
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_queryEntireHistory, queryEntireHistory !== null && queryEntireHistory !== void 0 ? queryEntireHistory : true, "f");
|
|
63
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_remoteTransactionSource, remoteTransactionSource, "f");
|
|
64
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_transactionLimit, transactionLimit, "f");
|
|
65
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_updateTransactions, updateTransactions !== null && updateTransactions !== void 0 ? updateTransactions : false, "f");
|
|
66
|
-
// Using a property instead of a method to provide a listener reference
|
|
67
|
-
// with the correct scope that we can remove later if stopped.
|
|
68
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_onLatestBlock, (blockNumberHex) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
try {
|
|
70
|
-
yield this.update(blockNumberHex);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error('Error while checking incoming transactions', error);
|
|
74
|
-
}
|
|
75
|
-
}), "f");
|
|
76
|
-
}
|
|
77
|
-
start() {
|
|
78
|
-
if (__classPrivateFieldGet(this, _IncomingTransactionHelper_isRunning, "f")) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_blockTracker, "f").addListener('latest', __classPrivateFieldGet(this, _IncomingTransactionHelper_onLatestBlock, "f"));
|
|
85
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, true, "f");
|
|
86
|
-
}
|
|
87
|
-
stop() {
|
|
88
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_blockTracker, "f").removeListener('latest', __classPrivateFieldGet(this, _IncomingTransactionHelper_onLatestBlock, "f"));
|
|
89
|
-
__classPrivateFieldSet(this, _IncomingTransactionHelper_isRunning, false, "f");
|
|
90
|
-
}
|
|
91
|
-
update(latestBlockNumberHex) {
|
|
92
|
-
var _a, _b, _c;
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const releaseLock = yield __classPrivateFieldGet(this, _IncomingTransactionHelper_mutex, "f").acquire();
|
|
95
|
-
(0, logger_1.incomingTransactionsLogger)('Checking for incoming transactions');
|
|
96
|
-
try {
|
|
97
|
-
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_canStart).call(this)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const latestBlockNumber = parseInt(latestBlockNumberHex || (yield __classPrivateFieldGet(this, _IncomingTransactionHelper_blockTracker, "f").getLatestBlock()), 16);
|
|
101
|
-
const additionalLastFetchedKeys = (_c = (_b = (_a = __classPrivateFieldGet(this, _IncomingTransactionHelper_remoteTransactionSource, "f")).getLastBlockVariations) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
102
|
-
const fromBlock = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getFromBlock).call(this, latestBlockNumber);
|
|
103
|
-
const address = __classPrivateFieldGet(this, _IncomingTransactionHelper_getCurrentAccount, "f").call(this);
|
|
104
|
-
const currentChainId = __classPrivateFieldGet(this, _IncomingTransactionHelper_getChainId, "f").call(this);
|
|
105
|
-
let remoteTransactions = [];
|
|
106
|
-
try {
|
|
107
|
-
remoteTransactions =
|
|
108
|
-
yield __classPrivateFieldGet(this, _IncomingTransactionHelper_remoteTransactionSource, "f").fetchTransactions({
|
|
109
|
-
address,
|
|
110
|
-
currentChainId,
|
|
111
|
-
fromBlock,
|
|
112
|
-
limit: __classPrivateFieldGet(this, _IncomingTransactionHelper_transactionLimit, "f"),
|
|
113
|
-
});
|
|
114
|
-
// TODO: Replace `any` with type
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
(0, logger_1.incomingTransactionsLogger)('Error while fetching remote transactions', error);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (!__classPrivateFieldGet(this, _IncomingTransactionHelper_updateTransactions, "f")) {
|
|
122
|
-
remoteTransactions = remoteTransactions.filter((tx) => { var _a; return ((_a = tx.txParams.to) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase(); });
|
|
123
|
-
}
|
|
124
|
-
const localTransactions = !__classPrivateFieldGet(this, _IncomingTransactionHelper_updateTransactions, "f")
|
|
125
|
-
? []
|
|
126
|
-
: __classPrivateFieldGet(this, _IncomingTransactionHelper_getLocalTransactions, "f").call(this);
|
|
127
|
-
const newTransactions = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getNewTransactions).call(this, remoteTransactions, localTransactions);
|
|
128
|
-
const updatedTransactions = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getUpdatedTransactions).call(this, remoteTransactions, localTransactions);
|
|
129
|
-
if (newTransactions.length > 0 || updatedTransactions.length > 0) {
|
|
130
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_sortTransactionsByTime).call(this, newTransactions);
|
|
131
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_sortTransactionsByTime).call(this, updatedTransactions);
|
|
132
|
-
(0, logger_1.incomingTransactionsLogger)('Found incoming transactions', {
|
|
133
|
-
new: newTransactions,
|
|
134
|
-
updated: updatedTransactions,
|
|
135
|
-
});
|
|
136
|
-
this.hub.emit('transactions', {
|
|
137
|
-
added: newTransactions,
|
|
138
|
-
updated: updatedTransactions,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_updateLastFetchedBlockNumber).call(this, remoteTransactions, additionalLastFetchedKeys);
|
|
142
|
-
}
|
|
143
|
-
finally {
|
|
144
|
-
releaseLock();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
exports.IncomingTransactionHelper = IncomingTransactionHelper;
|
|
150
|
-
_IncomingTransactionHelper_blockTracker = new WeakMap(), _IncomingTransactionHelper_getCurrentAccount = new WeakMap(), _IncomingTransactionHelper_getLastFetchedBlockNumbers = new WeakMap(), _IncomingTransactionHelper_getLocalTransactions = new WeakMap(), _IncomingTransactionHelper_getChainId = new WeakMap(), _IncomingTransactionHelper_isEnabled = new WeakMap(), _IncomingTransactionHelper_isRunning = new WeakMap(), _IncomingTransactionHelper_mutex = new WeakMap(), _IncomingTransactionHelper_onLatestBlock = new WeakMap(), _IncomingTransactionHelper_queryEntireHistory = new WeakMap(), _IncomingTransactionHelper_remoteTransactionSource = new WeakMap(), _IncomingTransactionHelper_transactionLimit = new WeakMap(), _IncomingTransactionHelper_updateTransactions = new WeakMap(), _IncomingTransactionHelper_instances = new WeakSet(), _IncomingTransactionHelper_sortTransactionsByTime = function _IncomingTransactionHelper_sortTransactionsByTime(transactions) {
|
|
151
|
-
transactions.sort((a, b) => (a.time < b.time ? -1 : 1));
|
|
152
|
-
}, _IncomingTransactionHelper_getNewTransactions = function _IncomingTransactionHelper_getNewTransactions(remoteTxs, localTxs) {
|
|
153
|
-
return remoteTxs.filter((tx) => !localTxs.some(({ hash }) => hash === tx.hash));
|
|
154
|
-
}, _IncomingTransactionHelper_getUpdatedTransactions = function _IncomingTransactionHelper_getUpdatedTransactions(remoteTxs, localTxs) {
|
|
155
|
-
return remoteTxs.filter((remoteTx) => localTxs.some((localTx) => remoteTx.hash === localTx.hash &&
|
|
156
|
-
__classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_isTransactionOutdated).call(this, remoteTx, localTx)));
|
|
157
|
-
}, _IncomingTransactionHelper_isTransactionOutdated = function _IncomingTransactionHelper_isTransactionOutdated(remoteTx, localTx) {
|
|
158
|
-
return UPDATE_CHECKS.some((getValue) => getValue(remoteTx) !== getValue(localTx));
|
|
159
|
-
}, _IncomingTransactionHelper_getLastFetchedBlockNumberDec = function _IncomingTransactionHelper_getLastFetchedBlockNumberDec() {
|
|
160
|
-
var _a, _b, _c;
|
|
161
|
-
const additionalLastFetchedKeys = (_c = (_b = (_a = __classPrivateFieldGet(this, _IncomingTransactionHelper_remoteTransactionSource, "f")).getLastBlockVariations) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
|
|
162
|
-
const lastFetchedKey = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getBlockNumberKey).call(this, additionalLastFetchedKeys);
|
|
163
|
-
const lastFetchedBlockNumbers = __classPrivateFieldGet(this, _IncomingTransactionHelper_getLastFetchedBlockNumbers, "f").call(this);
|
|
164
|
-
return lastFetchedBlockNumbers[lastFetchedKey];
|
|
165
|
-
}, _IncomingTransactionHelper_getFromBlock = function _IncomingTransactionHelper_getFromBlock(latestBlockNumber) {
|
|
166
|
-
const lastFetchedBlockNumber = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getLastFetchedBlockNumberDec).call(this);
|
|
167
|
-
if (lastFetchedBlockNumber) {
|
|
168
|
-
return lastFetchedBlockNumber + 1;
|
|
169
|
-
}
|
|
170
|
-
return __classPrivateFieldGet(this, _IncomingTransactionHelper_queryEntireHistory, "f")
|
|
171
|
-
? undefined
|
|
172
|
-
: latestBlockNumber - RECENT_HISTORY_BLOCK_RANGE;
|
|
173
|
-
}, _IncomingTransactionHelper_updateLastFetchedBlockNumber = function _IncomingTransactionHelper_updateLastFetchedBlockNumber(remoteTxs, additionalKeys) {
|
|
174
|
-
let lastFetchedBlockNumber = -1;
|
|
175
|
-
for (const tx of remoteTxs) {
|
|
176
|
-
const currentBlockNumberValue = tx.blockNumber
|
|
177
|
-
? parseInt(tx.blockNumber, 10)
|
|
178
|
-
: -1;
|
|
179
|
-
lastFetchedBlockNumber = Math.max(lastFetchedBlockNumber, currentBlockNumberValue);
|
|
180
|
-
}
|
|
181
|
-
if (lastFetchedBlockNumber === -1) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const lastFetchedKey = __classPrivateFieldGet(this, _IncomingTransactionHelper_instances, "m", _IncomingTransactionHelper_getBlockNumberKey).call(this, additionalKeys);
|
|
185
|
-
const lastFetchedBlockNumbers = __classPrivateFieldGet(this, _IncomingTransactionHelper_getLastFetchedBlockNumbers, "f").call(this);
|
|
186
|
-
const previousValue = lastFetchedBlockNumbers[lastFetchedKey];
|
|
187
|
-
if (previousValue >= lastFetchedBlockNumber) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
lastFetchedBlockNumbers[lastFetchedKey] = lastFetchedBlockNumber;
|
|
191
|
-
this.hub.emit('updatedLastFetchedBlockNumbers', {
|
|
192
|
-
lastFetchedBlockNumbers,
|
|
193
|
-
blockNumber: lastFetchedBlockNumber,
|
|
194
|
-
});
|
|
195
|
-
}, _IncomingTransactionHelper_getBlockNumberKey = function _IncomingTransactionHelper_getBlockNumberKey(additionalKeys) {
|
|
196
|
-
var _a;
|
|
197
|
-
const currentChainId = __classPrivateFieldGet(this, _IncomingTransactionHelper_getChainId, "f").call(this);
|
|
198
|
-
const currentAccount = (_a = __classPrivateFieldGet(this, _IncomingTransactionHelper_getCurrentAccount, "f").call(this)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
199
|
-
return [currentChainId, currentAccount, ...additionalKeys].join('#');
|
|
200
|
-
}, _IncomingTransactionHelper_canStart = function _IncomingTransactionHelper_canStart() {
|
|
201
|
-
const isEnabled = __classPrivateFieldGet(this, _IncomingTransactionHelper_isEnabled, "f").call(this);
|
|
202
|
-
const currentChainId = __classPrivateFieldGet(this, _IncomingTransactionHelper_getChainId, "f").call(this);
|
|
203
|
-
const isSupportedNetwork = __classPrivateFieldGet(this, _IncomingTransactionHelper_remoteTransactionSource, "f").isSupportedNetwork(currentChainId);
|
|
204
|
-
return isEnabled && isSupportedNetwork;
|
|
205
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkDTDTOMTBjs = require('../chunk-DTDTOMTB.js');
|
|
4
|
+
require('../chunk-S6VGOPUY.js');
|
|
5
|
+
require('../chunk-Z4BLTVTB.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.IncomingTransactionHelper = _chunkDTDTOMTBjs.IncomingTransactionHelper;
|
|
206
9
|
//# sourceMappingURL=IncomingTransactionHelper.js.map
|