Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/ethproto/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC, abstractmethod
from contextlib import contextmanager
from functools import partial
from warnings import warn

import requests
from environs import Env
Expand Down Expand Up @@ -283,9 +284,14 @@ def get_first_block(self, eth_wrapper):
resp = requests.get(url)
resp.raise_for_status()
resp = resp.json()
if not resp["result"]:
return -1
return int(resp["result"][0]["blockNumber"])
if resp.get("status") != "1":
warn(f"Failed to get first block from {etherscan_url}: {resp}")
return 0
try:
return int(resp["result"][0]["blockNumber"])
except (KeyError, TypeError):
warn(f"Failed to parse first block for {address}: {resp}")
return 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Antes respondía con -1 cuando no podía obtener el resultado, ahora devuelve 0. Porqué? Creo que sería mejor que devuelva -1 que es claro que no es un bloque válido.

O sino podría tirar excepción. De hecho tira excepción cuando falla el request (.raise_for_status()).

No me gusta lo de capturar los KeyError y TypeError. Qué tipo de error queremos manejar ahí?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo cambié para que levante excepción. Lo de KeyError y TypeError es para capturar todos los tipos de error que puede tener esa línea (si result es una cadena en vez de un array, si result no tiene blockNumber)... es solamente para levantar la respuesta completa en la excepción, porque si no es mucho mas dificil de debuggear cuando algo falla.


def get_contract_address(self, eth_wrapper):
return eth_wrapper.contract.address
Expand Down
Loading