accounts/abi/bind: constructor, auth utils and various backends

This commit is contained in:
Péter Szilágyi
2016-03-17 19:27:37 +02:00
parent 72826bb5ad
commit 86cfc22c79
10 changed files with 736 additions and 267 deletions

View File

@ -27,9 +27,10 @@ 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)")
pkgFlag = flag.String("pkg", "", "Go package name to generate the binding into")
typFlag = flag.String("type", "", "Go struct name for the binding (default = package name)")
outFlag = flag.String("out", "", "Output path for the generated binding")
outFlag = flag.String("out", "", "Output path for the generated binding (default = stdout)")
)
func main() {
@ -44,17 +45,25 @@ func main() {
fmt.Printf("No destination Go package specified (--pkg)\n")
os.Exit(-1)
}
// Generate the contract binding
in, err := ioutil.ReadFile(*abiFlag)
// Read the ABI json from disk and optionally the contract bytecode too
abi, err := ioutil.ReadFile(*abiFlag)
if err != nil {
fmt.Printf("Failed to read input ABI: %v\n", err)
os.Exit(-1)
}
bin := []byte{}
if *binFlag != "" {
if bin, err = ioutil.ReadFile(*binFlag); err != nil {
fmt.Printf("Failed to read input bytecode: %v\n", err)
os.Exit(-1)
}
}
// Generate the contract binding
kind := *typFlag
if kind == "" {
kind = *pkgFlag
}
code, err := bind.Bind(string(in), *pkgFlag, kind)
code, err := bind.Bind(string(abi), string(bin), *pkgFlag, kind)
if err != nil {
fmt.Printf("Failed to generate ABI binding: %v\n", err)
os.Exit(-1)