2
2
import os
3
3
from datetime import datetime
4
4
from web3 .exceptions import TransactionNotFound
5
+ from requests .exceptions import MissingSchema
5
6
6
7
import eth_utils
7
8
from cryptography .fernet import Fernet , InvalidToken
21
22
config_file ,
22
23
address ,
23
24
network ,
24
- ens_resolver
25
+ ens_mainnet_address ,
26
+ ens_resolver ,
27
+ logs
25
28
)
26
29
from eth_account import Account
30
+ from TheLootBoxWallet .code .custom_logs import logger
27
31
28
32
index_blueprint = Blueprint ('index_blueprint' , __name__ )
29
33
create_account_blueprint = Blueprint ('create_account_blueprint' , __name__ )
@@ -165,8 +169,8 @@ def save_account_info(pub_address, mnemonic_phrase, private_key, account_id):
165
169
'private_key' : str (private_key .decode ("utf-8" )),
166
170
'mnemonic_phrase' : str (mnemonic_phrase .decode ("utf-8" ))}
167
171
accounts_list .append (account_info )
168
- json . dump ( accounts_list , open (__location__ + accounts_file , 'w' ))
169
-
172
+ with open (__location__ + accounts_file , 'w' ):
173
+ json . dump ( accounts_list , open ( __location__ + accounts_file , 'w' ))
170
174
171
175
def populate_public_address_list ():
172
176
public_address_list = []
@@ -180,10 +184,16 @@ def populate_public_address_list():
180
184
return public_address_list
181
185
182
186
def get_ens_name (default_address ):
183
- domain = ens_resolver .name (default_address )
184
- if domain == None :
185
- domain = "No ENS name associated with this address."
186
- return domain
187
+ try :
188
+ if ens_mainnet_address != "" :
189
+ domain = ens_resolver .name (default_address )
190
+ if domain == None :
191
+ domain = "No ENS name associated with this address."
192
+ else :
193
+ domain = None
194
+ except MissingSchema :
195
+ flash (f"No ENS name associated with this address." , 'warning' )
196
+
187
197
188
198
@account_blueprint .route ('/account' , methods = ['GET' , 'POST' ])
189
199
def account ():
@@ -211,7 +221,8 @@ def account():
211
221
default_address : str = get_pub_address_from_config ()
212
222
ens_name : str = get_ens_name (default_address )
213
223
wei_balance = network .eth .get_balance (default_address )
214
- except (InvalidSignature , InvalidToken , ValueError ):
224
+ except (InvalidSignature , InvalidToken , ValueError ) as e :
225
+ print (e )
215
226
flash ("Invalid account key." , 'warning' )
216
227
return render_template ('unlock.html' , account = "current" , unlock_account_form = unlock_account_form , year = year )
217
228
else :
@@ -297,27 +308,30 @@ def send():
297
308
@send_transaction_blueprint .route ('/send_transaction' , methods = ['POST' ])
298
309
def send_transaction ():
299
310
if request .method == 'POST' and unlocked :
311
+ lookup_account_form = LookupAccountForm ()
312
+ replay_transaction_form = ReplayTransactionForm ()
313
+ default_address : str = get_pub_address_from_config ()
314
+ wei_balance = network .eth .get_balance (default_address )
300
315
to_account = request .form ['to_public_address' ]
301
316
amount = request .form ['amount_of_ether' ]
302
317
try :
303
318
tx = {
304
- 'nonce' : network .eth .get_transaction_count (pub_address , 'pending' ),
319
+ 'nonce' : network .eth .get_transaction_count (default_address , 'pending' ),
305
320
'to' : to_account ,
306
321
'value' : network .to_wei (amount , 'ether' ),
307
322
'gas' : network .to_wei ('0.03' , 'gwei' ),
308
323
'gasPrice' : gas_price ,
309
- 'from' : pub_address
324
+ 'from' : default_address
310
325
}
311
326
sign = network .eth .account .sign_transaction (tx , unlocked_account [1 ])
312
- network .eth .send_raw_transaction (sign .rawTransaction )
313
-
327
+ sent_transaction = network .eth .send_raw_transaction (sign .rawTransaction )
328
+ if logs :
329
+ logger .info (bytes (sent_transaction .hex (), encoding = 'utf8' ))
314
330
flash ('Transaction sent successfully!' , 'success' )
315
331
except Exception as e :
332
+ if logs :
333
+ logger .debug (e )
316
334
flash (e , 'warning' )
317
- lookup_account_form = LookupAccountForm ()
318
- replay_transaction_form = ReplayTransactionForm ()
319
- default_address : str = get_pub_address_from_config ()
320
- wei_balance = network .eth .get_balance (default_address )
321
335
return render_template ('account.html' , account = "unlocked" , pub_address = default_address ,
322
336
private_key = unlocked_account [1 ], mnemonic_phrase = unlocked_account [2 ],
323
337
account_list = populate_public_address_list (), lookup_account_form = lookup_account_form , replay_transaction_form = replay_transaction_form ,
0 commit comments