diff --git a/cmd/gaiacli/main.go b/cmd/gaiacli/main.go index dce125acb..0eb29c19c 100644 --- a/cmd/gaiacli/main.go +++ b/cmd/gaiacli/main.go @@ -17,9 +17,9 @@ const ( flagFee = "fee" ) -// gaiacliCmd is the entry point for this binary +// rootCmd is the entry point for this binary var ( - gaiacliCmd = &cobra.Command{ + rootCmd = &cobra.Command{ Use: "gaiacli", Short: "Gaia light-client", } @@ -54,16 +54,16 @@ func main() { cobra.EnableCommandSorting = false // generic client commands - AddClientCommands(gaiacliCmd) + AddClientCommands(rootCmd) // query commands (custom to binary) - gaiacliCmd.AddCommand( + rootCmd.AddCommand( GetCommands(getAccountCmd)...) // post tx commands (custom to binary) - gaiacliCmd.AddCommand( + rootCmd.AddCommand( PostCommands(postSendCommand())...) // add proxy, version and key info - gaiacliCmd.AddCommand( + rootCmd.AddCommand( lineBreak, serveCommand(), KeyCommands(), @@ -72,6 +72,6 @@ func main() { ) // prepare and add flags - executor := cli.PrepareBaseCmd(gaiacliCmd, "GA", os.ExpandEnv("$HOME/.gaiacli")) + executor := cli.PrepareBaseCmd(rootCmd, "GA", os.ExpandEnv("$HOME/.gaiacli")) executor.Execute() } diff --git a/cmd/gaiad/main.go b/cmd/gaiad/main.go index f42452135..d5f2311e4 100644 --- a/cmd/gaiad/main.go +++ b/cmd/gaiad/main.go @@ -1,95 +1,63 @@ package main import ( - "encoding/json" - "fmt" "os" + "path/filepath" "github.com/spf13/cobra" - "github.com/spf13/viper" abci "github.com/tendermint/abci/types" - tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tmlibs/cli" - tmflags "github.com/tendermint/tmlibs/cli/flags" - cmn "github.com/tendermint/tmlibs/common" + dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" - "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/examples/basecoin/app" "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/version" ) -// gaiadCmd is the entry point for this binary +// rootCmd is the entry point for this binary var ( - context = server.NewContext(nil, nil) - gaiadCmd = &cobra.Command{ - Use: "gaiad", - Short: "Gaia Daemon (server)", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - if cmd.Name() == version.VersionCmd.Name() { - return nil - } - config, err := tcmd.ParseConfig() - if err != nil { - return err - } - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel()) - if err != nil { - return err - } - if viper.GetBool(cli.TraceFlag) { - logger = log.NewTracingLogger(logger) - } - logger = logger.With("module", "main") - context.Config = config - context.Logger = logger - return nil - }, + context = server.NewContext(nil, nil) + rootCmd = &cobra.Command{ + Use: "gaiad", + Short: "Gaia Daemon (server)", + PersistentPreRunE: server.PersistentPreRunEFn(context), } ) -// defaultOptions sets up the app_options for the -// default genesis file -func defaultOptions(args []string) (json.RawMessage, string, cmn.HexBytes, error) { - addr, secret, err := server.GenerateCoinKey() - if err != nil { - return nil, "", nil, err - } - fmt.Println("Secret phrase to access coins:") - fmt.Println(secret) - - opts := fmt.Sprintf(`{ - "accounts": [{ - "address": "%s", - "coins": [ - { - "denom": "mycoin", - "amount": 9007199254740992 - } - ] - }] - }`, addr) - return json.RawMessage(opts), secret, addr, nil -} - +// TODO: distinguish from basecoin func generateApp(rootDir string, logger log.Logger) (abci.Application, error) { - // TODO: set this to something real - app := new(baseapp.BaseApp) - return app, nil + dataDir := filepath.Join(rootDir, "data") + dbMain, err := dbm.NewGoLevelDB("gaia", dataDir) + if err != nil { + return nil, err + } + dbAcc, err := dbm.NewGoLevelDB("gaia-acc", dataDir) + if err != nil { + return nil, err + } + dbIBC, err := dbm.NewGoLevelDB("gaia-ibc", dataDir) + if err != nil { + return nil, err + } + dbStaking, err := dbm.NewGoLevelDB("gaia-staking", dataDir) + if err != nil { + return nil, err + } + dbs := map[string]dbm.DB{ + "main": dbMain, + "acc": dbAcc, + "ibc": dbIBC, + "staking": dbStaking, + } + bapp := app.NewBasecoinApp(logger, dbs) + return bapp, nil } func main() { - gaiadCmd.AddCommand( - server.InitCmd(defaultOptions, context), - server.StartCmd(generateApp, context), - server.UnsafeResetAllCmd(context), - version.VersionCmd, - ) + server.AddCommands(rootCmd, server.DefaultGenAppState, generateApp, context) // prepare and add flags - executor := cli.PrepareBaseCmd(gaiadCmd, "GA", os.ExpandEnv("$HOME/.gaiad")) + executor := cli.PrepareBaseCmd(rootCmd, "GA", os.ExpandEnv("$HOME/.gaiad")) executor.Execute() }