You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
51
51
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`.
53
57
54
58
###### Parameters
55
59
| Name | Type | Description |
@@ -188,27 +192,27 @@ Removes the currently used money handler. This has the same effect as if [`regis
188
192
189
193
If no money handler is currently set, this method does nothing.
190
194
191
-
## Class: PluginOptions
192
-
<code>class PluginOptions</code>
195
+
## Class: PluginServices
196
+
<code>class PluginServices</code>
193
197
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.
Provides callback hooks to the host's persistence layer.
210
214
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`.
212
216
213
217
Method names are based on the popular LevelUP/LevelDOWN packages.
214
218
@@ -230,13 +234,47 @@ Method names are based on the popular LevelUP/LevelDOWN packages.
230
234
}
231
235
```
232
236
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
0 commit comments