cmd

package
v1.5.4-beta2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FlagName       = "name"
	FlagClientHome = "home-client"
	FlagOWK        = "owk"
)
View Source
var (
	FlagOverwrite = "overwrite"
	FlagWithTxs   = "with-txs"
	FlagIP        = "ip"
	FlagChainID   = "chain_id"
	FlagStateDB   = "statedb"
	//FlagDBName = "dbname"
	FlagWithValidator = "validator_key"
	FlagCoinName      = "denom"
)
View Source
var LineBreak = &cobra.Command{Run: func(cmd *cobra.Command, args []string) {}}

Functions

func AddGenesisAccountCmd

func AddGenesisAccountCmd(ctx *app.Context, cdc *codec.Codec) *cobra.Command

func AddGenesisShardCmd

func AddGenesisShardCmd(ctx *app.Context, cdc *codec.Codec) *cobra.Command

func AddGenesisValidatorCmd

func AddGenesisValidatorCmd(ctx *app.Context, cdc *codec.Codec) *cobra.Command

func AddServerCommands

func AddServerCommands(
	ctx *app.Context,
	cdc *amino.Codec,
	rootCmd *cobra.Command,
	appInit app.AppInit,
	appCreator app.AppCreator,
	appExport app.AppExporter,
)

func CopyFile

func CopyFile(src, dst string) error

func GetVersion

func GetVersion() string

return version of CLI/node and commit hash

func InitWithConfig

func InitWithConfig(cdc *amino.Codec, appInit app.AppInit, c *cfg.Config, initConfig InitConfig) (
	chainID string, nodeID string, appMessage json.RawMessage, pubKey crypto.PubKey, err error)

func InitWithConfig(cdc *amino.Codec, appInit app.AppInit, c *cfg.Config, initConfig InitConfig)(

	chainID string, nodeID string, appMessage json.RawMessage, pubKey string, err error) {
	var validatorKey secp256k1.PrivKeySecp256k1
	var privStr string
	nodeKey, err := node.LoadNodeKey(c.NodeKeyFile())
	privBz := viper.GetString(FlagWithValidator)
	if len(privBz) > 0 {
		//1.match length
		priByt := []byte(privBz)
		length := len(priByt)
		if length != 44 {
			panic(errors.New(fmt.Sprintf("length of validator key does not match, expected %d, got %d",44 ,length)))
		}

		//2.regex match
		rule := `=$`
		reg := regexp.MustCompile(rule)
		if !reg.MatchString(privBz) {
			panic(errors.New("the end of the validator key string should be an equal sign"))
		}

		//3.match base64 encoding
		_,err := base64.StdEncoding.DecodeString(privBz)
		if err != nil {
			panic(err)
		}

		privStr = fmt.Sprintf(`{"type":"%s","value":"%s"}`, secp256k1.PrivKeyAminoName, privBz)
		err = cdc.UnmarshalJSON([]byte(privStr), &validatorKey)
		if err != nil {
			panic(err)
		}
	}else {

		panic(errors.New("validator key can not be empty"))
	}

	pv := validator.GenFilePV(
		c.PrivValidatorKeyFile(),
		c.PrivValidatorStateFile(),
		validatorKey,
	)

	nodeKey, err = node.GenNodeKeyByPrivKey(c.NodeKeyFile(), pv.Key.PrivKey)
	if err != nil {
		panic(err)
	}
	nodeID = string(nodeKey.ID())

	chainID = initConfig.ChainID

	genFile := c.GenesisFile()
	if !initConfig.Overwrite && cmn.FileExists(genFile) {
		err = fmt.Errorf("genesis.json file already exists: %v", genFile)
		return
	}

	validator := appInit.GetValidator(nodeKey.PubKey(), viper.GetString(FlagName))
	validators := []tmtypes.GenesisValidator{validator}

	appState, err := appInit.AppGenState(validators)

	if err != nil {
		return
	}
	err = writeGenesisFile(cdc, genFile, initConfig.ChainID, validators, appState, initConfig.GenesisTime)
	if err != nil {
		return
	}
	return
}

func ParseAccAddress

func ParseAccAddress(addr string) types.AccAddress

func ParseCoin

func ParseCoin(denom, amount string) (types.Coin, error)

func StartInProcess

func StartInProcess(ctx *app.Context, appCreator app.AppCreator, cdc *codec.Codec) (*node.Node, error)

Types

type GenesisTx

type GenesisTx struct {
	NodeID    string                   `json:"node_id"`
	IP        string                   `json:"ip"`
	Validator tmtypes.GenesisValidator `json:"validator"`
	AppGenTx  json.RawMessage          `json:"app_gen_tx"`
}

type InitConfig

type InitConfig struct {
	ChainID     string
	GenTxs      bool
	GenTxsDir   string
	Overwrite   bool
	GenesisTime time.Time
}

type ValidatorAccount

type ValidatorAccount struct {
	Address    string `json:"address"`
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL