diff --git a/skale/contracts/base_contract.py b/skale/contracts/base_contract.py index d96f4eae..e52346d9 100644 --- a/skale/contracts/base_contract.py +++ b/skale/contracts/base_contract.py @@ -34,7 +34,7 @@ def transaction_method(transaction): @wraps(transaction_method) def wrapper(self, *args, wait_for=False, timeout=4, blocks_to_wait=50, retries=1, **kwargs): for retry in range(retries): - logging.info( + logger.info( f'transaction_method: {transaction.__name__}, try {retry+1}/{retries}, ' f'wallet: {self.skale.wallet.__class__.__name__}, ' f'sender: {self.skale.wallet.address}' @@ -61,9 +61,6 @@ def wrapper(self, *args, wait_for=False, timeout=4, blocks_to_wait=50, retries=1 class BaseContract: def __init__(self, skale, name, address, abi): self.skale = skale - self.web3 = skale.web3 self.name = name self.address = Web3.toChecksumAddress(address) - self.abi = abi - self.contract = self.web3.eth.contract( - address=self.address, abi=self.abi) + self.contract = skale.web3.eth.contract(address=self.address, abi=abi) diff --git a/skale/contracts_info.py b/skale/contracts_info.py index 35b41f08..6cf0c7a6 100644 --- a/skale/contracts_info.py +++ b/skale/contracts_info.py @@ -52,3 +52,10 @@ ContractInfo('token_state', 'TokenState', contracts.TokenState, ContractTypes.API, False) ] + + +def get_contracts_info(): + contracts_info = {} + for contract_info in CONTRACTS_INFO: + contracts_info[contract_info.name] = contract_info + return contracts_info diff --git a/skale/manager_client.py b/skale/manager_client.py index 3aa33f30..b2b62c3b 100644 --- a/skale/manager_client.py +++ b/skale/manager_client.py @@ -24,7 +24,7 @@ import skale.contracts as contracts from skale.wallets import BaseWallet -from skale.contracts_info import CONTRACTS_INFO +from skale.contracts_info import get_contracts_info from skale.utils.helper import get_abi from skale.utils.web3_utils import get_provider from skale.utils.exceptions import InvalidWalletError, EmptyWalletError @@ -48,14 +48,11 @@ def __init__(self, endpoint, abi_filepath, wallet=None, provider_timeout=30): self._endpoint = endpoint self.web3 = Web3(provider) self.web3.middleware_onion.inject(geth_poa_middleware, layer=0) # todo: may cause issues - self.abi = get_abi(abi_filepath) self.__contracts = {} - self.__contracts_info = {} self.nonces = {} if wallet: self.wallet = wallet - self.__init_contracts_info() - self.__init_contracts() + self.__init_contracts(get_abi(abi_filepath), get_contracts_info()) @property def gas_price(self): @@ -75,35 +72,28 @@ def wallet(self, wallet): raise InvalidWalletError(f'Wrong wallet class: {type(wallet).__name__}. \ Must be one of the BaseWallet subclasses') - def __init_contracts_info(self): - for contract_info in CONTRACTS_INFO: - self.__add_contract_info(contract_info) - - def __add_contract_info(self, contract_info): - self.__contracts_info[contract_info.name] = contract_info - - def __init_contracts(self): - self.add_lib_contract('contract_manager', contracts.ContractManager) - for name in self.__contracts_info: - info = self.__contracts_info[name] + def __init_contracts(self, abi, contracts_info): + self.add_lib_contract('contract_manager', contracts.ContractManager, abi) + for name in contracts_info: + info = contracts_info[name] if info.upgradeable: - self.init_upgradeable_contract(info) + self.init_upgradeable_contract(info, abi) else: - self.add_lib_contract(info.name, info.contract_class) + self.add_lib_contract(info.name, info.contract_class, abi) - def init_upgradeable_contract(self, contract_info): + def init_upgradeable_contract(self, contract_info, abi): address = self.get_contract_address(contract_info.contract_name) self.add_lib_contract(contract_info.name, contract_info.contract_class, - address) + abi, address) - def add_lib_contract(self, name, contract_class, contract_address=None): - address = contract_address or self.get_contract_address_by_name( - self.abi, name) + def add_lib_contract(self, name, contract_class, abi, contract_address=None): + address = contract_address or self.get_contract_address_by_name(abi, name) logger.info(f'Initialized: {name} at {address}') - abi = self.get_contract_abi_by_name(self.abi, name) if name == 'dkg': # todo: tmp fix - abi = self.get_contract_abi_by_name(self.abi, 'd_k_g') - self.add_contract(name, contract_class(self, name, address, abi)) + contract_abi = self.get_contract_abi_by_name(abi, 'd_k_g') + else: + contract_abi = self.get_contract_abi_by_name(abi, name) + self.add_contract(name, contract_class(self, name, address, contract_abi)) def get_contract_address_by_name(self, abi, name): if name == 'dkg': # todo: tmp fix diff --git a/tests/main_test.py b/tests/main_test.py index 4bbd02d1..ba7c4552 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -10,7 +10,6 @@ from skale.contracts import BaseContract from skale.contracts.functionality.nodes import Nodes from skale.contracts_info import CONTRACTS_INFO -from skale.utils.contract_info import ContractInfo from tests.constants import TEST_CONTRACT_NAME, ENDPOINT, TEST_ABI_FILEPATH, ETH_PRIVATE_KEY @@ -19,10 +18,6 @@ def test_lib_init(): wallet = Web3Wallet(ETH_PRIVATE_KEY, web3) skale = Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet, provider_timeout=20) - lib_contracts_info = skale._Skale__contracts_info - for contract_info in CONTRACTS_INFO: - assert isinstance(lib_contracts_info[contract_info.name], ContractInfo) - lib_contracts = skale._Skale__contracts assert len(lib_contracts) == len(CONTRACTS_INFO) @@ -31,11 +26,8 @@ def test_lib_init(): assert lib_contract.address is not None assert int(lib_contract.address, 16) != 0 assert web3.eth.getCode(lib_contract.address) - assert lib_contract.abi is not None assert skale.web3.provider._request_kwargs == {'timeout': 20} - assert skale.abi is not None - isinstance(skale.web3.provider, HTTPProvider) ws_endpoint = 'ws://localhost:8080'