func ParamToAddress(addr string, am *accounts.Manager) (addrHex string, err error) { if !((len(addr) == 40) || (len(addr) == 42)) { // with or without 0x index, err := strconv.Atoi(addr) if err != nil { Fatalf("Invalid account address '%s'", addr) } addrHex, err = am.AddressByIndex(index) if err != nil { return "", err } } else { addrHex = addr } return }
// MakeAddress converts an account specified directly as a hex encoded string or // a key index in the key store to an internal account representation. func MakeAddress(accman *accounts.Manager, account string) (a common.Address, err error) { // If the specified account is a valid address, return it if common.IsHexAddress(account) { return common.HexToAddress(account), nil } // Otherwise try to interpret the account as a keystore index index, err := strconv.Atoi(account) if err != nil { return a, fmt.Errorf("invalid account address or index %q", account) } hex, err := accman.AddressByIndex(index) if err != nil { return a, fmt.Errorf("can't get account #%d (%v)", index, err) } return common.HexToAddress(hex), nil }