Skip to content

Commit 317d4e4

Browse files
committed
Changed provider connection scheme
1 parent 71958a2 commit 317d4e4

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

tronapi/main.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from tronapi.exceptions import InvalidTronError, TronError
2222
from tronapi.manager import TronManager
23-
from tronapi import HttpProvider
23+
from tronapi import HttpProvider, constants
2424
from tronapi.transactionbuilder import TransactionBuilder
2525
from tronapi.trx import Trx
2626
from 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)

tronapi/trx.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,17 @@ def get_transaction_from_block(self, block: Any, index: int = 0):
8989

9090
return transactions[index]
9191

92-
def get_transaction(self, transaction_id):
92+
def get_transaction(self, transaction_id: str,
93+
is_confirm: bool = False):
9394
"""Query transaction based on id
9495
9596
Args:
9697
transaction_id (str): transaction id
97-
98+
is_confirm (bool):
9899
"""
99100

100-
response = self.tron.manager.request('/wallet/gettransactionbyid', {
101+
method = 'walletsolidity' if is_confirm else 'wallet'
102+
response = self.tron.manager.request('/{}/gettransactionbyid'.format(method), {
101103
'value': transaction_id
102104
})
103105

0 commit comments

Comments
 (0)