Skip to content

Commit

Permalink
genesis account coin denom flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Oct 11, 2017
1 parent 40c79a6 commit 1613da9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
37 changes: 21 additions & 16 deletions server/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ import (
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 (
// 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?
FlagDenom = "denom" //TODO group with other flags or remove? is this already a flag here?
FlagOption = "option"
FlagStatic = "static"
)

func init() {
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>")
InitCmd.Flags().Bool(FlagStatic, false, "use a static private validator")
// GetInitCmd - get the node initialization command, with a custom genesis account denom
func GetInitCmd(defaultDenom string) *cobra.Command {
initCmd := &cobra.Command{
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)
Expand Down Expand Up @@ -110,7 +115,7 @@ func initCmd(cmd *cobra.Command, args []string) error {
privValJSON = string(pvBytes)
}

genesis := GetGenesisJSON(pubkey, viper.GetString(FlagChainID),
genesis := GetGenesisJSON(pubkey, viper.GetString(FlagChainID), viper.GetString(FlagDenom),
userAddr, optionsStr)
return CreateGenesisValidatorFiles(cfg, genesis, privValJSON, cmd.Root().Name())
}
Expand Down Expand Up @@ -164,7 +169,7 @@ func CreateGenesisValidatorFiles(cfg *config.Config, genesis, privVal, appName s
// GetGenesisJSON returns a new tendermint genesis with Basecoin app_options
// that grant a large amount of "mycoin" to a single address
// 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(`{
"app_hash": "",
"chain_id": "%s",
Expand All @@ -184,7 +189,7 @@ func GetGenesisJSON(pubkey, chainID, addr string, options string) string {
"address": "%s",
"coins": [
{
"denom": "mycoin",
"denom": "%s",
"amount": 9007199254740992
}
]
Expand All @@ -193,5 +198,5 @@ func GetGenesisJSON(pubkey, chainID, addr string, options string) string {
"coin/issuer", {"app": "sigs", "addr": "%s"}%s
]
}
}`, chainID, pubkey, addr, addr, options)
}`, chainID, pubkey, addr, denom, addr, options)
}
4 changes: 2 additions & 2 deletions server/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var StartCmd = &cobra.Command{
RunE: startCmd,
}

// InitTickStartCmd - initialize a command as the start command with tick
func InitTickStartCmd(tick app.Ticker) *cobra.Command {
// GetTickStartCmd - initialize a command as the start command with tick
func GetTickStartCmd(tick app.Ticker) *cobra.Command {
startCmd := &cobra.Command{
Use: "start",
Short: "Start this full node",
Expand Down

0 comments on commit 1613da9

Please sign in to comment.