Skip to content

Commit

Permalink
Remove AppInit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Nov 15, 2018
1 parent 7b7d45d commit e7b191d
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 63 deletions.
8 changes: 0 additions & 8 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
Expand Down Expand Up @@ -92,13 +91,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
}
}

// get app init parameters for server init command
func GaiaAppInit() server.AppInit {

return server.AppInit{
AppGenState: GaiaAppGenStateJSON,
}
}

// Create the core parameters for genesis initialization for gaia
// note that the pubkey input is this machines pubkey
Expand Down
8 changes: 3 additions & 5 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ func main() {
Short: "Gaia Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}
appInit := app.GaiaAppInit()
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc, appInit))
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, server.AppInit{}))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.GenTxCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.AddGenesisAccountCmd(ctx, cdc))

server.AddCommands(ctx, cdc, rootCmd, appInit,
newApp, exportAppStateAndTMValidators)
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

// prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func displayInfo(cdc *codec.Codec, info printInfo) error {

// get cmd to initialize all files for tendermint and application
// nolint
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Expand Down
16 changes: 3 additions & 13 deletions cmd/gaia/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ func TestInitCmd(t *testing.T) {

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenState,
}
cmd := InitCmd(ctx, cdc, appInit)
cmd := InitCmd(ctx, cdc)

viper.Set(flagMoniker, "gaianode-test")

Expand Down Expand Up @@ -65,13 +62,9 @@ func TestEmptyState(t *testing.T) {

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenStateEmpty,
}

viper.Set(flagMoniker, "gaianode-test")

cmd := InitCmd(ctx, cdc, appInit)
cmd := InitCmd(ctx, cdc)
err = cmd.RunE(nil, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -116,10 +109,7 @@ func TestStartStandAlone(t *testing.T) {
require.Nil(t, err)
ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenState,
}
initCmd := InitCmd(ctx, cdc, appInit)
initCmd := InitCmd(ctx, cdc)
err = initCmd.RunE(nil, nil)
require.NoError(t, err)

Expand Down
3 changes: 1 addition & 2 deletions cmd/gaia/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ var (
const nodeDirPerm = 0755

// get cmd to initialize all files for tendermint testnet and application
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec,
appInit server.AppInit) *cobra.Command {
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {

cmd := &cobra.Command{
Use: "testnet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ The `simplegovd` command will run the daemon server as a background process. Fir

```go
// cmd/simplegovd/main.go
// SimpleGovAppInit initial parameters
var SimpleGovAppInit = server.AppInit{
AppGenState: SimpleGovAppGenState,
AppGenTx: server.SimpleAppGenTx,
}

// SimpleGovAppGenState sets up the app_state and appends the simpleGov app state
func SimpleGovAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {
Expand Down Expand Up @@ -137,7 +132,7 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

server.AddCommands(ctx, cdc, rootCmd, SimpleGovAppInit,
server.AddCommands(ctx, cdc, rootCmd,
server.ConstructAppCreator(newApp, "simplegov"),
server.ConstructAppExporter(exportAppState, "simplegov"))

Expand Down
10 changes: 4 additions & 6 deletions docs/examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

appInit := server.DefaultAppInit
rootCmd.AddCommand(InitCmd(ctx, cdc, appInit))
rootCmd.AddCommand(InitCmd(ctx, cdc))

server.AddCommands(ctx, cdc, rootCmd, appInit,
newApp, exportAppStateAndTMValidators)
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

// prepare and add flags
rootDir := os.ExpandEnv("$HOME/.basecoind")
Expand All @@ -58,7 +56,7 @@ func main() {

// get cmd to initialize all files for tendermint and application
// nolint: errcheck
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize genesis config, priv-validator file, and p2p-node file",
Expand All @@ -84,7 +82,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
return err
}

appState, err := appInit.AppGenState(
appState, err := server.SimpleAppGenState(
cdc, tmtypes.GenesisDoc{}, []json.RawMessage{genTx})
if err != nil {
return err
Expand Down
15 changes: 5 additions & 10 deletions docs/examples/democoin/cmd/democoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ const (
flagClientHome = "home-client"
)

// init parameters
var CoolAppInit = server.AppInit{
AppGenState: CoolAppGenState,
}

// coolGenAppParams sets up the app_state and appends the cool app state
func CoolAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) (
Expand Down Expand Up @@ -65,7 +61,7 @@ func CoolAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []js

// get cmd to initialize all files for tendermint and application
// nolint: errcheck
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize genesis config, priv-validator file, and p2p-node file",
Expand All @@ -91,7 +87,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
return err
}

appState, err := appInit.AppGenState(cdc, tmtypes.GenesisDoc{},
appState, err := CoolAppGenState(cdc, tmtypes.GenesisDoc{},
[]json.RawMessage{genTx})
if err != nil {
return err
Expand Down Expand Up @@ -157,11 +153,10 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

rootCmd.AddCommand(InitCmd(ctx, cdc, CoolAppInit))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, CoolAppInit))
rootCmd.AddCommand(InitCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))

server.AddCommands(ctx, cdc, rootCmd, CoolAppInit,
newApp, exportAppStateAndTMValidators)
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

// prepare and add flags
rootDir := os.ExpandEnv("$HOME/.democoind")
Expand Down
11 changes: 0 additions & 11 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
)

// Core functionality passed from the application to the server init command
type AppInit struct {
// AppGenState creates the core parameters initialization. It takes in a
// pubkey meant to represent the pubkey of the validator of this machine.
AppGenState func(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) (
appState json.RawMessage, err error)
}

// SimpleGenTx is a simple genesis tx
type SimpleGenTx struct {
Expand All @@ -30,10 +23,6 @@ type SimpleGenTx struct {

//_____________________________________________________________________

// simple default application init
var DefaultAppInit = AppInit{
AppGenState: SimpleAppGenState,
}

// Generate a genesis transaction
func SimpleAppGenTx(cdc *codec.Codec, pk crypto.PubKey) (
Expand Down
2 changes: 1 addition & 1 deletion server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func validateConfig(conf *cfg.Config) error {
// add server commands
func AddCommands(
ctx *Context, cdc *codec.Codec,
rootCmd *cobra.Command, appInit AppInit,
rootCmd *cobra.Command,
appCreator AppCreator, appExport AppExporter) {

rootCmd.PersistentFlags().String("log_level", ctx.Config.LogLevel, "Log level")
Expand Down

0 comments on commit e7b191d

Please sign in to comment.