-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeconnection.py
More file actions
830 lines (779 loc) · 31.4 KB
/
nodeconnection.py
File metadata and controls
830 lines (779 loc) · 31.4 KB
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
#Developer: Curly60e
#PyBLOCK its a clock of the Bitcoin blockchain.
#Version: 0.6.0b
import base64, codecs, json, requests
import pickle
import os
import os.path
import qrcode
import sys
import simplejson as json
import time as t
import numpy as np
from cfonts import render, say
from art import *
from pblogo import *
lndconnectload = {"ip_port":"", "tls":"", "macaroon":"", "ln":""}
def clear(): # clear the screen
os.system('cls' if os.name=='nt' else 'clear')
def closed():
print("<<< Back Control + C.\n\n")
if os.path.isfile('blndconnect.conf'): # Check if the file 'bclock.conf' is in the same folder
lndconnectData= pickle.load(open("blndconnect.conf", "rb")) # Load the file 'bclock.conf'
lndconnectload = lndconnectData # Copy the variable pathv to 'path'
else:
clear()
blogo()
print("\n\tIf you are going to use your local node leave IP:PORT/CERT/MACAROONS in blank.\n")
lndconnectload["ip_port"] = input("Insert IP:PORT to your node: ") # path to the bitcoin-cli
lndconnectload["tls"] = input("Insert the path to tls.cert file: ")
lndconnectload["macaroon"] = input("Insert the path to admin.macaroon: ")
print("\n\tLocal Lightning Node connection.\n")
lndconnectload["ln"] = input("Insert the path to lncli: ")
pickle.dump(lndconnectload, open("blndconnect.conf", "wb")) # Save the file 'bclock.conf'
#-------------------------RPC BITCOIN NODE CONNECTION
def rpc(method, params=[]):
payload = json.dumps({
"jsonrpc": "2.0",
"id": "minebet",
"method": method,
"params": params
})
path = {"ip_port":"", "rpcuser":"", "rpcpass":"", "bitcoincli":""}
if os.path.isfile('bclock.conf'): # Check if the file 'bclock.conf' is in the same folder
pathv = pickle.load(open("bclock.conf", "rb")) # Load the file 'bclock.conf'
path = pathv # Copy the variable pathv to 'path'
return requests.post(path['ip_port'], auth=(path['rpcuser'], path['rpcpass']), data=payload).json()['result']
def remoteHalving():
try:
b = rpc('getblockcount')
c = str(b)
oneh = 0 - int(c) + 210000
twoh = 210000 - int(c) + 210000
thrh = 420000 - int(c) + 210000
forh = 630000 - int(c) + 210000
fifh = 840000 - int(c) + 210000
sixh = 1050000 - int(c) + 210000
sevh = 1260000 - int(c) + 210000
eith = 1470000 - int(c) + 210000
ninh = 1680000 - int(c) + 210000
tenh = 1890000 - int(c) + 210000
q = """
\033[0;37;40m----------- HALVING HISTORY -----------
1st Halving: in {} Blocks {}
2nd Halving: in {} Blocks {}
3rd Halving: in {} Blocks {}
4th Halving: in {} Blocks {}
5th Halving: in {} Blocks {}
6th Halving: in {} Blocks {}
7th Halving: in {} Blocks {}
8th Halving: in {} Blocks {}
9th Halving: in {} Blocks {}
10th Halving: in {} Blocks {}
---------------------------------------
""".format("0" if int(c) == 210000 else oneh,"\033[1;32;40mCOMPLETE\033[0;37;40m","0" if int(c) == 420000 else twoh,"\033[1;32;40mCOMPLETE\033[0;37;40m", "0" if int(c) == 630000 else thrh,"\033[1;32;40mCOMPLETE\033[0;37;40m","0" if int(c) == 840000 else forh,"\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 840000 else "\033[1;35;40mPENDING\033[0;37;40m", "0" if int(c) >= 1050000 else fifh , "\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1050000 else "\033[1;35;40mPENDING\033[0;37;40m", sixh, "\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1260000 else "\033[1;35;40mPENDING\033[0;37;40m", sevh,"\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1470000 else "\033[1;35;40mPENDING\033[0;37;40m", eith,"\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1680000 else "\033[1;35;40mPENDING\033[0;37;40m", ninh, "\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1890000 else "\033[1;35;40mPENDING\033[0;37;40m", tenh, "\033[1;32;40mCOMPLETE\033[0;37;40m" if int(c) >= 1890000 else "\033[1;35;40mPENDING\033[0;37;40m")
print(q)
input("\nContinue...")
except:
pass
def remotegetblock():
try:
clear()
closed()
if os.path.isfile('pyblocksettingsClock.conf') or os.path.isfile('pyblocksettingsClock.conf'): # Check if the file 'bclock.conf' is in the same folder
settingsv = pickle.load(open("pyblocksettingsClock.conf", "rb")) # Load the file 'bclock.conf'
settingsClock = settingsv # Copy the variable pathv to 'path'
else:
settingsClock = {"gradient":"", "design":"block", "colorA":"green", "colorB":"yellow"}
pickle.dump(settingsClock, open("pyblocksettingsClock.conf", "wb"))
b = rpc('getblockcount')
c = str(b)
a = c
output = render(str(c), colors=[settingsClock['colorA'], settingsClock['colorB']], align='center')
print("\x1b[?25l" + output)
while True:
x = a
b = rpc('getblockcount')
c = str(b)
if c > a:
clear()
closed()
output = render(str(c), colors=[settingsClock['colorA'], settingsClock['colorB']], align='center')
print("\a\x1b[?25l" + output)
a = c
except:
pass
def remotegetblockcount(): # get access to bitcoin-cli with the command getblockcount
while True:
try:
a = rpc('getblockchaininfo')
d = a
clear()
blogo()
closed()
print("""
-------------------------------------------------------
\tGET BLOCKCHAIN INFORMATION
Chain: {}
Blocks: {}
Best BlockHash: {}
Difficulty: {}
Verification Progress: {}
Size on Disk: {}
Pruned: {}
-------------------------------------------------------
""".format(d['chain'], d['blocks'], d['bestblockhash'], d['difficulty'], d['verificationprogress'], d['size_on_disk'], d['pruned']))
t.sleep(2)
except:
break
def remoteconsole(): # get into the console from bitcoin-cli
print("\t\033[0;37;40mThis is \033[1;33;40mBitcoin-cli's \033[0;37;40mconsole. Type your respective commands you want to display.\n\n")
while True:
cle = input("\033[1;32;40mconsole $>: \033[0;37;40m")
a = rpc(cle)
print(a)
#-------------------------END RPC BITCOIN NODE CONNECTION
def consoleLN(): # get into the console from bitcoin-cli
print("\t\033[0;37;40mThis is \033[1;33;40mLncli's \033[0;37;40mconsole. Type your respective commands you want to display.\n\n")
while True:
cle = input("\033[1;32;40mconsole $>: \033[0;37;40m")
lsd = os.popen(lndconnectload['ln'] + " " + cle)
lsd0 = lsd.read()
lsd1 = str(lsd0)
print(lsd1)
lsd.close()
def locallistchaintxns():
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
lncli = " listchaintxns"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
n = d['transactions']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\t\nTransactions\n")
try:
print("\n\tLIST ONCHAIN TRANSACTIONS\n")
for item_ in n:
s = item_
print("Transaction Hash: " + s['tx_hash'])
nd = input("\nSelect RHash: ")
for item in n:
s = item
nn = s['tx_hash']
trx = s['dest_addresses']
if nd == nn:
print("\n--------------------------------------------------")
print("""
\nONCHAIN TRANSACTION DECODED
Amount: {} sats
Tx Hash: {}
Block Hash: {}
Block Height: {}
Confirmations: {}
Destination: {}
""".format(s['amount'], s['tx_hash'], s['block_hash'], s['block_height'], s['num_confirmations'], trx))
print("---------------------------------------------------\n")
print("\nTransaction Hash")
print("\033[1;30;47m")
qr.add_data(s['tx_hash'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
input("\nContinue... ")
except:
break
def locallistinvoices():
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
lncli = " listinvoices"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
n = d['invoices']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\tInvoices\n")
try:
print("\n\tLIST INVOICES\n")
for item_ in n:
s = item_
print("Invoice: " + s['r_hash'] + " " + s['state'])
nd = input("\nSelect RHash: ")
for item in n:
s = item
nn = s['r_hash']
if nd == nn:
print("\n----------------------------------------------------------------------------------------------------")
print("""
\nINVOICE DECODED
Memo: {}
Invoice: {}
Amount: {} sats
State: {}
""".format(s['memo'], s['payment_request'], s['amt_paid_sat'], s['state']))
print("----------------------------------------------------------------------------------------------------\n")
print("\033[1;30;47m")
qr.add_data(s['payment_request'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
input("\nContinue... ")
except:
break
def locallistchannels():
lncli = " listchannels"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
n = d['channels']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\t\nChannels\n")
try:
print("\n\tLIST CHANNELS\n")
for item_ in n:
s = item_
print("Node ID: " + s['remote_pubkey'])
nd = input("\nSelect a Node ID: ")
for item in n:
s = item
nn = s['remote_pubkey']
if nd == nn:
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tCHANNEL DECODED
Active: {}
Node ID: {}
Channel Point: {}
Channel Capacity: {} sats
Local Balance: {} sats
Remote Balance: {} sats
Total Sent: {} sats
Total Received: {} sats
""".format(s['active'], s['remote_pubkey'], s['channel_point'], s['capacity'], s['local_balance'], s['remote_balance'], s['total_satoshis_sent'], s['total_satoshis_received']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
except:
break
def localgetinfo():
lncli = " getinfo"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tNODE INFORMATION
Version: {}
Node ID: {}
Alias: {}
Color: {}
Pending Channels: {}
Active Channels: {}
Inactive Channels: {}
Peers: {}
URLS: {}
""".format(d['version'], d['identity_pubkey'], d['alias'], d['color'], d['num_pending_channels'], d['num_active_channels'], d['num_inactive_channels'], d['num_peers'], d['uris']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
def localaddinvoice():
lncli = " addinvoice"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
try:
amount = input("Amount in sats: ")
mem = input("Memo: ")
memo = mem.replace(" ","_")
lsd = os.popen(lndconnectload['ln'] + lncli + " --memo {}-PyBLOCK --amt {}".format(memo, amount)).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
print("\033[1;30;47m")
qr.add_data(d['payment_request'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
print("Lightning Invoice: " + d['payment_request'])
b = str(d['payment_request'])
while True:
lsd = os.popen(lndconnectload['ln'] + " decodepayreq " + b).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
r = d['payment_hash']
lsdn = os.popen(lndconnectload['ln'] + " lookupinvoice " + r).read()
lsdn0 = str(lsdn)
n = json.loads(lsdn0)
if n['state'] == 'SETTLED':
print("\033[1;32;40m")
clear()
blogo()
tick()
print("\033[0;37;40m")
t.sleep(2)
break
elif n['state'] == 'CANCELED':
print("\033[1;31;40m")
clear()
blogo()
canceled()
print("\033[0;37;40m")
t.sleep(2)
break
except:
pass
def localpayinvoice():
try:
invoiceN = input("Insert the invoice to pay: ")
invoice = invoiceN.lower()
lncli = " payinvoice "
lsd = os.popen(lndconnectload['ln'] + " decodepayreq " + invoice).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
if d['num_satoshis'] == "0":
amt = " --amt "
amount = input("Amount in satoshis: ")
os.system(lndconnectload['ln'] + lncli + invoice + amt + amount)
else:
os.system(lndconnectload['ln'] + lncli + invoice )
t.sleep(2)
except:
pass
def localgetnetworkinfo():
lncli = " getnetworkinfo"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tLIGHTNING NETWORK INFORMATION
Numbers of Nodes: {}
Numbers of Channels: {}
Total Network Capacity: {} sats
Average Channel Size: {}
Minimum Channel Size: {}
Maximum Channel Size: {}
Median Channel Size: {} sats
Zombie channels: {}
""".format(d['num_nodes'], d['num_channels'], d['total_network_capacity'], d['avg_channel_size'], d['min_channel_size'], d['max_channel_size'], d['median_channel_size_sat'], d['num_zombie_chans']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
def localkeysend():
try:
print("\n\tYou ar going to send a payment using KeySend - Note: You don't need any invoice, just your peer ID.")
lncli = " sendpayment "
node = input("Send to NodeID: ")
amount = input("Amount in sats: ")
while True:
if amount in ["", "0"]:
amount = input("\nAmount in sats: ")
else:
break
os.system(lndconnectload['ln'] + lncli + "--keysend --d=" + node + " --amt=" + amount + " --final_cltv_delta=40")
except:
pass
def localchannelbalance():
lncli = " channelbalance"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tLOCAL CHANNEL BALANCE
Balance: {} sats
Pending Channels: {} sats
""".format(d['balance'], d['pending_open_balance']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
def localnewaddress():
lncli = " newaddress p2wkh"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
print("\033[1;30;47m")
qr.add_data(d['address'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
print("Bitcoin Address: " + d['address'])
input("\nContinue... ")
def localbalanceOC():
lncli = " walletbalance"
lsd = os.popen(lndconnectload['ln'] + lncli).read()
lsd0 = str(lsd)
d = json.loads(lsd0)
print("\n----------------------------------------------------------------------------------------------------")
print("\n\tLOCAL ONCHAIN BALANCE\n")
print("Total Balance: " + d['total_balance'] + " sats")
print("Confirmed Balance: " + d['confirmed_balance'] + " sats")
print("Unconfirmed Balance: " + d['unconfirmed_balance'] + " sats")
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
# Remote connection with rest -------------------------------------
def getnewinvoice():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
try:
amount = input("Amount in sats: ")
memo = input("Memo: ")
url = 'https://{}/v1/invoices'.format(lndconnectload["ip_port"])
data = {
}
if amount == "":
r = requests.post(
url,
headers=headers, verify=cert_path,
json={"memo": memo + " -PyBLOCK"},
)
else:
r = requests.post(
url,
headers=headers, verify=cert_path,
json={"value": amount, "memo": memo + " -PyBLOCK"},
)
a = r.json()
print("\033[1;30;47m")
qr.add_data(a['payment_request'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
print("Lightning Invoice: " + a['payment_request'])
b = str(a['payment_request'])
while True:
url = 'https://{}/v1/payreq/{}'.format(lndconnectload["ip_port"], b)
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
url = 'https://{}/v1/invoice/{}'.format(lndconnectload["ip_port"],a['payment_hash'])
rr = requests.get(url, headers=headers, verify=cert_path)
m = rr.json()
if m['state'] == 'SETTLED':
print("\033[1;32;40m")
clear()
blogo()
tick()
print("\033[0;37;40m")
t.sleep(2)
break
elif m['state'] == 'CANCELED':
print("\033[1;31;40m")
clear()
blogo()
canceled()
print("\033[0;37;40m")
t.sleep(2)
break
except:
pass
def payinvoice():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
try:
while True:
bolt11N = input("Insert the invoice to pay: ")
url = 'https://{}/v1/payreq/{}'.format(lndconnectload["ip_port"],bolt11N)
r = requests.get(url, headers=headers, verify=cert_path)
s = r.json()
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tINVOICE DECODED
Destination: {}
Payment Hash: {}
Amount: {} sats
Description: {}
""".format(s['destination'], s['payment_hash'], s['num_satoshis'], s['description']))
print("----------------------------------------------------------------------------------------------------\n")
print("<<< Cancel Control + C")
input("\nEnter to Continue... ")
bolt11 = bolt11N.lower()
r = requests.post(
url='https://{}/v1/channels/transactions'.format(lndconnectload["ip_port"]), headers=headers, verify=cert_path, json={"payment_request": bolt11}
)
try:
r.json()['error']
print("\nThe Invoice don't have an amount. Please insert an Invoice with amount. \n")
continue
except:
break
ok, checking_id, fee_msat, error_message = r.ok, None, 0, None
r = requests.get(url='https://{}/v1/payreq/{}'.format(lndconnectload["ip_port"],bolt11), headers=headers, verify=cert_path,)
t.sleep(5)
if r.ok:
checking_id = r.json()["payment_hash"]
print("\033[1;32;40m")
clear()
blogo()
tick()
else:
error_message = r.json()["error"]
print("\033[1;31;40m")
clear()
blogo()
canceled()
print("\033[0;37;40m")
t.sleep(2)
except:
pass
def getnewaddress():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
try:
url = 'https://{}/v1/newaddress'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
addr = r.json()
print("\033[1;30;47m")
qr.add_data(addr['address'])
qr.print_ascii()
print("\033[0;37;40m")
print("Bitcoin Address: " + addr['address'])
qr.clear()
input("\nContinue... ")
except:
pass
def listinvoice():
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/invoices'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
n = a['invoices']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\tInvoices\n")
try:
print("\n\tLIST INVOICES\n")
for r in range(len(n)):
s = n[r]
print("Invoice: " + s['r_hash'] + " " + s['state'])
nd = input("\nSelect RHash: ")
for item in n:
s = item
nn = s['r_hash']
if nd == nn:
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tINVOICE DECODED
Memo: {}
Invoice: {}
Amount: {} sats
State: {}
""".format(s['memo'], s['payment_request'], s['amt_paid_sat'], s['state']))
print("----------------------------------------------------------------------------------------------------\n")
print("\033[1;30;47m")
qr.add_data(s['payment_request'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
input("\nContinue... ")
except:
break
input("\nContinue... ")
def getinfo():
try:
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/getinfo'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
print("\n----------------------------------------------------------------------------------------------------")
print("""
\t NODE INFORMATION
Version: {}
Node ID: {}
Alias: {}
Color: {}
Pending Channels: {}
Active Channels: {}
Inactive Channels: {}
Peers: {}
URLS: {}
""".format(a['version'], a['identity_pubkey'], a['alias'], a['color'], a['num_pending_channels'], a['num_active_channels'], a['num_inactive_channels'], a['num_peers'], a['uris']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
except:
pass
def channels():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/channels'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
n = a['channels']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\t\nChannels\n")
try:
print("\n\tLIST CHANNELS\n")
for r in range(len(n)):
s = n[r]
print("Node ID: " + s['remote_pubkey'])
nd = input("\nSelect a Node ID: ")
for item in n:
s = item
nn = s['remote_pubkey']
if nd == nn:
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tCHANNEL DECODED
Active: {}
Node ID: {}
Channel Point: {}
Channel Capacity: {} sats
Local Balance: {} sats
Remote Balance: {} sats
Total Sent: {} sats
Total Received: {} sats
""".format(s['active'], s['remote_pubkey'], s['channel_point'], s['capacity'], s['local_balance'], s['remote_balance'], s['total_satoshis_sent'], s['total_satoshis_received']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
except:
break
def channelbalance():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/balance/channels'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tLOCAL CHANNEL BALANCE
Balance: {} sats
Pending Channels: {} sats
""".format(a['balance'], a['pending_open_balance']))
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
def listonchaintxs():
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/transactions'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
n = a['transactions']
while True:
clear()
print("\033[1;32;40m")
blogo()
print("\033[0;37;40m")
print("<<< Back to the Main Menu Press Control + C.\n\n")
print("\t\nTransactions\n")
try:
print("\n\tLIST ONCHAIN TRANSACTIONS\n")
for r in range(len(n)):
s = n[r]
print("Transaction Hash: " + s['tx_hash'])
nd = input("\nSelect RHash: ")
for item in n:
s = item
nn = s['tx_hash']
trx = s['dest_addresses']
if nd == nn:
print("\n----------------------------------------------------------------------------------------------------")
print("""
\tONCHAIN TRANSACTION DECODED
Amount: {} sats
Tx Hash: {}
Block Hash: {}
Block Height: {}
Confirmations: {}
Destination: {}
""".format(s['amount'], s['tx_hash'], s['block_hash'], s['block_height'], s['num_confirmations'], trx))
print("----------------------------------------------------------------------------------------------------\n")
print("\nTransaction Hash")
print("\033[1;30;47m")
qr.add_data(s['tx_hash'])
qr.print_ascii()
print("\033[0;37;40m")
qr.clear()
input("\nContinue... ")
except:
break
def balanceOC():
cert_path = lndconnectload["tls"]
macaroon = codecs.encode(open(lndconnectload["macaroon"], 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
url = 'https://{}/v1/balance/blockchain'.format(lndconnectload["ip_port"])
r = requests.get(url, headers=headers, verify=cert_path)
a = r.json()
print("\n----------------------------------------------------------------------------------------------------")
print("\n\tLOCAL ONCHAIN BALANCE\n")
print("Total Balance: " + a['total_balance'] + " sats")
print("Confirmed Balance: " + a['confirmed_balance'] + " sats")
print("Unconfirmed Balance: " + a['unconfirmed_balance'] + " sats")
print("----------------------------------------------------------------------------------------------------\n")
input("\nContinue... ")
# END Remote connection with rest -------------------------------------
#---------------------------------OPENDIME-----------------------------
def ADDRbalance():
import os, sys; sys.path.insert(0, os.path.normpath(__file__ + '/support/pycode.zip'))
import support.pycode.od_wallet; support.pycode.od_wallet.main()