@metamask/multichain-account-service
Version:
Service to manage multichain accounts
62 lines • 2.23 kB
JavaScript
/**
* 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.
*/
export const traceFallback = async (_request, fn) => {
if (!fn) {
return undefined;
}
return await Promise.resolve(fn());
};
/**
* 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.
*/
export 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,
}), {});
}
/**
* Compute trace data for `createAccounts` options.
*
* @param options The `createAccounts` options.
* @returns An object containing options data depending on its type.
*/
export 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 {};
}
/**
* Trace names.
*/
export 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 || (TraceName = {}));
//# sourceMappingURL=traces.mjs.map