Skip to content

Commit

Permalink
refactor: cleanup new app v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bacbia3696 committed Aug 29, 2023
1 parent 1e50c85 commit fe82d43
Show file tree
Hide file tree
Showing 22 changed files with 12,011 additions and 4,794 deletions.
14 changes: 5 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -42,14 +43,14 @@ import (
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
gentleminttypes "github.com/sharering/shareledger/x/gentlemint/types"
"github.com/spf13/cast"

"github.com/sharering/shareledger/ante"
"github.com/sharering/shareledger/app/keepers"
"github.com/sharering/shareledger/app/params"
"github.com/sharering/shareledger/app/upgrades"
v2 "github.com/sharering/shareledger/app/upgrades/v2"
gentleminttypes "github.com/sharering/shareledger/x/gentlemint/types"
)

const (
Expand Down Expand Up @@ -85,7 +86,6 @@ type App struct {
cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
invCheckPeriod uint

// the module manager
ModuleManager *module.Manager
Expand All @@ -100,13 +100,11 @@ func New(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig params.EncodingConfig,

appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
encodingConfig := params.MakeTestEncodingConfig()
appCodec := encodingConfig.Codec
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -122,19 +120,17 @@ func New(
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
}

homePath := cast.ToString(appOpts.Get(flags.FlagHome))
// Setup keepers
app.AppKeepers = keepers.NewAppKeeper(
appCodec,
bApp,
encodingConfig.Amino,
maccPerms,
app.BlockedModuleAccountAddrs(),
skipUpgradeHeights,
homePath,
invCheckPeriod,
appOpts,
)

Expand Down
4 changes: 2 additions & 2 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var (
{
Name: "runtime",
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
AppName: "Shareledger",
AppName: "shareledger",
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
Expand Down Expand Up @@ -209,7 +209,7 @@ var (
{
Name: authtypes.ModuleName,
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: "cosmos",
Bech32Prefix: "shareledger",
ModuleAccountPermissions: moduleAccPerms,
// By default modules authority is the governance module. This is configurable with the following:
// Authority: "group", // A custom module authority can be set using a module name
Expand Down
8 changes: 4 additions & 4 deletions app/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"path/filepath"

"cosmossdk.io/depinject"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -68,6 +67,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
Expand All @@ -76,7 +76,6 @@ import (
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
assetmodule "github.com/sharering/shareledger/x/asset"
assetmodulekeeper "github.com/sharering/shareledger/x/asset/keeper"
bookingmodule "github.com/sharering/shareledger/x/booking"
Expand Down Expand Up @@ -214,6 +213,7 @@ func New(logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,

appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand Down
9 changes: 1 addition & 8 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"testing"
"time"

"github.com/cometbft/cometbft/crypto"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -131,17 +130,11 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

func setup() (*shareledgerapp.App, shareledgerapp.GenesisState) {
db := dbm.NewMemDB()
encCdc := shareledgerapp.MakeTestEncodingConfig()
var invCheckPeriod uint = 5
app := shareledgerapp.New(
log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
shareledgerapp.DefaultNodeHome,
invCheckPeriod,
encCdc,
EmptyAppOptions{},
)
return app, shareledgerapp.NewDefaultGenesisState()
Expand Down
15 changes: 9 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -64,12 +65,12 @@ import (
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"

ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"

"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cast"

assetmodulekeeper "github.com/sharering/shareledger/x/asset/keeper"
assetmoduletypes "github.com/sharering/shareledger/x/asset/types"
bookingmodulekeeper "github.com/sharering/shareledger/x/booking/keeper"
Expand All @@ -86,7 +87,6 @@ import (
idmoduletypes "github.com/sharering/shareledger/x/id/types"
swapmodulekeeper "github.com/sharering/shareledger/x/swap/keeper"
swapmoduletypes "github.com/sharering/shareledger/x/swap/types"
"github.com/spf13/cast"
)

type AppKeepers struct {
Expand Down Expand Up @@ -149,9 +149,7 @@ func NewAppKeeper(
legacyAmino *codec.LegacyAmino,
maccPerms map[string][]string,
blockedAddress map[string]bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
appOpts servertypes.AppOptions,
) AppKeepers {
appKeepers := AppKeepers{}
Expand Down Expand Up @@ -181,6 +179,7 @@ func NewAppKeeper(

appKeepers.CapabilityKeeper.Seal()

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
appKeepers.CrisisKeeper = crisiskeeper.NewKeeper(
appCodec,
appKeepers.GetKey(crisistypes.StoreKey),
Expand Down Expand Up @@ -316,6 +315,10 @@ func NewAppKeeper(

// set the governance module account as the authority for conducting upgrades
// UpgradeKeeper must be created before IBCKeeper
skipUpgradeHeights := map[int64]bool{}
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
appKeepers.keys[upgradetypes.StoreKey],
Expand Down
8 changes: 8 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by "buf config migrate-v1beta1". Edit as necessary, and
# remove this comment when you're finished.
#
# This workspace file points to the roots found in your
# previous "buf.yaml" configuration.
version: v1
directories:
- proto
20 changes: 4 additions & 16 deletions cmd/Shareledgerd/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -32,11 +31,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"

"github.com/sharering/shareledger/app"
"github.com/sharering/shareledger/app/params"
"github.com/sharering/shareledger/cmd/Shareledgerd/tools"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
Expand Down Expand Up @@ -244,10 +244,7 @@ func (ac appCreator) newApp(
}

return app.New(
logger, db, traceStore, true, skipUpgradeHeights,
homeDir,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
logger, db, traceStore, true,
appOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
Expand All @@ -274,11 +271,6 @@ func (ac appCreator) appExport(
appOpts servertypes.AppOptions,
modulesToExport []string,
) (servertypes.ExportedApp, error) {
homePath, ok := appOpts.Get(flags.FlagHome).(string)
if !ok || homePath == "" {
return servertypes.ExportedApp{}, errors.New("application home is not set")
}

var loadLatest bool
if height == -1 {
loadLatest = true
Expand All @@ -289,10 +281,6 @@ func (ac appCreator) appExport(
db,
traceStore,
loadLatest,
map[int64]bool{},
homePath,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
appOpts,
)

Expand Down
Loading

0 comments on commit fe82d43

Please sign in to comment.