Skip to content

Commit

Permalink
chore: changes in burnMsg logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal-kanna committed Sep 20, 2024
1 parent 877bc70 commit 46616f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
8 changes: 5 additions & 3 deletions x/did/client/cli/burn_cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"strings"

didtypes "github.com/cheqd/cheqd-node/x/did/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -13,7 +15,7 @@ func NewBurnCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "burn [amount] [flags]",
Short: "Burn tokens from an address",
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -25,14 +27,14 @@ func NewBurnCmd() *cobra.Command {
return err
}

amount, err := sdk.ParseCoinNormalized(args[0])
coins, err := sdk.ParseCoinsNormalized(strings.Join(args, ","))
if err != nil {
return err
}

msg := didtypes.NewMsgBurn(
clientCtx.GetFromAddress().String(),
sdk.NewCoins(amount),
coins,
)

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand Down
10 changes: 6 additions & 4 deletions x/did/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (k MsgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.MsgBu
bondDenom := k.stakingKeeper.BondDenom(sdkCtx)
denoms := msg.Amount.Denoms()
if len(denoms) != 0 {
err := ValidateDenom(denoms[0], bondDenom)
err := ValidateDenom(denoms, bondDenom)
if err != nil {
return nil, err
}
Expand All @@ -189,9 +189,11 @@ func (k MsgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.MsgBu
return &types.MsgBurnResponse{}, nil
}

func ValidateDenom(denom, bondDenom string) error {
if denom != bondDenom {
return errorsmod.Wrap(types.ErrInvalidDenom, denom)
func ValidateDenom(denom []string, bondDenom string) error {
for _, denom := range denom {
if denom != bondDenom {
return errorsmod.Wrap(types.ErrInvalidDenom, denom)
}
}
return nil
}
9 changes: 0 additions & 9 deletions x/did/types/tx_msg_burn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ func NewMsgBurn(sender string, amount sdk.Coins) *MsgBurn {
Amount: amount,
}
}

// NewMsgBurn creates a message to burn tokens
func NewMsgBurnFrom(amount sdk.Coins, fromAddress string) *MsgBurn {
return &MsgBurn{
Amount: amount,
FromAddress: fromAddress,
}
}

func (m MsgBurn) Route() string { return RouterKey }

func (m MsgBurn) ValidateBasic() error {
Expand Down

0 comments on commit 46616f6

Please sign in to comment.