Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhiteList control #357

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading