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-08-23 21:41:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
2020-08-23 21:41:54 +00:00
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
2019-09-26 15:50:55 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-08-23 21:41:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
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-10-06 18:57:55 +00:00
|
|
|
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
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)
|
2019-07-08 19:26:33 +00:00
|
|
|
|
2020-10-06 18:57:55 +00:00
|
|
|
tmamino.RegisterKeyType(ethsecp256k1.PubKey{}, ethsecp256k1.PubKeyName)
|
|
|
|
tmamino.RegisterKeyType(ethsecp256k1.PrivKey{}, ethsecp256k1.PrivKeyName)
|
2019-11-15 17:02:13 +00:00
|
|
|
|
2020-08-23 21:41:54 +00:00
|
|
|
keys.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)
|
2020-08-28 15:35:10 +00:00
|
|
|
ethermint.SetBip44CoinType(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(
|
2021-02-26 15:50:22 +00:00
|
|
|
client.GenerateChainID(
|
|
|
|
client.ValidateChainID(
|
|
|
|
genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome),
|
|
|
|
),
|
2020-08-04 18:52:32 +00:00
|
|
|
),
|
2020-08-23 21:41:54 +00:00
|
|
|
genutilcli.CollectGenTxsCmd(ctx, cdc, auth.GenesisAccountIterator{}, 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-08-23 21:41:54 +00:00
|
|
|
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, auth.GenesisAccountIterator{},
|
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-23 21:41:54 +00:00
|
|
|
client.TestnetCmd(ctx, cdc, app.ModuleBasics, auth.GenesisAccountIterator{}),
|
2019-07-08 19:26:33 +00:00
|
|
|
// AddGenesisAccountCmd allows users to add accounts to the genesis file
|
2020-08-23 21:41:54 +00:00
|
|
|
AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),
|
2020-04-22 19:26:01 +00:00
|
|
|
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 {
|
2020-08-25 19:17:15 +00:00
|
|
|
return app.NewEthermintApp(
|
|
|
|
logger,
|
|
|
|
db,
|
|
|
|
traceStore,
|
|
|
|
true,
|
|
|
|
map[int64]bool{},
|
|
|
|
0,
|
|
|
|
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(viper.GetString("pruning"))),
|
|
|
|
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
|
|
|
|
baseapp.SetHaltHeight(uint64(viper.GetInt(server.FlagHaltHeight))),
|
|
|
|
)
|
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) {
|
2020-11-27 18:42:04 +00:00
|
|
|
var ethermintApp *app.EthermintApp
|
2020-08-25 19:17:15 +00:00
|
|
|
|
2019-07-12 17:13:15 +00:00
|
|
|
if height != -1 {
|
2020-11-27 18:42:04 +00:00
|
|
|
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, 0)
|
|
|
|
|
|
|
|
if err := ethermintApp.LoadHeight(height); err != nil {
|
2019-07-12 17:13:15 +00:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-11-27 18:42:04 +00:00
|
|
|
} else {
|
|
|
|
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, 0)
|
2019-07-12 17:13:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 19:17:15 +00:00
|
|
|
return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
2019-07-12 17:13:15 +00:00
|
|
|
}
|