Minor cleanups and comments (#1712)
* Minor cleanups and comments * Lint
This commit is contained in:
@@ -29,6 +29,7 @@ type HandlerOptions struct {
|
||||
CircuitKeeper *circuitkeeper.Keeper
|
||||
}
|
||||
|
||||
// NewAnteHandler constructor
|
||||
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
|
||||
if options.AccountKeeper == nil {
|
||||
return nil, errors.New("account keeper is required for ante builder")
|
||||
|
||||
33
app/app.go
33
app/app.go
@@ -393,6 +393,21 @@ func NewWasmApp(
|
||||
logger,
|
||||
)
|
||||
|
||||
// optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
|
||||
// enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
|
||||
// txConfigOpts := tx.ConfigOptions{
|
||||
// EnabledSignModes: enabledSignModes,
|
||||
// TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
|
||||
// }
|
||||
// txConfig, err := tx.NewTxConfigWithOptions(
|
||||
// appCodec,
|
||||
// txConfigOpts,
|
||||
// )
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// app.txConfig = txConfig
|
||||
|
||||
app.StakingKeeper = stakingkeeper.NewKeeper(
|
||||
appCodec,
|
||||
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
|
||||
@@ -510,9 +525,7 @@ func NewWasmApp(
|
||||
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
|
||||
govRouter := govv1beta1.NewRouter()
|
||||
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
|
||||
// This should be removed. It is still in place to avoid failures of modules that have not yet been upgraded.
|
||||
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
|
||||
|
||||
govConfig := govtypes.DefaultConfig()
|
||||
/*
|
||||
Example of setting gov params:
|
||||
@@ -530,6 +543,9 @@ func NewWasmApp(
|
||||
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||
)
|
||||
|
||||
// Set legacy router for backwards compatibility with gov v1beta1
|
||||
govKeeper.SetLegacyRouter(govRouter)
|
||||
|
||||
app.GovKeeper = *govKeeper.SetHooks(
|
||||
govtypes.NewMultiGovHooks(
|
||||
// register the governance hooks
|
||||
@@ -631,9 +647,6 @@ func NewWasmApp(
|
||||
wasmOpts...,
|
||||
)
|
||||
|
||||
// Set legacy router for backwards compatibility with gov v1beta1
|
||||
app.GovKeeper.SetLegacyRouter(govRouter)
|
||||
|
||||
// Create Transfer Stack
|
||||
var transferStack porttypes.IBCModule
|
||||
transferStack = transfer.NewIBCModule(app.TransferKeeper)
|
||||
@@ -725,7 +738,6 @@ func NewWasmApp(
|
||||
paramsclient.ProposalHandler,
|
||||
},
|
||||
),
|
||||
ibctm.ModuleName: ibctm.AppModuleBasic{},
|
||||
})
|
||||
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
|
||||
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
|
||||
@@ -873,12 +885,7 @@ func NewWasmApp(
|
||||
// meaning that both `runMsgs` and `postHandler` state will be committed if
|
||||
// both are successful, and both will be reverted if any of the two fails.
|
||||
//
|
||||
// The SDK exposes a default postHandlers chain, which comprises of only
|
||||
// one decorator: the Transaction Tips decorator. However, some chains do
|
||||
// not need it by default, so feel free to comment the next line if you do
|
||||
// not need tips.
|
||||
// To read more about tips:
|
||||
// https://docs.cosmos.network/main/core/tips.html
|
||||
// The SDK exposes a default postHandlers chain
|
||||
//
|
||||
// Please note that changing any of the anteHandler or postHandler chain is
|
||||
// likely to be a state-machine breaking change, which needs a coordinated
|
||||
@@ -933,6 +940,8 @@ func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
|
||||
}
|
||||
|
||||
// Set the AnteHandler for the app
|
||||
app.SetAnteHandler(anteHandler)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,6 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
|
||||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
|
||||
)
|
||||
|
||||
// GenesisState of the blockchain is represented here as a map of raw json
|
||||
@@ -21,13 +12,3 @@ import (
|
||||
// the ModuleBasicManager which populates json from each BasicModule
|
||||
// object provided to it during init.
|
||||
type GenesisState map[string]json.RawMessage
|
||||
|
||||
// NewDefaultGenesisState generates the default state for the application.
|
||||
// Deprecated: use wasmApp.DefaultGenesis() instead
|
||||
func NewDefaultGenesisState(t *testing.T) GenesisState {
|
||||
t.Helper()
|
||||
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
|
||||
// note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
|
||||
tempApp := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), []wasmkeeper.Option{})
|
||||
return tempApp.DefaultGenesis()
|
||||
}
|
||||
|
||||
@@ -175,13 +175,6 @@ func SetupWithGenesisValSet(
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
votes := make([]abci.VoteInfo, len(valSet.Validators))
|
||||
for i, v := range valSet.Validators {
|
||||
votes[i] = abci.VoteInfo{
|
||||
Validator: abci.Validator{Address: v.Address, Power: v.VotingPower},
|
||||
}
|
||||
}
|
||||
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
Height: app.LastBlockHeight() + 1,
|
||||
Hash: app.LastCommitID().Hash,
|
||||
@@ -236,12 +229,12 @@ func AddTestAddrsIncremental(app *WasmApp, ctx sdk.Context, accNum int, accAmt s
|
||||
|
||||
func addTestAddrs(app *WasmApp, ctx sdk.Context, accNum int, accAmt sdkmath.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress {
|
||||
testAddrs := strategy(accNum)
|
||||
|
||||
denom, err := app.StakingKeeper.BondDenom(ctx)
|
||||
bondDenom, err := app.StakingKeeper.BondDenom(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(denom, accAmt))
|
||||
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, accAmt))
|
||||
|
||||
for _, addr := range testAddrs {
|
||||
initAccountWithCoins(app, ctx, addr, initCoins)
|
||||
@@ -262,13 +255,6 @@ func initAccountWithCoins(app *WasmApp, ctx sdk.Context, addr sdk.AccAddress, co
|
||||
}
|
||||
}
|
||||
|
||||
// ModuleAccountAddrs provides a list of blocked module accounts from configuration in AppConfig
|
||||
//
|
||||
// Ported from WasmApp
|
||||
func ModuleAccountAddrs() map[string]bool {
|
||||
return BlockedAddresses()
|
||||
}
|
||||
|
||||
var emptyWasmOptions []wasmkeeper.Option
|
||||
|
||||
// NewTestNetworkFixture returns a new WasmApp AppConstructor for network simulation tests
|
||||
|
||||
@@ -24,7 +24,7 @@ func NewUpgrade(semver string) upgrades.Upgrade {
|
||||
}
|
||||
|
||||
func CreateUpgradeHandler(
|
||||
mm *module.Manager,
|
||||
mm upgrades.ModuleManager,
|
||||
configurator module.Configurator,
|
||||
ak *upgrades.AppKeepers,
|
||||
) upgradetypes.UpgradeHandler {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
upgradetypes "cosmossdk.io/x/upgrade/types"
|
||||
|
||||
@@ -11,6 +13,10 @@ import (
|
||||
type AppKeepers struct {
|
||||
authkeeper.AccountKeeper
|
||||
}
|
||||
type ModuleManager interface {
|
||||
RunMigrations(ctx context.Context, cfg module.Configurator, fromVM module.VersionMap) (module.VersionMap, error)
|
||||
GetVersionMap() module.VersionMap
|
||||
}
|
||||
|
||||
// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
|
||||
// must have written, in order for the state migration to go smoothly.
|
||||
@@ -21,6 +27,6 @@ type Upgrade struct {
|
||||
UpgradeName string
|
||||
|
||||
// CreateUpgradeHandler defines the function that creates an upgrade handler
|
||||
CreateUpgradeHandler func(*module.Manager, module.Configurator, *AppKeepers) upgradetypes.UpgradeHandler
|
||||
CreateUpgradeHandler func(ModuleManager, module.Configurator, *AppKeepers) upgradetypes.UpgradeHandler
|
||||
StoreUpgrades storetypes.StoreUpgrades
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ var Upgrade = upgrades.Upgrade{
|
||||
}
|
||||
|
||||
func CreateUpgradeHandler(
|
||||
mm *module.Manager,
|
||||
mm upgrades.ModuleManager,
|
||||
configurator module.Configurator,
|
||||
ak *upgrades.AppKeepers,
|
||||
) upgradetypes.UpgradeHandler {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
@@ -49,6 +48,7 @@ func NewRootCmd() *cobra.Command {
|
||||
initClientCtx := client.Context{}.
|
||||
WithCodec(encodingConfig.Codec).
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithLegacyAmino(encodingConfig.Amino).
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(authtypes.AccountRetriever{}).
|
||||
@@ -56,8 +56,9 @@ func NewRootCmd() *cobra.Command {
|
||||
WithViper("") // In wasmd, we don't use any prefix for env variables.
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: version.AppName,
|
||||
Short: "Wasm Daemon (server)",
|
||||
Use: version.AppName,
|
||||
Short: "Wasm Daemon (server)",
|
||||
SilenceErrors: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
// set the default command outputs
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
@@ -75,19 +76,24 @@ func NewRootCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
// This needs to go after ReadFromClientConfig, as that function
|
||||
// sets the RPC client needed for SIGN_MODE_TEXTUAL.
|
||||
txConfigOpts := tx.ConfigOptions{
|
||||
EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL),
|
||||
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
|
||||
// sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
|
||||
// is only available if the client is online.
|
||||
if !initClientCtx.Offline {
|
||||
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
|
||||
txConfigOpts := tx.ConfigOptions{
|
||||
EnabledSignModes: enabledSignModes,
|
||||
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
|
||||
}
|
||||
txConfig, err := tx.NewTxConfigWithOptions(
|
||||
initClientCtx.Codec,
|
||||
txConfigOpts,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
initClientCtx = initClientCtx.WithTxConfig(txConfig)
|
||||
}
|
||||
txConfigWithTextual, err := tx.NewTxConfigWithOptions(
|
||||
codec.NewProtoCodec(encodingConfig.InterfaceRegistry),
|
||||
txConfigOpts,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual)
|
||||
|
||||
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user