-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into am/fix-proto-comments
- Loading branch information
Showing
16 changed files
with
2,070 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package address | ||
|
||
// Codec defines an interface to convert addresses from and to string/bytes. | ||
type Codec interface { | ||
// StringToBytes decodes text to bytes | ||
StringToBytes(text string) ([]byte, error) | ||
// BytesToString encodes bytes to text | ||
BytesToString(bz []byte) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
type bech32Codec struct { | ||
bech32Prefix string | ||
} | ||
|
||
var _ address.Codec = &bech32Codec{} | ||
|
||
func newBech32Codec(prefix string) bech32Codec { | ||
return bech32Codec{prefix} | ||
} | ||
|
||
// StringToBytes encodes text to bytes | ||
func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { | ||
hrp, bz, err := bech32.DecodeAndConvert(text) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if hrp != bc.bech32Prefix { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix") | ||
} | ||
|
||
if err := sdk.VerifyAddressFormat(bz); err != nil { | ||
return nil, err | ||
} | ||
|
||
return bz, nil | ||
} | ||
|
||
// BytesToString decodes bytes to text | ||
func (bc bech32Codec) BytesToString(bz []byte) (string, error) { | ||
text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return text, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.