Skip to content

Commit

Permalink
optimize command line
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed May 14, 2024
1 parent ae196cb commit 10620c9
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions modules/token/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -276,6 +277,12 @@ func GetCmdMintToken() *cobra.Command {
return cmd
}

// GetCmdBurnToken returns the command to burn tokens.
//
// This function handles the burning of tokens based on the provided coin input.
// It constructs and validates a message to burn the specified tokens.
// Returns an error if the operation encounters any issues.
// Returns a *cobra.Command.
func GetCmdBurnToken() *cobra.Command {
cmd := &cobra.Command{
Use: "burn [coin]",
Expand Down Expand Up @@ -431,13 +438,13 @@ func GetCmdSwapToErc20() *cobra.Command {
"--fees=<fee>",
version.AppName,
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

from := clientCtx.GetFromAddress().String()

paidAmount, token, err := parseMainCoin(clientCtx, args[0])
if err != nil {
return err
Expand All @@ -450,22 +457,24 @@ func GetCmdSwapToErc20() *cobra.Command {
if err != nil {
return err
}

from := clientCtx.GetFromAddress()
if len(receiver) <= 0 {
// set default receiver
receiver = from
receiver = common.BytesToAddress(from.Bytes()).Hex()
}

msg := &v1.MsgSwapToERC20{
Amount: paidAmount,
Sender: from,
Sender: from.String(),
Receiver: receiver,
}

if err := msg.ValidateBasic(); err != nil {
return err
}

var prompt = fmt.Sprintf("Swapping native token to ERC20, sender: %s, receiver: %s, contract: %s, amount: %s", from, receiver, token.GetContract(), paidAmount)
prompt := fmt.Sprintf("Swapping native token to ERC20, sender: %s, receiver: %s, contract: %s, amount: %s", from, receiver, token.GetContract(), paidAmount)

fmt.Println(prompt)

Expand All @@ -492,6 +501,7 @@ func GetCmdSwapFromErc20() *cobra.Command {
"--fees=<fee>",
version.AppName,
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down Expand Up @@ -526,7 +536,7 @@ func GetCmdSwapFromErc20() *cobra.Command {
return err
}

var prompt = fmt.Sprintf("Swapping native token from ERC20, sender: %s, receiver: %s, contract: %s, amount: %s", from, receiver, token.GetContract(), wantedAmount)
prompt := fmt.Sprintf("Swapping native token from ERC20, sender: %s, receiver: %s, contract: %s, amount: %s", from, receiver, token.GetContract(), wantedAmount)

fmt.Println(prompt)

Expand All @@ -538,4 +548,4 @@ func GetCmdSwapFromErc20() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)

return cmd
}
}

0 comments on commit 10620c9

Please sign in to comment.