forked from JWWeatherman/yeticold
-
Notifications
You must be signed in to change notification settings - Fork 1
/
appyeticold.py
1072 lines (1016 loc) · 52.7 KB
/
appyeticold.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
#IMPORTS
from flask import Flask, render_template, redirect, url_for, request
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import hashlib
import os
import subprocess
import json
import cv2
from qrtools.qrtools import QR
from pyzbar.pyzbar import decode
from PIL import Image
import random
import qrcode
from datetime import datetime
import time
import sys
#VARIABLES
app = Flask(__name__)
home = os.getenv("HOME")
IBD = False
progress = 0
privkeylist = []
privkeycount = 0
xprivlist = []
pubdesc = ''
selectedutxo = ''
addresses = ''
walletimported = False
error = ''
testblockchain = False
#FILE IMPORTS
sys.path.append(home + '/yeticold/utils/')
from formating import *
#RPC
rpcpsw = str(random.randrange(0,1000000))
settings = {"rpc_username": "rpcuser","rpc_password": rpcpsw,"rpc_host": "127.0.0.1","rpc_port": 8332,"address_chunk": 100}
wallet_template = "http://{rpc_username}:{rpc_password}@{rpc_host}:{rpc_port}/wallet/{wallet_name}"
def BTCprogress():
if not (os.path.exists(home + "/.bitcoin")):
return 0
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli getblockchaininfo'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[0]) == 0):
bitcoinprogress = json.loads(response[0].decode("utf-8"))['verificationprogress']
bitcoinprogress = bitcoinprogress * 100
bitcoinprogress = round(bitcoinprogress, 3)
else:
bitcoinprogress = 0
return bitcoinprogress
def BTCFinished():
if not (os.path.exists(home + "/.bitcoin")):
return False
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli getblockchaininfo'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[0]) == 0):
bitcoinprogress = json.loads(response[0].decode("utf-8"))['initialblockdownload']
else:
bitcoinprogress = True
return not bitcoinprogress
def BTCClosed():
if (subprocess.call('lsof -n -i :8332', shell=True) != 1):
return False
elif os.path.exists(home + "/.bitcoin/bitcoind.pid"):
subprocess.call('rm -r ~/.bitcoin/bitcoind.pid', shell=True)
return True
def BTCRunning():
if not (BTCprogress() == 0):
return True
return False
def RPC():
name = 'username'
wallet_name = 'yeticold'
uri = wallet_template.format(**settings, wallet_name=wallet_name)
rpc = AuthServiceProxy(uri, timeout=600) # 1 minute timeout
return rpc
def blockheight():
rpc = RPC()
Blockinfo = rpc.getblockchaininfo()
blockheight = 0
if Blockinfo['pruned']:
blockheight = Blockinfo['pruneheight']
return str(blockheight)
#FLOW
#ROUTES
@app.route("/", methods=['GET', 'POST'])
def redirectroute():
return redirect('/YCmenu')
@app.route("/YCmenu", methods=['GET', 'POST'])
def YCmenu():
if request.method == 'POST':
if request.form['option'] == 'startup':
return redirect('/YCblockchain')
else:
return redirect('/YCRblockchain')
return render_template('YCmenu.html')
#RECOVERY
@app.route("/YCRblockchain", methods=['GET', 'POST'])
def YCRblockchain():
global home
global rpcpsw
global testblockchain
if request.method == 'GET':
if (os.path.exists(home + "/.bitcoin")):
if (os.path.exists(home + "/.bitcoin/bitcoin.conf")):
with open(".bitcoin/bitcoin.conf","r+") as f:
old = f.read()
f.seek(0)
new = "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword="+rpcpsw+"\n"
f.write(new + old)
else:
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCRopenbitcoin')
if request.method == 'POST':
if request.form['option'] == 'downloadblockchain':
testblockchain = True
subprocess.Popen('python3 ~/yeticold/utils/testblockchain.py',shell=True,start_new_session=True)
else:
fmt = '%Y-%m-%d %H:%M:%S'
today = str(datetime.today()).split('.')[0]
print(request.form['date'] + ' 12:0:0')
print(today)
d1 = datetime.strptime(request.form['date'] + ' 12:0:0', fmt)
d2 = datetime.strptime(today, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
diff = (int(d2_ts - d1_ts) / 60) / 10
add = diff / 10
blockheight = diff + add + 550
blockheight = int(blockheight)
home = os.getenv("HOME")
subprocess.call(['mkdir ~/.bitcoin'],shell=True)
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nprune='+str(blockheight)+'\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCRopenbitcoin')
return render_template('YCRblockchain.html')
@app.route("/YCRopenbitcoin", methods=['GET', 'POST'])
def YCRopenbitcoin():
global home
global progress
global IBD
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
testblockchain = False
if BTCClosed():
if testblockchain == False:
subprocess.Popen('~/yeticold/bitcoin/bin/bitcoin-qt -proxy=127.0.0.1:9050',shell=True,start_new_session=True)
IBD = BTCFinished()
progress = BTCprogress()
if request.method == 'POST':
if IBD:
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticold"'],shell=True)
return redirect('/YCRscandescriptor')
else:
return redirect('/YCRopenbitcoin')
return render_template('YCRopenbitcoin.html', progress=progress, IBD=IBD)
#SWITCH TO OFFLINE
@app.route("/YCRblockchainB", methods=['GET', 'POST'])
def YCRblockchainB():
global rpcpsw
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
if (os.path.exists(home + "/.bitcoin/bitcoin.conf")):
with open(".bitcoin/bitcoin.conf","r+") as f:
old = f.read()
f.seek(0)
new = "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword="+rpcpsw+"\n"
f.write(new + old)
else:
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCRopenbitcoinB')
if request.method == 'POST':
if request.form['option'] == 'downloadblockchain':
testblockchain = True
subprocess.Popen('python3 ~/yeticold/utils/testblockchain.py',shell=True,start_new_session=True)
else:
fmt = '%Y-%m-%d %H:%M:%S'
today = str(datetime.today()).split('.')[0]
print(request.form['date'] + ' 12:0:0')
print(today)
d1 = datetime.strptime(request.form['date'] + ' 12:0:0', fmt)
d2 = datetime.strptime(today, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
diff = (int(d2_ts - d1_ts) / 60) / 10
add = diff / 10
blockheight = diff + add + 550
blockheight = int(blockheight)
home = os.getenv("HOME")
subprocess.call(['mkdir ~/.bitcoin'],shell=True)
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nprune='+str(blockheight)+'\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCRopenbitcoinB')
return render_template('YCRblockchainB.html')
@app.route("/YCRopenbitcoinB", methods=['GET', 'POST'])
def YCRopenbitcoinB():
global home
global progress
global IBD
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
testblockchain = False
if BTCClosed():
if testblockchain == False:
subprocess.Popen('~/yeticold/bitcoin/bin/bitcoin-qt -proxy=127.0.0.1:9050',shell=True,start_new_session=True)
IBD = BTCFinished()
progress = BTCprogress()
if request.method == 'POST':
if IBD:
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticold"'],shell=True)
return redirect('/YCRconnection')
else:
return redirect('/YCRopenbitcoinB')
return render_template('YCRopenbitcoinB.html', progress=progress, IBD=IBD)
@app.route("/YCRconnection", methods=['GET', 'POST'])
def YCRconnection():
if request.method == 'POST':
subprocess.call(['python3 ~/yeticold/utils/forgetnetworks.py'],shell=True)
subprocess.call(['nmcli n off'],shell=True)
return redirect('/YCRswitchlaptop')
return render_template('YCRconnection.html')
@app.route("/YCRswitchlaptop", methods=['GET', 'POST'])
def YCRswitchlaptop():
if request.method == 'POST':
return redirect('/YCRscanutxo')
return render_template('YCRswitchlaptop.html')
@app.route("/YCRscandescriptor", methods=['GET', 'POST'])
def YCRscandescriptor():
global pubdesc
if request.method == 'POST':
pubdesc = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
pubdesc = pubdesc.decode("utf-8")
pubdesc = pubdesc.replace('\n', '')
return redirect('/YCRrescanwallet')
return render_template('YCRscandescriptor.html')
@app.route("/YCRrescanwallet", methods=['GET', 'POST'])
def YCRrescanwallet():
global pubdesc
if request.method == 'GET':
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold importmulti \'[{ "desc": "'+pubdesc+'", "timestamp": "now", "range": [0,999], "watchonly": false}]\' \'{"rescan": true}\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
if not (len(response[1]) == 0):
print(response)
return "error response from importmulti: " + str(response[1]) + '\n' + '~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold importmulti \'[{ "desc": "'+pubdesc+'", "timestamp": "now", "range": [0,999], "watchonly": false}]\' \'{"rescan": true}\''
subprocess.Popen('~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold rescanblockchain '+blockheight(),shell=True,start_new_session=True)
if request.method == 'POST':
return redirect('/YCRdisplaywallet')
return render_template('YCRrescanwallet.html')
@app.route("/YCRdisplaywallet", methods=['GET', 'POST'])
def YCRdisplaywallet():
global selectedutxo
global addresses
global rpcpsw
global walletimported
global pubdesc
if request.method == 'GET':
subprocess.call(['rm -r ~/yeticold/static/address*'],shell=True)
pubdesc = pubdesc.replace('\n', '')
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold deriveaddresses "'+pubdesc+'" "[0,999]"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
adrlist = json.loads(response[0].decode("utf-8"))
addresses = []
totalwalletbal = 0
rpc = RPC()
for i in range(0, len(adrlist)):
adr = adrlist[i]
randomnum = str(random.randrange(0,1000000))
route = url_for('static', filename='address'+adr+''+randomnum+'.png')
response = rpc.listunspent(0, 9999999, [adr])
print(response)
if response == []:
totalbal = rpc.getreceivedbyaddress(adrlist[i])
if totalbal:
status = 3
else:
status = 0
address = {}
address['txid'] = ''
address['address'] = adr
address['balance'] = "0.00000000"
address['numbal'] = 0
address['status'] = status
address['route'] = route
addresses.append(address)
else:
for x in range(0, len(response)):
utxo = response[x]
txid = utxo['txid']
vout = utxo['vout']
scriptPubKey = utxo['scriptPubKey']
numamount = utxo['amount']
totalwalletbal = totalwalletbal + numamount
amount = "{:.8f}".format(float(numamount))
numamount = float(amount)
confs = utxo['confirmations']
totalbal = rpc.getreceivedbyaddress(adr)
if numamount:
if not confs:
status = 1
else:
status = 2
elif totalbal:
status = 3
else:
status = 0
address = {}
address['txid'] = txid
address['vout'] = vout
address['scriptPubKey'] = scriptPubKey
address['address'] = adr
address['balance'] = amount
address['numbal'] = numamount
address['status'] = status
address['route'] = route
addresses.append(address)
addresses.sort(key=lambda x: x['balance'], reverse=True)
for i in range(0, len(addresses)):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(addresses[i]['address'])
qr.make(fit=True)
color = '#e9ecef'
if (i % 2) == 0:
color = 'white'
img = qr.make_image(fill_color="black", back_color=color)
home = os.getenv("HOME")
img.save(home + '/yeticold/'+addresses[i]['route'])
if request.method == 'POST':
for i in range(0, len(addresses)):
if request.form['txid'] == addresses[i]['txid']:
selectedutxo = addresses[i]
break
if walletimported:
return redirect('/YCRdisplayutxoB')
return redirect('/YCRdisplayutxo')
return render_template('YCRdisplaywallet.html', addresses=addresses, len=len(addresses), TWB=totalwalletbal)
@app.route("/YCRdisplayutxo", methods=['GET', 'POST'])
def YCRdisplayutxo():
global selectedutxo
if request.method == 'GET':
randomnum = str(random.randrange(0,1000000))
qrname = randomnum
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(str(selectedutxo))
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
img.save(home + '/yeticold/static/qrcode' + qrname + '.png')
path = url_for('static', filename='qrcode' + qrname + '.png')
if request.method == 'POST':
return redirect('/YCRscantransaction')
return render_template('YCRdisplayutxo.html', qrdata=selectedutxo, path=path)
@app.route("/YCRscanutxo", methods=['GET', 'POST'])
def YCRscanutxo():
global selectedutxo
if request.method == 'POST':
selectedutxo = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
selectedutxo = eval(selectedutxo.decode("utf-8"))
return redirect('/YCRscandescriptorB')
return render_template('YCRscanutxo.html')
@app.route("/YCRscandescriptorB", methods=['GET', 'POST'])
def YCRscandescriptorB():
global pubdesc
if request.method == 'POST':
pubdesc = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
return redirect('/YCRimportseeds')
return render_template('YCRscandescriptorB.html')
@app.route('/YCRimportseeds', methods=['GET', 'POST'])
def YCRimportseeds():
global pubdesc
global privkeycount
global error
global privkeylist
global walletimported
if request.method == 'POST':
privkey = []
for i in range(1,14):
inputlist = request.form['row' + str(i)]
inputlist = inputlist.split(' ')
inputlist = inputlist[0:4]
privkey.append(inputlist[0])
privkey.append(inputlist[1])
privkey.append(inputlist[2])
privkey.append(inputlist[3])
privkeylist.append(PassphraseToWIF(privkey))
error = None
privkeycount = privkeycount + 1
if (privkeycount >= 3):
xpublist = []
for i in range(0,3):
rpc = RPC()
home = os.getenv('HOME')
path = home + '/yeticoldwallet' + str(i)
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticoldwallet'+str(i)+'" false true','~/yeticold/bitcoin/bin/bitcoin-cli loadwallet "yeticoldwallet'+str(i)+'"'],shell=True)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldwallet'+str(i)+' sethdseed true "'+privkeylist[i]+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldwallet'+str(i)+' dumpwallet "yeticoldwallet'+str(i)+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
wallet = open(path,'r')
wallet.readline()
wallet.readline()
wallet.readline()
wallet.readline()
wallet.readline()
privkeyline = wallet.readline()
privkeyline = privkeyline.split(" ")[4][:-1]
xprivlist.append(privkeyline)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold getdescriptorinfo "pk('+privkeyline+')"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = response[0].decode("utf-8")
xpub = response.split('(')[1].split(')')[0]
xpublist.append(xpub)
privkeycount = 0
descriptorxpubs = pubdesc.decode("utf-8").split(',')[1:]
descriptorxpubs[6] = descriptorxpubs[6].split('))')[0]
descriptorlist = descriptorxpubs
for i in range(0,3):
xpub = xpublist[i] + '/*'
for x in range(0,7):
oldxpub = descriptorxpubs[x]
if xpub == oldxpub:
descriptorlist[x] = (xprivlist[i] + '/*')
break
desc = '"wsh(multi(3,'+descriptorlist[0]+','+descriptorlist[1]+','+descriptorlist[2]+','+descriptorlist[3]+','+descriptorlist[4]+','+descriptorlist[5]+','+descriptorlist[6]+'))'
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticoldpriv"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv getdescriptorinfo '+desc+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = json.loads(response[0].decode("utf-8"))
checksum = response["checksum"]
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv importmulti \'[{ "desc": '+desc+'#'+ checksum +'", "timestamp": "now", "range": [0,999], "watchonly": false}]\' \'{"rescan": true}\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
walletimported = True
return redirect('/YCRscanrecipent')
else:
return redirect('/YCRimportseeds')
return render_template('YCRimportseeds.html', x=privkeycount + 1, error=error,i=privkeycount + 4)
@app.route("/YCRscanrecipent", methods=['GET', 'POST'])
def YCRscanrecipent():
global error
global receipentaddress
if request.method == 'POST':
error = None
if request.form['option'] == 'scan':
receipentaddress = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
receipentaddress = receipentaddress.decode("utf-8").replace('\n', '')
else:
receipentaddress = request.form['option']
if (receipentaddress.split(':')[0] == 'bitcoin'):
receipentaddress = receipentaddress.split(':')[1].split('?')[0]
if (receipentaddress[:3] == 'bc1') or (receipentaddress[:1] == '3') or (receipentaddress[:1] == '1'):
if not (len(receipentaddress) >= 26) and (len(receipentaddress) <= 35):
error = receipentaddress + ' is not a valid bitcoin address, address should have a length from 26 to 35 instead of ' + str(len(receipentaddress)) + '.'
else:
error = receipentaddress + ' is not a valid bitcoin address, address should have started with bc1, 3 or 1 instead of ' + receipentaddress[:1] + ', or ' + receipentaddress[:3] + '.'
if error:
return redirect('/YCRscanrecipent')
return redirect('/YCRconfirmsend')
return render_template('YCRscanrecipent.html', error=error)
@app.route("/YCRconfirmsend", methods=['GET', 'POST'])
def YCRconfirmsend():
global receipentaddress
if request.method == 'GET':
rpc = RPC()
amount = float(selectedutxo['balance'])
minerfee = float(rpc.estimatesmartfee(1)["feerate"])
kilobytespertrans = 0.200
amo = (amount - (minerfee * kilobytespertrans))
minerfee = (minerfee * kilobytespertrans)
amo = "{:.8f}".format(float(amo))
minerfee = "{:.8f}".format(float(minerfee))
if request.method == 'POST':
return redirect('/YCRdisplaytransaction')
return render_template('YCRconfirmsend.html', amount=amo, minerfee=minerfee, recipent=receipentaddress)
@app.route("/YCRdisplaytransaction", methods=['GET', 'POST'])
def YCRdisplaytransaction():
global selectedutxo
global receipentaddress
if request.method == 'GET':
rpc = RPC()
amount = float(selectedutxo['balance'])
minerfee = float(rpc.estimatesmartfee(1)["feerate"])
kilobytespertrans = 0.200
amo = (amount - (minerfee * kilobytespertrans))
minerfee = (minerfee * kilobytespertrans)
amo = "{:.8f}".format(float(amo))
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv createrawtransaction \'[{ "txid": "'+selectedutxo['txid']+'", "vout": '+str(selectedutxo['vout'])+'}]\' \'[{"'+receipentaddress+'" : '+str(amo)+'}]\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = response[0].decode("utf-8")
transonehex = response[:-1]
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv signrawtransactionwithwallet '+transonehex+' \'[{"txid":"'+selectedutxo['txid']+'","vout":'+str(selectedutxo['vout'])+',"scriptPubKey":"'+selectedutxo['scriptPubKey']+'","amount":"'+str(amount)+'"}]\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
transhex = json.loads(response[0].decode("utf-8"))['hex']
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(transhex)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
randomnum = str(random.randrange(0,1000000))
img.save(home + '/yeticold/static/qrcode'+randomnum+'.png')
path = url_for('static', filename='qrcode'+randomnum+'.png')
if request.method == 'POST':
return redirect('/YCRscanutxoB')
return render_template('YCRdisplaytransaction.html', qrdata=transhex, path=path)
@app.route("/YCRscantransaction", methods=['GET', 'POST'])
def YCRscantransaction():
if request.method == 'POST':
response = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
transactionhex = response.decode("utf-8")
print(transactionhex)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet= sendrawtransaction '+transactionhex],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
return redirect('/YCRdisplaywallet')
return render_template('YCRscantransaction.html')
#REPEAT RECOVERY
@app.route("/YCRdisplayutxoB", methods=['GET', 'POST'])
def YCRdisplayutxoB():
global selectedutxo
if request.method == 'GET':
randomnum = str(random.randrange(0,1000000))
qrname = randomnum
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(str(selectedutxo))
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
img.save(home + '/yeticold/static/qrcode' + qrname + '.png')
path = url_for('static', filename='qrcode' + qrname + '.png')
if request.method == 'POST':
return redirect('/YCRscantransactionB')
return render_template('YCRdisplayutxoB.html', qrdata=selectedutxo, path=path)
@app.route("/YCRscanutxoB", methods=['GET', 'POST'])
def YCRscanutxoB():
global selectedutxo
if request.method == 'POST':
selectedutxo = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
selectedutxo = eval(selectedutxo.decode("utf-8"))
return redirect('/YCRscanrecipentB')
return render_template('YCRscanutxoB.html')
@app.route("/YCRscanrecipentB", methods=['GET', 'POST'])
def YCRscanrecipentB():
global error
global receipentaddress
if request.method == 'POST':
error = None
if request.form['option'] == 'scan':
receipentaddress = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
receipentaddress = receipentaddress.decode("utf-8").replace('\n', '')
else:
receipentaddress = request.form['option']
if (receipentaddress.split(':')[0] == 'bitcoin'):
receipentaddress = receipentaddress.split(':')[1].split('?')[0]
if (receipentaddress[:3] == 'bc1') or (receipentaddress[:1] == '3') or (receipentaddress[:1] == '1'):
if not (len(receipentaddress) >= 26) and (len(receipentaddress) <= 35):
error = receipentaddress + ' is not a valid bitcoin address, address should have a length from 26 to 35 instead of ' + str(len(receipentaddress)) + '.'
else:
error = receipentaddress + ' is not a valid bitcoin address, address should have started with bc1, 3 or 1 instead of ' + receipentaddress[:1] + ', or ' + receipentaddress[:3] + '.'
if error:
return redirect('/YCRscanrecipentB')
return redirect('/YCRconfirmsendB')
return render_template('YCRscanrecipentB.html', error=error)
@app.route("/YCRconfirmsendB", methods=['GET', 'POST'])
def YCRconfirmsendB():
global receipentaddress
if request.method == 'GET':
rpc = RPC()
amount = float(selectedutxo['balance'])
minerfee = float(rpc.estimatesmartfee(1)["feerate"])
kilobytespertrans = 0.200
amo = (amount - (minerfee * kilobytespertrans))
minerfee = (minerfee * kilobytespertrans)
amo = "{:.8f}".format(float(amo))
minerfee = "{:.8f}".format(float(minerfee))
if request.method == 'POST':
return redirect('/YCRdisplaytransactionB')
return render_template('YCRconfirmsendB.html', amount=amo, minerfee=minerfee, recipent=receipentaddress)
@app.route("/YCRdisplaytransactionB", methods=['GET', 'POST'])
def YCRdisplaytransactionB():
global selectedutxo
global receipentaddress
if request.method == 'GET':
rpc = RPC()
amount = float(selectedutxo['balance'])
minerfee = float(rpc.estimatesmartfee(1)["feerate"])
kilobytespertrans = 0.200
amo = (amount - (minerfee * kilobytespertrans))
minerfee = (minerfee * kilobytespertrans)
amo = "{:.8f}".format(float(amo))
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv createrawtransaction \'[{ "txid": "'+selectedutxo['txid']+'", "vout": '+str(selectedutxo['vout'])+'}]\' \'[{"'+receipentaddress+'" : '+str(amo)+'}]\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = response[0].decode("utf-8")
transonehex = response[:-1]
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv signrawtransactionwithwallet '+transonehex+' \'[{"txid":"'+selectedutxo['txid']+'","vout":'+str(selectedutxo['vout'])+',"scriptPubKey":"'+selectedutxo['scriptPubKey']+'","amount":"'+str(amount)+'"}]\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
transhex = json.loads(response[0].decode("utf-8"))['hex']
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(transhex)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
randomnum = str(random.randrange(0,1000000))
img.save(home + '/yeticold/static/qrcode'+randomnum+'.png')
path = url_for('static', filename='qrcode'+randomnum+'.png')
if request.method == 'POST':
return redirect('/YCRscanutxoB')
return render_template('YCRdisplaytransactionB.html', qrdata=transhex, path=path)
@app.route("/YCRscantransactionB", methods=['GET', 'POST'])
def YCRscantransactionB():
if request.method == 'POST':
response = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
transactionhex = response.decode("utf-8")
print(transactionhex)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet= sendrawtransaction '+transactionhex],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
return redirect('/YCRdisplaywallet')
return render_template('YCRscantransactionB.html')
#SETUP
@app.route("/YCblockchain", methods=['GET', 'POST'])
def YCblockchain():
global rpcpsw
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
if (os.path.exists(home + "/.bitcoin/bitcoin.conf")):
with open(".bitcoin/bitcoin.conf","r+") as f:
old = f.read()
f.seek(0)
new = "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword="+rpcpsw+"\n"
f.write(new + old)
else:
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCopenbitcoin')
if request.method == 'POST':
if request.form['option'] == 'downloadblockchain':
testblockchain = True
subprocess.Popen('python3 ~/yeticold/utils/testblockchain.py',shell=True,start_new_session=True)
else:
fmt = '%Y-%m-%d %H:%M:%S'
today = str(datetime.today()).split('.')[0]
print(request.form['date'] + ' 12:0:0')
print(today)
d1 = datetime.strptime(request.form['date'] + ' 12:0:0', fmt)
d2 = datetime.strptime(today, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
diff = (int(d2_ts - d1_ts) / 60) / 10
add = diff / 10
blockheight = diff + add + 550
blockheight = int(blockheight)
home = os.getenv("HOME")
subprocess.call(['mkdir ~/.bitcoin'],shell=True)
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nprune='+str(blockheight)+'\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCopenbitcoin')
return render_template('YCblockchain.html')
@app.route("/YCopenbitcoin", methods=['GET', 'POST'])
def YCopenbitcoin():
global home
global progress
global IBD
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
testblockchain = False
if BTCClosed():
if testblockchain == False:
subprocess.Popen('~/yeticold/bitcoin/bin/bitcoin-qt -proxy=127.0.0.1:9050',shell=True,start_new_session=True)
IBD = BTCFinished()
progress = BTCprogress()
if request.method == 'POST':
if IBD:
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticold"'],shell=True)
return redirect('/YCscandescriptor')
else:
return redirect('/YCopenbitcoin')
return render_template('YCopenbitcoin.html', progress=progress, IBD=IBD)
#SWITCH TO OFFLINE
@app.route("/YCblockchainB", methods=['GET', 'POST'])
def YCblockchainB():
global rpcpsw
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
if (os.path.exists(home + "/.bitcoin/bitcoin.conf")):
with open(".bitcoin/bitcoin.conf","r+") as f:
old = f.read()
f.seek(0)
new = "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword="+rpcpsw+"\n"
f.write(new + old)
else:
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCopenbitcoinB')
if request.method == 'POST':
if request.form['option'] == 'downloadblockchain':
testblockchain = True
subprocess.Popen('python3 ~/yeticold/utils/testblockchain.py',shell=True,start_new_session=True)
else:
fmt = '%Y-%m-%d %H:%M:%S'
today = str(datetime.today()).split('.')[0]
print(request.form['date'] + ' 12:0:0')
print(today)
d1 = datetime.strptime(request.form['date'] + ' 12:0:0', fmt)
d2 = datetime.strptime(today, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
diff = (int(d2_ts - d1_ts) / 60) / 10
add = diff / 10
blockheight = diff + add + 550
blockheight = int(blockheight)
home = os.getenv("HOME")
subprocess.call(['mkdir ~/.bitcoin'],shell=True)
subprocess.call('echo "server=1\nrpcport=8332\nrpcuser=rpcuser\nprune='+str(blockheight)+'\nrpcpassword='+rpcpsw+'" >> '+home+'/.bitcoin/bitcoin.conf', shell=True)
return redirect('/YCopenbitcoinB')
return render_template('YCblockchainB.html')
@app.route("/YCopenbitcoinB", methods=['GET', 'POST'])
def YCopenbitcoinB():
global home
global progress
global IBD
global testblockchain
if request.method == 'GET':
home = os.getenv("HOME")
if (os.path.exists(home + "/.bitcoin")):
testblockchain = False
if BTCClosed():
if testblockchain == False:
subprocess.Popen('~/yeticold/bitcoin/bin/bitcoin-qt -proxy=127.0.0.1:9050',shell=True,start_new_session=True)
IBD = BTCFinished()
progress = BTCprogress()
if request.method == 'POST':
if IBD:
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticold"'],shell=True)
return redirect('/YCconnection')
else:
return redirect('/YCopenbitcoinB')
return render_template('YCopenbitcoinB.html', progress=progress, IBD=IBD)
@app.route("/YCconnection", methods=['GET', 'POST'])
def YCconnection():
if request.method == 'POST':
subprocess.call(['python3 ~/yeticold/utils/forgetnetworks.py'],shell=True)
subprocess.call(['nmcli n off'],shell=True)
return redirect('/YCgetseeds')
return render_template('YCconnection.html')
@app.route("/YCgetseeds", methods=['GET', 'POST'])
def YCgetseeds():
global privkeylist
global privkeycount
global xprivlist
global pubdesc
global home
global walletimported
if request.method == 'POST':
if request.form['skip'] == 'skip':
privkeylisttemp = []
for i in range(1,8):
rpc = RPC()
adr = rpc.getnewaddress()
newprivkey = rpc.dumpprivkey(adr)
binary = bin(decode58(newprivkey))[2:][8:-40]
newbinary = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
WIF = ConvertToWIF(xor(binary,newbinary))
privkeylisttemp.append(WIF)
privkeycount = 0
privkeylist = privkeylisttemp
else:
privkeylisttemp = []
for i in range(1,8):
rpc = RPC()
adr = rpc.getnewaddress()
newprivkey = rpc.dumpprivkey(adr)
binary = bin(decode58(newprivkey))[2:][8:-40]
WIF = ConvertToWIF(xor(binary,request.form['binary' + str(i)]))
privkeylisttemp.append(WIF)
privkeycount = 0
privkeylist = privkeylisttemp
for i in range(0,7):
home = os.getenv('HOME')
pathtwo = home + '/yeticoldwallet' + str(i)
path = home + '/yeticoldwallettwo' + str(i)
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticoldwallettwo'+str(i)+'"'],shell=True)
subprocess.call(['~/yeticold/bitcoin/bin/bitcoin-cli loadwallet "yeticoldwallettwo'+str(i)+'"'],shell=True)
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldwallettwo'+str(i)+' sethdseed true "'+privkeylist[i]+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[1]) == 0):
print(response)
return "error response from sethdseed: " + str(response[1]) + '\n' + '~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldwallettwo'+str(i)+' sethdseed true "'+privkeylist[i]+'"'
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldwallettwo'+str(i)+' dumpwallet "yeticoldwallettwo'+str(i)+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
wallet = open(path,'r')
wallet.readline()
wallet.readline()
wallet.readline()
wallet.readline()
wallet.readline()
privkeyline = wallet.readline()
privkeyline = privkeyline.split(" ")[4][:-1]
xprivlist.append(privkeyline)
addresses = []
checksum = None
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold getdescriptorinfo "wsh(multi(3,'+xprivlist[0]+'/*,'+xprivlist[1]+'/*,'+xprivlist[2]+'/*,'+xprivlist[3]+'/*,'+xprivlist[4]+'/*,'+xprivlist[5]+'/*,'+xprivlist[6]+'/*))"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not (len(response[0]) == 0):
response = json.loads(response[0].decode("utf-8"))
else:
print(response)
return "error response from getdescriptorinfo: " + str(response[1]) + '\n' + '~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold getdescriptorinfo "wsh(multi(3,'+xprivlist[0]+'/*,'+xprivlist[1]+'/*,'+xprivlist[2]+'/*,'+xprivlist[3]+'/*,'+xprivlist[4]+'/*,'+xprivlist[5]+'/*,'+xprivlist[6]+'/*))"'
checksum = response["checksum"]
pubdesc = response["descriptor"]
seedpath = home + '/Documents'
subprocess.call('rm -r '+seedpath+'/ycseed*', shell=True)
privdesc = '"wsh(multi(3,'+xprivlist[0]+'/*,'+xprivlist[1]+'/*,'+xprivlist[2]+'/*,'+xprivlist[3]+'/*,'+xprivlist[4]+'/*,'+xprivlist[5]+'/*,'+xprivlist[6]+'/*))'
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli createwallet "yeticoldpriv"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv getdescriptorinfo '+privdesc+'"'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
print(response)
response = json.loads(response[0].decode("utf-8"))
checksum = response["checksum"]
response = subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticoldpriv importmulti \'[{ "desc": '+privdesc+'#'+ checksum +'", "timestamp": "now", "range": [0,999], "watchonly": false}]\' \'{"rescan": true}\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
walletimported = True
return redirect('/YCdisplaydescriptor')
return render_template('YCgetseeds.html')
@app.route("/YCdisplaydescriptor", methods=['GET', 'POST'])
def YCdisplaydescriptor():
global privkeylist
global pubdesc
if request.method == 'GET':
randomnum = str(random.randrange(0,1000000))
firstqrname = randomnum
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(pubdesc)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
img.save(home + '/yeticold/static/firstqrcode' + firstqrname + '.png')
path = url_for('static', filename='firstqrcode' + firstqrname + '.png')
if request.method == 'POST':
return redirect('/YCdisplayseeds')
return render_template('YCdisplaydescriptor.html', qrdata=pubdesc, path=path)
@app.route("/YCscandescriptor", methods=['GET', 'POST'])
def YCscandescriptor():
global pubdesc
if request.method == 'POST':
pubdesc = subprocess.Popen(['python3 ~/yeticold/utils/scanqrcode.py'],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
pubdesc = pubdesc.decode("utf-8")
pubdesc = pubdesc.replace('\n', '')
subprocess.Popen(['~/yeticold/bitcoin/bin/bitcoin-cli -rpcwallet=yeticold importmulti \'[{ "desc": "'+pubdesc+'", "timestamp": "now", "range": [0,999], "watchonly": false}]\' \'{"rescan": true}\''],shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
return redirect('/YCprintpage')
return render_template('YCscandescriptor.html')
@app.route("/YCprintpage", methods=['GET', 'POST'])
def YCprintpage():
global pubdesc
randomnum = str(random.randrange(0,1000000))
firstqrname = randomnum
secondqrname = randomnum
thirdqrname = randomnum
path = url_for('static', filename='firstqrcode' + firstqrname + '.png')
if request.method == 'GET':
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(pubdesc)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
img.save(home + '/yeticold/static/firstqrcode' + firstqrname + '.png')
if request.method == 'POST':
return redirect('/YCswitchlaptop')
return render_template('YCprintpage.html', qrdata=pubdesc, path=path)
@app.route("/YCswitchlaptop", methods=['GET', 'POST'])
def YCswitchlaptop():
if request.method == 'POST':
return redirect('/YCRdisplaywallet')
return render_template('YCswitchlaptop.html')
@app.route('/YCdisplayseeds', methods=['GET', 'POST'])
def YCdisplayseeds():
global privkeylist
global privkeycount
global pubdesc
if request.method == 'GET':
privkey = privkeylist[privkeycount]
passphraselist = ConvertToPassphrase(privkey)
if request.method == 'POST':
home = os.getenv('HOME')
path = home + '/Documents'
subprocess.call('mkdir '+path+'/ycseed'+str(privkeycount + 1), shell=True)
subprocess.call('touch '+path+'/ycseed'+str(privkeycount + 1)+'/ycseed'+str(privkeycount + 1)+'.txt', shell=True)
file = ''
for i in range(0,13):
file = file + request.form['displayrow' + str(i+1)] + '\n'
file = file + '\n\nThis is your descriptor in text format you have a duplicate of this text in QR format in this folder.\n' + pubdesc + '\n'
file = file + '\n\nThis is a seed packet that contains 1/3 of the information needed to recover bitcoins in a 3 of 7 HD multisig wallet.\n'
file = file + 'There are 6 other packets that are identical except that they contain one of the other sets of seed words.\n'
file = file + 'The HD Multisig wallet was was created using YetiCold.com (a Python script to make the experience more user friendly) and Bitcoin Core 0.19 RC1.\n'
file = file + 'To recover the bitcoin go to YetiCold.com and click "Cold" and then follow the recovery instructions.\n'
file = file + 'YetiCold.com should direct you to download a script to make the process of using Bitcoin Core easier, but never trust any website with your seed words.\n'
file = file + 'Consider putting a small amount of money into YetiCold.com cold storage and recovering them before attempting to recover significant funds.\n'
file = file + 'A test run will give you the opportunity to make sure that your seed words are never connected to an online device before.\n'
file = file + 'If many years have passed you should check that YetiCold.com has retained a good reputation.\n'
file = file + 'If YetiCold.com is no longer reputable use Bitcoin Core alone to recover your bitcoin (with the help of a trusted expert only if absolutely needed as these people may attempt to steal the bitcoin).\n'
file = file + 'No software beyond Bitcoin Core is required to recover the stored bitcoin.\n'
file = file + 'This seed packet also contains a usb device that has a digital copy of the information on this document. It does not contain another set of seed words, but simply a copy of the seed words in this document.\n'
file = file + 'Two other seed packets must be obtained to recover the bitcoin stored.\n'
file = file + 'YetiCold.com recommends storing seed words in locations like safety deposit boxes, home safes, and with professionals such as accountants and lawyers.\n'
subprocess.call('echo "'+file+'" >> '+path+'/ycseed'+str(privkeycount + 1)+'/ycseed'+str(privkeycount + 1)+'.txt', shell=True)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(pubdesc)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
home = os.getenv("HOME")
img.save(home + '/Documents/ycseed'+str(privkeycount + 1)+'/descriptor.png')
privkeycount = privkeycount + 1
if (privkeycount == 7):
privkeycount = 0
return redirect('/YCcheckseeds')
else: