-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(feegrant): remove bech32 global (#15347)
Co-authored-by: Julien Robert <[email protected]>
- Loading branch information
1 parent
443eb3d
commit 572e657
Showing
36 changed files
with
402 additions
and
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package address | ||
|
||
import ( | ||
"cosmossdk.io/core/address" | ||
errorsmod "cosmossdk.io/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"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) address.Codec { | ||
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, errorsmod.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
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 was deleted.
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
Oops, something went wrong.