-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompts.py
373 lines (297 loc) · 12.4 KB
/
prompts.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
from time import sleep
from pyparsing import ParseExpression
import vars
from decorators import *
from helpers import *
from account_manager import DuplicatePrivateKeyException, PrivateKeyNotFoundException, NotEnoughAccountsException
from mint_manager import Web3ProviderURLNotValid, ContractABINotRightException, MinterClassNotRightException
@add_margin
def main_prompt(clear=False, msg=""):
if clear:
os.system('cls' if os.name == 'nt' else 'clear')
my_print("1. Start minting\n2. Configure\n3. Create batch account\n4. Share coins between accounts\n5. Gather coins on an account")
if msg != "":
my_print(msg)
is_int, answer = get_int_answer()
if not validate_number_selection(5, answer):
return main_prompt(True, "\nChoose 1 or 2.")
elif answer == 1:
vars.mint_manager.start_minting(vars.acc_manager)
elif answer == 2:
return configure_prompt()
elif answer == 3:
return create_account_prompt()
elif answer == 4:
return share_coin_prompt()
elif answer == 5:
return gather_coin_prompt()
@clear_on_entry
def configure_prompt(msg=""):
my_print("1. Add accounts\n2. Remove accounts\n3. List accounts\n4. Set web3 provider url\n5. Set contract address\n6. Set contract abi path\n7. Set minter file\n8. Select number of accs. to use\n9. Go back to the main menu")
if msg != "":
my_print(msg)
is_int, answer = get_int_answer()
if not is_int or not validate_number_selection(9, answer):
return configure_prompt("\nChoose [1-9]")
elif answer == 1:
return add_accounts_prompt()
elif answer == 2:
return remove_accounts_prompt()
elif answer == 3:
return list_accounts_prompt()
elif answer == 4:
return set_provider_url_prompt()
elif answer == 5:
return set_contract_address_prompt()
elif answer == 6:
return set_contract_abi_path_prompt()
elif answer == 7:
return select_minter_file_prompt()
elif answer == 8:
return select_no_of_accs_to_use_prompt()
elif answer == 9:
return main_prompt(True)
@clear_on_entry
def set_provider_url_prompt(msg=""):
my_print("Enter web3 provider url. Type stop to go back to the config page.")
if msg != "":
my_print(msg)
answer = input("> ")
if answer == "stop":
return configure_prompt()
else:
try:
vars.mint_manager.set_web3_provider_url(answer, True)
vars.acc_manager.set_web3_provider_url(answer, False) # TODO: maybe use a web3_manager?
except Web3ProviderURLNotValid:
return set_provider_url_prompt("URL not in proper form (https://example.com/asdfg")
else:
my_print("Set web3 provider url successfully.")
sleep(1.5)
return configure_prompt()
@clear_on_entry
def set_contract_address_prompt():
my_print("Enter contract address. Type stop to go back to the config page.")
answer = input("> ")
if answer == "stop":
return configure_prompt()
else:
vars.mint_manager.set_contract_address(answer)
my_print("\nContract address set successfully.")
sleep(1.5)
return configure_prompt()
@clear_on_entry
def set_contract_abi_path_prompt(msg=""):
my_print("Enter ABI (relative) path. Type stop to go back to the config page.")
if msg != "":
my_print(msg)
answer = input("> ")
if answer == "stop":
return configure_prompt()
else:
try:
vars.mint_manager.set_contract_abi_path(answer)
except ContractABINotRightException:
return set_contract_abi_path_prompt("ABI file not valid. Extension must be .json")
else:
my_print("Set contract abi path successfully!")
sleep(1.5)
return configure_prompt()
@clear_on_entry
def add_accounts_prompt(msg=""):
if msg != "":
my_print(msg)
my_print("Enter private key. Type stop to go back to the config page.")
answer = input("> ")
if answer == "stop":
return configure_prompt()
else:
try:
vars.acc_manager.add_private_key(answer)
except DuplicatePrivateKeyException:
return add_accounts_prompt("Account already added!")
else:
return add_accounts_prompt("Account added successfully!")
@clear_on_entry
def remove_accounts_prompt(msg="", msg_type=0): # 0 for err message. 1 for success message
if msg_type == 1 and msg != "":
my_print(msg)
accounts = vars.acc_manager.get_account_list()
no_accounts = len(accounts)
for index, acc in enumerate(accounts):
my_print(f"{index + 1}. {vars.acc_manager.get_address(acc)}")
my_print("Choose the account to delete: (Type stop to go back to the config page.)")
if msg_type == 0 and msg != "":
my_print(msg)
is_int, answer = get_int_answer()
if (not is_int and answer != "stop"):
return remove_accounts_prompt(f"\nChoose [1-{no_accounts}]", 0)
elif answer == "stop":
return configure_prompt()
elif is_int and validate_number_selection(no_accounts, answer):
vars.acc_manager.remove_private_key(accounts[answer - 1]) # highly inefficient, but I don't think I'll use this bot with more than 10 accounts.
return remove_accounts_prompt("Account removed successfully!\n", 1)
@clear_on_entry
def list_accounts_prompt(): # TODO: add balances and such
accounts = vars.acc_manager.get_account_list()
for index, acc in enumerate(accounts):
address = vars.acc_manager.get_address(acc)
balance = vars.acc_manager.get_balance(address)
my_print(f"{index + 1}. {address} {balance}")
my_print(f"\nType anything to go back to the config page.")
input("> ")
return configure_prompt()
@clear_on_entry
def select_minter_file_prompt(msg=""):
my_print("Enter minter file name without the .py extension (e.g. minters.example_minter). Type stop to go back to the config page.")
if msg != "":
my_print(msg)
answer = input("> ")
if answer == "stop":
return configure_prompt()
else:
try:
vars.mint_manager.set_mint_file(answer)
except MinterClassNotRightException:
return select_minter_file_prompt("\nChildMinter class is not written correctly! See minter.py")
else:
my_print("Minter file set successfully!")
sleep(1.5)
return configure_prompt()
@clear_on_entry
def select_no_of_accs_to_use_prompt(msg=""):
cur_no_accs = vars.acc_manager.get_no_of_accounts_to_use()
accs_len = len(vars.acc_manager.get_account_list())
my_print(f"Minotaur the Mintoor currently uses {cur_no_accs} accounts.\nNo. of accounts registered: {accs_len}\nType stop to go back to the configure page or type a number to choose number of accounts to use.")
if msg != "":
my_print(msg)
is_int, answer = get_int_answer()
if not is_int and answer != "stop":
return select_no_of_accs_to_use_prompt("\nEither type a number or type stop.")
elif is_int:
try:
vars.acc_manager.set_no_of_accounts_to_use(answer)
my_print("Set no. of accounts to use successfully!")
sleep(1.5)
return configure_prompt()
except NotEnoughAccountsException:
return select_no_of_accs_to_use_prompt("\nDon't have that many accounts.")
elif answer == "stop":
return configure_prompt()
@clear_on_entry
def create_account_prompt(msg=""):
my_print("How many accounts do you want to create? Type stop to go back to the main menu.")
if msg != "":
my_print(msg)
is_int, answer = get_int_answer()
if not is_int:
if answer == "stop":
return main_prompt(True)
else:
return create_account_prompt("\nEnter a number!")
else:
for i in range(answer):
vars.acc_manager.create_new_account()
my_print("Accounts created successfully!")
sleep(1.5)
return main_prompt(True)
@clear_on_entry
def share_coin_prompt(msg="", sender_selection = None, min_amount=None):
my_print("Current state of accounts:")
account_to_balance = {}
accounts = vars.acc_manager.get_account_list()
for index, acc in enumerate(accounts):
address = vars.acc_manager.get_address(acc)
balance = vars.acc_manager.get_balance(address)
account_to_balance[acc] = balance
my_print(f"{index + 1}. {address} {balance}")
if sender_selection is None:
my_print("Select account to send coins from. (Type stop to go back to the main prompt.)")
if msg != "":
my_print(msg)
msg = ""
is_int, answer = get_int_answer()
if not is_int and answer == "stop":
return main_prompt(True)
elif validate_number_selection(len(accounts), answer):
sender_selection = answer
else:
return share_coin_prompt(f"\nChoose [1-{len(accounts)}]")
if min_amount is None:
my_print("Minimum amount of coins in an account after sharing: (Type stop to go back to the main prompt.)")
if msg != "":
my_print(msg)
msg = ""
answer = ""
try:
answer = input("> ")
min_amount = float(answer)
except:
if answer == "stop":
return main_prompt(True)
else:
return share_coin_prompt("\nEnter a number (use 1.2 format)", sender_selection)
else:
if min_amount == 0:
return share_coin_prompt("\nEnter number bigger than 0.", sender_selection)
to_send = [] # [[acc1, balance1], [acc2, balance2]]
sender_priv_key = accounts[sender_selection - 1]
for key, value in account_to_balance.items():
if float(value) < min_amount:
to_send.append([vars.acc_manager.get_address(key), min_amount - float(value)])
sum = 0
for send_info in to_send:
sum += send_info[1]
if account_to_balance[sender_priv_key] < sum:
return share_coin_prompt("\nSender account doesn't have sufficient balance. Start over!", None, None)
# SEND HERE
for send_info in to_send:
address = send_info[0]
amount = send_info[1]
vars.acc_manager.send_coin(sender_priv_key, address, amount)
my_print("Coins shared successfully!")
sleep(1.5)
return main_prompt(True)
@clear_on_entry
def gather_coin_prompt(msg=""):
my_print("Current state of accounts:")
web3: Web3 = vars.acc_manager.web3
account_to_balance = {}
accounts = vars.acc_manager.get_account_list()
for index, acc in enumerate(accounts):
address = vars.acc_manager.get_address(acc)
balance = web3.eth.get_balance(address)
account_to_balance[acc] = balance
my_print(f"{index + 1}. {address} { web3.fromWei(balance, 'ether') }")
receiver_selection = None
my_print("Select account that'll receive coins. (Type stop to go back to the main prompt.)")
if msg != "":
my_print(msg)
msg = ""
is_int, answer = get_int_answer()
if not is_int and answer == "stop":
return main_prompt(True)
elif validate_number_selection(len(accounts), answer):
receiver_selection = answer - 1
else:
return gather_coin_prompt(f"\nChoose [1-{len(accounts)}]")
total_send_cost = web3.toWei(21000*26, "gwei") # 26 gas costs * 21000 gas
receiver_address = vars.acc_manager.get_address(accounts[receiver_selection])
for index, acc in enumerate(accounts):
if index != receiver_selection:
if account_to_balance[acc] > 0:
address = vars.acc_manager.get_address(acc)
tx = {
'nonce': web3.eth.get_transaction_count(address),
'to': receiver_address,
'value': account_to_balance[acc] - total_send_cost,
'gasPrice': web3.toWei(26, "gwei"),
'from': address,
'gas': 21000,
'chainId': web3.eth.chain_id
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key=acc)
web3.eth.send_raw_transaction(signed_tx.rawTransaction)
my_print("Coins gathered successfully!")
sleep(1.5)
return main_prompt(True)