cmd/abigen: address comments

This commit is contained in:
rjl493456442 2019-11-13 11:26:55 +08:00
parent 2a7e4442fc
commit c166c8da0a

View file

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"regexp"
"strings" "strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
@ -240,24 +241,16 @@ func abigen(c *cli.Context) error {
} }
// Extract all aliases from the flags // Extract all aliases from the flags
if c.GlobalIsSet(aliasFlag.Name) { if c.GlobalIsSet(aliasFlag.Name) {
v := strings.Split(c.GlobalString(aliasFlag.Name), ",") // We support multi-versions for aliasing
for _, alias := range v { // e.g.
// We support multi-versions for aliasing // foo=bar,foo2=bar2
// e.g. // foo:bar,foo2:bar2
// foo=bar re := regexp.MustCompile(`(?:(\w+)[:=](\w+))`)
// foo:bar submatches := re.FindAllStringSubmatch(c.GlobalString(aliasFlag.Name), -1)
index := strings.Index(alias, ":") for _, match := range submatches {
if index == -1 { aliases[match[1]] = match[2]
index = strings.Index(alias, "=")
}
// Filter out invalid aliasing
if index == -1 || index == 0 || index == len(alias)-1 {
continue
}
aliases[alias[:index]] = alias[index+1:] // Add to the aliasing map
} }
} }
// Generate the contract binding // Generate the contract binding
code, err := bind.Bind(types, abis, bins, sigs, c.GlobalString(pkgFlag.Name), lang, libs, aliases) code, err := bind.Bind(types, abis, bins, sigs, c.GlobalString(pkgFlag.Name), lang, libs, aliases)
if err != nil { if err != nil {