-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathWallet.py
More file actions
1569 lines (1287 loc) · 50.1 KB
/
Wallet.py
File metadata and controls
1569 lines (1287 loc) · 50.1 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
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
import getpass
import hashlib
import json
import time
import datetime
from helpers import is_py2, fetch_user_input, pretty_print, intercept_keyboard_interrupts, handle_replay, get_decoded_string
from operator import itemgetter
from iota import Iota, ProposedTransaction, Address,\
TryteString, Tag, Transaction
from iota.crypto.addresses import AddressGenerator
pretty_print('\nStarting wallet...\n\n\n\n')
'''
Returns a sha256 hash of the seed
'''
def create_seed_hash(seed):
return hashlib.sha256(seed.encode('utf-8')).hexdigest()
'''
Returns a sha256 hash of seed + address
'''
def get_checksum(address):
data = address + seed
return hashlib.sha256(data.encode('utf-8')).hexdigest()
'''
Verifies the integrity of a address
and returns True or False
'''
def verify_checksum(checksum, address):
actual_checksum = get_checksum(address)
return actual_checksum == checksum
'''
Will ask the user for a yes or no
and returns True or False accordingly
'''
def yes_no_user_input():
while True:
yes_no = fetch_user_input('Enter Y for yes or N for no: ')
yes_no = yes_no.lower()
if yes_no == 'n' or yes_no == 'no':
return False
elif yes_no == 'y' or yes_no == 'yes':
return True
else:
pretty_print(
'Ups seems like you entered something'
'different then "Y" or "N" '
)
'''
Asks the user to enter a number
and will only accept the user input
if it's a valid number
'''
def numbers_user_input(prompt):
while True:
user_input = fetch_user_input(prompt)
number = user_input.isdigit()
if number:
return int(user_input)
elif not number:
pretty_print('You didn\'t enter a number', color='red')
'''
Creates a unique file name by taking the first
12 characters of the sha256 hash from a seed
'''
def create_file_name():
seed_hash = create_seed_hash(seed)
file_name = seed_hash[:12]
file_name += '.txt'
return file_name
'''
The login screen.
Will make sure that only a valid seed is entered
'''
def log_in():
pretty_print(
'\n\n\n------------------------------------------------'
'Account login---------------------------------------'
'-----------------'
'\n\nA seed should only contain the letters A-Z and 9.'
' Lowercase letters will automatically be converted to\n'
'uppercase and everything else that is not A-Z,'
' will be converted to a 9.',
color='green'
)
password = getpass.getpass('\n \nPlease enter your'
' seed to login to your account: '
)
raw_seed = unicode(password) if is_py2 else str(password)
raw_seed = raw_seed.upper()
raw_seed = list(raw_seed)
allowed = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ9')
seed = ''
i = 0
while i < len(raw_seed) and i < 81:
char = raw_seed[i]
if char not in allowed:
char = '9'
seed += char
else:
seed += str(char)
i += 1
while len(seed) < 81:
seed += '9'
pretty_print('\n\nThe Sha256 hash of your seed is:')
pretty_print(create_seed_hash(seed), color='blue')
pretty_print('Should the seed be displayed for review?\n', color='red')
yes = yes_no_user_input()
if yes:
pretty_print('You entered ' + seed + ' as seed.')
elif not yes:
pretty_print('OK, seed won\'t be displayed!', color='blue')
return seed
'''
If there is no account file for the entered seed,
ths function will ask the user for the node to connect to.
The node address is then saved in the account file
'''
def first_login_prompt(data):
pretty_print(
'\n\nSeems like its your first time logging in to this seed!\n'
'By default the wallet will connect'
' to testnet node http://bahamapascal-tn1.ddns.net:14200'
'(while in Beta)\n'
'Do you want to connect to another host?\n\n'
)
yes = yes_no_user_input()
if yes:
data['account_data'][0]['settings'][0]['host'] = fetch_user_input(
'\nPlease enter the host'
' you want to connect to: '
)
pretty_print(
'\nHost set to '
+ str(data['account_data'][0]['settings'][0]['host'])
+ '\n\n',
color='blue'
)
return data
else:
pretty_print('Okay, I won\'t change the host!\n\n')
return data
'''
Will try to open the account file.
In case the file doesn't exist it will create a new account file.
'''
def read_account_data():
try:
with open(file_name, 'r') as account_data:
data = json.load(account_data)
return data
except:
with open(file_name, 'w') as account_data:
data = {}
data['account_data'] = []
data['account_data'].append({
'settings': [{
'host': 'http://bahamapascal-tn1.ddns.net:14200',
'min_weight_magnitude': 14,
'units': 'i'
}],
'address_data': [],
'fal_balance': [{'f_index': 0, 'l_index': 0}],
'transfers_data': []
})
data = first_login_prompt(data)
json.dump(data, account_data)
pretty_print('Created new account file!', color='blue')
return data
'''
Settings menu where the user can set account specific settings.
The settings are saved in the account file
'''
def set_settings():
pretty_print('Enter "min_weight_magnitude" to set the minWeightMagnitude')
pretty_print(
'Enter "unit" to set the Units used'
' to display iota tokens (i,Ki,Mi,Gi,Ti)'
)
pretty_print('Enter "host" to set a new host to connect to')
pretty_print('Enter "current_settings" to see ')
pretty_print('Enter "back" to quit the settings menu\n\n')
stay_in_settings = True
while stay_in_settings:
user_command_input = fetch_user_input('Please enter a command: ')
if user_command_input == 'min_weight_magnitude':
settings[0]['min_weight_magnitude'] = \
numbers_user_input('\nPlease enter the minWeightMagnitude: ')
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
pretty_print(
'MinWeightMagnitude set to '
+ str(settings[0]['min_weight_magnitude'])
+ '\n\n',
color='blue'
)
elif user_command_input == 'unit':
units = fetch_user_input('\nPlease enter "i","ki","mi","gi" or "ti": ')
if units == 'i'\
or units == 'ki' \
or units == 'mi'\
or units == 'gi'\
or units == 'ti':
settings[0]['units'] = units
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
pretty_print(
'Units set to ' + str(settings[0]['units']) + '\n\n',
color='blue'
)
else:
pretty_print(
'\n\nUps you seemed to have'
' entered something else'
' then "i","ki","mi","gi" or "ti" ',
color='red'
)
pretty_print(
'Please try again!\n\n',
color='green'
)
elif user_command_input == 'host':
settings[0]['host'] = fetch_user_input(
'\nPlease enter the'
' host you want to connect to: '
)
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
pretty_print(
'Host set to ' + str(settings[0]['host']) + '\n\n',
color='blue'
)
elif user_command_input == 'current_settings':
min_weight_magnitude = settings[0]['min_weight_magnitude']
units = settings[0]['units']
host = settings[0]['host']
pretty_print(
'\n\nMinWeightMagnitude is currently set to '
+ str(min_weight_magnitude) + '\n' +
'Units are set to ' + str(units) + '\n' +
'Host is set to ' + str(host) + '\n\n',
color='blue'
)
elif user_command_input == 'back':
stay_in_settings = False
else:
pretty_print(
'Ups I didn\'t understand'
' that command. Please try again!',
color='red'
)
'''
Converts Iotas into the unit that is set
in the account settings and returns a string
'''
def convert_units(value):
unit = settings[0]['units']
value = float(value)
if unit == 'i':
value = str(int(value)) + 'i'
return value
elif unit == 'ki':
value = '{0:.3f}'.format(value/1000)
value = str(value + 'Ki')
return value
elif unit == 'mi':
value = '{0:.6f}'.format(value / 1000000)
value = str(value) + 'Mi'
return value
elif unit == 'gi':
value = '{0:.9f}'.format(value / 1000000000)
value = str(value + 'Gi')
return value
elif unit == 'ti':
value = '{0:.12f}'.format(value / 1000000000000)
value = str(value + 'Ti')
return value
'''
Takes a address (81 Characters) and
converts it to an address with checksum (90 Characters)
'''
def address_checksum(address):
address = get_decoded_string(address)
bytes_address = bytes(address) if is_py2 else bytes(address,'utf8')
addy = Address(bytes_address)
return str(addy.with_valid_checksum()) if is_py2 else bytes(addy.with_valid_checksum())
'''
Takes an address with checksum
and verifies if the address matches with the checksum
'''
def is_valid_address(address_with_checksum):
address = address_with_checksum[:81]
new_address_with_checksum = address_checksum(address)
if new_address_with_checksum == address_with_checksum:
return True
else:
return False
'''
Writes the index, address and balance,
as well as the checksum of address +
seed into the account file
'''
def write_address_data(index, address, balance):
address = address_checksum(address) if is_py2 else address_checksum(address.encode())
for p in address_data:
if p['address'] == address.decode():
p['balance'] = balance
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
return
checksum = get_checksum(address.decode())
raw_account_data['account_data'][0]['address_data'].append({
'index': index,
'address': address.decode(),
'balance': balance,
'checksum': checksum
})
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
'''
Takes the f_index and/or the l_index
and saves them in the account file.
"f_index" is the index of the first address with balance
and "l_index" is the index of the last address with balance
'''
def write_fal_balance(f_index=0, l_index=0):
if f_index > 0 and l_index > 0:
fal_balance[0]['f_index'] = f_index
fal_balance[0]['l_index'] = l_index
elif f_index > 0:
fal_balance[0]['f_index'] = f_index
elif l_index > 0:
fal_balance[0]['l_index'] = l_index
else:
return
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
'''
Writes data of an transaction to the account file
'''
def write_transfers_data(
transaction_hash,
is_confirmed,
timestamp,
tag,
address,
message,
value,
bundle,
short_transaction_id
):
for p in transfers_data:
if p['transaction_hash'] == transaction_hash:
if is_confirmed == p['is_confirmed']:
return
else:
p['is_confirmed'] = is_confirmed
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
return
raw_account_data['account_data'][0]['transfers_data'].append({
'transaction_hash': transaction_hash,
'is_confirmed': is_confirmed,
'timestamp': timestamp,
'tag': tag,
'address': address,
'message': message,
'value': value,
'bundle': bundle,
'short_transaction_id': short_transaction_id
})
with open(file_name, 'w') as account_data:
json.dump(raw_account_data, account_data)
'''
Updates the f_index and l_index
'''
def update_fal_balance():
index_with_value = []
for data in address_data:
if data['balance'] > 0:
index = data['index']
index_with_value.append(index)
if len(index_with_value) > 0:
f_index = min(index_with_value)
l_index = max(index_with_value)
write_fal_balance(f_index, l_index)
return
'''
Sends a request to the IOTA node
and gets the current confirmed balance
'''
def address_balance(address):
api = Iota(iota_node)
gna_result = api.get_balances([Address(address).address])
balance = gna_result['balances']
return balance[0]
'''
Checks all addresses that are saved
in the account file and updates there balance.
start_index can be set in order to ignore
all addresses before the start index
'''
def update_addresses_balance(start_index=0):
max_index = 0
for data in address_data:
index = data['index']
if start_index <= index:
address = str(data['address'])
balance = address_balance(address)
write_address_data(index, address, balance)
if max_index < index:
max_index = index
if max_index < start_index:
pretty_print(
'Start index was not found.'
' You should generate more addresses'
' or use a lower start index',
color='red'
)
'''
Generates one or more addresses
and saves them in the account file
'''
def generate_addresses(count):
index_list = [-1]
for data in address_data:
index = data['index']
index_list.append(index)
if max(index_list) == -1:
start_index = 0
else:
start_index = max(index_list) + 1
as_encoded = seed if is_py2 else seed.encode('utf-8')
generator = AddressGenerator(as_encoded)
'''
This is the actual function to generate the address.
'''
addresses = generator.get_addresses(start_index, count)
i = 0
while i < count:
index = start_index + i
address = addresses[i]
versionised_address = str(address) if is_py2 else bytes(address)
balance = address_balance(versionised_address) if is_py2 else address_balance(versionised_address)
write_address_data(index, versionised_address, balance) if is_py2 else write_address_data(index, versionised_address.decode(), balance)
i += 1
update_fal_balance()
'''
Will generate and scan X addresses of an seed
for balance. If there are already saved addresses in the ac-
count data, it will start with the next higher address index
'''
def find_balance(count):
max_gap = 3
margin = 4
i = 0
balance_found = False
pretty_print(
'Generating addresses'
' and checking for balance, please wait...\n',
)
while i < count and margin > 0:
pretty_print(
'Checking address '
+ str(i+1) + ' in range of '
+ str(count),
color='green'
)
generate_addresses(1)
index_list = []
for data in address_data:
index = data['index']
index_list.append(index)
max_index = max(index_list)
for data in address_data:
index = data['index']
balance = data['balance']
if index == max_index and balance > 0:
balance_found = True
address = data['address']
pretty_print(
'Balance found! \n' +
' Index: ' + str(index) + '\n' +
' Address: ' + str(address) + '\n' +
' Balance: ' + convert_units(balance) + '\n',
color='green'
)
margin = max_gap
if count - i <= max_gap:
count += max_gap
elif index == max_index and margin <= max_gap:
margin -= 1
i += 1
if not balance_found:
pretty_print('No address with balance found!', color='red')
'''
Gets the first address after the last address with balance.
If there is no saved address it will generate a new one
'''
def get_deposit_address():
try:
l_index = fal_balance[0]['l_index']
if l_index == 0:
deposit_address = address_data[0]['address']
return deposit_address
for p in address_data:
address = p['address']
checksum = p['checksum']
integrity = verify_checksum(checksum, address)
if p['index'] > l_index and integrity:
deposit_address = p['address']
return deposit_address
elif not integrity:
return 'Invalid checksum!!!'
pretty_print('Generating address...', color='blue')
generate_addresses(1)
for p in address_data:
address = p['address']
checksum = p['checksum']
integrity = verify_checksum(checksum, address)
if p['index'] > l_index and integrity:
deposit_address = p['address']
return deposit_address
except:
'An error acoured while trying to get the deposit address'
'''
Displays all saved addresses and there balance
'''
def full_account_info():
update_addresses_balance(fal_balance[0]['f_index'])
update_fal_balance()
if len(address_data) > 0:
all_address_data = ''
for p in address_data:
address = p['address']
checksum = p['checksum']
balance = int(p['balance'])
integrity = verify_checksum(checksum, address)
if integrity:
data = 'Index: ' + str(p['index']) + ' '\
+ p['address'] +\
' balance: ' +\
convert_units(balance) + '\n'
all_address_data += data
else:
data = 'Index: ' \
+ str(p['index']) +\
' Invalid Checksum!!!' + '\n'
all_address_data += data
pretty_print(all_address_data)
fal_data = 'First index with balance: ' + str(
fal_balance[0]['f_index']) +\
'\n' +\
'Last index with balance is: ' +\
str(fal_balance[0]['l_index'])
pretty_print(fal_data)
else:
pretty_print('No Data to display!', color='red')
'''
Displays all addresses with balance,
the total account balance and a deposit address.
In case that there are no saved addresses it
will ask if the account should be scanned for balance.
If the User answers with no, then it will
just generate a deposit address (at index 0)
'''
def standard_account_info():
address_count = len(address_data)
update_addresses_balance(fal_balance[0]['f_index'])
update_fal_balance()
if address_count < 1:
pretty_print(
'\n\nThis seems to be the first time '
'you are using this account with the CL wallet!\n'
'If you are expecting balance on this account'
' you should scan for balance.\n'
'Do you want to scan for balance?\n\n '
)
yes = yes_no_user_input()
if yes:
pretty_print(
'\n\nOkay great, I will generate addresses'
' and check them for balance!\n'
'Please tell me how many addresses'
' I should check. If you say 100\n'
'I will generate addresses until balance'
' is found or until 100 addresses\n'
'have been generated.\n'
'So, whats the maximum number of '
'addresses I should check?\n\n'
)
prompt = 'Please enter the max number of addresses to check: '
addresses_to_check = numbers_user_input(prompt)
if addresses_to_check > 0:
find_balance(addresses_to_check)
standard_account_info()
elif addresses_to_check == 0:
pretty_print('You entered 0! I won\'t check any addresses.', color='green')
elif not yes:
pretty_print(
'\nOkay, then I will just generate a deposit address.\n'
'In case you wan\'t to generate addresses'
' after that, you can use the \'find balance\' command.\n'
'Generating deposit address...\n\n\n'
)
generate_addresses(1)
standard_account_info()
return
elif address_count > 0:
all_address_data = ''
total_balance = 0
for p in address_data:
balance = p['balance']
address = p['address']
checksum = p['checksum']
integrity = verify_checksum(checksum, address)
if balance > 0 and integrity:
total_balance += balance
data = 'Index: ' \
+ str(p['index']) \
+ ' ' + address \
+ ' balance: ' \
+ convert_units(balance) \
+ '\n'
all_address_data += data
elif not integrity:
total_balance += balance
data = 'Index: ' \
+ str(p['index']) \
+ ' Invalid Checksum!!!' \
+ '\n'
all_address_data += data
if total_balance > 0:
pretty_print(all_address_data)
pretty_print('\n' + 'Deposit address: ' + str(get_deposit_address()), color='blue')
pretty_print('\nTotal Balance: ' + convert_units(total_balance))
else:
pretty_print('No addresses with balance!', color='red')
pretty_print('\n' + 'Deposit address: ' + str(get_deposit_address()), color='blue')
'''
Will ask the user to enter the amount and Units (Iota, MegaIota, GigaIota,etc.)
'''
def transfer_value_user_input(prepared_transferes):
pretty_print(
'\n\nEnter a number and the the unit size.\n'
'Avalaible units are \'i\'(Iota), '
'\'ki\'(KiloIota), \'mi\'(MegaIota), '
'\'gi\'(GigaIota) and \'ti\'(TerraIota)\n'
'Example: If you enter \'12.3 gi\', I will send 12.3 GigaIota\n'
)
update_addresses_balance(fal_balance[0]['f_index'])
update_fal_balance()
total_balance = 0
for p in address_data:
balance = int(p['balance'])
total_balance += balance
if len(prepared_transferes) > 0:
for txn in prepared_transferes:
value = int(txn.value)
total_balance -= value
ask_user = True
while ask_user:
user_input = fetch_user_input('Please enter the amount to send: ')
user_input = user_input.upper()
user_input_as_list = list(user_input)
allowed_characters = list('1234567890. IKMGT')
allowed_for_numbers = list('1234567890.')
allowed_for_units = list('iIkKmMgGtT')
is_valid = True
value = ''
unit = ''
i = 0
while i < len(user_input_as_list):
char = user_input_as_list[i]
if char in allowed_characters:
if char in allowed_for_numbers:
value += char
elif char in allowed_for_units:
unit += char
else:
is_valid = False
i += 1
if is_valid:
try:
value = float(value)
if unit == 'I':
value = value
if 1 > value > 0:
pretty_print(
'You entered a amount greater '
'then 0 but smaller then 1 Iota!\n'
'Can only send whole Iotas...\n ',
color='red'
)
elif value > total_balance:
avaliable_balance = convert_units(total_balance)
pretty_print(
'You do not have sufficient balance!\n'
'The avaliable Balance is: ' + avaliable_balance,
color='red'
)
else:
return int(value)
elif unit == 'KI':
value *= 1000
if 1 > value > 0:
pretty_print(
'You entered a amount greater '
'then 0 but smaller then 1 Iota!\n'
'Can only send whole Iotas...\n ',
color='red'
)
elif value > total_balance:
avaliable_balance = convert_units(total_balance)
pretty_print(
'You do not have sufficient balance!\n'
'The avaliable Balance is: ' + avaliable_balance,
color='red'
)
else:
return int(value)
elif unit == 'MI':
value *= 1000000
if 1 > value > 0:
pretty_print(
'You entered a amount greater then 0 '
'but smaller then 1 Iota!\n'
'Can only send whole Iotas...\n ',
color='red'
)
elif value > total_balance:
avaliable_balance = convert_units(total_balance)
pretty_print(
'You do not have sufficient balance!\n'
'The avaliable Balance is: ' + avaliable_balance,
color='red'
)
else:
return int(value)
elif unit == 'GI':
value *= 1000000000
if 1 > value > 0:
pretty_print(
'You entered a amount greater then 0 '
'but smaller then 1 Iota!\n'
'Can only send whole Iotas...\n ',
color='red'
)
elif value > total_balance:
avaliable_balance = convert_units(total_balance)
pretty_print(
'You do not have sufficient balance!\n'
'The avaliable Balance is: ' + avaliable_balance,
color='red'
)
else:
return int(value)
elif unit == 'TI':
value *= 1000000000000
if 1 > value > 0:
pretty_print(
'You entered a amount greater then 0 '
'but smaller then 1 Iota!\n'
'Can only send whole Iotas...\n ',
color='red'
)
elif value > total_balance:
avaliable_balance = convert_units(total_balance)
pretty_print(
'You do not have sufficient balance!\n'
'The avaliable Balance is: ' + avaliable_balance,
color='red'
)
else:
return int(value)
else:
pretty_print(
'You didn\'t enter a valid '
'unit size! Please try again\n',
color='red'
)
except:
pretty_print(
'You didn\'t enter a valid '
'value! Please try again\n',
color='red'
)
else:
pretty_print(
'You didn\'t enter a valid '
'value! Please try again\n',
color='red'
)
'''
Gets all necessary data from the user to make one or more transfers
'''
def prepare_transferes():
new_transfer = True
prepared_transferes = []
while new_transfer:
get_recipient_address = True
while get_recipient_address:
recipient_address = fetch_user_input('\nPlease enter '
'the receiving address: ')
if len(recipient_address) == 81:
pretty_print(
'You entered a address without checksum. '
'Are you sure you want to continue?',
color='blue'
)
yes = yes_no_user_input()
if yes:
get_recipient_address = False
else:
pretty_print(
'Good choice! '
'Addresses with checksum are a lot safer to use.'
)
elif len(recipient_address) == 90:
is_valid = is_valid_address(recipient_address )if is_py2 else is_valid_address(recipient_address.encode())
if is_valid:
get_recipient_address = False
else:
pretty_print('Invalid address!! Please try again!', color='red')
else:
pretty_print(
'\nYou entered a invalid address. '
'Address must be 81 or 90 Char long!',