Skip to content

Commit

Permalink
Use function signature when multiple functions are defined #1854
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Aug 29, 2023
1 parent b4c0051 commit 4369155
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions consensus/polybft/contractsapi/bindings-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"go/format"
"log"
"regexp"
"strconv"
"strings"
"text/template"
Expand All @@ -23,6 +24,10 @@ const (
functionNameFormat = "%sFn"
)

var (
signatureFunctionFormat = regexp.MustCompile(`^(.*)\((.*)\)$`)
)

type generatedData struct {
resultString []string
structs []string
Expand Down Expand Up @@ -105,7 +110,7 @@ func main() {
gensc.ChildERC20PredicateACL,
false,
[]string{
"initialize",
"initialize(address,address,address,address,address,bool,bool,address)",
"withdrawTo",
},
[]string{},
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 4369155

Please sign in to comment.