Skip to content

Commit

Permalink
Skip compiled function singature structure (#138)
Browse files Browse the repository at this point in the history
- skip compiled structure from `4bytes`
  • Loading branch information
kchojn authored Apr 6, 2022
1 parent 33cd18c commit cdd7193
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ethtx/providers/signature_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
from abc import ABC, abstractmethod
from json import JSONDecodeError
from typing import Dict, List, Any, Iterator, TypedDict, Union, Tuple
from typing import Dict, List, Any, Iterator, TypedDict, Union, Tuple, Optional

import requests

Expand Down Expand Up @@ -68,7 +68,8 @@ def get_function(self, signature: str) -> Iterator[SignatureReturnType]:
)

for function in reversed(data):
yield self._parse_text_signature_response(function)
if parsed := self._parse_text_signature_response(function):
yield parsed

def get_event(self, signature: str) -> Iterator[SignatureReturnType]:
if signature == "0x":
Expand All @@ -79,7 +80,8 @@ def get_event(self, signature: str) -> Iterator[SignatureReturnType]:
)

for event in reversed(data):
yield self._parse_text_signature_response(event)
if parsed := self._parse_text_signature_response(event):
yield parsed

def url(self, endpoint: str) -> str:
return f"{self.API_URL}/{endpoint}/"
Expand Down Expand Up @@ -135,7 +137,7 @@ def _get(
return {}

@staticmethod
def _parse_text_signature_response(data: Dict) -> SignatureReturnType:
def _parse_text_signature_response(data: Dict) -> Optional[SignatureReturnType]:
text_sig = data.get("text_signature", "")

name = text_sig.split("(")[0] if text_sig else ""
Expand All @@ -145,6 +147,9 @@ def _parse_text_signature_response(data: Dict) -> SignatureReturnType:
)
if "(" in types:
args = tuple(types[types.find("(") + 1 : types.rfind(")")].split(","))
if any("(" in arg for arg in args):
log.warning("Could not parse signature: %s", text_sig)
return None
else:
args = list(filter(None, types.split(",")))

Expand Down

0 comments on commit cdd7193

Please sign in to comment.