-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from NillionNetwork/sean/update-account-prefix
chore: adding config for account prefixes
- Loading branch information
Showing
4 changed files
with
75 additions
and
5 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
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,55 @@ | ||
package nillionapp | ||
|
||
import ( | ||
"cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const ( | ||
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address. | ||
Bech32PrefixAccAddr = "nillion" | ||
) | ||
|
||
var ( | ||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key. | ||
Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub" | ||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address. | ||
Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper" | ||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key. | ||
Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub" | ||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address. | ||
Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons" | ||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key. | ||
Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub" | ||
) | ||
|
||
func init() { | ||
SetBech32AddressPrefixes() | ||
} | ||
|
||
func SetBech32AddressPrefixes() { | ||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) | ||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) | ||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) | ||
|
||
// This is copied from the cosmos sdk v0.43.0-beta1 | ||
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141 | ||
config.SetAddressVerifier(func(bytes []byte) error { | ||
if len(bytes) == 0 { | ||
return errors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") | ||
} | ||
|
||
if len(bytes) > address.MaxAddrLen { | ||
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes)) | ||
} | ||
|
||
if len(bytes) != 20 && len(bytes) != 32 { | ||
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes)) | ||
} | ||
|
||
return 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