forked from envadiv/Passage3D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added UpgradeHandler to burn unclaimed airdrop tokens (envadiv#168
) * feat: Added UpgradeHandler to burn coins for a specific address * chore: made review changes * chore : updated go docs * chore: made review changes
- Loading branch information
1 parent
0c3181c
commit 0bcafb0
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package v2 | ||
|
||
import ( | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
"github.com/envadiv/Passage3D/app/upgrades" | ||
claim "github.com/envadiv/Passage3D/x/claim/keeper" | ||
claimtypes "github.com/envadiv/Passage3D/x/claim/types" | ||
) | ||
|
||
const Name = "v2.4.0" | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: Name, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{}, | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
_ distribution.Keeper, | ||
bk bank.Keeper, | ||
ak auth.AccountKeeper, | ||
_ claim.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
|
||
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
if err := ExecuteProposal(ctx, ak, bk); err != nil { | ||
return nil, err | ||
} | ||
|
||
return fromVM, nil | ||
} | ||
} | ||
|
||
func ExecuteProposal(ctx sdk.Context, ak auth.AccountKeeper, bk bank.Keeper) error { | ||
// get airdrop claim module account | ||
addr := ak.GetModuleAddress(claimtypes.ModuleName) | ||
|
||
// get all balances of airdrop claim module account | ||
balances := bk.GetAllBalances(ctx, addr) | ||
|
||
// claim module account do not have the burner permissions | ||
// so we are sending it to the another module account and burning the tokens | ||
if err := bk.SendCoinsFromModuleToModule(ctx, claimtypes.ModuleName, govtypes.ModuleName, balances); err != nil { | ||
return err | ||
} | ||
|
||
// burn the coins from the module account | ||
err := bk.BurnCoins(ctx, govtypes.ModuleName, balances) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |