From 1f56d063e466861185d04e5704c851798750a122 Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Tue, 15 Feb 2022 11:50:10 +0700 Subject: [PATCH] fix wasm --- app/app.go | 54 ++++++++++++++++++++++++++----------------- app/wasm_config.go | 4 ++-- cmd/anoned/genwasm.go | 44 +++++++++++++++++++++++++++++++++++ cmd/anoned/main.go | 2 ++ 4 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 cmd/anoned/genwasm.go diff --git a/app/app.go b/app/app.go index 98e6769..72cabb6 100644 --- a/app/app.go +++ b/app/app.go @@ -380,12 +380,6 @@ func New( AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) - // register wasm gov proposal types - enabledProposals := GetEnabledProposals() - if len(enabledProposals) != 0 { - govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals)) - } - // Create Transfer Keepers app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), @@ -401,18 +395,6 @@ func New( // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper - app.GovKeeper = govkeeper.NewKeeper( - appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, - ) - - app.AnoneKeeper = *anonemodulekeeper.NewKeeper( - appCodec, - keys[anonemoduletypes.StoreKey], - keys[anonemoduletypes.MemStoreKey], - ) - anoneModule := anonemodule.NewAppModule(appCodec, app.AnoneKeeper) - wasmDir := filepath.Join(homePath, "data") wasmConfig, err := wasm.ReadWasmConfig(appOpts) @@ -443,6 +425,24 @@ func New( wasmOpts..., ) + // register wasm gov proposal types + enabledProposals := GetEnabledProposals() + if len(enabledProposals) != 0 { + govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals)) + } + + app.GovKeeper = govkeeper.NewKeeper( + appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, + &stakingKeeper, govRouter, + ) + + app.AnoneKeeper = *anonemodulekeeper.NewKeeper( + appCodec, + keys[anonemoduletypes.StoreKey], + keys[anonemoduletypes.MemStoreKey], + ) + anoneModule := anonemodule.NewAppModule(appCodec, app.AnoneKeeper) + // this line is used by starport scaffolding # stargate/app/keeperDefinition // Create static IBC router, add transfer route, then set and seal it @@ -493,12 +493,24 @@ func New( // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( - upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, - evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + ibchost.ModuleName, feegrant.ModuleName, + wasm.ModuleName, ) - app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) + app.mm.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + wasm.ModuleName, + ) // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. diff --git a/app/wasm_config.go b/app/wasm_config.go index 9d4f45d..ccab844 100644 --- a/app/wasm_config.go +++ b/app/wasm_config.go @@ -5,9 +5,9 @@ import ( ) const ( - // DefaultJunoInstanceCost is initially set the same as in wasmd + // DefaultAnoneInstanceCost is initially set the same as in wasmd DefaultAnOneInstanceCost uint64 = 60_000 - // DefaultJunoCompileCost set to a large number for testing + // DefaultAnoneCompileCost set to a large number for testing DefaultAnOneCompileCost uint64 = 100 ) diff --git a/cmd/anoned/genwasm.go b/cmd/anoned/genwasm.go new file mode 100644 index 0000000..aced3a1 --- /dev/null +++ b/cmd/anoned/genwasm.go @@ -0,0 +1,44 @@ +package main + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/notional-labs/anone/app" + "github.com/spf13/cobra" + "github.com/tendermint/spm/cosmoscmd" + + "github.com/CosmWasm/wasmd/x/wasm" + wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" +) + +func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command { + txCmd := &cobra.Command{ + Use: "add-wasm-genesis-message", + Short: "Wasm genesis subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + genesisIO := wasmcli.NewDefaultGenesisIO() + txCmd.AddCommand( + wasmcli.GenesisStoreCodeCmd(defaultNodeHome, genesisIO), + wasmcli.GenesisInstantiateContractCmd(defaultNodeHome, genesisIO), + wasmcli.GenesisExecuteContractCmd(defaultNodeHome, genesisIO), + wasmcli.GenesisListContractsCmd(defaultNodeHome, genesisIO), + wasmcli.GenesisListCodesCmd(defaultNodeHome, genesisIO), + ) + + return txCmd +} + +func GetWasmCmdOptions() []cosmoscmd.Option { + var options []cosmoscmd.Option + + options = append(options, + cosmoscmd.CustomizeStartCmd(func(startCmd *cobra.Command) { + wasm.AddModuleInitFlags(startCmd) + }), + cosmoscmd.AddSubCmd(AddGenesisWasmMsgCmd(app.DefaultNodeHome)), + ) + + return options +} diff --git a/cmd/anoned/main.go b/cmd/anoned/main.go index 7ba009f..cd32b86 100644 --- a/cmd/anoned/main.go +++ b/cmd/anoned/main.go @@ -9,6 +9,7 @@ import ( ) func main() { + cmdOptions := GetWasmCmdOptions() rootCmd, _ := cosmoscmd.NewRootCmd( app.Name, app.AccountAddressPrefix, @@ -17,6 +18,7 @@ func main() { app.ModuleBasics, app.New, // this line is used by starport scaffolding # root/arguments + cmdOptions..., ) if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { os.Exit(1)