diff --git a/app/app.go b/app/app.go index 8bd0d2d..8a0667c 100644 --- a/app/app.go +++ b/app/app.go @@ -1,11 +1,14 @@ package app import ( + "fmt" "io" "net/http" "os" "path/filepath" + v2 "github.com/pundix/pundix/app/fork/v2" + "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -455,6 +458,15 @@ func (app *App) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + // hard-fork + // v2 - fork + ctx.Logger().With("app/beginBlock").Info("beginBlock", "height", ctx.BlockHeight()) + if ctx.BlockHeight() == int64(pxtypes.V2HardForkHeight()) { + err := v2.Upgrade(ctx, app.UpgradeKeeper) + if err != nil { + panic(fmt.Sprintf("failed to hard fork v2: %v", err)) + } + } return app.mm.BeginBlock(ctx, req) } diff --git a/app/fork/v2/upgrade.go b/app/fork/v2/upgrade.go new file mode 100644 index 0000000..2631d4b --- /dev/null +++ b/app/fork/v2/upgrade.go @@ -0,0 +1,26 @@ +package v2 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + pxtypes "github.com/pundix/pundix/types" +) + +const ( + name = "pxv2" + info = `'{"binaries":{"darwin/arm64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Darwin_arm64.tar.gz","darwin/amd64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Darwin_amd64.tar.gz","linux/arm64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Linux_arm64.tar.gz","linux/amd64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Linux_amd64.tar.gz","windows/x86_64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Windows_x86_64.zip"}}'` +) + +func Upgrade(ctx sdk.Context, upgradeKeeper upgradekeeper.Keeper) error { + plan := types.Plan{ + Name: name, + Height: int64(pxtypes.V2SoftwareUpgradeHeight()), + Info: info, + } + ctx.Logger().With("fork/v2").Info("schedule upgrade begin", "plan", plan) + err := upgradeKeeper.ScheduleUpgrade(ctx, plan) + ctx.Logger().With("fork/v2").Info("schedule upgrade done", "err", err) + return err +} diff --git a/types/version.go b/types/version.go index 80621d2..fc53807 100644 --- a/types/version.go +++ b/types/version.go @@ -1,6 +1,7 @@ package types import ( + "math" "os" "sync" @@ -12,6 +13,9 @@ const ( TestnetChainId = "payalebar" testnetMintDenom = "bsc0x0BEdB58eC8D603E71556ef8aA4014c68DBd57AD7" testnetStakingBondDenom = "ibc/169A52CA4862329131348484982CE75B3D6CC78AFB94C3107026C70CB66E7B2E" + + testnetV2HardForkHeight = math.MaxUint64 + testnetV2UpgradeHeight = math.MaxUint64 ) // mainnet constant @@ -19,6 +23,9 @@ const ( MainnetChainId = "PUNDIX" mainnetMintDenom = "bsc0x29a63F4B209C29B4DC47f06FFA896F32667DAD2C" mainnetStakingBondDenom = "ibc/55367B7B6572631B78A93C66EF9FDFCE87CDE372CC4ED7848DA78C1EB1DCDD78" + + mainnetV2HardForkHeight = math.MaxUint64 + mainnetV2UpgradeHeight = math.MaxUint64 ) var ( @@ -62,3 +69,17 @@ func StakingBondDenom() string { } return mainnetStakingBondDenom } + +func V2HardForkHeight() uint64 { + if TestnetChainId == ChainId() { + return testnetV2HardForkHeight + } + return mainnetV2HardForkHeight +} + +func V2SoftwareUpgradeHeight() uint64 { + if TestnetChainId == ChainId() { + return testnetV2UpgradeHeight + } + return mainnetV2UpgradeHeight +}