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"
|
2019-11-02 17:13:31 +00:00
|
|
|
"fmt"
|
2019-07-12 17:13:15 +00:00
|
|
|
"io"
|
2019-11-02 17:13:31 +00:00
|
|
|
"math/big"
|
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"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2019-09-26 15:50:55 +00:00
|
|
|
"github.com/spf13/viper"
|
2019-07-08 19:26:33 +00:00
|
|
|
|
2019-11-04 20:45:02 +00:00
|
|
|
"github.com/cosmos/ethermint/app"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/ethermint/codec"
|
2019-11-15 17:02:13 +00:00
|
|
|
emintcrypto "github.com/cosmos/ethermint/crypto"
|
2019-07-12 17:13:15 +00:00
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2019-11-15 17:02:13 +00:00
|
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
2019-09-26 15:50:55 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2019-07-12 17:13:15 +00:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2019-09-26 15:50:55 +00:00
|
|
|
dbm "github.com/tendermint/tm-db"
|
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
|
|
|
|
2019-11-15 17:02:13 +00:00
|
|
|
tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
|
|
|
|
tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)
|
|
|
|
|
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()
|
|
|
|
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
|
|
|
|
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
|
|
|
|
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
|
|
|
config.Seal()
|
|
|
|
|
|
|
|
ctx := server.NewDefaultContext()
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
|
|
|
Use: "emintd",
|
|
|
|
Short: "Ethermint App Daemon (server)",
|
|
|
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
|
|
|
}
|
|
|
|
// CLI commands to initialize the chain
|
|
|
|
rootCmd.AddCommand(
|
2020-03-16 22:53:24 +00:00
|
|
|
withChainIDValidation(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),
|
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)
|
|
|
|
}
|
2019-11-02 17:13:31 +00:00
|
|
|
|
|
|
|
// Wraps cobra command with a RunE function with integer chain-id verification
|
|
|
|
func withChainIDValidation(baseCmd *cobra.Command) *cobra.Command {
|
|
|
|
// Copy base run command to be used after chain verification
|
|
|
|
baseRunE := baseCmd.RunE
|
|
|
|
|
|
|
|
// Function to replace command's RunE function
|
|
|
|
chainIDVerify := func(cmd *cobra.Command, args []string) error {
|
2020-04-22 19:26:01 +00:00
|
|
|
chainIDFlag := viper.GetString(flags.FlagChainID)
|
2019-11-02 17:13:31 +00:00
|
|
|
|
|
|
|
// Verify that the chain-id entered is a base 10 integer
|
|
|
|
_, ok := new(big.Int).SetString(chainIDFlag, 10)
|
|
|
|
if !ok {
|
2020-04-01 18:49:21 +00:00
|
|
|
return fmt.Errorf("invalid chainID: %s, must be base-10 integer format", chainIDFlag)
|
2019-11-02 17:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return baseRunE(cmd, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
baseCmd.RunE = chainIDVerify
|
|
|
|
return baseCmd
|
|
|
|
}
|