2018-05-25 13:46:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-08-14 22:13:54 +00:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2018-05-25 13:46:33 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2018-08-14 22:13:54 +00:00
|
|
|
"github.com/spf13/viper"
|
2018-05-25 13:46:33 +00:00
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
|
|
dbm "github.com/tendermint/tendermint/libs/db"
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2018-06-16 21:34:07 +00:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2018-05-25 13:46:33 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
2018-06-16 16:21:13 +00:00
|
|
|
"github.com/kava-labs/kava/internal/app"
|
2018-05-25 13:46:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-08-14 22:13:54 +00:00
|
|
|
// Create an app codec
|
|
|
|
cdc := app.CreateKavaAppCodec()
|
|
|
|
|
|
|
|
// Create a server context (a struct of a tendermint config and a logger)
|
2018-05-25 13:46:33 +00:00
|
|
|
ctx := server.NewDefaultContext()
|
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
// Create the root kvd command
|
|
|
|
cobra.EnableCommandSorting = false
|
2018-05-25 13:46:33 +00:00
|
|
|
rootCmd := &cobra.Command{
|
2018-06-16 21:34:07 +00:00
|
|
|
Use: "kvd",
|
2018-06-16 16:21:13 +00:00
|
|
|
Short: "Kava Daemon",
|
2018-05-25 13:46:33 +00:00
|
|
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
|
|
|
}
|
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
// Add server commands to kvd, passing in the app
|
|
|
|
appInit := app.KavaAppInit()
|
|
|
|
appCreator := server.ConstructAppCreator(newApp, "kava") // init db before calling newApp
|
|
|
|
appExporter := server.ConstructAppExporter(exportAppStateAndTMValidators, "kava")
|
|
|
|
|
|
|
|
server.AddCommands(ctx, cdc, rootCmd, appInit, appCreator, appExporter)
|
2018-05-25 13:46:33 +00:00
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
// handle envs and add some flags and stuff
|
|
|
|
executor := cli.PrepareBaseCmd(rootCmd, "KV", app.DefaultNodeHome)
|
|
|
|
|
|
|
|
// Run kvd
|
|
|
|
err := executor.Execute()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-05-25 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
|
|
|
|
return app.NewKavaApp(logger, db, traceStore, baseapp.SetPruning(viper.GetString("pruning")))
|
2018-05-25 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 22:13:54 +00:00
|
|
|
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, traceStore io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
|
|
|
tempApp := app.NewKavaApp(logger, db, traceStore)
|
|
|
|
return tempApp.ExportAppStateAndValidators()
|
2018-05-25 13:46:33 +00:00
|
|
|
}
|