paid-services 3.20.2 → 3.20.3

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,9 @@
1
1
  # Versions
2
2
 
3
+ ## Version 3.20.3
4
+
5
+ - `manageGroupJoin`: Allow coordinating pair when funds are below the capacity
6
+
3
7
  ## Version 3.20.2
4
8
 
5
9
  - `manageGroupJoin`: Allow opening a pair channel when funds are below capacity
@@ -6,6 +6,7 @@ const {returnResult} = require('asyncjs-util');
6
6
  const defaultChannelCapacity = 5e6;
7
7
  const defaultGroupSize = 3;
8
8
  const {floor} = Math;
9
+ const halfOf = input => Number(input) / 2;
9
10
  const isNumber = n => !isNaN(n);
10
11
  const isOdd = n => !!(n % 2);
11
12
  const maxChannelSize = 21e14;
@@ -47,76 +48,87 @@ module.exports = ({ask, lnd}, cbk) => {
47
48
  // Get the wallet balance to make sure there are enough funds to join
48
49
  getBalance: ['validate', ({}, cbk) => getChainBalance({lnd}, cbk)],
49
50
 
50
- // Ask for how big the channels should be
51
- askForCapacity: ['getBalance', ({getBalance}, cbk) => {
51
+ // Get the chain fee rate to use for a default in the chain fee query
52
+ getFeeRate: ['validate', ({}, cbk) => getChainFeeRate({lnd}, cbk)],
53
+
54
+ // Ask for how many group members there should be
55
+ askForCount: ['validate', ({}, cbk) => {
52
56
  return ask({
53
- default: defaultChannelCapacity,
54
- name: 'capacity',
55
- message: 'Channel capacity?',
57
+ default: defaultGroupSize,
58
+ name: 'size',
59
+ message: 'Total number of group members?',
56
60
  validate: input => {
57
61
  if (!input || !isNumber(input)) {
58
62
  return false;
59
63
  }
60
64
 
65
+ // Do not allow fractional members
61
66
  if (round(Number(input)) !== Number(input)) {
62
67
  return false;
63
68
  }
64
69
 
65
- if (Number(input) > getBalance.chain_balance) {
66
- return `Current chain balance is ${getBalance.chain_balance}`;
67
- }
68
-
69
- if (Number(input) < minChannelSize) {
70
- return `Minimum channel size is ${minChannelSize}`;
70
+ // Do not allow too many members
71
+ if (Number(input) > maxGroupSize) {
72
+ return `The maximum group size is ${maxGroupSize}`;
71
73
  }
72
74
 
73
- if (isOdd(Number(input))) {
74
- return 'Channel capacity must be even';
75
+ // Do not allow too few members
76
+ if (Number(input) < minGroupSize) {
77
+ return `The minimum group size is ${minGroupSize}`;
75
78
  }
76
79
 
77
80
  return true;
78
81
  },
79
82
  },
80
- ({capacity}) => cbk(null, Number(capacity)));
83
+ ({size}) => cbk(null, Number(size)));
81
84
  }],
82
85
 
83
- // Get the chain fee rate to use for a default in the chain fee query
84
- getFeeRate: ['validate', ({}, cbk) => getChainFeeRate({lnd}, cbk)],
86
+ // Ask for how big the channels should be
87
+ askForCapacity: [
88
+ 'askForCount',
89
+ 'getBalance',
90
+ ({askForCount, getBalance}, cbk) =>
91
+ {
92
+ const isPair = askForCount === minGroupSize;
85
93
 
86
- // Ask for how many group members there should be
87
- askForCount: ['askForCapacity', ({askForCapacity}, cbk) => {
88
94
  return ask({
89
- default: defaultGroupSize,
90
- name: 'size',
91
- message: 'Total number of group members?',
95
+ default: defaultChannelCapacity,
96
+ name: 'capacity',
97
+ message: 'Channel capacity?',
92
98
  validate: input => {
93
99
  if (!input || !isNumber(input)) {
94
100
  return false;
95
101
  }
96
102
 
97
- // Do not allow fractional members
98
103
  if (round(Number(input)) !== Number(input)) {
99
104
  return false;
100
105
  }
101
106
 
102
- // Do not allow too many members
103
- if (Number(input) > maxGroupSize) {
104
- return `The maximum group size is ${maxGroupSize}`;
107
+ if (!isPair && Number(input) > getBalance.chain_balance) {
108
+ return `Current chain balance is ${getBalance.chain_balance}`;
105
109
  }
106
110
 
107
- // Do not allow too few members
108
- if (Number(input) < minGroupSize) {
109
- return `The minimum group size is ${minGroupSize}`;
111
+ if (isPair && halfOf(input) > getBalance.chain_balance) {
112
+ return `Current chain balance is ${getBalance.chain_balance}`;
113
+ }
114
+
115
+ if (Number(input) < minChannelSize) {
116
+ return `Minimum channel size is ${minChannelSize}`;
117
+ }
118
+
119
+ if (isOdd(Number(input))) {
120
+ return 'Channel capacity must be even';
110
121
  }
111
122
 
112
123
  return true;
113
124
  },
114
125
  },
115
- ({size}) => cbk(null, size));
126
+ ({capacity}) => cbk(null, Number(capacity)));
116
127
  }],
117
128
 
118
129
  // Ask for a chain fee rate
119
130
  askForFeeRate: [
131
+ 'askForCapacity',
120
132
  'askForCount',
121
133
  'getFeeRate',
122
134
  ({askForCount, getFeeRate}, cbk) =>
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "ecpair": "2.0.1",
17
17
  "goldengate": "11.2.3",
18
18
  "invoices": "2.1.0",
19
- "ln-service": "53.17.5",
19
+ "ln-service": "53.20.0",
20
20
  "ln-sync": "3.13.1",
21
21
  "psbt": "2.7.1",
22
22
  "p2tr": "1.3.1",
@@ -25,8 +25,8 @@
25
25
  "description": "Lightning Paid Services library",
26
26
  "devDependencies": {
27
27
  "@alexbosworth/tap": "15.0.11",
28
- "ln-docker-daemons": "2.3.2",
29
- "mock-lnd": "1.4.1",
28
+ "ln-docker-daemons": "2.3.4",
29
+ "mock-lnd": "1.4.3",
30
30
  "secp256k1": "4.0.3"
31
31
  },
32
32
  "engines": {
@@ -47,5 +47,5 @@
47
47
  "integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
48
48
  "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/balanced/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js test/trades/*.js"
49
49
  },
50
- "version": "3.20.2"
50
+ "version": "3.20.3"
51
51
  }