Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed May 16, 2024
1 parent b1a5870 commit e6e8ec3
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 200 deletions.
7 changes: 3 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -85,7 +84,7 @@ func NewIrisApp(
baseAppOptions = append(baseAppOptions, NoOpMempoolOption())

bApp := baseapp.NewBaseApp(
iristypes.AppName,
params.AppName,
logger,
db,
encodingConfig.TxConfig.TxDecoder(),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions app/genesis.go
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keepers

import (
params2 "github.com/irisnet/irishub/v3/app/params"
"github.com/spf13/cast"

"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -110,7 +111,6 @@ import (
"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"
)

Expand Down Expand Up @@ -232,7 +232,7 @@ func New(
appKeepers.keys[authtypes.StoreKey],
ethermint.ProtoAccount,
maccPerms,
iristypes.Bech32PrefixAccAddr,
params2.Bech32PrefixAccAddr,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down Expand Up @@ -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,
params2.BaseToken.MinUnit: tokenv1.SwapParams{
MinUnit: params2.EvmToken.MinUnit,
Ratio: sdk.OneDec(),
},
iristypes.EvmToken.MinUnit: tokenv1.SwapParams{
MinUnit: iristypes.NativeToken.MinUnit,
params2.EvmToken.MinUnit: tokenv1.SwapParams{
MinUnit: params2.BaseToken.MinUnit,
Ratio: sdk.OneDec(),
},
})
Expand Down
2 changes: 1 addition & 1 deletion types/address.go → app/params/address.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types
package params

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

Expand Down
116 changes: 113 additions & 3 deletions app/params/params.go
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 0 additions & 23 deletions app/params/weights.go

This file was deleted.

10 changes: 4 additions & 6 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/upgrades/v200/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +15,7 @@ const (
)

var (
evmToken = types.EvmToken
evmToken = params.EvmToken
evmParams = etherminttypes.Params{
EvmDenom: evmToken.MinUnit,
EnableCreate: true,
Expand Down
19 changes: 9 additions & 10 deletions cmd/iris/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("")

Expand All @@ -70,7 +69,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return err
}

converter.handlePreRun(cmd, args)
// converter.handlePreRun(cmd, args)

customTemplate, customIRISHubConfig := initAppConfig()
customTMConfig := initTendermintConfig()
Expand Down Expand Up @@ -106,7 +105,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))
Expand All @@ -124,20 +123,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,
)
Expand All @@ -155,7 +154,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
genesisCommand(encodingConfig),
queryCommand(),
txCommand(),
Commands(iristypes.DefaultNodeHome),
Commands(params.DefaultNodeHome),
)
}

Expand All @@ -164,7 +163,7 @@ func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command
cmd := genutilcli.GenesisCoreCommand(
encodingConfig.TxConfig,
app.ModuleBasics,
iristypes.DefaultNodeHome,
params.DefaultNodeHome,
)

for _, subCmd := range cmds {
Expand Down
Loading

0 comments on commit e6e8ec3

Please sign in to comment.