1919import math
2020
2121from tronapi .abstract import TronBase
22- from tronapi .exceptions import InvalidTronError
22+ from tronapi .exceptions import InvalidTronError , TronError
2323from tronapi import utils
2424
2525
@@ -40,16 +40,16 @@ def get_event_result(self, contract_address=None, since=0, event_name=None, bloc
4040 """
4141
4242 if not self .event_server :
43- raise Exception ('No event server configured' )
43+ raise TronError ('No event server configured' )
4444
4545 if not self .is_address (contract_address ):
4646 raise InvalidTronError ('Invalid contract address provided' )
4747
4848 if event_name and not contract_address :
49- raise Exception ('Usage of event name filtering requires a contract address' )
49+ raise TronError ('Usage of event name filtering requires a contract address' )
5050
5151 if block_number and not event_name :
52- raise Exception ('Usage of block number filtering requires an event name' )
52+ raise TronError ('Usage of block number filtering requires an event name' )
5353
5454 route_params = []
5555
@@ -77,7 +77,7 @@ def get_event_transaction_id(self, tx_id):
7777 """
7878
7979 if not self .event_server :
80- raise Exception ('No event server configured' )
80+ raise TronError ('No event server configured' )
8181
8282 response = self .event_server .request ('/event/transaction/' + tx_id )
8383 return response
@@ -98,7 +98,7 @@ def get_block(self, block=None):
9898
9999 """
100100 if block is None :
101- raise Exception ('No block identifier provided' )
101+ raise TronError ('No block identifier provided' )
102102
103103 if block == 'latest' :
104104 return self .get_current_block ()
@@ -149,7 +149,7 @@ def get_block_transaction_count(self, block=None):
149149 transaction = self .get_block (block )
150150
151151 if 'transactions' not in transaction :
152- raise Exception ('Parameter "transactions" not found' )
152+ raise TronError ('Parameter "transactions" not found' )
153153
154154 if transaction is None :
155155 return 0
@@ -170,7 +170,7 @@ def get_transaction_from_block(self, block=None, index=0):
170170 transactions = self .get_block (block )['transactions' ]
171171
172172 if not transactions or len (transactions ) < index :
173- raise Exception ('Transaction not found in block' )
173+ raise TronError ('Transaction not found in block' )
174174
175175 return transactions [index ]
176176
@@ -186,7 +186,7 @@ def get_transaction(self, transaction_id):
186186 }, 'post' )
187187
188188 if not response :
189- raise Exception ('Transaction not found' )
189+ raise TronError ('Transaction not found' )
190190
191191 return response
192192
@@ -406,7 +406,7 @@ def send_transaction(self, from_address, to_address, amount):
406406
407407 """
408408 if not self .private_key :
409- raise Exception ('Missing private key' )
409+ raise TronError ('Missing private key' )
410410
411411 if not self .is_address (to_address ):
412412 raise InvalidTronError ('Invalid address provided' )
@@ -441,7 +441,7 @@ def _create_transaction(self, from_address, to_address, amount):
441441 _from = self .to_hex (from_address )
442442
443443 if _to == _from :
444- raise Exception ('Cannot transfer TRX to the same account' )
444+ raise TronError ('Cannot transfer TRX to the same account' )
445445
446446 return self .full_node .request ('/wallet/createtransaction' , {
447447 'to_address' : _to ,
@@ -461,7 +461,7 @@ def _sign_transaction(self, transaction):
461461
462462 """
463463 if 'signature' in transaction :
464- raise Exception ('Transaction is already signed' )
464+ raise TronError ('Transaction is already signed' )
465465
466466 return self .full_node .request ('/wallet/gettransactionsign' , {
467467 'transaction' : transaction ,
@@ -482,7 +482,7 @@ def _send_raw_transaction(self, signed):
482482 raise InvalidTronError ('Invalid transaction provided' )
483483
484484 if 'signature' not in signed :
485- raise Exception ('Transaction is not signed' )
485+ raise TronError ('Transaction is not signed' )
486486
487487 return self .full_node .request ('/wallet/broadcasttransaction' , signed , 'post' )
488488
0 commit comments