mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
bind: not sure if I'm keeping these commits. Waiting for advice
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
b39afc674c
commit
573181c8ba
2 changed files with 35 additions and 17 deletions
|
|
@ -41,6 +41,26 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,12 @@ var (
|
||||||
abiFlag = flag.String("abi", "", "Path to the Ethereum contract ABI json to bind")
|
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)")
|
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")
|
linkFlag = flag.String("link", "", "Library flag linker for name to addresses in the code")
|
||||||
solcFlag = flag.String("solc", "solc", "Solidity compiler to use if source builds are requested")
|
solFlag = flag.String("sol", "", "Comma separated path(s) to Solidity source(s) to build and bind")
|
||||||
excFlag = flag.String("exc", "", "Comma separated types to exclude from binding")
|
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")
|
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)")
|
||||||
|
|
@ -53,6 +54,9 @@ 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")
|
||||||
|
|
@ -77,21 +81,15 @@ func main() {
|
||||||
types []string
|
types []string
|
||||||
)
|
)
|
||||||
if *solFlag != "" {
|
if *solFlag != "" {
|
||||||
// Generate the list of types to exclude from binding
|
solc, err := compiler.InitSolc(*solcFlag)
|
||||||
exclude := make(map[string]bool)
|
|
||||||
for _, kind := range strings.Split(*excFlag, ",") {
|
|
||||||
exclude[strings.ToLower(kind)] = true
|
|
||||||
}
|
|
||||||
contracts, err := compiler.CompileSolidity(*solcFlag, *solFlag)
|
|
||||||
if err != nil {
|
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)
|
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 contracts {
|
||||||
if exclude[strings.ToLower(name)] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
abi, _ := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
|
abi, _ := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
|
||||||
abis = append(abis, string(abi))
|
abis = append(abis, string(abi))
|
||||||
bins = append(bins, contract.Code)
|
bins = append(bins, contract.Code)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue