1111
1212from tronapi .base .account import Account , PrivateKey
1313from tronapi .base .datastructures import AttributeDict
14- from tronapi .base .decorators import deprecated_for
1514from tronapi .base .encoding import (
1615 to_bytes ,
1716 to_int ,
2423from tronapi .transactionbuilder import TransactionBuilder
2524from tronapi .trx import Trx
2625from tronapi .base .validation import is_address
27- from tronapi .utils .crypto import keccak as tron_keccak
26+ from tronapi .utils .crypto import keccak
2827from tronapi .utils .currency import to_sun , from_sun
2928from tronapi .utils .types import is_integer
3029
3433
3534
3635class Tron :
36+ # Providers
37+ HTTPProvider = HttpProvider
38+
3739 _default_block = None
3840 _private_key = None
3941
@@ -51,7 +53,9 @@ class Tron:
5153 isAddress = staticmethod (is_address )
5254
5355 def __init__ (self , full_node , solidity_node ,
54- event_server = None , private_key = None ):
56+ event_server = None ,
57+ private_key = None ,
58+ modules = None ):
5559 """Connect to the Tron network.
5660
5761 Args:
@@ -73,10 +77,17 @@ def __init__(self, full_node, solidity_node,
7377 event_server = event_server
7478 ))
7579
80+ # If the parameter of the private key is not empty,
81+ # then write to the variable
7682 if private_key is not None :
7783 self .private_key = private_key
7884
79- for module_name , module_class in DEFAULT_MODULES .items ():
85+ # If custom methods are not declared,
86+ # we take the default from the list
87+ if modules is None :
88+ modules = DEFAULT_MODULES
89+
90+ for module_name , module_class in modules .items ():
8091 module_class .attach (self , module_name )
8192
8293 self .transaction = TransactionBuilder (self )
@@ -230,27 +241,18 @@ def is_valid_provider(provider) -> bool:
230241 return isinstance (provider , HttpProvider )
231242
232243 @staticmethod
233- @deprecated_for ("keccak" )
234244 @apply_to_return_value (HexBytes )
235245 def sha3 (primitive = None , text = None , hexstr = None ):
236- """Returns the Keccak SHA256 of the given value.
237- Text is encoded to UTF-8 before computing the hash, just like Solidity.
238- Any of the following are valid and equivalent:
239- """
240- return Tron .keccak (primitive , text , hexstr )
241-
242- @staticmethod
243- @apply_to_return_value (HexBytes )
244- def keccak (primitive = None , text = None , hexstr = None ):
245246 if isinstance (primitive , (bytes , int , type (None ))):
246247 input_bytes = to_bytes (primitive , hexstr = hexstr , text = text )
247- return tron_keccak (input_bytes )
248+ return keccak (input_bytes )
248249
249250 raise TypeError (
250- "You called keccak with first arg %r and keywords %r. You must call it with one of "
251- "these approaches: keccak(text='txt'), keccak(hexstr='0x747874'), "
252- "keccak(b'\\ x74\\ x78\\ x74'), or keccak(0x747874)." % (
253- primitive , {'text' : text , 'hexstr' : hexstr }
251+ "You called sha3 with first arg %r and keywords %r. You must call it with one of "
252+ "these approaches: sha3(text='txt'), sha3(hexstr='0x747874'), "
253+ "sha3(b'\\ x74\\ x78\\ x74'), or sha3(0x747874)." % (
254+ primitive ,
255+ {'text' : text , 'hexstr' : hexstr }
254256 )
255257 )
256258
0 commit comments