From 10620c98dd146b8bee616c94af8e65a8d8d36522 Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 14 May 2024 10:30:47 +0800 Subject: [PATCH 1/2] optimize command line --- modules/token/client/cli/tx.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/token/client/cli/tx.go b/modules/token/client/cli/tx.go index 4c1f459e..20eb8691 100644 --- a/modules/token/client/cli/tx.go +++ b/modules/token/client/cli/tx.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" @@ -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]", @@ -431,13 +438,13 @@ func GetCmdSwapToErc20() *cobra.Command { "--fees=", 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 @@ -450,14 +457,16 @@ 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, } @@ -465,7 +474,7 @@ func GetCmdSwapToErc20() *cobra.Command { 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) @@ -492,6 +501,7 @@ func GetCmdSwapFromErc20() *cobra.Command { "--fees=", version.AppName, ), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -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) @@ -538,4 +548,4 @@ func GetCmdSwapFromErc20() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd -} +} \ No newline at end of file From 07cea5d8979907aca4cd5d8876a44a33ae66e7b4 Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 14 May 2024 10:33:37 +0800 Subject: [PATCH 2/2] update changlelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6024c98d..146a5a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#410](https://github.com/irisnet/irismod/pull/410) Implement upgradeable contract. * [\#411](https://github.com/irisnet/irismod/pull/411) Implement erc20 upgrade. * [\#412](https://github.com/irisnet/irismod/pull/412) Optimize contract code +* [\#417](https://github.com/irisnet/irismod/pull/417) Optimize token command line ### Bug Fixes