ln-service 52.14.3 → 52.16.1

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 CHANGED
@@ -1,6 +1,15 @@
1
1
  # Versions
2
2
 
3
- ## 52.14.3
3
+ ## 52.16.1
4
+
5
+ - `subscribeToPayViaDetails`, `subscribeToPayViaRequest`: Add `paying`, and
6
+ `routing_failure` events to follow in-flight attempts and encountered routing failures
7
+
8
+ ## 52.15.0
9
+
10
+ - `getPayment`, `subscribeToPastPayment`: Add `pending` for pending payment details
11
+
12
+ ## 52.14.4
4
13
 
5
14
  - `probeForRoute`, `subscribeToProbeForRoute`, `subscribeToPayViaRoutes`,
6
15
  `payViaRoutes`: When probing (no hash), delete the payment failure record after the probe
package/README.md CHANGED
@@ -9,7 +9,7 @@ through npm.
9
9
 
10
10
  Supported LND versions:
11
11
 
12
- - v0.13.0-beta to v0.13.3-beta
12
+ - v0.13.0-beta to v0.13.4-beta
13
13
  - v0.12.0-beta to v0.12.1-beta
14
14
  - v0.11.0-beta to v0.11.1-beta
15
15
 
@@ -806,7 +806,7 @@ Requires `offchain:write` permission
806
806
 
807
807
  Method not supported on LND 0.12.1 or below
808
808
 
809
- `id` is not supported on LND 0.13.3 or below
809
+ `id` is not supported on LND 0.13.4 or below
810
810
 
811
811
  {
812
812
  [id]: <Delete Only Failed Attempt Records For Payment With Hash Hex String>
@@ -874,7 +874,7 @@ Delete a payment record
874
874
 
875
875
  Requires `offchain:write` permission
876
876
 
877
- Note: this method is not supported on LND 0.13.3 and below
877
+ Note: this method is not supported on LND 0.13.4 and below
878
878
 
879
879
  {
880
880
  id: <Payment Preimage Hash Hex String>
@@ -2324,6 +2324,30 @@ Requires `offchain:read` permission
2324
2324
  timeout: <Expiration Block Height Number>
2325
2325
  tokens: <Total Tokens Paid Number>
2326
2326
  }
2327
+ [pending]: {
2328
+ created_at: <Payment Created At ISO 8601 Date String>
2329
+ destination: <Payment Destination Hex String>
2330
+ id: <Payment Hash Hex String>
2331
+ mtokens: <Total Millitokens Pending String>
2332
+ paths: [{
2333
+ fee_mtokens: <Total Fee Millitokens Paid String>
2334
+ hops: [{
2335
+ channel: <Standard Format Channel Id String>
2336
+ channel_capacity: <Channel Capacity Tokens Number>
2337
+ fee: <Fee Tokens Rounded Down Number>
2338
+ fee_mtokens: <Fee Millitokens String>
2339
+ forward: <Forwarded Tokens Number>
2340
+ forward_mtokens: <Forward Millitokens String>
2341
+ public_key: <Public Key Hex String>
2342
+ timeout: <Timeout Block Height Number>
2343
+ }]
2344
+ mtokens: <Total Millitokens Pending String>
2345
+ }]
2346
+ [request]: <BOLT 11 Encoded Payment Request String>
2347
+ safe_tokens: <Payment Tokens Rounded Up Number>
2348
+ [timeout]: <Expiration Block Height Number>
2349
+ tokens: <Total Tokens Pending Number>
2350
+ }
2327
2351
  }
2328
2352
 
2329
2353
  Example:
@@ -2908,7 +2932,7 @@ Get wallet status.
2908
2932
 
2909
2933
  This method is not supported on LND 0.12.1 and below
2910
2934
 
2911
- `is_ready` is not supported on LND 0.13.3 and below
2935
+ `is_ready` is not supported on LND 0.13.4 and below
2912
2936
 
2913
2937
  {
2914
2938
  lnd: <Unauthenticated LND API Object>
@@ -4066,7 +4090,7 @@ If specified, message type is expected to be between 32768 and 65535
4066
4090
 
4067
4091
  Message data should not be larger than 65533 bytes
4068
4092
 
4069
- Note: this method is not supported in LND versions 0.13.3 and below
4093
+ Note: this method is not supported in LND versions 0.13.4 and below
4070
4094
 
4071
4095
  Requires `offchain:write` permission
4072
4096
 
@@ -4736,7 +4760,7 @@ Subscribe to HTLC events
4736
4760
 
4737
4761
  Requires `offchain:read` permission
4738
4762
 
4739
- Note: LND 0.13.3 and below do not return `secret` for forwards
4763
+ Note: LND 0.13.4 and below do not return `secret` for forwards
4740
4764
 
4741
4765
  {
4742
4766
  lnd: <Authenticated LND API Object>
@@ -5138,7 +5162,34 @@ Requires `offchain:read` permission
5138
5162
  }
5139
5163
 
5140
5164
  @event 'paying'
5141
- {}
5165
+ {
5166
+ created_at: <Payment Created At ISO 8601 Date String>
5167
+ destination: <Payment Destination Hex String>
5168
+ id: <Payment Hash Hex String>
5169
+ mtokens: <Total Millitokens Pending String>
5170
+ paths: [{
5171
+ fee: <Total Fee Tokens Pending Number>
5172
+ fee_mtokens: <Total Fee Millitokens Pending String>
5173
+ hops: [{
5174
+ channel: <Standard Format Channel Id String>
5175
+ channel_capacity: <Channel Capacity Tokens Number>
5176
+ fee: <Fee Tokens Rounded Down Number>
5177
+ fee_mtokens: <Fee Millitokens String>
5178
+ forward: <Forward Tokens Number>
5179
+ forward_mtokens: <Forward Millitokens String>
5180
+ public_key: <Public Key Hex String>
5181
+ timeout: <Timeout Block Height Number>
5182
+ }]
5183
+ mtokens: <Total Millitokens Pending String>
5184
+ safe_fee: <Total Fee Tokens Pending Rounded Up Number>
5185
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5186
+ timeout: <Expiration Block Height Number>
5187
+ }]
5188
+ [request]: <BOLT 11 Encoded Payment Request String>
5189
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5190
+ [timeout]: <Expiration Block Height Number>
5191
+ tokens: <Total Tokens Pending Rounded Down Number>
5192
+ }
5142
5193
 
5143
5194
  Example:
5144
5195
 
@@ -5156,7 +5207,7 @@ Subscribe to successful outgoing payments
5156
5207
 
5157
5208
  Requires `offchain:read` permission
5158
5209
 
5159
- Note: Method not supported on LND 0.13.3 and below
5210
+ Note: Method not supported on LND 0.13.4 and below
5160
5211
 
5161
5212
  {
5162
5213
  lnd: <Authenticated LND API Object>
@@ -5309,7 +5360,61 @@ Requires `offchain:write` permission
5309
5360
  }
5310
5361
 
5311
5362
  @event 'paying'
5312
- {}
5363
+ {
5364
+ created_at: <Payment Created At ISO 8601 Date String>
5365
+ destination: <Payment Destination Hex String>
5366
+ id: <Payment Hash Hex String>
5367
+ mtokens: <Total Millitokens Pending String>
5368
+ paths: [{
5369
+ fee: <Total Fee Tokens Pending Number>
5370
+ fee_mtokens: <Total Fee Millitokens Pending String>
5371
+ hops: [{
5372
+ channel: <Standard Format Channel Id String>
5373
+ channel_capacity: <Channel Capacity Tokens Number>
5374
+ fee: <Fee Tokens Rounded Down Number>
5375
+ fee_mtokens: <Fee Millitokens String>
5376
+ forward: <Forward Tokens Number>
5377
+ forward_mtokens: <Forward Millitokens String>
5378
+ public_key: <Public Key Hex String>
5379
+ timeout: <Timeout Block Height Number>
5380
+ }]
5381
+ mtokens: <Total Millitokens Pending String>
5382
+ safe_fee: <Total Fee Tokens Pending Rounded Up Number>
5383
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5384
+ timeout: <Expiration Block Height Number>
5385
+ }]
5386
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5387
+ [timeout]: <Expiration Block Height Number>
5388
+ tokens: <Total Tokens Pending Rounded Down Number>
5389
+ }
5390
+
5391
+ @event 'routing_failure'
5392
+ {
5393
+ [channel]: <Standard Format Channel Id String>
5394
+ index: <Failure Index Number>
5395
+ [mtokens]: <Millitokens String>
5396
+ [public_key]: <Public Key Hex String>
5397
+ reason: <Failure Reason String>
5398
+ route: {
5399
+ fee: <Total Route Fee Tokens To Pay Number>
5400
+ fee_mtokens: <Total Route Fee Millitokens To Pay String>
5401
+ hops: [{
5402
+ channel: <Standard Format Channel Id String>
5403
+ channel_capacity: <Channel Capacity Tokens Number>
5404
+ fee: <Fee Number>
5405
+ fee_mtokens: <Fee Millitokens String>
5406
+ forward: <Forward Tokens Number>
5407
+ forward_mtokens: <Forward Millitokens String>
5408
+ public_key: <Public Key Hex String>
5409
+ timeout: <Timeout Block Height Number>
5410
+ }]
5411
+ mtokens: <Total Route Millitokens String>
5412
+ [payment]: <Payment Identifier Hex String>
5413
+ timeout: <Expiration Block Height Number>
5414
+ tokens: <Total Route Tokens Number>
5415
+ [total_mtokens]: <Total Millitokens String>
5416
+ }
5417
+ }
5313
5418
 
5314
5419
  Example:
5315
5420
 
@@ -5406,7 +5511,61 @@ Requires `offchain:write` permission
5406
5511
  }
5407
5512
 
5408
5513
  @event 'paying'
5409
- {}
5514
+ {
5515
+ created_at: <Payment Created At ISO 8601 Date String>
5516
+ destination: <Payment Destination Hex String>
5517
+ id: <Payment Hash Hex String>
5518
+ mtokens: <Total Millitokens Pending String>
5519
+ paths: [{
5520
+ fee: <Total Fee Tokens Pending Number>
5521
+ fee_mtokens: <Total Fee Millitokens Pending String>
5522
+ hops: [{
5523
+ channel: <Standard Format Channel Id String>
5524
+ channel_capacity: <Channel Capacity Tokens Number>
5525
+ fee: <Fee Tokens Rounded Down Number>
5526
+ fee_mtokens: <Fee Millitokens String>
5527
+ forward: <Forward Tokens Number>
5528
+ forward_mtokens: <Forward Millitokens String>
5529
+ public_key: <Public Key Hex String>
5530
+ timeout: <Timeout Block Height Number>
5531
+ }]
5532
+ mtokens: <Total Millitokens Pending String>
5533
+ safe_fee: <Total Fee Tokens Pending Rounded Up Number>
5534
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5535
+ timeout: <Expiration Block Height Number>
5536
+ }]
5537
+ safe_tokens: <Total Tokens Pending, Rounded Up Number>
5538
+ [timeout]: <Expiration Block Height Number>
5539
+ tokens: <Total Tokens Pending Rounded Down Number>
5540
+ }
5541
+
5542
+ @event 'routing_failure'
5543
+ {
5544
+ [channel]: <Standard Format Channel Id String>
5545
+ index: <Failure Index Number>
5546
+ [mtokens]: <Millitokens String>
5547
+ [public_key]: <Public Key Hex String>
5548
+ reason: <Failure Reason String>
5549
+ route: {
5550
+ fee: <Total Route Fee Tokens To Pay Number>
5551
+ fee_mtokens: <Total Route Fee Millitokens To Pay String>
5552
+ hops: [{
5553
+ channel: <Standard Format Channel Id String>
5554
+ channel_capacity: <Channel Capacity Tokens Number>
5555
+ fee: <Fee Number>
5556
+ fee_mtokens: <Fee Millitokens String>
5557
+ forward: <Forward Tokens Number>
5558
+ forward_mtokens: <Forward Millitokens String>
5559
+ public_key: <Public Key Hex String>
5560
+ timeout: <Timeout Block Height Number>
5561
+ }]
5562
+ mtokens: <Total Route Millitokens String>
5563
+ [payment]: <Payment Identifier Hex String>
5564
+ timeout: <Expiration Block Height Number>
5565
+ tokens: <Total Route Tokens Number>
5566
+ [total_mtokens]: <Total Millitokens String>
5567
+ }
5568
+ }
5410
5569
 
5411
5570
  Example:
5412
5571
 
@@ -5605,7 +5764,7 @@ Subscribe to incoming peer messages
5605
5764
 
5606
5765
  Requires `offchain:read` permission
5607
5766
 
5608
- This method is not supported in LND 0.13.3 and below
5767
+ This method is not supported in LND 0.13.4 and below
5609
5768
 
5610
5769
  {
5611
5770
  lnd: <Authenticated LND API Object>
@@ -5851,7 +6010,7 @@ Requires `macaroon:write` permission
5851
6010
 
5852
6011
  LND must be running with "RPC middleware" enabled: `rpcmiddleware.enable=1`
5853
6012
 
5854
- This method is not supported in LND 0.13.3 and below
6013
+ This method is not supported in LND 0.13.4 and below
5855
6014
 
5856
6015
  {
5857
6016
  [id]: <RPC Middleware Interception Name String>
@@ -5870,7 +6029,7 @@ This method is not supported in LND 0.13.3 and below
5870
6029
  @event 'close_channel_request'
5871
6030
  {
5872
6031
  accept: ({}, [cbk]) => {}
5873
- id: <Request Id Number>
6032
+ id: <Message Id Number>
5874
6033
  macaroon: <Base64 Encoded Macaroon String>
5875
6034
  reject: ({message: <Rejection String>}, [cbk]) => {}
5876
6035
  request: {
@@ -5888,7 +6047,7 @@ This method is not supported in LND 0.13.3 and below
5888
6047
  @event 'open_channel_request'
5889
6048
  {
5890
6049
  accept: ({}, [cbk]) => {}
5891
- id: <Request Id Number>
6050
+ id: <Message Id Number>
5892
6051
  macaroon: <Base64 Encoded Macaroon String>
5893
6052
  reject: ({message: <Rejection String>}, [cbk]) => {}
5894
6053
  request: {
@@ -5909,7 +6068,7 @@ This method is not supported in LND 0.13.3 and below
5909
6068
  @event 'pay_via_route_request'
5910
6069
  {
5911
6070
  accept: ({}, [cbk]) => {}
5912
- id: <Request Id Number>
6071
+ id: <Message Id Number>
5913
6072
  macaroon: <Base64 Encoded Macaroon String>
5914
6073
  reject: ({message: <Rejection String>}, [cbk]) => {}
5915
6074
  request: {
@@ -5939,14 +6098,16 @@ This method is not supported in LND 0.13.3 and below
5939
6098
 
5940
6099
  @event 'request'
5941
6100
  {
5942
- id: <Request Id Number>
6101
+ call: <Call Identifier Number>
6102
+ id: <Message Id Number>
5943
6103
  [macaroon]: <Base64 Encoded Macaroon String>
5944
6104
  [uri]: <RPC URI String>
5945
6105
  }
5946
6106
 
5947
6107
  @event 'response'
5948
6108
  {
5949
- id: <Request Id Number>
6109
+ call: <Call Identifier Number>
6110
+ id: <Message Id Number>
5950
6111
  [macaroon]: <Base64 Encoded Macaroon String>
5951
6112
  [uri]: <RPC URI String>
5952
6113
  }
@@ -6016,7 +6177,7 @@ Subscribe to wallet status events
6016
6177
 
6017
6178
  This method is not supported on LND 0.12.1 and below
6018
6179
 
6019
- `ready` is not supported on LND 0.13.3 and below
6180
+ `ready` is not supported on LND 0.13.4 and below
6020
6181
 
6021
6182
  {
6022
6183
  lnd: <Unauthenticated LND API Object>
@@ -6256,7 +6417,7 @@ Setting both `base_fee_tokens` and `base_fee_mtokens` is not supported
6256
6417
 
6257
6418
  Requires `offchain:write` permission
6258
6419
 
6259
- `failures` are not returned on LND 0.13.3 and below
6420
+ `failures` are not returned on LND 0.13.4 and below
6260
6421
 
6261
6422
  {
6262
6423
  [base_fee_mtokens]: <Base Fee Millitokens Charged String>
@@ -6293,7 +6454,7 @@ await updateRoutingFees({lnd, fee_rate: 2500});
6293
6454
 
6294
6455
  Verify an access token has a given set of permissions
6295
6456
 
6296
- Note: this method is not supported in LND versions 0.13.3 and below
6457
+ Note: this method is not supported in LND versions 0.13.4 and below
6297
6458
 
6298
6459
  Requires `macaroon:read` permission
6299
6460
 
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  "bolt07": "1.7.4",
11
11
  "cors": "2.8.5",
12
12
  "express": "4.17.1",
13
- "invoices": "2.0.1",
14
- "lightning": "4.13.1",
13
+ "invoices": "2.0.2",
14
+ "lightning": "4.14.4",
15
15
  "macaroon": "3.0.4",
16
16
  "morgan": "1.10.0",
17
17
  "ws": "8.2.3"
@@ -23,8 +23,9 @@
23
23
  "async": "3.2.2",
24
24
  "asyncjs-util": "1.2.7",
25
25
  "bip66": "1.1.5",
26
- "bitcoinjs-lib": "5.2.0",
26
+ "bitcoinjs-lib": "6.0.0",
27
27
  "bn.js": "5.2.0",
28
+ "ecpair": "1.0.1",
28
29
  "portfinder": "1.0.28",
29
30
  "psbt": "1.1.10",
30
31
  "rimraf": "3.0.2",
@@ -61,5 +62,5 @@
61
62
  "tower_server-integration-tests": "tap --no-coverage test/tower_serverrpc-integration/*.js",
62
63
  "wallet-integration-tests": "tap --no-coverage test/walletrpc-integration/*.js"
63
64
  },
64
- "version": "52.14.3"
65
+ "version": "52.16.1"
65
66
  }
@@ -33,7 +33,7 @@ test('Delete payment', async ({afterEach, fail, end, equal, strictSame}) => {
33
33
 
34
34
  const priorLength = (await getPayments({lnd})).payments.length;
35
35
 
36
- // LND 0.13.3 and below do not support deletePayment
36
+ // LND 0.13.4 and below do not support deletePayment
37
37
  try {
38
38
  await deletePayment({lnd, id: invoice.id});
39
39
  } catch (err) {
@@ -123,6 +123,7 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
123
123
  is_failed: true,
124
124
  is_pending: false,
125
125
  payment: undefined,
126
+ pending: undefined,
126
127
  },
127
128
  'Got failed state'
128
129
  );
@@ -15,7 +15,6 @@ test(`Get network info`, async ({end, equal}) => {
15
15
  equal(result.max_channel_size, 0, 'Maximum channel size');
16
16
  equal(result.median_channel_size, 0, 'Median channel size');
17
17
  equal(result.min_channel_size, 0, 'Minimum channel size');
18
- equal(result.node_count, 1, 'Node count');
19
18
  equal(result.not_recently_updated_policy_count, 0, 'Not updated count');
20
19
  equal(result.total_capacity, 0, 'Total capacity');
21
20
 
@@ -60,7 +60,6 @@ test(`Pay private invoice`, async ({end, equal, strictSame}) => {
60
60
  to: cluster.remote,
61
61
  });
62
62
 
63
-
64
63
  await addPeer({
65
64
  lnd,
66
65
  public_key: cluster.remote.public_key,
@@ -23,7 +23,7 @@ test(`Send peer message`, async ({end, equal, strictSame}) => {
23
23
  } catch (err) {
24
24
  const [code] = err;
25
25
 
26
- // Send message to peer is not supported on LND 0.13.3 or lower
26
+ // Send message to peer is not supported on LND 0.13.4 or lower
27
27
  if (code === 501) {
28
28
  await cluster.kill({});
29
29
 
@@ -49,13 +49,15 @@ test(`Send peer message`, async ({end, equal, strictSame}) => {
49
49
  }
50
50
  });
51
51
 
52
+ const [message] = messages;
53
+
52
54
  strictSame(
53
- messages,
54
- [{
55
+ message,
56
+ {
55
57
  message: Buffer.from('message').toString('hex'),
56
58
  public_key: cluster.control.public_key,
57
59
  type: 32768,
58
- }],
60
+ },
59
61
  'Message successfully sent to peer'
60
62
  );
61
63
 
@@ -23,7 +23,7 @@ test(`Subscribe to peer messages`, async ({end, equal, strictSame}) => {
23
23
  } catch (err) {
24
24
  const [code] = err;
25
25
 
26
- // Send message to peer is not supported on LND 0.13.3 or lower
26
+ // Send message to peer is not supported on LND 0.13.4 or lower
27
27
  if (code === 501) {
28
28
  await cluster.kill({});
29
29
 
@@ -23,7 +23,7 @@ test(`Subscribe to RPC requests`, async ({end, equal, fail, strictSame}) => {
23
23
  }
24
24
  })();
25
25
 
26
- // LND 0.13.3 and below do not support rpc interception
26
+ // LND 0.13.4 and below do not support rpc interception
27
27
  if (!spawned) {
28
28
  return end();
29
29
  }
@@ -71,7 +71,7 @@ test(`Update routing fees`, async ({end, equal, strictSame}) => {
71
71
  transaction_vout: 1,
72
72
  }];
73
73
 
74
- // Failures is not supported on LND 0.13.3 and below
74
+ // Failures is not supported on LND 0.13.4 and below
75
75
  if (!!failures.length) {
76
76
  strictSame(failures, expectedFailures, 'Got expected failures');
77
77
  }
@@ -16,7 +16,7 @@ test(`Verify access`, async ({end, equal, rejects, strictSame}) => {
16
16
 
17
17
  const {macaroon} = await grantAccess({lnd, permissions});
18
18
 
19
- // verifyAccess is not supported on LND 0.13.3 and below
19
+ // verifyAccess is not supported on LND 0.13.4 and below
20
20
  try {
21
21
  const validity = await verifyAccess({lnd, macaroon, permissions});
22
22
 
@@ -86,13 +86,18 @@ test(`Get sweep transactions`, async ({end, equal}) => {
86
86
  equal(!!transaction.confirmation_count, true, 'Sweep confirm count');
87
87
  equal(!!transaction.confirmation_height, true, 'Sweep confirm height');
88
88
  equal(!!transaction.created_at, true, 'Sweep creation date');
89
- equal(transaction.description, undefined, 'Sweep has description');
90
89
  equal(transaction.fee, undefined, 'Sweep fee is undefined');
91
90
  equal(transaction.id.length, 64, 'Sweep has transaction id');
92
91
  equal(transaction.is_confirmed, true, 'Sweep is confirmed');
93
92
  equal(transaction.output_addresses.length, 1, 'Sweep has out address');
94
93
  equal(!!transaction.transaction.length, true, 'Sweep has transaction');
95
94
 
95
+ if (!!transaction.description) {
96
+ equal(transaction.description, '0:sweep', 'Sweep has description');
97
+ } else {
98
+ equal(transaction.description, undefined, 'Sweep has description');
99
+ }
100
+
96
101
  await cluster.kill({});
97
102
 
98
103
  return end();
@@ -2,7 +2,7 @@ const {join} = require('path');
2
2
  const {spawn} = require('child_process');
3
3
 
4
4
  const asyncAuto = require('async/auto');
5
- const {ECPair} = require('bitcoinjs-lib');
5
+ const {ECPair} = require('ecpair');
6
6
  const openPortFinder = require('portfinder');
7
7
  const {networks} = require('bitcoinjs-lib');
8
8
  const {payments} = require('bitcoinjs-lib');
@@ -2,7 +2,7 @@ const {encode} = require('varuint-bitcoin');
2
2
 
3
3
  const {address} = require('bitcoinjs-lib');
4
4
  const {crypto} = require('bitcoinjs-lib');
5
- const {ECPair} = require('bitcoinjs-lib');
5
+ const {ECPair} = require('ecpair');
6
6
  const {networks} = require('bitcoinjs-lib');
7
7
  const {payments} = require('bitcoinjs-lib');
8
8
  const {script} = require('bitcoinjs-lib');
@@ -6,7 +6,7 @@ const {spawn} = require('child_process');
6
6
  const asyncAuto = require('async/auto');
7
7
  const asyncMapSeries = require('async/mapSeries');
8
8
  const asyncRetry = require('async/retry');
9
- const {ECPair} = require('bitcoinjs-lib');
9
+ const {ECPair} = require('ecpair');
10
10
  const {networks} = require('bitcoinjs-lib');
11
11
  const openPortFinder = require('portfinder');
12
12
 
@@ -2,7 +2,7 @@ const asyncAuto = require('async/auto');
2
2
  const asyncMap = require('async/map');
3
3
  const asyncTimesSeries = require('async/timesSeries');
4
4
  const asyncRetry = require('async/retry');
5
- const {ECPair} = require('bitcoinjs-lib');
5
+ const {ECPair} = require('ecpair');
6
6
  const {networks} = require('bitcoinjs-lib');
7
7
  const {payments} = require('bitcoinjs-lib');
8
8
  const {returnResult} = require('asyncjs-util');
@@ -7,7 +7,7 @@ const asyncAuto = require('async/auto');
7
7
  const asyncMap = require('async/map');
8
8
  const asyncMapSeries = require('async/mapSeries');
9
9
  const asyncRetry = require('async/retry');
10
- const {ECPair} = require('bitcoinjs-lib');
10
+ const {ECPair} = require('ecpair');
11
11
  const {networks} = require('bitcoinjs-lib');
12
12
  const openPortFinder = require('portfinder');
13
13
 
@@ -4,8 +4,6 @@ const {test} = require('@alexbosworth/tap');
4
4
  const {addPeer} = require('./../../');
5
5
  const {createCluster} = require('./../macros');
6
6
  const {createInvoice} = require('./../../');
7
- const {deleteForwardingReputations} = require('./../../');
8
- const {delay} = require('./../macros');
9
7
  const {getChannels} = require('./../../');
10
8
  const {getForwardingReputations} = require('./../../');
11
9
  const {payViaRoutes} = require('./../../');
@@ -1,3 +1,4 @@
1
+ const {once} = require('events');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {addPeer} = require('./../../');
@@ -6,16 +7,18 @@ const {createInvoice} = require('./../../');
6
7
  const {deleteForwardingReputations} = require('./../../');
7
8
  const {getHeight} = require('./../../');
8
9
  const {getInvoice} = require('./../../');
10
+ const {getPayment} = require('./../../');
9
11
  const {getWalletVersion} = require('./../../');
10
12
  const {payViaPaymentRequest} = require('./../../');
11
13
  const {subscribeToForwardRequests} = require('./../../');
14
+ const {subscribeToPayViaRequest} = require('./../../');
12
15
  const {setupChannel} = require('./../macros');
13
16
  const {waitForRoute} = require('./../macros');
14
17
 
15
18
  const tokens = 100;
16
19
 
17
20
  // Paying an invoice should settle the invoice
18
- test(`Pay via payment request`, async ({end, equal, rejects}) => {
21
+ test(`Pay via payment request`, async ({end, equal, rejects, strictSame}) => {
19
22
  const cluster = await createCluster({});
20
23
 
21
24
  const {lnd} = cluster.control;
@@ -61,6 +64,67 @@ test(`Pay via payment request`, async ({end, equal, rejects}) => {
61
64
  );
62
65
 
63
66
  sub.removeAllListeners();
67
+
68
+ await deleteForwardingReputations({lnd});
69
+
70
+ const sub2 = subscribeToForwardRequests({lnd: cluster.target.lnd});
71
+
72
+ sub2.on('forward_request', forward => forward.reject());
73
+
74
+ const failures = [];
75
+ const paying = [];
76
+
77
+ const pay = subscribeToPayViaRequest({lnd, request: invoice.request});
78
+
79
+ pay.on('paying', pending => paying.push(pending));
80
+ pay.on('routing_failure', failure => failures.push(failure));
81
+
82
+ await once(pay, 'failed');
83
+
84
+ strictSame(
85
+ failures,
86
+ [{
87
+ channel: channel.id,
88
+ index: 1,
89
+ mtokens: '101000',
90
+ public_key: cluster.target.public_key,
91
+ reason: 'TemporaryChannelFailure',
92
+ route: {
93
+ fee: 1,
94
+ fee_mtokens: '1000',
95
+ hops: [
96
+ {
97
+ channel: channel.id,
98
+ channel_capacity: 1e6,
99
+ fee: 1,
100
+ fee_mtokens: '1000',
101
+ forward: 100,
102
+ forward_mtokens: '100000',
103
+ public_key: cluster.target.public_key,
104
+ timeout: 497,
105
+ },
106
+ {
107
+ channel: remoteChan.id,
108
+ channel_capacity: 1e6,
109
+ fee: 0,
110
+ fee_mtokens: '0',
111
+ forward: 100,
112
+ forward_mtokens: '100000',
113
+ public_key: cluster.remote.public_key,
114
+ timeout: 497,
115
+ },
116
+ ],
117
+ mtokens: '101000',
118
+ payment: invoice.payment,
119
+ timeout: 537,
120
+ tokens: 101,
121
+ total_mtokens: '100000',
122
+ },
123
+ }],
124
+ 'Failure is emitted'
125
+ );
126
+
127
+ sub2.removeAllListeners();
64
128
  }
65
129
 
66
130
  await deleteForwardingReputations({lnd});
@@ -71,6 +135,53 @@ test(`Pay via payment request`, async ({end, equal, rejects}) => {
71
135
  const sub = subscribeToForwardRequests({lnd: cluster.target.lnd});
72
136
 
73
137
  sub.once('forward_request', async forward => {
138
+ const {pending} = await getPayment({lnd, id: invoice.id});
139
+
140
+ equal(pending.destination, cluster.remote.public_key, 'Pending remote');
141
+ equal(!!pending.created_at, true, 'Has creation date');
142
+ equal(pending.id, invoice.id, 'Payment id is present');
143
+ equal(pending.mtokens, invoice.mtokens, 'Pending payment mtokens');
144
+
145
+ strictSame(
146
+ pending.paths,
147
+ [{
148
+ fee: 1,
149
+ fee_mtokens: '1000',
150
+ hops: [
151
+ {
152
+ channel: forward.in_channel,
153
+ channel_capacity: 1e6,
154
+ fee: 1,
155
+ fee_mtokens: '1000',
156
+ forward: 100,
157
+ forward_mtokens: '100000',
158
+ public_key: cluster.target.public_key,
159
+ timeout: 497,
160
+ },
161
+ {
162
+ channel: forward.out_channel,
163
+ channel_capacity: 1e6,
164
+ fee: 0,
165
+ fee_mtokens: '0',
166
+ forward: 100,
167
+ forward_mtokens: '100000',
168
+ public_key: cluster.remote.public_key,
169
+ timeout: 497,
170
+ },
171
+ ],
172
+ mtokens: '101000',
173
+ payment: invoice.payment,
174
+ timeout: 537,
175
+ tokens: 101,
176
+ total_mtokens: '100000',
177
+ }],
178
+ 'Paths are present'
179
+ );
180
+
181
+ equal(pending.request, invoice.request, 'Pending pay of request');
182
+ equal(pending.timeout, 537, 'Pending timeout');
183
+ equal(pending.tokens, invoice.tokens, 'Pending pay of invoice tokens');
184
+
74
185
  const info = await getHeight({lnd: cluster.target.lnd});
75
186
 
76
187
  equal(forward.cltv_delta, 40, 'Forward has CLTV delta');
@@ -78,7 +189,7 @@ test(`Pay via payment request`, async ({end, equal, rejects}) => {
78
189
  equal(forward.fee_mtokens, '1000', 'Forward has precise routing fee');
79
190
  equal(forward.hash, invoice.id, 'Forward has payment hash');
80
191
  equal(forward.in_channel, channel.id, 'Forward has inbound channel')
81
- equal(forward.in_payment, [invoice].length, 'Forward has payment index');
192
+ equal(forward.in_payment, 2, 'Forward has payment index');
82
193
  equal(forward.messages.length, [].length, 'Forward has no messages');
83
194
  equal(forward.mtokens, invoice.mtokens, 'Forward has tokens out');
84
195
  equal(forward.out_channel, remoteChan.id, 'Forward has outbound chan');
@@ -54,7 +54,7 @@ test(`Subscribe to past payment`, async ({end, rejects, strictSame}) => {
54
54
 
55
55
  [sub, sub2].forEach(n => n.removeAllListeners());
56
56
 
57
- // LND 0.13.3 and below do not support preimages in forward notifications
57
+ // LND 0.13.4 and below do not support preimages in forward notifications
58
58
  if (!!sent && !!sent.secret) {
59
59
  strictSame(got, payment, 'Payment subscription notifies of payment');
60
60
  }