2020
2121from tronapi .exceptions import InvalidTronError , TronError
2222from tronapi .manager import TronManager
23- from tronapi import HttpProvider
23+ from tronapi import HttpProvider , constants
2424from tronapi .transactionbuilder import TransactionBuilder
2525from tronapi .trx import Trx
2626from tronapi .base .validation import is_address
@@ -39,6 +39,7 @@ class Tron:
3939
4040 _default_block = None
4141 _private_key = None
42+ _default_address = AttributeDict ({})
4243
4344 # Encoding and Decoding
4445 toBytes = staticmethod (to_bytes )
@@ -53,12 +54,7 @@ class Tron:
5354 # Validate address
5455 isAddress = staticmethod (is_address )
5556
56- def __init__ (self ,
57- full_node : Union [str , HttpProvider ],
58- solidity_node : Union [str , HttpProvider ],
59- event_server : Union [str , HttpProvider ]= None ,
60- private_key : str = None ,
61- modules : Any = None ):
57+ def __init__ (self , ** kwargs ):
6258 """Connect to the Tron network.
6359
6460 Args:
@@ -69,26 +65,29 @@ def __init__(self,
6965
7066 """
7167
72- self ._default_address = AttributeDict ({})
68+ # We check the obtained nodes, if the necessary parameters
69+ # are not specified, then we take the default
70+ kwargs .setdefault ('full_node' , constants .DEFAULT_FULL_NODE )
71+ kwargs .setdefault ('solidity_node' , constants .DEFAULT_SOLIDITY_NODE )
72+ kwargs .setdefault ('event_server' , constants .DEFAULT_EVENT_SERVER )
7373
7474 # The node manager allows you to automatically determine the node
7575 # on the router or manually refer to a specific node.
7676 # solidity_node, full_node or event_server
7777 self .manager = TronManager (self , dict (
78- full_node = full_node ,
79- solidity_node = solidity_node ,
80- event_server = event_server
78+ full_node = kwargs . get ( ' full_node' ) ,
79+ solidity_node = kwargs . get ( ' solidity_node' ) ,
80+ event_server = kwargs . get ( ' event_server' )
8181 ))
8282
8383 # If the parameter of the private key is not empty,
8484 # then write to the variable
85- if private_key is not None :
86- self .private_key = private_key
85+ if ' private_key' in kwargs :
86+ self .private_key = kwargs . get ( ' private_key' )
8787
8888 # If custom methods are not declared,
8989 # we take the default from the list
90- if modules is None :
91- modules = DEFAULT_MODULES
90+ modules = kwargs .setdefault ('modules' , DEFAULT_MODULES )
9291
9392 for module_name , module_class in modules .items ():
9493 module_class .attach (self , module_name )
0 commit comments