@metamask/multichain-account-service 7.0.0 → 8.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 +63 -1
- package/dist/MultichainAccountGroup.cjs +4 -69
- package/dist/MultichainAccountGroup.cjs.map +1 -1
- package/dist/MultichainAccountGroup.d.cts +0 -6
- package/dist/MultichainAccountGroup.d.cts.map +1 -1
- package/dist/MultichainAccountGroup.d.mts +0 -6
- package/dist/MultichainAccountGroup.d.mts.map +1 -1
- package/dist/MultichainAccountGroup.mjs +5 -70
- package/dist/MultichainAccountGroup.mjs.map +1 -1
- package/dist/MultichainAccountService-method-action-types.cjs +7 -0
- package/dist/MultichainAccountService-method-action-types.cjs.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.cts +177 -0
- package/dist/MultichainAccountService-method-action-types.d.cts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.d.mts +177 -0
- package/dist/MultichainAccountService-method-action-types.d.mts.map +1 -0
- package/dist/MultichainAccountService-method-action-types.mjs +6 -0
- package/dist/MultichainAccountService-method-action-types.mjs.map +1 -0
- package/dist/MultichainAccountService.cjs +59 -28
- package/dist/MultichainAccountService.cjs.map +1 -1
- package/dist/MultichainAccountService.d.cts +24 -2
- package/dist/MultichainAccountService.d.cts.map +1 -1
- package/dist/MultichainAccountService.d.mts +24 -2
- package/dist/MultichainAccountService.d.mts.map +1 -1
- package/dist/MultichainAccountService.mjs +60 -29
- package/dist/MultichainAccountService.mjs.map +1 -1
- package/dist/MultichainAccountWallet.cjs +302 -164
- package/dist/MultichainAccountWallet.cjs.map +1 -1
- package/dist/MultichainAccountWallet.d.cts +27 -7
- package/dist/MultichainAccountWallet.d.cts.map +1 -1
- package/dist/MultichainAccountWallet.d.mts +27 -7
- package/dist/MultichainAccountWallet.d.mts.map +1 -1
- package/dist/MultichainAccountWallet.mjs +303 -165
- package/dist/MultichainAccountWallet.mjs.map +1 -1
- package/dist/analytics/perf.cjs +65 -0
- package/dist/analytics/perf.cjs.map +1 -0
- package/dist/analytics/perf.d.cts +34 -0
- package/dist/analytics/perf.d.cts.map +1 -0
- package/dist/analytics/perf.d.mts +34 -0
- package/dist/analytics/perf.d.mts.map +1 -0
- package/dist/analytics/perf.mjs +59 -0
- package/dist/analytics/perf.mjs.map +1 -0
- package/dist/analytics/timer.cjs +14 -0
- package/dist/analytics/timer.cjs.map +1 -0
- package/dist/analytics/timer.d.cts +8 -0
- package/dist/analytics/timer.d.cts.map +1 -0
- package/dist/analytics/timer.d.mts +8 -0
- package/dist/analytics/timer.d.mts.map +1 -0
- package/dist/analytics/timer.mjs +10 -0
- package/dist/analytics/timer.mjs.map +1 -0
- package/dist/analytics/traces.cjs +49 -1
- package/dist/analytics/traces.cjs.map +1 -1
- package/dist/analytics/traces.d.cts +28 -0
- package/dist/analytics/traces.d.cts.map +1 -1
- package/dist/analytics/traces.d.mts +28 -0
- package/dist/analytics/traces.d.mts.map +1 -1
- package/dist/analytics/traces.mjs +46 -0
- package/dist/analytics/traces.mjs.map +1 -1
- package/dist/errors.cjs +32 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +16 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +16 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +28 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +14 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +8 -0
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.cjs +5 -6
- package/dist/providers/AccountProviderWrapper.cjs.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.cts +5 -4
- package/dist/providers/AccountProviderWrapper.d.cts.map +1 -1
- package/dist/providers/AccountProviderWrapper.d.mts +5 -4
- package/dist/providers/AccountProviderWrapper.d.mts.map +1 -1
- package/dist/providers/AccountProviderWrapper.mjs +5 -6
- package/dist/providers/AccountProviderWrapper.mjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.cjs +0 -10
- package/dist/providers/BaseBip44AccountProvider.cjs.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.cts +1 -17
- package/dist/providers/BaseBip44AccountProvider.d.cts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.d.mts +1 -17
- package/dist/providers/BaseBip44AccountProvider.d.mts.map +1 -1
- package/dist/providers/BaseBip44AccountProvider.mjs +0 -10
- package/dist/providers/BaseBip44AccountProvider.mjs.map +1 -1
- package/dist/providers/BtcAccountProvider.cjs +15 -33
- package/dist/providers/BtcAccountProvider.cjs.map +1 -1
- package/dist/providers/BtcAccountProvider.d.cts +6 -4
- package/dist/providers/BtcAccountProvider.d.cts.map +1 -1
- package/dist/providers/BtcAccountProvider.d.mts +6 -4
- package/dist/providers/BtcAccountProvider.d.mts.map +1 -1
- package/dist/providers/BtcAccountProvider.mjs +16 -34
- package/dist/providers/BtcAccountProvider.mjs.map +1 -1
- package/dist/providers/EvmAccountProvider.cjs +44 -3
- package/dist/providers/EvmAccountProvider.cjs.map +1 -1
- package/dist/providers/EvmAccountProvider.d.cts.map +1 -1
- package/dist/providers/EvmAccountProvider.d.mts.map +1 -1
- package/dist/providers/EvmAccountProvider.mjs +44 -3
- package/dist/providers/EvmAccountProvider.mjs.map +1 -1
- package/dist/providers/SnapAccountProvider.cjs +111 -21
- package/dist/providers/SnapAccountProvider.cjs.map +1 -1
- package/dist/providers/SnapAccountProvider.d.cts +33 -2
- package/dist/providers/SnapAccountProvider.d.cts.map +1 -1
- package/dist/providers/SnapAccountProvider.d.mts +33 -2
- package/dist/providers/SnapAccountProvider.d.mts.map +1 -1
- package/dist/providers/SnapAccountProvider.mjs +113 -23
- package/dist/providers/SnapAccountProvider.mjs.map +1 -1
- package/dist/providers/SolAccountProvider.cjs +31 -39
- package/dist/providers/SolAccountProvider.cjs.map +1 -1
- package/dist/providers/SolAccountProvider.d.cts +10 -3
- package/dist/providers/SolAccountProvider.d.cts.map +1 -1
- package/dist/providers/SolAccountProvider.d.mts +10 -3
- package/dist/providers/SolAccountProvider.d.mts.map +1 -1
- package/dist/providers/SolAccountProvider.mjs +32 -40
- package/dist/providers/SolAccountProvider.mjs.map +1 -1
- package/dist/providers/TrxAccountProvider.cjs +15 -37
- package/dist/providers/TrxAccountProvider.cjs.map +1 -1
- package/dist/providers/TrxAccountProvider.d.cts +6 -4
- package/dist/providers/TrxAccountProvider.d.cts.map +1 -1
- package/dist/providers/TrxAccountProvider.d.mts +6 -4
- package/dist/providers/TrxAccountProvider.d.mts.map +1 -1
- package/dist/providers/TrxAccountProvider.mjs +16 -38
- package/dist/providers/TrxAccountProvider.mjs.map +1 -1
- package/dist/providers/index.cjs +2 -1
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +1 -1
- package/dist/providers/index.d.cts.map +1 -1
- package/dist/providers/index.d.mts +1 -1
- package/dist/providers/index.d.mts.map +1 -1
- package/dist/providers/index.mjs +1 -1
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/utils.cjs +15 -5
- package/dist/providers/utils.cjs.map +1 -1
- package/dist/providers/utils.d.cts +9 -2
- package/dist/providers/utils.d.cts.map +1 -1
- package/dist/providers/utils.d.mts +9 -2
- package/dist/providers/utils.d.mts.map +1 -1
- package/dist/providers/utils.mjs +13 -4
- package/dist/providers/utils.mjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.cjs +72 -8
- package/dist/snaps/SnapPlatformWatcher.cjs.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts +15 -1
- package/dist/snaps/SnapPlatformWatcher.d.cts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts +15 -1
- package/dist/snaps/SnapPlatformWatcher.d.mts.map +1 -1
- package/dist/snaps/SnapPlatformWatcher.mjs +72 -8
- package/dist/snaps/SnapPlatformWatcher.mjs.map +1 -1
- package/dist/tests/accounts.cjs +7 -1
- package/dist/tests/accounts.cjs.map +1 -1
- package/dist/tests/accounts.d.cts +9 -0
- package/dist/tests/accounts.d.cts.map +1 -1
- package/dist/tests/accounts.d.mts +9 -0
- package/dist/tests/accounts.d.mts.map +1 -1
- package/dist/tests/accounts.mjs +6 -0
- package/dist/tests/accounts.mjs.map +1 -1
- package/dist/tests/index.cjs.map +1 -1
- package/dist/tests/index.d.cts +1 -0
- package/dist/tests/index.d.cts.map +1 -1
- package/dist/tests/index.d.mts +1 -0
- package/dist/tests/index.d.mts.map +1 -1
- package/dist/tests/index.mjs.map +1 -1
- package/dist/tests/providers.cjs +14 -16
- package/dist/tests/providers.cjs.map +1 -1
- package/dist/tests/providers.d.cts +11 -0
- package/dist/tests/providers.d.cts.map +1 -1
- package/dist/tests/providers.d.mts +11 -0
- package/dist/tests/providers.d.mts.map +1 -1
- package/dist/tests/providers.mjs +14 -17
- package/dist/tests/providers.mjs.map +1 -1
- package/dist/tests/types.cjs +3 -0
- package/dist/tests/types.cjs.map +1 -0
- package/dist/tests/types.d.cts +7 -0
- package/dist/tests/types.d.cts.map +1 -0
- package/dist/tests/types.d.mts +7 -0
- package/dist/tests/types.d.mts.map +1 -0
- package/dist/tests/types.mjs +2 -0
- package/dist/tests/types.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +13 -54
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +13 -54
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +49 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +32 -5
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +32 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +45 -4
- package/dist/utils.mjs.map +1 -1
- package/package.json +9 -7
- package/dist/constants/traces.cjs +0 -9
- package/dist/constants/traces.cjs.map +0 -1
- package/dist/constants/traces.d.cts +0 -5
- package/dist/constants/traces.d.cts.map +0 -1
- package/dist/constants/traces.d.mts +0 -5
- package/dist/constants/traces.d.mts.map +0 -1
- package/dist/constants/traces.mjs +0 -6
- package/dist/constants/traces.mjs.map +0 -1
|
@@ -10,13 +10,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _MultichainAccountWallet_instances, _MultichainAccountWallet_lock, _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accountGroups, _MultichainAccountWallet_messenger, _MultichainAccountWallet_log, _MultichainAccountWallet_initialized, _MultichainAccountWallet_status, _MultichainAccountWallet_withLock,
|
|
13
|
+
var _MultichainAccountWallet_instances, _MultichainAccountWallet_lock, _MultichainAccountWallet_id, _MultichainAccountWallet_providers, _MultichainAccountWallet_entropySource, _MultichainAccountWallet_accountGroups, _MultichainAccountWallet_messenger, _MultichainAccountWallet_trace, _MultichainAccountWallet_log, _MultichainAccountWallet_initialized, _MultichainAccountWallet_status, _MultichainAccountWallet_withLock, _MultichainAccountWallet_getProviders, _MultichainAccountWallet_createAccountsRangeForProvider, _MultichainAccountWallet_createOrUpdateMultichainAccountGroup, _MultichainAccountWallet_buildGroupStateForRange, _MultichainAccountWallet_createMultichainAccountGroupsRange, _MultichainAccountWallet_alignAccountsForRange, _MultichainAccountWallet_createMultichainAccountGroups;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MultichainAccountWallet = void 0;
|
|
16
16
|
const account_api_1 = require("@metamask/account-api");
|
|
17
17
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
18
18
|
const utils_1 = require("@metamask/utils");
|
|
19
19
|
const async_mutex_1 = require("async-mutex");
|
|
20
|
+
const analytics_1 = require("./analytics/index.cjs");
|
|
21
|
+
const errors_1 = require("./errors.cjs");
|
|
20
22
|
const logger_1 = require("./logger.cjs");
|
|
21
23
|
const MultichainAccountGroup_1 = require("./MultichainAccountGroup.cjs");
|
|
22
24
|
const EvmAccountProvider_1 = require("./providers/EvmAccountProvider.cjs");
|
|
@@ -26,7 +28,7 @@ const utils_2 = require("./utils.cjs");
|
|
|
26
28
|
* group index).
|
|
27
29
|
*/
|
|
28
30
|
class MultichainAccountWallet {
|
|
29
|
-
constructor({ providers, entropySource, messenger, }) {
|
|
31
|
+
constructor({ providers, entropySource, messenger, trace, }) {
|
|
30
32
|
_MultichainAccountWallet_instances.add(this);
|
|
31
33
|
_MultichainAccountWallet_lock.set(this, new async_mutex_1.Mutex());
|
|
32
34
|
_MultichainAccountWallet_id.set(this, void 0);
|
|
@@ -34,6 +36,7 @@ class MultichainAccountWallet {
|
|
|
34
36
|
_MultichainAccountWallet_entropySource.set(this, void 0);
|
|
35
37
|
_MultichainAccountWallet_accountGroups.set(this, void 0);
|
|
36
38
|
_MultichainAccountWallet_messenger.set(this, void 0);
|
|
39
|
+
_MultichainAccountWallet_trace.set(this, void 0);
|
|
37
40
|
_MultichainAccountWallet_log.set(this, void 0);
|
|
38
41
|
_MultichainAccountWallet_initialized.set(this, false);
|
|
39
42
|
_MultichainAccountWallet_status.set(this, void 0);
|
|
@@ -42,6 +45,7 @@ class MultichainAccountWallet {
|
|
|
42
45
|
__classPrivateFieldSet(this, _MultichainAccountWallet_entropySource, entropySource, "f");
|
|
43
46
|
__classPrivateFieldSet(this, _MultichainAccountWallet_messenger, messenger, "f");
|
|
44
47
|
__classPrivateFieldSet(this, _MultichainAccountWallet_accountGroups, new Map(), "f");
|
|
48
|
+
__classPrivateFieldSet(this, _MultichainAccountWallet_trace, trace ?? analytics_1.traceFallback, "f");
|
|
45
49
|
__classPrivateFieldSet(this, _MultichainAccountWallet_log, (0, logger_1.createModuleLogger)(logger_1.projectLogger, `[${__classPrivateFieldGet(this, _MultichainAccountWallet_id, "f")}]`), "f");
|
|
46
50
|
// Initial synchronization (don't emit events during initialization).
|
|
47
51
|
__classPrivateFieldSet(this, _MultichainAccountWallet_status, 'uninitialized', "f");
|
|
@@ -168,83 +172,65 @@ class MultichainAccountWallet {
|
|
|
168
172
|
* @param options - Options to configure the account creation.
|
|
169
173
|
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
|
|
170
174
|
* account providers to finish creating their accounts before returning. If `false`, only
|
|
171
|
-
* the EVM provider
|
|
172
|
-
*
|
|
173
|
-
* @throws If
|
|
174
|
-
*
|
|
175
|
-
* errors from non-EVM providers will be logged but ignored, and only errors from the
|
|
176
|
-
* EVM provider will be thrown.
|
|
175
|
+
* the EVM provider is used and non-EVM account creation is deferred via
|
|
176
|
+
* {@link MultichainAccountWallet.alignAccountsOf}. Defaults to `false`.
|
|
177
|
+
* @throws If groupIndex is greater than the next available group index.
|
|
178
|
+
* @throws If any account provider fails to create accounts.
|
|
177
179
|
* @returns The multichain account group for this group index.
|
|
178
180
|
*/
|
|
179
|
-
async createMultichainAccountGroup(groupIndex, options = {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let group = this.getMultichainAccountGroup(groupIndex);
|
|
186
|
-
if (group) {
|
|
187
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Trying to re-create existing group: [${group.id}] (idempotent)`);
|
|
188
|
-
return group;
|
|
189
|
-
}
|
|
190
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Creating new group for index ${groupIndex}...`);
|
|
191
|
-
// Extract the EVM provider from the list of providers.
|
|
192
|
-
// We always await EVM account creation first.
|
|
193
|
-
const [evmProvider, ...otherProviders] = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f");
|
|
194
|
-
(0, utils_1.assert)(evmProvider instanceof EvmAccountProvider_1.EvmAccountProvider, 'EVM account provider must be first');
|
|
195
|
-
const evmAccounts = await evmProvider
|
|
196
|
-
.createAccounts({
|
|
197
|
-
type: keyring_api_1.AccountCreationType.Bip44DeriveIndex,
|
|
198
|
-
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
199
|
-
groupIndex,
|
|
200
|
-
})
|
|
201
|
-
.then((accounts) => accounts.map((account) => account.id))
|
|
202
|
-
.catch((error) => {
|
|
203
|
-
const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider "${evmProvider.getName()}". Error: ${error.message}`;
|
|
204
|
-
console.warn(errorMessage);
|
|
205
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.ERROR_PREFIX} ${errorMessage}:`, error);
|
|
206
|
-
const sentryError = (0, utils_2.createSentryError)(`Unable to create account with provider "${evmProvider.getName()}"`, error, {
|
|
207
|
-
groupIndex,
|
|
208
|
-
provider: evmProvider.getName(),
|
|
209
|
-
});
|
|
210
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
|
|
211
|
-
throw error;
|
|
212
|
-
});
|
|
213
|
-
group = new MultichainAccountGroup_1.MultichainAccountGroup({
|
|
214
|
-
wallet: this,
|
|
215
|
-
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
181
|
+
async createMultichainAccountGroup(groupIndex, options = {}) {
|
|
182
|
+
// Use this to avoid having it as `boolean | undefined`.
|
|
183
|
+
const waitForAllProvidersToFinishCreatingAccounts = options.waitForAllProvidersToFinishCreatingAccounts ?? false;
|
|
184
|
+
return await __classPrivateFieldGet(this, _MultichainAccountWallet_trace, "f").call(this, {
|
|
185
|
+
name: analytics_1.TraceName.WalletCreateMultichainAccountGroup,
|
|
186
|
+
data: {
|
|
216
187
|
groupIndex,
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
awaitAll: true,
|
|
227
|
-
group,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
// eslint-disable-next-line no-void
|
|
232
|
-
void __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createNonEvmAccounts).call(this, {
|
|
233
|
-
groupIndex,
|
|
234
|
-
providers: otherProviders,
|
|
235
|
-
awaitAll: false,
|
|
236
|
-
group,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
// Register the account(s) to our internal map.
|
|
240
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
|
|
241
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `New group created: [${group.id}]`);
|
|
242
|
-
if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
|
|
243
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
|
|
188
|
+
waitForAllProvidersToFinishCreatingAccounts,
|
|
189
|
+
},
|
|
190
|
+
}, async () => {
|
|
191
|
+
(0, utils_2.assertGroupIndexIsValid)(groupIndex, this.getNextGroupIndex());
|
|
192
|
+
// If the group already exists, return it.
|
|
193
|
+
const existingGroup = this.getMultichainAccountGroup(groupIndex);
|
|
194
|
+
if (existingGroup) {
|
|
195
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Trying to re-create existing group: [${existingGroup.id}] (idempotent)`);
|
|
196
|
+
return existingGroup;
|
|
244
197
|
}
|
|
198
|
+
// Create a single group with a range of 1 (so we can reuse the batch creation logic) for the
|
|
199
|
+
// given group index.
|
|
200
|
+
const groups = await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createMultichainAccountGroups).call(this, { from: groupIndex, to: groupIndex }, options);
|
|
201
|
+
const group = groups[0];
|
|
202
|
+
(0, utils_1.assert)(group, `Expected group at index ${groupIndex} to exist`);
|
|
245
203
|
return group;
|
|
246
204
|
});
|
|
247
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Creates multiple multichain account groups up to maxGroupIndex.
|
|
208
|
+
*
|
|
209
|
+
* NOTE: This operation WILL lock the wallet's mutex.
|
|
210
|
+
*
|
|
211
|
+
* @param range - The range of group indices to create.
|
|
212
|
+
* @param range.from - Starting group index to create (inclusive) (defaults to 0).
|
|
213
|
+
* @param range.to - Maximum group index to create (inclusive).
|
|
214
|
+
* @param options - Options to configure the account creation.
|
|
215
|
+
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
|
|
216
|
+
* account providers to finish creating their accounts before returning. If `false`, only
|
|
217
|
+
* the EVM provider is used and non-EVM account creation is deferred via
|
|
218
|
+
* {@link MultichainAccountWallet.alignAccounts}. Defaults to false.
|
|
219
|
+
* @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).
|
|
220
|
+
* @returns Array of created multichain account groups.
|
|
221
|
+
*/
|
|
222
|
+
async createMultichainAccountGroups({ from = 0, to }, options = {}) {
|
|
223
|
+
// Use this to avoid having it as `boolean | undefined`.
|
|
224
|
+
const waitForAllProvidersToFinishCreatingAccounts = options.waitForAllProvidersToFinishCreatingAccounts ?? false;
|
|
225
|
+
return await __classPrivateFieldGet(this, _MultichainAccountWallet_trace, "f").call(this, {
|
|
226
|
+
name: analytics_1.TraceName.WalletCreateMultichainAccountGroups,
|
|
227
|
+
data: {
|
|
228
|
+
from,
|
|
229
|
+
to,
|
|
230
|
+
waitForAllProvidersToFinishCreatingAccounts,
|
|
231
|
+
},
|
|
232
|
+
}, async () => await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createMultichainAccountGroups).call(this, { from, to }, options));
|
|
233
|
+
}
|
|
248
234
|
/**
|
|
249
235
|
* Creates the next multichain account group.
|
|
250
236
|
*
|
|
@@ -262,9 +248,14 @@ class MultichainAccountWallet {
|
|
|
262
248
|
* NOTE: This operation WILL lock the wallet's mutex.
|
|
263
249
|
*/
|
|
264
250
|
async alignAccounts() {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
251
|
+
const nextGroupIndex = this.getNextGroupIndex();
|
|
252
|
+
if (nextGroupIndex > 0) {
|
|
253
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Aligning accounts...');
|
|
254
|
+
const from = 0;
|
|
255
|
+
const to = nextGroupIndex - 1;
|
|
256
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:alignment', async () => await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccountsForRange).call(this, { from, to }, __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")));
|
|
257
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Aligned!');
|
|
258
|
+
}
|
|
268
259
|
}
|
|
269
260
|
/**
|
|
270
261
|
* Align a specific multichain account group.
|
|
@@ -274,12 +265,12 @@ class MultichainAccountWallet {
|
|
|
274
265
|
* @param groupIndex - The group index to align.
|
|
275
266
|
*/
|
|
276
267
|
async alignAccountsOf(groupIndex) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
}
|
|
268
|
+
const group = this.getMultichainAccountGroup(groupIndex);
|
|
269
|
+
if (group) {
|
|
270
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Aligning accounts for group "${group.id}"...`);
|
|
271
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:alignment', async () => await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccountsForRange).call(this, { from: groupIndex, to: groupIndex }, __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"), { trace: { data: { groupIndex } } }));
|
|
272
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Aligned accounts for group "${group.id}"!`);
|
|
273
|
+
}
|
|
283
274
|
}
|
|
284
275
|
/**
|
|
285
276
|
* Discover and create accounts for all providers.
|
|
@@ -316,13 +307,11 @@ class MultichainAccountWallet {
|
|
|
316
307
|
}
|
|
317
308
|
catch (error) {
|
|
318
309
|
context.stopped = true;
|
|
319
|
-
|
|
320
|
-
(0,
|
|
321
|
-
const sentryError = (0, utils_2.createSentryError)('Unable to discover accounts', error, {
|
|
310
|
+
(0, logger_1.projectLogger)(message(`failed (with: "${(0, utils_2.toErrorMessage)(error)}")`, targetGroupIndex));
|
|
311
|
+
(0, errors_1.reportError)(__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"), `Unable to discover accounts with provider "${providerName}"`, error, {
|
|
322
312
|
provider: providerName,
|
|
323
313
|
groupIndex: targetGroupIndex,
|
|
324
314
|
});
|
|
325
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
|
|
326
315
|
break;
|
|
327
316
|
}
|
|
328
317
|
if (!accounts.length) {
|
|
@@ -362,13 +351,22 @@ class MultichainAccountWallet {
|
|
|
362
351
|
}
|
|
363
352
|
// Align missing accounts from group. This is required to create missing account from non-discovered
|
|
364
353
|
// indexes for some providers.
|
|
365
|
-
|
|
354
|
+
const nextGroupIndex = this.getNextGroupIndex();
|
|
355
|
+
if (nextGroupIndex > 0) {
|
|
356
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccountsForRange).call(this, { from: 0, to: nextGroupIndex - 1 }, __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"), {
|
|
357
|
+
trace: {
|
|
358
|
+
data: {
|
|
359
|
+
discovery: true, // Tag to identify discovery-alignment traces in analytics.
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
366
364
|
return providerContexts.flatMap((context) => context.accounts);
|
|
367
365
|
});
|
|
368
366
|
}
|
|
369
367
|
}
|
|
370
368
|
exports.MultichainAccountWallet = MultichainAccountWallet;
|
|
371
|
-
_MultichainAccountWallet_lock = new WeakMap(), _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accountGroups = new WeakMap(), _MultichainAccountWallet_messenger = new WeakMap(), _MultichainAccountWallet_log = new WeakMap(), _MultichainAccountWallet_initialized = new WeakMap(), _MultichainAccountWallet_status = new WeakMap(), _MultichainAccountWallet_instances = new WeakSet(), _MultichainAccountWallet_withLock =
|
|
369
|
+
_MultichainAccountWallet_lock = new WeakMap(), _MultichainAccountWallet_id = new WeakMap(), _MultichainAccountWallet_providers = new WeakMap(), _MultichainAccountWallet_entropySource = new WeakMap(), _MultichainAccountWallet_accountGroups = new WeakMap(), _MultichainAccountWallet_messenger = new WeakMap(), _MultichainAccountWallet_trace = new WeakMap(), _MultichainAccountWallet_log = new WeakMap(), _MultichainAccountWallet_initialized = new WeakMap(), _MultichainAccountWallet_status = new WeakMap(), _MultichainAccountWallet_instances = new WeakSet(), _MultichainAccountWallet_withLock =
|
|
372
370
|
/**
|
|
373
371
|
* Set the wallet status and run the associated operation callback.
|
|
374
372
|
*
|
|
@@ -391,94 +389,234 @@ async function _MultichainAccountWallet_withLock(status, operation) {
|
|
|
391
389
|
release();
|
|
392
390
|
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Releasing wallet lock (was "${status}")`);
|
|
393
391
|
}
|
|
394
|
-
},
|
|
392
|
+
}, _MultichainAccountWallet_getProviders = function _MultichainAccountWallet_getProviders() {
|
|
393
|
+
const [evmProvider, ...otherProviders] = __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f");
|
|
394
|
+
(0, utils_1.assert)(evmProvider instanceof EvmAccountProvider_1.EvmAccountProvider, 'EVM account provider must be first');
|
|
395
|
+
return [evmProvider, ...otherProviders];
|
|
396
|
+
}, _MultichainAccountWallet_createAccountsRangeForProvider =
|
|
395
397
|
/**
|
|
396
|
-
* Create accounts
|
|
397
|
-
* When awaitAll is true, waits for all providers and throws if any failed.
|
|
398
|
-
* When false, starts work in background and logs errors without throwing.
|
|
398
|
+
* Create accounts for a given provider and group index range.
|
|
399
399
|
*
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @
|
|
404
|
-
* @param options.group - The group object pertaining to the group index to create accounts for.
|
|
405
|
-
* @throws If awaitAll is true and any provider fails to create accounts.
|
|
406
|
-
* @returns A promise that resolves when done (if awaitAll is true) or immediately (if false).
|
|
400
|
+
* @param provider - The provider to create accounts for.
|
|
401
|
+
* @param from - The starting group index (inclusive).
|
|
402
|
+
* @param to - The ending group index (inclusive).
|
|
403
|
+
* @returns The created accounts.
|
|
407
404
|
*/
|
|
408
|
-
async function
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
type: keyring_api_1.AccountCreationType.
|
|
405
|
+
async function _MultichainAccountWallet_createAccountsRangeForProvider(provider, from, to) {
|
|
406
|
+
const isBatching = to > from;
|
|
407
|
+
try {
|
|
408
|
+
return await provider.createAccounts({
|
|
409
|
+
type: keyring_api_1.AccountCreationType.Bip44DeriveIndexRange,
|
|
413
410
|
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (providerFailures.length) {
|
|
433
|
-
// We warn there's failures on some providers and thus misalignment, but we still create the group
|
|
434
|
-
const message = `Unable to create some accounts for group index: ${groupIndex}. Providers threw the following errors:${providerFailures}`;
|
|
435
|
-
console.warn(message);
|
|
436
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${message}`);
|
|
437
|
-
}
|
|
438
|
-
// No need to fetch the accounts list from the AccountsController since we already have the account IDs to be used in the controller
|
|
439
|
-
const groupState = results.reduce((state, result, idx) => {
|
|
440
|
-
if (result.status === 'fulfilled') {
|
|
441
|
-
state[providers[idx].getName()] = result.value.map((account) => account.id);
|
|
442
|
-
}
|
|
443
|
-
return state;
|
|
444
|
-
}, {});
|
|
411
|
+
range: {
|
|
412
|
+
from,
|
|
413
|
+
to,
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
(0, errors_1.reportError)(__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"), `Unable to create ${isBatching ? 'some accounts (batch)' : 'some accounts'} with provider "${provider.getName()}"`, error, {
|
|
419
|
+
range: { from, to },
|
|
420
|
+
provider: provider.getName(),
|
|
421
|
+
isBatching,
|
|
422
|
+
});
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
}, _MultichainAccountWallet_createOrUpdateMultichainAccountGroup = function _MultichainAccountWallet_createOrUpdateMultichainAccountGroup(groupIndex, groupState) {
|
|
426
|
+
let group = __classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").get(groupIndex);
|
|
427
|
+
if (group) {
|
|
428
|
+
// NOTE: This will publish an update event automatically.
|
|
445
429
|
group.update(groupState);
|
|
430
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Group updated: [${group.id}]`);
|
|
446
431
|
}
|
|
447
432
|
else {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
entropySource: __classPrivateFieldGet(this, _MultichainAccountWallet_entropySource, "f"),
|
|
454
|
-
groupIndex,
|
|
455
|
-
})
|
|
456
|
-
.then((accounts) => {
|
|
457
|
-
const accountIds = accounts.map((account) => account.id);
|
|
458
|
-
group.update({ [provider.getName()]: accountIds });
|
|
459
|
-
return group;
|
|
460
|
-
})
|
|
461
|
-
.catch((error) => {
|
|
462
|
-
// Log errors from background providers but don't fail the operation
|
|
463
|
-
const errorMessage = `Unable to create some accounts for group index: ${groupIndex} with provider "${provider.getName()}". Error: ${error.message}`;
|
|
464
|
-
console.warn(errorMessage);
|
|
465
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${errorMessage}:`, error);
|
|
466
|
-
const sentryError = (0, utils_2.createSentryError)(`Unable to create account with provider "${provider.getName()}"`, error, {
|
|
467
|
-
groupIndex,
|
|
468
|
-
provider: provider.getName(),
|
|
469
|
-
});
|
|
470
|
-
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").captureException?.(sentryError);
|
|
471
|
-
});
|
|
433
|
+
group = new MultichainAccountGroup_1.MultichainAccountGroup({
|
|
434
|
+
wallet: this,
|
|
435
|
+
providers: __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f"),
|
|
436
|
+
groupIndex,
|
|
437
|
+
messenger: __classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f"),
|
|
472
438
|
});
|
|
439
|
+
group.init(groupState);
|
|
440
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_accountGroups, "f").set(groupIndex, group);
|
|
441
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Group created: [${group.id}]`);
|
|
442
|
+
if (__classPrivateFieldGet(this, _MultichainAccountWallet_initialized, "f")) {
|
|
443
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_messenger, "f").publish('MultichainAccountService:multichainAccountGroupCreated', group);
|
|
444
|
+
}
|
|
473
445
|
}
|
|
474
|
-
|
|
446
|
+
return group;
|
|
447
|
+
}, _MultichainAccountWallet_buildGroupStateForRange =
|
|
475
448
|
/**
|
|
476
|
-
*
|
|
449
|
+
* Build group state for a range of group indices by calling all providers in parallel.
|
|
450
|
+
*
|
|
451
|
+
* This is a non-locking shared core used by both creation and alignment paths.
|
|
477
452
|
*
|
|
478
|
-
*
|
|
453
|
+
* @param from - Starting group index (inclusive).
|
|
454
|
+
* @param to - Ending group index (inclusive).
|
|
455
|
+
* @param providers - The providers to create accounts for.
|
|
456
|
+
* @returns The collected group state and any provider failure messages.
|
|
479
457
|
*/
|
|
480
|
-
async function
|
|
481
|
-
const
|
|
482
|
-
await Promise.
|
|
458
|
+
async function _MultichainAccountWallet_buildGroupStateForRange(from, to, providers) {
|
|
459
|
+
const groupStateByGroupIndex = new Map();
|
|
460
|
+
const results = await Promise.allSettled(providers.map(async (provider) => {
|
|
461
|
+
const providerName = provider.getName();
|
|
462
|
+
const accounts = await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createAccountsRangeForProvider).call(this, provider, from, to);
|
|
463
|
+
accounts.forEach((account) => {
|
|
464
|
+
const { groupIndex } = account.options.entropy;
|
|
465
|
+
let groupState = groupStateByGroupIndex.get(groupIndex);
|
|
466
|
+
if (!groupState) {
|
|
467
|
+
groupState = {};
|
|
468
|
+
groupStateByGroupIndex.set(groupIndex, groupState);
|
|
469
|
+
}
|
|
470
|
+
if (!groupState[providerName]) {
|
|
471
|
+
groupState[providerName] = [];
|
|
472
|
+
}
|
|
473
|
+
groupState[providerName].push(account.id);
|
|
474
|
+
});
|
|
475
|
+
}));
|
|
476
|
+
const failures = providers.reduce((messages, provider, index) => {
|
|
477
|
+
const result = results[index];
|
|
478
|
+
if (result?.status === 'rejected') {
|
|
479
|
+
messages.push(`[${provider.getName()}] ${(0, utils_2.toErrorMessage)(result.reason)}`);
|
|
480
|
+
}
|
|
481
|
+
return messages;
|
|
482
|
+
}, []);
|
|
483
|
+
return { groupStateByGroupIndex, failures };
|
|
484
|
+
}, _MultichainAccountWallet_createMultichainAccountGroupsRange =
|
|
485
|
+
/**
|
|
486
|
+
* Internal method to create a range of multichain account groups.
|
|
487
|
+
*
|
|
488
|
+
* This method acquires the wallet lock internally and creates accounts for all
|
|
489
|
+
* given providers synchronously. Callers decide which providers to pass.
|
|
490
|
+
*
|
|
491
|
+
* @param range - The range of group indices to create.
|
|
492
|
+
* @param range.from - Starting group index to create (inclusive).
|
|
493
|
+
* @param range.to - Maximum group index to create (inclusive).
|
|
494
|
+
* @param providers - The providers to create accounts for.
|
|
495
|
+
* @returns Array of created multichain account groups.
|
|
496
|
+
*/
|
|
497
|
+
async function _MultichainAccountWallet_createMultichainAccountGroupsRange({ from: rangeFrom, to }, providers) {
|
|
498
|
+
return await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:create-accounts', async () => {
|
|
499
|
+
const groups = [];
|
|
500
|
+
// Get existing groups (fromGroupIndex to nextGroupIndex - 1).
|
|
501
|
+
let from = rangeFrom;
|
|
502
|
+
for (; from <= to; from++) {
|
|
503
|
+
const group = this.getMultichainAccountGroup(from);
|
|
504
|
+
if (group) {
|
|
505
|
+
groups.push(group);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
break; // Assuming we have no gap, if the group does not exist, we can stop and create the remaining ones.
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// Create new groups now.
|
|
512
|
+
if (from <= to) {
|
|
513
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Creating groups from index ${from} to ${to}...`);
|
|
514
|
+
const { groupStateByGroupIndex, failures } = await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_buildGroupStateForRange).call(this, from, to, providers);
|
|
515
|
+
// Check for provider failures — always treated as hard errors.
|
|
516
|
+
if (failures.length) {
|
|
517
|
+
throw new Error(failures.reduce((message, failure) => `${message}\n- ${failure}`, 'Unable to create some accounts. Providers threw the following errors:'));
|
|
518
|
+
}
|
|
519
|
+
// Create or update groups from the collected state.
|
|
520
|
+
for (let groupIndex = from; groupIndex <= to; groupIndex++) {
|
|
521
|
+
const groupState = groupStateByGroupIndex.get(groupIndex);
|
|
522
|
+
if (groupState) {
|
|
523
|
+
const group = __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createOrUpdateMultichainAccountGroup).call(this, groupIndex, groupState);
|
|
524
|
+
groups.push(group);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} Failed to create new group for group index: ${groupIndex} because no accounts were created for it`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return groups;
|
|
532
|
+
});
|
|
533
|
+
}, _MultichainAccountWallet_alignAccountsForRange =
|
|
534
|
+
/**
|
|
535
|
+
* Align accounts for a range of group indices (non-locking).
|
|
536
|
+
*
|
|
537
|
+
* Calls all providers in parallel via the batch API. Provider failures are
|
|
538
|
+
* logged as warnings (best-effort); no error is thrown.
|
|
539
|
+
*
|
|
540
|
+
* @param range - The range of group indices to align.
|
|
541
|
+
* @param range.from - Starting group index (inclusive).
|
|
542
|
+
* @param range.to - Ending group index (inclusive).
|
|
543
|
+
* @param providers - The providers to align accounts for.
|
|
544
|
+
* @param options - Options.
|
|
545
|
+
* @param options.trace - Trace options.
|
|
546
|
+
* @param options.trace.data - Optional trace data.
|
|
547
|
+
*/
|
|
548
|
+
async function _MultichainAccountWallet_alignAccountsForRange({ from, to }, providers, options = {}) {
|
|
549
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_trace, "f").call(this, {
|
|
550
|
+
name: analytics_1.TraceName.WalletAlignment,
|
|
551
|
+
data: {
|
|
552
|
+
from,
|
|
553
|
+
to,
|
|
554
|
+
...(0, analytics_1.toProviderDataTraces)(providers),
|
|
555
|
+
...options.trace?.data,
|
|
556
|
+
},
|
|
557
|
+
}, async () => {
|
|
558
|
+
const { groupStateByGroupIndex, failures } = await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_buildGroupStateForRange).call(this, from, to, providers);
|
|
559
|
+
if (failures.length) {
|
|
560
|
+
const error = failures.reduce((message, failure) => `${message}\n- ${failure}`, 'Unable to align some accounts. Providers threw the following errors:');
|
|
561
|
+
console.warn(error);
|
|
562
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.WARNING_PREFIX} ${error}`);
|
|
563
|
+
}
|
|
564
|
+
for (let groupIndex = from; groupIndex <= to; groupIndex++) {
|
|
565
|
+
const groupState = groupStateByGroupIndex.get(groupIndex);
|
|
566
|
+
if (groupState) {
|
|
567
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createOrUpdateMultichainAccountGroup).call(this, groupIndex, groupState);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}, _MultichainAccountWallet_createMultichainAccountGroups =
|
|
572
|
+
/**
|
|
573
|
+
* Creates multiple multichain account groups up to maxGroupIndex.
|
|
574
|
+
*
|
|
575
|
+
* NOTE: This operation WILL lock the wallet's mutex.
|
|
576
|
+
*
|
|
577
|
+
* @param range - The range of group indices to create.
|
|
578
|
+
* @param range.from - Starting group index to create (inclusive).
|
|
579
|
+
* @param range.to - Maximum group index to create (inclusive).
|
|
580
|
+
* @param options - Options to configure the account creation.
|
|
581
|
+
* @param options.waitForAllProvidersToFinishCreatingAccounts - Whether to wait for all
|
|
582
|
+
* account providers to finish creating their accounts before returning. If `false`, only
|
|
583
|
+
* the EVM provider is used and non-EVM account creation is deferred via
|
|
584
|
+
* {@link MultichainAccountWallet.alignAccounts}. Defaults to false.
|
|
585
|
+
* @throws If range is invalid (e.g. from is greater than to, from or to is negative, etc.).
|
|
586
|
+
* @returns Array of created multichain account groups.
|
|
587
|
+
*/
|
|
588
|
+
async function _MultichainAccountWallet_createMultichainAccountGroups({ from, to }, options) {
|
|
589
|
+
(0, utils_2.assertGroupIndexRangeIsValid)({ from, to });
|
|
590
|
+
(0, utils_2.assertGroupIndexIsValid)(from, this.getNextGroupIndex());
|
|
591
|
+
const waitForAllProvidersToFinishCreatingAccounts = options.waitForAllProvidersToFinishCreatingAccounts ?? false;
|
|
592
|
+
const [evmProvider, ...otherProviders] = __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_getProviders).call(this);
|
|
593
|
+
const providers = waitForAllProvidersToFinishCreatingAccounts
|
|
594
|
+
? __classPrivateFieldGet(this, _MultichainAccountWallet_providers, "f")
|
|
595
|
+
: [evmProvider];
|
|
596
|
+
const groups = await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_createMultichainAccountGroupsRange).call(this, { from, to }, providers);
|
|
597
|
+
// We need to run a post-alignment since non-EVM accounts have not
|
|
598
|
+
// been created yet.
|
|
599
|
+
if (!waitForAllProvidersToFinishCreatingAccounts) {
|
|
600
|
+
const alignOtherAccounts = async () => {
|
|
601
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `Aligning accounts... (post)`);
|
|
602
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_withLock).call(this, 'in-progress:alignment', async () => {
|
|
603
|
+
await __classPrivateFieldGet(this, _MultichainAccountWallet_instances, "m", _MultichainAccountWallet_alignAccountsForRange).call(this, { from, to }, otherProviders, {
|
|
604
|
+
trace: {
|
|
605
|
+
data: {
|
|
606
|
+
post: true, // Tag to identify post-alignment traces in analytics.
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, 'Aligned accounts! (post)');
|
|
612
|
+
};
|
|
613
|
+
// eslint-disable-next-line no-void
|
|
614
|
+
void alignOtherAccounts().catch((error) => {
|
|
615
|
+
const errorMessage = `Unable to align non-EVM accounts from group index ${from} to ${to}`;
|
|
616
|
+
__classPrivateFieldGet(this, _MultichainAccountWallet_log, "f").call(this, `${logger_1.ERROR_PREFIX} ${errorMessage}: ${(0, utils_2.toErrorMessage)(error)} (post)`);
|
|
617
|
+
console.error(errorMessage, error);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return groups;
|
|
483
621
|
};
|
|
484
622
|
//# sourceMappingURL=MultichainAccountWallet.cjs.map
|