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