Skip to content

Commit f881be2

Browse files
authored
SIP-28: Background Events (#150)
* SIP-28: Background Events * Changes after code-review * Changes after code-review * Merged endowment:background-events and endowment:cronjob
1 parent d5ef36d commit f881be2

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

SIPS/sip-28.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
sip: 28
3+
title: Background Events
4+
status: Draft
5+
author: Olaf Tomalka (@ritave)
6+
created: 2024-10-09
7+
---
8+
9+
## Abstract
10+
11+
This SIP introduces a way to schedule non-recurring events in the future.
12+
13+
## Motivation
14+
15+
Scheduled recurring events are already supported in the Snaps platform via the Cronjobs feature. By introducing non-recurring events we will allow novel use-cases for Snap developers, such as allowing a snap that sets a reminder for ENS domain expiration date.
16+
17+
## Specification
18+
19+
> Indented sections like this are considered non-normative.
20+
21+
### Language
22+
23+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
24+
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
25+
"OPTIONAL" written in uppercase in this document are to be interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt)
26+
27+
### Snap Manifest
28+
29+
This SIP doesn't introduce any new permissions, but rather extends `endowment:cronjob` with new capabilities through two new RPC methods.
30+
31+
### RPC Methods
32+
33+
#### `snap_scheduleBackgroundEvent`
34+
35+
This method allows a Snap to schedule a one-off callback to `onCronjob` handler in the future with a JSON-RPC request object as a parameter.
36+
37+
```typescript
38+
type ScheduleBackgroundEventParams = {
39+
date: string;
40+
request: JsonRpcRequest;
41+
};
42+
43+
type ScheduleBackgroundEventResult = string;
44+
```
45+
46+
The RPC method takes two parameters:
47+
48+
- `date` - An [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time and optional timezone offset.
49+
- The time's precision SHALL be truncated on the extension side to minutes.
50+
- If no timezone is provided, the time SHALL be understood to be local-time.
51+
> Use ISO's `Z` identifier if you want to use UTC time.
52+
- `request` - A JSON object that will provided as-is to `onCronjob` handler as parameter.
53+
54+
An example of usage is given below.
55+
56+
```typescript
57+
snap.request({
58+
method: "snap_scheduleBackgroundEvent",
59+
params: {
60+
date: "2024-10-09T09:59",
61+
request: {
62+
method: "foobar",
63+
params: {
64+
foo: "bar",
65+
},
66+
},
67+
},
68+
});
69+
```
70+
71+
The RPC method call returns a `string` that is a unique ID representing that specific background event, allowing it to be cancelled.
72+
73+
#### `snap_cancelBackgroundEvent`
74+
75+
This method allows to cancel an already scheduled background event using the unique ID returned from `snap_backgroundEventSchedule`
76+
77+
```typescript
78+
type CancelBackgroundEventParams = { id: string };
79+
```
80+
81+
This RPC method takes one argument:
82+
83+
- `id` - The id that was returned during schedule.
84+
85+
An example of usage is given below.
86+
87+
```typescript
88+
snap.request({
89+
method: "snap_cancelBackgroundEvent",
90+
params: {
91+
id: myReturnedId,
92+
},
93+
});
94+
```
95+
96+
### `onCronjob` handler
97+
98+
This SIP doesn't modify `onCronjob` handler in any way.
99+
100+
## Copyright
101+
102+
Copyright and related rights waived via [CC0](../LICENSE).

0 commit comments

Comments
 (0)