From 00b02834beae119d24e60d09f0274347aee01da8 Mon Sep 17 00:00:00 2001 From: Kushagra Sharma Date: Fri, 15 Mar 2019 16:51:00 +0000 Subject: [PATCH] common/compiler, cmd/abigen: style --- cmd/abigen/main.go | 17 +++++++++++------ common/compiler/helpers.go | 2 +- common/compiler/solidity.go | 6 ++---- common/compiler/solidity_test.go | 2 +- common/compiler/vyper.go | 2 +- common/compiler/vyper_test.go | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index 132dec9f75..b6ec04ce16 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -1,4 +1,4 @@ -// Copyright 2016 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of go-ethereum. // // go-ethereum is free software: you can redistribute it and/or modify @@ -90,19 +90,21 @@ func main() { var contracts map[string]*compiler.Contract var err error - if *solFlag != "" { + + switch { + case *solFlag != "": contracts, err = compiler.CompileSolidity(*solcFlag, *solFlag) if err != nil { fmt.Printf("Failed to build Solidity contract: %v\n", err) os.Exit(-1) } - } else if *vyFlag != "" { + case *vyFlag != "": contracts, err = compiler.CompileVyper(*vyperFlag, *vyFlag) if err != nil { fmt.Printf("Failed to build Vyper contract: %v\n", err) os.Exit(-1) } - } else { + default: contracts, err = contractsFromStdin() if err != nil { fmt.Printf("Failed to read input ABIs from STDIN: %v\n", err) @@ -114,7 +116,11 @@ func main() { if exclude[strings.ToLower(name)] { continue } - abi, _ := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse + abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse + if err != nil { + fmt.Printf("Failed to parse ABIs from compiler output: %v\n", err) + os.Exit(-1) + } abis = append(abis, string(abi)) bins = append(bins, contract.Code) @@ -152,7 +158,6 @@ func main() { types = append(types, kind) } // Generate the contract binding - fmt.Printf("%+v", abis) code, err := bind.Bind(types, abis, bins, *pkgFlag, lang) if err != nil { fmt.Printf("Failed to generate ABI binding: %v\n", err) diff --git a/common/compiler/helpers.go b/common/compiler/helpers.go index 59e650a2c3..4de706f6b6 100644 --- a/common/compiler/helpers.go +++ b/common/compiler/helpers.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index 1692c41c1f..02346a1615 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify @@ -28,8 +28,6 @@ import ( "strings" ) -var solVersionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`) - // Solidity contains information about the solidity compiler. type Solidity struct { Path, Version, FullVersion string @@ -69,7 +67,7 @@ func SolidityVersion(solc string) (*Solidity, error) { if err != nil { return nil, err } - matches := solVersionRegexp.FindStringSubmatch(out.String()) + matches := versionRegexp.FindStringSubmatch(out.String()) if len(matches) != 4 { return nil, fmt.Errorf("can't parse solc version %q", out.String()) } diff --git a/common/compiler/solidity_test.go b/common/compiler/solidity_test.go index 491e3665e2..6be2bda52c 100644 --- a/common/compiler/solidity_test.go +++ b/common/compiler/solidity_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify diff --git a/common/compiler/vyper.go b/common/compiler/vyper.go index 7f0455925f..a9bca95e59 100644 --- a/common/compiler/vyper.go +++ b/common/compiler/vyper.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify diff --git a/common/compiler/vyper_test.go b/common/compiler/vyper_test.go index 68480ef5ca..7761c92aff 100644 --- a/common/compiler/vyper_test.go +++ b/common/compiler/vyper_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify