Skip to content

Commit 4dcfc4f

Browse files
committed
docs(lpi2): add PluginServices and assign final RFC number
1 parent 26cf939 commit 4dcfc4f

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

0000-ledger-plugin-interface-2/0000-ledger-plugin-interface-2.md renamed to 0024-ledger-plugin-interface-2/0024-ledger-plugin-interface-2.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To send ILP payments through a new ledger, one must implement a ledger plugin th
1818
###### Methods
1919
| | Name |
2020
|:--|:--|
21-
| `new` | [**LedgerPlugin**](#new-ledgerplugin) ( opts ) |
21+
| `new` | [**LedgerPlugin**](#new-ledgerplugin) ( opts, api ) |
2222
| | [**connect**](#ledgerpluginconnect) ( options ) `⇒ Promise.<undefined>` |
2323
| | [**disconnect**](#ledgerplugindisconnect) ( ) `⇒ Promise.<undefined>` |
2424
| | [**isConnected**](#ledgerpluginisconnected) ( ) `⇒ Boolean` |
@@ -45,11 +45,15 @@ To send ILP payments through a new ledger, one must implement a ledger plugin th
4545
### Instance Management
4646

4747
#### new LedgerPlugin
48-
<code>new LedgerPlugin( **opts** : [PluginOptions](#class-pluginoptions) )</code>
48+
<code>new LedgerPlugin( **opts** : object, **api**? : [PluginServices](#class-pluginservices) )</code>
4949

5050
Create a new instance of the plugin. Each instance typically corresponds to a different ledger. However, some plugins MAY deviate from a strict one-to-one relationship and MAY internally act as a virtual connector to more than one counterparty.
5151

52-
Throws `InvalidFieldsError` if the constructor is given incorrect arguments.
52+
The first parameter `opts` is a configuration object the shape of which is specific to each plugin. Plugins will often be configured through environment variables, so it is recommended that the `opts` SHOULD be JSON serializable. However, plugins MAY use non-serializable values to offer advanced features.
53+
54+
The second parameter `api` is optional and is used to pass additional environment services to the plugin, such as a logger or a key-value store. Most plugins SHOULD work even if this parameter is `undefined`, but MAY offer less functionality in that case (e.g. no persistence.)
55+
56+
Throws `InvalidFieldsError` if the constructor is given incorrect arguments in `opts`. Throws `TypeError` if `opts` is not an object or `api` is defined and not an object. Throws `InvalidServicesError` if a service is required, but not provided via `api`.
5357

5458
###### Parameters
5559
| Name | Type | Description |
@@ -188,27 +192,27 @@ Removes the currently used money handler. This has the same effect as if [`regis
188192

189193
If no money handler is currently set, this method does nothing.
190194

191-
## Class: PluginOptions
192-
<code>class PluginOptions</code>
195+
## Class: PluginServices
196+
<code>class PluginServices</code>
193197

194-
Plugin options are passed in to the [`LedgerPlugin`](#class-ledgerplugin)
195-
constructor when a plugin is being instantiated. The fields are ledger
196-
specific. Any fields which cannot be represented as strings are preceded with
197-
an underscore, and listed in the table below.
198+
Plugin services are optionally passed in to the [`LedgerPlugin`](#class-ledgerplugin)
199+
constructor when a plugin is being instantiated. Which services are provided
200+
MAY vary based on the host environment or none MAY be available at all.
198201

199202
###### Special Fields
200203
| Type | Name | Description |
201204
|:--|:--|:--|
202-
| `Object` | [_store](#pluginoptions-_store) | Persistence layer callbacks |
205+
| `Object` | [store](#pluginservices-store) | Simple key-value store object |
206+
| `Object` | [log](#pluginservices-log) | Simple logger object |
203207

204208
### Fields
205209

206-
#### PluginOptions#_store
207-
<code>**_store**:Object</code>
210+
#### PluginServices#store
211+
<code>**store**:Object</code>
208212

209213
Provides callback hooks to the host's persistence layer.
210214

211-
Persistence MAY be required for internal use by some ledger plugins. For this purpose hosts MAY be configured with a persistence layer.
215+
Most plugins SHOULD work (possibly with higher trust or degraded experience) without a `store`. However, if a plugin is not able to function without a store and none is provided, the constructor MUST throw an `InvalidServicesError`.
212216

213217
Method names are based on the popular LevelUP/LevelDOWN packages.
214218

@@ -230,13 +234,47 @@ Method names are based on the popular LevelUP/LevelDOWN packages.
230234
}
231235
```
232236

237+
#### PluginServices#log
238+
<code>**log**:Object</code>
239+
240+
Provides logging hooks to the host. Hosts MAY use this feature to prefix log lines with the identifier of the plugin instance.
241+
242+
If this parameter is not provided, the plugin SHOULD use a suitable default logging mechanism.
243+
244+
The logging methods support [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. The following formatters are available:
245+
246+
| Formatter | Representation |
247+
|-----------|----------------|
248+
| `%O` | Pretty-print an Object on multiple lines. |
249+
| `%o` | Pretty-print an Object all on a single line. |
250+
| `%s` | String. |
251+
| `%d` | Number (both integer and float). |
252+
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
253+
| `%%` | Single percent sign ('%'). This does not consume an argument. |
254+
255+
Log messages MUST NOT contain private keys or other credentials.
256+
257+
###### Example
258+
```js
259+
{
260+
// Extremely verbose debug information
261+
debug: (message, ...params) => { }
262+
// Notable events that may happen during normal operation
263+
info: (message, ...params) => { }
264+
// Warnings indicate unusual events that call for the user's attention
265+
warn: (message, ...params) => { }
266+
// Errors indicate something went wrong
267+
error: (message, ...params) => { }
268+
}
269+
```
270+
233271
## Class: ConnectOptions
234272
<code>class ConnectOptions</code>
235273

236274
###### Fields
237275
| Type | Name | Description |
238276
|:--|:--|:--|
239-
| `Number` | [timeout](#connectoptions-timeout) | milliseconds |
277+
| `Number` | [timeout](#connectoptions-timeout) | Amount of time before the client SHOULD give up trying to connect (in milliseconds) |
240278

241279
### Fields
242280

0 commit comments

Comments
 (0)