balanceofsatoshis 12.26.4 → 12.26.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,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 12.26.5
4
+
5
+ - `telegram`: Optimize /command speed by reducing duplicate wallet info calls
6
+
3
7
  ## 12.26.4
4
8
 
5
9
  - `telegram`: Fix button push handling and responding to button push queries
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  "ini": "3.0.1",
37
37
  "inquirer": "9.1.0",
38
38
  "ln-accounting": "5.0.7",
39
- "ln-service": "53.20.0",
39
+ "ln-service": "53.21.0",
40
40
  "ln-sync": "3.13.1",
41
41
  "ln-telegram": "3.22.3",
42
42
  "moment": "2.29.4",
@@ -83,5 +83,5 @@
83
83
  "postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis --push .",
84
84
  "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/peers/*.js test/responses/*.js test/routing/*.js test/services/*.js test/swaps/*.js test/tags/*.js test/telegram/*.js test/wallets/*.js"
85
85
  },
86
- "version": "12.26.4"
86
+ "version": "12.26.5"
87
87
  }
@@ -1,18 +1,19 @@
1
1
  const asyncAuto = require('async/auto');
2
- const asyncMap = require('async/map');
3
2
  const {returnResult} = require('asyncjs-util');
4
- const {getWalletInfo} = require('ln-service');
5
3
 
6
4
  const {getLnds} = require('./../lnd');
7
5
 
8
- const fromName = node => `${node.alias} ${node.public_key.substring(0, 8)}`;
9
6
  const {isArray} = Array;
10
- const sanitize = n => (n || '').replace(/_/g, '\\_').replace(/[*~`]/g, '');
11
7
 
12
8
  /** Get node details for telegram commands
13
9
 
14
10
  {
15
11
  logger: <Winston Logger Object>
12
+ names: [{
13
+ alias: <Node Alias String>
14
+ from: <Node Name String>
15
+ public_key: <Node Identity Public Key Hex String>
16
+ }]
16
17
  nodes: [<Saved Node Name String>]
17
18
  }
18
19
 
@@ -26,7 +27,7 @@ const sanitize = n => (n || '').replace(/_/g, '\\_').replace(/[*~`]/g, '');
26
27
  }]
27
28
  }
28
29
  */
29
- module.exports = ({logger, nodes}, cbk) => {
30
+ module.exports = ({logger, names, nodes}, cbk) => {
30
31
  return new Promise((resolve, reject) => {
31
32
  return asyncAuto({
32
33
  // Check arguments
@@ -45,32 +46,19 @@ module.exports = ({logger, nodes}, cbk) => {
45
46
  // Get associated LNDs
46
47
  getLnds: ['validate', ({}, cbk) => getLnds({logger, nodes}, cbk)],
47
48
 
48
- // Get node info for the nodes
49
- getNodes: ['getLnds', ({getLnds}, cbk) => {
50
- return asyncMap(getLnds.lnds, (lnd, cbk) => {
51
- return getWalletInfo({lnd}, (err, res) => {
52
- if (!!err) {
53
- return cbk([503, 'FailedToGetNodeInfoForTelegramNode', {err}]);
54
- }
55
-
56
- const named = fromName({
57
- alias: res.alias,
58
- public_key: res.public_key,
59
- });
49
+ // Merge node info for the nodes
50
+ nodes: ['getLnds', ({getLnds}, cbk) => {
51
+ const nodes = getLnds.lnds.map((lnd, i) => {
52
+ return {
53
+ lnd,
54
+ alias: names[i].alias,
55
+ from: names[i].from,
56
+ public_key: names[i].public_key,
57
+ };
58
+ });
60
59
 
61
- return cbk(null, {
62
- lnd,
63
- alias: res.alias,
64
- from: sanitize(named),
65
- public_key: res.public_key,
66
- });
67
- });
68
- },
69
- cbk);
60
+ return cbk(null, {nodes});
70
61
  }],
71
-
72
- // List of nodes with details
73
- nodes: ['getNodes', ({getNodes}, cbk) => cbk(null, {nodes: getNodes})],
74
62
  },
75
63
  returnResult({reject, resolve, of: 'nodes'}, cbk));
76
64
  });
@@ -56,7 +56,7 @@ const {version} = require('./../package');
56
56
 
57
57
  const fileAsDoc = file => new InputFile(file.source, file.filename);
58
58
  const fromName = node => `${node.alias} ${node.public_key.substring(0, 8)}`;
59
- const getDetails = (logger, nodes) => getNodeDetails({logger, nodes});
59
+ const getLnds = (x, y, z) => getNodeDetails({logger: x, names: y, nodes: z});
60
60
  const {isArray} = Array;
61
61
  const isHash = n => /^[0-9A-F]{64}$/i.test(n);
62
62
  let isBotInit = false;
@@ -164,6 +164,12 @@ module.exports = (args, cbk) => {
164
164
  return cbk();
165
165
  }
166
166
 
167
+ const names = getNodes.map(node => ({
168
+ alias: node.alias,
169
+ from: node.from,
170
+ public_key: node.public_key,
171
+ }));
172
+
167
173
  args.bot.catch(err => args.logger.error({telegram_error: err}));
168
174
 
169
175
  // Catch message editing
@@ -183,7 +189,7 @@ module.exports = (args, cbk) => {
183
189
  await handleBackupCommand({
184
190
  from: ctx.message.from.id,
185
191
  id: connectedId,
186
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
192
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
187
193
  reply: ctx.reply,
188
194
  send: (n, opts) => ctx.replyWithDocument(fileAsDoc(n), opts),
189
195
  });
@@ -218,7 +224,7 @@ module.exports = (args, cbk) => {
218
224
  await handleCostsCommand({
219
225
  from: ctx.message.from.id,
220
226
  id: connectedId,
221
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
227
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
222
228
  reply: n => ctx.reply(n, markdown),
223
229
  request: args.request,
224
230
  working: () => ctx.replyWithChatAction('typing'),
@@ -234,7 +240,7 @@ module.exports = (args, cbk) => {
234
240
  await handleEarningsCommand({
235
241
  from: ctx.message.from.id,
236
242
  id: connectedId,
237
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
243
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
238
244
  reply: n => ctx.reply(n, markdown),
239
245
  working: () => ctx.replyWithChatAction('typing'),
240
246
  });
@@ -249,7 +255,7 @@ module.exports = (args, cbk) => {
249
255
  await handleGraphCommand({
250
256
  from: ctx.message.from.id,
251
257
  id: connectedId,
252
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
258
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
253
259
  remove: () => ctx.deleteMessage(),
254
260
  reply: (message, options) => ctx.reply(message, options),
255
261
  text: ctx.message.text,
@@ -266,7 +272,7 @@ module.exports = (args, cbk) => {
266
272
  await handleInfoCommand({
267
273
  from: ctx.message.from.id,
268
274
  id: connectedId,
269
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
275
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
270
276
  remove: () => ctx.deleteMessage(),
271
277
  reply: (message, options) => ctx.reply(message, options),
272
278
  });
@@ -281,7 +287,7 @@ module.exports = (args, cbk) => {
281
287
  await handleInvoiceCommand({
282
288
  ctx,
283
289
  id: connectedId,
284
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
290
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
285
291
  });
286
292
  } catch (err) {
287
293
  args.logger.error({err});
@@ -317,7 +323,7 @@ module.exports = (args, cbk) => {
317
323
  await handleLiquidityCommand({
318
324
  from: ctx.message.from.id,
319
325
  id: connectedId,
320
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
326
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
321
327
  reply: (n, opt) => ctx.reply(n, opt),
322
328
  text: ctx.message.text,
323
329
  working: () => ctx.replyWithChatAction('typing'),
@@ -346,7 +352,7 @@ module.exports = (args, cbk) => {
346
352
  budget,
347
353
  from: ctx.message.from.id,
348
354
  id: connectedId,
349
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
355
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
350
356
  reply: message => ctx.reply(message, markdown),
351
357
  request: args.request,
352
358
  text: ctx.message.text,
@@ -365,7 +371,7 @@ module.exports = (args, cbk) => {
365
371
  await handlePendingCommand({
366
372
  from: ctx.message.from.id,
367
373
  id: connectedId,
368
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
374
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
369
375
  reply: (message, options) => ctx.reply(message, options),
370
376
  working: () => ctx.replyWithChatAction('typing'),
371
377
  });
@@ -444,7 +450,7 @@ module.exports = (args, cbk) => {
444
450
  ctx,
445
451
  bot: args.bot,
446
452
  id: connectedId,
447
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
453
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
448
454
  });
449
455
  } catch (err) {
450
456
  args.logger.error({err});
@@ -460,7 +466,7 @@ module.exports = (args, cbk) => {
460
466
  ctx,
461
467
  api: args.bot.api,
462
468
  id: connectedId,
463
- nodes: (await getDetails(args.logger, args.nodes)).nodes,
469
+ nodes: (await getLnds(args.logger, names, args.nodes)).nodes,
464
470
  });
465
471
  } catch (err) {
466
472
  args.logger.error({err});