lightning 10.10.0 → 10.10.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,5 +1,10 @@
1
1
  # Versions
2
2
 
3
+ ## 10.10.1
4
+
5
+ - `closeChannel`, `openChannel`, `sendToChainAddress`, `sendToChainAddresses`:
6
+ Add default chain fee conf target when no chain fee is specified
7
+
3
8
  ## 10.10.0
4
9
 
5
10
  - `getPendingSweeps`: Add method to get the list of pending outpoints to sweep
@@ -10,7 +10,7 @@ const hashAsTxId = hash => hash.slice().reverse().toString('hex');
10
10
  delivery_address: <Request Cooperative Close Address String>
11
11
  force: <Force Close Channel Bool>
12
12
  max_fee_per_vbyte: <Max Fee Tokens Per VByte String>
13
- sat_per_byte: <Chain Fee Tokens Per Virtual Byte String>
13
+ sat_per_vbyte: <Chain Fee Tokens Per Virtual Byte String>
14
14
  target_conf: <Target Confirm Within N Blocks Number>
15
15
  }
16
16
 
@@ -31,7 +31,7 @@ module.exports = args => {
31
31
  is_force_close: args.force || undefined,
32
32
  max_tokens_per_vbyte: Number(args.max_fee_per_vbyte) || undefined,
33
33
  target_confirmations: args.target_conf || undefined,
34
- tokens_per_vbyte: Number(args.sat_per_byte) || undefined,
34
+ tokens_per_vbyte: Number(args.sat_per_vbyte) || undefined,
35
35
  transaction_id: hashAsTxId(args.channel_point.funding_txid_bytes),
36
36
  transaction_vout: args.channel_point.output_index,
37
37
  };
@@ -142,7 +142,7 @@ module.exports = (args, cbk) => {
142
142
  backups_count: session.num_backups,
143
143
  max_backups_count: session.max_backups,
144
144
  pending_backups_count: session.num_pending_backups,
145
- sweep_tokens_per_vbyte: session.sweep_sat_per_byte,
145
+ sweep_tokens_per_vbyte: session.sweep_sat_per_vbyte,
146
146
  })),
147
147
  sockets: tower.addresses,
148
148
  }));
@@ -183,13 +183,13 @@ module.exports = (args, cbk) => {
183
183
  return cbk([503, 'ExpectedMaxUpdateCountInWatchtowerPolicyInfo']);
184
184
  }
185
185
 
186
- if (res.sweep_sat_per_byte === undefined) {
186
+ if (res.sweep_sat_per_vbyte === undefined) {
187
187
  return cbk([503, 'ExpectedSweepSatsPerByteInWatchtowerPolicy']);
188
188
  }
189
189
 
190
190
  return cbk(null, {
191
191
  max_session_update_count: res.max_updates,
192
- sweep_tokens_per_vbyte: res.sweep_sat_per_byte,
192
+ sweep_tokens_per_vbyte: res.sweep_sat_per_vbyte,
193
193
  });
194
194
  });
195
195
  }],
@@ -6,6 +6,7 @@ const {addPeer} = require('./../peers');
6
6
  const {getChannel} = require('./../info');
7
7
  const {isLnd} = require('./../../lnd_requests');
8
8
 
9
+ const defaultConfTarget = 6;
9
10
  const method = 'closeChannel';
10
11
  const type = 'default';
11
12
 
@@ -107,8 +108,28 @@ module.exports = (args, cbk) => {
107
108
  return getChannel({id: args.id, lnd: args.lnd}, cbk);
108
109
  }],
109
110
 
111
+ // Determine what the confirmations to confirm should be
112
+ targetConf: ['validate', ({}, cbk) => {
113
+ // Exit early when a chain fee cannot be specified
114
+ if (!!args.is_force_close) {
115
+ return cbk();
116
+ }
117
+
118
+ // Exit early when there is a chain fee rate specified
119
+ if (!!args.tokens_per_vbyte) {
120
+ return cbk();
121
+ }
122
+
123
+ return cbk(null, args.target_confirmations || defaultConfTarget);
124
+ }],
125
+
110
126
  // Close out the channel
111
- closeChannel: ['addPeer', 'getChannel', ({getChannel}, cbk) => {
127
+ closeChannel: [
128
+ 'addPeer',
129
+ 'getChannel',
130
+ 'targetConf',
131
+ ({getChannel, targetConf}, cbk) =>
132
+ {
112
133
  let isFinished = false;
113
134
  const tokensPerVByte = args.tokens_per_vbyte;
114
135
  const transactionId = Buffer.from(getChannel.transaction_id, 'hex');
@@ -122,8 +143,8 @@ module.exports = (args, cbk) => {
122
143
  delivery_address: args.address || undefined,
123
144
  force: !!args.is_force_close,
124
145
  max_fee_per_vbyte: args.max_tokens_per_vbyte || undefined,
125
- sat_per_byte: !!tokensPerVByte ? tokensPerVByte : undefined,
126
- target_conf: args.target_confirmations || undefined,
146
+ sat_per_vbyte: !!tokensPerVByte ? tokensPerVByte : undefined,
147
+ target_conf: targetConf,
127
148
  });
128
149
 
129
150
  const finished = (err, res) => {
@@ -92,21 +92,10 @@ module.exports = (args, cbk) => {
92
92
  return cbk([503, 'ExpectedChainFeeInResponseToChainFeeEstimate']);
93
93
  }
94
94
 
95
- if (!res.feerate_sat_per_byte) {
96
- return cbk([503, 'ExpectedFeeRateValueInChainFeeEstimateQuery']);
97
- }
98
-
99
- const fee = Number(res.fee_sat);
100
-
101
- // Exit early in LND 0.12.1 and below that do not support sat/vbyte
102
- if (!hasNumber(res.sat_per_vbyte)) {
103
- return cbk(null, {
104
- fee,
105
- tokens_per_vbyte: Number(res.feerate_sat_per_byte),
106
- });
107
- }
108
-
109
- return cbk(null, {fee, tokens_per_vbyte: Number(res.sat_per_vbyte)});
95
+ return cbk(null, {
96
+ fee: Number(res.fee_sat),
97
+ tokens_per_vbyte: Number(res.sat_per_vbyte),
98
+ });
110
99
  });
111
100
  }],
112
101
  },
@@ -5,6 +5,7 @@ const {addPeer} = require('./../peers');
5
5
  const {isLnd} = require('./../../lnd_requests');
6
6
 
7
7
  const anchors = 'ANCHORS';
8
+ const defaultChainFeeConfTarget = 6;
8
9
  const defaultMinConfs = 1;
9
10
  const defaultMinHtlcMtokens = '1';
10
11
  const errMemoLength = /^provided memo \(.*\) is of length \d*, exceeds (\d*)$/;
@@ -170,7 +171,9 @@ module.exports = (args, cbk) => {
170
171
  };
171
172
 
172
173
  if (!!args.chain_fee_tokens_per_vbyte) {
173
- options.sat_per_byte = args.chain_fee_tokens_per_vbyte;
174
+ options.sat_per_vbyte = args.chain_fee_tokens_per_vbyte;
175
+ } else {
176
+ options.target_conf = defaultChainFeeConfTarget;
174
177
  }
175
178
 
176
179
  if (!!args.cooperative_close_address) {
@@ -54,7 +54,7 @@ module.exports = (args, cbk) => {
54
54
  feeRate: ['validate', ({}, cbk) => {
55
55
  // Exit early when the fee rate is specified
56
56
  if (!!args.fee_tokens_per_vbyte) {
57
- return cbk(null, {sat_per_byte: args.fee_tokens_per_vbyte});
57
+ return cbk(null, {sat_per_vbyte: args.fee_tokens_per_vbyte});
58
58
  }
59
59
 
60
60
  // Exit early when the confirmation target is specified
@@ -74,7 +74,7 @@ module.exports = (args, cbk) => {
74
74
  output_index: args.transaction_vout,
75
75
  txid_str: args.transaction_id,
76
76
  },
77
- sat_per_byte: feeRate.sat_per_byte,
77
+ sat_per_vbyte: feeRate.sat_per_vbyte,
78
78
  target_conf: feeRate.target_conf,
79
79
  },
80
80
  (err, res) => {
@@ -3,6 +3,7 @@ const {returnResult} = require('asyncjs-util');
3
3
 
4
4
  const {isLnd} = require('./../../lnd_requests');
5
5
 
6
+ const defaultConfTarget = 6;
6
7
  const initialConfirmationCount = 0;
7
8
  const {isArray} = Array;
8
9
  const {isInteger} = Number;
@@ -83,18 +84,28 @@ module.exports = (args, cbk) => {
83
84
  return cbk();
84
85
  },
85
86
 
87
+ // Determine what the confirmations to confirm should be
88
+ targetConf: ['validate', ({}, cbk) => {
89
+ // Exit early when there is a chain fee rate specified
90
+ if (!!args.fee_tokens_per_vbyte) {
91
+ return cbk();
92
+ }
93
+
94
+ return cbk(null, args.target_confirmations || defaultConfTarget);
95
+ }],
96
+
86
97
  // Send coins
87
- send: ['validate', ({}, cbk) => {
98
+ send: ['targetConf', ({targetConf}, cbk) => {
88
99
  return args.lnd.default.sendCoins({
89
100
  addr: args.address,
90
101
  amount: args.tokens || undefined,
91
102
  coin_selection_strategy: strategy(args.utxo_selection),
92
103
  min_confs: args.utxo_confirmations || undefined,
93
104
  label: args.description || undefined,
94
- sat_per_byte: args.fee_tokens_per_vbyte || undefined,
105
+ sat_per_vbyte: args.fee_tokens_per_vbyte || undefined,
95
106
  send_all: args.is_send_all || undefined,
96
107
  spend_unconfirmed: args.utxo_confirmations === unconfirmedConfCount,
97
- target_conf: args.target_confirmations || undefined,
108
+ target_conf: targetConf,
98
109
  },
99
110
  (err, res) => {
100
111
  if (!!err && err.details === lowBalanceErr) {
@@ -3,6 +3,7 @@ const {returnResult} = require('asyncjs-util');
3
3
 
4
4
  const {isLnd} = require('./../../lnd_requests');
5
5
 
6
+ const defaultConfTarget = 6;
6
7
  const initialConfirmationCount = 0;
7
8
  const {isArray} = Array;
8
9
  const method = 'sendMany';
@@ -74,7 +75,17 @@ module.exports = (args, cbk) => {
74
75
  return cbk();
75
76
  },
76
77
 
77
- send: ['validate', ({}, cbk) => {
78
+ // Determine what the confirmations to confirm should be
79
+ targetConf: ['validate', ({}, cbk) => {
80
+ // Exit early when there is a chain fee rate specified
81
+ if (!!args.fee_tokens_per_vbyte) {
82
+ return cbk();
83
+ }
84
+
85
+ return cbk(null, args.target_confirmations || defaultConfTarget);
86
+ }],
87
+
88
+ send: ['targetConf', ({targetConf}, cbk) => {
78
89
  const AddrToAmount = {};
79
90
 
80
91
  args.send_to
@@ -85,9 +96,9 @@ module.exports = (args, cbk) => {
85
96
  coin_selection_strategy: strategy(args.utxo_selection),
86
97
  label: args.description || undefined,
87
98
  min_confs: args.utxo_confirmations || undefined,
88
- sat_per_byte: args.fee_tokens_per_vbyte || undefined,
99
+ sat_per_vbyte: args.fee_tokens_per_vbyte || undefined,
89
100
  spend_unconfirmed: args.utxo_confirmations === unconfirmedConfCount,
90
- target_conf: args.target_confirmations || undefined,
101
+ target_conf: targetConf,
91
102
  };
92
103
 
93
104
  return args.lnd.default.sendMany(send, (err, res) => {
package/package.json CHANGED
@@ -53,5 +53,5 @@
53
53
  "directory": "test/typescript"
54
54
  },
55
55
  "types": "index.d.ts",
56
- "version": "10.10.0"
56
+ "version": "10.10.1"
57
57
  }
@@ -12,7 +12,7 @@ const makeArgs = overrides => {
12
12
  },
13
13
  delivery_address: 'delivery_address',
14
14
  force: true,
15
- sat_per_byte: '1',
15
+ sat_per_vbyte: '1',
16
16
  target_conf: 1,
17
17
  };
18
18
 
@@ -47,7 +47,7 @@ const tests = [
47
47
  args: makeArgs({
48
48
  delivery_address: '',
49
49
  force: false,
50
- sat_per_byte: '0',
50
+ sat_per_vbyte: '0',
51
51
  target_conf: 0,
52
52
  }),
53
53
  description: 'Defaults are selected',
@@ -19,7 +19,7 @@ const tests = [
19
19
  },
20
20
  delivery_address: 'delivery_address',
21
21
  force: true,
22
- sat_per_byte: '1',
22
+ sat_per_vbyte: '1',
23
23
  target_conf: 1,
24
24
  }),
25
25
  },
@@ -28,7 +28,7 @@ const makeTower = overrides => {
28
28
  max_backups: 1,
29
29
  num_backups: 1,
30
30
  num_pending_backups: 1,
31
- sweep_sat_per_byte: 1,
31
+ sweep_sat_per_vbyte: 1,
32
32
  }],
33
33
  };
34
34
 
@@ -60,7 +60,7 @@ const makeLnd = args => {
60
60
  return cbk(null, args.policyRes);
61
61
  }
62
62
 
63
- return cbk(null, {max_updates: 1, sweep_sat_per_byte: 1});
63
+ return cbk(null, {max_updates: 1, sweep_sat_per_vbyte: 1});
64
64
  },
65
65
  stats: ({}, cbk) => {
66
66
  if (!!args.statsErr) {
@@ -57,52 +57,12 @@ const tests = [
57
57
  description: 'Fee sat is expected in estimate fee response',
58
58
  error: [503, 'ExpectedChainFeeInResponseToChainFeeEstimate'],
59
59
  },
60
- {
61
- args: {
62
- lnd: {default: {estimateFee: ({}, cbk) => cbk(null, {fee_sat: '1'})}},
63
- send_to: [{address: 'address', tokens: 1}],
64
- },
65
- description: 'Fee rate is expected in estimate fee response',
66
- error: [503, 'ExpectedFeeRateValueInChainFeeEstimateQuery'],
67
- },
68
- {
69
- args: {
70
- lnd: {
71
- default: {
72
- estimateFee: ({}, cbk) => cbk(null, {
73
- fee_sat: '1',
74
- feerate_sat_per_byte: '1',
75
- }),
76
- },
77
- },
78
- send_to: [{address: 'address', tokens: 1}],
79
- },
80
- description: 'Fee rate and fee are given in chain response',
81
- expected: {fee: 1, tokens_per_vbyte: 1},
82
- },
83
- {
84
- args: {
85
- lnd: {
86
- default: {
87
- estimateFee: ({}, cbk) => cbk(null, {
88
- fee_sat: '1',
89
- feerate_sat_per_byte: '1',
90
- }),
91
- },
92
- },
93
- send_to: [{address: 'address', tokens: 1}],
94
- utxo_confirmations: 0,
95
- },
96
- description: 'Passing 0 UTXO confirmations is supported',
97
- expected: {fee: 1, tokens_per_vbyte: 1},
98
- },
99
60
  {
100
61
  args: {
101
62
  lnd: {
102
63
  default: {
103
64
  estimateFee: ({}, cbk) => cbk(null, {
104
65
  fee_sat: '1',
105
- feerate_sat_per_byte: '1',
106
66
  sat_per_vbyte: '2',
107
67
  }),
108
68
  },
@@ -119,7 +79,6 @@ const tests = [
119
79
  default: {
120
80
  estimateFee: ({}, cbk) => cbk(null, {
121
81
  fee_sat: '1',
122
- feerate_sat_per_byte: '1',
123
82
  sat_per_vbyte: '2',
124
83
  }),
125
84
  },
@@ -1,4 +1,4 @@
1
- const {deepStrictEqual} = require('node:assert').strict;
1
+ const {deepEqual} = require('node:assert').strict;
2
2
  const {rejects} = require('node:assert').strict;
3
3
  const test = require('node:test');
4
4
 
@@ -22,6 +22,20 @@ const makeArgs = overrides => {
22
22
  return args;
23
23
  };
24
24
 
25
+ const makeExpected = overrides => {
26
+ const args = {
27
+ confirmation_count: 0,
28
+ id: Buffer.alloc(32).toString('hex'),
29
+ is_confirmed: false,
30
+ is_outgoing: true,
31
+ tokens: 1,
32
+ };
33
+
34
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
35
+
36
+ return args;
37
+ };
38
+
25
39
  const tests = [
26
40
  {
27
41
  args: makeArgs({address: undefined}),
@@ -89,35 +103,17 @@ const tests = [
89
103
  {
90
104
  args: makeArgs({log: console.log, wss: [{clients: [null]}]}),
91
105
  description: 'Send coins with null wss client',
92
- expected: {
93
- confirmation_count: 0,
94
- id: Buffer.alloc(32).toString('hex'),
95
- is_confirmed: false,
96
- is_outgoing: true,
97
- tokens: 1,
98
- },
106
+ expected: makeExpected({}),
99
107
  },
100
108
  {
101
109
  args: makeArgs({log: console.log, wss: [{clients: [{}]}]}),
102
110
  description: 'Send coins with no ready state',
103
- expected: {
104
- confirmation_count: 0,
105
- id: Buffer.alloc(32).toString('hex'),
106
- is_confirmed: false,
107
- is_outgoing: true,
108
- tokens: 1,
109
- },
111
+ expected: makeExpected({}),
110
112
  },
111
113
  {
112
114
  args: makeArgs({log: () => {}, wss: [{clients: [{readyState: 1}]}]}),
113
115
  description: 'Send coins with no send method',
114
- expected: {
115
- confirmation_count: 0,
116
- id: Buffer.alloc(32).toString('hex'),
117
- is_confirmed: false,
118
- is_outgoing: true,
119
- tokens: 1,
120
- },
116
+ expected: makeExpected({}),
121
117
  },
122
118
  {
123
119
  args: makeArgs({
@@ -127,35 +123,22 @@ const tests = [
127
123
  tokens: undefined,
128
124
  }),
129
125
  description: 'Send coins with broadcast',
130
- expected: {
131
- confirmation_count: 0,
132
- id: Buffer.alloc(32).toString('hex'),
133
- is_confirmed: false,
134
- is_outgoing: true,
135
- tokens: undefined,
136
- },
126
+ expected: makeExpected({tokens: undefined}),
137
127
  },
138
128
  {
139
129
  args: makeArgs({}),
140
130
  description: 'Send coins',
141
- expected: {
142
- confirmation_count: 0,
143
- id: Buffer.alloc(32).toString('hex'),
144
- is_confirmed: false,
145
- is_outgoing: true,
146
- tokens: 1,
147
- },
131
+ expected: makeExpected({}),
132
+ },
133
+ {
134
+ args: makeArgs({fee_tokens_per_vbyte: 1}),
135
+ description: 'Send coins with a fee rate',
136
+ expected: makeExpected({}),
148
137
  },
149
138
  {
150
139
  args: makeArgs({utxo_selection: 'random'}),
151
140
  description: 'Send coins with coin selection',
152
- expected: {
153
- confirmation_count: 0,
154
- id: Buffer.alloc(32).toString('hex'),
155
- is_confirmed: false,
156
- is_outgoing: true,
157
- tokens: 1,
158
- },
141
+ expected: makeExpected({}),
159
142
  },
160
143
  ];
161
144
 
@@ -166,7 +149,7 @@ tests.forEach(({args, description, error, expected}) => {
166
149
  } else {
167
150
  const res = await sendToChainAddress(args);
168
151
 
169
- deepStrictEqual(res, expected, 'Got expected result');
152
+ deepEqual(res, expected, 'Got expected result');
170
153
  }
171
154
 
172
155
  return;
@@ -21,6 +21,20 @@ const makeArgs = overrides => {
21
21
  return args;
22
22
  };
23
23
 
24
+ const makeExpected = overrides => {
25
+ const args = {
26
+ confirmation_count: 0,
27
+ id: Buffer.alloc(32).toString('hex'),
28
+ is_confirmed: false,
29
+ is_outgoing: true,
30
+ tokens: 1,
31
+ };
32
+
33
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
34
+
35
+ return args;
36
+ };
37
+
24
38
  const tests = [
25
39
  {
26
40
  args: makeArgs({lnd: undefined}),
@@ -75,35 +89,17 @@ const tests = [
75
89
  {
76
90
  args: makeArgs({log: console.log, wss: [{clients: [null]}]}),
77
91
  description: 'Send coins with null wss client',
78
- expected: {
79
- confirmation_count: 0,
80
- id: Buffer.alloc(32).toString('hex'),
81
- is_confirmed: false,
82
- is_outgoing: true,
83
- tokens: 1,
84
- },
92
+ expected: makeExpected({}),
85
93
  },
86
94
  {
87
95
  args: makeArgs({log: console.log, wss: [{clients: [{}]}]}),
88
96
  description: 'Send coins with no ready state',
89
- expected: {
90
- confirmation_count: 0,
91
- id: Buffer.alloc(32).toString('hex'),
92
- is_confirmed: false,
93
- is_outgoing: true,
94
- tokens: 1,
95
- },
97
+ expected: makeExpected({}),
96
98
  },
97
99
  {
98
100
  args: makeArgs({log: () => {}, wss: [{clients: [{readyState: 1}]}]}),
99
101
  description: 'Send coins with no send method',
100
- expected: {
101
- confirmation_count: 0,
102
- id: Buffer.alloc(32).toString('hex'),
103
- is_confirmed: false,
104
- is_outgoing: true,
105
- tokens: 1,
106
- },
102
+ expected: makeExpected({}),
107
103
  },
108
104
  {
109
105
  args: makeArgs({
@@ -111,35 +107,22 @@ const tests = [
111
107
  wss: [{clients: [{readyState: 1, send: () => {}}]}],
112
108
  }),
113
109
  description: 'Send coins with broadcast',
114
- expected: {
115
- confirmation_count: 0,
116
- id: Buffer.alloc(32).toString('hex'),
117
- is_confirmed: false,
118
- is_outgoing: true,
119
- tokens: 1,
120
- },
110
+ expected: makeExpected({}),
121
111
  },
122
112
  {
123
113
  args: makeArgs({}),
124
114
  description: 'Send coins',
125
- expected: {
126
- confirmation_count: 0,
127
- id: Buffer.alloc(32).toString('hex'),
128
- is_confirmed: false,
129
- is_outgoing: true,
130
- tokens: 1,
131
- },
115
+ expected: makeExpected({}),
116
+ },
117
+ {
118
+ args: makeArgs({fee_tokens_per_vbyte: 1}),
119
+ description: 'Send coins with fee rate',
120
+ expected: makeExpected({}),
132
121
  },
133
122
  {
134
123
  args: makeArgs({utxo_selection: 'random'}),
135
124
  description: 'Send coins with coin selection',
136
- expected: {
137
- confirmation_count: 0,
138
- id: Buffer.alloc(32).toString('hex'),
139
- is_confirmed: false,
140
- is_outgoing: true,
141
- tokens: 1,
142
- },
125
+ expected: makeExpected({}),
143
126
  },
144
127
  ];
145
128