-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroute.js
50 lines (42 loc) · 1.56 KB
/
route.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 router = require('./router')
var crypto = require('crypto')
var ByteBuffer = require('bytebuffer')
var sha = require('js-sha256')
const LND_KEYSEND_KEY = 5482373484
const SPHINX_CUSTOM_RECORD_KEY = 133773310
function jlog(s) {
console.log(JSON.stringify(s, null, 2))
}
/*
node route.js --hops=023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f,0227230b7b685f1742b944bfc5d79ddc8c5a90b68499775ee10895f87307d8d22e,02a0591e848d24246a349fe61c5d7a86bab7c3d9598366675b9c91deb3e31ddf57,03e278ab0ed1f0b21af7280428d4f00a542aa8be703ccce1be285596645d64a827
node route.js --hops=023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f,03a9a8d953fe747d0dd94dd3c567ddc58451101e987e2d2bf7a4d1e10a2c89ff38
*/
async function test() {
const args = minimist(process.argv.slice(2))
const hops = args['hops']
if (!hops) {
return console.log("NO HOPS")
}
const hs = hops.split(',')
try {
const r = await router.buildRoute(hs,3)
const randoStr = crypto.randomBytes(32).toString('hex');
const preimage = ByteBuffer.fromHex(randoStr)
r.route.hops = r.route.hops.map((h,i)=>{
if(i===r.route.hops.length-1) {
return {...h, custom_records:{
[`${LND_KEYSEND_KEY}`]: preimage,
// [`${SPHINX_CUSTOM_RECORD_KEY}`]: ByteBuffer.fromUTF8(opts.data || '{}'),
}}
}
return h
})
r.payment_hash = sha.sha256.arrayBuffer(preimage.toBuffer())
const j = await router.sendToRoute(r)
console.log("SUCCESS",j)
} catch(e) {
console.log("ERROR",e)
}
}
test()