Skip to content

Commit 69953bc

Browse files
committed
plugin: Document JSON-RPC passthrough and notifications
Signed-off-by: Christian Decker <decker.christian@gmail.com>
1 parent 26f17e8 commit 69953bc

File tree

1 file changed

+99
-3
lines changed

1 file changed

+99
-3
lines changed

doc/plugins.md

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ this example:
7878
"description": "Returns the current time in {timezone}",
7979
"long_description": "Returns the current time in the timezone that is given as the only parameter.\nThis description may be quite long and is allowed to span multiple lines."
8080
}
81+
],
82+
"subscriptions": [
83+
"connect",
84+
"disconnect"
8185
]
8286
}
8387
```
@@ -109,8 +113,12 @@ simple JSON object containing the options:
109113

110114
```json
111115
{
112-
"objects": {
116+
"options": {
113117
"greeting": "World"
118+
},
119+
"configuration": {
120+
"lightning-dir": "/home/user/.lightning",
121+
"rpc-file": "lightning-rpc"
114122
}
115123
}
116124
```
@@ -120,10 +128,98 @@ arbitrary and will currently be discarded by `lightningd`. JSON-RPC
120128
commands were chosen over notifications in order not to force plugins
121129
to implement notifications which are not that well supported.
122130

123-
## Event stream subscriptions
131+
## JSON-RPC passthrough
124132

125-
*TBD*
133+
Plugins may register their own JSON-RPC methods that are exposed
134+
through the JSON-RPC provided by `lightningd`. This provides users
135+
with a single interface to interact with, while allowing the addition
136+
of custom methods without having to modify the daemon itself.
137+
138+
JSON-RPC methods are registered as part of the `getmanifest`
139+
result. Each registered method must provide a `name` and a
140+
`description`. An optional `long_description` may also be
141+
provided. This information is then added to the internal dispatch
142+
table, and used to return the help text when using `lightning-cli
143+
help`, and the methods can be called using the `name`.
144+
145+
For example the above `getmanifest` result will register two methods,
146+
called `hello` and `gettime`:
147+
148+
```json
149+
...
150+
"rpcmethods": [
151+
{
152+
"name": "hello",
153+
"description": "Returns a personalized greeting for {greeting} (set via options)."
154+
},
155+
{
156+
"name": "gettime",
157+
"description": "Returns the current time in {timezone}",
158+
"long_description": "Returns the current time in the timezone that is given as the only parameter.\nThis description may be quite long and is allowed to span multiple lines."
159+
}
160+
],
161+
...
162+
```
163+
164+
The RPC call will be passed through unmodified, with the exception of
165+
the JSON-RPC call `id`, which is internally remapped to a unique
166+
integer instead, in order to avoid collisions. When passing the result
167+
back the `id` field is restored to its original value.
168+
169+
## Event notifications
126170

171+
Event notifications allow a plugin to subscribe to events in
172+
`lightningd`. `lightningd` will then send a push notification if an
173+
event matching the subscription occurred. A notification is defined in
174+
the JSON-RPC [specification][jsonrpc-spec] as an RPC call that does
175+
not include an `id` parameter:
176+
177+
> A Notification is a Request object without an "id" member. A Request
178+
> object that is a Notification signifies the Client's lack of
179+
> interest in the corresponding Response object, and as such no
180+
> Response object needs to be returned to the client. The Server MUST
181+
> NOT reply to a Notification, including those that are within a batch
182+
> request.
183+
>
184+
> Notifications are not confirmable by definition, since they do not
185+
> have a Response object to be returned. As such, the Client would not
186+
> be aware of any errors (like e.g. "Invalid params","Internal
187+
> error").
188+
189+
Plugins subscribe by returning an array of subscriptions as part of
190+
the `getmanifest` response. The result for the `getmanifest` call
191+
above for example subscribes to the two topics `connect` and
192+
`disconnect`. The topics that are currently defined and the
193+
corresponding payloads are listed below.
194+
195+
### Notification Types
196+
197+
#### `connect`
198+
199+
A notification for topic `connect` is sent every time a new connection
200+
to a peer is established.
201+
202+
```json
203+
{
204+
"id": "02f6725f9c1c40333b67faea92fd211c183050f28df32cac3f9d69685fe9665432",
205+
"address": "1.2.3.4"
206+
}
207+
```
208+
209+
#### `disconnect`
210+
211+
A notification for topic `disconnect` is sent every time a connection
212+
to a peer was lost.
213+
214+
```json
215+
{
216+
"id": "02f6725f9c1c40333b67faea92fd211c183050f28df32cac3f9d69685fe9665432"
217+
}
218+
```
127219
## Hooks
128220

129221
*TBD*
222+
223+
224+
[jsonrpc-spec]: https://www.jsonrpc.org/specification
225+
[jsonrpc-notification-spec]: https://www.jsonrpc.org/specification#notification

0 commit comments

Comments
 (0)