genesis account coin denom flag

This commit is contained in:
rigelrozanski 2017-10-11 14:06:57 -04:00
parent 40c79a65b3
commit 1613da91ca
2 changed files with 23 additions and 18 deletions

View File

@ -18,24 +18,29 @@ import (
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
) )
// InitCmd - node initialization command
var InitCmd = &cobra.Command{
Use: "init [address]",
Short: "Initialize genesis files for a blockchain",
RunE: initCmd,
}
//nolint - flags
var ( var (
// InitCmd - node initialization command
InitCmd = GetInitCmd("mycoin")
//nolint - flags
FlagChainID = "chain-id" //TODO group with other flags or remove? is this already a flag here? FlagChainID = "chain-id" //TODO group with other flags or remove? is this already a flag here?
FlagDenom = "denom" //TODO group with other flags or remove? is this already a flag here?
FlagOption = "option" FlagOption = "option"
FlagStatic = "static" FlagStatic = "static"
) )
func init() { // GetInitCmd - get the node initialization command, with a custom genesis account denom
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID") func GetInitCmd(defaultDenom string) *cobra.Command {
InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>") initCmd := &cobra.Command{
InitCmd.Flags().Bool(FlagStatic, false, "use a static private validator") Use: "init [address]",
Short: "Initialize genesis files for a blockchain",
RunE: initCmd,
}
initCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
initCmd.Flags().String(FlagDenom, defaultDenom, "Coin denomination for genesis account")
initCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>")
initCmd.Flags().Bool(FlagStatic, false, "use a static private validator")
return initCmd
} }
// returns 1 iff it set a file, otherwise 0 (so we can add them) // returns 1 iff it set a file, otherwise 0 (so we can add them)
@ -110,7 +115,7 @@ func initCmd(cmd *cobra.Command, args []string) error {
privValJSON = string(pvBytes) privValJSON = string(pvBytes)
} }
genesis := GetGenesisJSON(pubkey, viper.GetString(FlagChainID), genesis := GetGenesisJSON(pubkey, viper.GetString(FlagChainID), viper.GetString(FlagDenom),
userAddr, optionsStr) userAddr, optionsStr)
return CreateGenesisValidatorFiles(cfg, genesis, privValJSON, cmd.Root().Name()) return CreateGenesisValidatorFiles(cfg, genesis, privValJSON, cmd.Root().Name())
} }
@ -164,7 +169,7 @@ func CreateGenesisValidatorFiles(cfg *config.Config, genesis, privVal, appName s
// GetGenesisJSON returns a new tendermint genesis with Basecoin app_options // GetGenesisJSON returns a new tendermint genesis with Basecoin app_options
// that grant a large amount of "mycoin" to a single address // that grant a large amount of "mycoin" to a single address
// TODO: A better UX for generating genesis files // TODO: A better UX for generating genesis files
func GetGenesisJSON(pubkey, chainID, addr string, options string) string { func GetGenesisJSON(pubkey, chainID, denom, addr string, options string) string {
return fmt.Sprintf(`{ return fmt.Sprintf(`{
"app_hash": "", "app_hash": "",
"chain_id": "%s", "chain_id": "%s",
@ -184,7 +189,7 @@ func GetGenesisJSON(pubkey, chainID, addr string, options string) string {
"address": "%s", "address": "%s",
"coins": [ "coins": [
{ {
"denom": "mycoin", "denom": "%s",
"amount": 9007199254740992 "amount": 9007199254740992
} }
] ]
@ -193,5 +198,5 @@ func GetGenesisJSON(pubkey, chainID, addr string, options string) string {
"coin/issuer", {"app": "sigs", "addr": "%s"}%s "coin/issuer", {"app": "sigs", "addr": "%s"}%s
] ]
} }
}`, chainID, pubkey, addr, addr, options) }`, chainID, pubkey, addr, denom, addr, options)
} }

View File

@ -30,8 +30,8 @@ var StartCmd = &cobra.Command{
RunE: startCmd, RunE: startCmd,
} }
// InitTickStartCmd - initialize a command as the start command with tick // GetTickStartCmd - initialize a command as the start command with tick
func InitTickStartCmd(tick app.Ticker) *cobra.Command { func GetTickStartCmd(tick app.Ticker) *cobra.Command {
startCmd := &cobra.Command{ startCmd := &cobra.Command{
Use: "start", Use: "start",
Short: "Start this full node", Short: "Start this full node",