Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
atheeshp committed Oct 10, 2023
1 parent a2d100a commit 381cd02
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
26 changes: 21 additions & 5 deletions app/upgrades/v2.2.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,41 @@ func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ distribution.Keeper,
_ bank.Keeper,
_ auth.AccountKeeper,
bk bank.Keeper,
ak auth.AccountKeeper,
ck claim.Keeper,
) upgradetypes.UpgradeHandler {

return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if err := ExecuteProposal(ctx, ck); err != nil {
if err := ExecuteProposal(ctx, ak, bk, ck); err != nil {
return nil, err
}

return fromVM, nil
}
}

func ExecuteProposal(ctx sdk.Context, ck claim.Keeper) error {
func ExecuteProposal(ctx sdk.Context, ak auth.AccountKeeper, bk bank.Keeper, ck claim.Keeper) error {
var newClaimRecords = []claimtypes.ClaimRecord{}
var sixMonths = time.Hour * 24 * 180

if err := ck.SetClaimRecords(ctx, newClaimRecords); err != nil {
// sum the newly added claim records balance
var amount sdk.Coins
for _, record := range newClaimRecords {
amount.Add(record.ClaimableAmount...)

// set the claim record in claim module
ck.SetClaimRecord(ctx, record)
}

// get airdrop account
airdropAccAddr, err := sdk.AccAddressFromBech32("pasg1lel0s624jr9zsz4ml6yv9e5r4uzukfs7hwh22w")
if err != nil {
return err
}

// send the added balances from airdrop account to claim module account
if err := bk.SendCoinsFromAccountToModule(ctx, airdropAccAddr, claimtypes.ModuleName, amount); err != nil {
return err
}

Expand Down
17 changes: 9 additions & 8 deletions x/claim/keeper/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ func (k Keeper) CreateModuleAccount(ctx sdk.Context, amount sdk.Coin) {

existingModuleAcctBalance := k.bankKeeper.GetBalance(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), amount.Denom)
if existingModuleAcctBalance.IsPositive() {
actual := existingModuleAcctBalance.Add(amount)
ctx.Logger().Info(fmt.Sprintf("WARNING! There is a bug in claims on InitGenesis, that you are subject to."+
" You likely expect the claims module account balance to be %d %s, but it will actually be %d %s due to this bug.",
amount.Amount.Int64(), amount.Denom, actual.Amount.Int64(), actual.Denom))
}

if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, mintCoins); err != nil {
panic(err)
if !existingModuleAcctBalance.Equal(amount) {
ctx.Logger().Info(fmt.Sprintf("WARNING! There is a bug in claims on InitGenesis, that you are subject to."+
" You likely expect the claims module account balance to be %s, but it will actually be %s due to this bug.",
amount.String(), existingModuleAcctBalance.String()))
}
} else {
if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, mintCoins); err != nil {
panic(err)
}
}
}

Expand Down

0 comments on commit 381cd02

Please sign in to comment.