UNPKG

@metamask/snaps-rpc-methods

Version:
73 lines 2.32 kB
import { rpcErrors } from "@metamask/rpc-errors"; import { number, create, object, string, StructError, exactOptional } from "@metamask/superstruct"; const hookNames = { endTrace: true, }; const EndTraceParametersStruct = object({ id: exactOptional(string()), name: string(), timestamp: exactOptional(number()), }); /** * End a performance trace in Sentry. This method is only available to * preinstalled Snaps. * * @internal */ export const endTraceHandler = { implementation: getEndTraceImplementation, hookNames, actionNames: ['SnapController:getSnap'], }; /** * The `snap_endTrace` method implementation. This method is used to end a * performance trace in Sentry. It is only available to preinstalled Snaps. * * @param request - The JSON-RPC request object. * @param response - The JSON-RPC response object. * @param _next - The `json-rpc-engine` "next" callback. Not used by this * function. * @param end - The `json-rpc-engine` "end" callback. * @param hooks - The RPC method hooks. * @param hooks.endTrace - The hook function to end a performance trace. * @param messenger - The messenger used to call controller actions. * @returns Nothing. */ function getEndTraceImplementation(request, response, _next, end, { endTrace }, messenger) { const snap = messenger.call('SnapController:getSnap', request.origin); if (!snap?.preinstalled) { return end(rpcErrors.methodNotFound()); } const { params } = request; try { const validatedParams = getValidatedParams(params); endTrace(validatedParams); response.result = null; } catch (error) { return end(error); } return end(); } /** * Validate the parameters for the `snap_endTrace` method. * * @param params - Parameters to validate. * @returns Validated parameters. * @throws Throws RPC error if validation fails. */ function getValidatedParams(params) { try { return create(params, EndTraceParametersStruct); } catch (error) { if (error instanceof StructError) { throw rpcErrors.invalidParams({ message: `Invalid params: ${error.message}.`, }); } /* istanbul ignore next */ throw rpcErrors.internal(); } } //# sourceMappingURL=endTrace.mjs.map