Skip to content

Commit 2221345

Browse files
committed
Initial v3.0.0 beta
1 parent ac30968 commit 2221345

File tree

9 files changed

+77
-42
lines changed

9 files changed

+77
-42
lines changed

.bumpversion.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[bumpversion]
2+
current_version = 3.0.0
3+
commit = True
4+
tag = True
5+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<stage>[^.]*)\.(?P<devnum>\d+))?
6+
serialize =
7+
{major}.{minor}.{patch}-{stage}.{devnum}
8+
{major}.{minor}.{patch}
9+
10+
[bumpversion:part:stage]
11+
optional_value = stable
12+
first_value = stable
13+
values =
14+
alpha
15+
beta
16+
stable
17+
18+
[bumpversion:part:devnum]
19+
20+
[bumpversion:file:setup.py]
21+
search = version='{current_version}',
22+
replace = version='{new_version}',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
py_version = platform.python_version()
2626

27-
PACKAGE_VERSION = '2.0.5'
27+
PACKAGE_VERSION = '3.0.0'
2828

2929
EXTRAS_REQUIRE = {
3030
'tester': [

tronapi/__init__.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,22 @@
55
# --------------------------------------------------------------------
66

77
import sys
8-
import warnings
98

109
import pkg_resources
1110

11+
from eth_account import Account # noqa: E402
1212
from tronapi.providers.http import HttpProvider # noqa: E402
1313
from tronapi.main import Tron # noqa: E402
1414

15-
if (3, 5) <= sys.version_info < (3, 6):
16-
warnings.warn(
17-
"Support for Python 3.5 will be removed in tronapi v5",
18-
category=DeprecationWarning,
19-
stacklevel=2)
20-
2115
if sys.version_info < (3, 5):
22-
raise EnvironmentError(
23-
"Python 3.5 or above is required. "
24-
"Note that support for Python 3.5 will be remove in tronapi v5")
16+
raise EnvironmentError("Python 3.5 or above is required")
2517

2618

2719
__version__ = pkg_resources.get_distribution("tronapi").version
2820

2921
__all__ = [
3022
'__version__',
3123
'HttpProvider',
24+
'Account',
3225
'Tron',
33-
]
26+
]

tronapi/base/contracts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
def find_matching_fn_abi(abi, fn_identifier=None, args=None, kwargs=None):
26+
global diagnosis
2627
args = args or tuple()
2728
kwargs = kwargs or dict()
2829
filters = []

tronapi/base/toolz/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# --------------------------------------------------------------------------------------------
1+
# --------------------------------------------------------------------
22
# Copyright (c) iEXBase. All rights reserved.
3-
# Licensed under the MIT License. See License.txt in the project root for license information.
4-
# --------------------------------------------------------------------------------------------
3+
# Licensed under the MIT License.
4+
# See License.txt in the project root for license information.
5+
# --------------------------------------------------------------------
56

67
try:
78
from cytoolz import (

tronapi/base/toolz/curried.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
from cytoolz.curried import (
3+
keymap,
4+
valmap,
5+
)
6+
except ImportError:
7+
from toolz.curried import ( # noqa: F401
8+
keymap,
9+
valmap,
10+
)

tronapi/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class NoABIFunctionsFound(AttributeError):
4141
"""
4242
pass
4343

44+
class ValidationError(Exception):
45+
"""
46+
Raised when a supplied value is invalid.
47+
"""
48+
pass
4449

4550
class TransportError(TronError):
4651
"""Base exception for transport related errors.

tronapi/main.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from tronapi.base.account import Account, PrivateKey
1313
from tronapi.base.datastructures import AttributeDict
14-
from tronapi.base.decorators import deprecated_for
1514
from tronapi.base.encoding import (
1615
to_bytes,
1716
to_int,
@@ -24,7 +23,7 @@
2423
from tronapi.transactionbuilder import TransactionBuilder
2524
from tronapi.trx import Trx
2625
from tronapi.base.validation import is_address
27-
from tronapi.utils.crypto import keccak as tron_keccak
26+
from tronapi.utils.crypto import keccak
2827
from tronapi.utils.currency import to_sun, from_sun
2928
from tronapi.utils.types import is_integer
3029

@@ -34,6 +33,9 @@
3433

3534

3635
class 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

tronapi/trx.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import math
88
from typing import Any
99

10-
from eth_account.account import Account as EthAccount
10+
from eth_account import Account
1111

1212
from tronapi.contract import Contract
1313
from tronapi.exceptions import InvalidTronError, TronError
@@ -24,7 +24,7 @@
2424

2525

2626
class Trx(Module):
27-
defaultContractFactory = Contract
27+
default_contract_factory = Contract
2828

2929
def get_current_block(self):
3030
"""Query the latest block"""
@@ -417,7 +417,7 @@ def sign(self, transaction: Any, use_tron: bool = True):
417417
# before encrypting or decrypting
418418
header = TRX_MESSAGE_HEADER if use_tron else ETH_MESSAGE_HEADER
419419
message_hash = self.tron.sha3(text=header + transaction)
420-
signed_message = EthAccount.signHash(message_hash, private_key=self.tron.private_key)
420+
signed_message = Account.signHash(message_hash, private_key=self.tron.private_key)
421421

422422
return signed_message
423423

@@ -475,7 +475,7 @@ def verify_message(self, message, signed_message=None, address=None, use_tron: b
475475
header = TRX_MESSAGE_HEADER if use_tron else ETH_MESSAGE_HEADER
476476

477477
message_hash = self.tron.sha3(text=header + message)
478-
recovered = EthAccount.recoverHash(message_hash, signature=signed_message.signature)
478+
recovered = Account.recoverHash(message_hash, signature=signed_message.signature)
479479

480480
tron_address = '41' + recovered[2:]
481481
base58address = self.tron.address.from_hex(tron_address).decode()
@@ -667,13 +667,14 @@ def get_contract(self, contract_address):
667667
})
668668

669669
def contract(self, address=None, **kwargs):
670-
ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)
671-
ContractFactory = ContractFactoryClass.factory(self.tron, **kwargs)
670+
contract_factory_class = kwargs.pop('contract_factory_class',
671+
self.default_contract_factory)
672+
contract_factory = contract_factory_class.factory(self.tron, **kwargs)
672673

673674
if address:
674-
return ContractFactory(address)
675+
return contract_factory(address)
675676
else:
676-
return ContractFactory
677+
return contract_factory
677678

678679
def validate_address(self, address, _is_hex=False):
679680
"""Validate address

0 commit comments

Comments
 (0)