Skip to content

Commit 275cd49

Browse files
authored
cmd/abigen: Sanitize vyper's combined json names (#20419)
* cmd/abigen: Sanitize vyper's combined json names * Review feedback: handle full paths
1 parent f51cf57 commit 275cd49

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎cmd/abigen/main.go‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"fmt"
2222
"io/ioutil"
2323
"os"
24+
"path/filepath"
2425
"regexp"
2526
"strings"
2627

28+
"github.com/ethereum/go-ethereum/accounts/abi"
2729
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2830
"github.com/ethereum/go-ethereum/cmd/utils"
2931
"github.com/ethereum/go-ethereum/common/compiler"
@@ -193,10 +195,22 @@ func abigen(c *cli.Context) error {
193195
utils.Fatalf("Failed to build Solidity contract: %v", err)
194196
}
195197
case c.GlobalIsSet(vyFlag.Name):
196-
contracts, err = compiler.CompileVyper(c.GlobalString(vyperFlag.Name), c.GlobalString(vyFlag.Name))
198+
output, err := compiler.CompileVyper(c.GlobalString(vyperFlag.Name), c.GlobalString(vyFlag.Name))
197199
if err != nil {
198200
utils.Fatalf("Failed to build Vyper contract: %v", err)
199201
}
202+
contracts = make(map[string]*compiler.Contract)
203+
for n, contract := range output {
204+
name := n
205+
// Sanitize the combined json names to match the
206+
// format expected by solidity.
207+
if !strings.Contains(n, ":") {
208+
// Remove extra path components
209+
name = abi.ToCamelCase(strings.TrimSuffix(filepath.Base(name), ".vy"))
210+
}
211+
contracts[name] = contract
212+
}
213+
200214
case c.GlobalIsSet(jsonFlag.Name):
201215
jsonOutput, err := ioutil.ReadFile(c.GlobalString(jsonFlag.Name))
202216
if err != nil {

0 commit comments

Comments
 (0)