Skip to content

Commit 8e1c917

Browse files
author
peiyun@inj21
committed
add setup.py
1 parent 32e7c38 commit 8e1c917

File tree

5 files changed

+73
-65
lines changed

5 files changed

+73
-65
lines changed

setup.py

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@
99
import sys
1010
from shutil import rmtree
1111

12-
from setuptools import setup, Command
12+
from setuptools import setup, Command, find_packages
1313

14-
NAME = 'injective.sdk'
15-
DESCRIPTION = 'Injective Python SDK, with Exchange API client'
16-
URL = 'https://github.com/InjectiveLabs/sdk-python'
17-
18-
AUTHOR = 'Injective Labs'
19-
REQUIRES_PYTHON = '>=3.9.0'
20-
VERSION = '0.2.0'
14+
NAME = "injective-py"
15+
DESCRIPTION = "Injective Python SDK, with Exchange API client"
16+
URL = "https://github.com/InjectiveLabs/sdk-python"
17+
18+
AUTHOR = "Injective Labs"
19+
REQUIRES_PYTHON = ">=3.9.0"
20+
VERSION = "0.2.0"
2121

2222
REQUIRED = [
23-
'grpcio',
24-
'asyncio',
25-
'aiohttp',
26-
'ecdsa',
27-
'bech32',
28-
'mnemonic',
29-
'hdwallets',
23+
"grpcio",
24+
"asyncio",
25+
"aiohttp",
26+
"ecdsa",
27+
"bech32",
28+
"mnemonic",
29+
"hdwallets",
30+
"pysha3",
3031
]
3132

3233
# The rest you shouldn't have to touch too much :)
@@ -39,31 +40,31 @@
3940
# Import the README and use it as the long-description.
4041
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
4142
try:
42-
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
43-
long_description = '\n' + f.read()
43+
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
44+
long_description = "\n" + f.read()
4445
except FileNotFoundError:
4546
long_description = DESCRIPTION
4647

4748
# Load the package's __version__.py module as a dictionary.
4849
about = {}
4950
if not VERSION:
5051
project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
51-
with open(os.path.join(here, project_slug, '__version__.py')) as f:
52+
with open(os.path.join(here, project_slug, "__version__.py")) as f:
5253
exec(f.read(), about)
5354
else:
54-
about['__version__'] = VERSION
55+
about["__version__"] = VERSION
5556

5657

5758
class UploadCommand(Command):
5859
"""Support setup.py upload."""
5960

60-
description = 'Build and publish the package.'
61+
description = "Build and publish the package."
6162
user_options = []
6263

6364
@staticmethod
6465
def status(s):
6566
"""Prints things in bold."""
66-
print('\033[1m{0}\033[0m'.format(s))
67+
print("\033[1m{0}\033[0m".format(s))
6768

6869
def initialize_options(self):
6970
pass
@@ -73,55 +74,52 @@ def finalize_options(self):
7374

7475
def run(self):
7576
try:
76-
self.status('Removing previous builds…')
77-
rmtree(os.path.join(here, 'dist'))
77+
self.status("Removing previous builds…")
78+
rmtree(os.path.join(here, "dist"))
7879
except OSError:
7980
pass
8081

81-
self.status('Building Source and Wheel (universal) distribution…')
82-
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
82+
self.status("Building Source and Wheel (universal) distribution…")
83+
os.system("{0} setup.py sdist bdist_wheel --universal".format(sys.executable))
8384

84-
self.status('Uploading the package to PyPI via Twine…')
85-
os.system('twine upload dist/*')
85+
self.status("Uploading the package to PyPI via Twine…")
86+
os.system("twine upload dist/*")
8687

87-
self.status('Pushing git tags…')
88-
os.system('git tag v{0}'.format(about['__version__']))
89-
os.system('git push --tags')
88+
self.status("Pushing git tags…")
89+
os.system("git tag v{0}".format(about["__version__"]))
90+
os.system("git push --tags")
9091

9192
sys.exit()
9293

9394

9495
# Where the magic happens:
9596
setup(
9697
name=NAME,
97-
version=about['__version__'],
98+
version=about["__version__"],
9899
description=DESCRIPTION,
99100
long_description=long_description,
100-
long_description_content_type='text/markdown',
101+
long_description_content_type="text/markdown",
101102
author=AUTHOR,
102103
author_email=EMAIL,
103104
python_requires=REQUIRES_PYTHON,
104105
url=URL,
105-
py_modules=['exchange_api', 'chainclient'],
106-
107-
# entry_points={
108-
# 'console_scripts': ['mycli=mymodule:cli'],
109-
# },
106+
package_dir={"": "src"},
107+
packages=find_packages(where="src"),
110108
install_requires=REQUIRED,
111109
include_package_data=True,
112-
license='Apache 2.0',
110+
license="Apache Software License 2.0",
113111
classifiers=[
114112
# Trove classifiers
115113
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
116-
'License :: OSI Approved :: Apache 2.0 License',
117-
'Programming Language :: Python',
118-
'Programming Language :: Python :: 3',
119-
'Programming Language :: Python :: 3.9',
120-
'Programming Language :: Python :: Implementation :: CPython',
121-
'Programming Language :: Python :: Implementation :: PyPy'
114+
"License :: OSI Approved :: Apache Software License",
115+
"Programming Language :: Python",
116+
"Programming Language :: Python :: 3",
117+
"Programming Language :: Python :: 3.9",
118+
"Programming Language :: Python :: Implementation :: CPython",
119+
"Programming Language :: Python :: Implementation :: PyPy",
122120
],
123121
# $ setup.py publish support.
124122
cmdclass={
125-
'upload': UploadCommand,
123+
"upload": UploadCommand,
126124
},
127-
)
125+
)

src/injective/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from hdwallets import BIP32DerivationError as BIP32DerivationError
22

3-
from chainclient._transaction import Transaction as Transaction
4-
from chainclient._wallet import generate_wallet as generate_wallet
5-
from chainclient._wallet import privkey_to_address as privkey_to_address
6-
from chainclient._wallet import privkey_to_pubkey as privkey_to_pubkey
7-
from chainclient._wallet import privkey_to_uncompressed_pubkey as privkey_to_uncompressed_pubkey
8-
from chainclient._wallet import pubkey_to_address as pubkey_to_address
9-
from chainclient._wallet import seed_to_privkey as seed_to_privkey
3+
from ._transaction import Transaction as Transaction
4+
from ._wallet import generate_wallet as generate_wallet
5+
from ._wallet import privkey_to_address as privkey_to_address
6+
from ._wallet import privkey_to_pubkey as privkey_to_pubkey
7+
from ._wallet import privkey_to_uncompressed_pubkey as privkey_to_uncompressed_pubkey
8+
from ._wallet import pubkey_to_address as pubkey_to_address
9+
from ._wallet import seed_to_privkey as seed_to_privkey

src/injective/chainclient/_transaction.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import base64
2-
import hashlib
32
import json
43
from typing import Any, Dict, List
54

65
import ecdsa
76
import sha3
87

9-
from _wallet import DEFAULT_BECH32_HRP, privkey_to_address, privkey_to_pubkey
10-
from _typings import SyncMode
8+
from ._wallet import DEFAULT_BECH32_HRP, privkey_to_address, privkey_to_pubkey
9+
from ._typings import SyncMode
1110

1211

1312
class Transaction:
@@ -47,7 +46,9 @@ def __init__(
4746

4847
# Cosmos SDK • Bank Module
4948

50-
def add_cosmos_bank_msg_send(self, recipient: str, amount: int, denom: str = "inj") -> None:
49+
def add_cosmos_bank_msg_send(
50+
self, recipient: str, amount: int, denom: str = "inj"
51+
) -> None:
5152
msg = {
5253
"type": "cosmos-sdk/MsgSend",
5354
"value": {
@@ -60,7 +61,9 @@ def add_cosmos_bank_msg_send(self, recipient: str, amount: int, denom: str = "in
6061

6162
# Injective • Exchange Module
6263

63-
def add_exchange_msg_deposit(self, subaccount: str, amount: int, denom: str = "inj") -> None:
64+
def add_exchange_msg_deposit(
65+
self, subaccount: str, amount: int, denom: str = "inj"
66+
) -> None:
6467
msg = {
6568
"type": "exchange/MsgDeposit",
6669
"value": {
@@ -85,7 +88,10 @@ def get_signed(self) -> str:
8588
"signatures": [
8689
{
8790
"signature": self._sign(),
88-
"pub_key": {"type": "injective/PubKeyEthSecp256k1", "value": base64_pubkey},
91+
"pub_key": {
92+
"type": "injective/PubKeyEthSecp256k1",
93+
"value": base64_pubkey,
94+
},
8995
"account_number": str(self._account_num),
9096
"sequence": str(self._sequence),
9197
}
@@ -96,14 +102,20 @@ def get_signed(self) -> str:
96102
return json.dumps(signed_tx, separators=(",", ":"))
97103

98104
def _sign(self) -> str:
99-
message_str = json.dumps(self._get_sign_message(), separators=(",", ":"), sort_keys=True)
105+
message_str = json.dumps(
106+
self._get_sign_message(), separators=(",", ":"), sort_keys=True
107+
)
100108
message_bytes = message_str.encode("utf-8")
101109

102110
privkey = ecdsa.SigningKey.from_string(self._privkey, curve=ecdsa.SECP256k1)
103111
signature_compact_keccak = privkey.sign_deterministic(
104-
message_bytes, hashfunc=sha3.keccak_256, sigencode=ecdsa.util.sigencode_string_canonize
112+
message_bytes,
113+
hashfunc=sha3.keccak_256,
114+
sigencode=ecdsa.util.sigencode_string_canonize,
115+
)
116+
signature_base64_str = base64.b64encode(signature_compact_keccak).decode(
117+
"utf-8"
105118
)
106-
signature_base64_str = base64.b64encode(signature_compact_keccak).decode("utf-8")
107119
return signature_base64_str
108120

109121
def _get_sign_message(self) -> Dict[str, Any]:

src/injective/chainclient/_wallet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import hashlib
2-
31
import bech32
42
import ecdsa
53
import hdwallets
64
import mnemonic
75
import sha3
86

97
from hdwallets import BIP32DerivationError as BIP32DerivationError
10-
from _typings import Wallet
8+
from ._typings import Wallet
119

1210

1311
DEFAULT_DERIVATION_PATH = "m/44'/60'/0'/0/0"

0 commit comments

Comments
 (0)