Skip to content

Commit

Permalink
convert cro->basecro by pre-processing cli arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Sep 14, 2020
1 parent eef87d0 commit 612cd86
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/chain-maind/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return rootCmd, encodingConfig
}

func convertCoin(s string) string {
coin, err := sdk.ParseCoin(s)
if err != nil {
panic(err)
}
if coin.Denom == "cro" {
coin.Denom = "basecro"
coin.Amount = coin.Amount.Mul(sdk.NewInt(100000000))
}
return coin.String()
}

func convertDenom(args []string) {
if len(args) >= 5 && args[0] == "tx" && args[1] == "bank" && args[2] == "send" {
args[5] = convertCoin(args[5])
} else if len(args) >= 4 && args[0] == "tx" && args[1] == "staking" && args[2] == "delegate" {
args[4] = convertCoin(args[4])
}
}

// Execute executes the root command.
func Execute(rootCmd *cobra.Command) error {
// Create and set a client.Context on the command's Context. During the pre-run
Expand All @@ -79,6 +99,8 @@ func Execute(rootCmd *cobra.Command) error {
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext())

convertDenom(os.Args[1:])
rootCmd.SetArgs(os.Args[1:])
executor := tmcli.PrepareBaseCmd(rootCmd, "", app.DefaultNodeHome(appName))
return executor.ExecuteContext(ctx)
}
Expand Down

0 comments on commit 612cd86

Please sign in to comment.