Skip to content

Commit

Permalink
Fix usage to deleted w3 in EVMFundManager
Browse files Browse the repository at this point in the history
  • Loading branch information
PooyaFekri committed Nov 27, 2023
1 parent dcf08f3 commit 240ce7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 8 additions & 2 deletions faucet/faucet_manager/fund_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions faucet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 240ce7f

Please sign in to comment.