Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Use function signature when multiple functions are defined #1854

Merged
merged 1 commit into from
Aug 29, 2023
Merged
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
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