-
Notifications
You must be signed in to change notification settings - Fork 21.5k
common/compiler, cmd/abigen: remove solc/vyper compiler integration #24935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,19 +17,15 @@ | |
| package main | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "errors" | ||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/ethereum/go-ethereum/cmd/utils" | ||
| "github.com/ethereum/go-ethereum/common/compiler" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| "github.com/ethereum/go-ethereum/internal/flags" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "gopkg.in/urfave/cli.v1" | ||
|
|
@@ -59,24 +55,6 @@ var ( | |
| Name: "combined-json", | ||
| Usage: "Path to the combined-json file generated by compiler", | ||
| } | ||
| solFlag = cli.StringFlag{ | ||
| Name: "sol", | ||
| Usage: "Path to the Ethereum contract Solidity source to build and bind", | ||
| } | ||
| solcFlag = cli.StringFlag{ | ||
| Name: "solc", | ||
| Usage: "Solidity compiler to use if source builds are requested", | ||
| Value: "solc", | ||
| } | ||
| vyFlag = cli.StringFlag{ | ||
| Name: "vy", | ||
| Usage: "Path to the Ethereum contract Vyper source to build and bind", | ||
| } | ||
| vyperFlag = cli.StringFlag{ | ||
| Name: "vyper", | ||
| Usage: "Vyper compiler to use if source builds are requested", | ||
| Value: "vyper", | ||
| } | ||
| excFlag = cli.StringFlag{ | ||
| Name: "exc", | ||
| Usage: "Comma separated types to exclude from binding", | ||
|
|
@@ -107,10 +85,6 @@ func init() { | |
| binFlag, | ||
| typeFlag, | ||
| jsonFlag, | ||
| solFlag, | ||
| solcFlag, | ||
| vyFlag, | ||
| vyperFlag, | ||
| excFlag, | ||
| pkgFlag, | ||
| outFlag, | ||
|
|
@@ -122,10 +96,13 @@ func init() { | |
| } | ||
|
|
||
| func abigen(c *cli.Context) error { | ||
| utils.CheckExclusive(c, abiFlag, jsonFlag, solFlag, vyFlag) // Only one source can be selected. | ||
| utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected. | ||
| if c.GlobalString(pkgFlag.Name) == "" { | ||
| utils.Fatalf("No destination package specified (--pkg)") | ||
| } | ||
| if c.GlobalString(abiFlag.Name) == "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json can also be a source of abigen, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh well spotted!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bleh, that brings back solidity.go and |
||
| return errors.New("abi flag must be specified") | ||
| } | ||
| var lang bind.Lang | ||
| switch c.GlobalString(langFlag.Name) { | ||
| case "go": | ||
|
|
@@ -146,101 +123,37 @@ func abigen(c *cli.Context) error { | |
| sigs []map[string]string | ||
| libs = make(map[string]string) | ||
| aliases = make(map[string]string) | ||
| abi []byte | ||
| err error | ||
| ) | ||
| if c.GlobalString(abiFlag.Name) != "" { | ||
| // Load up the ABI, optional bytecode and type name from the parameters | ||
| var ( | ||
| abi []byte | ||
| err error | ||
| ) | ||
| input := c.GlobalString(abiFlag.Name) | ||
| if input == "-" { | ||
| abi, err = io.ReadAll(os.Stdin) | ||
| } else { | ||
| abi, err = os.ReadFile(input) | ||
| } | ||
| if err != nil { | ||
| utils.Fatalf("Failed to read input ABI: %v", err) | ||
| } | ||
| abis = append(abis, string(abi)) | ||
|
|
||
| var bin []byte | ||
| if binFile := c.GlobalString(binFlag.Name); binFile != "" { | ||
| if bin, err = os.ReadFile(binFile); err != nil { | ||
| utils.Fatalf("Failed to read input bytecode: %v", err) | ||
| } | ||
| if strings.Contains(string(bin), "//") { | ||
| utils.Fatalf("Contract has additional library references, please use other mode(e.g. --combined-json) to catch library infos") | ||
| } | ||
| } | ||
| bins = append(bins, string(bin)) | ||
|
|
||
| kind := c.GlobalString(typeFlag.Name) | ||
| if kind == "" { | ||
| kind = c.GlobalString(pkgFlag.Name) | ||
| } | ||
| types = append(types, kind) | ||
| // Load up the ABI, optional bytecode and type name from the parameters | ||
| if input := c.GlobalString(abiFlag.Name); input == "-" { | ||
| abi, err = io.ReadAll(os.Stdin) | ||
| } else { | ||
| // Generate the list of types to exclude from binding | ||
| exclude := make(map[string]bool) | ||
| for _, kind := range strings.Split(c.GlobalString(excFlag.Name), ",") { | ||
| exclude[strings.ToLower(kind)] = true | ||
| } | ||
| var err error | ||
| var contracts map[string]*compiler.Contract | ||
|
|
||
| switch { | ||
| case c.GlobalIsSet(solFlag.Name): | ||
| contracts, err = compiler.CompileSolidity(c.GlobalString(solcFlag.Name), c.GlobalString(solFlag.Name)) | ||
| if err != nil { | ||
| utils.Fatalf("Failed to build Solidity contract: %v", err) | ||
| } | ||
| case c.GlobalIsSet(vyFlag.Name): | ||
| output, err := compiler.CompileVyper(c.GlobalString(vyperFlag.Name), c.GlobalString(vyFlag.Name)) | ||
| if err != nil { | ||
| utils.Fatalf("Failed to build Vyper contract: %v", err) | ||
| } | ||
| contracts = make(map[string]*compiler.Contract) | ||
| for n, contract := range output { | ||
| name := n | ||
| // Sanitize the combined json names to match the | ||
| // format expected by solidity. | ||
| if !strings.Contains(n, ":") { | ||
| // Remove extra path components | ||
| name = abi.ToCamelCase(strings.TrimSuffix(filepath.Base(name), ".vy")) | ||
| } | ||
| contracts[name] = contract | ||
| } | ||
| abi, err = os.ReadFile(input) | ||
| } | ||
| if err != nil { | ||
| utils.Fatalf("Failed to read input ABI: %v", err) | ||
| } | ||
| abis = append(abis, string(abi)) | ||
|
|
||
| case c.GlobalIsSet(jsonFlag.Name): | ||
| jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name)) | ||
| if err != nil { | ||
| utils.Fatalf("Failed to read combined-json from compiler: %v", err) | ||
| } | ||
| contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "") | ||
| if err != nil { | ||
| utils.Fatalf("Failed to read contract information from json output: %v", err) | ||
| } | ||
| var bin []byte | ||
| if binFile := c.GlobalString(binFlag.Name); binFile != "" { | ||
| if bin, err = os.ReadFile(binFile); err != nil { | ||
| utils.Fatalf("Failed to read input bytecode: %v", err) | ||
| } | ||
| // Gather all non-excluded contract for binding | ||
| for name, contract := range contracts { | ||
| if exclude[strings.ToLower(name)] { | ||
| continue | ||
| } | ||
| abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse | ||
| if err != nil { | ||
| utils.Fatalf("Failed to parse ABIs from compiler output: %v", err) | ||
| } | ||
| abis = append(abis, string(abi)) | ||
| bins = append(bins, contract.Code) | ||
| sigs = append(sigs, contract.Hashes) | ||
| nameParts := strings.Split(name, ":") | ||
| types = append(types, nameParts[len(nameParts)-1]) | ||
|
|
||
| libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] | ||
| libs[libPattern] = nameParts[len(nameParts)-1] | ||
| if strings.Contains(string(bin), "//") { | ||
| utils.Fatalf("Contract has additional library references, please use other mode(e.g. --combined-json) to catch library infos") | ||
| } | ||
| } | ||
| bins = append(bins, string(bin)) | ||
|
|
||
| kind := c.GlobalString(typeFlag.Name) | ||
| if kind == "" { | ||
| kind = c.GlobalString(pkgFlag.Name) | ||
| } | ||
| types = append(types, kind) | ||
|
|
||
| // Extract all aliases from the flags | ||
| if c.GlobalIsSet(aliasFlag.Name) { | ||
| // We support multi-versions for aliasing | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goimports