Skip to content

Commit e3f6b3d

Browse files
committed
Update formatting
1 parent 9589a31 commit e3f6b3d

26 files changed

+1610
-1148
lines changed

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.git
2+
/.idea
3+
venv
4+
.mypy_cache
5+
Dockerfile
6+
.dockerignore
7+
.gitignore

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
exclude = .git,__pycache__,proto,venv

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
__pycache__/
2+
venv
3+
.mypy_cache
24
.idea

.mypy.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[mypy]
2+
strict = True
3+
allow_untyped_calls=True
4+
warn_return_any=False

Dockerfile

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,34 @@ ENV PYTHONUSERBASE $PYROOT
1010

1111
WORKDIR /build
1212

13-
# Install pipenv
14-
RUN pip install 'pipenv==2018.11.26'
13+
# Setup virtualenv
14+
RUN python -m venv /opt/venv
15+
ENV PATH="/opt/venv/bin:$PATH"
1516

16-
# Copy Pipfile, Pipfile.lock to the build container
17-
COPY Pipfile* ./
17+
# Copy requirements
18+
COPY requirements.txt ./
1819

1920
# Install build dependencies
2021
RUN apt-get update && \
2122
apt-get install -y \
2223
gcc \
2324
&& rm -rf /var/lib/apt/lists/*
25+
2426
# Install dependencies
25-
RUN PIP_USER=1 PIP_IGNORE_INSTALLED=1 pipenv install --system --deploy --ignore-pipfile
27+
RUN pip install --require-hashes -r requirements.txt
2628

2729
####################
2830
# Production image #
2931
####################
3032
FROM python:3.8.7-slim
3133

3234
# Dependencies path
33-
ENV PYROOT /pyroot
34-
ENV PATH $PYROOT/bin:$PATH
35-
ENV PYTHONPATH $PYROOT/lib/python:$PATH
36-
# This is crucial for pkg_resources to work
37-
ENV PYTHONUSERBASE $PYROOT
35+
ENV PATH="/opt/venv/bin:$PATH"
3836

39-
WORKDIR /src
37+
WORKDIR /app
4038

4139
# Copy dependencies from build container
42-
COPY --from=builder $PYROOT/bin/ $PYROOT/bin/
43-
COPY --from=builder $PYROOT/lib/ $PYROOT/lib/
40+
COPY --from=builder /opt/venv /opt/venv
4441

4542
# Copy source code
4643
COPY . ./

Pipfile

-17
This file was deleted.

Pipfile.lock

-505
This file was deleted.

contracts/__init__.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import json
22
import os
33

4-
from eth_typing import ChecksumAddress
4+
from eth_typing.evm import ChecksumAddress
55
from web3 import Web3
66
from web3.contract import Contract
77

8-
from reporting.settings import (
8+
from src.settings import (
99
POOL_CONTRACT_ADDRESS,
1010
REWARD_ETH_CONTRACT_ADDRESS,
1111
STAKED_ETH_CONTRACT_ADDRESS,
12-
BALANCE_REPORTERS_CONTRACT_ADDRESS
12+
BALANCE_REPORTERS_CONTRACT_ADDRESS,
1313
)
1414

1515

1616
def get_staked_eth_contract(w3: Web3) -> Contract:
1717
""":returns instance of `StakedEthToken` contract."""
1818
current_dir = os.path.dirname(__file__)
19-
with open(os.path.join(current_dir, 'abi/IStakedEthToken.json')) as f:
19+
with open(os.path.join(current_dir, "abi/IStakedEthToken.json")) as f:
2020
abi = json.load(f)
2121

2222
return w3.eth.contract(abi=abi, address=STAKED_ETH_CONTRACT_ADDRESS)
@@ -25,7 +25,7 @@ def get_staked_eth_contract(w3: Web3) -> Contract:
2525
def get_reward_eth_contract(w3: Web3) -> Contract:
2626
""":returns instance of `RewardEthToken` contract."""
2727
current_dir = os.path.dirname(__file__)
28-
with open(os.path.join(current_dir, 'abi/IRewardEthToken.json')) as f:
28+
with open(os.path.join(current_dir, "abi/IRewardEthToken.json")) as f:
2929
abi = json.load(f)
3030

3131
return w3.eth.contract(abi=abi, address=REWARD_ETH_CONTRACT_ADDRESS)
@@ -34,19 +34,18 @@ def get_reward_eth_contract(w3: Web3) -> Contract:
3434
def get_pool_contract(w3: Web3) -> Contract:
3535
""":returns instance of `Pool` contract."""
3636
current_dir = os.path.dirname(__file__)
37-
with open(os.path.join(current_dir, 'abi/IPool.json')) as f:
37+
with open(os.path.join(current_dir, "abi/IPool.json")) as f:
3838
abi = json.load(f)
3939

40-
return w3.eth.contract(
41-
abi=abi,
42-
address=POOL_CONTRACT_ADDRESS
43-
)
40+
return w3.eth.contract(abi=abi, address=POOL_CONTRACT_ADDRESS)
4441

4542

46-
def get_ownable_pausable_contract(w3: Web3, contract_address: ChecksumAddress) -> Contract:
43+
def get_ownable_pausable_contract(
44+
w3: Web3, contract_address: ChecksumAddress
45+
) -> Contract:
4746
""":returns instance of `OwnablePausable` contract."""
4847
current_dir = os.path.dirname(__file__)
49-
with open(os.path.join(current_dir, 'abi/OwnablePausableUpgradeable.json')) as f:
48+
with open(os.path.join(current_dir, "abi/OwnablePausableUpgradeable.json")) as f:
5049
abi = json.load(f)
5150

5251
return w3.eth.contract(abi=abi, address=contract_address)
@@ -55,10 +54,7 @@ def get_ownable_pausable_contract(w3: Web3, contract_address: ChecksumAddress) -
5554
def get_balance_reporters_contract(w3: Web3) -> Contract:
5655
""":returns instance of `Balance Reporters` contract."""
5756
current_dir = os.path.dirname(__file__)
58-
with open(os.path.join(current_dir, 'abi/IBalanceReporters.json')) as f:
57+
with open(os.path.join(current_dir, "abi/IBalanceReporters.json")) as f:
5958
abi = json.load(f)
6059

61-
return w3.eth.contract(
62-
abi=abi,
63-
address=BALANCE_REPORTERS_CONTRACT_ADDRESS
64-
)
60+
return w3.eth.contract(abi=abi, address=BALANCE_REPORTERS_CONTRACT_ADDRESS)

main.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
import sys
44
import time
55
from loguru import logger
6-
from notifiers.logging import NotificationHandler
6+
from notifiers.logging import NotificationHandler # type: ignore
77

8-
from utils import (
9-
get_web3_client,
10-
configure_default_account,
11-
InterruptHandler,
12-
check_default_account_balance
13-
)
14-
from reporting.reward_token import RewardToken
15-
from reporting.settings import (
8+
from src.reward_token import RewardToken
9+
from src.settings import (
1610
WEB3_WS_ENDPOINT,
1711
WEB3_HTTP_ENDPOINT,
1812
INJECT_POA_MIDDLEWARE,
@@ -25,22 +19,29 @@
2519
BALANCE_ERROR_THRESHOLD,
2620
APPLY_GAS_PRICE_STRATEGY,
2721
MAX_TX_WAIT_SECONDS,
28-
LOG_LEVEL
22+
LOG_LEVEL,
23+
)
24+
from src.utils import (
25+
get_web3_client,
26+
configure_default_account,
27+
InterruptHandler,
28+
check_default_account_balance,
2929
)
3030

3131
# Send notification to admins on error
32-
handler = NotificationHandler('telegram')
32+
handler = NotificationHandler("telegram")
3333
logger.remove(0)
3434
logger.add(
3535
sink=sys.stderr,
36-
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> <level>{level}</level> <level>{message}</level>",
37-
level=LOG_LEVEL
36+
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green>"
37+
" <level>{level}</level> <level>{message}</level>",
38+
level=LOG_LEVEL,
3839
)
39-
logger.add(handler, level='ERROR', backtrace=False, diagnose=False)
40+
logger.add(handler, level="ERROR", backtrace=False, diagnose=False)
4041

4142

4243
@logger.catch
43-
def main():
44+
def main() -> None:
4445
# setup Web3 client
4546
web3_client = get_web3_client(
4647
http_endpoint=WEB3_HTTP_ENDPOINT,
@@ -51,7 +52,7 @@ def main():
5152
inject_poa=INJECT_POA_MIDDLEWARE,
5253
inject_local_filter=INJECT_LOCAL_FILTER_MIDDLEWARE,
5354
inject_stale_check=INJECT_STALE_CHECK_MIDDLEWARE,
54-
stale_check_allowable_delay=STALE_CHECK_MIDDLEWARE_ALLOWABLE_DELAY
55+
stale_check_allowable_delay=STALE_CHECK_MIDDLEWARE_ALLOWABLE_DELAY,
5556
)
5657

5758
# setup default account
@@ -61,26 +62,30 @@ def main():
6162
interrupt_handler = InterruptHandler()
6263

6364
reward_token_total_rewards = RewardToken(
64-
w3=web3_client,
65-
interrupt_handler=interrupt_handler
65+
w3=web3_client, interrupt_handler=interrupt_handler
6666
)
6767

6868
while not interrupt_handler.exit:
6969
# сheck reporter balance
7070
check_default_account_balance(
71-
web3_client,
72-
BALANCE_WARNING_THRESHOLD,
73-
BALANCE_ERROR_THRESHOLD
71+
web3_client, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
7472
)
7573

7674
current_datetime = datetime.now(tz=timezone.utc)
7775
if reward_token_total_rewards.next_update_at > current_datetime:
78-
logger.info(f'Scheduling next rewards update at {reward_token_total_rewards.next_update_at}')
79-
time.sleep((reward_token_total_rewards.next_update_at - current_datetime).total_seconds())
76+
logger.info(
77+
f"Scheduling next rewards update at"
78+
f" {reward_token_total_rewards.next_update_at}"
79+
)
80+
time.sleep(
81+
(
82+
reward_token_total_rewards.next_update_at - current_datetime
83+
).total_seconds()
84+
)
8085

8186
# update Reward Token total rewards
8287
reward_token_total_rewards.process()
8388

8489

85-
if __name__ == '__main__':
90+
if __name__ == "__main__":
8691
main()

0 commit comments

Comments
 (0)