diff --git a/app/app.go b/app/app.go index d1a6eeede5..890705fc55 100644 --- a/app/app.go +++ b/app/app.go @@ -40,7 +40,6 @@ import ( "github.com/irisnet/irishub/v3/app/params" "github.com/irisnet/irishub/v3/app/rpc" "github.com/irisnet/irishub/v3/client/lite" - iristypes "github.com/irisnet/irishub/v3/types" ) var ( @@ -85,7 +84,7 @@ func NewIrisApp( baseAppOptions = append(baseAppOptions, NoOpMempoolOption()) bApp := baseapp.NewBaseApp( - iristypes.AppName, + params.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), @@ -237,7 +236,7 @@ func (app *IrisApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R // InitChainer application update at chain initialization func (app *IrisApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - var genesisState iristypes.GenesisState + var genesisState GenesisState if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } @@ -360,7 +359,7 @@ func (app *IrisApp) DefaultGenesis() map[string]json.RawMessage { // Init initializes the IrisApp. func (app *IrisApp) Init() { - iristypes.InjectCodec(app.legacyAmino, app.interfaceRegistry) + params.InjectCodec(app.legacyAmino, app.interfaceRegistry) } // NoOpMempoolOption returns a function that sets up a no-op mempool for the given BaseApp. diff --git a/app/genesis.go b/app/genesis.go index d75e1f0680..632739576a 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -1,11 +1,12 @@ package app -import ( - "github.com/irisnet/irishub/v3/types" -) +import "encoding/json" -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState() types.GenesisState { - encCfg := RegisterEncodingConfig() - return ModuleBasics.DefaultGenesis(encCfg.Marshaler) -} +// GenesisState The genesis state of the blockchain is represented here as a map of raw json +// messages key'd by a identifier string. +// The identifier is used to determine which module genesis information belongs +// to so it may be appropriately routed during init chain. +// Within this application default genesis information is retrieved from +// the ModuleBasicManager which populates json from each BasicModule +// object provided to it during init. +type GenesisState map[string]json.RawMessage diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 579d6ac3ad..d4a74d8656 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -105,12 +105,12 @@ import ( tokentypes "github.com/irisnet/irismod/modules/token/types" tokenv1 "github.com/irisnet/irismod/modules/token/types/v1" + appparams "github.com/irisnet/irishub/v3/app/params" guardiankeeper "github.com/irisnet/irishub/v3/modules/guardian/keeper" guardiantypes "github.com/irisnet/irishub/v3/modules/guardian/types" "github.com/irisnet/irishub/v3/modules/internft" mintkeeper "github.com/irisnet/irishub/v3/modules/mint/keeper" minttypes "github.com/irisnet/irishub/v3/modules/mint/types" - iristypes "github.com/irisnet/irishub/v3/types" "github.com/irisnet/irishub/v3/wrapper" ) @@ -232,7 +232,7 @@ func New( appKeepers.keys[authtypes.StoreKey], ethermint.ProtoAccount, maccPerms, - iristypes.Bech32PrefixAccAddr, + appparams.Bech32PrefixAccAddr, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) @@ -556,12 +556,12 @@ func New( authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ).WithSwapRegistry(tokenv1.SwapRegistry{ - iristypes.NativeToken.MinUnit: tokenv1.SwapParams{ - MinUnit: iristypes.EvmToken.MinUnit, + appparams.BaseToken.MinUnit: tokenv1.SwapParams{ + MinUnit: appparams.EvmToken.MinUnit, Ratio: sdk.OneDec(), }, - iristypes.EvmToken.MinUnit: tokenv1.SwapParams{ - MinUnit: iristypes.NativeToken.MinUnit, + appparams.EvmToken.MinUnit: tokenv1.SwapParams{ + MinUnit: appparams.BaseToken.MinUnit, Ratio: sdk.OneDec(), }, }) diff --git a/types/address.go b/app/params/address.go similarity index 99% rename from types/address.go rename to app/params/address.go index f563f9218c..441c22be69 100644 --- a/types/address.go +++ b/app/params/address.go @@ -1,4 +1,4 @@ -package types +package params import sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/app/params/params.go b/app/params/params.go index b6aa5fb55e..7a9a968a37 100644 --- a/app/params/params.go +++ b/app/params/params.go @@ -1,7 +1,117 @@ package params -// Simulation parameter constants +// MUST be loaded before running +import ( + "fmt" + "math/big" + "os" + "path/filepath" + + "github.com/cometbft/cometbft/crypto" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/evmos/ethermint/ethereum/eip712" + etherminttypes "github.com/evmos/ethermint/types" + + tokentypes "github.com/irisnet/irismod/modules/token/types" + tokenv1 "github.com/irisnet/irismod/modules/token/types/v1" +) + const ( - StakePerAccount = "stake_per_account" - InitiallyBondedValidators = "initially_bonded_validators" + // AppName is the name of the app + AppName = "IrisApp" + EIP155ChainID = "6688" ) + +var ( + // BaseToken represents the native token + BaseToken tokenv1.Token + // EvmToken represents the EVM token + EvmToken tokenv1.Token + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string +) + +func init() { + // set bech32 prefix + ConfigureBech32Prefix() + + // set coin denom regexs + sdk.SetCoinDenomRegex(func() string { + return `[a-zA-Z][a-zA-Z0-9/-]{2,127}` + }) + + BaseToken = tokenv1.Token{ + Symbol: "iris", + Name: "Irishub staking token", + Scale: 6, + MinUnit: "uiris", + InitialSupply: 2000000000, + MaxSupply: 10000000000, + Mintable: true, + Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), + } + + EvmToken = tokenv1.Token{ + Symbol: "eris", + Name: "IRISHub EVM Fee Token", + Scale: 18, + MinUnit: "weris", + InitialSupply: 0, + MaxSupply: 10000000000, + Mintable: true, + Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), + } + sdk.DefaultBondDenom = BaseToken.MinUnit + + if err := sdk.RegisterDenom(BaseToken.Symbol, sdk.OneDec()); err != nil { + panic(err) + } + + if err := sdk.RegisterDenom(BaseToken.MinUnit, sdk.NewDecFromIntWithPrec(sdk.OneInt(), int64(BaseToken.Scale))); err != nil { + panic(err) + } + + userHomeDir, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, ".iris") + owner, err := sdk.AccAddressFromBech32(BaseToken.Owner) + if err != nil { + panic(err) + } + + // replace the default token + tokenv1.SetNativeToken( + BaseToken.Symbol, + BaseToken.Name, + BaseToken.MinUnit, + BaseToken.Scale, + BaseToken.InitialSupply, + BaseToken.MaxSupply, + BaseToken.Mintable, + owner, + ) + + etherminttypes.InjectChainIDParser(parseChainID) +} + +// InjectCodec injects an app codec +func InjectCodec(legacyAmino *codec.LegacyAmino, interfaceRegistry types.InterfaceRegistry) { + eip712.InjectCodec(eip712.Codec{ + InterfaceRegistry: interfaceRegistry, + Amino: legacyAmino, + }) +} + +func parseChainID(_ string) (*big.Int, error) { + eip155ChainID, ok := new(big.Int).SetString(EIP155ChainID, 10) + if !ok { + return nil, fmt.Errorf("invalid chain-id: %s", EIP155ChainID) + } + return eip155ChainID, nil +} diff --git a/app/params/weights.go b/app/params/weights.go deleted file mode 100644 index 0ba377b009..0000000000 --- a/app/params/weights.go +++ /dev/null @@ -1,23 +0,0 @@ -package params - -// Default simulation operation weights for messages and gov proposals -const ( - DefaultWeightMsgSend int = 100 - DefaultWeightMsgMultiSend int = 10 - DefaultWeightMsgSetWithdrawAddress int = 50 - DefaultWeightMsgWithdrawDelegationReward int = 50 - DefaultWeightMsgWithdrawValidatorCommission int = 50 - DefaultWeightMsgFundCommunityPool int = 50 - DefaultWeightMsgDeposit int = 100 - DefaultWeightMsgVote int = 67 - DefaultWeightMsgUnjail int = 100 - DefaultWeightMsgCreateValidator int = 100 - DefaultWeightMsgEditValidator int = 5 - DefaultWeightMsgDelegate int = 100 - DefaultWeightMsgUndelegate int = 100 - DefaultWeightMsgBeginRedelegate int = 100 - - DefaultWeightCommunitySpendProposal int = 5 - DefaultWeightTextProposal int = 5 - DefaultWeightParamChangeProposal int = 5 -) diff --git a/app/sim_test.go b/app/sim_test.go index 8523f77b31..154d000621 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -19,13 +19,11 @@ import ( tokentypes "github.com/irisnet/irismod/modules/token/types" "github.com/stretchr/testify/require" - "github.com/irisnet/irishub/v3/app/params" - iristypes "github.com/irisnet/irishub/v3/types" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/irisnet/irishub/v3/app/params" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store" @@ -129,7 +127,7 @@ func TestAppImportExport(t *testing.T) { config := simcli.NewConfigFromFlags() config.ChainID = AppChainID - sdk.DefaultBondDenom = iristypes.NativeToken.Symbol + sdk.DefaultBondDenom = params.BaseToken.Symbol db, dir, logger, skip, err := simtestutil.SetupSimulation( config, @@ -199,7 +197,7 @@ func TestAppImportExport(t *testing.T) { newApp := createApp(logger, db, encfg, fauxMerkleModeOpt) require.Equal(t, "IrisApp", newApp.Name()) - var genesisState iristypes.GenesisState + var genesisState GenesisState err = json.Unmarshal(exported.AppState, &genesisState) require.NoError(t, err) @@ -393,7 +391,7 @@ func TestAppStateDeterminism(t *testing.T) { if !simcli.FlagEnabledValue { t.Skip("skipping application simulation") } - sdk.DefaultBondDenom = iristypes.NativeToken.Symbol + sdk.DefaultBondDenom = params.BaseToken.Symbol config := simcli.NewConfigFromFlags() config.InitialBlockHeight = 1 diff --git a/app/upgrades/v200/config.go b/app/upgrades/v200/config.go index 81b92b32cd..871eab8d87 100644 --- a/app/upgrades/v200/config.go +++ b/app/upgrades/v200/config.go @@ -5,8 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" etherminttypes "github.com/evmos/ethermint/x/evm/types" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - - "github.com/irisnet/irishub/v3/types" + "github.com/irisnet/irishub/v3/app/params" ) // NOTE: Before the release of irishub 2.0.0, the configuration in this file must be modified @@ -16,7 +15,7 @@ const ( ) var ( - evmToken = types.EvmToken + evmToken = params.EvmToken evmParams = etherminttypes.Params{ EvmDenom: evmToken.MinUnit, EnableCreate: true, diff --git a/cmd/iris/cmd/root.go b/cmd/iris/cmd/root.go index 94b6411a50..2340800d8f 100644 --- a/cmd/iris/cmd/root.go +++ b/cmd/iris/cmd/root.go @@ -33,7 +33,6 @@ import ( "github.com/irisnet/irishub/v3/app" "github.com/irisnet/irishub/v3/app/params" - iristypes "github.com/irisnet/irishub/v3/types" ) // NewRootCmd creates a new root command for simd. It is called once in the @@ -48,7 +47,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). WithBroadcastMode(flags.BroadcastSync). - WithHomeDir(iristypes.DefaultNodeHome). + WithHomeDir(params.DefaultNodeHome). WithKeyringOptions(etherminthd.EthSecp256k1Option()). WithViper("") @@ -70,8 +69,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return err } - converter.handlePreRun(cmd, args) - customTemplate, customIRISHubConfig := initAppConfig() customTMConfig := initTendermintConfig() return server.InterceptConfigsPreRunHandler( @@ -106,7 +103,7 @@ func initTendermintConfig() *tmcfg.Config { // initAppConfig helps to override default appConfig template and configs. // return "", nil if no custom configuration is required for the application. func initAppConfig() (string, interface{}) { - customAppTemplate, customAppConfig := servercfg.AppConfig(iristypes.NativeToken.MinUnit) + customAppTemplate, customAppConfig := servercfg.AppConfig(params.BaseToken.MinUnit) srvCfg, ok := customAppConfig.(servercfg.Config) if !ok { panic(fmt.Errorf("unknown app config type %T", customAppConfig)) @@ -124,20 +121,20 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { } rootCmd.AddCommand( - genutilcli.InitCmd(app.ModuleBasics, iristypes.DefaultNodeHome), + genutilcli.InitCmd(app.ModuleBasics, params.DefaultNodeHome), genutilcli.ValidateGenesisCmd(app.ModuleBasics), - AddGenesisAccountCmd(iristypes.DefaultNodeHome), + AddGenesisAccountCmd(params.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), ethermintdebug.Cmd(), config.Cmd(), mergeGenesisCmd(encodingConfig), - pruning.Cmd(ac.newApp, iristypes.DefaultNodeHome), + pruning.Cmd(ac.newApp, params.DefaultNodeHome), ) ethermintserver.AddCommands( rootCmd, - ethermintserver.NewDefaultStartOptions(ac.newApp, iristypes.DefaultNodeHome), + ethermintserver.NewDefaultStartOptions(ac.newApp, params.DefaultNodeHome), ac.appExport, addModuleInitFlags, ) @@ -155,7 +152,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { genesisCommand(encodingConfig), queryCommand(), txCommand(), - Commands(iristypes.DefaultNodeHome), + Commands(params.DefaultNodeHome), ) } @@ -164,7 +161,7 @@ func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command cmd := genutilcli.GenesisCoreCommand( encodingConfig.TxConfig, app.ModuleBasics, - iristypes.DefaultNodeHome, + params.DefaultNodeHome, ) for _, subCmd := range cmds { diff --git a/cmd/iris/cmd/testnet.go b/cmd/iris/cmd/testnet.go index 4022862f83..1830e0be3f 100644 --- a/cmd/iris/cmd/testnet.go +++ b/cmd/iris/cmd/testnet.go @@ -12,6 +12,7 @@ import ( "path/filepath" evmtypes "github.com/evmos/ethermint/x/evm/types" + iristypes "github.com/irisnet/irishub/v3/app/params" tokentypes "github.com/irisnet/irismod/modules/token/types" "github.com/spf13/cobra" @@ -46,7 +47,6 @@ import ( tokentypesv1 "github.com/irisnet/irismod/modules/token/types/v1" guardiantypes "github.com/irisnet/irishub/v3/modules/guardian/types" - iristypes "github.com/irisnet/irishub/v3/types" ) var ( @@ -302,7 +302,7 @@ func InitTestnet( return err } - customAppTemplate, _ := servercfg.AppConfig(iristypes.NativeToken.MinUnit) + customAppTemplate, _ := servercfg.AppConfig(iristypes.BaseToken.MinUnit) srvconfig.SetConfigTemplate(customAppTemplate) srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), simappConfig) @@ -368,7 +368,7 @@ func initGenFiles( tokenGenState.Tokens = append(tokenGenState.Tokens, iristypes.EvmToken) appGenState[tokentypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&tokenGenState) - //set system service in the genesis state + // set system service in the genesis state var serviceGenState servicetypes.GenesisState clientCtx.Codec.MustUnmarshalJSON(appGenState[servicetypes.ModuleName], &serviceGenState) serviceGenState.Definitions = append( @@ -377,7 +377,7 @@ func initGenFiles( ) serviceGenState.Bindings = append( serviceGenState.Bindings, - servicetypes.GenOraclePriceSvcBinding(iristypes.NativeToken.MinUnit), + servicetypes.GenOraclePriceSvcBinding(iristypes.BaseToken.MinUnit), ) serviceGenState.Definitions = append( serviceGenState.Definitions, diff --git a/cmd/iris/main.go b/cmd/iris/main.go index 504ca5c00f..8c407642b3 100644 --- a/cmd/iris/main.go +++ b/cmd/iris/main.go @@ -5,16 +5,16 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + "github.com/irisnet/irishub/v3/app/params" _ "github.com/irisnet/irishub/v3/client/lite/statik" "github.com/irisnet/irishub/v3/cmd/iris/cmd" - "github.com/irisnet/irishub/v3/types" ) func main() { rootCmd, _ := cmd.NewRootCmd() - if err := svrcmd.Execute(rootCmd, "", types.DefaultNodeHome); err != nil { + if err := svrcmd.Execute(rootCmd, "", params.DefaultNodeHome); err != nil { switch e := err.(type) { case server.ErrorCode: os.Exit(e.Code) diff --git a/modules/guardian/types/msgs_test.go b/modules/guardian/types/msgs_test.go index da71a4ebf5..e3f6d71b95 100644 --- a/modules/guardian/types/msgs_test.go +++ b/modules/guardian/types/msgs_test.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - _ "github.com/irisnet/irishub/v3/types" + _ "github.com/irisnet/irishub/v3/app/params" ) // nolint: deadcode unused diff --git a/types/chain_id.go b/types/chain_id.go deleted file mode 100644 index 28c960b22d..0000000000 --- a/types/chain_id.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -import ( - "fmt" - "math/big" -) - -var ( - EIP155ChainID = "6688" -) - -func parseChainID(_ string) (*big.Int, error) { - eip155ChainID, ok := new(big.Int).SetString(EIP155ChainID, 10) - if !ok { - return nil, fmt.Errorf("invalid chain-id: %s" + EIP155ChainID) - } - return eip155ChainID, nil -} diff --git a/types/genesis.go b/types/genesis.go deleted file mode 100644 index eb89414eae..0000000000 --- a/types/genesis.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -import "encoding/json" - -// The genesis state of the blockchain is represented here as a map of raw json -// messages key'd by a identifier string. -// The identifier is used to determine which module genesis information belongs -// to so it may be appropriately routed during init chain. -// Within this application default genesis information is retrieved from -// the ModuleBasicManager which populates json from each BasicModule -// object provided to it during init. -type GenesisState map[string]json.RawMessage diff --git a/types/runtime.go b/types/runtime.go deleted file mode 100644 index 99a60c58c6..0000000000 --- a/types/runtime.go +++ /dev/null @@ -1,100 +0,0 @@ -package types - -// MUST be loaded before running -import ( - "os" - "path/filepath" - - "github.com/cometbft/cometbft/crypto" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/evmos/ethermint/ethereum/eip712" - etherminttypes "github.com/evmos/ethermint/types" - - tokentypes "github.com/irisnet/irismod/modules/token/types" - tokenv1 "github.com/irisnet/irismod/modules/token/types/v1" -) - -const ( - // AppName is the name of the app - AppName = "IrisApp" -) - -var ( - // NativeToken represents the native token - NativeToken tokenv1.Token - // EvmToken represents the EVM token - EvmToken tokenv1.Token - // DefaultNodeHome default home directories for the application daemon - DefaultNodeHome string -) - -func init() { - // set bech32 prefix - ConfigureBech32Prefix() - - // set coin denom regexs - sdk.SetCoinDenomRegex(func() string { - return `[a-zA-Z][a-zA-Z0-9/-]{2,127}` - }) - - NativeToken = tokenv1.Token{ - Symbol: "iris", - Name: "Irishub staking token", - Scale: 6, - MinUnit: "uiris", - InitialSupply: 2000000000, - MaxSupply: 10000000000, - Mintable: true, - Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), - } - - EvmToken = tokenv1.Token{ - Symbol: "eris", - Name: "IRISHub EVM Fee Token", - Scale: 18, - MinUnit: "weris", - InitialSupply: 0, - MaxSupply: 10000000000, - Mintable: true, - Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), - } - sdk.DefaultBondDenom = NativeToken.MinUnit - - - userHomeDir, err := os.UserHomeDir() - if err != nil { - panic(err) - } - - DefaultNodeHome = filepath.Join(userHomeDir, ".iris") - owner, err := sdk.AccAddressFromBech32(NativeToken.Owner) - if err != nil { - panic(err) - } - - // replace the default token - tokenv1.SetNativeToken( - NativeToken.Symbol, - NativeToken.Name, - NativeToken.MinUnit, - NativeToken.Scale, - NativeToken.InitialSupply, - NativeToken.MaxSupply, - NativeToken.Mintable, - owner, - ) - - etherminttypes.InjectChainIDParser(parseChainID) -} - -// InjectCodec injects an app codec -func InjectCodec(legacyAmino *codec.LegacyAmino, interfaceRegistry types.InterfaceRegistry) { - eip712.InjectCodec(eip712.Codec{ - InterfaceRegistry: interfaceRegistry, - Amino: legacyAmino, - }) -}