本文整理匯總了Golang中github.com/ethereum/go-ethereum/accounts.Manager.AddressByIndex方法的典型用法代碼示例。如果您正苦於以下問題:Golang Manager.AddressByIndex方法的具體用法?Golang Manager.AddressByIndex怎麽用?Golang Manager.AddressByIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ethereum/go-ethereum/accounts.Manager
的用法示例。
在下文中一共展示了Manager.AddressByIndex方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ParamToAddress
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
}
示例2: MakeAddress
// 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
}