From c4fdf2a386527be79584f42bd30b61fd655cb32e Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:13:25 +0900 Subject: [PATCH 1/3] add denom flag --- app/genesis.go | 11 +++++------ app/test_helpers.go | 3 ++- cmd/minitiad/init.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/genesis.go b/app/genesis.go index 2e7a7fa..0a9a792 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -13,7 +13,6 @@ import ( ibctypes "github.com/cosmos/ibc-go/v7/modules/core/types" opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" - "github.com/initia-labs/miniwasm/types" auctiontypes "github.com/skip-mev/block-sdk/x/auction/types" ) @@ -28,19 +27,19 @@ import ( type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec, mbm module.BasicManager) GenesisState { +func NewDefaultGenesisState(cdc codec.JSONCodec, mbm module.BasicManager, denom string) GenesisState { return GenesisState(mbm.DefaultGenesis(cdc)). ConfigureMinGasPrices(cdc). ConfigureICA(cdc). ConfigureIBCAllowedClients(cdc). - ConfigureAuctionFee(cdc) + ConfigureAuctionFee(cdc, denom) } -func (genState GenesisState) ConfigureAuctionFee(cdc codec.JSONCodec) GenesisState { +func (genState GenesisState) ConfigureAuctionFee(cdc codec.JSONCodec, denom string) GenesisState { var auctionGenState auctiontypes.GenesisState cdc.MustUnmarshalJSON(genState[auctiontypes.ModuleName], &auctionGenState) - auctionGenState.Params.ReserveFee.Denom = types.BaseDenom - auctionGenState.Params.MinBidIncrement.Denom = types.BaseDenom + auctionGenState.Params.ReserveFee.Denom = denom + auctionGenState.Params.MinBidIncrement.Denom = denom genState[auctiontypes.ModuleName] = cdc.MustMarshalJSON(&auctionGenState) return genState diff --git a/app/test_helpers.go b/app/test_helpers.go index 3501a7d..263c1a9 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -22,6 +22,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" + "github.com/initia-labs/miniwasm/types" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" ) @@ -64,7 +65,7 @@ func setup(db *dbm.DB, withGenesis bool) (*MinitiaApp, GenesisState) { ) if withGenesis { - return app, NewDefaultGenesisState(encCdc.Marshaler, ModuleBasics) + return app, NewDefaultGenesisState(encCdc.Marshaler, ModuleBasics, types.BaseDenom) } return app, GenesisState{} diff --git a/cmd/minitiad/init.go b/cmd/minitiad/init.go index 6d89d60..3998c5e 100644 --- a/cmd/minitiad/init.go +++ b/cmd/minitiad/init.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" minitiaapp "github.com/initia-labs/miniwasm/app" + "github.com/initia-labs/miniwasm/types" ) const ( @@ -33,6 +34,9 @@ const ( // FlagRecover defines a flag to initialize the private validator key from a specific seed. FlagRecover = "recover" + + // FlagDenom defines a flag to set default denom a chain operator want to use. + FlagDenom = "denom" ) type printInfo struct { @@ -85,6 +89,11 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { chainID = fmt.Sprintf("test-chain-%v", cometrand.Str(6)) } + denom, err := cmd.Flags().GetString(FlagDenom) + if err != nil { + return err + } + // Get bip39 mnemonic var mnemonic string recover, _ := cmd.Flags().GetBool(FlagRecover) @@ -116,7 +125,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { } appState, err := json.MarshalIndent( - minitiaapp.NewDefaultGenesisState(cdc, mbm), "", " ", + minitiaapp.NewDefaultGenesisState(cdc, mbm, denom), "", " ", ) if err != nil { return errors.Wrap(err, "Failed to marshall default genesis state") @@ -153,6 +162,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file") cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") + cmd.Flags().String(FlagDenom, types.BaseDenom, "genesis file default denom") return cmd } From 1e9b7259ef6947dd4d9915b9aa31550991996a59 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:24:16 +0900 Subject: [PATCH 2/3] fix lint --- app/test_helpers.go | 14 +++++++------- cmd/minitiad/root.go | 3 --- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/test_helpers.go b/app/test_helpers.go index 263c1a9..fd90b3a 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -79,6 +79,13 @@ func SetupWithGenesisAccounts( ) *MinitiaApp { app, genesisState := setup(nil, true) + if genAccs == nil || len(genAccs) == 0 { + privAcc := secp256k1.GenPrivKey() + genAccs = []authtypes.GenesisAccount{ + authtypes.NewBaseAccount(privAcc.PubKey().Address().Bytes(), privAcc.PubKey(), 0, 0), + } + } + // set genesis accounts authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) @@ -95,13 +102,6 @@ func SetupWithGenesisAccounts( valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) } - if genAccs == nil || len(genAccs) == 0 { - privAcc := secp256k1.GenPrivKey() - genAccs = []authtypes.GenesisAccount{ - authtypes.NewBaseAccount(privAcc.PubKey().Address().Bytes(), privAcc.PubKey(), 0, 0), - } - } - validators := make([]opchildtypes.Validator, 0, len(valSet.Validators)) for _, val := range valSet.Validators { diff --git a/cmd/minitiad/root.go b/cmd/minitiad/root.go index bf4bfb0..2ca8193 100644 --- a/cmd/minitiad/root.go +++ b/cmd/minitiad/root.go @@ -40,9 +40,6 @@ import ( "github.com/initia-labs/miniwasm/app/params" ) -// missing flag from cosmos-sdk -const flagIAVLCacheSize = "iavl-cache-size" - // NewRootCmd creates a new root command for initiad. It is called once in the // main function. func NewRootCmd() (*cobra.Command, params.EncodingConfig) { From 179df67d8aa22f2d0658a3fdd887603cf4f16682 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:25:39 +0900 Subject: [PATCH 3/3] fix lint --- app/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test_helpers.go b/app/test_helpers.go index fd90b3a..30c9092 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -79,7 +79,7 @@ func SetupWithGenesisAccounts( ) *MinitiaApp { app, genesisState := setup(nil, true) - if genAccs == nil || len(genAccs) == 0 { + if len(genAccs) == 0 { privAcc := secp256k1.GenPrivKey() genAccs = []authtypes.GenesisAccount{ authtypes.NewBaseAccount(privAcc.PubKey().Address().Bytes(), privAcc.PubKey(), 0, 0),