feat(hubl): cache bech32 prefix (#15954)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package address
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
@@ -21,13 +24,17 @@ func NewBech32Codec(prefix string) address.Codec {
|
||||
|
||||
// StringToBytes encodes text to bytes
|
||||
func (bc Bech32Codec) StringToBytes(text string) ([]byte, error) {
|
||||
if len(strings.TrimSpace(text)) == 0 {
|
||||
return []byte{}, errors.New("empty address string is not allowed")
|
||||
}
|
||||
|
||||
hrp, bz, err := bech32.DecodeAndConvert(text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if hrp != bc.Bech32Prefix {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix")
|
||||
return nil, errorsmod.Wrapf(sdkerrors.ErrLogic, "hrp does not match bech32 prefix: expected '%s' got '%s'", bc.Bech32Prefix, hrp)
|
||||
}
|
||||
|
||||
if err := sdk.VerifyAddressFormat(bz); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user