app: change bech32 prefix cosmos -> eth (#429)
This commit is contained in:
parent
1428cd6a5c
commit
5ff2b316cb
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
"github.com/cosmos/ethermint/app/ante"
|
"github.com/cosmos/ethermint/app/ante"
|
||||||
ethermintcodec "github.com/cosmos/ethermint/codec"
|
ethermintcodec "github.com/cosmos/ethermint/codec"
|
||||||
eminttypes "github.com/cosmos/ethermint/types"
|
ethermint "github.com/cosmos/ethermint/types"
|
||||||
"github.com/cosmos/ethermint/x/evm"
|
"github.com/cosmos/ethermint/x/evm"
|
||||||
"github.com/cosmos/ethermint/x/faucet"
|
"github.com/cosmos/ethermint/x/faucet"
|
||||||
|
|
||||||
@ -37,6 +37,12 @@ import (
|
|||||||
dbm "github.com/tendermint/tm-db"
|
dbm "github.com/tendermint/tm-db"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// set the address prefixes
|
||||||
|
config := sdk.GetConfig()
|
||||||
|
ethermint.SetBech32Prefixes(config)
|
||||||
|
}
|
||||||
|
|
||||||
const appName = "Ethermint"
|
const appName = "Ethermint"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -176,7 +182,7 @@ func NewEthermintApp(
|
|||||||
|
|
||||||
// use custom Ethermint account for contracts
|
// use custom Ethermint account for contracts
|
||||||
app.AccountKeeper = auth.NewAccountKeeper(
|
app.AccountKeeper = auth.NewAccountKeeper(
|
||||||
appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], eminttypes.ProtoAccount,
|
appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], ethermint.ProtoAccount,
|
||||||
)
|
)
|
||||||
app.BankKeeper = bank.NewBaseKeeper(
|
app.BankKeeper = bank.NewBaseKeeper(
|
||||||
appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
|
appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/cosmos/ethermint/codec"
|
"github.com/cosmos/ethermint/codec"
|
||||||
"github.com/cosmos/ethermint/crypto"
|
"github.com/cosmos/ethermint/crypto"
|
||||||
"github.com/cosmos/ethermint/rpc"
|
"github.com/cosmos/ethermint/rpc"
|
||||||
|
ethermint "github.com/cosmos/ethermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -44,9 +45,7 @@ func main() {
|
|||||||
|
|
||||||
// Read in the configuration file for the sdk
|
// Read in the configuration file for the sdk
|
||||||
config := sdk.GetConfig()
|
config := sdk.GetConfig()
|
||||||
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
|
ethermint.SetBech32Prefixes(config)
|
||||||
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
|
|
||||||
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
|
||||||
config.Seal()
|
config.Seal()
|
||||||
|
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/cosmos/ethermint/client"
|
"github.com/cosmos/ethermint/client"
|
||||||
"github.com/cosmos/ethermint/codec"
|
"github.com/cosmos/ethermint/codec"
|
||||||
"github.com/cosmos/ethermint/crypto"
|
"github.com/cosmos/ethermint/crypto"
|
||||||
|
ethermint "github.com/cosmos/ethermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const flagInvCheckPeriod = "inv-check-period"
|
const flagInvCheckPeriod = "inv-check-period"
|
||||||
@ -52,9 +53,7 @@ func main() {
|
|||||||
clientkeys.KeysCdc = cdc
|
clientkeys.KeysCdc = cdc
|
||||||
|
|
||||||
config := sdk.GetConfig()
|
config := sdk.GetConfig()
|
||||||
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
|
ethermint.SetBech32Prefixes(config)
|
||||||
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
|
|
||||||
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
|
||||||
config.Seal()
|
config.Seal()
|
||||||
|
|
||||||
ctx := server.NewDefaultContext()
|
ctx := server.NewDefaultContext()
|
||||||
|
30
types/config.go
Normal file
30
types/config.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// EthBech32Prefix defines the Bech32 prefix used for EthAccounts
|
||||||
|
EthBech32Prefix = "eth"
|
||||||
|
|
||||||
|
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
|
||||||
|
Bech32PrefixAccAddr = EthBech32Prefix
|
||||||
|
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||||
|
Bech32PrefixAccPub = EthBech32Prefix + sdk.PrefixPublic
|
||||||
|
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||||
|
Bech32PrefixValAddr = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator
|
||||||
|
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||||
|
Bech32PrefixValPub = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
|
||||||
|
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||||
|
Bech32PrefixConsAddr = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
|
||||||
|
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||||
|
Bech32PrefixConsPub = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
|
||||||
|
func SetBech32Prefixes(config *sdk.Config) {
|
||||||
|
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
|
||||||
|
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||||
|
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||||
|
}
|
27
types/config_test.go
Normal file
27
types/config_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSetBech32Prefixes(t *testing.T) {
|
||||||
|
config := sdk.GetConfig()
|
||||||
|
require.Equal(t, sdk.Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
|
||||||
|
require.Equal(t, sdk.Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
|
||||||
|
require.Equal(t, sdk.Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
|
||||||
|
require.Equal(t, sdk.Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
|
||||||
|
require.Equal(t, sdk.Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
|
||||||
|
require.Equal(t, sdk.Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
|
||||||
|
|
||||||
|
SetBech32Prefixes(config)
|
||||||
|
require.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
|
||||||
|
require.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
|
||||||
|
require.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
|
||||||
|
require.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
|
||||||
|
require.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
|
||||||
|
require.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user