diff --git a/types/account.go b/types/account.go index 00d180a1c7..fa471ab49f 100644 --- a/types/account.go +++ b/types/account.go @@ -62,6 +62,15 @@ func GetAccAddressBech32(address string) (addr Address, err error) { return Address(bz), nil } +// must create an Address from a string +func MustGetAccAddressBech32(address string) Address { + addr, err := GetAccAddressBech32(address) + if err != nil { + panic(err) + } + return addr +} + // create a Pubkey from a string func GetAccPubKeyBech32(address string) (pk crypto.PubKey, err error) { bz, err := getFromBech32(address, Bech32PrefixAccPub) @@ -77,6 +86,15 @@ func GetAccPubKeyBech32(address string) (pk crypto.PubKey, err error) { return pk, nil } +// must create a Pubkey from a string +func MustGetAccPubkeyBec32(address string) crypto.PubKey { + pk, err := GetAccPubKeyBech32(address) + if err != nil { + panic(err) + } + return pk +} + // create an Address from a hex string func GetValAddressHex(address string) (addr Address, err error) { if len(address) == 0 { @@ -98,7 +116,16 @@ func GetValAddressBech32(address string) (addr Address, err error) { return Address(bz), nil } -//Decode a validator publickey into a public key +// must create an Address from a bech32 string +func MustGetValAddressBech32(address string) Address { + addr, err := GetValAddressBech32(address) + if err != nil { + panic(err) + } + return addr +} + +// decode a validator public key into a PubKey func GetValPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) { bz, err := getFromBech32(pubkey, Bech32PrefixValPub) if err != nil { @@ -113,6 +140,15 @@ func GetValPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) { return pk, nil } +// must decode a validator public key into a PubKey +func MustGetValPubKeyBech32(pubkey string) crypto.PubKey { + pk, err := GetValPubKeyBech32(pubkey) + if err != nil { + panic(err) + } + return pk +} + func getFromBech32(bech32str, prefix string) ([]byte, error) { if len(bech32str) == 0 { return nil, errors.New("must provide non-empty string")