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 +4 -0
- package/groups/ask_for_group_details.js +41 -29
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -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
|
-
//
|
|
51
|
-
|
|
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:
|
|
54
|
-
name: '
|
|
55
|
-
message: '
|
|
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
|
-
|
|
66
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
({
|
|
83
|
+
({size}) => cbk(null, Number(size)));
|
|
81
84
|
}],
|
|
82
85
|
|
|
83
|
-
//
|
|
84
|
-
|
|
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:
|
|
90
|
-
name: '
|
|
91
|
-
message: '
|
|
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
|
-
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
({
|
|
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.
|
|
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.
|
|
29
|
-
"mock-lnd": "1.4.
|
|
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.
|
|
50
|
+
"version": "3.20.3"
|
|
51
51
|
}
|