Skip to content

Commit 6922e93

Browse files
committed
update
1 parent 8d09895 commit 6922e93

File tree

15 files changed

+63
-98
lines changed

15 files changed

+63
-98
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
'Programming Language :: Python :: 3.6',
122122
'Programming Language :: Python :: 3.7',
123123
],
124-
packages=["tronapi", "trx_account"],
124+
packages=["tronapi"],
125125
include_package_data=True,
126126
install_requires=install_requires,
127127
tests_require=EXTRAS_REQUIRE['tester'],
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,34 @@
88
from binascii import unhexlify
99

1010
import base58
11-
from eth_account.datastructures import AttributeDict
11+
import ecdsa
1212
from eth_keys import KeyAPI
13+
from eth_account import Account as ETHAccount
1314
from trx_utils import is_hex
1415

1516

16-
class Account(object):
17+
class Account:
18+
@staticmethod
19+
def create():
20+
generate_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
21+
return PrivateKey(generate_key.to_string().hex())
22+
23+
@staticmethod
24+
def sign_hash(message_hash, private_key):
25+
if not is_hex(message_hash):
26+
raise ValueError('Invalid message_hash provided')
27+
28+
return ETHAccount.signHash(message_hash, private_key)
29+
30+
@staticmethod
31+
def recover_hash(message_hash, signature):
32+
if not is_hex(message_hash):
33+
raise ValueError('Invalid message_hash provided')
34+
35+
return ETHAccount.recoverHash(message_hash, signature=signature)
36+
37+
38+
class Address(object):
1739
@staticmethod
1840
def from_hex(address):
1941
"""Helper function that will convert a generic value from hex"""

tronapi/common/contracts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
merge_args_and_kwargs
2727
)
2828

29-
from tronapi.common.function_identifiers import FallbackFn
3029
from tronapi.common.normalizers import (
3130
abi_address_to_hex,
3231
abi_bytes_to_bytes,
@@ -45,6 +44,10 @@
4544
)
4645

4746

47+
class FallbackFn:
48+
pass
49+
50+
4851
def find_matching_fn_abi(abi, fn_identifier=None, args=None, kwargs=None):
4952
args = args or tuple()
5053
kwargs = kwargs or dict()

tronapi/common/encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
from typing import Union
44

5+
from eth_account.datastructures import AttributeDict
56
from hexbytes import HexBytes
67

78
from eth_utils import (
@@ -44,7 +45,6 @@
4445
)
4546

4647
from tronapi.common.validation import assert_one_val
47-
from trx_account import AttributeDict
4848

4949

5050
def hex_encode_abi_type(abi_type, value, force_size=None):

tronapi/common/function_identifiers.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

tronapi/common/normalizers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from toolz import curry
1111

1212
from tronapi.common.abi import process_type
13+
from tronapi.common.account import Address
1314
from tronapi.common.encoding import (
1415
to_bytes,
1516
text_if_str,
@@ -19,7 +20,6 @@
1920
validate_abi,
2021
validate_address
2122
)
22-
from trx_account import Account
2323

2424

2525
def implicitly_identity(to_wrap):
@@ -75,7 +75,7 @@ def addresses_checksummed(abi_type, data):
7575

7676

7777
def to_checksum_address(address: str):
78-
return Account().from_hex(address)
78+
return Address().from_hex(address)
7979

8080

8181
@curry

tronapi/common/validation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
is_address_type, is_int_type, is_uint_type, is_bool_type, sub_type_of_array_type, is_array_type, \
3939
length_of_array_type
4040
from tronapi.exceptions import InvalidAddress
41-
from tronapi.utils.help import hex_to_base58
4241

4342

4443
def _prepare_selector_collision_msg(duplicates):

tronapi/contract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
from tronapi.common.contracts import (
3232
find_matching_fn_abi,
3333
encode_abi,
34-
get_function_info
34+
get_function_info,
35+
FallbackFn
3536
)
3637
from tronapi.common.datatypes import PropertyCheckingFactory
3738
from tronapi.common.encoding import to_4byte_hex
38-
from tronapi.common.function_identifiers import FallbackFn
3939
from tronapi.common.normalizers import (
4040
normalize_abi,
4141
normalize_bytecode,

tronapi/main.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
:license: MIT License
1616
"""
1717

18-
import ecdsa
18+
from eth_account.datastructures import AttributeDict
1919
from eth_utils import (
2020
apply_to_return_value,
2121
to_hex,
@@ -33,12 +33,8 @@
3333

3434
from tronapi.common.abi import map_abi_data
3535

36-
from trx_account import (
37-
Account,
38-
PrivateKey,
39-
AttributeDict
40-
)
4136

37+
from tronapi.common.account import Address, PrivateKey, Account
4238
from tronapi.common.normalizers import abi_resolver
4339
from tronapi.common.encoding import (
4440
to_bytes,
@@ -256,7 +252,7 @@ def get_event_transaction_id(self, tx_id):
256252
return response
257253

258254
@property
259-
def address(self):
255+
def address(self) -> Address:
260256
"""Helper object that allows you to convert
261257
between hex/base58 and private key representations of a TRON address.
262258
@@ -265,7 +261,7 @@ def address(self):
265261
please use the function tron.to_hex.
266262
267263
"""
268-
return Account()
264+
return Address()
269265

270266
@property
271267
def create_account(self) -> PrivateKey:
@@ -276,8 +272,7 @@ def create_account(self) -> PrivateKey:
276272
provided by other or invoke this very API on a public network.
277273
278274
"""
279-
generate_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
280-
return PrivateKey(generate_key.to_string().hex())
275+
return Account.create()
281276

282277
@staticmethod
283278
def is_valid_provider(provider) -> bool:

tronapi/providers/base.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# Licensed under the MIT License.
44
# See License.txt in the project root for license information.
55
# --------------------------------------------------------------------
6+
import platform
67

7-
from tronapi.utils.help import format_user_agent
8+
import tronapi
89

910

1011
class BaseProvider(object):
@@ -26,3 +27,17 @@ def _http_default_headers():
2627
'Content-Type': 'application/json',
2728
'User-Agent': format_user_agent()
2829
}
30+
31+
@staticmethod
32+
def format_user_agent(name=None):
33+
"""Construct a User-Agent suitable for use in client code.
34+
This will identify use by the provided ``name`` (which should be on the
35+
format ``dist_name/version``), TronAPI version and Python version.
36+
.. versionadded:: 1.1
37+
"""
38+
parts = ['TronAPI/%s' % tronapi.__version__,
39+
'%s/%s' % (platform.python_implementation(),
40+
platform.python_version())]
41+
if name:
42+
parts.insert(0, name)
43+
return ' '.join(parts)

0 commit comments

Comments
 (0)