From 436915563e12bf6ff91faedb531bcbcbe15884f1 Mon Sep 17 00:00:00 2001 From: Roman Behma <13855864+begmaroman@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:54:04 +0100 Subject: [PATCH] Use function signature when multiple functions are defined #1854 --- .../polybft/contractsapi/bindings-gen/main.go | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/consensus/polybft/contractsapi/bindings-gen/main.go b/consensus/polybft/contractsapi/bindings-gen/main.go index 520cee5d37..e081c12734 100644 --- a/consensus/polybft/contractsapi/bindings-gen/main.go +++ b/consensus/polybft/contractsapi/bindings-gen/main.go @@ -6,6 +6,7 @@ import ( "fmt" "go/format" "log" + "regexp" "strconv" "strings" "text/template" @@ -23,6 +24,10 @@ const ( functionNameFormat = "%sFn" ) +var ( + signatureFunctionFormat = regexp.MustCompile(`^(.*)\((.*)\)$`) +) + type generatedData struct { resultString []string structs []string @@ -105,7 +110,7 @@ func main() { gensc.ChildERC20PredicateACL, false, []string{ - "initialize", + "initialize(address,address,address,address,address,bool,bool,address)", "withdrawTo", }, []string{}, @@ -415,8 +420,18 @@ func main() { } } - for _, method := range c.functions { - if err := generateFunction(generatedData, c.contractName, c.artifact.Abi.Methods[method]); err != nil { + for _, methodRaw := range c.functions { + // There could be two objects with the same name in the generated JSON ABI (hardhat bug). + // This case can be fixed by specifying a function signature instead of just name + // e.g. "myFunc(address,bool,uint256)" instead of just "myFunc" + var method *abi.Method + if signatureFunctionFormat.MatchString(methodRaw) { + method = c.artifact.Abi.GetMethodBySignature(methodRaw) + } else { + method = c.artifact.Abi.GetMethod(methodRaw) + } + + if err := generateFunction(generatedData, c.contractName, method); err != nil { log.Fatal(err) } }