UNPKG

@metamask/multichain-account-service

Version:
68 lines 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TraceName = exports.toCreateAccountsV2DataTraces = exports.toProviderDataTraces = exports.traceFallback = void 0; /** * Fallback function for tracing. * This function is used when no specific trace function is provided. * It executes the provided function in a trace context if available. * * @param _request - The trace request containing additional data and context. * @param fn - The function to execute within the trace context. * @returns A promise that resolves to the result of the executed function. * If no function is provided, it resolves to undefined. */ const traceFallback = async (_request, fn) => { if (!fn) { return undefined; } return await Promise.resolve(fn()); }; exports.traceFallback = traceFallback; /** * Compute trace data for a list of providers. * * @param providers Providers to be included in the trace data. * @returns An object mapping provider names to true, indicating their presence in the trace. */ function toProviderDataTraces(providers) { // We cannot use complex objects within traces, so we just map provider names with true. return providers.reduce((data, provider) => ({ ...data, [provider.getName()]: true, }), {}); } exports.toProviderDataTraces = toProviderDataTraces; /** * Compute trace data for `createAccounts` options. * * @param options The `createAccounts` options. * @returns An object containing options data depending on its type. */ function toCreateAccountsV2DataTraces(options) { if (options.type === 'bip44:derive-index') { return { groupIndex: options.groupIndex, }; } else if (options.type === 'bip44:derive-index-range') { return { from: options.range.from, to: options.range.to, }; } return {}; } exports.toCreateAccountsV2DataTraces = toCreateAccountsV2DataTraces; /** * Trace names. */ var TraceName; (function (TraceName) { TraceName["SnapDiscoverAccounts"] = "Snap Discover Accounts"; TraceName["EvmDiscoverAccounts"] = "EVM Discover Accounts"; TraceName["ProviderCreateAccounts"] = "Provider Create Accounts (v2 - batched)"; TraceName["WalletAlignment"] = "Wallet Alignment"; TraceName["WalletCreateMultichainAccountGroup"] = "Wallet Create Multichain Account Group"; TraceName["WalletCreateMultichainAccountGroups"] = "Wallet Create Multichain Account Groups"; })(TraceName || (exports.TraceName = TraceName = {})); //# sourceMappingURL=traces.cjs.map