paid-services 3.7.0 → 3.8.0
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 +5 -0
- package/index.js +4 -0
- package/package.json +3 -3
- package/trades/index.js +3 -1
- package/trades/service_anchored_trades.js +31 -6
- package/trades/trade_from_invoice.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## Version 3.8.0
|
|
4
|
+
|
|
5
|
+
- `encodeTrade`: Add method to encode a trade-secret
|
|
6
|
+
- `serviceAnchoredTrades`: Add method to serve open trade-secrets
|
|
7
|
+
|
|
3
8
|
## Version 3.7.0
|
|
4
9
|
|
|
5
10
|
- `changeChannelCapacity`: Add support for decreasing funds into a new channel
|
package/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const {changeChannelCapacity} = require('./capacity');
|
|
2
2
|
const {confirmServiceUse} = require('./client');
|
|
3
|
+
const {encodeTrade} = require('./trades');
|
|
3
4
|
const {getServiceSchema} = require('./client');
|
|
4
5
|
const {getServicesList} = require('./client');
|
|
5
6
|
const {makePeerRequest} = require('./p2p');
|
|
6
7
|
const {makeServiceRequest} = require('./client');
|
|
7
8
|
const {manageTrades} = require('./trades');
|
|
8
9
|
const {schema} = require('./services');
|
|
10
|
+
const {serviceAnchoredTrades} = require('./trades');
|
|
9
11
|
const {servicePaidRequests} = require('./server');
|
|
10
12
|
const {servicePeerRequests} = require('./p2p');
|
|
11
13
|
|
|
@@ -14,11 +16,13 @@ const serviceIds = schema.types;
|
|
|
14
16
|
module.exports = {
|
|
15
17
|
changeChannelCapacity,
|
|
16
18
|
confirmServiceUse,
|
|
19
|
+
encodeTrade,
|
|
17
20
|
getServiceSchema,
|
|
18
21
|
getServicesList,
|
|
19
22
|
makePeerRequest,
|
|
20
23
|
makeServiceRequest,
|
|
21
24
|
manageTrades,
|
|
25
|
+
serviceAnchoredTrades,
|
|
22
26
|
serviceIds,
|
|
23
27
|
servicePaidRequests,
|
|
24
28
|
servicePeerRequests,
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"bolt01": "1.2.3",
|
|
13
13
|
"bolt07": "1.8.0",
|
|
14
14
|
"invoices": "2.0.3",
|
|
15
|
-
"ln-service": "53.4.
|
|
15
|
+
"ln-service": "53.4.2",
|
|
16
16
|
"ln-sync": "3.6.1"
|
|
17
17
|
},
|
|
18
18
|
"description": "Lightning Paid Services library",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"url": "https://github.com/alexbosworth/paid-services.git"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"integration-tests": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
|
|
40
|
+
"integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
|
|
41
41
|
"test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.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"
|
|
42
42
|
},
|
|
43
|
-
"version": "3.
|
|
43
|
+
"version": "3.8.0"
|
|
44
44
|
}
|
package/trades/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const encodeTrade = require('./encode_trade');
|
|
1
2
|
const manageTrades = require('./manage_trades');
|
|
3
|
+
const serviceAnchoredTrades = require('./service_anchored_trades');
|
|
2
4
|
|
|
3
|
-
module.exports = {manageTrades};
|
|
5
|
+
module.exports = {encodeTrade, manageTrades, serviceAnchoredTrades};
|
|
@@ -13,6 +13,7 @@ const defaultInvoicesLimit = 100;
|
|
|
13
13
|
const events = ['details', 'error', 'failure', 'settled', 'trade'];
|
|
14
14
|
const fromNow = date => new Date(date) - new Date();
|
|
15
15
|
const {keys} = Object;
|
|
16
|
+
const sumOf = arr => arr.reduce((sum, n) => sum + n, 0);
|
|
16
17
|
|
|
17
18
|
/** Service trades represented by anchored invoices
|
|
18
19
|
|
|
@@ -47,6 +48,7 @@ const {keys} = Object;
|
|
|
47
48
|
// Starting service for trade
|
|
48
49
|
@event 'start'
|
|
49
50
|
{
|
|
51
|
+
created_at: <Open Trade Created At ISO 8601 Date String>
|
|
50
52
|
description: <Trade Description String>
|
|
51
53
|
expires_at: <Trade Expires at ISO 8601 Date String>
|
|
52
54
|
id: <Trade Id Hex String>
|
|
@@ -86,6 +88,7 @@ module.exports = ({lnd}) => {
|
|
|
86
88
|
|
|
87
89
|
// Pick up the trade to service
|
|
88
90
|
emitter.emit('start', {
|
|
91
|
+
created_at: trade.created_at,
|
|
89
92
|
description: trade.description,
|
|
90
93
|
expires_at: trade.expires_at,
|
|
91
94
|
id: trade.id,
|
|
@@ -129,6 +132,28 @@ module.exports = ({lnd}) => {
|
|
|
129
132
|
// Listen for any new invoices that represent anchored trades
|
|
130
133
|
const sub = subscribeToInvoices({lnd});
|
|
131
134
|
|
|
135
|
+
// Stop servicing all trades
|
|
136
|
+
const stopService = () => {
|
|
137
|
+
// Stop paging in progress
|
|
138
|
+
paging.token = false;
|
|
139
|
+
|
|
140
|
+
// Stop listening to all invoices
|
|
141
|
+
sub.removeAllListeners();
|
|
142
|
+
|
|
143
|
+
// Stop listening to all anchor invoices
|
|
144
|
+
return keys(listening).forEach(id => listening[id].removeAllListeners());
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Stop the service when there are no more listeners
|
|
148
|
+
emitter.on('removeListener', () => {
|
|
149
|
+
// Exit early when there are still listeners on an event
|
|
150
|
+
if (!!sumOf(events.map(n => emitter.listenerCount(n)))) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return stopService();
|
|
155
|
+
});
|
|
156
|
+
|
|
132
157
|
// Listen for new trades to appear
|
|
133
158
|
sub.on('invoice_updated', invoice => {
|
|
134
159
|
const {trade} = tradeFromInvoice(invoice);
|
|
@@ -155,13 +180,13 @@ module.exports = ({lnd}) => {
|
|
|
155
180
|
if (!!err) {
|
|
156
181
|
emitter.emit(err);
|
|
157
182
|
|
|
158
|
-
// Stop
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// Stop listening to all anchor invoices
|
|
162
|
-
keys(listening).forEach(id => listening[id].removeAllListeners());
|
|
183
|
+
// Stop the service
|
|
184
|
+
return stopService();
|
|
185
|
+
}
|
|
163
186
|
|
|
164
|
-
|
|
187
|
+
// Exit early when paging is already stopped
|
|
188
|
+
if (paging.token === false) {
|
|
189
|
+
return cbk();
|
|
165
190
|
}
|
|
166
191
|
|
|
167
192
|
paging.token = res.next || false;
|
|
@@ -3,6 +3,7 @@ const decodeAnchoredTrade = require('./decode_anchored_trade');
|
|
|
3
3
|
/** Derive open trade details from an invoice
|
|
4
4
|
|
|
5
5
|
{
|
|
6
|
+
created_at: <Invoice Created At ISO 8601 Date String>
|
|
6
7
|
description: <Invoice Description String>
|
|
7
8
|
id: <Invoice Id Hex String>
|
|
8
9
|
expires_at: <Invoice Expiration ISO 8601 Date String>
|
|
@@ -15,6 +16,7 @@ const decodeAnchoredTrade = require('./decode_anchored_trade');
|
|
|
15
16
|
@returns
|
|
16
17
|
{
|
|
17
18
|
[trade]: {
|
|
19
|
+
created_at: <Open Trade Created At ISO 8601 Date String>
|
|
18
20
|
description: <Trade Description String>
|
|
19
21
|
expires_at: <Trade Expires at ISO 8601 Date String>
|
|
20
22
|
id: <Trade Id Hex String>
|
|
@@ -41,6 +43,7 @@ module.exports = args => {
|
|
|
41
43
|
|
|
42
44
|
return {
|
|
43
45
|
trade: {
|
|
46
|
+
created_at: args.created_at,
|
|
44
47
|
description: trade.description,
|
|
45
48
|
expires_at: args.expires_at,
|
|
46
49
|
id: args.id,
|