Skip to content

Commit 8698291

Browse files
author
abel
committed
(feat) Added Poetry to the proyect and the pyproject.toml configuration file. Added pre-commit. Added the use of Flake8 through Flakeheaven.
1 parent 8e63e6e commit 8698291

File tree

144 files changed

+2806
-504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2806
-504
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
2525
run: |
2626
python setup.py sdist bdist_wheel
27-
twine upload --skip-existing dist/*
27+
twine upload --skip-existing dist/*

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,5 @@ cython_debug/
143143

144144
.chain_cookie
145145
.exchange_cookie
146+
147+
.flakeheaven_cache

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exclude: '^pyinjective/proto/.*'
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v3.2.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- repo: https://github.com/flakeheaven/flakeheaven
10+
rev: 3.3.0
11+
hooks:
12+
- id: flakeheaven
13+
name: flakeheaven
14+
description: '`flakeheaven` is a `flake8` wrapper.'
15+
entry: flakeheaven lint
16+
language: python
17+
types_or: [ python, jupyter, markdown, rst, yaml ]
18+
require_serial: true
19+
minimum_pre_commit_version: 2.9.0

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,4 @@ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
200200
distributed under the License is distributed on an "AS IS" BASIS,
201201
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202202
See the License for the specific language governing permissions and
203-
limitations under the License.
203+
limitations under the License.

NOTICE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
55
Originally released by Injective Labs Inc. under: <br />
66
Apache License <br />
77
Version 2.0, January 2004 <br />
8-
http://www.apache.org/licenses/
8+
http://www.apache.org/licenses/

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,4 @@ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
252252
Originally released by Injective Labs Inc. under: <br />
253253
Apache License <br />
254254
Version 2.0, January 2004 <br />
255-
http://www.apache.org/licenses/
256-
255+
http://www.apache.org/licenses/

compatibility-tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ API users must also install the typing_extensions library with the below command
3838

3939
```bash
4040
pip3 install typing_extensions
41-
```
41+
```
4242

4343
The Python 3.7 stdlib has an older version of typing.py so the above change in the code will fix the compatibility issue by importing Literal from typing_extensions

compatibility-tests/tests.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import asyncio
22
import aiohttp
3-
import logging
4-
import json
53
import base64
6-
import hashlib
74
import json
85
import ecdsa
96
import sha3
107
import grpc
118

129
from typing import Any, Dict, List
1310
from injective.chain_client._wallet import (
14-
generate_wallet,
1511
privkey_to_address,
1612
privkey_to_pubkey,
17-
pubkey_to_address,
1813
seed_to_privkey,
1914
DEFAULT_BECH32_HRP,
2015
)
@@ -25,6 +20,7 @@
2520

2621
MIN_GAS_PRICE = 500000000
2722

23+
2824
class Transaction:
2925

3026
def __init__(
@@ -130,6 +126,7 @@ def _get_sign_message(self) -> Dict[str, Any]:
130126
"msgs": self._msgs,
131127
}
132128

129+
133130
async def main() -> None:
134131
sender_pk = seed_to_privkey(
135132
"physical page glare junk return scale subject river token door mirror title"
@@ -143,7 +140,9 @@ async def main() -> None:
143140
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
144141
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
145142

146-
subacc = await accounts_rpc.SubaccountsList(accounts_rpc_pb.SubaccountsListRequest(account_address = account_addr))
143+
subacc = await accounts_rpc.SubaccountsList(
144+
accounts_rpc_pb.SubaccountsListRequest(account_address=account_addr)
145+
)
147146
for sub in subacc.subaccounts:
148147
print("Primary subaccount:", sub)
149148
break
@@ -162,7 +161,7 @@ async def main() -> None:
162161
denom="inj",
163162
)
164163
tx.add_exchange_msg_deposit(
165-
subaccount= sub,
164+
subaccount=sub,
166165
amount=10000000000000000,
167166
denom="inj",
168167
)
@@ -172,6 +171,7 @@ async def main() -> None:
172171
print("Signed Tx:", tx_json)
173172
print("Sent Tx:", await post_tx(tx_json))
174173

174+
175175
async def get_account_num_seq(address: str) -> (int, int):
176176
async with aiohttp.ClientSession() as session:
177177
async with session.request(
@@ -186,6 +186,7 @@ async def get_account_num_seq(address: str) -> (int, int):
186186
acc = resp['account']['base_account']
187187
return acc['account_number'], acc['sequence']
188188

189+
189190
async def post_tx(tx_json: str):
190191
async with aiohttp.ClientSession() as session:
191192
async with session.request(
@@ -204,4 +205,4 @@ async def post_tx(tx_json: str):
204205
return resp['txhash']
205206

206207
if __name__ == "__main__":
207-
asyncio.get_event_loop().run_until_complete(main())
208+
asyncio.get_event_loop().run_until_complete(main())

compatibility-tests/unit_tests.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
from typing import Any, Dict, List
1010
from injective.chain_client._wallet import (
11-
generate_wallet,
1211
privkey_to_address,
1312
privkey_to_pubkey,
14-
pubkey_to_address,
1513
seed_to_privkey,
1614
DEFAULT_BECH32_HRP,
1715
)
@@ -22,6 +20,7 @@
2220

2321
MIN_GAS_PRICE = 500000000
2422

23+
2524
class Transaction:
2625

2726
def __init__(
@@ -50,7 +49,6 @@ def __init__(
5049
self._sync_mode = sync_mode
5150
self._msgs: List[dict] = []
5251

53-
5452
def add_cosmos_bank_msg_send(self, recipient: str, amount: int, denom: str = "inj") -> None:
5553
msg = {
5654
"type": "cosmos-sdk/MsgSend",
@@ -141,6 +139,7 @@ async def get_account_num_seq(address: str) -> (int, int):
141139
acc = resp['account']['base_account']
142140
return acc['account_number'], acc['sequence']
143141

142+
144143
async def post_tx(tx_json: str):
145144
async with aiohttp.ClientSession() as session:
146145
async with session.request(
@@ -158,6 +157,7 @@ async def post_tx(tx_json: str):
158157

159158
return resp['txhash']
160159

160+
161161
@pytest.fixture
162162
async def msg_send():
163163
sender_pk = seed_to_privkey(
@@ -172,7 +172,9 @@ async def msg_send():
172172
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
173173
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
174174

175-
subacc = await accounts_rpc.SubaccountsList(accounts_rpc_pb.SubaccountsListRequest(account_address = account_addr))
175+
subacc = await accounts_rpc.SubaccountsList(
176+
accounts_rpc_pb.SubaccountsListRequest(account_address=account_addr)
177+
)
176178
for sub in subacc.subaccounts:
177179
print("Primary subaccount:", sub)
178180
break
@@ -191,7 +193,7 @@ async def msg_send():
191193
denom="inj",
192194
)
193195
tx.add_exchange_msg_deposit(
194-
subaccount= sub,
196+
subaccount=sub,
195197
amount=10000000000000000,
196198
denom="inj",
197199
)
@@ -204,6 +206,7 @@ async def msg_send():
204206

205207
return len(tx_result)
206208

209+
207210
@pytest.mark.asyncio
208211
async def test_msg_send(msg_send):
209-
assert msg_send == 64
212+
assert msg_send == 64

examples/SendToInjective.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import json
2-
import requests
32

43
import asyncio
5-
import logging
64

75
from pyinjective.core.network import Network
86
from pyinjective.sendtocosmos import Peggo
97

108
import importlib.resources as pkg_resources
119
import pyinjective
1210

11+
1312
async def main() -> None:
1413
# select network: testnet, mainnet
1514
network = Network.testnet()
@@ -25,13 +24,26 @@ async def main() -> None:
2524
receiver = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
2625
amount = 1
2726

28-
data = '{"@type": "/injective.exchange.v1beta1.MsgDeposit","sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku","subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000","amount": {"denom": "inj","amount": "1000000000000000000"}}'
27+
data = ('{"@type": "/injective.exchange.v1beta1.MsgDeposit",'
28+
'"sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",'
29+
'"subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",'
30+
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
31+
)
2932

3033
import_peggo = pkg_resources.read_text(pyinjective, 'Peggo_ABI.json')
3134
peggo_abi = json.loads(import_peggo)
3235

33-
peggo_composer.sendToInjective(ethereum_endpoint=ethereum_endpoint, private_key=private_key, token_contract=token_contract,
34-
receiver=receiver, amount=amount, maxFeePerGas=maxFeePerGas_Gwei, maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei, data=data, peggo_abi=peggo_abi)
36+
peggo_composer.sendToInjective(
37+
ethereum_endpoint=ethereum_endpoint,
38+
private_key=private_key,
39+
token_contract=token_contract,
40+
receiver=receiver,
41+
amount=amount,
42+
maxFeePerGas=maxFeePerGas_Gwei,
43+
maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei,
44+
data=data,
45+
peggo_abi=peggo_abi
46+
)
3547

3648
if __name__ == "__main__":
3749
asyncio.get_event_loop().run_until_complete(main())

0 commit comments

Comments
 (0)