Skip to content

Commit

Permalink
Merge pull request #2173 from Sifchain/feature/inflation-rewards
Browse files Browse the repository at this point in the history
Feature | Inflation Rewards
  • Loading branch information
intl-man authored Nov 14, 2021
2 parents 45810de + 6cb4db5 commit 3790b5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 27 additions & 5 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,51 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"

dispensationtypes "github.com/Sifchain/sifnode/x/dispensation/types"
)

const upgradeName = "0.9.13"
const upgradeName = "0.9.14"

const distributionVersion = "0.9.14"
const distributionAddress = "sif1ct2s3t8u2kffjpaekhtngzv6yc4vm97xajqyl3"
const distributionAmount = "200000000000000000000000000" // 200m

func SetupHandlers(app *SifchainApp) {
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan types.Plan) {
app.Logger().Info("Running upgrade handler for " + upgradeName)
if plan.Name == distributionVersion {
mintAmount, ok := sdk.NewIntFromString(distributionAmount)
if !ok {
panic("failed to get mint amount")
}
mintCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), mintAmount))
err := app.BankKeeper.MintCoins(ctx, dispensationtypes.ModuleName, mintCoins)
if err != nil {
panic(err)
}
address, err := sdk.AccAddressFromBech32(distributionAddress)
if err != nil {
panic(err)
}
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, dispensationtypes.ModuleName, address, mintCoins)
if err != nil {
panic(err)
}
}
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{},
}

// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
// so that new stores start with the correct version (the current height of chain),
// instead the default which is the latest version that store last committed i.e 0 for new stores.
app.SetStoreLoader(types.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.13
0.9.14

0 comments on commit 3790b5d

Please sign in to comment.