Skip to content

Commit 9589a31

Browse files
authored
Merge pull request stakewise#1 from tsudmi/major-refactoring
Refactor balance reporter
2 parents d7d0413 + 1d0ffb1 commit 9589a31

15 files changed

+658
-514
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###########
22
# Builder #
33
###########
4-
FROM python:3.8.6-slim AS builder
4+
FROM python:3.8.7-slim AS builder
55

66
# This is where pip will install to
77
ENV PYROOT /pyroot
@@ -27,7 +27,7 @@ RUN PIP_USER=1 PIP_IGNORE_INSTALLED=1 pipenv install --system --deploy --ignore-
2727
####################
2828
# Production image #
2929
####################
30-
FROM python:3.8.6-slim
30+
FROM python:3.8.7-slim
3131

3232
# Dependencies path
3333
ENV PYROOT /pyroot

Pipfile

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ web3 = "*"
1010
grpcio = "*"
1111
protobuf = "*"
1212
google-api-core = "*"
13-
prometheus-client = "*"
1413

1514
[dev-packages]
1615

Pipfile.lock

+25-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/__init__.py

+43-28
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
11
import json
2-
from os import path
3-
from typing import Dict
2+
import os
43

5-
from eth_typing import Address
4+
from eth_typing import ChecksumAddress
65
from web3 import Web3
76
from web3.contract import Contract
87

9-
current_dir = path.dirname(__file__)
8+
from reporting.settings import (
9+
POOL_CONTRACT_ADDRESS,
10+
REWARD_ETH_CONTRACT_ADDRESS,
11+
STAKED_ETH_CONTRACT_ADDRESS,
12+
BALANCE_REPORTERS_CONTRACT_ADDRESS
13+
)
1014

1115

12-
def _load_abi(filename: str) -> Dict:
13-
with open(path.join(current_dir, 'abi', filename), 'r') as f:
14-
return json.load(f)
16+
def get_staked_eth_contract(w3: Web3) -> Contract:
17+
""":returns instance of `StakedEthToken` contract."""
18+
current_dir = os.path.dirname(__file__)
19+
with open(os.path.join(current_dir, 'abi/IStakedEthToken.json')) as f:
20+
abi = json.load(f)
1521

22+
return w3.eth.contract(abi=abi, address=STAKED_ETH_CONTRACT_ADDRESS)
1623

17-
def get_settings_contract(w3: Web3, contract_address: Address) -> Contract:
18-
return w3.eth.contract(
19-
abi=_load_abi('ISettings.json'),
20-
address=contract_address
21-
)
2224

25+
def get_reward_eth_contract(w3: Web3) -> Contract:
26+
""":returns instance of `RewardEthToken` contract."""
27+
current_dir = os.path.dirname(__file__)
28+
with open(os.path.join(current_dir, 'abi/IRewardEthToken.json')) as f:
29+
abi = json.load(f)
30+
31+
return w3.eth.contract(abi=abi, address=REWARD_ETH_CONTRACT_ADDRESS)
2332

24-
def get_validators_contract(w3: Web3, contract_address: Address) -> Contract:
25-
return w3.eth.contract(
26-
abi=_load_abi('IValidators.json'),
27-
address=contract_address
28-
)
2933

34+
def get_pool_contract(w3: Web3) -> Contract:
35+
""":returns instance of `Pool` contract."""
36+
current_dir = os.path.dirname(__file__)
37+
with open(os.path.join(current_dir, 'abi/IPool.json')) as f:
38+
abi = json.load(f)
3039

31-
def get_reward_eth_token_contract(w3: Web3, contract_address: Address) -> Contract:
3240
return w3.eth.contract(
33-
abi=_load_abi('IRewardEthToken.json'),
34-
address=contract_address
41+
abi=abi,
42+
address=POOL_CONTRACT_ADDRESS
3543
)
3644

3745

38-
def get_staked_eth_token_contract(w3: Web3, contract_address: Address) -> Contract:
39-
return w3.eth.contract(
40-
abi=_load_abi('IStakedEthToken.json'),
41-
address=contract_address
42-
)
46+
def get_ownable_pausable_contract(w3: Web3, contract_address: ChecksumAddress) -> Contract:
47+
""":returns instance of `OwnablePausable` contract."""
48+
current_dir = os.path.dirname(__file__)
49+
with open(os.path.join(current_dir, 'abi/OwnablePausableUpgradeable.json')) as f:
50+
abi = json.load(f)
51+
52+
return w3.eth.contract(abi=abi, address=contract_address)
53+
4354

55+
def get_balance_reporters_contract(w3: Web3) -> Contract:
56+
""":returns instance of `Balance Reporters` contract."""
57+
current_dir = os.path.dirname(__file__)
58+
with open(os.path.join(current_dir, 'abi/IBalanceReporters.json')) as f:
59+
abi = json.load(f)
4460

45-
def get_balance_reporters_contract(w3: Web3, contract_address: Address) -> Contract:
4661
return w3.eth.contract(
47-
abi=_load_abi('IBalanceReporters.json'),
48-
address=contract_address
62+
abi=abi,
63+
address=BALANCE_REPORTERS_CONTRACT_ADDRESS
4964
)

0 commit comments

Comments
 (0)