Skip to content

Commit

Permalink
fix duplicate token query
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-z committed Apr 18, 2024
1 parent bb6bbfe commit b0bffe8
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions modules/token/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func NewTxCmd() *cobra.Command {
GetCmdBurnToken(),
GetCmdTransferTokenOwner(),
GetCmdSwapFeeToken(),
GetCmdSwapToErc20(),
GetCmdSwapFromErc20(),
)

return txCmd
Expand Down Expand Up @@ -436,10 +438,14 @@ func GetCmdSwapToErc20() *cobra.Command {
}

from := clientCtx.GetFromAddress().String()
paidAmount, _, err := parseMainCoin(clientCtx, args[0])
paidAmount, token, err := parseMainCoin(clientCtx, args[0])
if err != nil {
return err
}
if len(token.GetContract()) <= 0 {
return fmt.Errorf("corresponding erc20 contract of %s does not exist", paidAmount.Denom)
}

receiver, err := cmd.Flags().GetString(FlagTo)
if err != nil {
return err
Expand All @@ -455,14 +461,6 @@ func GetCmdSwapToErc20() *cobra.Command {
Receiver: receiver,
}

token, err := queryToken(clientCtx, paidAmount.Denom)
if err != nil {
return err
}
if len(token.GetContract()) <= 0 {
return fmt.Errorf("corresponding erc20 contract of %s does not exist", paidAmount.Denom)
}

if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down Expand Up @@ -501,10 +499,14 @@ func GetCmdSwapFromErc20() *cobra.Command {
}

from := clientCtx.GetFromAddress().String()
wantedAmount, _, err := parseMainCoin(clientCtx, args[0])
wantedAmount, token, err := parseMainCoin(clientCtx, args[0])
if err != nil {
return err
}
if len(token.GetContract()) <= 0 {
return fmt.Errorf("corresponding erc20 contract of %s does not exist", wantedAmount.Denom)
}

receiver, err := cmd.Flags().GetString(FlagTo)
if err != nil {
return err
Expand All @@ -520,14 +522,6 @@ func GetCmdSwapFromErc20() *cobra.Command {
Receiver: receiver,
}

token, err := queryToken(clientCtx, wantedAmount.Denom)
if err != nil {
return err
}
if len(token.GetContract()) <= 0 {
return fmt.Errorf("corresponding erc20 contract of %s does not exist", wantedAmount.Denom)
}

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

0 comments on commit b0bffe8

Please sign in to comment.