Commit f7a8e8ba authored by Mark Tyneway's avatar Mark Tyneway

op-bindings: fix generation

parent fd11bb78
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"text/template" "text/template"
...@@ -84,17 +85,22 @@ func main() { ...@@ -84,17 +85,22 @@ func main() {
// and hold a mapping from the contract name to the contract path. // and hold a mapping from the contract name to the contract path.
// Walk walks the directory deterministically, so the later instance // Walk walks the directory deterministically, so the later instance
// of the contract with the same name will be used // of the contract with the same name will be used
re := regexp.MustCompile(`\.\d+\.\d+\.\d+`)
artifactPaths := make(map[string]string) artifactPaths := make(map[string]string)
if err := filepath.Walk(f.ForgeArtifacts, if err := filepath.Walk(f.ForgeArtifacts,
func(path string, info os.FileInfo, err error) error { func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
base := filepath.Base(path)
if strings.HasSuffix(base, ".json") { if strings.HasSuffix(path, ".json") {
name := base[:len(base)-5] base := filepath.Base(path)
if _, ok := artifactPaths[name]; !ok { name := strings.TrimSuffix(base, ".json")
artifactPaths[name] = path
// remove the compiler version from the name
sanitized := re.ReplaceAllString(name, "")
if _, ok := artifactPaths[sanitized]; !ok {
artifactPaths[sanitized] = path
} }
} }
return nil return nil
...@@ -108,6 +114,7 @@ func main() { ...@@ -108,6 +114,7 @@ func main() {
artifactPath := path.Join(f.ForgeArtifacts, name+".sol", name+".json") artifactPath := path.Join(f.ForgeArtifacts, name+".sol", name+".json")
forgeArtifactData, err := os.ReadFile(artifactPath) forgeArtifactData, err := os.ReadFile(artifactPath)
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
log.Printf("cannot find forge-artifact for %s at standard path %s, trying %s\n", name, artifactPath, artifactPaths[name])
artifactPath = artifactPaths[name] artifactPath = artifactPaths[name]
forgeArtifactData, err = os.ReadFile(artifactPath) forgeArtifactData, err = os.ReadFile(artifactPath)
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment