Skip to content

Commit

Permalink
Change order of checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulBernal committed Apr 15, 2024
1 parent 1434f87 commit e740926
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions x/burn/keeper/msg_server_burn_coins_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var authorizedAddresses = map[string]bool{
"bcna1tdpec339xrucmmr4x73teu3lc2phq45mv07z9n": true, // Vesting account
"bcna1465kg4xaa5sl3vlm02zwe6y7jqltyncvcsygxr": true, // Business Development
"bcna16pczhqlsglmjyyap3785cqnpq30q430jkgw4gk": true, // Marketing
"bcna1tqywev6xmvrnagfq57c0h5susdy3l789rumufz": true, // Test1
"bcna1rp6fpd8lry8kgmxaermw8eqlkgr4q9lv3u0eae": true, // Test1
"bcna1h2sz97wffluqtt07zmkky3cvuywv6dzq38zr9r": true, // Test2
"bcna1zvxldjgetj5u9wah0t8fnz229533xzsmz8y5js": true, // Test3
}
Expand All @@ -29,11 +29,6 @@ func (k msgServer) BurnCoinsAction(goCtx context.Context, msg *types.MsgBurnCoin
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid creator address: %s", err)
}

// Check if the address of the creator is whitelisted
if _, ok := authorizedAddresses[msg.Creator]; !ok {
return nil, sdkerrors.ErrUnauthorized.Wrap("address not authorized to burn coins")
}

// Validate the coins
coins := sdk.NewCoins(msg.Amount)
if !coins.IsValid() {
Expand All @@ -50,6 +45,11 @@ func (k msgServer) BurnCoinsAction(goCtx context.Context, msg *types.MsgBurnCoin
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
}

// Check if the address of the creator is whitelisted
if _, ok := authorizedAddresses[msg.Creator]; !ok {
return nil, sdkerrors.ErrUnauthorized.Wrap("address not authorized to burn coins")
}

// Gets the balance of the sender to check if are there enough coins.
balance := k.bankKeeper.GetBalance(ctx, creatorAddr, msg.Amount.Denom)
if balance.Amount.LT(msg.Amount.Amount) {
Expand Down

0 comments on commit e740926

Please sign in to comment.