paid-services 3.14.2 → 3.14.5

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,10 @@
1
1
  # Versions
2
2
 
3
- ## Version 3.14.2
3
+ ## Version 3.14.5
4
+
5
+ - `manageTrades`: Fix connecting to sellers when not already connected
6
+
7
+ ## Version 3.14.4
4
8
 
5
9
  - `manageTrades`: Fix listing of trades that have fiat-pricing
6
10
 
package/package.json CHANGED
@@ -14,14 +14,14 @@
14
14
  "bolt07": "1.8.0",
15
15
  "ecpair": "2.0.1",
16
16
  "invoices": "2.0.4",
17
- "ln-service": "53.9.3",
17
+ "ln-service": "53.9.4",
18
18
  "ln-sync": "3.11.0",
19
19
  "tiny-secp256k1": "2.2.1"
20
20
  },
21
21
  "description": "Lightning Paid Services library",
22
22
  "devDependencies": {
23
- "@alexbosworth/tap": "15.0.10",
24
- "ln-docker-daemons": "2.2.4",
23
+ "@alexbosworth/tap": "15.0.11",
24
+ "ln-docker-daemons": "2.2.5",
25
25
  "mock-lnd": "1.4.1",
26
26
  "secp256k1": "4.0.3"
27
27
  },
@@ -43,5 +43,5 @@
43
43
  "integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
44
44
  "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"
45
45
  },
46
- "version": "3.14.2"
46
+ "version": "3.14.5"
47
47
  }
@@ -1,4 +1,5 @@
1
1
  const {test} = require('@alexbosworth/tap');
2
+ const tinysecp = require('tiny-secp256k1');
2
3
 
3
4
  const method = require('./../../capacity/interim_replacement_psbt');
4
5
 
@@ -31,6 +32,8 @@ const tests = [
31
32
 
32
33
  tests.forEach(({args, description, error, expected}) => {
33
34
  return test(description, async ({end, strictSame, throws}) => {
35
+ args.ecp = (await import('ecpair')).ECPairFactory(tinysecp);
36
+
34
37
  if (!!error) {
35
38
  throws(() => method(args), new Error(error), 'Got error');
36
39
  } else {
@@ -1,15 +1,18 @@
1
- const addPeer = require('ln-service');
1
+ const {addPeer} = require('ln-service');
2
2
  const asyncAuto = require('async/auto');
3
3
  const asyncDetect = require('async/detect');
4
4
  const asyncDetectSeries = require('async/detectSeries');
5
5
  const asyncMap = require('async/map');
6
+ const asyncRetry = require('async/retry');
6
7
  const {getChannel} = require('ln-service');
7
8
  const {getIdentity} = require('ln-service');
8
9
  const {getNode} = require('ln-service');
9
10
  const {getPeers} = require('ln-service');
10
11
  const {returnResult} = require('asyncjs-util');
11
12
 
13
+ const interval = 1000;
12
14
  const {isArray} = Array;
15
+ const times = 10;
13
16
  const uniq = arr => Array.from(new Set(arr));
14
17
 
15
18
  /** Connect to a seller
@@ -169,6 +172,30 @@ module.exports = ({lnd, logger, nodes}, cbk) => {
169
172
  cbk);
170
173
  }],
171
174
 
175
+ // Confirm the connection
176
+ confirmConnected: ['connect', ({connect}, cbk) => {
177
+ return asyncRetry({interval, times}, cbk => {
178
+ return getPeers({lnd}, (err, res) => {
179
+ if (!!err) {
180
+ return cbk(err);
181
+ }
182
+
183
+ const peer = res.peers.find(n => n.public_key === connect.id);
184
+
185
+ if (!peer) {
186
+ return cbk([503, 'FailedToConnectToPeer']);
187
+ }
188
+
189
+ if (!peer.bytes_received) {
190
+ return cbk([503, 'FailedToFinalizeConnectionWithPeer']);
191
+ }
192
+
193
+ return cbk();
194
+ });
195
+ },
196
+ cbk);
197
+ }],
198
+
172
199
  // Connected to seller
173
200
  connected: ['connect', ({connect}, cbk) => {
174
201
  if (!connect) {
@@ -315,8 +315,10 @@ module.exports = ({ask, lnd, logger, request, separator}, cbk) => {
315
315
  return logger.info(`sold: ${tokensAsBigUnit(tokens)} ${item}`);
316
316
  });
317
317
 
318
- sub.on('start', ({description, tokens}) => {
319
- const trade = `${tokensAsBigUnit(tokens)} ${description}`;
318
+ sub.on('start', ({description, price, tokens}) => {
319
+ const amount = !!tokens ? tokensAsBigUnit(tokens) : price;
320
+
321
+ const trade = `${amount} ${description}`;
320
322
 
321
323
  return logger.info(`open: ${trade}`);
322
324
  });
@@ -95,6 +95,7 @@ module.exports = ({lnd, request}) => {
95
95
  description: trade.description,
96
96
  expires_at: trade.expires_at,
97
97
  id: trade.id,
98
+ price: trade.price,
98
99
  secret: trade.secret,
99
100
  tokens: trade.tokens,
100
101
  });