Skip to content

Commit

Permalink
Merge pull request #417 from irisnet/fix/fix-token-cli
Browse files Browse the repository at this point in the history
refactor: optimize token command line
  • Loading branch information
mitch1024 authored May 14, 2024
2 parents ae196cb + 07cea5d commit dd2c7e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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
}
}

0 comments on commit dd2c7e4

Please sign in to comment.