clightningjs
C-lightning plugin library for nodejs
Installation
npm install clightningjs --save
Usage
Summary
Methods
A method should take a JSON array as parameter and return either a valid JSON-encodable value :
#!/usr/bin/env nodeconst Plugin = ; const helloPlugin = ; { if !params || paramslength === 0 return 'Hello world'; else return 'Hello ' + params0; } helloPlugin;helloPluginstart;
Or a promise :
#!/usr/bin/env nodeconst Plugin = ; const helloPlugin = ; { return Promise;} helloPlugin;helloPluginstart;
Startup options
You can add a startup option to lightningd
and make a method behave depending on it:
#!/usr/bin/env nodeconst Plugin = ; const helloPlugin = ; { return Promise;} helloPlugin;helloPlugin;helloPluginstart;
Notifications subscription
You can subscribe to lightningd
notifications, the plugin will emit events upon their reception :
#!/usr/bin/env nodeconst fs = ;const Plugin = ; const listenPlugin = ; listenPlugin;listenPluginnotificationswarning; listenPluginstart;
Hooks subscription
You can subscribe to lightningd
hooks :
#!/usr/bin/env nodeconst fs = ;const Plugin = ; const dbBackup = ; { fs; return true;} dbBackup;dbBackupstart;
More
You can restrict RPC control over your plugin with
// myStaticPlugin cannot be stopped by RPCconst myStaticPlugin = dynamic: false ;
You can log to lightningd
logs with myPlugin.log(message, logLevel)
, with the level
defaulting to 'info'.
You can do some stuff at initialization (just before responding to the init
message):
const myPlugin = ;// "params" contains the params passed by `lightningd` along with the `init` messagemyPlugin { myPlugin;};
You can return a promise to a hook or a RPC method callback. This allows to not restrain
the context of an RPC method or a hook result only to the registered callback. Here is an
example from test/hodl.js
which, well, hodl an HTLC..
const myWonderfulPlugin = dynamic: true;myWonderfulPluginrelasedHtlc = ; myWonderfulPlugin; { myWonderfulPlugin; myWonderfulPluginrelasedHtlc; return "OK";} myWonderfulPlugin; myWonderfulPluginstart;
More about C-lightning plugins
You can find more about C-lightning plugins :
- On the lightningd/plugins repo
- On the doc
- On the C-lightning repo
Plugins in other languages :
LICENCE
BSD 3-clause clear