@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
39 lines • 1.42 kB
JavaScript
import { providerErrors } from "@metamask/rpc-errors";
import { SnapEndowments } from "../endowments/index.mjs";
const methodName = 'snap_getBackgroundEvents';
const hookNames = {
getBackgroundEvents: true,
hasPermission: true,
};
export const getBackgroundEventsHandler = {
methodNames: [methodName],
implementation: getGetBackgroundEventsImplementation,
hookNames,
};
/**
* The `snap_getBackgroundEvents` method implementation.
*
* @param _req - The JSON-RPC request object. Not used by this function.
* @param res - 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.getBackgroundEvents - The function to get the background events.
* @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.
* @returns An array of background events.
*/
async function getGetBackgroundEventsImplementation(_req, res, _next, end, { getBackgroundEvents, hasPermission }) {
if (!hasPermission(SnapEndowments.Cronjob)) {
return end(providerErrors.unauthorized());
}
try {
const events = getBackgroundEvents();
res.result = events;
}
catch (error) {
return end(error);
}
return end();
}
//# sourceMappingURL=getBackgroundEvents.mjs.map