lightning 4.14.0 → 4.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/index.js +4 -4
- package/lnd_methods/macaroon/subscribe_to_rpc_requests.d.ts +8 -4
- package/lnd_methods/offchain/disconnect_watchtower.d.ts +0 -2
- package/lnd_methods/offchain/disconnect_watchtower.js +0 -1
- package/lnd_methods/offchain/emit_payment.js +21 -0
- package/lnd_methods/offchain/subscribe_to_past_payment.d.ts +50 -1
- package/lnd_methods/offchain/subscribe_to_past_payment.js +5 -0
- package/lnd_methods/offchain/subscribe_to_pay.js +57 -2
- package/lnd_methods/offchain/subscribe_to_pay_via_details.js +55 -1
- package/lnd_methods/offchain/subscribe_to_pay_via_request.js +56 -1
- package/lnd_responses/index.js +2 -0
- package/lnd_responses/routing_failure_from_htlc.js +105 -0
- package/package.json +3 -3
- package/test/lnd_methods/offchain/test_get_payment.js +2 -0
- package/test/lnd_responses/test_routing_failure_from_htlc.js +137 -0
- package/test/typescript/disconnect_watchtower.test-d.ts +0 -6
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -75,10 +75,10 @@ const {lndGateway} = require('./lnd_gateway');
|
|
|
75
75
|
const {lockUtxo} = require('./lnd_methods');
|
|
76
76
|
const {openChannel} = require('./lnd_methods');
|
|
77
77
|
const {openChannels} = require('./lnd_methods');
|
|
78
|
+
const {pay} = require('./lnd_methods');
|
|
78
79
|
const {payViaPaymentDetails} = require('./lnd_methods');
|
|
79
80
|
const {payViaPaymentRequest} = require('./lnd_methods');
|
|
80
81
|
const {payViaRoutes} = require('./lnd_methods');
|
|
81
|
-
const {pay} = require('./lnd_methods');
|
|
82
82
|
const {prepareForChannelProposal} = require('./lnd_methods');
|
|
83
83
|
const {probeForRoute} = require('./lnd_methods');
|
|
84
84
|
const {proposeChannel} = require('./lnd_methods');
|
|
@@ -123,8 +123,8 @@ const {subscribeToWalletStatus} = require('./lnd_methods');
|
|
|
123
123
|
const {unauthenticatedLndGrpc} = require('./lnd_grpc');
|
|
124
124
|
const {unlockUtxo} = require('./lnd_methods');
|
|
125
125
|
const {unlockWallet} = require('./lnd_methods');
|
|
126
|
-
const {updateConnectedWatchtower} = require('./lnd_methods');
|
|
127
126
|
const {updateChainTransaction} = require('./lnd_methods');
|
|
127
|
+
const {updateConnectedWatchtower} = require('./lnd_methods');
|
|
128
128
|
const {updatePathfindingSettings} = require('./lnd_methods');
|
|
129
129
|
const {updateRoutingFees} = require('./lnd_methods');
|
|
130
130
|
const {verifyAccess} = require('./lnd_methods');
|
|
@@ -211,10 +211,10 @@ module.exports = {
|
|
|
211
211
|
lockUtxo,
|
|
212
212
|
openChannel,
|
|
213
213
|
openChannels,
|
|
214
|
+
pay,
|
|
214
215
|
payViaPaymentDetails,
|
|
215
216
|
payViaPaymentRequest,
|
|
216
217
|
payViaRoutes,
|
|
217
|
-
pay,
|
|
218
218
|
prepareForChannelProposal,
|
|
219
219
|
probeForRoute,
|
|
220
220
|
proposeChannel,
|
|
@@ -259,8 +259,8 @@ module.exports = {
|
|
|
259
259
|
unauthenticatedLndGrpc,
|
|
260
260
|
unlockUtxo,
|
|
261
261
|
unlockWallet,
|
|
262
|
-
updateConnectedWatchtower,
|
|
263
262
|
updateChainTransaction,
|
|
263
|
+
updateConnectedWatchtower,
|
|
264
264
|
updatePathfindingSettings,
|
|
265
265
|
updateRoutingFees,
|
|
266
266
|
verifyAccess,
|
|
@@ -21,8 +21,6 @@ export type SubscribeToRpcRequestsResult = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type SubscribeToRpcRequestsCommonEvent = {
|
|
24
|
-
/** Call Id Number */
|
|
25
|
-
call: number;
|
|
26
24
|
/** Message Id Number */
|
|
27
25
|
id: number;
|
|
28
26
|
/** Base64 Encoded Macaroon String */
|
|
@@ -122,11 +120,17 @@ export type SubscribeToRpcRequestsPayViaRouteRequestEvent =
|
|
|
122
120
|
};
|
|
123
121
|
}>;
|
|
124
122
|
|
|
123
|
+
export type SubscribeToRpcRequestsRequestOrResponseEvent =
|
|
124
|
+
SubscribeToRpcRequestsCommonEvent & {
|
|
125
|
+
/** Call Id Number */
|
|
126
|
+
call: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
125
129
|
export type SubscribeToRpcRequestsRequestEvent =
|
|
126
|
-
|
|
130
|
+
SubscribeToRpcRequestsRequestOrResponseEvent;
|
|
127
131
|
|
|
128
132
|
export type SubscribeToRpcRequestsResponseEvent =
|
|
129
|
-
|
|
133
|
+
SubscribeToRpcRequestsRequestOrResponseEvent;
|
|
130
134
|
|
|
131
135
|
/**
|
|
132
136
|
* Subscribe to RPC requests and their responses
|
|
@@ -17,7 +17,6 @@ const unimplementedError = '12 UNIMPLEMENTED: unknown service wtclientrpc.Watcht
|
|
|
17
17
|
{
|
|
18
18
|
lnd: <Authenticated LND API Object>
|
|
19
19
|
public_key: <Watchtower Public Key Hex String>
|
|
20
|
-
[retry_delay]: <Retry Delay Milliseconds Number>
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
@returns via cbk or Promise
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
const {confirmedFromPayment} = require('./../../lnd_responses');
|
|
2
2
|
const {failureFromPayment} = require('./../../lnd_responses');
|
|
3
3
|
const {pendingFromPayment} = require('./../../lnd_responses');
|
|
4
|
+
const {routingFailureFromHtlc} = require('./../../lnd_responses');
|
|
4
5
|
const {states} = require('./payment_states');
|
|
5
6
|
|
|
7
|
+
const failedStatus = 'FAILED';
|
|
8
|
+
const {isArray} = Array;
|
|
9
|
+
|
|
6
10
|
/** Emit payment from payment event
|
|
7
11
|
|
|
8
12
|
{
|
|
@@ -22,6 +26,23 @@ module.exports = ({data, emitter}) => {
|
|
|
22
26
|
return emitter.emit('failed', failureFromPayment(data));
|
|
23
27
|
|
|
24
28
|
case states.paying:
|
|
29
|
+
const hasHtlcs = !!data && isArray(data.htlcs) && !!data.htlcs.length;
|
|
30
|
+
|
|
31
|
+
// Exit early when no HTLCs are attached
|
|
32
|
+
if (!hasHtlcs) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Emit routing failures
|
|
37
|
+
data.htlcs.filter(n => n.status === failedStatus).forEach(htlc => {
|
|
38
|
+
return emitter.emit('routing_failure', routingFailureFromHtlc(htlc));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Exit early when the HTLCs have no pending payments
|
|
42
|
+
if (!data.htlcs.find(n => n.status === states.paying)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
return emitter.emit('paying', pendingFromPayment(data));
|
|
26
47
|
|
|
27
48
|
default:
|
|
@@ -66,7 +66,56 @@ export type SubscribeToPastPaymentFailedEvent = {
|
|
|
66
66
|
is_route_not_found: boolean;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
export type SubscribeToPastPaymentPayingEvent = {
|
|
69
|
+
export type SubscribeToPastPaymentPayingEvent = {
|
|
70
|
+
/** Payment Created At ISO 8601 Date String */
|
|
71
|
+
created_at: string;
|
|
72
|
+
/** Payment Destination Hex String */
|
|
73
|
+
destination: string;
|
|
74
|
+
/** Payment Hash Hex String */
|
|
75
|
+
id: string;
|
|
76
|
+
/** Total Millitokens Pending String */
|
|
77
|
+
mtokens: string;
|
|
78
|
+
paths: {
|
|
79
|
+
/** Total Fee Tokens Pending Number */
|
|
80
|
+
fee: number;
|
|
81
|
+
/** Total Fee Millitokens Pending String */
|
|
82
|
+
fee_mtokens: string;
|
|
83
|
+
hops: {
|
|
84
|
+
/** Standard Format Channel Id String */
|
|
85
|
+
channel: string;
|
|
86
|
+
/** Channel Capacity Tokens Number */
|
|
87
|
+
channel_capacity: number;
|
|
88
|
+
/** Fee Tokens Rounded Down Number */
|
|
89
|
+
fee: number;
|
|
90
|
+
/** Fee Millitokens String */
|
|
91
|
+
fee_mtokens: string;
|
|
92
|
+
/** Forward Tokens Number */
|
|
93
|
+
forward: number;
|
|
94
|
+
/** Forward Millitokens String */
|
|
95
|
+
forward_mtokens: string;
|
|
96
|
+
/** Public Key Hex String */
|
|
97
|
+
public_key: string;
|
|
98
|
+
/** Timeout Block Height Number */
|
|
99
|
+
timeout: number;
|
|
100
|
+
}[];
|
|
101
|
+
/** Total Millitokens Pending String */
|
|
102
|
+
mtokens: string;
|
|
103
|
+
/** Total Fee Tokens Pending Rounded Up Number */
|
|
104
|
+
safe_fee: number;
|
|
105
|
+
/** Total Tokens Pending, Rounded Up Number */
|
|
106
|
+
safe_tokens: number;
|
|
107
|
+
/** Expiration Block Height Number */
|
|
108
|
+
timeout: number;
|
|
109
|
+
}[];
|
|
110
|
+
/** BOLT 11 Encoded Payment Request String */
|
|
111
|
+
request?: string;
|
|
112
|
+
/** Total Tokens Pending, Rounded Up Number */
|
|
113
|
+
safe_tokens: number;
|
|
114
|
+
/** Expiration Block Height Number */
|
|
115
|
+
timeout?: number;
|
|
116
|
+
/** Total Tokens Pending Rounded Down Number */
|
|
117
|
+
tokens: number;
|
|
118
|
+
};
|
|
70
119
|
|
|
71
120
|
/**
|
|
72
121
|
* Subscribe to the status of a past payment
|
|
@@ -8,10 +8,12 @@ const {confirmedFromPayment} = require('./../../lnd_responses');
|
|
|
8
8
|
const {confirmedFromPaymentStatus} = require('./../../lnd_responses');
|
|
9
9
|
const emitPayment = require('./emit_payment');
|
|
10
10
|
const {failureFromPayment} = require('./../../lnd_responses');
|
|
11
|
+
const {handleRemoveListener} = require('./../../grpc');
|
|
11
12
|
const {isLnd} = require('./../../lnd_requests');
|
|
12
13
|
const {safeTokens} = require('./../../bolt00');
|
|
13
14
|
const {states} = require('./payment_states');
|
|
14
15
|
|
|
16
|
+
const events = ['confirmed', 'failed', 'paying'];
|
|
15
17
|
const hexToBuffer = hex => Buffer.from(hex, 'hex');
|
|
16
18
|
const {isArray} = Array;
|
|
17
19
|
const isHash = n => /^[0-9A-F]{64}$/i.test(n);
|
|
@@ -141,6 +143,9 @@ module.exports = args => {
|
|
|
141
143
|
|
|
142
144
|
const sub = args.lnd[type][method]({payment_hash: hash});
|
|
143
145
|
|
|
146
|
+
// Terminate subscription when all listeners are removed
|
|
147
|
+
handleRemoveListener({emitter, events, subscription: sub});
|
|
148
|
+
|
|
144
149
|
sub.on('data', data => emitPayment({data, emitter}));
|
|
145
150
|
sub.on('end', () => emitter.emit('end'));
|
|
146
151
|
sub.on('error', err => emitError(err));
|
|
@@ -146,7 +146,62 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
@event 'paying'
|
|
149
|
-
{
|
|
149
|
+
{
|
|
150
|
+
created_at: <Payment Created At ISO 8601 Date String>
|
|
151
|
+
destination: <Payment Destination Hex String>
|
|
152
|
+
id: <Payment Hash Hex String>
|
|
153
|
+
mtokens: <Total Millitokens Pending String>
|
|
154
|
+
paths: [{
|
|
155
|
+
fee: <Total Fee Tokens Pending Number>
|
|
156
|
+
fee_mtokens: <Total Fee Millitokens Pending String>
|
|
157
|
+
hops: [{
|
|
158
|
+
channel: <Standard Format Channel Id String>
|
|
159
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
160
|
+
fee: <Fee Tokens Rounded Down Number>
|
|
161
|
+
fee_mtokens: <Fee Millitokens String>
|
|
162
|
+
forward: <Forward Tokens Number>
|
|
163
|
+
forward_mtokens: <Forward Millitokens String>
|
|
164
|
+
public_key: <Public Key Hex String>
|
|
165
|
+
timeout: <Timeout Block Height Number>
|
|
166
|
+
}]
|
|
167
|
+
mtokens: <Total Millitokens Pending String>
|
|
168
|
+
safe_fee: <Total Fee Tokens Pending Rounded Up Number>
|
|
169
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
170
|
+
timeout: <Expiration Block Height Number>
|
|
171
|
+
}]
|
|
172
|
+
[request]: <BOLT 11 Encoded Payment Request String>
|
|
173
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
174
|
+
[timeout]: <Expiration Block Height Number>
|
|
175
|
+
tokens: <Total Tokens Pending Rounded Down Number>
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@event 'routing_failure'
|
|
179
|
+
{
|
|
180
|
+
[channel]: <Standard Format Channel Id String>
|
|
181
|
+
index: <Failure Index Number>
|
|
182
|
+
[mtokens]: <Millitokens String>
|
|
183
|
+
[public_key]: <Public Key Hex String>
|
|
184
|
+
reason: <Failure Reason String>
|
|
185
|
+
route: {
|
|
186
|
+
fee: <Total Route Fee Tokens To Pay Number>
|
|
187
|
+
fee_mtokens: <Total Route Fee Millitokens To Pay String>
|
|
188
|
+
hops: [{
|
|
189
|
+
channel: <Standard Format Channel Id String>
|
|
190
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
191
|
+
fee: <Fee Number>
|
|
192
|
+
fee_mtokens: <Fee Millitokens String>
|
|
193
|
+
forward: <Forward Tokens Number>
|
|
194
|
+
forward_mtokens: <Forward Millitokens String>
|
|
195
|
+
public_key: <Public Key Hex String>
|
|
196
|
+
timeout: <Timeout Block Height Number>
|
|
197
|
+
}]
|
|
198
|
+
mtokens: <Total Route Millitokens String>
|
|
199
|
+
[payment]: <Payment Identifier Hex String>
|
|
200
|
+
timeout: <Expiration Block Height Number>
|
|
201
|
+
tokens: <Total Route Tokens Number>
|
|
202
|
+
[total_mtokens]: <Total Millitokens String>
|
|
203
|
+
}
|
|
204
|
+
}
|
|
150
205
|
*/
|
|
151
206
|
module.exports = args => {
|
|
152
207
|
if (!!args.cltv_delta && !!args.request) {
|
|
@@ -316,7 +371,7 @@ module.exports = args => {
|
|
|
316
371
|
last_hop_pubkey: hexToBuf(args.incoming_peer),
|
|
317
372
|
max_parts: args.max_paths || defaultMaxPaths,
|
|
318
373
|
max_shard_size_msat: args.max_path_mtokens || undefined,
|
|
319
|
-
no_inflight_updates:
|
|
374
|
+
no_inflight_updates: false,
|
|
320
375
|
outgoing_chan_id: !hasOutIds ? singleOut : undefined,
|
|
321
376
|
outgoing_chan_ids: outgoingChannelIds,
|
|
322
377
|
payment_addr: !!args.payment ? hexToBuf(args.payment) : undefined,
|
|
@@ -120,7 +120,61 @@ const type = 'router';
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
@event 'paying'
|
|
123
|
-
{
|
|
123
|
+
{
|
|
124
|
+
created_at: <Payment Created At ISO 8601 Date String>
|
|
125
|
+
destination: <Payment Destination Hex String>
|
|
126
|
+
id: <Payment Hash Hex String>
|
|
127
|
+
mtokens: <Total Millitokens Pending String>
|
|
128
|
+
paths: [{
|
|
129
|
+
fee: <Total Fee Tokens Pending Number>
|
|
130
|
+
fee_mtokens: <Total Fee Millitokens Pending String>
|
|
131
|
+
hops: [{
|
|
132
|
+
channel: <Standard Format Channel Id String>
|
|
133
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
134
|
+
fee: <Fee Tokens Rounded Down Number>
|
|
135
|
+
fee_mtokens: <Fee Millitokens String>
|
|
136
|
+
forward: <Forward Tokens Number>
|
|
137
|
+
forward_mtokens: <Forward Millitokens String>
|
|
138
|
+
public_key: <Public Key Hex String>
|
|
139
|
+
timeout: <Timeout Block Height Number>
|
|
140
|
+
}]
|
|
141
|
+
mtokens: <Total Millitokens Pending String>
|
|
142
|
+
safe_fee: <Total Fee Tokens Pending Rounded Up Number>
|
|
143
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
144
|
+
timeout: <Expiration Block Height Number>
|
|
145
|
+
}]
|
|
146
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
147
|
+
[timeout]: <Expiration Block Height Number>
|
|
148
|
+
tokens: <Total Tokens Pending Rounded Down Number>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@event 'routing_failure'
|
|
152
|
+
{
|
|
153
|
+
[channel]: <Standard Format Channel Id String>
|
|
154
|
+
index: <Failure Index Number>
|
|
155
|
+
[mtokens]: <Millitokens String>
|
|
156
|
+
[public_key]: <Public Key Hex String>
|
|
157
|
+
reason: <Failure Reason String>
|
|
158
|
+
route: {
|
|
159
|
+
fee: <Total Route Fee Tokens To Pay Number>
|
|
160
|
+
fee_mtokens: <Total Route Fee Millitokens To Pay String>
|
|
161
|
+
hops: [{
|
|
162
|
+
channel: <Standard Format Channel Id String>
|
|
163
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
164
|
+
fee: <Fee Number>
|
|
165
|
+
fee_mtokens: <Fee Millitokens String>
|
|
166
|
+
forward: <Forward Tokens Number>
|
|
167
|
+
forward_mtokens: <Forward Millitokens String>
|
|
168
|
+
public_key: <Public Key Hex String>
|
|
169
|
+
timeout: <Timeout Block Height Number>
|
|
170
|
+
}]
|
|
171
|
+
mtokens: <Total Route Millitokens String>
|
|
172
|
+
[payment]: <Payment Identifier Hex String>
|
|
173
|
+
timeout: <Expiration Block Height Number>
|
|
174
|
+
tokens: <Total Route Tokens Number>
|
|
175
|
+
[total_mtokens]: <Total Millitokens String>
|
|
176
|
+
}
|
|
177
|
+
}
|
|
124
178
|
*/
|
|
125
179
|
module.exports = args => {
|
|
126
180
|
if (!isPublicKey(args.destination)) {
|
|
@@ -100,7 +100,62 @@ const type = 'router';
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
@event 'paying'
|
|
103
|
-
{
|
|
103
|
+
{
|
|
104
|
+
created_at: <Payment Created At ISO 8601 Date String>
|
|
105
|
+
destination: <Payment Destination Hex String>
|
|
106
|
+
id: <Payment Hash Hex String>
|
|
107
|
+
mtokens: <Total Millitokens Pending String>
|
|
108
|
+
paths: [{
|
|
109
|
+
fee: <Total Fee Tokens Pending Number>
|
|
110
|
+
fee_mtokens: <Total Fee Millitokens Pending String>
|
|
111
|
+
hops: [{
|
|
112
|
+
channel: <Standard Format Channel Id String>
|
|
113
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
114
|
+
fee: <Fee Tokens Rounded Down Number>
|
|
115
|
+
fee_mtokens: <Fee Millitokens String>
|
|
116
|
+
forward: <Forward Tokens Number>
|
|
117
|
+
forward_mtokens: <Forward Millitokens String>
|
|
118
|
+
public_key: <Public Key Hex String>
|
|
119
|
+
timeout: <Timeout Block Height Number>
|
|
120
|
+
}]
|
|
121
|
+
mtokens: <Total Millitokens Pending String>
|
|
122
|
+
safe_fee: <Total Fee Tokens Pending Rounded Up Number>
|
|
123
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
124
|
+
timeout: <Expiration Block Height Number>
|
|
125
|
+
}]
|
|
126
|
+
[request]: <BOLT 11 Encoded Payment Request String>
|
|
127
|
+
safe_tokens: <Total Tokens Pending, Rounded Up Number>
|
|
128
|
+
[timeout]: <Expiration Block Height Number>
|
|
129
|
+
tokens: <Total Tokens Pending Rounded Down Number>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@event 'routing_failure'
|
|
133
|
+
{
|
|
134
|
+
[channel]: <Standard Format Channel Id String>
|
|
135
|
+
index: <Failure Index Number>
|
|
136
|
+
[mtokens]: <Millitokens String>
|
|
137
|
+
[public_key]: <Public Key Hex String>
|
|
138
|
+
reason: <Failure Reason String>
|
|
139
|
+
route: {
|
|
140
|
+
fee: <Total Route Fee Tokens To Pay Number>
|
|
141
|
+
fee_mtokens: <Total Route Fee Millitokens To Pay String>
|
|
142
|
+
hops: [{
|
|
143
|
+
channel: <Standard Format Channel Id String>
|
|
144
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
145
|
+
fee: <Fee Number>
|
|
146
|
+
fee_mtokens: <Fee Millitokens String>
|
|
147
|
+
forward: <Forward Tokens Number>
|
|
148
|
+
forward_mtokens: <Forward Millitokens String>
|
|
149
|
+
public_key: <Public Key Hex String>
|
|
150
|
+
timeout: <Timeout Block Height Number>
|
|
151
|
+
}]
|
|
152
|
+
mtokens: <Total Route Millitokens String>
|
|
153
|
+
[payment]: <Payment Identifier Hex String>
|
|
154
|
+
timeout: <Expiration Block Height Number>
|
|
155
|
+
tokens: <Total Route Tokens Number>
|
|
156
|
+
[total_mtokens]: <Total Millitokens String>
|
|
157
|
+
}
|
|
158
|
+
}
|
|
104
159
|
*/
|
|
105
160
|
module.exports = args => {
|
|
106
161
|
if (!args.request) {
|
package/lnd_responses/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const pendingAsPendingChannels = require('./pending_as_pending_channels');
|
|
|
14
14
|
const pendingFromPayment = require('./pending_from_payment');
|
|
15
15
|
const policyFromChannelUpdate = require('./policy_from_channel_update');
|
|
16
16
|
const routesFromQueryRoutes = require('./routes_from_query_routes');
|
|
17
|
+
const routingFailureFromHtlc = require('./routing_failure_from_htlc');
|
|
17
18
|
const rpcAttemptHtlcAsAttempt = require('./rpc_attempt_htlc_as_attempt');
|
|
18
19
|
const rpcChannelAsChannel = require('./rpc_channel_as_channel');
|
|
19
20
|
const rpcChannelAsOldRpcChannel = require('./rpc_channel_as_old_rpc_channel');
|
|
@@ -57,6 +58,7 @@ module.exports = {
|
|
|
57
58
|
pendingFromPayment,
|
|
58
59
|
policyFromChannelUpdate,
|
|
59
60
|
routesFromQueryRoutes,
|
|
61
|
+
routingFailureFromHtlc,
|
|
60
62
|
rpcAttemptHtlcAsAttempt,
|
|
61
63
|
rpcChannelAsChannel,
|
|
62
64
|
rpcChannelAsOldRpcChannel,
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const paymentFailure = require('./payment_failure');
|
|
2
|
+
const rpcRouteAsRoute = require('./rpc_route_as_route');
|
|
3
|
+
|
|
4
|
+
/** Derive routing failure details from an HTLC
|
|
5
|
+
|
|
6
|
+
{
|
|
7
|
+
attempt_time_ns: <HTLC Sent At Epoch Time Nanoseconds String>
|
|
8
|
+
failure: {
|
|
9
|
+
[channel_update]: {
|
|
10
|
+
base_fee: <Base Fee Millitokens Number>
|
|
11
|
+
chain_hash: <Chain Hash Buffer Object>
|
|
12
|
+
[chan_id]: <Numeric Channel Id String>
|
|
13
|
+
channel_flags: <Channel Flags Number>
|
|
14
|
+
extra_opaque_data: <Extra Opaque Data Buffer Object>
|
|
15
|
+
fee_rate: <Fee Rate Number>
|
|
16
|
+
htlc_maximum_msat: <Maximum HTLC Millitokens Number>
|
|
17
|
+
htlc_minimum_msat: <Minimum HTLC Millitokens Number>
|
|
18
|
+
message_flags: <Message Flags Number>
|
|
19
|
+
signature: <Signature Buffer Object>
|
|
20
|
+
time_lock_delta: <CLTV Delta Number>
|
|
21
|
+
timestamp: <Update Epoch Time Seconds Number>
|
|
22
|
+
}
|
|
23
|
+
code: <Failure Code String>
|
|
24
|
+
[failure_source_index]: <Failed Hop Index Number>
|
|
25
|
+
height: <Height Number>
|
|
26
|
+
htlc_msat: <HTLC Millitokens String>
|
|
27
|
+
}
|
|
28
|
+
resolve_time_ns: <HTLC Resolved At Epoch Time Nanoseconds String>
|
|
29
|
+
route: {
|
|
30
|
+
hops: [{
|
|
31
|
+
amt_to_forward: <Tokens to Forward String>
|
|
32
|
+
amt_to_forward_msat: <Millitokens to Forward String>
|
|
33
|
+
chan_id: <Numeric Format Channel Id String>
|
|
34
|
+
chan_capacity: <Channel Capacity Number>
|
|
35
|
+
expiry: <Timeout Chain Height Number>
|
|
36
|
+
fee: <Fee in Tokens Number>
|
|
37
|
+
fee_msat: <Fee in Millitokens Number>
|
|
38
|
+
[mpp_record]: {
|
|
39
|
+
payment_addr: <Payment Identifier Buffer>
|
|
40
|
+
total_amt_msat: <Total Payment Millitokens Amount String>
|
|
41
|
+
}
|
|
42
|
+
pub_key: <Next Hop Public Key Hex String>
|
|
43
|
+
tlv_payload: <Has Extra TLV Data Bool>
|
|
44
|
+
}]
|
|
45
|
+
total_amt: <Total Tokens String>
|
|
46
|
+
total_amt_msat: <Route Total Millitokens String>
|
|
47
|
+
total_fees: <Route Fee Tokens String>
|
|
48
|
+
total_fees_msat: <Route Total Fees Millitokens String>
|
|
49
|
+
total_time_lock: <Route Total Timelock Number>
|
|
50
|
+
}
|
|
51
|
+
status: <HTLC Status String>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@throws
|
|
55
|
+
<Error>
|
|
56
|
+
|
|
57
|
+
@returns
|
|
58
|
+
{
|
|
59
|
+
[channel]: <Standard Format Channel Id String>
|
|
60
|
+
index: <Failure Index Number>
|
|
61
|
+
[mtokens]: <Millitokens String>
|
|
62
|
+
[public_key]: <Public Key Hex String>
|
|
63
|
+
reason: <Failure Reason String>
|
|
64
|
+
route: {
|
|
65
|
+
fee: <Total Route Fee Tokens To Pay Number>
|
|
66
|
+
fee_mtokens: <Total Route Fee Millitokens To Pay String>
|
|
67
|
+
hops: [{
|
|
68
|
+
channel: <Standard Format Channel Id String>
|
|
69
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
70
|
+
fee: <Fee Number>
|
|
71
|
+
fee_mtokens: <Fee Millitokens String>
|
|
72
|
+
forward: <Forward Tokens Number>
|
|
73
|
+
forward_mtokens: <Forward Millitokens String>
|
|
74
|
+
public_key: <Public Key Hex String>
|
|
75
|
+
timeout: <Timeout Block Height Number>
|
|
76
|
+
}]
|
|
77
|
+
mtokens: <Total Route Millitokens String>
|
|
78
|
+
[payment]: <Payment Identifier Hex String>
|
|
79
|
+
timeout: <Expiration Block Height Number>
|
|
80
|
+
tokens: <Total Route Tokens Number>
|
|
81
|
+
[total_mtokens]: <Total Millitokens String>
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
*/
|
|
85
|
+
module.exports = htlc => {
|
|
86
|
+
const from = htlc.route.hops[htlc.failure.failure_source_index - 1] || {};
|
|
87
|
+
|
|
88
|
+
const failure = paymentFailure({
|
|
89
|
+
channel: htlc.channel,
|
|
90
|
+
failure: htlc.failure,
|
|
91
|
+
index: htlc.index,
|
|
92
|
+
key: from.pub_key,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const route = rpcRouteAsRoute(htlc.route);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
route,
|
|
99
|
+
channel: failure.details.channel,
|
|
100
|
+
index: failure.details.index,
|
|
101
|
+
mtokens: route.mtokens,
|
|
102
|
+
public_key: from.pub_key,
|
|
103
|
+
reason: failure.message,
|
|
104
|
+
};
|
|
105
|
+
};
|
package/package.json
CHANGED
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"@types/ws": "8.2.0",
|
|
16
16
|
"async": "3.2.2",
|
|
17
17
|
"asyncjs-util": "1.2.7",
|
|
18
|
-
"bitcoinjs-lib": "
|
|
18
|
+
"bitcoinjs-lib": "6.0.0",
|
|
19
19
|
"bn.js": "5.2.0",
|
|
20
20
|
"body-parser": "1.19.0",
|
|
21
21
|
"bolt07": "1.7.4",
|
|
22
22
|
"bolt09": "0.2.0",
|
|
23
23
|
"cbor": "8.1.0",
|
|
24
24
|
"express": "4.17.1",
|
|
25
|
-
"invoices": "2.0.
|
|
25
|
+
"invoices": "2.0.2",
|
|
26
26
|
"psbt": "1.1.10"
|
|
27
27
|
},
|
|
28
28
|
"description": "Lightning Network client library",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"directory": "test/typescript"
|
|
57
57
|
},
|
|
58
58
|
"types": "index.d.ts",
|
|
59
|
-
"version": "4.14.
|
|
59
|
+
"version": "4.14.4"
|
|
60
60
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {routingFailureFromHtlc} = require('./../../lnd_responses');
|
|
4
|
+
|
|
5
|
+
const makeHtlc = overrides => {
|
|
6
|
+
const htlc = {
|
|
7
|
+
attempt_time_ns: '1',
|
|
8
|
+
failure: {
|
|
9
|
+
channel_update: {
|
|
10
|
+
base_fee: 1,
|
|
11
|
+
chain_hash: Buffer.alloc(32),
|
|
12
|
+
chan_id: '1',
|
|
13
|
+
channel_flags: 1,
|
|
14
|
+
extra_opaque_data: Buffer.alloc(0),
|
|
15
|
+
fee_rate: 1,
|
|
16
|
+
htlc_maximum_msat: 1,
|
|
17
|
+
htlc_minimum_msat: 1,
|
|
18
|
+
message_flags: 1,
|
|
19
|
+
signature: Buffer.alloc(0),
|
|
20
|
+
time_lock_delta: 1,
|
|
21
|
+
timestamp: 1,
|
|
22
|
+
},
|
|
23
|
+
code: 'TEMPORARY_CHANNEL_FAILURE',
|
|
24
|
+
failure_source_index: 0,
|
|
25
|
+
height: 1,
|
|
26
|
+
htlc_msat: '1000',
|
|
27
|
+
},
|
|
28
|
+
resolve_time_ns: '1',
|
|
29
|
+
route: {
|
|
30
|
+
hops: [{
|
|
31
|
+
amt_to_forward: '1',
|
|
32
|
+
amt_to_forward_msat: '1000',
|
|
33
|
+
chan_id: '1',
|
|
34
|
+
chan_capacity: 1,
|
|
35
|
+
expiry: 1,
|
|
36
|
+
fee: 0,
|
|
37
|
+
fee_msat: '0',
|
|
38
|
+
pub_key: Buffer.alloc(33, 3).toString('hex'),
|
|
39
|
+
tlv_payload: true,
|
|
40
|
+
}],
|
|
41
|
+
total_amt: '1',
|
|
42
|
+
total_amt_msat: '1000',
|
|
43
|
+
total_fees: 0,
|
|
44
|
+
total_fees_msat: '0',
|
|
45
|
+
total_time_lock: 1,
|
|
46
|
+
},
|
|
47
|
+
status: 'FAILED',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Object.keys(overrides || {}).forEach(k => htlc[k] = overrides[k]);
|
|
51
|
+
|
|
52
|
+
return htlc;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const makeExpected = overrides => {
|
|
56
|
+
const expected = {
|
|
57
|
+
route: {
|
|
58
|
+
fee: 0,
|
|
59
|
+
fee_mtokens: '0',
|
|
60
|
+
hops: [
|
|
61
|
+
{
|
|
62
|
+
channel: '0x0x1',
|
|
63
|
+
channel_capacity: 1,
|
|
64
|
+
fee: 0,
|
|
65
|
+
fee_mtokens: '0',
|
|
66
|
+
forward: 1,
|
|
67
|
+
forward_mtokens: '1000',
|
|
68
|
+
public_key: '030303030303030303030303030303030303030303030303030303030303030303',
|
|
69
|
+
timeout: 1,
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
mtokens: '1000',
|
|
73
|
+
payment: undefined,
|
|
74
|
+
timeout: 1,
|
|
75
|
+
tokens: 1,
|
|
76
|
+
total_mtokens: undefined,
|
|
77
|
+
},
|
|
78
|
+
channel: '0x0x1',
|
|
79
|
+
index: 0,
|
|
80
|
+
mtokens: '1000',
|
|
81
|
+
public_key: undefined,
|
|
82
|
+
reason: 'TemporaryChannelFailure',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
Object.keys(overrides || {}).forEach(key => expected[key] = overrides[key]);
|
|
86
|
+
|
|
87
|
+
return expected;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const tests = [
|
|
91
|
+
{
|
|
92
|
+
args: makeHtlc({}),
|
|
93
|
+
description: 'HTLC is mapped to a routing failure',
|
|
94
|
+
expected: makeExpected({}),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
args: makeHtlc({
|
|
98
|
+
failure: {
|
|
99
|
+
channel_update: {
|
|
100
|
+
base_fee: 1,
|
|
101
|
+
chain_hash: Buffer.alloc(32),
|
|
102
|
+
chan_id: '1',
|
|
103
|
+
channel_flags: 1,
|
|
104
|
+
extra_opaque_data: Buffer.alloc(0),
|
|
105
|
+
fee_rate: 1,
|
|
106
|
+
htlc_maximum_msat: 1,
|
|
107
|
+
htlc_minimum_msat: 1,
|
|
108
|
+
message_flags: 1,
|
|
109
|
+
signature: Buffer.alloc(0),
|
|
110
|
+
time_lock_delta: 1,
|
|
111
|
+
timestamp: 1,
|
|
112
|
+
},
|
|
113
|
+
code: 'TEMPORARY_CHANNEL_FAILURE',
|
|
114
|
+
failure_source_index: 1,
|
|
115
|
+
height: 1,
|
|
116
|
+
htlc_msat: '1000',
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
description: 'HTLC is mapped to a routing failure with key',
|
|
120
|
+
expected: makeExpected({
|
|
121
|
+
index: 1,
|
|
122
|
+
public_key: Buffer.alloc(33, 3).toString('hex'),
|
|
123
|
+
}),
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
128
|
+
return test(description, ({end, strictSame, throws}) => {
|
|
129
|
+
if (!!error) {
|
|
130
|
+
throws(() => routingFailureFromHtlc(args), new Error(error), 'Got err');
|
|
131
|
+
} else {
|
|
132
|
+
strictSame(routingFailureFromHtlc(args), expected, 'HTLC mapped');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return end();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -10,13 +10,7 @@ expectError(disconnectWatchtower());
|
|
|
10
10
|
expectError(disconnectWatchtower({}));
|
|
11
11
|
expectError(disconnectWatchtower({lnd}));
|
|
12
12
|
expectError(disconnectWatchtower({public_key}));
|
|
13
|
-
expectError(disconnectWatchtower({retry_delay}));
|
|
14
|
-
expectError(disconnectWatchtower({lnd, retry_delay}));
|
|
15
13
|
|
|
16
14
|
expectType<void>(await disconnectWatchtower({lnd, public_key}));
|
|
17
|
-
expectType<void>(await disconnectWatchtower({lnd, public_key, retry_delay}));
|
|
18
15
|
|
|
19
16
|
expectType<void>(disconnectWatchtower({lnd, public_key}, () => {}));
|
|
20
|
-
expectType<void>(
|
|
21
|
-
disconnectWatchtower({lnd, public_key, retry_delay}, () => {})
|
|
22
|
-
);
|