forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* in progress * update app.toml and config.toml * Update app/params/genesis.go * remove finished TODO comments
- Loading branch information
Showing
7 changed files
with
276 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/cosmos/go-bip39" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
tmcfg "github.com/tendermint/tendermint/config" | ||
"github.com/tendermint/tendermint/libs/cli" | ||
tmos "github.com/tendermint/tendermint/libs/os" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
"github.com/tendermint/tendermint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/input" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
appcfg "github.com/cosmos/cosmos-sdk/server/config" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
) | ||
|
||
const ( | ||
// FlagOverwrite defines a flag to overwrite an existing genesis JSON file. | ||
FlagOverwrite = "overwrite" | ||
|
||
// FlagSeed defines a flag to initialize the private validator key from a specific seed. | ||
FlagRecover = "recover" | ||
) | ||
|
||
type printInfo struct { | ||
Moniker string `json:"moniker" yaml:"moniker"` | ||
ChainID string `json:"chain_id" yaml:"chain_id"` | ||
NodeID string `json:"node_id" yaml:"node_id"` | ||
GenTxsDir string `json:"gentxs_dir" yaml:"gentxs_dir"` | ||
AppMessage json.RawMessage `json:"app_message" yaml:"app_message"` | ||
} | ||
|
||
func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.RawMessage) printInfo { | ||
return printInfo{ | ||
Moniker: moniker, | ||
ChainID: chainID, | ||
NodeID: nodeID, | ||
GenTxsDir: genTxsDir, | ||
AppMessage: appMessage, | ||
} | ||
} | ||
|
||
func displayInfo(info printInfo) error { | ||
out, err := json.MarshalIndent(info, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = fmt.Fprintf(os.Stderr, "%s\n", string(sdk.MustSortJSON(out))) | ||
|
||
return err | ||
} | ||
|
||
// InitCmd returns a command that initializes all files needed for Tendermint | ||
// and the respective application. | ||
func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init [moniker]", | ||
Short: "Initialize private validator, p2p, genesis, and application configuration files", | ||
Long: `Initialize validators's and node's configuration files.`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
cdc := clientCtx.JSONMarshaler | ||
|
||
serverCtx := server.GetServerContextFromCmd(cmd) | ||
config := serverCtx.Config | ||
|
||
config.P2P.MaxNumOutboundPeers = 40 | ||
config.Mempool.Size = 10000 | ||
config.StateSync.TrustPeriod = 112 * time.Hour | ||
config.FastSync.Version = "v2" | ||
|
||
config.SetRoot(clientCtx.HomeDir) | ||
|
||
appConfig := appcfg.DefaultConfig() | ||
appConfig.API.Enable = true | ||
appConfig.StateSync.SnapshotInterval = 1500 | ||
appConfig.StateSync.SnapshotKeepRecent = 2 | ||
|
||
chainID, _ := cmd.Flags().GetString(flags.FlagChainID) | ||
if chainID == "" { | ||
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6)) | ||
} | ||
|
||
fmt.Println("help") | ||
|
||
// Get bip39 mnemonic | ||
var mnemonic string | ||
recover, _ := cmd.Flags().GetBool(FlagRecover) | ||
if recover { | ||
inBuf := bufio.NewReader(cmd.InOrStdin()) | ||
mnemonic, err := input.GetString("Enter your bip39 mnemonic", inBuf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !bip39.IsMnemonicValid(mnemonic) { | ||
return errors.New("invalid mnemonic") | ||
} | ||
} | ||
|
||
nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
config.Moniker = args[0] | ||
|
||
genFile := config.GenesisFile() | ||
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite) | ||
|
||
if !overwrite && tmos.FileExists(genFile) { | ||
return fmt.Errorf("genesis.json file already exists: %v", genFile) | ||
} | ||
appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ") | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to marshall default genesis state") | ||
} | ||
|
||
genDoc := &types.GenesisDoc{} | ||
if _, err := os.Stat(genFile); err != nil { | ||
if !os.IsNotExist(err) { | ||
return err | ||
} | ||
} else { | ||
genDoc, err = types.GenesisDocFromFile(genFile) | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to read genesis doc from file") | ||
} | ||
} | ||
|
||
genDoc.ChainID = chainID | ||
genDoc.Validators = nil | ||
genDoc.AppState = appState | ||
if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil { | ||
return errors.Wrap(err, "Failed to export gensis file") | ||
} | ||
|
||
toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState) | ||
|
||
tmcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) | ||
appcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "app.toml"), appConfig) | ||
|
||
return displayInfo(toPrint) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory") | ||
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file") | ||
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating") | ||
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters