Skip to content

Commit

Permalink
Merge pull request #357 from BitCannaGlobal/047-burn-module-whitelist
Browse files Browse the repository at this point in the history
WhiteList control
  • Loading branch information
RaulBernal authored Apr 15, 2024
2 parents 9b98150 + e740926 commit 9d38fbb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions x/burn/keeper/msg_server_burn_coins_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// List of auth. addresses (whitelist)
var authorizedAddresses = map[string]bool{
"bcna1tdpec339xrucmmr4x73teu3lc2phq45mv07z9n": true, // Vesting account
"bcna1465kg4xaa5sl3vlm02zwe6y7jqltyncvcsygxr": true, // Business Development
"bcna16pczhqlsglmjyyap3785cqnpq30q430jkgw4gk": true, // Marketing
"bcna1rp6fpd8lry8kgmxaermw8eqlkgr4q9lv3u0eae": true, // Test1
"bcna1h2sz97wffluqtt07zmkky3cvuywv6dzq38zr9r": true, // Test2
"bcna1zvxldjgetj5u9wah0t8fnz229533xzsmz8y5js": true, // Test3
}

// Move coins from sender to Bank account module and then the module burns the coins.
func (k msgServer) BurnCoinsAction(goCtx context.Context, msg *types.MsgBurnCoinsAction) (*types.MsgBurnCoinsActionResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// Validate the address
creatorAddr, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid creator address: %s", err)
Expand All @@ -34,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 9d38fbb

Please sign in to comment.