Skip to content

Commit 311af05

Browse files
committed
update
1 parent afa0b56 commit 311af05

File tree

2 files changed

+67
-15
lines changed

2 files changed

+67
-15
lines changed

tronapi/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
# Licensed under the MIT License.
55
# See License.txt in the project root for license information.
66
# --------------------------------------------------------------------
7-
from typing import Union, Any
7+
8+
"""
9+
tronapi.main
10+
===============
11+
12+
Connect to the Tron network.
13+
14+
:copyright: © 2018 by the iEXBase.
15+
:license: MIT License
16+
"""
17+
818

919
import ecdsa
1020
from eth_utils import apply_to_return_value, to_hex
@@ -58,10 +68,8 @@ def __init__(self, **kwargs):
5868
"""Connect to the Tron network.
5969
6070
Args:
61-
full_node (Any): A provider connected to a valid full node
62-
solidity_node (Any): A provider connected to a valid solidity node
63-
event_server (Any): Optional for smart contract events. Expects a valid event server URL
64-
private_key (str): Optional default private key used when signing transactions
71+
kwargs (Any): We fill the most necessary parameters
72+
for working with blockchain Tron
6573
6674
"""
6775

@@ -85,14 +93,18 @@ def __init__(self, **kwargs):
8593
if 'private_key' in kwargs:
8694
self.private_key = kwargs.get('private_key')
8795

96+
# We check whether the default wallet address is set when
97+
# defining the class, and then written to the variable
98+
if 'default_address' in kwargs:
99+
self.default_address = kwargs.get('default_address')
100+
88101
# If custom methods are not declared,
89102
# we take the default from the list
90103
modules = kwargs.setdefault('modules', DEFAULT_MODULES)
91-
92104
for module_name, module_class in modules.items():
93105
module_class.attach(self, module_name)
94106

95-
self.transaction = TransactionBuilder(self)
107+
self.transaction_builder = TransactionBuilder(self)
96108

97109
@property
98110
def default_block(self):

tronapi/trx.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# See License.txt in the project root for license information.
55
# --------------------------------------------------------------------
66

7+
"""
8+
tronapi.trx
9+
===============
10+
11+
Work with basic methods
12+
13+
:copyright: © 2018 by the iEXBase.
14+
:license: MIT License
15+
"""
16+
717
import math
818
from typing import Any
919

@@ -321,7 +331,11 @@ def send_transaction(self, to, amount, options=None):
321331
if 'from' not in options:
322332
options = assoc(options, 'from', self.tron.default_address.hex)
323333

324-
tx = self.tron.transaction.send_transaction(to, amount, options['from'])
334+
tx = self.tron.transaction_builder.send_transaction(
335+
to,
336+
amount,
337+
options['from']
338+
)
325339
# If a comment is attached to the transaction,
326340
# in this case adding to the object
327341
if 'message' in options:
@@ -348,7 +362,12 @@ def send_token(self, to, amount, token_id=None, account=None):
348362
if account is None:
349363
account = self.tron.default_address.hex
350364

351-
tx = self.tron.transaction.send_token(to, amount, token_id, account)
365+
tx = self.tron.transaction_builder.send_token(
366+
to,
367+
amount,
368+
token_id,
369+
account
370+
)
352371
sign = self.sign(tx)
353372
result = self.broadcast(sign)
354373

@@ -371,7 +390,12 @@ def freeze_balance(self, amount=0, duration=3, resource='BANDWIDTH', account=Non
371390
if account is None:
372391
account = self.tron.default_address.hex
373392

374-
transaction = self.tron.transaction.freeze_balance(amount, duration, resource, account)
393+
transaction = self.tron.transaction_builder.freeze_balance(
394+
amount,
395+
duration,
396+
resource,
397+
account
398+
)
375399
sign = self.sign(transaction)
376400
response = self.broadcast(sign)
377401

@@ -391,7 +415,10 @@ def unfreeze_balance(self, resource='BANDWIDTH', account=None):
391415
if account is None:
392416
account = self.tron.default_address.hex
393417

394-
transaction = self.tron.transaction.unfreeze_balance(resource, account)
418+
transaction = self.tron.transaction_builder.unfreeze_balance(
419+
resource,
420+
account
421+
)
395422
sign = self.sign(transaction)
396423
response = self.broadcast(sign)
397424

@@ -499,7 +526,10 @@ def update_account(self, account_name, address=None):
499526
if address is None:
500527
address = self.tron.default_address.hex
501528

502-
transaction = self.tron.transaction.update_account(account_name, address)
529+
transaction = self.tron.transaction_builder.update_account(
530+
account_name,
531+
address
532+
)
503533
sign = self.sign(transaction)
504534
response = self.broadcast(sign)
505535

@@ -518,7 +548,10 @@ def apply_for_sr(self, url, address):
518548
if address is None:
519549
address = self.tron.default_address.hex
520550

521-
transaction = self.tron.transaction.apply_for_sr(url, address)
551+
transaction = self.tron.transaction_builder.apply_for_sr(
552+
url,
553+
address
554+
)
522555
sign = self.sign(transaction)
523556
response = self.broadcast(sign)
524557

@@ -755,7 +788,11 @@ def vote_proposal(self, proposal_id, has_approval, voter_address):
755788
if voter_address is None:
756789
voter_address = self.tron.default_address.hex
757790

758-
transaction = self.tron.transaction.vote_proposal(proposal_id, has_approval, voter_address)
791+
transaction = self.tron.transaction_builder.vote_proposal(
792+
proposal_id,
793+
has_approval,
794+
voter_address
795+
)
759796
sign = self.sign(transaction)
760797
response = self.broadcast(sign)
761798

@@ -775,7 +812,10 @@ def proposal_delete(self, proposal_id: int, issuer_address: str):
775812
if issuer_address is None:
776813
issuer_address = self.tron.default_address.hex
777814

778-
transaction = self.tron.transaction.delete_proposal(proposal_id, issuer_address)
815+
transaction = self.tron.transaction_builder.delete_proposal(
816+
proposal_id,
817+
issuer_address
818+
)
779819
sign = self.sign(transaction)
780820
response = self.broadcast(sign)
781821

0 commit comments

Comments
 (0)