-
Notifications
You must be signed in to change notification settings - Fork 3
/
htlcStopper.js
32 lines (24 loc) · 1021 Bytes
/
htlcStopper.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
// rejects any new htlcs
// made so can reject new htlcs few minutes before shutting down node to avoid new pending htlcs
// needs bos.js and package.json with {"type": "module"} in same folder
// run with "npm link balanceofsatoshis && node htlcStopper"
import { subscribeToForwardRequests } from 'balanceofsatoshis/node_modules/ln-service/index.js'
import bos from './bos.js'
const initialize = async (showLogs = true) => {
showLogs && printout('started')
const auth = await bos.initializeAuth()
const subForwardRequests = subscribeToForwardRequests({ lnd: auth })
subForwardRequests.on('forward_request', f => {
showLogs && printout('rejecting: ' + JSON.stringify(f, null, 2))
return f.reject()
})
}
// -------- helpers ----------
const printout = (...args) => {
// print async when possible
setImmediate(() => {
console.log(`${getDate()} htlcLimiter(): ${args.join(' ')}`)
})
}
const getDate = timestamp => (timestamp ? new Date(timestamp) : new Date()).toISOString()
initialize()