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

feat: add denom flag #1

Merged
merged 3 commits into from
Dec 12, 2023
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
11 changes: 5 additions & 6 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
17 changes: 9 additions & 8 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{}
Expand All @@ -78,6 +79,13 @@ func SetupWithGenesisAccounts(
) *MinitiaApp {
app, genesisState := setup(nil, true)

if 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)
Expand All @@ -94,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 {
Expand Down
12 changes: 11 additions & 1 deletion cmd/minitiad/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
3 changes: 0 additions & 3 deletions cmd/minitiad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading