Skip to content

Commit 63f1462

Browse files
fix: correct function signatures
1 parent 7787749 commit 63f1462

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

configuration/types.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import re
23
from typing import Callable, Self
34

45
from attrs import field, frozen
@@ -18,13 +19,15 @@ def abi_from_file_location(file_location):
1819

1920

2021
def event_signature(event_abi: ABIEvent) -> str:
22+
assert "inputs" in event_abi
2123
params = ""
2224
for index, input in enumerate(event_abi["inputs"]):
2325
if index > 0:
2426
params += ","
2527

2628
if input["type"] == "tuple[]":
2729
params += "("
30+
assert "components" in input
2831
for index2, tuple_component in enumerate(input["components"]):
2932
if index2 > 0:
3033
params += ","
@@ -35,6 +38,7 @@ def event_signature(event_abi: ABIEvent) -> str:
3538

3639
elif input["type"] == "tuple":
3740
params += "("
41+
assert "components" in input
3842
for index2, tuple_component in enumerate(input["components"]):
3943
if index2 > 0:
4044
params += ","
@@ -53,6 +57,31 @@ def function_signature(function_name: str) -> str:
5357
return Web3.keccak(text=function_name).hex()[:8]
5458

5559

60+
def canonicalize_base_type(base: str) -> str:
61+
if base == "uint":
62+
return "uint256"
63+
if base == "int":
64+
return "int256"
65+
return base
66+
67+
68+
def full_type_from_param(param) -> str:
69+
t = param["type"]
70+
m = re.match(r"([^\[]+)(.*)$", t)
71+
# parameter types will match this regex
72+
assert m
73+
base = m.group(1)
74+
suffix = m.group(2) or ""
75+
76+
if base == "tuple":
77+
comps = param.get("components", [])
78+
inner = ",".join(full_type_from_param(c) for c in comps)
79+
return f"({inner}){suffix}"
80+
else:
81+
base_canon = canonicalize_base_type(base)
82+
return f"{base_canon}{suffix}"
83+
84+
5685
@frozen
5786
class Event:
5887
name: str
@@ -79,8 +108,9 @@ class Function:
79108

80109
def to_full_name(self):
81110
assert "inputs" in self.abi
82-
inputs = [i["type"] for i in self.abi["inputs"]] # type: ignore
83-
return f"{self.name}({','.join(inputs)})"
111+
inputs = self.abi["inputs"]
112+
types = ",".join(full_type_from_param(inp) for inp in inputs)
113+
return f"{self.name}({types})"
84114

85115
def __str__(self) -> str:
86116
return f"Function: {self.to_full_name()}, signature: {self.signature}"

0 commit comments

Comments
 (0)