@metamask/assets-controllers 47.0.0 → 48.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 +20 -1
- package/dist/AccountTrackerController.cjs.map +1 -1
- package/dist/AccountTrackerController.d.cts +8 -3
- package/dist/AccountTrackerController.d.cts.map +1 -1
- package/dist/AccountTrackerController.d.mts +8 -3
- package/dist/AccountTrackerController.d.mts.map +1 -1
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +3 -3
- package/dist/AssetsContractController.cjs.map +1 -1
- package/dist/AssetsContractController.d.cts +3 -3
- package/dist/AssetsContractController.d.cts.map +1 -1
- package/dist/AssetsContractController.d.mts +3 -3
- package/dist/AssetsContractController.d.mts.map +1 -1
- package/dist/AssetsContractController.mjs +3 -3
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts +2 -2
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts +2 -2
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs +324 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs.map +1 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts +66 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts.map +1 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts +66 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts.map +1 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs +319 -0
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs.map +1 -0
- package/dist/MultichainAssetsController/index.cjs +7 -0
- package/dist/MultichainAssetsController/index.cjs.map +1 -0
- package/dist/MultichainAssetsController/index.d.cts +3 -0
- package/dist/MultichainAssetsController/index.d.cts.map +1 -0
- package/dist/MultichainAssetsController/index.d.mts +3 -0
- package/dist/MultichainAssetsController/index.d.mts.map +1 -0
- package/dist/MultichainAssetsController/index.mjs +2 -0
- package/dist/MultichainAssetsController/index.mjs.map +1 -0
- package/dist/MultichainAssetsController/utils.cjs +26 -0
- package/dist/MultichainAssetsController/utils.cjs.map +1 -0
- package/dist/MultichainAssetsController/utils.d.cts +13 -0
- package/dist/MultichainAssetsController/utils.d.cts.map +1 -0
- package/dist/MultichainAssetsController/utils.d.mts +13 -0
- package/dist/MultichainAssetsController/utils.d.mts.map +1 -0
- package/dist/MultichainAssetsController/utils.mjs +22 -0
- package/dist/MultichainAssetsController/utils.mjs.map +1 -0
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs +30 -65
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +5 -25
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +5 -25
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs +32 -67
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -1
- package/dist/MultichainBalancesController/constants.cjs +1 -10
- package/dist/MultichainBalancesController/constants.cjs.map +1 -1
- package/dist/MultichainBalancesController/constants.d.cts +0 -4
- package/dist/MultichainBalancesController/constants.d.cts.map +1 -1
- package/dist/MultichainBalancesController/constants.d.mts +0 -4
- package/dist/MultichainBalancesController/constants.d.mts.map +1 -1
- package/dist/MultichainBalancesController/constants.mjs +0 -9
- package/dist/MultichainBalancesController/constants.mjs.map +1 -1
- package/dist/MultichainBalancesController/index.cjs +1 -4
- package/dist/MultichainBalancesController/index.cjs.map +1 -1
- package/dist/MultichainBalancesController/index.d.cts +2 -3
- package/dist/MultichainBalancesController/index.d.cts.map +1 -1
- package/dist/MultichainBalancesController/index.d.mts +2 -3
- package/dist/MultichainBalancesController/index.d.mts.map +1 -1
- package/dist/MultichainBalancesController/index.mjs +1 -2
- package/dist/MultichainBalancesController/index.mjs.map +1 -1
- package/dist/MultichainBalancesController/utils.cjs +1 -14
- package/dist/MultichainBalancesController/utils.cjs.map +1 -1
- package/dist/MultichainBalancesController/utils.d.cts +0 -7
- package/dist/MultichainBalancesController/utils.d.cts.map +1 -1
- package/dist/MultichainBalancesController/utils.d.mts +0 -7
- package/dist/MultichainBalancesController/utils.d.mts.map +1 -1
- package/dist/MultichainBalancesController/utils.mjs +1 -13
- package/dist/MultichainBalancesController/utils.mjs.map +1 -1
- package/dist/NftController.cjs +1 -1
- package/dist/NftController.cjs.map +1 -1
- package/dist/NftController.d.cts +3 -3
- package/dist/NftController.d.cts.map +1 -1
- package/dist/NftController.d.mts +3 -3
- package/dist/NftController.d.mts.map +1 -1
- package/dist/NftController.mjs +1 -1
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs.map +1 -1
- package/dist/NftDetectionController.d.cts +2 -2
- package/dist/NftDetectionController.d.cts.map +1 -1
- package/dist/NftDetectionController.d.mts +2 -2
- package/dist/NftDetectionController.d.mts.map +1 -1
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/types.cjs.map +1 -1
- package/dist/RatesController/types.d.cts +2 -2
- package/dist/RatesController/types.d.cts.map +1 -1
- package/dist/RatesController/types.d.mts +2 -2
- package/dist/RatesController/types.d.mts.map +1 -1
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +6 -4
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +6 -4
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +1 -1
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +2 -2
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +2 -2
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +1 -1
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +1 -1
- package/dist/TokenListController.cjs.map +1 -1
- package/dist/TokenListController.d.cts +3 -3
- package/dist/TokenListController.d.cts.map +1 -1
- package/dist/TokenListController.d.mts +3 -3
- package/dist/TokenListController.d.mts.map +1 -1
- package/dist/TokenListController.mjs +1 -1
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +1 -1
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts +3 -3
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts +3 -3
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs +1 -1
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokensController.cjs +9 -6
- package/dist/TokensController.cjs.map +1 -1
- package/dist/TokensController.d.cts +3 -3
- package/dist/TokensController.d.cts.map +1 -1
- package/dist/TokensController.d.mts +3 -3
- package/dist/TokensController.d.mts.map +1 -1
- package/dist/TokensController.mjs +9 -6
- package/dist/TokensController.mjs.map +1 -1
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +1 -1
- package/package.json +14 -11
- package/dist/MultichainBalancesController/BalancesTracker.cjs +0 -122
- package/dist/MultichainBalancesController/BalancesTracker.cjs.map +0 -1
- package/dist/MultichainBalancesController/BalancesTracker.d.cts +0 -54
- package/dist/MultichainBalancesController/BalancesTracker.d.cts.map +0 -1
- package/dist/MultichainBalancesController/BalancesTracker.d.mts +0 -54
- package/dist/MultichainBalancesController/BalancesTracker.d.mts.map +0 -1
- package/dist/MultichainBalancesController/BalancesTracker.mjs +0 -118
- package/dist/MultichainBalancesController/BalancesTracker.mjs.map +0 -1
- package/dist/MultichainBalancesController/Poller.cjs +0 -45
- package/dist/MultichainBalancesController/Poller.cjs.map +0 -1
- package/dist/MultichainBalancesController/Poller.d.cts +0 -7
- package/dist/MultichainBalancesController/Poller.d.cts.map +0 -1
- package/dist/MultichainBalancesController/Poller.d.mts +0 -7
- package/dist/MultichainBalancesController/Poller.d.mts.map +0 -1
- package/dist/MultichainBalancesController/Poller.mjs +0 -41
- package/dist/MultichainBalancesController/Poller.mjs.map +0 -1
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
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");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _BalancesTracker_instances, _BalancesTracker_poller, _BalancesTracker_updateBalance, _BalancesTracker_balances, _BalancesTracker_isBalanceOutdated;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.BalancesTracker = void 0;
|
|
16
|
-
const Poller_1 = require("./Poller.cjs");
|
|
17
|
-
const BALANCES_TRACKING_INTERVAL = 5000; // Every 5s in milliseconds.
|
|
18
|
-
class BalancesTracker {
|
|
19
|
-
constructor(updateBalanceCallback) {
|
|
20
|
-
_BalancesTracker_instances.add(this);
|
|
21
|
-
_BalancesTracker_poller.set(this, void 0);
|
|
22
|
-
_BalancesTracker_updateBalance.set(this, void 0);
|
|
23
|
-
_BalancesTracker_balances.set(this, {});
|
|
24
|
-
__classPrivateFieldSet(this, _BalancesTracker_updateBalance, updateBalanceCallback, "f");
|
|
25
|
-
__classPrivateFieldSet(this, _BalancesTracker_poller, new Poller_1.Poller(() => this.updateBalances(), BALANCES_TRACKING_INTERVAL), "f");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Starts the tracking process.
|
|
29
|
-
*/
|
|
30
|
-
start() {
|
|
31
|
-
__classPrivateFieldGet(this, _BalancesTracker_poller, "f").start();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Stops the tracking process.
|
|
35
|
-
*/
|
|
36
|
-
stop() {
|
|
37
|
-
__classPrivateFieldGet(this, _BalancesTracker_poller, "f").stop();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Checks if an account ID is being tracked.
|
|
41
|
-
*
|
|
42
|
-
* @param accountId - The account ID.
|
|
43
|
-
* @returns True if the account is being tracked, false otherwise.
|
|
44
|
-
*/
|
|
45
|
-
isTracked(accountId) {
|
|
46
|
-
return Object.prototype.hasOwnProperty.call(__classPrivateFieldGet(this, _BalancesTracker_balances, "f"), accountId);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Asserts that an account ID is being tracked.
|
|
50
|
-
*
|
|
51
|
-
* @param accountId - The account ID.
|
|
52
|
-
* @throws If the account ID is not being tracked.
|
|
53
|
-
*/
|
|
54
|
-
assertBeingTracked(accountId) {
|
|
55
|
-
if (!this.isTracked(accountId)) {
|
|
56
|
-
throw new Error(`Account is not being tracked: ${accountId}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Starts tracking a new account ID. This method has no effect on already tracked
|
|
61
|
-
* accounts.
|
|
62
|
-
*
|
|
63
|
-
* @param accountId - The account ID.
|
|
64
|
-
* @param blockTime - The block time (used when refreshing the account balances).
|
|
65
|
-
*/
|
|
66
|
-
track(accountId, blockTime) {
|
|
67
|
-
// Do not overwrite current info if already being tracked!
|
|
68
|
-
if (!this.isTracked(accountId)) {
|
|
69
|
-
__classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId] = {
|
|
70
|
-
lastUpdated: 0,
|
|
71
|
-
blockTime,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Stops tracking a tracked account ID.
|
|
77
|
-
*
|
|
78
|
-
* @param accountId - The account ID.
|
|
79
|
-
* @throws If the account ID is not being tracked.
|
|
80
|
-
*/
|
|
81
|
-
untrack(accountId) {
|
|
82
|
-
this.assertBeingTracked(accountId);
|
|
83
|
-
delete __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Update the balances for a tracked account ID.
|
|
87
|
-
*
|
|
88
|
-
* @param accountId - The account ID.
|
|
89
|
-
* @throws If the account ID is not being tracked.
|
|
90
|
-
*/
|
|
91
|
-
async updateBalance(accountId) {
|
|
92
|
-
this.assertBeingTracked(accountId);
|
|
93
|
-
// We check if the balance is outdated (by comparing to the block time associated
|
|
94
|
-
// with this kind of account).
|
|
95
|
-
//
|
|
96
|
-
// This might not be super accurate, but we could probably compute this differently
|
|
97
|
-
// and try to sync with the "real block time"!
|
|
98
|
-
const info = __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
|
|
99
|
-
if (__classPrivateFieldGet(this, _BalancesTracker_instances, "m", _BalancesTracker_isBalanceOutdated).call(this, info)) {
|
|
100
|
-
await __classPrivateFieldGet(this, _BalancesTracker_updateBalance, "f").call(this, accountId);
|
|
101
|
-
__classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId].lastUpdated = Date.now();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Update the balances of all tracked accounts (only if the balances
|
|
106
|
-
* is considered outdated).
|
|
107
|
-
*/
|
|
108
|
-
async updateBalances() {
|
|
109
|
-
await Promise.allSettled(Object.keys(__classPrivateFieldGet(this, _BalancesTracker_balances, "f")).map(async (accountId) => {
|
|
110
|
-
await this.updateBalance(accountId);
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.BalancesTracker = BalancesTracker;
|
|
115
|
-
_BalancesTracker_poller = new WeakMap(), _BalancesTracker_updateBalance = new WeakMap(), _BalancesTracker_balances = new WeakMap(), _BalancesTracker_instances = new WeakSet(), _BalancesTracker_isBalanceOutdated = function _BalancesTracker_isBalanceOutdated({ lastUpdated, blockTime }) {
|
|
116
|
-
return (
|
|
117
|
-
// Never been updated:
|
|
118
|
-
lastUpdated === 0 ||
|
|
119
|
-
// Outdated:
|
|
120
|
-
Date.now() - lastUpdated >= blockTime);
|
|
121
|
-
};
|
|
122
|
-
//# sourceMappingURL=BalancesTracker.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BalancesTracker.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAkC;AAOlC,MAAM,0BAA0B,GAAG,IAAI,CAAC,CAAC,4BAA4B;AAErE,MAAa,eAAe;IAO1B,YAAY,qBAA2D;;QANvE,0CAAgB;QAEhB,iDAAqD;QAErD,oCAAyC,EAAE,EAAC;QAG1C,uBAAA,IAAI,kCAAkB,qBAAqB,MAAA,CAAC;QAE5C,uBAAA,IAAI,2BAAW,IAAI,eAAM,CACvB,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,EAC3B,0BAA0B,CAC3B,MAAA,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,+BAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,uBAAA,IAAI,+BAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,SAAiB;QACzB,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,uBAAA,IAAI,iCAAU,EAAE,SAAS,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,SAAiB;QAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;SAC/D;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAiB,EAAE,SAAiB;QACxC,0DAA0D;QAC1D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,GAAG;gBAC1B,WAAW,EAAE,CAAC;gBACd,SAAS;aACV,CAAC;SACH;IACH,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,SAAiB;QACvB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACnC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAEnC,iFAAiF;QACjF,8BAA8B;QAC9B,EAAE;QACF,mFAAmF;QACnF,8CAA8C;QAC9C,MAAM,IAAI,GAAG,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,uBAAA,IAAI,sEAAmB,MAAvB,IAAI,EAAoB,IAAI,CAAC,EAAE;YACjC,MAAM,uBAAA,IAAI,sCAAe,MAAnB,IAAI,EAAgB,SAAS,CAAC,CAAC;YACrC,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;SACpD;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,IAAI,CAAC,uBAAA,IAAI,iCAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;YAClD,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CAkBF;AAjID,0CAiIC;iQARoB,EAAE,WAAW,EAAE,SAAS,EAAe;IACxD,OAAO;IACL,sBAAsB;IACtB,WAAW,KAAK,CAAC;QACjB,YAAY;QACZ,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,IAAI,SAAS,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import { Poller } from './Poller';\n\ntype BalanceInfo = {\n lastUpdated: number;\n blockTime: number;\n};\n\nconst BALANCES_TRACKING_INTERVAL = 5000; // Every 5s in milliseconds.\n\nexport class BalancesTracker {\n #poller: Poller;\n\n #updateBalance: (accountId: string) => Promise<void>;\n\n #balances: Record<string, BalanceInfo> = {};\n\n constructor(updateBalanceCallback: (accountId: string) => Promise<void>) {\n this.#updateBalance = updateBalanceCallback;\n\n this.#poller = new Poller(\n () => this.updateBalances(),\n BALANCES_TRACKING_INTERVAL,\n );\n }\n\n /**\n * Starts the tracking process.\n */\n start(): void {\n this.#poller.start();\n }\n\n /**\n * Stops the tracking process.\n */\n stop(): void {\n this.#poller.stop();\n }\n\n /**\n * Checks if an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @returns True if the account is being tracked, false otherwise.\n */\n isTracked(accountId: string) {\n return Object.prototype.hasOwnProperty.call(this.#balances, accountId);\n }\n\n /**\n * Asserts that an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n assertBeingTracked(accountId: string) {\n if (!this.isTracked(accountId)) {\n throw new Error(`Account is not being tracked: ${accountId}`);\n }\n }\n\n /**\n * Starts tracking a new account ID. This method has no effect on already tracked\n * accounts.\n *\n * @param accountId - The account ID.\n * @param blockTime - The block time (used when refreshing the account balances).\n */\n track(accountId: string, blockTime: number) {\n // Do not overwrite current info if already being tracked!\n if (!this.isTracked(accountId)) {\n this.#balances[accountId] = {\n lastUpdated: 0,\n blockTime,\n };\n }\n }\n\n /**\n * Stops tracking a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n untrack(accountId: string) {\n this.assertBeingTracked(accountId);\n delete this.#balances[accountId];\n }\n\n /**\n * Update the balances for a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n async updateBalance(accountId: string) {\n this.assertBeingTracked(accountId);\n\n // We check if the balance is outdated (by comparing to the block time associated\n // with this kind of account).\n //\n // This might not be super accurate, but we could probably compute this differently\n // and try to sync with the \"real block time\"!\n const info = this.#balances[accountId];\n if (this.#isBalanceOutdated(info)) {\n await this.#updateBalance(accountId);\n this.#balances[accountId].lastUpdated = Date.now();\n }\n }\n\n /**\n * Update the balances of all tracked accounts (only if the balances\n * is considered outdated).\n */\n async updateBalances() {\n await Promise.allSettled(\n Object.keys(this.#balances).map(async (accountId) => {\n await this.updateBalance(accountId);\n }),\n );\n }\n\n /**\n * Checks if the balance is outdated according to the provided data.\n *\n * @param param - The balance info.\n * @param param.lastUpdated - The last updated timestamp.\n * @param param.blockTime - The block time.\n * @returns True if the balance is outdated, false otherwise.\n */\n #isBalanceOutdated({ lastUpdated, blockTime }: BalanceInfo): boolean {\n return (\n // Never been updated:\n lastUpdated === 0 ||\n // Outdated:\n Date.now() - lastUpdated >= blockTime\n );\n }\n}\n"]}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export declare class BalancesTracker {
|
|
2
|
-
#private;
|
|
3
|
-
constructor(updateBalanceCallback: (accountId: string) => Promise<void>);
|
|
4
|
-
/**
|
|
5
|
-
* Starts the tracking process.
|
|
6
|
-
*/
|
|
7
|
-
start(): void;
|
|
8
|
-
/**
|
|
9
|
-
* Stops the tracking process.
|
|
10
|
-
*/
|
|
11
|
-
stop(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Checks if an account ID is being tracked.
|
|
14
|
-
*
|
|
15
|
-
* @param accountId - The account ID.
|
|
16
|
-
* @returns True if the account is being tracked, false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
isTracked(accountId: string): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Asserts that an account ID is being tracked.
|
|
21
|
-
*
|
|
22
|
-
* @param accountId - The account ID.
|
|
23
|
-
* @throws If the account ID is not being tracked.
|
|
24
|
-
*/
|
|
25
|
-
assertBeingTracked(accountId: string): void;
|
|
26
|
-
/**
|
|
27
|
-
* Starts tracking a new account ID. This method has no effect on already tracked
|
|
28
|
-
* accounts.
|
|
29
|
-
*
|
|
30
|
-
* @param accountId - The account ID.
|
|
31
|
-
* @param blockTime - The block time (used when refreshing the account balances).
|
|
32
|
-
*/
|
|
33
|
-
track(accountId: string, blockTime: number): void;
|
|
34
|
-
/**
|
|
35
|
-
* Stops tracking a tracked account ID.
|
|
36
|
-
*
|
|
37
|
-
* @param accountId - The account ID.
|
|
38
|
-
* @throws If the account ID is not being tracked.
|
|
39
|
-
*/
|
|
40
|
-
untrack(accountId: string): void;
|
|
41
|
-
/**
|
|
42
|
-
* Update the balances for a tracked account ID.
|
|
43
|
-
*
|
|
44
|
-
* @param accountId - The account ID.
|
|
45
|
-
* @throws If the account ID is not being tracked.
|
|
46
|
-
*/
|
|
47
|
-
updateBalance(accountId: string): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Update the balances of all tracked accounts (only if the balances
|
|
50
|
-
* is considered outdated).
|
|
51
|
-
*/
|
|
52
|
-
updateBalances(): Promise<void>;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=BalancesTracker.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BalancesTracker.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":"AASA,qBAAa,eAAe;;gBAOd,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IASvE;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM;IAI3B;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM;IAMpC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAU1C;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM;IAKzB;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM;IAerC;;;OAGG;IACG,cAAc;CAwBrB"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export declare class BalancesTracker {
|
|
2
|
-
#private;
|
|
3
|
-
constructor(updateBalanceCallback: (accountId: string) => Promise<void>);
|
|
4
|
-
/**
|
|
5
|
-
* Starts the tracking process.
|
|
6
|
-
*/
|
|
7
|
-
start(): void;
|
|
8
|
-
/**
|
|
9
|
-
* Stops the tracking process.
|
|
10
|
-
*/
|
|
11
|
-
stop(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Checks if an account ID is being tracked.
|
|
14
|
-
*
|
|
15
|
-
* @param accountId - The account ID.
|
|
16
|
-
* @returns True if the account is being tracked, false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
isTracked(accountId: string): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Asserts that an account ID is being tracked.
|
|
21
|
-
*
|
|
22
|
-
* @param accountId - The account ID.
|
|
23
|
-
* @throws If the account ID is not being tracked.
|
|
24
|
-
*/
|
|
25
|
-
assertBeingTracked(accountId: string): void;
|
|
26
|
-
/**
|
|
27
|
-
* Starts tracking a new account ID. This method has no effect on already tracked
|
|
28
|
-
* accounts.
|
|
29
|
-
*
|
|
30
|
-
* @param accountId - The account ID.
|
|
31
|
-
* @param blockTime - The block time (used when refreshing the account balances).
|
|
32
|
-
*/
|
|
33
|
-
track(accountId: string, blockTime: number): void;
|
|
34
|
-
/**
|
|
35
|
-
* Stops tracking a tracked account ID.
|
|
36
|
-
*
|
|
37
|
-
* @param accountId - The account ID.
|
|
38
|
-
* @throws If the account ID is not being tracked.
|
|
39
|
-
*/
|
|
40
|
-
untrack(accountId: string): void;
|
|
41
|
-
/**
|
|
42
|
-
* Update the balances for a tracked account ID.
|
|
43
|
-
*
|
|
44
|
-
* @param accountId - The account ID.
|
|
45
|
-
* @throws If the account ID is not being tracked.
|
|
46
|
-
*/
|
|
47
|
-
updateBalance(accountId: string): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Update the balances of all tracked accounts (only if the balances
|
|
50
|
-
* is considered outdated).
|
|
51
|
-
*/
|
|
52
|
-
updateBalances(): Promise<void>;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=BalancesTracker.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BalancesTracker.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":"AASA,qBAAa,eAAe;;gBAOd,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IASvE;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM;IAI3B;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM;IAMpC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAU1C;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM;IAKzB;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM;IAerC;;;OAGG;IACG,cAAc;CAwBrB"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
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");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
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");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _BalancesTracker_instances, _BalancesTracker_poller, _BalancesTracker_updateBalance, _BalancesTracker_balances, _BalancesTracker_isBalanceOutdated;
|
|
13
|
-
import { Poller } from "./Poller.mjs";
|
|
14
|
-
const BALANCES_TRACKING_INTERVAL = 5000; // Every 5s in milliseconds.
|
|
15
|
-
export class BalancesTracker {
|
|
16
|
-
constructor(updateBalanceCallback) {
|
|
17
|
-
_BalancesTracker_instances.add(this);
|
|
18
|
-
_BalancesTracker_poller.set(this, void 0);
|
|
19
|
-
_BalancesTracker_updateBalance.set(this, void 0);
|
|
20
|
-
_BalancesTracker_balances.set(this, {});
|
|
21
|
-
__classPrivateFieldSet(this, _BalancesTracker_updateBalance, updateBalanceCallback, "f");
|
|
22
|
-
__classPrivateFieldSet(this, _BalancesTracker_poller, new Poller(() => this.updateBalances(), BALANCES_TRACKING_INTERVAL), "f");
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Starts the tracking process.
|
|
26
|
-
*/
|
|
27
|
-
start() {
|
|
28
|
-
__classPrivateFieldGet(this, _BalancesTracker_poller, "f").start();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Stops the tracking process.
|
|
32
|
-
*/
|
|
33
|
-
stop() {
|
|
34
|
-
__classPrivateFieldGet(this, _BalancesTracker_poller, "f").stop();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Checks if an account ID is being tracked.
|
|
38
|
-
*
|
|
39
|
-
* @param accountId - The account ID.
|
|
40
|
-
* @returns True if the account is being tracked, false otherwise.
|
|
41
|
-
*/
|
|
42
|
-
isTracked(accountId) {
|
|
43
|
-
return Object.prototype.hasOwnProperty.call(__classPrivateFieldGet(this, _BalancesTracker_balances, "f"), accountId);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Asserts that an account ID is being tracked.
|
|
47
|
-
*
|
|
48
|
-
* @param accountId - The account ID.
|
|
49
|
-
* @throws If the account ID is not being tracked.
|
|
50
|
-
*/
|
|
51
|
-
assertBeingTracked(accountId) {
|
|
52
|
-
if (!this.isTracked(accountId)) {
|
|
53
|
-
throw new Error(`Account is not being tracked: ${accountId}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Starts tracking a new account ID. This method has no effect on already tracked
|
|
58
|
-
* accounts.
|
|
59
|
-
*
|
|
60
|
-
* @param accountId - The account ID.
|
|
61
|
-
* @param blockTime - The block time (used when refreshing the account balances).
|
|
62
|
-
*/
|
|
63
|
-
track(accountId, blockTime) {
|
|
64
|
-
// Do not overwrite current info if already being tracked!
|
|
65
|
-
if (!this.isTracked(accountId)) {
|
|
66
|
-
__classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId] = {
|
|
67
|
-
lastUpdated: 0,
|
|
68
|
-
blockTime,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Stops tracking a tracked account ID.
|
|
74
|
-
*
|
|
75
|
-
* @param accountId - The account ID.
|
|
76
|
-
* @throws If the account ID is not being tracked.
|
|
77
|
-
*/
|
|
78
|
-
untrack(accountId) {
|
|
79
|
-
this.assertBeingTracked(accountId);
|
|
80
|
-
delete __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Update the balances for a tracked account ID.
|
|
84
|
-
*
|
|
85
|
-
* @param accountId - The account ID.
|
|
86
|
-
* @throws If the account ID is not being tracked.
|
|
87
|
-
*/
|
|
88
|
-
async updateBalance(accountId) {
|
|
89
|
-
this.assertBeingTracked(accountId);
|
|
90
|
-
// We check if the balance is outdated (by comparing to the block time associated
|
|
91
|
-
// with this kind of account).
|
|
92
|
-
//
|
|
93
|
-
// This might not be super accurate, but we could probably compute this differently
|
|
94
|
-
// and try to sync with the "real block time"!
|
|
95
|
-
const info = __classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId];
|
|
96
|
-
if (__classPrivateFieldGet(this, _BalancesTracker_instances, "m", _BalancesTracker_isBalanceOutdated).call(this, info)) {
|
|
97
|
-
await __classPrivateFieldGet(this, _BalancesTracker_updateBalance, "f").call(this, accountId);
|
|
98
|
-
__classPrivateFieldGet(this, _BalancesTracker_balances, "f")[accountId].lastUpdated = Date.now();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Update the balances of all tracked accounts (only if the balances
|
|
103
|
-
* is considered outdated).
|
|
104
|
-
*/
|
|
105
|
-
async updateBalances() {
|
|
106
|
-
await Promise.allSettled(Object.keys(__classPrivateFieldGet(this, _BalancesTracker_balances, "f")).map(async (accountId) => {
|
|
107
|
-
await this.updateBalance(accountId);
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
_BalancesTracker_poller = new WeakMap(), _BalancesTracker_updateBalance = new WeakMap(), _BalancesTracker_balances = new WeakMap(), _BalancesTracker_instances = new WeakSet(), _BalancesTracker_isBalanceOutdated = function _BalancesTracker_isBalanceOutdated({ lastUpdated, blockTime }) {
|
|
112
|
-
return (
|
|
113
|
-
// Never been updated:
|
|
114
|
-
lastUpdated === 0 ||
|
|
115
|
-
// Outdated:
|
|
116
|
-
Date.now() - lastUpdated >= blockTime);
|
|
117
|
-
};
|
|
118
|
-
//# sourceMappingURL=BalancesTracker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BalancesTracker.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/BalancesTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAOlC,MAAM,0BAA0B,GAAG,IAAI,CAAC,CAAC,4BAA4B;AAErE,MAAM,OAAO,eAAe;IAO1B,YAAY,qBAA2D;;QANvE,0CAAgB;QAEhB,iDAAqD;QAErD,oCAAyC,EAAE,EAAC;QAG1C,uBAAA,IAAI,kCAAkB,qBAAqB,MAAA,CAAC;QAE5C,uBAAA,IAAI,2BAAW,IAAI,MAAM,CACvB,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,EAC3B,0BAA0B,CAC3B,MAAA,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,+BAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,uBAAA,IAAI,+BAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,SAAiB;QACzB,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,uBAAA,IAAI,iCAAU,EAAE,SAAS,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,SAAiB;QAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;SAC/D;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAiB,EAAE,SAAiB;QACxC,0DAA0D;QAC1D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YAC9B,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,GAAG;gBAC1B,WAAW,EAAE,CAAC;gBACd,SAAS;aACV,CAAC;SACH;IACH,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,SAAiB;QACvB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnC,OAAO,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACnC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAEnC,iFAAiF;QACjF,8BAA8B;QAC9B,EAAE;QACF,mFAAmF;QACnF,8CAA8C;QAC9C,MAAM,IAAI,GAAG,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,uBAAA,IAAI,sEAAmB,MAAvB,IAAI,EAAoB,IAAI,CAAC,EAAE;YACjC,MAAM,uBAAA,IAAI,sCAAe,MAAnB,IAAI,EAAgB,SAAS,CAAC,CAAC;YACrC,uBAAA,IAAI,iCAAU,CAAC,SAAS,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;SACpD;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,IAAI,CAAC,uBAAA,IAAI,iCAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;YAClD,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CAkBF;iQARoB,EAAE,WAAW,EAAE,SAAS,EAAe;IACxD,OAAO;IACL,sBAAsB;IACtB,WAAW,KAAK,CAAC;QACjB,YAAY;QACZ,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,IAAI,SAAS,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import { Poller } from './Poller';\n\ntype BalanceInfo = {\n lastUpdated: number;\n blockTime: number;\n};\n\nconst BALANCES_TRACKING_INTERVAL = 5000; // Every 5s in milliseconds.\n\nexport class BalancesTracker {\n #poller: Poller;\n\n #updateBalance: (accountId: string) => Promise<void>;\n\n #balances: Record<string, BalanceInfo> = {};\n\n constructor(updateBalanceCallback: (accountId: string) => Promise<void>) {\n this.#updateBalance = updateBalanceCallback;\n\n this.#poller = new Poller(\n () => this.updateBalances(),\n BALANCES_TRACKING_INTERVAL,\n );\n }\n\n /**\n * Starts the tracking process.\n */\n start(): void {\n this.#poller.start();\n }\n\n /**\n * Stops the tracking process.\n */\n stop(): void {\n this.#poller.stop();\n }\n\n /**\n * Checks if an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @returns True if the account is being tracked, false otherwise.\n */\n isTracked(accountId: string) {\n return Object.prototype.hasOwnProperty.call(this.#balances, accountId);\n }\n\n /**\n * Asserts that an account ID is being tracked.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n assertBeingTracked(accountId: string) {\n if (!this.isTracked(accountId)) {\n throw new Error(`Account is not being tracked: ${accountId}`);\n }\n }\n\n /**\n * Starts tracking a new account ID. This method has no effect on already tracked\n * accounts.\n *\n * @param accountId - The account ID.\n * @param blockTime - The block time (used when refreshing the account balances).\n */\n track(accountId: string, blockTime: number) {\n // Do not overwrite current info if already being tracked!\n if (!this.isTracked(accountId)) {\n this.#balances[accountId] = {\n lastUpdated: 0,\n blockTime,\n };\n }\n }\n\n /**\n * Stops tracking a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n untrack(accountId: string) {\n this.assertBeingTracked(accountId);\n delete this.#balances[accountId];\n }\n\n /**\n * Update the balances for a tracked account ID.\n *\n * @param accountId - The account ID.\n * @throws If the account ID is not being tracked.\n */\n async updateBalance(accountId: string) {\n this.assertBeingTracked(accountId);\n\n // We check if the balance is outdated (by comparing to the block time associated\n // with this kind of account).\n //\n // This might not be super accurate, but we could probably compute this differently\n // and try to sync with the \"real block time\"!\n const info = this.#balances[accountId];\n if (this.#isBalanceOutdated(info)) {\n await this.#updateBalance(accountId);\n this.#balances[accountId].lastUpdated = Date.now();\n }\n }\n\n /**\n * Update the balances of all tracked accounts (only if the balances\n * is considered outdated).\n */\n async updateBalances() {\n await Promise.allSettled(\n Object.keys(this.#balances).map(async (accountId) => {\n await this.updateBalance(accountId);\n }),\n );\n }\n\n /**\n * Checks if the balance is outdated according to the provided data.\n *\n * @param param - The balance info.\n * @param param.lastUpdated - The last updated timestamp.\n * @param param.blockTime - The block time.\n * @returns True if the balance is outdated, false otherwise.\n */\n #isBalanceOutdated({ lastUpdated, blockTime }: BalanceInfo): boolean {\n return (\n // Never been updated:\n lastUpdated === 0 ||\n // Outdated:\n Date.now() - lastUpdated >= blockTime\n );\n }\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
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");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _Poller_interval, _Poller_callback, _Poller_handle;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Poller = void 0;
|
|
16
|
-
const error_1 = require("./error.cjs");
|
|
17
|
-
class Poller {
|
|
18
|
-
constructor(callback, interval) {
|
|
19
|
-
_Poller_interval.set(this, void 0);
|
|
20
|
-
_Poller_callback.set(this, void 0);
|
|
21
|
-
_Poller_handle.set(this, undefined);
|
|
22
|
-
__classPrivateFieldSet(this, _Poller_interval, interval, "f");
|
|
23
|
-
__classPrivateFieldSet(this, _Poller_callback, callback, "f");
|
|
24
|
-
}
|
|
25
|
-
start() {
|
|
26
|
-
if (__classPrivateFieldGet(this, _Poller_handle, "f")) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
__classPrivateFieldSet(this, _Poller_handle, setInterval(() => {
|
|
30
|
-
__classPrivateFieldGet(this, _Poller_callback, "f").call(this).catch((err) => {
|
|
31
|
-
console.error(new error_1.PollerError(err.message));
|
|
32
|
-
});
|
|
33
|
-
}, __classPrivateFieldGet(this, _Poller_interval, "f")), "f");
|
|
34
|
-
}
|
|
35
|
-
stop() {
|
|
36
|
-
if (!__classPrivateFieldGet(this, _Poller_handle, "f")) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
clearInterval(__classPrivateFieldGet(this, _Poller_handle, "f"));
|
|
40
|
-
__classPrivateFieldSet(this, _Poller_handle, undefined, "f");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.Poller = Poller;
|
|
44
|
-
_Poller_interval = new WeakMap(), _Poller_callback = new WeakMap(), _Poller_handle = new WeakMap();
|
|
45
|
-
//# sourceMappingURL=Poller.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Poller.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAsC;AAEtC,MAAa,MAAM;IAOjB,YAAY,QAA6B,EAAE,QAAgB;QAN3D,mCAAkB;QAElB,mCAA+B;QAE/B,yBAAsC,SAAS,EAAC;QAG9C,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;QAC1B,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,uBAAA,IAAI,sBAAQ,EAAE;YAChB,OAAO;SACR;QAED,uBAAA,IAAI,kBAAW,WAAW,CAAC,GAAG,EAAE;YAC9B,uBAAA,IAAI,wBAAU,MAAd,IAAI,CAAY,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC7B,OAAO,CAAC,KAAK,CAAC,IAAI,mBAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,uBAAA,IAAI,wBAAU,CAAC,MAAA,CAAC;IACrB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,uBAAA,IAAI,sBAAQ,EAAE;YACjB,OAAO;SACR;QACD,aAAa,CAAC,uBAAA,IAAI,sBAAQ,CAAC,CAAC;QAC5B,uBAAA,IAAI,kBAAW,SAAS,MAAA,CAAC;IAC3B,CAAC;CACF;AA/BD,wBA+BC","sourcesContent":["import { PollerError } from './error';\n\nexport class Poller {\n #interval: number;\n\n #callback: () => Promise<void>;\n\n #handle: NodeJS.Timeout | undefined = undefined;\n\n constructor(callback: () => Promise<void>, interval: number) {\n this.#interval = interval;\n this.#callback = callback;\n }\n\n start() {\n if (this.#handle) {\n return;\n }\n\n this.#handle = setInterval(() => {\n this.#callback().catch((err) => {\n console.error(new PollerError(err.message));\n });\n }, this.#interval);\n }\n\n stop() {\n if (!this.#handle) {\n return;\n }\n clearInterval(this.#handle);\n this.#handle = undefined;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Poller.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;;gBAOL,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM;IAK3D,KAAK;IAYL,IAAI;CAOL"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Poller.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;;gBAOL,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM;IAK3D,KAAK;IAYL,IAAI;CAOL"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
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");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
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");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Poller_interval, _Poller_callback, _Poller_handle;
|
|
13
|
-
import { PollerError } from "./error.mjs";
|
|
14
|
-
export class Poller {
|
|
15
|
-
constructor(callback, interval) {
|
|
16
|
-
_Poller_interval.set(this, void 0);
|
|
17
|
-
_Poller_callback.set(this, void 0);
|
|
18
|
-
_Poller_handle.set(this, undefined);
|
|
19
|
-
__classPrivateFieldSet(this, _Poller_interval, interval, "f");
|
|
20
|
-
__classPrivateFieldSet(this, _Poller_callback, callback, "f");
|
|
21
|
-
}
|
|
22
|
-
start() {
|
|
23
|
-
if (__classPrivateFieldGet(this, _Poller_handle, "f")) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
__classPrivateFieldSet(this, _Poller_handle, setInterval(() => {
|
|
27
|
-
__classPrivateFieldGet(this, _Poller_callback, "f").call(this).catch((err) => {
|
|
28
|
-
console.error(new PollerError(err.message));
|
|
29
|
-
});
|
|
30
|
-
}, __classPrivateFieldGet(this, _Poller_interval, "f")), "f");
|
|
31
|
-
}
|
|
32
|
-
stop() {
|
|
33
|
-
if (!__classPrivateFieldGet(this, _Poller_handle, "f")) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
clearInterval(__classPrivateFieldGet(this, _Poller_handle, "f"));
|
|
37
|
-
__classPrivateFieldSet(this, _Poller_handle, undefined, "f");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
_Poller_interval = new WeakMap(), _Poller_callback = new WeakMap(), _Poller_handle = new WeakMap();
|
|
41
|
-
//# sourceMappingURL=Poller.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Poller.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/Poller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,MAAM,OAAO,MAAM;IAOjB,YAAY,QAA6B,EAAE,QAAgB;QAN3D,mCAAkB;QAElB,mCAA+B;QAE/B,yBAAsC,SAAS,EAAC;QAG9C,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;QAC1B,uBAAA,IAAI,oBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,uBAAA,IAAI,sBAAQ,EAAE;YAChB,OAAO;SACR;QAED,uBAAA,IAAI,kBAAW,WAAW,CAAC,GAAG,EAAE;YAC9B,uBAAA,IAAI,wBAAU,MAAd,IAAI,CAAY,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC7B,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,uBAAA,IAAI,wBAAU,CAAC,MAAA,CAAC;IACrB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,uBAAA,IAAI,sBAAQ,EAAE;YACjB,OAAO;SACR;QACD,aAAa,CAAC,uBAAA,IAAI,sBAAQ,CAAC,CAAC;QAC5B,uBAAA,IAAI,kBAAW,SAAS,MAAA,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { PollerError } from './error';\n\nexport class Poller {\n #interval: number;\n\n #callback: () => Promise<void>;\n\n #handle: NodeJS.Timeout | undefined = undefined;\n\n constructor(callback: () => Promise<void>, interval: number) {\n this.#interval = interval;\n this.#callback = callback;\n }\n\n start() {\n if (this.#handle) {\n return;\n }\n\n this.#handle = setInterval(() => {\n this.#callback().catch((err) => {\n console.error(new PollerError(err.message));\n });\n }, this.#interval);\n }\n\n stop() {\n if (!this.#handle) {\n return;\n }\n clearInterval(this.#handle);\n this.#handle = undefined;\n }\n}\n"]}
|