From 573181c8ba1fe15d0afdd9249d887b14b558f65b Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Sun, 20 Aug 2017 13:04:44 -0500 Subject: [PATCH] bind: not sure if I'm keeping these commits. Waiting for advice Signed-off-by: RJ Catalano --- accounts/abi/bind/bind.go | 20 ++++++++++++++++++++ cmd/abigen/main.go | 32 +++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 73e95e02a1..762008d9bf 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -41,6 +41,26 @@ const ( LangObjC ) +type BindOpts struct { + Abi string + Bin string + Typ string + + Link string + SolFiles string + RemapPaths string + Compiler string + Exec string + + Lang Lang + Pkg string + OutputFile string +} + +func CompileAndBind(files ...string) + +func BindIndividualFiles(abis string, bytecodes string, pkg string, lang Lang) + // Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant // to be used as is in client code, but rather as an intermediate struct which // enforces compile time type safety and naming convention opposed to having to diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index f63b3fa7a7..fd4ac7f1e3 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -29,14 +29,15 @@ import ( ) var ( - abiFlag = flag.String("abi", "", "Path to the Ethereum contract ABI json to bind") - binFlag = flag.String("bin", "", "Path to the Ethereum contract bytecode (generate deploy method)") - typFlag = flag.String("type", "", "Struct name for the binding (default = package name)") - linkFlag = flag.String("link", "", "Library flag linker for name to addresses in the code") + abiFlag = flag.String("abi", "", "Path to the Ethereum contract ABI json to bind") + binFlag = flag.String("bin", "", "Path to the Ethereum contract bytecode (generate deploy method)") + typFlag = flag.String("type", "", "Struct name for the binding (default = package name)") - solFlag = flag.String("sol", "", "Path to the Ethereum contract Solidity source to build and bind") - 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") + linkFlag = flag.String("link", "", "Library flag linker for name to addresses in the code") + solFlag = flag.String("sol", "", "Comma separated path(s) to Solidity source(s) to build and bind") + pathsFlag = flag.String("paths", "", "Comma separated path(s) in the form of solidity remappings (advanced only)") + solcFlag = flag.String("compiler", "solc", "Compiler to use if source builds are requested (default = solc)") + execFlag = flag.String("exec", "", "Execute compiler with user generated command, advanced only, use commas to represent spaces in one string") pkgFlag = flag.String("pkg", "", "Package name to generate the binding into") outFlag = flag.String("out", "", "Output file for the generated binding (default = stdout)") @@ -53,6 +54,9 @@ func main() { } else if (*abiFlag != "" || *binFlag != "" || *typFlag != "") && *solFlag != "" { fmt.Printf("Contract ABI (--abi), bytecode (--bin) and type (--type) flags are mutually exclusive with the Solidity source (--sol) flag\n") os.Exit(-1) + } else if (*binFlag == "" || *solFlag == "") && *linkFlag != "" { + fmt.Printf("No contract bytecode created through (--bin) or (--sol) options to use with (--link) option\n") + os.Exit(-1) } if *pkgFlag == "" { fmt.Printf("No destination package specified (--pkg)\n") @@ -77,21 +81,15 @@ func main() { types []string ) if *solFlag != "" { - // Generate the list of types to exclude from binding - exclude := make(map[string]bool) - for _, kind := range strings.Split(*excFlag, ",") { - exclude[strings.ToLower(kind)] = true - } - contracts, err := compiler.CompileSolidity(*solcFlag, *solFlag) + solc, err := compiler.InitSolc(*solcFlag) if err != nil { - fmt.Printf("Failed to build Solidity contract: %v\n", err) + fmt.Printf("Failed to initialize Solidity compiler: %v\n", err) os.Exit(-1) } + + solc.Compile(compiler.FlagOpts{}, strings.Split(*solFlag, ",")) // Gather all non-excluded contract for binding for name, contract := range contracts { - if exclude[strings.ToLower(name)] { - continue - } abi, _ := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse abis = append(abis, string(abi)) bins = append(bins, contract.Code)