forked from stakwork/sphinx-keysend-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartbeat.js
50 lines (44 loc) · 1.14 KB
/
heartbeat.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
38
39
40
41
42
43
44
45
46
47
48
49
50
var minimist = require('minimist')
var LND = require('./lightning')
var signer = require('./signer')
var sub = require('./subscribe')
function jlog(s) {
console.log(JSON.stringify(s, null, 2))
}
async function test() {
const args = minimist(process.argv.slice(2))
const dest = args['dest']
if (!dest) {
return console.log("NO DEST")
}
sub.subscribeInvoices(function(data){
jlog(data)
console.log("=> RECEIVED KEYSEND RESPONSE!")
process.exit(0)
})
setTimeout(()=>{
console.log("NEVER RECEIVED RESPONSE")
process.exit(0)
},15000)
const amt = 10
const pub_key = await LND.getMyPubKey()
let data = JSON.stringify({
type: 26, // heartbeat type
message: { amount: amt },
sender: {pub_key}
})
const sig = await signer.signAscii(data)
data = data + sig
const opts = {amt,dest,data}
try {
const r = await LND.keysend(opts)
console.log("=> KEYSEND SUCCESS")
} catch (e) {
console.log(e)
console.log("=> KEYSEND FAILURE")
jlog({
payment_error: e
})
}
}
test()