cmd/abigen: added vyper support in abigen

This commit is contained in:
Kushagra Sharma 2019-02-18 20:16:16 +00:00
parent 49ff08be6d
commit 192c5bfd61

View file

@ -37,6 +37,9 @@ var (
solcFlag = flag.String("solc", "solc", "Solidity compiler to use if source builds are requested") solcFlag = flag.String("solc", "solc", "Solidity compiler to use if source builds are requested")
excFlag = flag.String("exc", "", "Comma separated types to exclude from binding") excFlag = flag.String("exc", "", "Comma separated types to exclude from binding")
vyFlag = flag.String("vy", "", "Path to the Ethereum contract Vyper source to build and bind")
vyperFlag = flag.String("vyper", "vyper", "Vyper compiler to use if source builds are requested")
pkgFlag = flag.String("pkg", "", "Package name to generate the binding into") pkgFlag = flag.String("pkg", "", "Package name to generate the binding into")
outFlag = flag.String("out", "", "Output file for the generated binding (default = stdout)") outFlag = flag.String("out", "", "Output file for the generated binding (default = stdout)")
langFlag = flag.String("lang", "go", "Destination language for the bindings (go, java, objc)") langFlag = flag.String("lang", "go", "Destination language for the bindings (go, java, objc)")
@ -46,11 +49,14 @@ func main() {
// Parse and ensure all needed inputs are specified // Parse and ensure all needed inputs are specified
flag.Parse() flag.Parse()
if *abiFlag == "" && *solFlag == "" { if *abiFlag == "" && *solFlag == "" && *vyFlag == "" {
fmt.Printf("No contract ABI (--abi) or Solidity source (--sol) specified\n") fmt.Printf("No contract ABI (--abi), Solidity source (--sol), or Vyper source (--vy) specified\n")
os.Exit(-1) os.Exit(-1)
} else if (*abiFlag != "" || *binFlag != "" || *typFlag != "") && *solFlag != "" { } else if (*abiFlag != "" || *binFlag != "" || *typFlag != "") && (*solFlag != "" || *vyFlag != "") {
fmt.Printf("Contract ABI (--abi), bytecode (--bin) and type (--type) flags are mutually exclusive with the Solidity source (--sol) flag\n") fmt.Printf("Contract ABI (--abi), bytecode (--bin) and type (--type) flags are mutually exclusive with the Solidity (--sol) and Vyper (--vy) flags\n")
os.Exit(-1)
} else if *solFlag != "" && *vyFlag != "" {
fmt.Printf("Solidity (--sol) and Vyper (--vy) flags are mutually exclusive\n")
os.Exit(-1) os.Exit(-1)
} }
if *pkgFlag == "" { if *pkgFlag == "" {
@ -75,7 +81,7 @@ func main() {
bins []string bins []string
types []string types []string
) )
if *solFlag != "" || (*abiFlag == "-" && *pkgFlag == "") { if *solFlag != "" || *vyFlag != "" || (*abiFlag == "-" && *pkgFlag == "") {
// Generate the list of types to exclude from binding // Generate the list of types to exclude from binding
exclude := make(map[string]bool) exclude := make(map[string]bool)
for _, kind := range strings.Split(*excFlag, ",") { for _, kind := range strings.Split(*excFlag, ",") {
@ -90,6 +96,12 @@ func main() {
fmt.Printf("Failed to build Solidity contract: %v\n", err) fmt.Printf("Failed to build Solidity contract: %v\n", err)
os.Exit(-1) os.Exit(-1)
} }
} else if *vyFlag != "" {
contracts, err = compiler.CompileVyper(*vyperFlag, *vyFlag)
if err != nil {
fmt.Printf("Failed to build Vyper contract: %v\n", err)
os.Exit(-1)
}
} else { } else {
contracts, err = contractsFromStdin() contracts, err = contractsFromStdin()
if err != nil { if err != nil {