npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clightningjs

v0.2.2

Published

Plugins for C-lightning, a Lightning Network implementation. Also contains an RPC wrapper.

Downloads

202

Readme

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 node
const Plugin = require('clightningjs');

const helloPlugin = new Plugin();

function sayHello(params) {
  if (!params || params.length === 0) {
    return 'Hello world';
  } else {
    return 'Hello ' + params[0];
  }
}

helloPlugin.addMethod('hello', sayHello, 'name', 'If you launch me, I\'ll great you !');
helloPlugin.start();

Or a promise :

#!/usr/bin/env node
const Plugin = require('clightningjs');

const helloPlugin = new Plugin();

async function sayBye(params) {
  return Promise.resolve('Bye bye');
}

helloPlugin.addMethod('bye', sayBye, '', 'If you launch me, I\'ll say good bye');
helloPlugin.start();

Startup options

You can add a startup option to lightningd and make a method behave depending on it:

#!/usr/bin/env node
const Plugin = require('clightningjs');

const helloPlugin = new Plugin();

async function sayBye(params) {
  return Promise.resolve('Bye bye ' + helloPlugin.options['byename'].value);
}

helloPlugin.addOption('byename', 'continuum', 'The name of whow I should say bye to', 'string');
helloPlugin.addMethod('bye', sayBye, '', 'If you launch me, I\'ll say good bye');
helloPlugin.start();

Notifications subscription

You can subscribe to lightningd notifications, the plugin will emit events upon their reception :

#!/usr/bin/env node
const fs = require('fs');
const Plugin = require('clightningjs');

const listenPlugin = new Plugin();

listenPlugin.subscribe('warning');
listenPlugin.notifications.warning.on('warning', (params) => {
  fs.writeFile('log', params.warning.log, () => {});
});

listenPlugin.start();

Hooks subscription

You can subscribe to lightningd hooks :

#!/usr/bin/env node
const fs = require('fs');
const Plugin = require('clightningjs');

const dbBackup = new Plugin();

function useLessBackup(params) {
  fs.writeFile('logDb', params.writes, () => {});
  return true;
}

dbBackup.addHook('db_write', useLessBackup);
dbBackup.start();

More

You can restrict RPC control over your plugin with

// myStaticPlugin cannot be stopped by RPC
const myStaticPlugin = new Plugin({ 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 = new Plugin();
// "params" contains the params passed by `lightningd` along with the `init` message
myPlugin.onInit= function (params) {
	myPlugin.log('I\'m going to be initialized !!');
};

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 = new Plugin({dynamic: true});
myWonderfulPlugin.relasedHtlc = new EventEmitter();

myWonderfulPlugin.addHook('htlc_accepted', () => {
  myWonderfulPlugin.log('Ok, I won\'t release the HTLC, but will return!');
  return new Promise((resolve, reject) => {
    myWonderfulPlugin.relasedHtlc.on('released', () => {
      myWonderfulPlugin.log('Resolved');
      resolve({'result': 'continue'});
    });
  });
});

function releaseHtlc(params) {
  myWonderfulPlugin.log('Ok, finally I will release the HTLC and all the stuck liquidity.');
  myWonderfulPlugin.relasedHtlc.emit('released');
  return "OK";
}

myWonderfulPlugin.addMethod('releasehtlc', releaseHtlc, '', 'release an HTLC', '.');

myWonderfulPlugin.start();

More about C-lightning plugins

You can find more about C-lightning plugins :

Plugins in other languages :

LICENCE

BSD 3-clause clear