Skip to content

Commit dd82d0a

Browse files
authored
refactor: remove cosmoscmd (#5)
* upgrade * new files
1 parent 15b11f2 commit dd82d0a

832 files changed

Lines changed: 2351 additions & 519444 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/app.go

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,21 @@ import (
9696
ibcporttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types"
9797
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"
9898
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
99+
"github.com/ignite/cli/ignite/pkg/openapiconsole"
99100
"github.com/spf13/cast"
100101
abci "github.com/tendermint/tendermint/abci/types"
101102
tmjson "github.com/tendermint/tendermint/libs/json"
102103
"github.com/tendermint/tendermint/libs/log"
103104
tmos "github.com/tendermint/tendermint/libs/os"
104105
dbm "github.com/tendermint/tm-db"
105106

106-
"github.com/ignite/cli/ignite/pkg/cosmoscmd"
107-
"github.com/ignite/cli/ignite/pkg/openapiconsole"
108-
109-
"github.com/ignite/example/docs"
110-
111107
examplemodule "github.com/ignite/example/x/example"
112108
examplemodulekeeper "github.com/ignite/example/x/example/keeper"
113109
examplemoduletypes "github.com/ignite/example/x/example/types"
114110
// this line is used by starport scaffolding # stargate/app/moduleImport
111+
112+
appparams "github.com/ignite/example/app/params"
113+
"github.com/ignite/example/docs"
115114
)
116115

117116
const (
@@ -185,7 +184,6 @@ var (
185184
)
186185

187186
var (
188-
_ cosmoscmd.App = (*App)(nil)
189187
_ servertypes.Application = (*App)(nil)
190188
_ simapp.App = (*App)(nil)
191189
)
@@ -261,15 +259,21 @@ func New(
261259
skipUpgradeHeights map[int64]bool,
262260
homePath string,
263261
invCheckPeriod uint,
264-
encodingConfig cosmoscmd.EncodingConfig,
262+
encodingConfig appparams.EncodingConfig,
265263
appOpts servertypes.AppOptions,
266264
baseAppOptions ...func(*baseapp.BaseApp),
267-
) cosmoscmd.App {
265+
) *App {
268266
appCodec := encodingConfig.Marshaler
269267
cdc := encodingConfig.Amino
270268
interfaceRegistry := encodingConfig.InterfaceRegistry
271269

272-
bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
270+
bApp := baseapp.NewBaseApp(
271+
Name,
272+
logger,
273+
db,
274+
encodingConfig.TxConfig.TxDecoder(),
275+
baseAppOptions...,
276+
)
273277
bApp.SetCommitMultiStoreTracer(traceStore)
274278
bApp.SetVersion(version.Version)
275279
bApp.SetInterfaceRegistry(interfaceRegistry)
@@ -346,7 +350,7 @@ func New(
346350
app.BlockedModuleAccountAddrs(),
347351
)
348352

349-
stakingKeeper := stakingkeeper.NewKeeper(
353+
app.StakingKeeper = stakingkeeper.NewKeeper(
350354
appCodec,
351355
keys[stakingtypes.StoreKey],
352356
app.AccountKeeper,
@@ -358,7 +362,7 @@ func New(
358362
appCodec,
359363
keys[minttypes.StoreKey],
360364
app.GetSubspace(minttypes.ModuleName),
361-
&stakingKeeper,
365+
&app.StakingKeeper,
362366
app.AccountKeeper,
363367
app.BankKeeper,
364368
authtypes.FeeCollectorName,
@@ -370,14 +374,14 @@ func New(
370374
app.GetSubspace(distrtypes.ModuleName),
371375
app.AccountKeeper,
372376
app.BankKeeper,
373-
&stakingKeeper,
377+
&app.StakingKeeper,
374378
authtypes.FeeCollectorName,
375379
)
376380

377381
app.SlashingKeeper = slashingkeeper.NewKeeper(
378382
appCodec,
379383
keys[slashingtypes.StoreKey],
380-
&stakingKeeper,
384+
&app.StakingKeeper,
381385
app.GetSubspace(slashingtypes.ModuleName),
382386
)
383387

@@ -416,12 +420,6 @@ func New(
416420
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
417421
)
418422

419-
// register the staking hooks
420-
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
421-
app.StakingKeeper = *stakingKeeper.SetHooks(
422-
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
423-
)
424-
425423
// ... other modules keepers
426424

427425
// Create IBC Keeper
@@ -492,7 +490,7 @@ func New(
492490
app.GetSubspace(govtypes.ModuleName),
493491
app.AccountKeeper,
494492
app.BankKeeper,
495-
&stakingKeeper,
493+
&app.StakingKeeper,
496494
govRouter,
497495
app.MsgServiceRouter(),
498496
govConfig,
@@ -508,6 +506,8 @@ func New(
508506

509507
// this line is used by starport scaffolding # stargate/app/keeperDefinition
510508

509+
/**** IBC Routing ****/
510+
511511
// Sealing prevents other modules from creating scoped sub-keepers
512512
app.CapabilityKeeper.Seal()
513513

@@ -518,7 +518,25 @@ func New(
518518
// this line is used by starport scaffolding # ibc/app/router
519519
app.IBCKeeper.SetRouter(ibcRouter)
520520

521-
/**** Module Options ****/
521+
/**** Module Hooks ****/
522+
523+
// register hooks after all modules have been initialized
524+
525+
app.StakingKeeper.SetHooks(
526+
stakingtypes.NewMultiStakingHooks(
527+
// insert staking hooks receivers here
528+
app.DistrKeeper.Hooks(),
529+
app.SlashingKeeper.Hooks(),
530+
),
531+
)
532+
533+
app.GovKeeper.SetHooks(
534+
govtypes.NewMultiGovHooks(
535+
// insert governance hooks receivers here
536+
),
537+
)
538+
539+
/**** Module Options ****/
522540

523541
// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
524542
// we prefer to be more strict in what arguments the modules expect.
@@ -690,7 +708,7 @@ func New(
690708
},
691709
)
692710
if err != nil {
693-
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
711+
panic(fmt.Errorf("failed to create AnteHandler: %w", err))
694712
}
695713

696714
app.SetAnteHandler(anteHandler)
@@ -714,9 +732,6 @@ func New(
714732
// Name returns the name of the App
715733
func (app *App) Name() string { return app.BaseApp.Name() }
716734

717-
// GetBaseApp returns the base app of the application
718-
func (app App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }
719-
720735
// BeginBlocker application updates every begin block
721736
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
722737
return app.mm.BeginBlock(ctx, req)

app/encoding.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package app
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/codec"
5+
"github.com/cosmos/cosmos-sdk/codec/types"
6+
"github.com/cosmos/cosmos-sdk/std"
7+
"github.com/cosmos/cosmos-sdk/x/auth/tx"
8+
9+
"github.com/ignite/example/app/params"
10+
)
11+
12+
// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
13+
func makeEncodingConfig() params.EncodingConfig {
14+
amino := codec.NewLegacyAmino()
15+
interfaceRegistry := types.NewInterfaceRegistry()
16+
marshaler := codec.NewProtoCodec(interfaceRegistry)
17+
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
18+
19+
return params.EncodingConfig{
20+
InterfaceRegistry: interfaceRegistry,
21+
Marshaler: marshaler,
22+
TxConfig: txCfg,
23+
Amino: amino,
24+
}
25+
}
26+
27+
// MakeEncodingConfig creates an EncodingConfig for testing
28+
func MakeEncodingConfig() params.EncodingConfig {
29+
encodingConfig := makeEncodingConfig()
30+
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
31+
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
32+
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
33+
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
34+
return encodingConfig
35+
}

app/export.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ import (
44
"encoding/json"
55
"log"
66

7-
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
8-
97
servertypes "github.com/cosmos/cosmos-sdk/server/types"
108
sdk "github.com/cosmos/cosmos-sdk/types"
119
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
1210
"github.com/cosmos/cosmos-sdk/x/staking"
1311
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
12+
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
1413
)
1514

1615
// ExportAppStateAndValidators exports the state of the application for a genesis
1716
// file.
1817
func (app *App) ExportAppStateAndValidators(
1918
forZeroHeight bool, jailAllowedAddrs []string,
2019
) (servertypes.ExportedApp, error) {
21-
2220
// as if they could withdraw from the start of the next block
2321
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
2422

@@ -50,8 +48,7 @@ func (app *App) ExportAppStateAndValidators(
5048

5149
// prepare for fresh start at zero height
5250
// NOTE zero height genesis is a temporary feature which will be deprecated
53-
//
54-
// in favour of export at a block height
51+
// in favour of export at a block height
5552
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
5653
applyAllowedAddrs := false
5754

app/params/encoding.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package params
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/client"
5+
"github.com/cosmos/cosmos-sdk/codec"
6+
"github.com/cosmos/cosmos-sdk/codec/types"
7+
)
8+
9+
// EncodingConfig specifies the concrete encoding types to use for a given app.
10+
// This is provided for compatibility between protobuf and amino implementations.
11+
type EncodingConfig struct {
12+
InterfaceRegistry types.InterfaceRegistry
13+
Marshaler codec.Codec
14+
TxConfig client.TxConfig
15+
Amino *codec.LegacyAmino
16+
}

app/simulation_test.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,21 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/cosmos/cosmos-sdk/baseapp"
9-
"github.com/cosmos/cosmos-sdk/codec"
108
"github.com/cosmos/cosmos-sdk/simapp"
11-
sdk "github.com/cosmos/cosmos-sdk/types"
12-
"github.com/cosmos/cosmos-sdk/types/module"
139
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
1410
"github.com/cosmos/cosmos-sdk/x/simulation"
15-
"github.com/ignite/cli/ignite/pkg/cosmoscmd"
16-
"github.com/ignite/example/app"
1711
"github.com/stretchr/testify/require"
1812
abci "github.com/tendermint/tendermint/abci/types"
1913
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
2014
tmtypes "github.com/tendermint/tendermint/types"
15+
16+
"github.com/ignite/example/app"
2117
)
2218

2319
func init() {
2420
simapp.GetSimulatorFlags()
2521
}
2622

27-
type SimApp interface {
28-
cosmoscmd.App
29-
GetBaseApp() *baseapp.BaseApp
30-
AppCodec() codec.Codec
31-
SimulationManager() *module.SimulationManager
32-
ModuleAccountAddrs() map[string]bool
33-
Name() string
34-
LegacyAmino() *codec.LegacyAmino
35-
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
36-
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
37-
InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
38-
}
39-
4023
var defaultConsensusParams = &abci.ConsensusParams{
4124
Block: &abci.BlockParams{
4225
MaxBytes: 200000,
@@ -72,7 +55,7 @@ func BenchmarkSimulation(b *testing.B) {
7255
require.NoError(b, err)
7356
})
7457

75-
encoding := cosmoscmd.MakeEncodingConfig(app.ModuleBasics)
58+
encoding := app.MakeEncodingConfig()
7659

7760
app := app.New(
7861
logger,
@@ -86,24 +69,21 @@ func BenchmarkSimulation(b *testing.B) {
8669
simapp.EmptyAppOptions{},
8770
)
8871

89-
simApp, ok := app.(SimApp)
90-
require.True(b, ok, "can't use simapp")
91-
9272
// Run randomized simulations
9373
_, simParams, simErr := simulation.SimulateFromSeed(
9474
b,
9575
os.Stdout,
96-
simApp.GetBaseApp(),
97-
simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()),
76+
app.BaseApp,
77+
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
9878
simulationtypes.RandomAccounts,
99-
simapp.SimulationOperations(simApp, simApp.AppCodec(), config),
100-
simApp.ModuleAccountAddrs(),
79+
simapp.SimulationOperations(app, app.AppCodec(), config),
80+
app.ModuleAccountAddrs(),
10181
config,
102-
simApp.AppCodec(),
82+
app.AppCodec(),
10383
)
10484

10585
// export state and simParams before the simulation error is checked
106-
err = simapp.CheckExportSimulation(simApp, config, simParams)
86+
err = simapp.CheckExportSimulation(app, config, simParams)
10787
require.NoError(b, err)
10888
require.NoError(b, simErr)
10989

cmd/exampled/cmd/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
6+
"github.com/ignite/example/app"
7+
)
8+
9+
func initSDKConfig() {
10+
// Set prefixes
11+
accountPubKeyPrefix := app.AccountAddressPrefix + "pub"
12+
validatorAddressPrefix := app.AccountAddressPrefix + "valoper"
13+
validatorPubKeyPrefix := app.AccountAddressPrefix + "valoperpub"
14+
consNodeAddressPrefix := app.AccountAddressPrefix + "valcons"
15+
consNodePubKeyPrefix := app.AccountAddressPrefix + "valconspub"
16+
17+
// Set and seal config
18+
config := sdk.GetConfig()
19+
config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix)
20+
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
21+
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
22+
config.Seal()
23+
}

0 commit comments

Comments
 (0)