-
Notifications
You must be signed in to change notification settings - Fork 79
/
bos
executable file
·2330 lines (2220 loc) · 98 KB
/
bos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
const {lstat} = require('fs');
const {mkdir} = require('fs');
const {readdir} = require('fs');
const {readFile} = require('fs');
const {rmdir} = require('fs');
const {spawn} = require('child_process');
const {statSync} = require('fs');
const {unlink} = require('fs');
const {writeFile} = require('fs');
const importLazy = require('import-lazy')(require);
const accounting = importLazy('ln-accounting');
const fetch = importLazy('@alexbosworth/node-fetch');
const fiat = importLazy('@alexbosworth/fiat');
const lnService = importLazy('ln-service');
const lnSync = importLazy('ln-sync');
const paidServices = importLazy('paid-services');
const prog = require('@alexbosworth/caporal');
const tabtab = importLazy('tabtab');
const autocomplete = require('./commands/autocomplete');
const commandConstants = require('./commands/constants');
const {accountingCategories} = commandConstants;
const balances = importLazy('./balances');
const chain = importLazy('./chain');
const commands = importLazy('./commands');
const display = importLazy('./display');
const encryption = importLazy('./encryption');
const lnd = importLazy('./lnd');
const lnurl = importLazy('./lnurl');
const {lnurlFunctions} = commandConstants;
const lsp = importLazy('./lsp');
const network = importLazy('./network');
const nodes = importLazy('./nodes');
const offchain = importLazy('./offchain');
const {peerSortOptions} = commandConstants;
const peers = importLazy('./peers');
const {priceProviders} = commandConstants;
const {rateProviders} = commandConstants;
const responses = importLazy('./responses');
const routing = importLazy('./routing');
const services = importLazy('./services');
const {swapTypes} = commandConstants;
const swaps = importLazy('./swaps');
const telegram = importLazy('./telegram');
const triggers = importLazy('./triggers');
const wallets = importLazy('./wallets');
const {version} = importLazy('./package');
const {BOOL} = prog;
const collect = arr => [].concat(...[arr]).filter(n => !!n);
const {exit} = process;
const flatten = arr => [].concat(...arr);
const {FLOAT} = prog;
const {floor} = Math;
const hexMatch = /^[0-9a-f]+$/i;
const {INT} = prog;
const {keys} = Object;
const lndForNode = (logger, node) => lnd.authenticatedLnd({logger, node});
const months = [...Array(12).keys()].map(n => ++n);
const {REPEATABLE} = prog;
const {STRING} = prog;
const yearMatch = /^\d{4}$/;
prog
.version(version)
// Get accounting information
.command('accounting', 'Get an accounting rundown')
.argument('<category>', 'Report category', keys(accountingCategories))
.help(`Categories: ${keys(accountingCategories).join(', ')}`)
.help(`Rate providers: ${rateProviders.join(', ')}`)
.help('Privacy note: this requests tx related data from third parties')
.option('--csv', 'Output a CSV')
.option('--date <day>', 'Show only records for specific date')
.option('--disable-fiat', 'Avoid looking up fiat conversions for records')
.option('--month <month>', 'Show only records for specific month', months)
.option('--node <node_name>', 'Get details from named node')
.option('--rate-provider <rate_provider>', 'Rate provider', rateProviders)
.option('--year <year>', 'Show only records for specified year', yearMatch)
.action((args, options, logger) => {
const table = !!options.csv ? null : 'rows';
return new Promise(async (resolve, reject) => {
try {
return balances.getAccountingReport({
category: args.category,
date: options.date,
is_csv: !!options.csv,
is_fiat_disabled: options.disableFiat,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
month: options.month,
node: options.node,
rate_provider: options.rateProvider,
request: commands.simpleRequest,
year: options.year,
},
responses.returnObject({logger, reject, resolve, table}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Advertise to other nodes on the network
.command('advertise', 'Broadcast advertisement')
.help('use --filter conditions to limit broadcast scope: capacity > 1*m')
.help('--filter variables: CAPACITY/CHANNELS_COUNT/K/M')
.help('Default filter scope: channels_count > 9')
.help('To only advertise to direct peers use --max-hops 0')
.help('To avoid advertising to direct peers use --min-hops 1')
.help('Multiple --tag is supported to advertise across multiple tags')
.option('--budget <budget>', 'Spending amount to allow for advertising', INT)
.option('--dryrun', 'Avoid actually sending advertisements')
.option('--filter <expression>', 'Require node match condition', REPEATABLE)
.option('--max-hops <max_hops>', 'Maximum number of relaying nodes', INT)
.option('--message <message>', 'Custom advertisement message')
.option('--min-hops <min_hops>', 'Minimum number of relaying nodes', INT)
.option('--node <node_name>', 'Advertise via saved node')
.option('--tag <tag_name>', 'Advertise to a tag', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return await services.advertise({
logger,
budget: options.budget || undefined,
filters: flatten([options.filter].filter(n => !!n)),
fs: {getFile: readFile},
is_dry_run: !!options.dryrun,
lnd: (await lndForNode(logger, options.node)).lnd,
message: options.message,
max_hops: options.maxHops,
min_hops: options.minHops,
tags: flatten([options.tag].filter(n => !!n)),
});
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Direct autopilot to mirror one or more nodes on the network
.command('autopilot', 'Enable autopilot')
.visible(false)
.argument('<status>', 'Status of autopilot', ['off', 'on'])
.help('Autopilot status is either on or off')
.help('Mirroring and urls require lnd --autopilot.heuristic=externalscore:1')
.option('--dryrun', 'Show scoring without changing autopilot settings')
.option('--mirror <pubkey>', 'Mirror channels of node', REPEATABLE)
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Set autopilot on saved node')
.option('--url <url>', 'Follow nodes from a scoring URL', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return network.setAutopilot({
is_dry_run: !!options.dryrun,
is_enabled: args.status === 'on',
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
mirrors: flatten([options.mirror].filter(n => !!n)),
node: options.node,
request: commands.simpleRequest,
urls: flatten([options.url].filter(n => !!n)),
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Get local balance information
.command('balance', 'Get total tokens')
.help('Sums balances on-chain, in channels, and pending, plus commit fees')
.help('Multiple --node arguments are supported to sum across nodes')
.option('--above <tokens>', 'Return tokens above watermark', INT)
.option('--below <tokens>', 'Return tokens below watermark', INT)
.option('--confirmed', 'Return confirmed funds only')
.option('--detailed', 'Return detailed balance information')
.option('--node <node_name>', 'Node to get balance for', REPEATABLE)
.option('--offchain', 'List only off-chain tokens')
.option('--onchain', 'List only on-chain tokens')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
// Exit early when detailed balance details are requested
if (!!options.detailed) {
return balances.getDetailedBalance({
lnds: (await lnd.getLnds({logger, nodes: options.node})).lnds,
is_confirmed: options.confirmed,
},
responses.returnObject({logger, reject, resolve}));
}
return balances.getBalance({
above: options.above,
below: options.below,
is_confirmed: !!options.confirmed,
is_offchain_only: !!options.offchain,
is_onchain_only: !!options.onchain,
lnd: (await lndForNode(logger, options.node)).lnd,
},
responses.returnNumber({logger, reject, resolve, number: 'balance'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Broadcast a chain transaction
.command('broadcast', 'Submit a signed transaction to the mempool')
.argument('<tx>', 'Signed raw transaction')
.option('--description <description>', 'Describe the transaction being sent')
.option('--node <node_name>', 'Node to submit transaction on')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return lnSync.broadcastTransaction({
logger,
description: options.description,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
transaction: args.tx,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Call API directly
.command('call', 'Make a raw API call and to get a raw API response')
.help('If you do not specify a method it will list the supported methods')
.argument('[method]', 'Method to call')
.option('--json', 'Output raw JSON as the output')
.option('--node <node_name>', 'Saved node to use for call')
.option('--param <param>', 'query encoded name=value', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const r = options.json ? responses.returnJson : responses.returnObject;
return commands.callRawApi({
logger,
ask: await commands.interrogate({}),
lnd: (await lndForNode(logger, options.node)).lnd,
method: args.method,
params: flatten([options.param].filter(n => !!n)),
},
r({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Get the number of days until the RPC cert expires
.command('cert-validity-days', 'Number of days until the cert is invalid')
.option('--below <number_of_days>', 'Return number of days below mark', INT)
.option('--node <node_name>', 'Node to check cert on')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
return lnd.getCertValidityDays({
logger,
below: options.below,
node: options.node,
},
responses.returnNumber({logger, reject, resolve, number: 'days'}));
});
})
// Deposit coins
.command('chain-deposit', 'Deposit coins in the on-chain wallet')
.help('--format address types supported: np2wpkh, p2tr (default), p2wpkh')
.argument('[amount]', 'Amount to receive', INT)
.option('--format <format>', 'Address type', ['np2wpkh', 'p2tr', 'p2wpkh'])
.option('--fresh', 'Create a fresh address')
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Node to deposit coins to')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return chain.getDepositAddress({
format: options.format || undefined,
fresh: options.fresh || undefined,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
tokens: args.amount,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Get the current chain fee rates
.command('chainfees', 'Get the current chain fee estimates')
.help('Lookup chain fee estimates at various confirm targets')
.option('--blocks <depth>', 'Blocks confirm target depth to estimate to')
.option('--file <path>', 'Write the output to a JSON file at desired path')
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Node to get chain fees view from')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return chain.getChainFees({
blocks: options.blocks,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
},
responses.returnObject({
logger,
reject,
resolve,
file: options.file,
write: writeFile,
}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Change the capacity of an existing channel
.command('change-channel-capacity', 'Change the capacity of a channel')
.visible(false)
.help('Remote node must be prepared to receive this type of request')
.help('The remote node should also run this same command after you propose')
.option('--node <node_name>', 'Use saved node details instead of local node')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const {lnd} = await lndForNode(logger, options.node);
const saved = await nodes.manageSavedNodes({
logger,
spawn,
ask: await commands.interrogate({}),
fs: {
writeFile,
getDirectoryFiles: readdir,
getFile: readFile,
getFileStatus: lstat,
makeDirectory: mkdir,
removeDirectory: rmdir,
removeFile: unlink,
},
is_including_lnd_api: true,
lock_credentials_to: [],
network: (await lnSync.getNetwork({lnd})).network,
});
return paidServices.changeChannelCapacity({
lnd,
logger,
ask: await commands.interrogate({}),
nodes: saved.nodes,
},
responses.returnObject({exit, logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Show a chart of chain fees paid
.command('chart-chain-fees', 'Get a chart of chain fee expenses')
.help('Show chart of mining fee expenditure over time')
.help('Privacy note: this requests tx data from third parties')
.option('--days <days>', 'Chart over the past number of days', INT)
.option('--end <end_date>', 'End date for chart as YYYY-MM-DD', STRING)
.option('--no-color', 'Disable colors')
.option('--node <node_name>', 'Chain fees from saved node(s)', REPEATABLE)
.option('--start <start_date>', 'Start date for chart as YYYY-MM-DD', STRING)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return routing.getChainFeesChart({
days: options.days,
end_date: options.end,
is_monochrome: !!options.noColor,
lnds: (await lnd.getLnds({logger, nodes: options.node})).lnds,
request: commands.simpleRequest,
start_date: options.start,
},
responses.returnChart({logger, reject, resolve, data: 'data'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Show a chart of fees earned
.command('chart-fees-earned', 'Get a chart of earned routing fees')
.argument('[via]', 'Routing fees earned via a specified node or tag')
.help('Show the routing fees earned')
.option('--count', 'Show count of forwards instead of fees earned')
.option('--days <days>', 'Chart fees over the past number of days', INT)
.option('--end <end_date>', 'End date for chart as YYYY-MM-DD', STRING)
.option('--forwarded', 'Show amount forwarded instead of fees earned')
.option('--node <node_name>', 'Get saved node fees earned', REPEATABLE)
.option('--start <start_date>', 'Start date for chart as YYYY-MM-DD', STRING)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return routing.getFeesChart({
days: options.days,
end_date: options.end,
fs: {getFile: readFile},
is_count: options.count,
is_forwarded: options.forwarded,
lnds: (await lnd.getLnds({logger, nodes: options.node})).lnds,
start_date: options.start,
via: args.via || undefined,
},
responses.returnChart({logger, reject, resolve, data: 'data'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Show a chart of routing fees paid
.command('chart-fees-paid', 'Get a chart of paid routing fees')
.help('Show the routing fees paid to forwarding nodes')
.help('--rebalances can return results much more quickly')
.option('--days <days>', 'Chart fees over the past number of days', INT)
.option('--end <end_date>', 'End date for chart as YYYY-MM-DD', STRING)
.option('--in <key_or_alias>', 'Fees paid on routes in node with peer')
.option('--most-fees', 'View table of fees paid per node')
.option('--most-forwarded', 'View table of forwarded per node')
.option('--network', 'Show only non-peers in table view')
.option('--node <node_name>', 'Get fees chart for saved node(s)', REPEATABLE)
.option('--out <key_or_alias>', 'Fees paid on routes out node with peer')
.option('--peers', 'Show only peers in table view')
.option('--rebalances', 'Only consider fees paid in self-to-self transfers')
.option('--start <start_date>', 'Start date for chart as YYYY-MM-DD', STRING)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
const data = 'data';
const table = 'rows';
const asTable = responses.returnObject({logger, reject, resolve, table});
const chart = responses.returnChart({data, logger, reject, resolve});
try {
return routing.getFeesPaid({
days: options.days,
end_date: options.end,
fs: {getFile: readFile},
in: options.in,
is_most_fees_table: options.mostFees,
is_most_forwarded_table: options.mostForwarded,
is_network: options.network,
is_peer: options.peers,
is_rebalances_only: options.rebalances,
lnds: (await lnd.getLnds({logger, nodes: options.node})).lnds,
out: options.out,
start_date: options.start,
},
(options.mostFees || options.mostForwarded) ? asTable : chart);
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Chart earnings from payments received
.command('chart-payments-received', 'Get a chart of received payments')
.help('Show chart for settled invoices from external parties')
.option('--count', 'Show count of settled instead of amount received')
.option('--days <days>', 'Chart over the past number of days', INT)
.option('--end <end_date>', 'Final date for chart as YYYY-MM-DD', STRING)
.option('--for <query>', 'Only consider payments including a specific query')
.option('--node <node_name>', 'Get payments from saved node(s)', REPEATABLE)
.option('--start <start_date>', 'Start date for chart as YYYY-MM-DD', STRING)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return wallets.getReceivedChart({
days: options.days,
end_date: options.end,
is_count: options.count,
lnds: (await lnd.getLnds({logger, nodes: options.node})).lnds,
query: options.for,
start_date: options.start,
},
responses.returnChart({logger, reject, resolve, data: 'data'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Clean a command of unnecessary references
.command('clean-command', 'Clean command to remove outdated references')
.visible(false)
.argument('<command>', 'Escaped command to cleanup')
.option('--node <node_name>', 'Saved node to use for lookups')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return commands.clean({
lnd: (await lndForNode(logger, options.node)).lnd,
command: args.command,
},
responses.returnOutput({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Clean out failed payments
.command('clean-failed-payments', 'Clean out past failed payment data')
.help('Remove old failed payment data for probes and other failed payments')
.option('--dryrun', 'Avoid actually deleting the failed payment record')
.option('--node <node_name>', 'Clean failed payments on a saved node')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return wallets.cleanFailedPayments({
logger,
is_dry_run: !!options.dryrun,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Determine the outcomes of channel closings
.command('closed', 'Get the status of a channel closings')
.help('Channel closes with chain-transaction derived resolution details')
.help('Privacy note: this requests tx data from third parties')
.option('--limit [limit]', 'Limit of closings to get', INT, 20)
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Get channel closes from saved node')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return chain.getChannelCloses({
limit: options.limit,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
request: commands.simpleRequest,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Connect to a node
.command('connect', 'Connect to a node')
.argument('<id>', 'Public key id of node to connect to')
.option('--node <node_name>', 'Saved node to connect with')
.option('--retries <count>', 'Times to retry the connection', INT)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return peers.connectToPeer({
logger,
id: args.id,
lnd: (await lndForNode(logger, options.node)).lnd,
retries: options.retries,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Coordinate a new group channel
.command('create-channel-group', 'Coordinate balanced channels group')
.help('Other nodes can join the group using join-channel-group')
.help('When using --allow, all joining nodes must be identified')
.help('To specify order of group pairings, order using --allow ordering')
.help('For 2 person channels the joining node is the channel initiator')
.help('Do not use a chain fee that will not confirm within two weeks')
.option('--allow <public_key>', 'Only allow these nodes to join', REPEATABLE)
.option('--capacity <channel_capacity>', 'Channel capacity', INT, 5e6)
.option('--fee-rate <per_vbyte>', 'Chain fee rate for open', INT)
.option('--node <node_name>', 'Use saved node to create channels group')
.option('--size <count>', 'Number of group members', INT, 3)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const {lnd} = await lndForNode(logger, options.node);
const defaultRate = await lnService.getChainFeeRate({lnd});
return await paidServices.createGroupChannel({
lnd,
logger,
capacity: options.capacity,
count: options.size,
members: flatten([options.allow].filter(n => !!n)),
rate: options.feeRate || floor(defaultRate.tokens_per_vbyte),
},
responses.returnObject({exit, logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Create a fanout group
.command('create-fanout-group', 'Coordinate a group to fanout utxos')
.help('Other nodes can join the group using join-channel-group')
.help('When using --allow, all joining nodes must be identified')
.help('To specify order of group pairings, order using --allow ordering')
.help('For 2 person channels the joining node is the channel initiator')
.option('--allow <public_key>', 'Only allow these nodes to join', REPEATABLE)
.option('--output-size <output_size>', 'Output size', INT, 5e6)
.option('--fee-rate <per_vbyte>', 'Chain fee rate for open', INT)
.option('--node <node_name>', 'Use saved node to create channels group')
.option('--size <count>', 'Number of group members', INT, 3)
.option('--output-count <count>', 'Number of fanout sized outputs', INT, 1)
.option('--select-utxos', 'Specify UTXOs to spend interactively from a list')
.option('--utxo <outpoint>', 'Spend a specific tx_id:vout', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const {lnd} = await lndForNode(logger, options.node);
const defaultRate = await lnService.getChainFeeRate({lnd});
return await paidServices.createGroupFanout({
lnd,
logger,
ask: await commands.interrogate({}),
capacity: options.outputSize,
count: options.size,
inputs: flatten([options.utxo].filter(n => !!n)),
is_selecting_utxos: options.selectUtxos || !options.utxo,
members: flatten([options.allow].filter(n => !!n)),
output_count: options.outputCount,
rate: options.feeRate || floor(defaultRate.tokens_per_vbyte),
},
responses.returnObject({exit, logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Export LND credentials
.command('credentials', 'Export local credentials')
.help('Output encrypted remote access credentials. Use with "nodes --add"')
.option('--cleartext', 'Output remote access credentials without encryption')
.option('--days <days>', 'Expiration days for credentials', INT, 365)
.option('--method <method_name>', 'White-list specific method', REPEATABLE)
.option('--node <node_name>', 'Get credentials for a saved node')
.option('--nospend', 'Credentials do not include spending privileges')
.option('--readonly', 'Credentials only include read permissions')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
return lnd.getCredentials({
logger,
ask: await commands.interrogate({}),
expire_days: options.days,
is_cleartext: options.cleartext,
is_nospend: options.nospend,
is_readonly: options.readonly,
methods: flatten([options.method].filter(n => !!n)),
node: options.node,
},
responses.returnObject({logger, reject, resolve}));
});
})
// Decrypt a message
.command('decrypt', 'Decrypt data using the node key')
.visible(false)
.argument('<encrypted>', 'Encrypted message')
.help('Decrypt a message encrypted to the node key or to another node key')
.option('--node <node_name>', 'Node to decrypt with')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return encryption.decryptWithNode({
encrypted: args.encrypted,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Delete all payments
.command('delete-payments-history', 'Delete all records of past payments')
.visible(false)
.option('--node <node_name>', 'Node to delete all past payments on')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return lnService.deletePayments({
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Encrypt a message
.command('encrypt', 'Encrypt data using the node key')
.visible(false)
.help('Encrypt a message to the node key or to another node key')
.option('--node <node_name>', 'Node to encrypt with')
.option('--message <message>', 'Text message to encrypt')
.option('--to <to>', 'Encrypt message to another node')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return encryption.encryptToNode({
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
message: options.message,
to: options.to,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Fan out utxos
.command('fanout', 'Fan out utxos')
.visible(false)
.argument('<size>', 'UTXO minimum size', INT)
.argument('<count>', 'Desired number of total utxos', INT)
.help('Make a bunch of utxos by making a tx with a bunch of outputs')
.option('--confirmed', 'Only consider confirmed existing utxos')
.option('--dryrun', 'Execute a fan-out dry run')
.option('--feerate <feerate>', 'Feerate in per vbyte rate', INT)
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Node to do fan out for')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return chain.splitUtxos({
count: args.count,
is_confirmed: !!options.confirmed,
is_dry_run: !!options.dryrun,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
size: args.size,
tokens_per_vbyte: options.feerate,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Show and set routing policy fee rates
.command('fees', 'Show and adjust routing fee rates')
.help('List out fee rates, fix problems with routing policies, set out fees')
.help('When setting fee, if channels pending, will wait for confirm to set')
.help('--set-fee-rate can use formulas: https://formulajs.info/functions/')
.help('Specify PERCENT(0.00) to set the fee as a fraction of routed amount')
.help('Specify BIPS() to set the fee as parts per thousand')
.help('You can use INBOUND and OUTBOUND in formulas for IF formulas')
.help('You can use INBOUND_FEE_RATE to mirror an inbound fee')
.help('You can use FEE_RATE_OF_<PUBKEY> to reference other node rates')
.help('--set-inbound-discount-rate is total discount on traffic from peer')
.option('--node <node_name>', 'Saved node (not peer to set fees on)')
.option('--set-cltv-delta <count>', 'Set the number of blocks for CLTV', INT)
.option('--set-fee-rate <rate>', 'Fee in parts per million or use a formula')
.option('--set-inbound-rate-discount <rate>', 'Source discount rate in PPM')
.option('--to <peer>', 'Peer key/alias/tag to set fees', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return routing.adjustFees({
logger,
cltv_delta: options.setCltvDelta,
fee_rate: options.setFeeRate,
fs: {getFile: readFile},
inbound_rate_discount: options.setInboundRateDiscount,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
to: flatten([options.to].filter(n => !!n)),
},
responses.returnObject({logger, reject, resolve, table: 'rows'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Query the node to search for something
.command('find', 'Find a record')
.help('Look for something in the node db that matches a query')
.argument('<query>', 'Query for a record')
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Node to find record on')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return lnd.findRecord({
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
query: args.query,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Get forwards
.command('forwards', 'Show recent forwarding earnings')
.help('Peers where routing has taken place from inbound and outbound sides')
.help('Sorts: earned_in/earned_out/earned_total/inbound/liquidity/outbound')
.option('--complete', 'Show complete set of records in non table view')
.option('--days <days>', 'Number of past days to evaluate', INT)
.option('--in <from>', 'Forwards that originated from a specific peer')
.option('--no-color', 'Mute all colors')
.option('--node <node_name>', 'Node to get forwards for')
.option('--out <to>', 'Forwards that sent out to a specified peer')
.option('--sort <type>', 'Sort forward-active peers by earnings/liquidity')
.option('--tag <tag_name>', 'Only show peers in a tag', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const {lnd} = await lndForNode(logger, options.node);
const table = !!options.complete ? undefined : 'rows';
return network.getForwards({
lnd,
days: options.days,
from: (await lnSync.findKey({lnd, query: options.in})).public_key,
fs: {getFile: readFile},
is_monochrome: !!options.noColor,
is_table: !options.complete,
sort: options.sort || undefined,
tags: collect(options.tag),
to: (await lnSync.findKey({lnd, query: options.out})).public_key,
},
responses.returnObject({logger, reject, resolve, table}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Fund and sign a chain transaction
.command('fund', 'Make a signed transaction spending on-chain funds')
.help('Use LND UTXOs to craft a signed raw transaction sending to addresses')
.help('Specify <address> <amount> <address> <amount> for addresses, amounts')
.help('Amounts support formulas, use MAX to reference selected UTXOs total')
.help('--utxo can be specified multiple times to spend multiple UTXOs')
.argument('<address_amount...>', 'Address and amount to send')
.option('--broadcast', 'Broadcast the signed transaction')
.option('--dryrun', 'Avoid locking up UTXOs')
.option('--fee-rate <fee>', 'Per vbyte fee rate for on-chain tx fee')
.option('--node <node_name>', 'Node to spend coins')
.option('--select-utxos', 'Specify UTXOs to spend interactively from a list')
.option('--utxo <outpoint>', 'Spend a specific tx_id:vout', REPEATABLE)
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return chain.fundTransaction({
logger,
addresses: args.addressAmount.filter((n, i) => !(i % 2)),
amounts: args.addressAmount.filter((n, i) => i % 2),
ask: await commands.interrogate({}),
fee_tokens_per_vbyte: options.feeRate,
is_broadcast: options.broadcast,
is_dry_run: !!options.dryrun,
is_selecting_utxos: options.selectUtxos,
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
utxos: flatten([options.utxo].filter(n => !!n)),
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Buy an inbound channel
.command('get-inbound-channel', 'Buy an inbound channel')
.help('Obtain an inbound channel from a node on the network')
.argument('[service]', 'Public key identity of node to get channel from')
.option('--amount <tokens>', 'Capacity of inbound channel desired', INT, 5e6)
.option('--days <days>', 'Minimum days expected for channel lifetime')
.option('--dryrun <dryrun>', 'Request a price quote only')
.option('--max-wait-hours <hours>', 'Hours to wait for the open', INT, 40)
.option('--node <node_name>', 'Node to get inbound channel for')
.option('--recovery <orderId>', 'Check the status of prior order', STRING)
.option('--type <type>', 'Channel type: private/public', STRING, 'public')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
return lsp.lsps1Client({
logger,
ask: await commands.interrogate({}),
capacity: options.amount,
fs: {getFile: readFile},
is_dry_run: !!options.dryrun,
lifetime: options.days,
lnd: (await lndForNode(logger, options.node)).lnd,
max_wait_hours: options.maxWaitHours,
recovery: options.recovery,
service_node: args.service,
type: options.type,
},
responses.returnObject({logger, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Give a peer some tokens
.command('gift', 'Give a direct peer some free funds off-chain')
.visible(false)
.help('Send some funds to a connected peer')
.argument('<target>', 'Peer to give funds to')
.argument('<amount>', 'Tokens to give', INT)
.option('--node <node_name>', 'Source node to use to pay gift')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
const number = 'gave_tokens';
try {
return network.sendGift({
lnd: (await lnd.authenticatedLnd({logger, node: options.node})).lnd,
to: args.target,
tokens: args.amount,
},
responses.returnNumber({logger, number, reject, resolve}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Get the edges of a given node
.command('graph', 'List out the connections a node has with other nodes')
.argument('<alias_or_public_key>', 'Node in the graph to look up')
.help('--filter variables: AGE/CAPACITY/HOPS/IN_FEE_RATE/OUT_FEE_RATE')
.help('Example: --filter "age<7*144" for connections in the last week')
.help(' ←-PPM will represent a source-based inbound discount when present')
.option('--filter <formula>', 'Filter formula to apply', REPEATABLE)
.option('--node <node_name>', 'Node to use for lookup')
.option('--sort <sort_connections_by', 'Sort peers by field')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
try {
const {lnd} = await lndForNode(logger, options.node);
return network.getGraphEntry({
lnd,
logger,
filters: flatten([options.filter].filter(n => !!n)),
fs: {getFile: readFile},
query: args.aliasOrPublicKey.trim(),
sort: options.sort,
},
responses.returnObject({logger, reject, resolve, table: 'rows'}));
} catch (err) {
return logger.error({err}) && reject();
}
});
})
// Intercept inbound channel requests and set requirements for inbound opens
.command('inbound-channel-rules', 'Enforce rules for inbound channels')
.help('Rules should be written evaluating to TRUE to accept a channel')
.help('Example rule: --rule "CAPACITY > 100000"')
.help('You can use multiple --rule flags to enforce multiple rules')
.help('Multiple --coop-close-address supported, will cycle through them')
.help('Avoid requiring Blockchain confirmations using --trust-funding-from')
.help('For formulas: CAPACITIES are the sizes of the peer public channels')
.help('For formulas: CAPACITY is the size of the requested channel open')
.help('For formulas: CHANNEL_AGES are the block ages of public channels')
.help('For formulas: CLEARNET is when peer advertises a clearnet address')
.help('For formulas: FEE_RATES are the outbound fee rates for the peer')
.help('For formulas: JOINT_PUBLIC_CAPACITY is graph capacity with the peer')
.help('For formulas: LOCAL_BALANCE is the gifted amount from the peer')
.help('For formulas: M is 1,000,000 - use like CAPACITY > 10*M')
.help('For formulas: OBSOLETE is chan type, like NOT(OBSOLETE)')
.help('For formulas: PUBLIC_KEY is the public key of the requesting peer')
.help('For formulas: PRIVATE is when request is for private channel')
.help('For formulas: TOR is when peer advertises a Tor address')
.help('For formulas: Use IF(X, Y, Z) to make branching condition rules')
.help('Try formulas on the sandbox: https://formulajs.info/functions/')
.option('--coop-close-address', 'Use a coop close address', REPEATABLE)