2018-05-25 13:46:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-08-14 22:13:54 +00:00
|
|
|
"io"
|
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
|
|
|
|
2019-06-20 13:37:57 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-06-20 16:29:13 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
gaiaInit "github.com/kava-labs/kava/init"
|
2019-06-20 13:37:57 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-05-25 13:46:33 +00:00
|
|
|
)
|
|
|
|
|
2019-06-07 11:59:19 +00:00
|
|
|
// gaiad custom flags
|
|
|
|
const flagInvCheckPeriod = "inv-check-period"
|
|
|
|
|
|
|
|
var invCheckPeriod uint
|
|
|
|
|
2018-05-25 13:46:33 +00:00
|
|
|
func main() {
|
2019-06-07 11:59:19 +00:00
|
|
|
cdc := app.MakeCodec()
|
2018-08-14 22:13:54 +00:00
|
|
|
|
2019-06-07 11:59:19 +00:00
|
|
|
config := sdk.GetConfig()
|
2019-06-20 13:37:57 +00:00
|
|
|
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
|
|
|
|
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
|
|
|
|
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
2019-06-07 11:59:19 +00:00
|
|
|
config.Seal()
|
2018-05-25 13:46:33 +00:00
|
|
|
|
2019-06-07 11:59:19 +00:00
|
|
|
ctx := server.NewDefaultContext()
|
2018-08-14 22:13:54 +00:00
|
|
|
cobra.EnableCommandSorting = false
|
2018-05-25 13:46:33 +00:00
|
|
|
rootCmd := &cobra.Command{
|
2019-06-20 13:37:57 +00:00
|
|
|
Use: "gaiad",
|
|
|
|
Short: "Gaia Daemon (server)",
|
2018-05-25 13:46:33 +00:00
|
|
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
|
|
|
}
|
|
|
|
|
2019-06-20 13:37:57 +00:00
|
|
|
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc))
|
|
|
|
rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc))
|
|
|
|
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))
|
|
|
|
rootCmd.AddCommand(gaiaInit.GenTxCmd(ctx, cdc))
|
|
|
|
rootCmd.AddCommand(gaiaInit.AddGenesisAccountCmd(ctx, cdc))
|
|
|
|
rootCmd.AddCommand(gaiaInit.ValidateGenesisCmd(ctx, cdc))
|
2019-06-07 11:59:19 +00:00
|
|
|
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
|
|
|
|
|
|
|
|
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
|
|
|
|
|
|
|
|
// prepare and add flags
|
2019-06-20 13:37:57 +00:00
|
|
|
executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome)
|
2019-06-07 11:59:19 +00:00
|
|
|
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
|
|
|
|
0, "Assert registered invariants every N blocks")
|
2018-08-14 22:13:54 +00:00
|
|
|
err := executor.Execute()
|
|
|
|
if err != nil {
|
2019-06-20 13:37:57 +00:00
|
|
|
// handle with #870
|
2018-08-14 22:13:54 +00:00
|
|
|
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 {
|
2019-06-20 13:37:57 +00:00
|
|
|
return app.NewGaiaApp(
|
2019-06-07 11:59:19 +00:00
|
|
|
logger, db, traceStore, true, invCheckPeriod,
|
|
|
|
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
|
|
|
|
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
|
|
|
|
)
|
2018-10-02 22:50:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-07 11:59:19 +00:00
|
|
|
func exportAppStateAndTMValidators(
|
|
|
|
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
|
|
|
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
2018-10-02 22:50:49 +00:00
|
|
|
|
2019-06-07 11:59:19 +00:00
|
|
|
if height != -1 {
|
2019-06-20 13:37:57 +00:00
|
|
|
gApp := app.NewGaiaApp(logger, db, traceStore, false, uint(1))
|
|
|
|
err := gApp.LoadHeight(height)
|
2019-06-07 11:59:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
2018-10-02 22:50:49 +00:00
|
|
|
}
|
2019-06-20 13:37:57 +00:00
|
|
|
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
2018-10-03 17:11:13 +00:00
|
|
|
}
|
2019-06-20 13:37:57 +00:00
|
|
|
gApp := app.NewGaiaApp(logger, db, traceStore, true, uint(1))
|
|
|
|
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
2018-10-03 17:11:13 +00:00
|
|
|
}
|