-
Notifications
You must be signed in to change notification settings - Fork 13
/
hodl.js
executable file
·37 lines (30 loc) · 1.16 KB
/
hodl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
const EventEmitter = require('events');
const fs = require('fs');
const Plugin = require('../src/plugin.js');
/* A quick test plugin for an HTLC hodled until releasehtlc RPC method is called
* through lightningd. */
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";
}
function testMethodPromise(params) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve('Ok'), 1000);
});
}
myWonderfulPlugin.addMethod('releasehtlc', releaseHtlc, '', 'release an HTLC', '.');
myWonderfulPlugin.addMethod('testpromise', testMethodPromise, '', '', '');
myWonderfulPlugin.start();