forked from alexbosworth/ln-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute_hint_from_route.js
49 lines (41 loc) · 1.2 KB
/
route_hint_from_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
const {chanNumber} = require('bolt07');
const {isArray} = Array;
const firstHopOffset = 1;
/** Get a raw route hint from a route
{
route: [{
[base_fee_mtokens]: <Base Routing Fee In Millitokens String>
[channel]: <Standard Format Channel Id String>
[cltv_delta]: <CLTV Blocks Delta Number>
[fee_rate]: <Fee Rate In Millitokens Per Million Number>
public_key: <Forward Edge Public Key Hex String>
}]
}
@throws
<Error>
@returns
{
hops: [{
fee_base_msat: <Hop Base Fee Millitokens>
fee_proportional_millionths: <Hop Fee Rate Number>
chan_id: <Numeric Format Hop Channel Id String>
cltv_expiry_delta: <Hop CLTV Delta Number>
node_id: <Hop Public Key Hex String>
}]
}
*/
module.exports = ({route}) => {
if (!isArray(route) || !route.length) {
throw new Error('ExpectedRouteArrayToDeriveHints');
}
const hops = route.slice(firstHopOffset).map((hop, i) => {
return {
fee_base_msat: hop.base_fee_mtokens,
fee_proportional_millionths: hop.fee_rate,
chan_id: chanNumber({channel: hop.channel}).number,
cltv_expiry_delta: hop.cltv_delta,
node_id: route[i].public_key,
};
});
return {hops};
};