Skip to content

Commit

Permalink
fix: add fallback gas for gas station API
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Jul 25, 2023
1 parent a9e01a1 commit 7834dc9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@

DEFAULT_GAS_STATION_STRATEGY = {"gas_price_api_key": "", "gas_price_strategy": "fast"}

GAS_STATION_FALLBACK_ESTIMATE = 20 # gwei

DEFAULT_GAS_PRICE_STRATEGIES = {
EIP1559: DEFAULT_EIP1559_STRATEGY,
GAS_STATION: DEFAULT_GAS_STATION_STRATEGY,
Expand Down Expand Up @@ -337,11 +339,16 @@ def gas_station_gas_price_strategy(
:param transaction_params: transaction parameters
:return: wei
"""
_default_logger.info( # pragma: nocover
"`ethgasstation.info` has been deprecated and will be replaced with an alternative on the next release."
)
response = requests.get(f"{ETH_GASSTATION_URL}?api-key={gas_price_api_key}")
if response.status_code != 200:
raise ValueError( # pragma: nocover
f"Gas station API response: {response.status_code}, {response.text}"
if response.status_code != 200: # pragma: nocover
# TODO : Use some other gas station API # pylint: disable=fixme
_default_logger.error(
f"Gas station API response: {response.status_code}, {response.text}, using fallback gas price."
)
return {"gasPrice": web3.toWei(GAS_STATION_FALLBACK_ESTIMATE, "gwei")}
response_dict = response.json()
_default_logger.debug("Gas station API response: {}".format(response_dict))
result = response_dict.get(gas_price_strategy, None)
Expand Down

0 comments on commit 7834dc9

Please sign in to comment.