2018-07-19 21:16:48 +00:00
|
|
|
package main
|
|
|
|
|
2019-07-08 19:26:33 +00:00
|
|
|
import (
|
2019-07-12 17:13:15 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2020-08-04 18:52:32 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
dbm "github.com/tendermint/tm-db"
|
2019-07-12 17:13:15 +00:00
|
|
|
|
2019-09-26 15:50:55 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2019-11-13 17:00:21 +00:00
|
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
2019-09-26 15:50:55 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
2019-11-13 17:00:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
2019-09-26 15:50:55 +00:00
|
|
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
2019-11-05 16:50:55 +00:00
|
|
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
|
2019-11-04 20:45:02 +00:00
|
|
|
"github.com/cosmos/ethermint/app"
|
2020-08-04 18:52:32 +00:00
|
|
|
"github.com/cosmos/ethermint/client"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/ethermint/codec"
|
2020-08-04 18:52:32 +00:00
|
|
|
"github.com/cosmos/ethermint/crypto"
|
2020-08-05 13:27:48 +00:00
|
|
|
ethermint "github.com/cosmos/ethermint/types"
|
2019-07-08 19:26:33 +00:00
|
|
|
)
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
const flagInvCheckPeriod = "inv-check-period"
|
|
|
|
|
|
|
|
var invCheckPeriod uint
|
|
|
|
|
2018-07-19 21:16:48 +00:00
|
|
|
func main() {
|
2019-07-08 19:26:33 +00:00
|
|
|
cobra.EnableCommandSorting = false
|
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
cdc := codec.MakeCodec(app.ModuleBasics)
|
|
|
|
appCodec := codec.NewAppCodec(cdc)
|
2019-07-08 19:26:33 +00:00
|
|
|
|
2020-08-04 18:52:32 +00:00
|
|
|
tmamino.RegisterKeyType(crypto.PubKeySecp256k1{}, crypto.PubKeyAminoName)
|
|
|
|
tmamino.RegisterKeyType(crypto.PrivKeySecp256k1{}, crypto.PrivKeyAminoName)
|
2019-11-15 17:02:13 +00:00
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
keyring.CryptoCdc = cdc
|
2019-11-04 20:45:02 +00:00
|
|
|
genutil.ModuleCdc = cdc
|
2019-11-05 16:50:55 +00:00
|
|
|
genutiltypes.ModuleCdc = cdc
|
2019-11-13 17:00:21 +00:00
|
|
|
clientkeys.KeysCdc = cdc
|
2019-11-04 20:45:02 +00:00
|
|
|
|
2019-07-08 19:26:33 +00:00
|
|
|
config := sdk.GetConfig()
|
2020-08-05 13:27:48 +00:00
|
|
|
ethermint.SetBech32Prefixes(config)
|
2019-07-08 19:26:33 +00:00
|
|
|
config.Seal()
|
|
|
|
|
|
|
|
ctx := server.NewDefaultContext()
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
2020-08-05 15:17:50 +00:00
|
|
|
Use: "ethermintd",
|
2019-07-08 19:26:33 +00:00
|
|
|
Short: "Ethermint App Daemon (server)",
|
|
|
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
|
|
|
}
|
|
|
|
// CLI commands to initialize the chain
|
|
|
|
rootCmd.AddCommand(
|
2020-08-04 18:52:32 +00:00
|
|
|
client.ValidateChainID(
|
|
|
|
genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome),
|
|
|
|
),
|
2020-04-22 19:26:01 +00:00
|
|
|
genutilcli.CollectGenTxsCmd(ctx, cdc, bank.GenesisBalancesIterator{}, app.DefaultNodeHome),
|
2020-07-17 18:07:05 +00:00
|
|
|
genutilcli.MigrateGenesisCmd(ctx, cdc),
|
2019-11-13 17:00:21 +00:00
|
|
|
genutilcli.GenTxCmd(
|
2020-04-22 19:26:01 +00:00
|
|
|
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, bank.GenesisBalancesIterator{},
|
2020-04-01 18:49:21 +00:00
|
|
|
app.DefaultNodeHome, app.DefaultCLIHome,
|
2019-11-04 20:45:02 +00:00
|
|
|
),
|
2020-03-16 22:53:24 +00:00
|
|
|
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),
|
2020-08-04 18:52:32 +00:00
|
|
|
client.TestnetCmd(ctx, cdc, app.ModuleBasics, bank.GenesisBalancesIterator{}),
|
2019-07-08 19:26:33 +00:00
|
|
|
// AddGenesisAccountCmd allows users to add accounts to the genesis file
|
2020-04-22 19:26:01 +00:00
|
|
|
AddGenesisAccountCmd(ctx, cdc, appCodec, app.DefaultNodeHome, app.DefaultCLIHome),
|
|
|
|
flags.NewCompletionCmd(rootCmd, true),
|
2019-07-08 19:26:33 +00:00
|
|
|
)
|
|
|
|
|
2019-07-12 17:13:15 +00:00
|
|
|
// Tendermint node base commands
|
|
|
|
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
|
2019-07-08 19:26:33 +00:00
|
|
|
|
|
|
|
// prepare and add flags
|
2020-03-16 22:53:24 +00:00
|
|
|
executor := cli.PrepareBaseCmd(rootCmd, "EM", app.DefaultNodeHome)
|
2020-04-01 18:49:21 +00:00
|
|
|
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
|
|
|
|
0, "Assert registered invariants every N blocks")
|
2019-07-08 19:26:33 +00:00
|
|
|
err := executor.Execute()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-07-19 21:16:48 +00:00
|
|
|
}
|
2019-07-08 19:26:33 +00:00
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
|
|
|
|
return app.NewEthermintApp(logger, db, traceStore, true, 0,
|
2019-09-26 15:50:55 +00:00
|
|
|
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))))
|
2019-07-12 17:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func exportAppStateAndTMValidators(
|
2020-04-01 18:49:21 +00:00
|
|
|
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
2019-07-12 17:13:15 +00:00
|
|
|
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
|
|
|
|
|
|
|
if height != -1 {
|
2020-04-01 18:49:21 +00:00
|
|
|
emintApp := app.NewEthermintApp(logger, db, traceStore, true, 0)
|
2019-07-12 17:13:15 +00:00
|
|
|
err := emintApp.LoadHeight(height)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
|
|
|
}
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
emintApp := app.NewEthermintApp(logger, db, traceStore, true, 0)
|
2019-07-12 17:13:15 +00:00
|
|
|
|
|
|
|
return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
|
|
|
}
|