From 6cd053bcfef1691d90edc8c282a49fb2c877b14e Mon Sep 17 00:00:00 2001 From: Philip Schlump Date: Tue, 11 Sep 2018 20:17:58 -0600 Subject: [PATCH] abigen support for `--type` flag with piped data `abigen` fails to support the `--type` flag when data is piped to it. Ethereum Issue: #17647 This change is to fix the command line processing to support a piped ABI to `abigen` and use the `--type` flag. --- cmd/abigen/main.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index 3ac37ba7ad..994fc13503 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -75,7 +75,7 @@ func main() { bins []string types []string ) - if *solFlag != "" || *abiFlag == "-" { + if *solFlag != "" || (*abiFlag == "-" && *pkgFlag == "") { // Generate the list of types to exclude from binding exclude := make(map[string]bool) for _, kind := range strings.Split(*excFlag, ",") { @@ -111,10 +111,20 @@ func main() { } } else { // Otherwise load up the ABI, optional bytecode and type name from the parameters - abi, err := ioutil.ReadFile(*abiFlag) - if err != nil { - fmt.Printf("Failed to read input ABI: %v\n", err) - os.Exit(-1) + var abi []byte + var err error + if *abiFlag == "-" { + abi, err = ioutil.ReadAll(os.Stdin) + if err != nil { + fmt.Printf("Failed to read input ABI from stdin: %v\n", err) + os.Exit(-1) + } + } else { + abi, err = ioutil.ReadFile(*abiFlag) + if err != nil { + fmt.Printf("Failed to read input ABI: %v\n", err) + os.Exit(-1) + } } abis = append(abis, string(abi)) @@ -156,5 +166,10 @@ func contractsFromStdin() (map[string]*compiler.Contract, error) { return nil, err } - return compiler.ParseCombinedJSON(bytes, "", "", "", "") + code, err := compiler.ParseCombinedJSON(bytes, "", "", "", "") + if err != nil { + fmt.Printf("Error from parse: %s\n", err) + return nil, err + } + return code, nil }