Skip to content

Commit

Permalink
CM-268 Enable/disable CRUD module (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruck committed Feb 28, 2020
1 parent 6ea0e0d commit dff1dde
Showing 1 changed file with 55 additions and 20 deletions.
75 changes: 55 additions & 20 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package app

import (
"encoding/json"
"os"

bluzellechain "github.com/bluzelle/curium/types"
"github.com/bluzelle/curium/x/crud"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -32,17 +32,17 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

bam "github.com/cosmos/cosmos-sdk/baseapp"

bluzellechain "github.com/bluzelle/curium/types"
"os"
)

const crud_module_entry = "bluzelle_crud"

var (
// default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.blzcli")
Expand All @@ -51,19 +51,7 @@ var (
DefaultNodeHome = os.ExpandEnv("$HOME/.blzd")

// ModuleBasicManager is in charge of setting up basic module elements
ModuleBasics = module.NewBasicManager(
genaccounts.AppModuleBasic{},
genutil.AppModuleBasic{},
auth.AppModuleBasic{},
bank.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
params.AppModuleBasic{},
slashing.AppModuleBasic{},
supply.AppModuleBasic{},

crud.AppModule{},
)
ModuleBasics = newBasicManager(DefaultNodeHome)

// account permissions
maccPerms = map[string][]string{
Expand All @@ -74,6 +62,51 @@ var (
}
)

func IsCrudEnabled(nodeHome string) bool {
enabled := true

viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(nodeHome + "/config/")

if viper.ReadInConfig() == nil {
if viper.IsSet(crud_module_entry) {
enabled = viper.GetBool(crud_module_entry)
}
}

return enabled
}

func newBasicManager(nodeHome string) module.BasicManager {
if IsCrudEnabled(nodeHome) {
return module.NewBasicManager(
genaccounts.AppModuleBasic{},
genutil.AppModuleBasic{},
auth.AppModuleBasic{},
bank.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
params.AppModuleBasic{},
slashing.AppModuleBasic{},
supply.AppModuleBasic{},
crud.AppModule{},
)
} else {
return module.NewBasicManager(
genaccounts.AppModuleBasic{},
genutil.AppModuleBasic{},
auth.AppModuleBasic{},
bank.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
params.AppModuleBasic{},
slashing.AppModuleBasic{},
supply.AppModuleBasic{},
)
}
}

func MakeCodec() *codec.Codec {
var cdc = codec.New()
ModuleBasics.RegisterCodec(cdc)
Expand Down Expand Up @@ -239,7 +272,9 @@ func NewCRUDApp(
)

// register all module routes and module queriers
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
if IsCrudEnabled(DefaultNodeHome) {
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
}

// The initChainer handles translating the genesis.json file into initial state for the network
app.SetInitChainer(app.InitChainer)
Expand Down

0 comments on commit dff1dde

Please sign in to comment.