Skip to content
Open
Changes from all commits
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: 8 additions & 4 deletions src/opengradient/client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from pathlib import Path
from typing import Callable

from .exceptions import OpenGradientError

_ABI_DIR = Path(__file__).parent.parent / "abi"
_BIN_DIR = Path(__file__).parent.parent / "bin"

Expand All @@ -22,7 +20,8 @@ def get_abi(abi_name: str) -> dict:
"""Returns the ABI for the requested contract."""
abi_path = _ABI_DIR / abi_name
with open(abi_path, "r") as f:
return json.load(f)
result: dict = json.load(f)
return result


def get_bin(bin_name: str) -> str:
Expand Down Expand Up @@ -50,6 +49,9 @@ def run_with_retry(
"""
effective_retries = max_retries if max_retries is not None else DEFAULT_MAX_RETRY

if effective_retries < 1:
raise ValueError(f"max_retries must be at least 1, got {effective_retries}")

for attempt in range(effective_retries):
try:
return txn_function()
Expand All @@ -58,8 +60,10 @@ def run_with_retry(

if any(error in error_msg for error in _NONCE_ERRORS):
if attempt == effective_retries - 1:
raise OpenGradientError(f"Transaction failed after {effective_retries} attempts: {e}")
raise RuntimeError(f"Transaction failed after {effective_retries} attempts: {e}")
time.sleep(retry_delay)
continue

raise

raise RuntimeError(f"run_with_retry exhausted {effective_retries} attempts without returning or raising")
Loading