This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
866 lines (643 loc) · 26.7 KB
/
main.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
from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import askopenfilename
import tkinter as tk
import os
import sys
import base64
import platform
import solcxir
from textwrap import wrap
from web3 import Web3
import threading
from itertools import islice
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto import Random
import sv_ttk
from tkinter import ttk
from decouple import config
import argparse
parser = argparse.ArgumentParser(description='BFY Data uploader')
parser.add_argument("-t", "--time_out", help="Timeout time with RPC", type=int, default=1200) #20 minuts of time out? Yes maybe no one mine on the pool
parser.add_argument("-e", "--encoding_type", help="Encoding Type of the file valid options: base64, base64withpassword", type=str, default="base64")
parser.add_argument("-g", "--gui", help="Enable/Disable gui", type=str, default="True")
parser.add_argument("-i", "--input", help="Patch of the file to upload (work only with --gui False)", type=str)
parser.add_argument("-rpc", help="RPC url of blockyfile", type=str, default= "https://node1.blockyfile.org/")
parser.add_argument("-p", "--password", help="Password of base64withpassword encoding", type=str, default= "Password")
parser.add_argument("-gasprice", help="GasPrice for transaction", type=int)
args = parser.parse_args()
encodingtype = args.encoding_type
timeoutblockchain = args.time_out
gui = args.gui
filepath = args.input
rpc = args.rpc
passwordbase64 = args.password
web3 = Web3(Web3.HTTPProvider(rpc, request_kwargs={'timeout': timeoutblockchain}))
if platform.system() == "Linux":
screensize = "475x300"
if platform.system() == "Windows":
screensize = "435x300"
if args.gasprice == None:
gasprice = web3.eth.gas_price
print("gas:" + str(web3.fromWei(web3.eth.gas_price, 'gwei')))
else:
gasprice = web3.toWei(args.gasprice, 'gwei')
print("gas:" + str(args.gasprice))
constfrocontract = 0.0000000000715 * float(gasprice) #is the 0.0000000000715 1 trasaction of 100kb (the max one for 1 block)
def encrypt(key, source, encode=True):
key = SHA256.new(key).digest() # use SHA-256 over our key to get a proper-sized AES key
IV = Random.new().read(AES.block_size) # generate IV
encryptor = AES.new(key, AES.MODE_CBC, IV)
padding = AES.block_size - len(source) % AES.block_size # calculate needed padding
source += bytes([padding]) * padding # Python 2.x: source += chr(padding) * padding
data = IV + encryptor.encrypt(source) # store the IV at the beginning and encrypt
return base64.b64encode(data).decode("latin-1") if encode else data
def clearFile():
indice = 52
conta = 0
for i in range(101):
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
#print("Your name: " + data[3])
data[indice] = " \n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +1
indice = 1050
for i in range(101):
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " \n"
data[indice+1] = " \n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
indice = 1350
for i in range(101):
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " \n"
data[indice+1] = " \n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
#region Archivatore Dati
def UploadToBlockchain():
from solcxir import compile_standard
solcxir.install_solc('0.5.0')
if gui == "True":
ws.update_idletasks()
compiledcontract = compile_standard({
"language": "Solidity",
"sources" : { "contract.sol": {
"content": contratto
}},
"settings": {
"outputSelection": {
"*": { "*":
["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
}
}, solc_version = "0.5.0")
# 4. Export contract data
abi = compiledcontract['contracts']['contract.sol']['SolidityTest']['abi']
bytecode = compiledcontract['contracts']['contract.sol']['SolidityTest']['evm']['bytecode']['object']
# Create address variable
account_from = {
'private_key': config('private_key'),
'address': config('address'),
}
print(f'Attempting to deploy from account: { account_from["address"] }')
# 4. Create contract instance
Incrementer = web3.eth.contract(abi=abi, bytecode=bytecode)
# 5. Build constructor tx
construct_txn = Incrementer.constructor().buildTransaction(
{
'from': account_from['address'],
'gasPrice': gasprice,
'chainId': 171,
'nonce': web3.eth.get_transaction_count(account_from['address'])
}
)
# 6. Sign tx with PK
tx_create = web3.eth.account.sign_transaction(construct_txn, account_from['private_key'])
# 7. Send tx and wait for receipt
tx_hash = web3.eth.send_raw_transaction(tx_create.rawTransaction)
tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash, timeout=timeoutblockchain)
print(f'Contract deployed at address: { tx_receipt.contractAddress }')
return tx_receipt.contractAddress
#endregion
#region UploadAggregator
def UploadAggregator():
import solcxir
from solcxir import compile_files
solcxir.install_solc('0.8.18') #don't use 0.8.20 or >
compiledcontract = compile_files(
["contracts/aggregator.sol"],
output_values=["abi", "metadata", "bin"],
solc_version="0.8.18",
optimize = True,
via_ir = True
)
contract_id, contract_interface = compiledcontract.popitem()
# 4. Export contract data
abi = contract_interface['abi']
bytecode = contract_interface['bin']
# Create address variable
account_from = {
'private_key': config('private_key'),
'address': config('address'),
}
print(f'Attempting to deploy from account: { account_from["address"] }')
# 4. Create contract instance
Incrementer = web3.eth.contract(abi=abi, bytecode=bytecode)
# 5. Build constructor tx
construct_txn = Incrementer.constructor().buildTransaction(
{
'from': account_from['address'],
'gasPrice': gasprice,
'chainId': 171,
'nonce': web3.eth.get_transaction_count(account_from['address'])
}
)
# 6. Sign tx with PK
tx_create = web3.eth.account.sign_transaction(construct_txn, account_from['private_key'])
# 7. Send tx and wait for receipt
tx_hash = web3.eth.send_raw_transaction(tx_create.rawTransaction)
tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash, timeout=timeoutblockchain)
print(f'Contract deployed at address: { tx_receipt.contractAddress }')
return tx_receipt.contractAddress
#endregion
solcxir.install_solc('0.8.18')
ws = Tk()
ws.title('BlockyFile data upload')
ws.geometry(screensize)
#region Convert File to string
def open_file():
if gui == "True":
ws.option_add('*foreground', 'black') # set all tk widgets' foreground to black
filepath = askopenfilename(title="Select file", filetypes=(("text files", ".txt .pdf .docx"), ("image files", ".png .jpeg .jpg .gif .webp"), ("video files", ".mp4 .webm .mkv .avi .m4v"), ("audio files", ".mp3 .m4a .ogg .wav"), ("website files", ".html .js .css"), ("all files (not supported)", "*.*")))
if filepath is not None:
pass
print(filepath)
else:
filepath = args.input
global base64_utf8_str, dataurl, size, ContractToBeCreated, contrctlist, cut, type_format, sizemb
binary_fc = open(filepath, 'rb').read() # fc aka file_content
base64_utf8_str = base64.b64encode(binary_fc).decode('utf-8')
ext = filepath.split('.')[-1]
#tryed with mimetypes but don't work all time
if ext == 'png':
type_format = "image/png"
dataurl = f'data:image/png;base64,{base64_utf8_str}'
if ext == 'jpeg':
type_format = "image/jpeg"
dataurl = f'data:image/jpeg;base64,{base64_utf8_str}'
if ext == 'gif':
type_format = "image/gif"
dataurl = f'data:image/gif;base64,{base64_utf8_str}'
if ext == 'webp':
type_format = "image/webp"
dataurl = f'data:image/webp;base64,{base64_utf8_str}'
if ext == 'jpg':
type_format = "image/jpg"
dataurl = f'data:image/jpg;base64,{base64_utf8_str}'
if ext == 'webm':
type_format = "image/webm"
dataurl = f'data:video/webm;base64,{base64_utf8_str}'
if ext == 'mkv':
type_format = "video/x-matroska"
dataurl = f'data:video/x-matroska;base64,{base64_utf8_str}'
if ext == 'avi':
type_format = "video/x-msvideo"
dataurl = f'data:video/x-msvideo;base64,{base64_utf8_str}'
if ext == 'm4a':
type_format = "audio/x-m4a"
dataurl = f'data:audio/x-m4a;base64,{base64_utf8_str}'
if ext == 'ogg':
type_format = "audio/ogg"
dataurl = f'data:audio/ogg;base64,{base64_utf8_str}'
if ext == 'wav':
type_format = "audio/wav"
dataurl = f'data:audio/wav;base64,{base64_utf8_str}'
if ext == 'mp3':
type_format = "audio/mpeg"
dataurl = f'data:audio/mpeg;base64,{base64_utf8_str}'
if ext == 'mp4':
type_format = "video/mp4"
dataurl = f'data:video/mp4;base64,{base64_utf8_str}'
if ext == 'm4v':
type_format = "video/mp4"
dataurl = f'data:video/mp4;base64,{base64_utf8_str}'
if ext == 'html':
type_format = "text/html"
dataurl = f'data:text/html;base64,{base64_utf8_str}'
if ext == 'css':
type_format = "text/css"
dataurl = f'data:text/css;base64,{base64_utf8_str}'
if ext == 'js':
type_format = "text/javascript"
dataurl = f'data:text/javascript;base64,{base64_utf8_str}'
if ext == 'pdf':
type_format = "application/pdf"
dataurl = f'data:application/pdf;base64,{base64_utf8_str}'
if ext == 'docx':
type_format = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
dataurl = f'data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,{base64_utf8_str}'
#print(dataurl)
if encodingtype == "base64withpassword":
if gui == "True":
dataurl = encrypt(bytes(textbox.get(), encoding='utf-8'), bytes(dataurl, encoding='utf-8'))
else:
dataurl = encrypt(bytes(passwordbase64, encoding='utf-8'), bytes(dataurl, encoding='utf-8'))
#about this part: https://ibb.co/BTWvk1V don't ask, it just work
size = len(dataurl)/1024
sizemb = int(len(dataurl)/1048576) #for write in contract
ContractToBeCreated = int(len(dataurl)/100000) # 100kb = 1 divisione, 500k = 5 divisioni
print("size: " + str(size) + " bytes")
contrctlist = []
# check if the number of kb does not exceed 110 for each contract if making one more. error found 260 kb divided into 2 parts would be 130 or greater than 126
if ContractToBeCreated > 0:
if int(size)/ContractToBeCreated > 110:
ContractToBeCreated = ContractToBeCreated + 1
print("Contracts to do: " + str(ContractToBeCreated))
cut = int(len(dataurl)/ContractToBeCreated) #it just work : )
print("bytes per block: " + str(cut))
cost = str(round((ContractToBeCreated * constfrocontract), 2))
if cost == "0.0": cost = "<" + str(round((1 * constfrocontract), 2))
#endregion
adhar3 = Label(
ws,
text="contracts to create " + str(ContractToBeCreated+1)
)
adhar3.grid(row=2, column=0, padx=10)
adhar4 = Label(
ws,
text="Cost: " + cost
)
adhar4.grid(row=2, column=1, padx=10)
def uploadFiles():
global pb1
pb1 = ttk.Progressbar(
ws,
orient=HORIZONTAL,
length=300,
mode='determinate'
)
pb1.grid(row=5, columnspan=3, pady=30)
if gui == "True":
ws.update_idletasks()
threading.Thread(target=start).start()
def start():
#region Archivatore Dati
if size > 100:
b = wrap(dataurl, cut+10)
i=0
contrctlist = []
while i < int(ContractToBeCreated):
if gui == "True":
ws.update_idletasks()
with open('contracts/contract.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
#print("Your name: " + data[3])
global contratto
data[3] = 'string data = "' + b[i] + '";\n'
# and write everything back
with open('contracts/contract.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
with open('contracts/contract.sol', 'r') as file:
# read a list of lines into data
contratto = file.read()
print("uploading " + str(i+1) + " contract:")
contrctlist.append(UploadToBlockchain())
i = i +1
if gui == "True":
pb1['value'] += (100/ContractToBeCreated)
ws.update_idletasks()
else:
contrctlist = []
with open('contracts/contract.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
#print("Your name: " + data[3])
data[3] = 'string data = "' + dataurl + '";\n'
# and write everything back
with open('contracts/contract.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
with open('contracts/contract.sol', 'r') as file:
# read a list of lines into data
contratto = file.read()
contrctlist.append(UploadToBlockchain())
for i in contrctlist:
print(i)
# aggregator start
global Aggregator
if (len(contrctlist)) > 71:
contrctlist = [contrctlist[x:x+70] for x in range(0, len(contrctlist), 70)]
AggregatorList = []
for contract in contrctlist:
indice = 52
conta = 0
for i in contract:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +1
conta = conta +1
#Delate All funcion
indice = 1050
conta = 0
deleteallreturn = ""
for i in contract:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".delateAll();\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
indice = 1350
conta = 0
for i in contract:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".SetOwner(newowner);\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
indice = indice +2
conta = conta +1
conta = 0
concatenamente = ""
for i in contract:
concatenamente = concatenamente + "my_" + str(conta) + ".getValue(),"
conta = conta + 1
#write return
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[15] = " string encode = \"" + encodingtype + "\"" + ";\n"
data[16] = " string type_format = \"" + type_format + "\"" + ";\n"
data[17] = " uint size = " + str(sizemb) + ";\n"
data[1036] = " " + "return string.concat(" + concatenamente[:-1] + ");\n"
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
contratto = file.read()
AggregatorList.append(UploadAggregator())
#clear the file
clearFile()
indice = 52
conta = 0
for i in AggregatorList:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +1
conta = conta +1
#Delate All funcion
indice = 1050
conta = 0
deleteallreturn = ""
for i in AggregatorList:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".delateAll();\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
indice = 1350
conta = 0
for i in AggregatorList:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".SetOwner(newowner);\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
#upload aggregator with aggregator generated
indice = 52
conta = 0
for i in AggregatorList:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
#print("Your name: " + data[3])
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +1
conta = conta +1
#fineciclo
conta = 0
concatenamente = ""
for i in AggregatorList:
concatenamente = concatenamente + "my_" + str(conta) + ".GetData(),"
conta = conta + 1
#scrivi return
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[15] = " string encode = \"" + encodingtype + "\"" + ";\n"
data[16] = " string type_format = \"" + type_format + "\"" + ";\n"
data[17] = " uint size = " + str(sizemb) + ";\n"
data[1036] = " " + "return string.concat(" + concatenamente[:-1] + ");\n"
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
contratto = file.read()
Aggregator = UploadAggregator()
#clear the file
clearFile()
else:
indice = 52
conta = 0
for i in contrctlist:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +1
conta = conta +1
#Delate All funcion
indice = 1050
conta = 0
deleteallreturn = ""
for i in contrctlist:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".delateAll();\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
#corretto fino a qui
indice = indice +2
conta = conta +1
indice = 1350
conta = 0
for i in contrctlist:
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[indice] = " "+ "A my_" + str(conta) + "= A(" + i + ");\n"
data[indice+1] = " "+ "my_" + str(conta) + ".SetOwner(newowner);\n"
# and write everything back
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
indice = indice +2
conta = conta +1
#fineciclo
conta = 0
concatenamente = ""
for i in contrctlist:
concatenamente = concatenamente + "my_" + str(conta) + ".getValue(),"
conta = conta + 1
#scrivi return
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
data = file.readlines()
data[15] = " string encode = \"" + encodingtype + "\"" + ";\n"
data[16] = " string type_format = \"" + type_format + "\"" + ";\n"
data[17] = " uint size = " + str(sizemb) + ";\n"
data[1036] = " " + "return string.concat(" + concatenamente[:-1] + ");\n"
with open('contracts/aggregator.sol', 'w') as file:
file.writelines( data )
with open('contracts/aggregator.sol', 'r') as file:
# read a list of lines into data
contratto = file.read()
Aggregator = UploadAggregator()
#clear the file
clearFile()
#endregion
if gui == "True":
pb1.destroy()
Label(ws, text='File Uploaded Successfully!', foreground='green').grid(row=4, columnspan=2, pady=10)
textbox = Entry(ws, width=45)
textbox.insert(0, "This is Temporary Text...")
textbox.grid(row=8, column=0, pady=10)
textbox.delete(0, END)
textbox.insert(0, Aggregator)
adhar = Label(
ws,
text='Upload file: '
)
adhar.grid(row=0, column=0, padx=0)
adharbtn = Button(
ws,
text ='Choose File',
command = lambda:open_file()
)
adharbtn.grid(row=0, column=1, sticky="e")
upld = Button(
ws,
text='Upload Files',
command=uploadFiles
)
upld.grid(row=3, columnspan=2, pady=10)
upld.grid(sticky=tk.W + tk.E)
def restart():
python = sys.executable
os.execl(python, python, * sys.argv)
upld = Button(
ws,
text='Restart',
command=restart
)
upld.grid(row=9, columnspan=2, pady=10)
upld.grid(sticky=tk.W + tk.E)
adhar2 = Label(
ws,
text=' Upload Status:'
)
adhar2.grid(row=4, column=0, padx=10)
adhar4 = Label(
ws,
text=' (Before chose file)'
)
adhar4.grid(row=10, column=0, padx=7)
adhar3 = Label(
ws,
text=' Encryption type:'
)
adhar3.grid(row=11, column=0, padx=10)
def handle_checkbutton_selection():
if checkbutton1_var.get() == 1:
checkbutton2_var.set(0)
textbox.grid_forget()
global encodingtype
encodingtype = "base64"
def handle_checkbutton_selection2():
if checkbutton2_var.get() == 1:
checkbutton1_var.set(0)
global textbox
textbox = Entry(ws, width=25)
textbox.insert(0, "Password")
textbox.grid(row=14, column=0, pady=10)
global encodingtype
encodingtype = "base64withpassword"
checkbutton1_var = tk.IntVar()
checkbutton2_var = tk.IntVar()
checkbutton1 = ttk.Checkbutton(ws, text="base64", variable=checkbutton1_var, command=handle_checkbutton_selection)
checkbutton2 = ttk.Checkbutton(ws, text="base64 + password", variable=checkbutton2_var, command=handle_checkbutton_selection2)
checkbutton1.grid(row=13, column=0, sticky="w", padx=0, ipadx = 0)
checkbutton2.grid(row=13, column=1, sticky="w", padx=0, ipadx = 0)
sv_ttk.set_theme("dark")
#base64 is default
checkbutton1_var.set(1)
if gui == "True":
ws.iconphoto(False, PhotoImage(file = "logo.png"))
ws.mainloop()
else:
open_file()
start()