forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautogenerate-rpc-examples.py
2109 lines (1974 loc) · 160 KB
/
autogenerate-rpc-examples.py
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
# NOTE: For detailed documentation, refer to https://docs.corelightning.org/docs/writing-json-schemas.
# NOTE: Set the test `TIMEOUT` to greater than 3 seconds to prevent failures caused by waiting on the bitcoind response.
# The `dev-bitcoind-poll` interval is 3 seconds, so a shorter timeout may result in test failures.
# NOTE: Different nodes are selected to record examples based on data availability, quality, and volume.
# For example, node `l1` is used to capture examples for `listsendpays`, whereas node `l2` is utilized for `listforwards`.
from fixtures import * # noqa: F401,F403
from fixtures import TEST_NETWORK
from pyln.client import RpcError, Millisatoshi # type: ignore
from pyln.testing.utils import GENERATE_EXAMPLES
from utils import only_one, mine_funding_to_announce, sync_blockheight, wait_for, first_scid, serialize_payload_tlv, serialize_payload_final_tlv
import sys
import os
import re
import time
import pytest
import unittest
import json
import logging
import ast
import subprocess
CWD = os.getcwd()
CLN_VERSION = 'v'
with open(os.path.join('.version'), 'r') as f:
CLN_VERSION = CLN_VERSION + f.read().strip()
FUND_WALLET_AMOUNT_SAT = 200000000
FUND_CHANNEL_AMOUNT_SAT = 10**6
REGENERATING_RPCS = []
ALL_RPC_EXAMPLES = {}
EXAMPLES_JSON = {}
LOG_FILE = './tests/autogenerate-examples-status.log'
TEMP_EXAMPLES_FILE = './tests/autogenerate-examples.json'
IGNORE_RPCS_LIST = ['dev-splice', 'reckless', 'sql-template']
# Constants for replacing values in examples
NEW_VALUES_LIST = {
'root_dir': '/root/lightning',
'tmp_dir': '/tmp/.lightning',
'str_1': '1',
'num_1': 1,
'balance_msat_1': 202050000000,
'fees_paid_msat_1': 5020000,
'bytes_used': 1630000,
'bytes_max': 10485760,
'assocdata_1': 'assocdata0' + ('01' * 27),
'hsm_secret_cdx_1': 'cl10leetsd35kw6r5de5kueedxyesqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluplcg0lxenqd',
'error_message_1': 'All addresses failed: 127.0.0.1:19736: Cryptographic handshake: peer closed connection (wrong key?). ',
'configs_3_addr2': "127.0.0.1:19735",
'bitcoin-rpcport': 18332,
'grpc-port': 9736,
'blockheight_110': 110,
'blockheight_130': 130,
'blockheight_160': 160,
'script_pubkey_1': 'scriptpubkey' + ('01' * 28),
'script_pubkey_2': 'scriptpubkey' + ('02' * 28),
'onion_1': 'onion' + ('10' * 1363),
'onion_2': 'onion' + ('20' * 1363),
'onion_3': 'onion' + ('30' * 1363),
'shared_secrets_1': ['sharedsecret' + ('10' * 26), 'sharedsecret' + ('11' * 26), 'sharedsecret' + ('12' * 26)],
'shared_secrets_2': ['sharedsecret' + ('20' * 26), 'sharedsecret' + ('21' * 26), 'sharedsecret' + ('22' * 26)],
'invreq_id_1': 'invreqid' + ('01' * 28),
'invreq_id_2': 'invreqid' + ('02' * 28),
'invreq_id_l1_l22': 'invreqid' + ('03' * 28),
'invoice_1': 'lni1qqg0qe' + ('01' * 415),
'invoice_2': 'lni1qqg0qe' + ('02' * 415),
'invoice_3': 'lni1qqg0qe' + ('03' * 415),
'funding_txid_1': 'fundingtxid001' + ('01' * 25),
'funding_txid_2': 'fundingtxid002' + ('02' * 25),
'signature_1': 'dcde30c4bb50bed221009d' + ('01' * 60),
'signature_2': 'dcdepay30c4bb50bed209d' + ('02' * 60),
'destination_1': 'bcrt1p52' + ('01' * 28),
'destination_2': 'bcrt1qcqqv' + ('01' * 17),
'destination_3': 'bcrt1phtprcvhz' + ('02' * 25),
'destination_4': 'bcrt1p00' + ('02' * 28),
'destination_5': 'bcrt1p00' + ('03' * 28),
'destination_6': 'bcrt1p00' + ('04' * 28),
'destination_7': 'bcrt1p338x' + ('07' * 28),
'funding_serial_1': 17725655605188010000,
'funding_serial_2': 17725655605188020000,
'funding_serial_3': 17725655605188030000,
'funding_serial_4': 17725655605188040000,
'funding_serial_5': 17725655605188050000,
'l1_id': 'nodeid' + ('01' * 30),
'l2_id': 'nodeid' + ('02' * 30),
'l3_id': 'nodeid' + ('03' * 30),
'l4_id': 'nodeid' + ('04' * 30),
'l5_id': 'nodeid' + ('05' * 30),
'l10_id': 'nodeid' + ('10' * 30),
'l12_id': 'nodeid' + ('12' * 30),
'l1_alias': 'JUNIORBEAM',
'l2_alias': 'SILENTARTIST',
'l3_alias': 'HOPPINGFIRE',
'l4_alias': 'JUNIORFELONY',
'l2_port': 19735,
'l3_port': 19736,
'l1_addr': '127.0.0.1:19734',
'l2_addr': '127.0.0.1:19735',
'l3_addr': '127.0.0.1:19736',
'l4_addr': '127.0.0.1:19737',
'l5_addr': '127.0.0.1:19738',
'l6_addr': '127.0.0.1:19739',
'c12': '109x1x1',
'c23': '111x1x1',
'c23_2': '123x1x1',
'c25': '115x1x1',
'c34': '125x1x1',
'c34_2': '130x1x1',
'c35_tx': '020000000000305fundchanneltx' + ('35000' * 99),
'c41_tx': '020000000000401fundchanneltx' + ('41000' * 99),
'upgrade_tx': '02000000000101upgd' + ('20000' * 34),
'close1_tx': '02000000000101cls0' + ('01' * 200),
'close2_tx': '02000000000101cls1' + ('02' * 200),
'send_tx_1': '02000000000101sendpt' + ('64000' * 100),
'send_tx_2': '02000000000102sendpt' + ('65000' * 100),
'tx_55': '02000000000155multiw' + ('55000' * 100),
'tx_56': '02000000000155multiw' + ('56000' * 100),
'tx_61': '02000000000155multiw' + ('61000' * 100),
'tx_91': '020000000001wthdrw' + ('91000' * 100),
'tx_92': '020000000002wthdrw' + ('92000' * 100),
'unsigned_tx_1': '0200000000' + ('0002' * 66),
'unsigned_tx_3': '0200000000' + ('0006' * 66),
'unsigned_tx_4': '0200000000' + ('0008' * 66),
'multi_tx_1': '02000000000101multif' + ('50000' * 100),
'multi_tx_2': '02000000000102multif' + ('60000' * 100),
'ocs_tx_1': '02000000000101sgpsbt' + ('11000' * 100),
'ocs_tx_2': '02000000000101sgpsbt' + ('12000' * 100),
'txsend_tx_1': '02000000000101txsend' + ('00011' * 100),
'txsend_tx_2': '02000000000101txsend' + ('00022' * 100),
'c12_txid': 'channeltxid' + ('120000' * 9),
'c23_txid': 'channeltxid' + ('230000' * 9),
'c23_2_txid': 'channeltxid' + ('230200' * 9),
'c34_txid': 'channeltxid' + ('340000' * 9),
'c34_2_txid': 'channeltxid' + ('340200' * 9),
'c35_txid': 'channeltxid' + ('350000' * 9),
'c41_txid': 'channeltxid' + ('410000' * 9),
'c1112_txid': 'channeltxid' + ('111200' * 9),
'upgrade_txid': 'txidupgrade' + ('200000' * 9),
'close1_txid': 'txid' + ('01' * 30),
'close2_txid': 'txid' + ('02' * 30),
'send_txid_1': 'txid' + ('64000' * 11),
'send_txid_2': 'txid' + ('65000' * 11),
'txid_55': 'txid' + ('55000' * 11),
'txid_56': 'txid' + ('56000' * 11),
'txid_61': 'txid' + ('61000' * 11),
'withdraw_txid_l21': 'txidwithdraw21' + ('91000' * 10),
'withdraw_txid_l22': 'txidwithdraw22' + ('92000' * 10),
'txprep_txid_1': 'txidtxprep0001' + ('00001' * 10),
'txprep_txid_2': 'txidtxprep0002' + ('00002' * 10),
'txprep_txid_3': 'txidtxprep0003' + ('00003' * 10),
'txprep_txid_4': 'txidtxprep0004' + ('00004' * 10),
'multi_txid_1': 'channeltxid010' + ('50000' * 10),
'multi_txid_2': 'channeltxid020' + ('60000' * 10),
'utxo_1': 'utxo' + ('01' * 30),
'ocs_txid_1': 'txidocsigned10' + ('11000' * 10),
'ocs_txid_2': 'txidocsigned10' + ('12000' * 10),
'c12_channel_id': 'channelid0' + ('120000' * 9),
'c23_channel_id': 'channelid0' + ('230000' * 9),
'c23_2_channel_id': 'channelid0' + ('230200' * 9),
'c25_channel_id': 'channelid0' + ('250000' * 9),
'c34_channel_id': 'channelid0' + ('340000' * 9),
'c34_2_channel_id': 'channelid0' + ('340200' * 9),
'c35_channel_id': 'channelid0' + ('350000' * 9),
'c41_channel_id': 'channelid0' + ('410000' * 9),
'c78_channel_id': 'channelid0' + ('780000' * 9),
'c1112_channel_id': 'channelid0' + ('111200' * 9),
'c910_channel_id_1': 'channelid' + ('09101' * 11),
'c910_channel_id_2': 'channelid' + ('09102' * 11),
'mf_channel_id_1': 'channelid' + ('11000' * 11),
'mf_channel_id_2': 'channelid' + ('12000' * 11),
'mf_channel_id_3': 'channelid' + ('13000' * 11),
'mf_channel_id_4': 'channelid' + ('15200' * 11),
'mf_channel_id_5': 'channelid' + ('12400' * 11),
'time_at_800': 1738000000,
'time_at_850': 1738500000,
'time_at_900': 1739000000,
'bolt11_l11': 'lnbcrt100n1pnt2' + ('bolt11invl010100000000' * 10),
'bolt11_l12': 'lnbcrt100n1pnt2' + ('bolt11invl010200000000' * 10),
'bolt11_l13': 'lnbcrt100n1pnt2' + ('bolt11invl010300000000' * 10),
'bolt11_l14': 'lnbcrt100n1pnt2' + ('bolt11invl010400000000' * 10),
'bolt11_l21': 'lnbcrt100n1pnt2' + ('bolt11invl020100000000' * 10),
'bolt11_l22': 'lnbcrt100n1pnt2' + ('bolt11invl020200000000' * 10),
'bolt11_l23': 'lnbcrt100n1pnt2' + ('bolt11invl020300000000' * 10),
'bolt11_l24': 'lnbcrt100n1pnt2' + ('bolt11invl020400000000' * 10),
'bolt11_l25': 'lnbcrt100n1pnt2' + ('bolt11invl020500000000' * 10),
'bolt11_l26': 'lnbcrt100n1pnt2' + ('bolt11invl020600000000' * 10),
'bolt11_l27': 'lnbcrt100n1pnt2' + ('bolt11invl020700000000' * 10),
'bolt11_l31': 'lnbcrt100n1pnt2' + ('bolt11invl030100000000' * 10),
'bolt11_l33': 'lnbcrt100n1pnt2' + ('bolt11invl030300000000' * 10),
'bolt11_l34': 'lnbcrt100n1pnt2' + ('bolt11invl030400000000' * 10),
'bolt11_l41': 'lnbcrt100n1pnt2' + ('bolt11invl040100000000' * 10),
'bolt11_l66': 'lnbcrt100n1pnt2' + ('bolt11invl060600000000' * 10),
'bolt11_l67': 'lnbcrt100n1pnt2' + ('bolt11invl060700000000' * 10),
'bolt11_wt_1': 'lnbcrt222n1pnt3005720bolt11wtinv' + ('01' * 160),
'bolt11_wt_2': 'lnbcrt222n1pnt3005720bolt11wtinv' + ('02' * 160),
'bolt11_di_1': 'lnbcrt222n1pnt3005720bolt11300' + ('01' * 170),
'bolt11_di_2': 'lnbcrt222n1pnt3005720bolt11300' + ('01' * 170),
'bolt11_dp_1': 'lnbcrt222n1pnt3005720bolt11400' + ('01' * 170),
'bolt12_l21': 'lno1qgsq000bolt' + ('21000' * 24),
'bolt12_l22': 'lno1qgsq000bolt' + ('22000' * 24),
'bolt12_l23': 'lno1qgsq000bolt' + ('23000' * 24),
'bolt12_l24': 'lno1qgsq000bolt' + ('24000' * 24),
'bolt12_si_1': 'lno1qgsq000bolt' + ('si100' * 24),
'offerid_l21': 'offeridl' + ('2100000' * 8),
'offerid_l22': 'offeridl' + ('2200000' * 8),
'offerid_l23': 'offeridl' + ('2300000' * 8),
'payment_hash_l11': 'paymenthashinvl0' + ('1100' * 12),
'payment_hash_l21': 'paymenthashinvl0' + ('2100' * 12),
'payment_hash_l22': 'paymenthashinvl0' + ('2200' * 12),
'payment_hash_l27': 'paymenthashinvl0' + ('2700' * 12),
'payment_hash_l31': 'paymenthashinvl0' + ('3100' * 12),
'payment_hash_l24': 'paymenthashinvl0' + ('2400' * 12),
'payment_hash_l25': 'paymenthashinvl0' + ('2500' * 12),
'payment_hash_l26': 'paymenthashinvl0' + ('2600' * 12),
'payment_hash_l33': 'paymenthashinvl0' + ('3300' * 12),
'payment_hash_l34': 'paymenthashinvl0' + ('3400' * 12),
'payment_hash_key_1': 'paymenthashkey01' + ('k101' * 12),
'payment_hash_key_2': 'paymenthashkey02' + ('k201' * 12),
'payment_hash_key_3': 'paymenthashkey03' + ('k301' * 12),
'payment_hash_cmd_pay_1': 'paymenthashcmdpy' + ('cp10' * 12),
'payment_hash_si_1': 'paymenthashsdinv' + ('si10' * 12),
'payment_hash_wspc_1': 'paymenthashwtspct2' + ('01' * 23),
'payment_hash_winv_1': 'paymenthashwaitinv' + ('01' * 23),
'payment_hash_winv_2': 'paymenthashwaitinv' + ('02' * 23),
'payment_hash_di_1': 'paymenthashdelinv1' + ('01' * 23),
'payment_hash_di_2': 'paymenthashdelinv2' + ('02' * 23),
'payment_hash_dp_1': 'paymenthashdelpay1' + ('01' * 23),
'payment_hash_dp_2': 'paymenthashdelpay2' + ('02' * 23),
'payment_hash_dp_3': 'paymenthashdelpay3' + ('03' * 23),
'payment_preimage_1': 'paymentpreimage1' + ('01' * 24),
'payment_preimage_2': 'paymentpreimage2' + ('02' * 24),
'payment_preimage_3': 'paymentpreimage3' + ('03' * 24),
'payment_preimage_ep_1': 'paymentpreimagep' + ('01' * 24),
'payment_preimage_ep_2': 'paymentpreimagep' + ('02' * 24),
'payments_preimage_i_1': 'paymentpreimagei' + ('01' * 24),
'payments_preimage_w_1': 'paymentpreimagew' + ('01' * 24),
'payment_preimage_cmd_1': 'paymentpreimagec' + ('01' * 24),
'payment_preimage_r_1': 'paymentpreimager' + ('01' * 24),
'payment_preimage_r_2': 'paymentpreimager' + ('02' * 24),
'payment_preimage_wi_1': 'paymentpreimagewaitinv0' + ('01' * 21),
'payment_preimage_wi_2': 'paymentpreimagewaitinv0' + ('02' * 21),
'payment_preimage_di_1': 'paymentpreimagedelinv01' + ('01' * 21),
'payment_preimage_dp_1': 'paymentpreimgdp1' + ('01' * 24),
'payment_preimage_xp_1': 'paymentpreimgxp1' + ('01' * 24),
'payment_preimage_xp_2': 'paymentpreimgxp2' + ('02' * 24),
'payment_preimage_io_1': 'paymentpreimgio1' + ('03' * 24),
'payment_secret_l11': 'paymentsecretinvl00' + ('11000' * 9),
'payment_secret_l22': 'paymentsecretinvl00' + ('22000' * 9),
'payment_secret_l31': 'paymentsecretinvl00' + ('31000' * 9),
'init_psbt_1': 'cHNidP8BAgpsbt10' + ('01' * 52),
'init_psbt_2': 'cHNidP8BAgpsbt20' + ('02' * 84),
'init_psbt_3': 'cHNidP8BAgpsbt30' + ('03' * 92),
'upgrade_psbt_1': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('110000' * 100),
'psbt_1': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('711000' * 120),
'psbt_2': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('712000' * 120),
'psbt_3': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('713000' * 120),
'psbt_4': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('714000' * 120),
'psbt_5_1': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('715100' * 120),
'psbt_5_2': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('715200' * 120),
'psbt_6_1': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('716100' * 120),
'psbt_6_2': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('716200' * 120),
'psbt_7': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('911000' * 40),
'psbt_8': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('922000' * 40),
'psbt_9': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('101000' * 40),
'psbt_10': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('201000' * 40),
'psbt_12': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('401000' * 40),
'psbt_13': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('310000' * 40),
'psbt_14': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('410000' * 40),
'psbt_15': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('510000' * 40),
'psbt_16': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('520000' * 40),
'psbt_17': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('610000' * 40),
'psbt_18': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('710000' * 40),
'psbt_19': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('810000' * 40),
'psbt_20': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('910000' * 40),
'psbt_21': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('101000' * 40),
'psbt_22': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('111000' * 40),
'psbt_23': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('121000' * 40),
'psbt_24': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('011100' * 40),
'psbt_25': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('011200' * 40),
'psbt_26': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('022200' * 40),
'signed_psbt_1': 'cHNidP8BAgQCAAAAAQMEbwAAAAEEAQpsbt' + ('718000' * 120),
'htlc_max_msat': 18446744073709552000,
}
# Used for collecting values from responses and replace them with NEW_VALUES_LIST before updating examples in schema files
REPLACE_RESPONSE_VALUES = [
{'data_keys': ['any'], 'original_value': re.compile(re.escape(CWD)), 'new_value': NEW_VALUES_LIST['root_dir']},
{'data_keys': ['any'], 'original_value': re.compile(r'/tmp/ltests-[^/]+/test_generate_examples_[^/]+/lightning-[^/]+'), 'new_value': NEW_VALUES_LIST['tmp_dir']},
{'data_keys': ['outnum', 'funding_outnum', 'vout'], 'original_value': '0', 'new_value': NEW_VALUES_LIST['str_1']},
{'data_keys': ['outnum', 'funding_outnum', 'vout'], 'original_value': 0, 'new_value': NEW_VALUES_LIST['num_1']},
{'data_keys': ['outnum', 'funding_outnum', 'vout'], 'original_value': 2, 'new_value': NEW_VALUES_LIST['num_1']},
{'data_keys': ['outnum', 'funding_outnum', 'vout'], 'original_value': 3, 'new_value': NEW_VALUES_LIST['num_1']},
{'data_keys': ['type'], 'original_value': 'unilateral', 'new_value': 'mutual'},
]
if os.path.exists(LOG_FILE):
open(LOG_FILE, 'w').close()
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%H:%M:%S',
handlers=[
logging.FileHandler(LOG_FILE),
logging.StreamHandler()
])
logger = logging.getLogger(__name__)
class MissingExampleError(Exception):
pass
def update_list_responses(data, list_key=None, slice_upto=5, update_func=None, sort=False, sort_key=None):
"""Update responses received from various list rpcs to limit the number of items in the list, sort the list and update the values in the list"""
if list_key is not None:
if isinstance(data[list_key], list):
data[list_key] = data[list_key][0:slice_upto]
if sort:
data[list_key] = sorted(data[list_key], key=lambda x: x[sort_key]) if sort_key is not None else {k: data[list_key][k] for k in sorted(data[list_key])}
if update_func is not None and isinstance(data[list_key], list):
for i, item in enumerate(data[list_key]):
update_func(item, i)
return data
def replace_values_in_json(data, data_key):
"""Replace values in JSON data with new values before saving them in the schema files"""
if isinstance(data, dict):
return {key: replace_values_in_json(value, key) for key, value in data.items()}
elif isinstance(data, list):
for replace_value in REPLACE_RESPONSE_VALUES:
if any(item == 'any' or item == data_key for item in replace_value['data_keys']) and data == replace_value['original_value']:
data = replace_value['new_value']
return data
return [replace_values_in_json(item, 'listitem') for item in data]
elif isinstance(data, str):
for replace_value in REPLACE_RESPONSE_VALUES:
if any(item == data_key for item in replace_value['data_keys']) and data == replace_value['original_value']:
data = replace_value['new_value']
break
elif any(item == 'any' for item in replace_value['data_keys']) and isinstance(replace_value['original_value'], str) and data == replace_value['original_value']:
data = data.replace(replace_value['original_value'], replace_value['new_value'])
break
elif replace_value['data_keys'] == ['any'] and isinstance(replace_value['original_value'], re.Pattern):
if re.match(replace_value['original_value'], data):
data = replace_value['original_value'].sub(replace_value['new_value'], data)
break
return data
elif isinstance(data, (int, float)):
for replace_value in REPLACE_RESPONSE_VALUES:
if any(item == 'any' or item == data_key for item in replace_value['data_keys']) and data == replace_value['original_value']:
data = replace_value['new_value']
break
return data
else:
return data
def update_examples_in_schema_files():
"""Update examples in JSON schema files"""
try:
# For testing
if os.path.exists(TEMP_EXAMPLES_FILE):
open(TEMP_EXAMPLES_FILE, 'w').close()
with open(TEMP_EXAMPLES_FILE, 'w+', encoding='utf-8') as file:
json.dump({'new_values_list': NEW_VALUES_LIST, 'replace_response_values': REPLACE_RESPONSE_VALUES[4:], 'examples_json': EXAMPLES_JSON}, file, indent=2, ensure_ascii=False)
updated_examples = {}
for method, method_examples in EXAMPLES_JSON.items():
try:
global CWD
file_path = os.path.join(CWD, 'doc', 'schemas', f'lightning-{method}.json') if method != 'sql' else os.path.join(CWD, 'doc', 'schemas', f'lightning-{method}-template.json')
logger.info(f'Updating examples for {method} in file {file_path}')
with open(file_path, 'r+', encoding='utf-8') as file:
data = json.load(file)
updated_examples[method] = replace_values_in_json(method_examples, 'examples')['examples']
data['examples'] = updated_examples[method]
file.seek(0)
json.dump(data, file, indent=2, ensure_ascii=False)
file.write('\n')
file.truncate()
except FileNotFoundError as fnf_error:
logger.error(f'File not found error {fnf_error} for {file_path}')
raise
except Exception as e:
logger.error(f'Error saving example in file {file_path}: {e}')
raise
except Exception as e:
logger.error(f'Error updating examples in schema files: {e}')
raise
# For testing
if os.path.exists(TEMP_EXAMPLES_FILE):
open(TEMP_EXAMPLES_FILE, 'w').close()
with open(TEMP_EXAMPLES_FILE, 'w+', encoding='utf-8') as file:
json.dump({'new_values_list': NEW_VALUES_LIST, 'replace_response_values': REPLACE_RESPONSE_VALUES[4:], 'examples_json': EXAMPLES_JSON, 'updated_examples_json': updated_examples}, file, indent=2, ensure_ascii=False)
logger.info(f'Updated All Examples in Schema Files!')
return None
def update_example(node, method, params, response=None, description=None):
"""Add example request, response and other details in json array for future use"""
method_examples = EXAMPLES_JSON.get(method, {'examples': []})
method_id = len(method_examples['examples']) + 1
req = {
'id': f'example:{method}#{method_id}',
'method': method,
'params': params
}
logger.info(f'Method \'{method}\', Params {params}')
# Execute the RPC call and get the response
if response is None:
response = node.rpc.call(method, params)
logger.info(f'{method} response: {response}')
# Return response without updating the file because user doesn't want to update the example
# Executing the method and returning the response is useful for further example updates
if method not in REGENERATING_RPCS:
return response
else:
method_examples['examples'].append({'request': req, 'response': response} if description is None else {'description': description, 'request': req, 'response': response})
EXAMPLES_JSON[method] = method_examples
logger.info(f'Updated {method}#{method_id} example json')
return response
def setup_test_nodes(node_factory, bitcoind):
"""Sets up six test nodes for various transaction scenarios:
l1, l2, l3 for transactions and forwards
l4 for complex transactions (sendpayment, keysend, renepay)
l5 for keysend with routehints and channel backup & recovery
l5, l6 for backup and recovery
l7, l8 for splicing (added later)
l9, l10 for low level fundchannel examples (added later)
l11, l12 for low level openchannel examples (added later)
l13 for recover (added later)
l1->l2, l2->l3, l3->l4, l2->l5 (unannounced), l9->l10, l11->l12
l1.info['id']: 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518
l2.info['id']: 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59
l3.info['id']: 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d
l4.info['id']: 0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199
l5.info['id']: 032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e
l6.info['id']: 0265b6ab5ec860cd257865d61ef0bbf5b3339c36cbda8b26b74e7f1dca490b6518
"""
try:
global FUND_WALLET_AMOUNT_SAT, FUND_CHANNEL_AMOUNT_SAT
options = [
{
'experimental-dual-fund': None,
'may_reconnect': True,
'dev-hsmd-no-preapprove-check': None,
'dev-no-plugin-checksum': None,
'dev-no-version-checks': None,
'allow-deprecated-apis': True,
'allow_bad_gossip': True,
'log-level': 'debug',
'broken_log': '.*',
'dev-bitcoind-poll': 3, # Default 1; increased to avoid rpc failures
}.copy()
for i in range(6)
]
l1, l2, l3, l4, l5, l6 = node_factory.get_nodes(6, opts=options)
# Upgrade wallet
# Write the data/p2sh_wallet_hsm_secret to the hsm_path, so node can spend funds at p2sh_wrapped_addr
p2sh_wrapped_addr = '2N2V4ee2vMkiXe5FSkRqFjQhiS9hKqNytv3'
update_example(node=l1, method='upgradewallet', params={})
txid = bitcoind.rpc.sendtoaddress(p2sh_wrapped_addr, 20000000 / 10 ** 8)
bitcoind.generate_block(1)
l1.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'.format(txid))
# Doing it with 'reserved ok' should have 1. We use a big feerate so we can get over the RBF hump
upgrade_res2 = update_example(node=l1, method='upgradewallet', params={'feerate': 'urgent', 'reservedok': True})
# Fund node wallets for further transactions
fund_nodes = [l1, l2, l3, l4, l5]
for node in fund_nodes:
node.fundwallet(FUND_WALLET_AMOUNT_SAT)
# Connect nodes and fund channels
getinfo_res2 = update_example(node=l2, method='getinfo', params={})
update_example(node=l1, method='connect', params={'id': l2.info['id'], 'host': 'localhost', 'port': l2.daemon.port})
update_example(node=l2, method='connect', params={'id': l3.info['id'], 'host': 'localhost', 'port': l3.daemon.port})
l3.rpc.connect(l4.info['id'], 'localhost', l4.port)
l2.rpc.connect(l5.info['id'], 'localhost', l5.port)
c12, c12res = l1.fundchannel(l2, FUND_CHANNEL_AMOUNT_SAT)
c23, c23res = l2.fundchannel(l3, FUND_CHANNEL_AMOUNT_SAT)
c34, c34res = l3.fundchannel(l4, FUND_CHANNEL_AMOUNT_SAT)
c25, c25res = l2.fundchannel(l5, announce_channel=False)
mine_funding_to_announce(bitcoind, [l1, l2, l3, l4])
l1.wait_channel_active(c12)
l1.wait_channel_active(c23)
l1.wait_channel_active(c34)
# Balance these newly opened channels
l1.rpc.pay(l2.rpc.invoice('500000sat', 'lbl balance l1 to l2', 'description send some sats l1 to l2')['bolt11'])
l2.rpc.pay(l3.rpc.invoice('500000sat', 'lbl balance l2 to l3', 'description send some sats l2 to l3')['bolt11'])
l2.rpc.pay(l5.rpc.invoice('500000sat', 'lbl balance l2 to l5', 'description send some sats l2 to l5')['bolt11'])
l3.rpc.pay(l4.rpc.invoice('500000sat', 'lbl balance l3 to l4', 'description send some sats l3 to l4')['bolt11'])
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['any', 'id', 'pubkey', 'destination'], 'original_value': l1.info['id'], 'new_value': NEW_VALUES_LIST['l1_id']},
{'data_keys': ['any', 'id', 'pubkey', 'destination'], 'original_value': l2.info['id'], 'new_value': NEW_VALUES_LIST['l2_id']},
{'data_keys': ['any', 'id', 'pubkey', 'destination'], 'original_value': l3.info['id'], 'new_value': NEW_VALUES_LIST['l3_id']},
{'data_keys': ['any', 'id', 'pubkey', 'destination'], 'original_value': l4.info['id'], 'new_value': NEW_VALUES_LIST['l4_id']},
{'data_keys': ['any', 'id', 'pubkey', 'destination'], 'original_value': l5.info['id'], 'new_value': NEW_VALUES_LIST['l5_id']},
{'data_keys': ['alias'], 'original_value': l1.info['alias'], 'new_value': NEW_VALUES_LIST['l1_alias']},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l1.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l1_addr']]},
{'data_keys': ['alias'], 'original_value': l2.info['alias'], 'new_value': NEW_VALUES_LIST['l2_alias']},
{'data_keys': ['port'], 'original_value': l2.info['binding'][0]['port'], 'new_value': NEW_VALUES_LIST['l2_port']},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l2.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l2_addr']]},
{'data_keys': ['version'], 'original_value': getinfo_res2['version'], 'new_value': CLN_VERSION},
{'data_keys': ['blockheight'], 'original_value': getinfo_res2['blockheight'], 'new_value': NEW_VALUES_LIST['blockheight_110']},
{'data_keys': ['alias'], 'original_value': l3.info['alias'], 'new_value': NEW_VALUES_LIST['l3_alias']},
{'data_keys': ['port'], 'original_value': l3.info['binding'][0]['port'], 'new_value': NEW_VALUES_LIST['l3_port']},
{'data_keys': ['addr'], 'original_value': f'127.0.0.1:{l3.info["binding"][0]["port"]}', 'new_value': NEW_VALUES_LIST['l3_addr']},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l3.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l3_addr']]},
{'data_keys': ['alias'], 'original_value': l4.info['alias'], 'new_value': NEW_VALUES_LIST['l4_alias']},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l4.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l4_addr']]},
{'data_keys': ['any', 'scid', 'channel', 'short_channel_id', 'in_channel'], 'original_value': c12, 'new_value': NEW_VALUES_LIST['c12']},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l5.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l5_addr']]},
{'data_keys': ['netaddr'], 'original_value': [f'127.0.0.1:{l6.info["binding"][0]["port"]}'], 'new_value': [NEW_VALUES_LIST['l6_addr']]},
{'data_keys': ['txid', 'funding_txid'], 'original_value': c12res['txid'], 'new_value': NEW_VALUES_LIST['c12_txid']},
{'data_keys': ['channel_id', 'account'], 'original_value': c12res['channel_id'], 'new_value': NEW_VALUES_LIST['c12_channel_id']},
{'data_keys': ['scid', 'channel', 'short_channel_id', 'id', 'out_channel'], 'original_value': c23, 'new_value': NEW_VALUES_LIST['c23']},
{'data_keys': ['txid'], 'original_value': c23res['txid'], 'new_value': NEW_VALUES_LIST['c23_txid']},
{'data_keys': ['channel_id', 'account', 'origin', 'originating_account'], 'original_value': c23res['channel_id'], 'new_value': NEW_VALUES_LIST['c23_channel_id']},
{'data_keys': ['scid', 'channel', 'short_channel_id'], 'original_value': c34, 'new_value': NEW_VALUES_LIST['c34']},
{'data_keys': ['txid'], 'original_value': c34res['txid'], 'new_value': NEW_VALUES_LIST['c34_txid']},
{'data_keys': ['channel_id', 'account', 'origin'], 'original_value': c34res['channel_id'], 'new_value': NEW_VALUES_LIST['c34_channel_id']},
{'data_keys': ['scid', 'channel', 'short_channel_id', 'id'], 'original_value': c25, 'new_value': NEW_VALUES_LIST['c25']},
{'data_keys': ['channel_id', 'account'], 'original_value': c25res['channel_id'], 'new_value': NEW_VALUES_LIST['c25_channel_id']},
{'data_keys': ['tx'], 'original_value': upgrade_res2['tx'], 'new_value': NEW_VALUES_LIST['upgrade_tx']},
{'data_keys': ['txid'], 'original_value': upgrade_res2['txid'], 'new_value': NEW_VALUES_LIST['upgrade_txid']},
{'data_keys': ['initialpsbt', 'psbt', 'signed_psbt'], 'original_value': upgrade_res2['psbt'], 'new_value': NEW_VALUES_LIST['upgrade_psbt_1']},
])
return l1, l2, l3, l4, l5, l6, c12, c23, c25
except Exception as e:
logger.error(f'Error in setting up nodes: {e}')
raise
def generate_transactions_examples(l1, l2, l3, l4, l5, c25, bitcoind):
"""Generate examples for various transactions and forwards"""
try:
logger.info('Simple Transactions Start...')
global FUND_CHANNEL_AMOUNT_SAT
# Simple Transactions by creating invoices, paying invoices, keysends
inv_l31 = update_example(node=l3, method='invoice', params={'amount_msat': 10**4, 'label': 'lbl_l31', 'description': 'Invoice description l31'})
route_l1_l3 = update_example(node=l1, method='getroute', params={'id': l3.info['id'], 'amount_msat': 10**4, 'riskfactor': 1})['route']
inv_l32 = update_example(node=l3, method='invoice', params={'amount_msat': '50000msat', 'label': 'lbl_l32', 'description': 'l32 description'})
update_example(node=l2, method='getroute', params={'id': l4.info['id'], 'amount_msat': 500000, 'riskfactor': 10, 'cltv': 9})['route']
sendpay_res1 = update_example(node=l1, method='sendpay', params={'route': route_l1_l3, 'payment_hash': inv_l31['payment_hash'], 'payment_secret': inv_l31['payment_secret']})
waitsendpay_res1 = update_example(node=l1, method='waitsendpay', params={'payment_hash': inv_l31['payment_hash']})
keysend_res1 = update_example(node=l1, method='keysend', params={'destination': l3.info['id'], 'amount_msat': 10000})
keysend_res2 = update_example(node=l1, method='keysend', params={'destination': l4.info['id'], 'amount_msat': 10000000, 'extratlvs': {'133773310': '68656c6c6f776f726c64', '133773312': '66696c7465726d65'}})
scid = only_one([channel for channel in l2.rpc.listpeerchannels()['channels'] if channel['peer_id'] == l3.info['id']])['alias']['remote']
routehints = [[{
'scid': scid,
'id': l2.info['id'],
'feebase': '1msat',
'feeprop': 10,
'expirydelta': 9,
}]]
example_routehints = [[{
'scid': NEW_VALUES_LIST['c23'],
'id': NEW_VALUES_LIST['l2_id'],
'feebase': '1msat',
'feeprop': 10,
'expirydelta': 9,
}]]
keysend_res3 = update_example(node=l1, method='keysend', params={'destination': l3.info['id'], 'amount_msat': 10000, 'routehints': routehints})
inv_l11 = l1.rpc.invoice('10000msat', 'lbl_l11', 'l11 description')
inv_l21 = l2.rpc.invoice('any', 'lbl_l21', 'l21 description')
inv_l22 = l2.rpc.invoice('200000msat', 'lbl_l22', 'l22 description')
inv_l33 = l3.rpc.invoice('100000msat', 'lbl_l33', 'l33 description')
inv_l34 = l3.rpc.invoice(4000, 'failed', 'failed description')
pay_res1 = update_example(node=l1, method='pay', params=[inv_l32['bolt11']])
pay_res2 = update_example(node=l2, method='pay', params={'bolt11': inv_l33['bolt11']})
inv_l41 = l4.rpc.invoice('10000msat', 'test_xpay_simple', 'test_xpay_simple bolt11')
xpay_res1 = update_example(node=l1, method='xpay', params=[inv_l41['bolt11']])
offer_l11 = l1.rpc.offer('any')
inv_l14 = l1.rpc.fetchinvoice(offer_l11['bolt12'], '1000msat')
xpay_res2 = update_example(node=l1, method='xpay', params={'invstring': inv_l14['invoice']})
update_example(node=l1, method='injectonionmessage', params={'message': '0002cb7cd2001e3c670d64135542dcefdf4a3f590eb142cee9277b317848471906caeabe4afeae7f4e31f6ca9c119b643d5369c5e55f892f205469a185f750697124a2bb7ccea1245ec12d76340bcf7371ba6d1c9ddfe09b4153fce524417c14a594fdbb5e7c698a5daffe77db946727a38711be2ecdebdd347d2a9f990810f2795b3c39b871d7c72a11534bd388ca2517630263d96d8cc72d146bae800638066175c85a8e8665160ea332ed7d27efc31c960604d61c3f83801c25cbb69ae3962c2ef13b1fa9adc8dcbe3dc8d9a5e27ff5669e076b02cafef8f2c88fc548e03642180d57606386ad6ce27640339747d40f26eb5b9e93881fc8c16d5896122032b64bb5f1e4be6f41f5fa4dbd7851989aeccd80b2d5f6f25427f171964146185a8eaa57891d91e49a4d378743231e19edd5994c3118c9a415958a5d9524a6ecc78c0205f5c0059a7fbcf1abad706a189b712476d112521c9a4650d0ff09890536acae755a2b07d00811044df28b288d3dc2d5ae3f8bf3cf7a2950e2167105dfad0fb8398ef08f36abcdb1bfd6aca3241c33810f0750f35bdfb7c60b1759275b7704ab1bc8f3ea375b3588eab10e4f948f12fe0a3c77b67bebeedbcced1de0f0715f9959e5497cda5f8f6ab76c15b3dcc99956465de1bf2855338930650f8e8e8c391d9bb8950125dd60d8289dade0556d9dc443761983e26adcc223412b756e2fd9ad64022859b6cab20e8ffc3cf39ae6045b2c3338b1145ee3719a098e58c425db764d7f9a5034dbb730c20202f79bc3c53fab78ecd530aa0e8f7698c9ea53cb96dc9c639282c362d31177c5b81979f46f2db6090b8e171db47287523f28c462e35ef489b51426387f2709c342083968153b5f8a51cd5716b38106bb0f21c5ccfc28dd7c74b71c8367ae8ca348f66a7996bbc535076a1f65d9109658ec042257ca7523488fb1807dc8bec42739ccae066739cf58083b4e2c65e52e1747a6ec2aa26338bb6f2c3195a2b160e26dec70a2cfde269fa7c10c45d346a8bcc313bb618324edadc0291d15f4dc00ca3a7ad7131045fdf6978ba52178f4699525efcb8d96561630e2f28eaa97c66c38c66301b6c6f0124b550db620b09f35b9d45d1441cab7d93be5e3c39b9becfab7f8d05dd3a7a6e27a1d3f23f1dd01e967f5206600619f75439181848f7f4148216c11314b4eaf64c28c268ad4b33ea821d57728e9a9e9e1b6c4bcf35d14958295fc5f92bd6846f33c46f5fa20f569b25bc916b94e554f27a37448f873497e13baef8c740a7587828cc4136dd21b8584e6983e376e91663f8f91559637738b400fb49940fc2df299dfd448604b63c2f5d1f1ec023636f3baf2be5730364afd38191726a7c0d9477b1f231da4d707aabc6ad8036488181dbdb16b48500f2333036629004504d3524f87ece6afb04c4ba03ea6fce069e98b1ab7bf51f237d7c0f40756744dd703c6023b6461b90730f701404e8dddfaff40a9a60e670be7729556241fc9cc8727a586e38b71616bff8772c873b37d920d51a6ad31219a24b12f268545e2cfeb9e662236ab639fd4ecf865612678471ff7b320c934a13ca1f2587fc6a90f839c3c81c0ff84b51330820431418918e8501844893b53c1e0de46d51a64cb769974a996c58ff06683ebdc46fd4bb8e857cecebab785a351c64fd486fb648d25936cb09327b70d22c243035d4343fa3d2d148e2df5cd928010e34ae42b0333e698142050d9405b39f3aa69cecf8a388afbc7f199077b911cb829480f0952966956fe57d815f0d2467f7b28af11f8820645b601c0e1ad72a4684ebc60287d23ec3502f4c65ca44f5a4a0d79e3a5718cd23e7538cb35c57673fb9a1173e5526e767768117c7fefc2e3718f44f790b27e61995fecc6aef05107e75355be301ebe1500c147bb655a159f',
'path_key': '03ccf3faa19e8d124f27d495e3359f4002a6622b9a02df9a51b609826d354cda52'})
blockheight = l1.rpc.getinfo()['blockheight']
amt = 10**3
route = l1.rpc.getroute(l4.info['id'], amt, 10)['route']
inv = l4.rpc.invoice(amt, "lbl l4", "desc l4")
first_hop = route[0]
sendonion_hops = []
example_hops = []
i = 1
for h, n in zip(route[:-1], route[1:]):
sendonion_hops.append({'pubkey': h['id'], 'payload': serialize_payload_tlv(amt, 18 + 6, n['channel'], blockheight).hex()})
example_hops.append({'pubkey': NEW_VALUES_LIST['l2_id'] if i == 1 else NEW_VALUES_LIST['l3_id'], 'payload': 'payload0' + ((str(i) + '0') * 13)})
i += 1
sendonion_hops.append({'pubkey': route[-1]['id'], 'payload': serialize_payload_final_tlv(amt, 18, amt, blockheight, inv['payment_secret']).hex()})
example_hops.append({'pubkey': NEW_VALUES_LIST['l4_id'], 'payload': 'payload0' + ((str(i) + '0') * 13)})
onion_res1 = update_example(node=l1, method='createonion', params={'hops': sendonion_hops, 'assocdata': inv['payment_hash']})
onion_res2 = update_example(node=l1, method='createonion', params={'hops': sendonion_hops, 'assocdata': inv['payment_hash'], 'session_key': '41' * 32})
sendonion_res1 = update_example(node=l1, method='sendonion', params={'onion': onion_res1['onion'], 'first_hop': first_hop, 'payment_hash': inv['payment_hash']})
# Close channels examples
close_res1 = update_example(node=l2, method='close', params={'id': l3.info['id'], 'unilateraltimeout': 1})
address_l41 = l4.rpc.newaddr()
close_res2 = update_example(node=l3, method='close', params={'id': l4.info['id'], 'destination': address_l41['bech32']})
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1, l2, l3, l4])
# Channel 2 to 3 is closed, l1->l3 payment will fail where `failed` forward will be saved on l2
l1.rpc.sendpay(route_l1_l3, inv_l34['payment_hash'], payment_secret=inv_l34['payment_secret'])
with pytest.raises(RpcError):
l1.rpc.waitsendpay(inv_l34['payment_hash'])
# Reopen channels for further examples
c23_2, c23res2 = l2.fundchannel(l3, FUND_CHANNEL_AMOUNT_SAT)
c34_2, c34res2 = l3.fundchannel(l4, FUND_CHANNEL_AMOUNT_SAT)
mine_funding_to_announce(bitcoind, [l3, l4])
l2.wait_channel_active(c23_2)
update_example(node=l2, method='setchannel', params={'id': c23_2, 'ignorefeelimits': True})
update_example(node=l2, method='setchannel', params={'id': c25, 'feebase': 4000, 'feeppm': 300, 'enforcedelay': 0})
# Some more invoices for signing and preapproving
inv_l12 = l1.rpc.invoice(1000, 'label inv_l12', 'description inv_l12')
inv_l24 = l2.rpc.invoice(123000, 'label inv_l24', 'description inv_l24', 3600)
inv_l25 = l2.rpc.invoice(124000, 'label inv_l25', 'description inv_l25', 3600)
inv_l26 = l2.rpc.invoice(125000, 'label inv_l26', 'description inv_l26', 3600)
signinv_res1 = update_example(node=l2, method='signinvoice', params={'invstring': inv_l12['bolt11']})
signinv_res2 = update_example(node=l3, method='signinvoice', params=[inv_l26['bolt11']])
update_example(node=l1, method='preapprovekeysend', params={'destination': l2.info['id'], 'payment_hash': '00' * 32, 'amount_msat': 1000})
update_example(node=l5, method='preapprovekeysend', params=[l5.info['id'], '01' * 32, 2000])
update_example(node=l1, method='preapproveinvoice', params={'bolt11': inv_l24['bolt11']})
update_example(node=l1, method='preapproveinvoice', params=[inv_l25['bolt11']])
inv_req = update_example(node=l2, method='invoicerequest', params={'amount': 1000000, 'description': 'Simple test'})
sendinvoice_res1 = update_example(node=l1, method='sendinvoice', params={'invreq': inv_req['bolt12'], 'label': 'test sendinvoice'})
inv_l13 = l1.rpc.invoice(amount_msat=100000, label='lbl_l13', description='l13 description', preimage='01' * 32)
createinv_res1 = update_example(node=l2, method='createinvoice', params={'invstring': inv_l13['bolt11'], 'label': 'lbl_l13', 'preimage': '01' * 32})
inv_l27 = l2.rpc.invoice(amt, 'test_injectpaymentonion1', 'test injectpaymentonion1 description')
injectpaymentonion_hops = [
{'pubkey': l1.info['id'],
'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()},
{'pubkey': l2.info['id'],
'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv_l27['payment_secret']).hex()}]
onion_res3 = l1.rpc.createonion(hops=injectpaymentonion_hops, assocdata=inv_l27['payment_hash'])
injectpaymentonion_res1 = update_example(node=l1, method='injectpaymentonion', params={
'onion': onion_res3['onion'],
'payment_hash': inv_l27['payment_hash'],
'amount_msat': 1000,
'cltv_expiry': blockheight + 18 + 6,
'partid': 1,
'groupid': 0})
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['destination'], 'original_value': address_l41['bech32'], 'new_value': NEW_VALUES_LIST['destination_6']},
{'data_keys': ['tx'], 'original_value': close_res1['tx'], 'new_value': NEW_VALUES_LIST['close1_tx']},
{'data_keys': ['txs'], 'original_value': close_res1['txs'], 'new_value': [NEW_VALUES_LIST['close1_tx']]},
{'data_keys': ['txid', 'spending_txid'], 'original_value': close_res1['txid'], 'new_value': NEW_VALUES_LIST['close1_txid']},
{'data_keys': ['txids'], 'original_value': close_res1['txids'], 'new_value': [NEW_VALUES_LIST['close1_txid']]},
{'data_keys': ['tx'], 'original_value': close_res2['tx'], 'new_value': NEW_VALUES_LIST['close2_tx']},
{'data_keys': ['txs'], 'original_value': close_res2['txs'], 'new_value': [NEW_VALUES_LIST['close2_tx']]},
{'data_keys': ['txid'], 'original_value': close_res2['txid'], 'new_value': NEW_VALUES_LIST['close2_txid']},
{'data_keys': ['txids'], 'original_value': close_res2['txids'], 'new_value': [NEW_VALUES_LIST['close2_txid']]},
{'data_keys': ['any', 'bolt11'], 'original_value': createinv_res1['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l21']},
{'data_keys': ['payment_hash'], 'original_value': createinv_res1['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l21']},
{'data_keys': ['expires_at'], 'original_value': createinv_res1['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_hash'], 'original_value': inv_l31['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l31']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l31['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l31']},
{'data_keys': ['payment_secret'], 'original_value': inv_l31['payment_secret'], 'new_value': NEW_VALUES_LIST['payment_secret_l31']},
{'data_keys': ['expires_at'], 'original_value': inv_l31['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_hash'], 'original_value': inv_l32['payment_hash'], 'new_value': 'paymenthashinvl0' + ('3200' * 12)},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l32['bolt11'], 'new_value': 'lnbcrt100n1pnt2' + ('bolt11invl032000000000' * 10)},
{'data_keys': ['payment_secret'], 'original_value': inv_l32['payment_secret'], 'new_value': 'paymentsecretinvl000' + ('3200' * 11)},
{'data_keys': ['expires_at'], 'original_value': inv_l32['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_hash'], 'original_value': inv_l11['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l11']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l11['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l11']},
{'data_keys': ['payment_secret'], 'original_value': inv_l11['payment_secret'], 'new_value': NEW_VALUES_LIST['payment_secret_l11']},
{'data_keys': ['expires_at'], 'original_value': inv_l11['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_hash'], 'original_value': inv_l21['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l21']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l21['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l21']},
{'data_keys': ['payment_hash'], 'original_value': inv_l22['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l22']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l22['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l22']},
{'data_keys': ['payment_secret'], 'original_value': inv_l22['payment_secret'], 'new_value': NEW_VALUES_LIST['payment_secret_l22']},
{'data_keys': ['payment_hash'], 'original_value': inv_l33['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l33']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l33['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l33']},
{'data_keys': ['payment_hash'], 'original_value': inv_l34['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l34']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l34['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l34']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l41['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l41']},
{'data_keys': ['invstring'], 'original_value': inv_l14['invoice'], 'new_value': NEW_VALUES_LIST['invoice_3']},
{'data_keys': ['hops'], 'original_value': sendonion_hops, 'new_value': example_hops},
{'data_keys': ['any', 'assocdata'], 'original_value': inv['payment_hash'], 'new_value': NEW_VALUES_LIST['assocdata_1']},
{'data_keys': ['onion'], 'original_value': onion_res1['onion'], 'new_value': NEW_VALUES_LIST['onion_1']},
{'data_keys': ['shared_secrets'], 'original_value': onion_res1['shared_secrets'], 'new_value': NEW_VALUES_LIST['shared_secrets_1']},
{'data_keys': ['any', 'onion'], 'original_value': onion_res2['onion'], 'new_value': NEW_VALUES_LIST['onion_2']},
{'data_keys': ['shared_secrets'], 'original_value': onion_res2['shared_secrets'], 'new_value': NEW_VALUES_LIST['shared_secrets_2']},
{'data_keys': ['onion'], 'original_value': onion_res3['onion'], 'new_value': NEW_VALUES_LIST['onion_3']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l27['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l27']},
{'data_keys': ['payment_hash'], 'original_value': inv_l27['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l27']},
{'data_keys': ['payment_preimage'], 'original_value': injectpaymentonion_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_io_1']},
{'data_keys': ['created_at'], 'original_value': injectpaymentonion_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['completed_at'], 'original_value': injectpaymentonion_res1['completed_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['id', 'scid', 'channel', 'short_channel_id', 'out_channel'], 'original_value': c23_2, 'new_value': NEW_VALUES_LIST['c23_2']},
{'data_keys': ['txid'], 'original_value': c23res2['txid'], 'new_value': NEW_VALUES_LIST['c23_2_txid']},
{'data_keys': ['any', 'channel_id', 'account'], 'original_value': c23res2['channel_id'], 'new_value': NEW_VALUES_LIST['c23_2_channel_id']},
{'data_keys': ['scid', 'channel', 'short_channel_id'], 'original_value': c34_2, 'new_value': NEW_VALUES_LIST['c34_2']},
{'data_keys': ['txid'], 'original_value': c34res2['txid'], 'new_value': NEW_VALUES_LIST['c34_2_txid']},
{'data_keys': ['channel_id', 'account'], 'original_value': c34res2['channel_id'], 'new_value': NEW_VALUES_LIST['c34_2_channel_id']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l12['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l12']},
{'data_keys': ['payment_hash'], 'original_value': inv_l24['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l24']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l24['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l24']},
{'data_keys': ['expires_at'], 'original_value': inv_l24['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_hash'], 'original_value': inv_l25['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l25']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l25['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l25']},
{'data_keys': ['payment_hash'], 'original_value': inv_l26['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_l26']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l26['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l26']},
{'data_keys': ['any', 'invstring', 'bolt11'], 'original_value': inv_l13['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l13']},
{'data_keys': ['invreq_id'], 'original_value': inv_req['invreq_id'], 'new_value': NEW_VALUES_LIST['invreq_id_1']},
{'data_keys': ['any', 'bolt12', 'invreq'], 'original_value': inv_req['bolt12'], 'new_value': NEW_VALUES_LIST['bolt12_l21']},
{'data_keys': ['payment_hash'], 'original_value': keysend_res1['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_key_1']},
{'data_keys': ['created_at'], 'original_value': keysend_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_preimage'], 'original_value': keysend_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_1']},
{'data_keys': ['payment_hash'], 'original_value': keysend_res2['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_key_2']},
{'data_keys': ['created_at'], 'original_value': keysend_res2['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_preimage'], 'original_value': keysend_res2['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_2']},
{'data_keys': ['payment_hash'], 'original_value': keysend_res3['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_key_3']},
{'data_keys': ['created_at'], 'original_value': keysend_res3['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_preimage'], 'original_value': keysend_res3['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_3']},
{'data_keys': ['routehints'], 'original_value': routehints, 'new_value': example_routehints},
{'data_keys': ['created_at'], 'original_value': pay_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_preimage'], 'original_value': pay_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_ep_1']},
{'data_keys': ['created_at'], 'original_value': pay_res2['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_preimage'], 'original_value': pay_res2['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_ep_2']},
{'data_keys': ['any', 'bolt12', 'invreq'], 'original_value': sendinvoice_res1['bolt12'], 'new_value': NEW_VALUES_LIST['bolt12_si_1']},
{'data_keys': ['payment_hash'], 'original_value': sendinvoice_res1['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_si_1']},
{'data_keys': ['payment_preimage'], 'original_value': sendinvoice_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payments_preimage_i_1']},
{'data_keys': ['paid_at'], 'original_value': sendinvoice_res1['paid_at'], 'new_value': NEW_VALUES_LIST['time_at_850']},
{'data_keys': ['expires_at'], 'original_value': sendinvoice_res1['expires_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['created_at'], 'original_value': sendonion_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['created_at'], 'original_value': sendpay_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['any', 'bolt11'], 'original_value': signinv_res1['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l66']},
{'data_keys': ['any', 'bolt11'], 'original_value': signinv_res2['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l67']},
{'data_keys': ['payment_preimage'], 'original_value': waitsendpay_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payments_preimage_w_1']},
{'data_keys': ['created_at'], 'original_value': waitsendpay_res1['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['completed_at'], 'original_value': waitsendpay_res1['completed_at'], 'new_value': NEW_VALUES_LIST['time_at_900']},
{'data_keys': ['payment_preimage'], 'original_value': xpay_res1['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_xp_1']},
{'data_keys': ['payment_preimage'], 'original_value': xpay_res2['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_xp_2']},
])
logger.info('Simple Transactions Done!')
return c23_2, c23res2, c34_2, inv_l11, inv_l21, inv_l22, inv_l31, inv_l32, inv_l34
except Exception as e:
logger.error(f'Error in generating transactions examples: {e}')
raise
def generate_runes_examples(l1, l2, l3):
"""Covers all runes related examples"""
try:
logger.info('Runes Start...')
# Runes
trimmed_id = l1.info['id'][:20]
rune_l21 = update_example(node=l2, method='createrune', params={}, description=['This creates a fresh rune which can do anything:'])
rune_l22 = update_example(node=l2, method='createrune', params={'rune': rune_l21['rune'], 'restrictions': 'readonly'},
description=['We can add restrictions to that rune, like so:',
'',
'The `readonly` restriction is a short-cut for two restrictions:',
'',
'1: `[\'method^list\', \'method^get\', \'method=summary\']`: You may call list, get or summary.',
'',
'2: `[\'method/listdatastore\']`: But not listdatastore: that contains sensitive stuff!'])
update_example(node=l2, method='createrune', params={'rune': rune_l21['rune'], 'restrictions': [['method^list', 'method^get', 'method=summary'], ['method/listdatastore']]}, description=['We can do the same manually (readonly), like so:'])
rune_l23 = update_example(node=l2, method='createrune', params={'restrictions': [[f'id^{trimmed_id}'], ['method=listpeers']]}, description=[f'This will allow the rune to be used for id starting with {trimmed_id}, and for the method listpeers:'])
rune_l24 = update_example(node=l2, method='createrune', params={'restrictions': [['method=pay'], ['pnameamountmsat<10000']]}, description=['This will allow the rune to be used for the method pay, and for the parameter amount\\_msat to be less than 10000:'])
update_example(node=l2, method='createrune', params={'restrictions': [[f'id={l1.info["id"]}'], ['method=listpeers'], ['pnum=1'], [f'pnameid={l1.info["id"]}', f'parr0={l1.info["id"]}']]}, description=["Let's create a rune which lets a specific peer run listpeers on themselves:"])
rune_l25 = update_example(node=l2, method='createrune', params={'restrictions': [[f'id={l1.info["id"]}'], ['method=listpeers'], ['pnum=1'], [f'pnameid^{trimmed_id}', f'parr0^{trimmed_id}']]}, description=["This allows `listpeers` with 1 argument (`pnum=1`), which is either by name (`pnameid`), or position (`parr0`). We could shorten this in several ways: either allowing only positional or named parameters, or by testing the start of the parameters only. Here's an example which only checks the first 10 bytes of the `listpeers` parameter:"])
update_example(node=l2, method='createrune', params=[rune_l25['rune'], [['time<"$(($(date +%s) + 24*60*60))"', 'rate=2']]], description=["Before we give this to our peer, let's add two more restrictions: that it only be usable for 24 hours from now (`time<`), and that it can only be used twice a minute (`rate=2`). `date +%s` can give us the current time in seconds:"])
update_example(node=l2, method='commando-listrunes', params={'rune': rune_l23['rune']})
update_example(node=l2, method='commando-listrunes', params={})
commando_res1 = update_example(node=l1, method='commando', params={'peer_id': l2.info['id'], 'rune': rune_l21['rune'], 'method': 'newaddr', 'params': {'addresstype': 'p2tr'}})
update_example(node=l1, method='commando', params={'peer_id': l2.info['id'], 'rune': rune_l23['rune'], 'method': 'listpeers', 'params': [l3.info['id']]})
inv_l23 = l2.rpc.invoice('any', 'lbl_l23', 'l23 description')
commando_res3 = update_example(node=l1, method='commando', params={'peer_id': l2.info['id'], 'rune': rune_l24['rune'], 'method': 'pay', 'params': {'bolt11': inv_l23['bolt11'], 'amount_msat': 9900}})
update_example(node=l2, method='checkrune', params={'nodeid': l2.info['id'], 'rune': rune_l22['rune'], 'method': 'listpeers', 'params': {}})
update_example(node=l2, method='checkrune', params={'nodeid': l2.info['id'], 'rune': rune_l24['rune'], 'method': 'pay', 'params': {'amount_msat': 9999}})
showrunes_res1 = update_example(node=l2, method='showrunes', params={'rune': rune_l21['rune']})
showrunes_res2 = update_example(node=l2, method='showrunes', params={})
update_example(node=l2, method='commando-blacklist', params={'start': 1})
update_example(node=l2, method='commando-blacklist', params={'start': 2, 'end': 3})
update_example(node=l2, method='blacklistrune', params={'start': 1})
update_example(node=l2, method='blacklistrune', params={'start': 0, 'end': 2})
update_example(node=l2, method='blacklistrune', params={'start': 3, 'end': 4})
# Commando runes
rune_l11 = update_example(node=l1, method='commando-rune', params={}, description=['This creates a fresh rune which can do anything:'])
update_example(node=l1, method='commando-rune', params={'rune': rune_l11['rune'], 'restrictions': 'readonly'},
description=['We can add restrictions to that rune, like so:',
'',
'The `readonly` restriction is a short-cut for two restrictions:',
'',
'1: `[\'method^list\', \'method^get\', \'method=summary\']`: You may call list, get or summary.',
'',
'2: `[\'method/listdatastore\']`: But not listdatastore: that contains sensitive stuff!'])
update_example(node=l1, method='commando-rune', params={'rune': rune_l11['rune'], 'restrictions': [['method^list', 'method^get', 'method=summary'], ['method/listdatastore']]}, description=['We can do the same manually (readonly), like so:'])
update_example(node=l1, method='commando-rune', params={'restrictions': [[f'id^{trimmed_id}'], ['method=listpeers']]}, description=[f'This will allow the rune to be used for id starting with {trimmed_id}, and for the method listpeers:'])
update_example(node=l1, method='commando-rune', params={'restrictions': [['method=pay'], ['pnameamountmsat<10000']]}, description=['This will allow the rune to be used for the method pay, and for the parameter amount\\_msat to be less than 10000:'])
update_example(node=l1, method='commando-rune', params={'restrictions': [[f'id={l1.info["id"]}'], ['method=listpeers'], ['pnum=1'], [f'pnameid={l1.info["id"]}', f'parr0={l1.info["id"]}']]}, description=["Let's create a rune which lets a specific peer run listpeers on themselves:"])
rune_l15 = update_example(node=l1, method='commando-rune', params={'restrictions': [[f'id={l1.info["id"]}'], ['method=listpeers'], ['pnum=1'], [f'pnameid^{trimmed_id}', f'parr0^{trimmed_id}']]}, description=["This allows `listpeers` with 1 argument (`pnum=1`), which is either by name (`pnameid`), or position (`parr0`). We could shorten this in several ways: either allowing only positional or named parameters, or by testing the start of the parameters only. Here's an example which only checks the first 10 bytes of the `listpeers` parameter:"])
update_example(node=l1, method='commando-rune', params=[rune_l15['rune'], [['time<"$(($(date +%s) + 24*60*60))"', 'rate=2']]], description=["Before we give this to our peer, let's add two more restrictions: that it only be usable for 24 hours from now (`time<`), and that it can only be used twice a minute (`rate=2`). `date +%s` can give us the current time in seconds:"])
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['last_used'], 'original_value': showrunes_res1['runes'][0]['last_used'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['last_used'], 'original_value': showrunes_res2['runes'][1]['last_used'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['last_used'], 'original_value': showrunes_res2['runes'][2]['last_used'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['any', 'bolt11'], 'original_value': inv_l23['bolt11'], 'new_value': NEW_VALUES_LIST['bolt11_l23']},
{'data_keys': ['p2tr'], 'original_value': commando_res1['p2tr'], 'new_value': NEW_VALUES_LIST['destination_7']},
{'data_keys': ['created_at'], 'original_value': commando_res3['created_at'], 'new_value': NEW_VALUES_LIST['time_at_800']},
{'data_keys': ['payment_hash'], 'original_value': commando_res3['payment_hash'], 'new_value': NEW_VALUES_LIST['payment_hash_cmd_pay_1']},
{'data_keys': ['payment_preimage'], 'original_value': commando_res3['payment_preimage'], 'new_value': NEW_VALUES_LIST['payment_preimage_cmd_1']},
])
logger.info('Runes Done!')
return rune_l21
except Exception as e:
logger.error(f'Error in generating runes examples: {e}')
raise
def generate_datastore_examples(l2):
"""Covers all datastore related examples"""
try:
logger.info('Datastore Start...')
l2.rpc.datastore(key='somekey', hex='61', mode='create-or-append')
l2.rpc.datastore(key=['test', 'name'], string='saving data to the store', mode='must-create')
update_example(node=l2, method='datastore', params={'key': ['employee', 'index'], 'string': 'saving employee keys to the store', 'mode': 'must-create'})
update_example(node=l2, method='datastore', params={'key': 'otherkey', 'string': 'other', 'mode': 'must-create'})
update_example(node=l2, method='datastore', params={'key': 'otherkey', 'string': ' key: text to be appended to the otherkey', 'mode': 'must-append', 'generation': 0})
update_example(node=l2, method='datastoreusage', params={})
update_example(node=l2, method='datastoreusage', params={'key': ['test', 'name']})
update_example(node=l2, method='datastoreusage', params={'key': 'otherkey'})
update_example(node=l2, method='deldatastore', params={'key': ['test', 'name']})
update_example(node=l2, method='deldatastore', params={'key': 'otherkey', 'generation': 1})
logger.info('Datastore Done!')
except Exception as e:
logger.error(f'Error in generating datastore examples: {e}')
raise
def generate_bookkeeper_examples(l2, l3, c23_2_chan_id):
"""Generates all bookkeeper rpc examples"""
try:
logger.info('Bookkeeper Start...')
update_example(node=l2, method='funderupdate', params={})
update_example(node=l2, method='funderupdate', params={'policy': 'fixed', 'policy_mod': '50000sat', 'min_their_funding_msat': 1000, 'per_channel_min_msat': '1000sat', 'per_channel_max_msat': '500000sat', 'fund_probability': 100, 'fuzz_percent': 0, 'leases_only': False})
bkprinspect_res1 = update_example(node=l2, method='bkpr-inspect', params={'account': c23_2_chan_id})
update_example(node=l2, method='bkpr-dumpincomecsv', params=['koinly', 'koinly.csv'])
bkpr_channelsapy_res1 = l2.rpc.bkpr_channelsapy()
fields = [
('utilization_out', '3{}.7060%'),
('utilization_out_initial', '5{}.5591%'),
('utilization_in', '1{}.0027%'),
('utilization_in_initial', '5{}.0081%'),
('apy_out', '0.008{}%'),
('apy_out_initial', '0.012{}%'),
('apy_in', '0.008{}%'),
('apy_in_initial', '0.025{}%'),
('apy_total', '0.016{}%'),
('apy_total_initial', '0.016{}%'),
]
for i, channel in enumerate(bkpr_channelsapy_res1['channels_apy']):
for key, pattern in fields:
if key in channel:
channel[key] = pattern.format(i)
update_example(node=l2, method='bkpr-channelsapy', params={}, response=bkpr_channelsapy_res1)
# listincome and editing descriptions
listincome_result = l3.rpc.bkpr_listincome(consolidate_fees=False)
invoice = next((event for event in listincome_result['income_events'] if 'payment_id' in event), None)
utxo_event = next((event for event in listincome_result['income_events'] if 'outpoint' in event), None)
update_example(node=l3, method='bkpr-editdescriptionbypaymentid', params={'payment_id': invoice['payment_id'], 'description': 'edited invoice description from description send some sats l2 to l3'})
# Try to edit a payment_id that does not exist
update_example(node=l3, method='bkpr-editdescriptionbypaymentid', params={'payment_id': 'c000' + ('01' * 30), 'description': 'edited invoice description for non existing payment id'})
editdescriptionbyoutpoint_res1 = update_example(node=l3, method='bkpr-editdescriptionbyoutpoint', params={'outpoint': utxo_event['outpoint'], 'description': 'edited utxo description'})
# Try to edit an outpoint that does not exist
update_example(node=l3, method='bkpr-editdescriptionbyoutpoint', params={'outpoint': 'abcd' + ('02' * 30) + ':1', 'description': 'edited utxo description for non existing outpoint'})
bkprlistbal_res1 = update_example(node=l3, method='bkpr-listbalances', params={})
bkprlistaccountevents_res1 = l3.rpc.bkpr_listaccountevents(c23_2_chan_id)
bkprlistaccountevents_res1['events'] = [next((event for event in bkprlistaccountevents_res1['events'] if event['tag'] == 'channel_open'), None)]
bkprlistaccountevents_res1 = update_list_responses(bkprlistaccountevents_res1, list_key='events')
update_example(node=l3, method='bkpr-listaccountevents', params=[c23_2_chan_id], response=bkprlistaccountevents_res1)
bkprlistaccountevents_res2 = l3.rpc.bkpr_listaccountevents()
external_event = None
wallet_event = None
channel_event = None
for bkprevent in bkprlistaccountevents_res2['events']:
event_seleted = None
if wallet_event is None and bkprevent['account'] == 'wallet':
bkprevent['blockheight'] = 141
wallet_event = bkprevent
event_seleted = '01'
elif external_event is None and bkprevent['account'] == 'external' and bkprevent['origin'] == next((value['original_value'] for value in REPLACE_RESPONSE_VALUES if value['new_value'] == NEW_VALUES_LIST['c34_channel_id']), None):
bkprevent['blockheight'] = 142
external_event = bkprevent
event_seleted = '02'
elif channel_event is None and bkprevent['account'] not in ['external', 'wallet']:
bkprevent['blockheight'] = 143
channel_event = bkprevent
event_seleted = '03'
if event_seleted is not None:
bkpr_new_values = [
{'data_keys': ['timestamp'], 'original_value': bkprevent['timestamp'], 'new_value': NEW_VALUES_LIST['time_at_850'] + (int(event_seleted) * 10000)},
]
if 'debit_msat' in bkprevent and bkprevent['debit_msat'] > 0:
bkpr_new_values.extend([
{'data_keys': ['debit_msat'], 'original_value': bkprevent['debit_msat'], 'new_value': 200000000000},
])
if 'txid' in bkprevent:
bkpr_new_values.extend([
{'data_keys': ['txid'], 'original_value': bkprevent['txid'], 'new_value': 'txidbk' + (event_seleted * 29)},
])
if 'outpoint' in bkprevent:
bkpr_new_values.extend([
{'data_keys': ['outpoint'], 'original_value': bkprevent['outpoint'], 'new_value': 'txidbk' + (event_seleted * 29) + ':1'},
])
if 'payment_id' in bkprevent:
bkpr_new_values.extend([
{'data_keys': ['payment_id'], 'original_value': bkprevent['payment_id'], 'new_value': 'paymentidbk0' + (event_seleted * 26)},
])
REPLACE_RESPONSE_VALUES.extend(bkpr_new_values)
if wallet_event and external_event and channel_event:
break
bkprlistaccountevents_res2['events'] = [event for event in [external_event, wallet_event, channel_event] if event is not None]
update_example(node=l3, method='bkpr-listaccountevents', params={}, response=bkprlistaccountevents_res2)
bkprlistincome_res1 = l3.rpc.bkpr_listincome(consolidate_fees=False)
bkprlistincome_res1 = update_list_responses(bkprlistincome_res1, list_key='income_events', slice_upto=4, update_func=lambda x, i: x.update({
**({'timestamp': NEW_VALUES_LIST['time_at_850'] + (i * 10000)} if 'timestamp' in x else {}),
**({'payment_id': 'paymentid000' + (f"{i:02}" * 26)} if 'payment_id' in x else {}),
**({'outpoint': 'txidbk' + (f"{i:02}" * 29) + ':1'} if 'outpoint' in x else {})}), sort=True, sort_key='tag')
update_example(node=l3, method='bkpr-listincome', params={'consolidate_fees': False}, response=bkprlistincome_res1)
bkprlistincome_res2 = l3.rpc.bkpr_listincome()
deposit_income = None
invoice_income = None
fee_income = None
for bkprincome in bkprlistincome_res2['income_events']:
income_seleted = None
if deposit_income is None and bkprincome['tag'] == 'deposit':
deposit_income = bkprincome
income_seleted = 1
elif invoice_income is None and bkprincome['tag'] == 'invoice':
invoice_income = bkprincome
income_seleted = 2
elif fee_income is None and bkprincome['tag'] == 'onchain_fee' and bkprincome['txid'] == next((value['original_value'] for value in REPLACE_RESPONSE_VALUES if value['new_value'] == NEW_VALUES_LIST['c34_2_txid']), None):
fee_income = bkprincome
income_seleted = 3
if income_seleted is not None:
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['timestamp'], 'original_value': bkprincome['timestamp'], 'new_value': NEW_VALUES_LIST['time_at_850'] + (income_seleted * 10000)},
])
if 'debit_msat' in bkprincome and bkprincome['debit_msat'] > 0:
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['debit_msat'], 'original_value': bkprincome['debit_msat'], 'new_value': 6960000},
])
if 'payment_id' in bkprincome:
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['payment_id'], 'original_value': bkprincome['payment_id'], 'new_value': 'paymentid000' + (f"{income_seleted:02}" * 26)},
])
if 'outpoint' in bkprincome:
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['outpoint'], 'original_value': bkprincome['outpoint'], 'new_value': 'txidbk' + (f"{income_seleted:02}" * 29) + ':1'},
])
if deposit_income and invoice_income and fee_income:
break
bkprlistincome_res2['income_events'] = [income for income in [deposit_income, invoice_income, fee_income] if income is not None]
update_example(node=l3, method='bkpr-listincome', params={}, response=bkprlistincome_res2)
REPLACE_RESPONSE_VALUES.extend([
{'data_keys': ['balance_msat'], 'original_value': bkprlistbal_res1['accounts'][0]['balances'][0]['balance_msat'], 'new_value': NEW_VALUES_LIST['balance_msat_1']},
{'data_keys': ['fees_paid_msat'], 'original_value': bkprinspect_res1['txs'][0]['fees_paid_msat'], 'new_value': NEW_VALUES_LIST['fees_paid_msat_1']},
{'data_keys': ['timestamp'], 'original_value': bkprlistaccountevents_res1['events'][0]['timestamp'], 'new_value': NEW_VALUES_LIST['time_at_850']},
{'data_keys': ['outpoint'], 'original_value': bkprlistaccountevents_res1['events'][0]['outpoint'], 'new_value': 'txidbk' + ('01' * 29) + ':1'},
{'data_keys': ['blockheight'], 'original_value': editdescriptionbyoutpoint_res1['updated'][0]['blockheight'], 'new_value': NEW_VALUES_LIST['blockheight_110']},
])
logger.info('Bookkeeper Done!')
except Exception as e:
logger.error(f'Error in generating bookkeeper examples: {e}')
raise
def generate_offers_renepay_examples(l1, l2, inv_l21, inv_l34):
"""Covers all offers and renepay related examples"""
try:
logger.info('Offers and Renepay Start...')
# Offers & Offers Lists
offer_l21 = update_example(node=l2, method='offer', params={'amount': '10000msat', 'description': 'Fish sale!'})
offer_l22 = update_example(node=l2, method='offer', params={'amount': '1000sat', 'description': 'Coffee', 'quantity_max': 10})
offer_l23 = l2.rpc.offer('2000sat', 'Offer to Disable')
fetchinv_res1 = update_example(node=l1, method='fetchinvoice', params={'offer': offer_l21['bolt12'], 'payer_note': 'Thanks for the fish!'})
fetchinv_res2 = update_example(node=l1, method='fetchinvoice', params={'offer': offer_l22['bolt12'], 'amount_msat': 2000000, 'quantity': 2})
update_example(node=l2, method='disableoffer', params={'offer_id': offer_l23['offer_id']})