Add MustUnBech32() functions

This commit is contained in:
Christopher Goes 2018-06-07 21:36:03 +02:00
parent 3c17fa285c
commit 7baed6d361
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
1 changed files with 37 additions and 1 deletions

View File

@ -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")