mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
bind,abigen: decide to play this a bit more conservatively
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
573181c8ba
commit
d3baeb21ae
2 changed files with 18 additions and 35 deletions
|
|
@ -41,26 +41,6 @@ const (
|
||||||
LangObjC
|
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
|
// 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
|
// 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
|
// enforces compile time type safety and naming convention opposed to having to
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,9 @@ var (
|
||||||
binFlag = flag.String("bin", "", "Path to the Ethereum contract bytecode (generate deploy method)")
|
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)")
|
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")
|
solFlag = flag.String("sol", "", "Path to the Ethereum contract Solidity source to build and bind")
|
||||||
solFlag = flag.String("sol", "", "Comma separated path(s) to Solidity source(s) to build and bind")
|
solcFlag = flag.String("solc", "solc", "Solidity compiler to use if source builds are requested")
|
||||||
pathsFlag = flag.String("paths", "", "Comma separated path(s) in the form of solidity remappings (advanced only)")
|
excFlag = flag.String("exc", "", "Comma separated types to exclude from binding")
|
||||||
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")
|
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)")
|
||||||
|
|
@ -54,9 +52,6 @@ func main() {
|
||||||
} else if (*abiFlag != "" || *binFlag != "" || *typFlag != "") && *solFlag != "" {
|
} 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")
|
fmt.Printf("Contract ABI (--abi), bytecode (--bin) and type (--type) flags are mutually exclusive with the Solidity source (--sol) flag\n")
|
||||||
os.Exit(-1)
|
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 == "" {
|
if *pkgFlag == "" {
|
||||||
fmt.Printf("No destination package specified (--pkg)\n")
|
fmt.Printf("No destination package specified (--pkg)\n")
|
||||||
|
|
@ -81,18 +76,26 @@ func main() {
|
||||||
types []string
|
types []string
|
||||||
)
|
)
|
||||||
if *solFlag != "" {
|
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
|
||||||
|
}
|
||||||
solc, err := compiler.InitSolc(*solcFlag)
|
solc, err := compiler.InitSolc(*solcFlag)
|
||||||
|
|
||||||
|
solReturn, err := solc.Compile(compiler.SolcFlagOpts{}, *solFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to initialize Solidity compiler: %v\n", err)
|
fmt.Printf("Failed to build Solidity contract: %v\n", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
solc.Compile(compiler.FlagOpts{}, strings.Split(*solFlag, ","))
|
|
||||||
// Gather all non-excluded contract for binding
|
// Gather all non-excluded contract for binding
|
||||||
for name, contract := range contracts {
|
for name, contract := range solReturn.Contracts {
|
||||||
abi, _ := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
|
if exclude[strings.ToLower(name)] {
|
||||||
abis = append(abis, string(abi))
|
continue
|
||||||
bins = append(bins, contract.Code)
|
}
|
||||||
|
|
||||||
|
abis = append(abis, contract.Abi)
|
||||||
|
bins = append(bins, contract.Bin)
|
||||||
|
|
||||||
nameParts := strings.Split(name, ":")
|
nameParts := strings.Split(name, ":")
|
||||||
types = append(types, nameParts[len(nameParts)-1])
|
types = append(types, nameParts[len(nameParts)-1])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue