Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: optimize token command line #417

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
}
}
Loading