mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
This example shows how a user of the tendermint library can build their own node and supply it with its own commands. It includes two todos in order to make it easier for library users to use tendermint.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package commands
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/tendermint/tendermint/types"
|
|
cmn "github.com/tendermint/tmlibs/common"
|
|
)
|
|
|
|
var InitFilesCmd = &cobra.Command{
|
|
Use: "init",
|
|
Short: "Initialize Tendermint",
|
|
Run: initFiles,
|
|
}
|
|
|
|
func initFiles(cmd *cobra.Command, args []string) {
|
|
privValFile := config.PrivValidatorFile()
|
|
if _, err := os.Stat(privValFile); os.IsNotExist(err) {
|
|
privValidator := types.GenPrivValidator()
|
|
privValidator.SetFile(privValFile)
|
|
privValidator.Save()
|
|
|
|
genFile := config.GenesisFile()
|
|
|
|
if _, err := os.Stat(genFile); os.IsNotExist(err) {
|
|
genDoc := types.GenesisDoc{
|
|
ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)),
|
|
}
|
|
genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{
|
|
PubKey: privValidator.PubKey,
|
|
Power: 10,
|
|
}}
|
|
|
|
genDoc.SaveAs(genFile)
|
|
}
|
|
|
|
logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
|
|
} else {
|
|
logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile())
|
|
}
|
|
}
|