Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize cosmos address prefix #1572

Merged
merged 5 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func main() {
if err != nil {
logrus.WithField("module", "main").Fatalln(err)
}

cosmos.CustomizeConfig()

// TODO: rename NewAppFactory to something else
appFactory := cosmos.NewAppFactory(logger.TendermintLogger(), db)

Expand Down
48 changes: 48 additions & 0 deletions cosmos/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cosmos

import sdktypes "github.com/cosmos/cosmos-sdk/types"

const (
// CoinType is a mesg coin type.
CoinType = 50000

// Bech32MainPrefix defines the main Bech32 prefix
Bech32MainPrefix = "mesgtest"

// PrefixAccount is the prefix for account keys
PrefixAccount = "acc"
// PrefixValidator is the prefix for validator keys
PrefixValidator = "val"
// PrefixConsensus is the prefix for consensus keys
PrefixConsensus = "cons"
// PrefixPublic is the prefix for public keys
PrefixPublic = "pub"
// PrefixOperator is the prefix for operator keys
PrefixOperator = "oper"

// PrefixAddress is the prefix for addresses
PrefixAddress = "addr"

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32MainPrefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = Bech32MainPrefix + PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = Bech32MainPrefix + PrefixValidator + PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = Bech32MainPrefix + PrefixValidator + PrefixOperator + PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = Bech32MainPrefix + PrefixValidator + PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic
)

// CustomizeConfig customizes the cosmos application like addresses prefixes and coin type
func CustomizeConfig() {
antho1404 marked this conversation as resolved.
Show resolved Hide resolved
config := sdktypes.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.SetCoinType(CoinType)
config.Seal()
}