From 240ce7fc346bd97e5109576e289a86084e03ac2e Mon Sep 17 00:00:00 2001 From: Pooya Fekri Date: Mon, 27 Nov 2023 09:32:46 +0330 Subject: [PATCH] Fix usage to deleted w3 in EVMFundManager --- core/utils.py | 3 +++ faucet/faucet_manager/fund_manager.py | 10 ++++++++-- faucet/models.py | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/utils.py b/core/utils.py index af4568ce..c28a4db7 100644 --- a/core/utils.py +++ b/core/utils.py @@ -146,3 +146,6 @@ def to_checksum_address(address: str): def get_transaction_receipt(self, hash): return self.w3.eth.get_transaction_receipt(hash) + + def get_balance(self, address): + self.w3.eth.get_balance(address) diff --git a/faucet/faucet_manager/fund_manager.py b/faucet/faucet_manager/fund_manager.py index 6e6874ea..dc761336 100644 --- a/faucet/faucet_manager/fund_manager.py +++ b/faucet/faucet_manager/fund_manager.py @@ -39,10 +39,13 @@ def __init__(self, chain: Chain): self.web3_utils.set_account(self.chain.wallet.main_key) self.web3_utils.set_contract(self.get_fund_manager_checksum_address(), abi=manager_abi) + def get_gas_price(self): + return self.web3_utils.get_gas_price() + @property def is_gas_price_too_high(self): try: - gas_price = self.web3_utils.get_gas_price() + gas_price = self.get_gas_price() logging.info(f"Gas price: {gas_price} vs max: {self.chain.max_gas_price}") if gas_price > self.chain.max_gas_price: return True @@ -51,6 +54,9 @@ def is_gas_price_too_high(self): logging.error(e) return True + def get_balance(self, address): + return self.web3_utils.get_balance(address) + def get_fund_manager_checksum_address(self): return self.web3_utils.to_checksum_address(self.chain.fund_manager_address) @@ -63,7 +69,7 @@ def multi_transfer(self, data): def _transfer(self, tx_function_str, *args): tx = self.prepare_tx_for_broadcast(tx_function_str, *args) try: - self.web3_utils.send_raw_tx(tx.rawTransaction) + self.web3_utils.send_raw_tx(tx) return tx["hash"].hex() except Exception as e: raise FundMangerException.RPCError(str(e)) diff --git a/faucet/models.py b/faucet/models.py index 178f15ac..25c8c72e 100644 --- a/faucet/models.py +++ b/faucet/models.py @@ -258,7 +258,7 @@ def get_manager_balance(self): if self.chain_type == NetworkTypes.EVM or int(self.chain_id) == 500: # if self.chain_id == 500: # logging.debug("chain XDC NONEVM is checking its balances") - funds = EVMFundManager(self).w3.eth.get_balance(self.fund_manager_address) + funds = EVMFundManager(self).get_balance(self.fund_manager_address) return funds elif self.chain_type == NetworkTypes.SOLANA: @@ -293,7 +293,7 @@ def get_wallet_balance(self): ) if self.chain_type == NetworkTypes.EVM or int(self.chain_id) == 500: - return EVMFundManager(self).w3.eth.get_balance(self.wallet.address) + return EVMFundManager(self).get_balance(self.wallet.address) elif self.chain_type == NetworkTypes.SOLANA: fund_manager = SolanaFundManager(self) v = fund_manager.w3.get_balance(Pubkey.from_string(self.wallet.address)).value @@ -325,7 +325,7 @@ def gas_price(self): try: from faucet.faucet_manager.fund_manager import EVMFundManager - return EVMFundManager(self).w3.eth.gas_price + return EVMFundManager(self).get_gas_price() except: # noqa: E722 logging.exception(f"Error getting gas price for {self.chain_name}") return self.max_gas_price + 1