-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates to #44 - perform module migration to add the photon module in the upgrade module version map - register the photon denom metata in the bank module - add a storeloader for the photon module (required for all new modules)
- Loading branch information
Showing
6 changed files
with
118 additions
and
13 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,23 @@ | ||
package v2 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/atomone-hub/atomone/app/upgrades" | ||
photontypes "github.com/atomone-hub/atomone/x/photon/types" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v2" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: store.StoreUpgrades{ | ||
Added: []string{ | ||
// new module added in v2 | ||
photontypes.ModuleName, | ||
}, | ||
}, | ||
} |
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,66 @@ | ||
package v2 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
"github.com/atomone-hub/atomone/app/keepers" | ||
) | ||
|
||
// CreateUpgradeHandler returns a upgrade handler for AtomOne v2 | ||
// which executes the following migrations: | ||
// - add new denom metadata for photon in the bank module store. | ||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
keepers *keepers.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx.Logger().Info("Starting module migrations...") | ||
// RunMigrations will detect the add of the photon module, will initiate | ||
// its genesis and will fill the versionMap with its consensus version. | ||
vm, err := mm.RunMigrations(ctx, configurator, vm) | ||
if err != nil { | ||
return vm, err | ||
} | ||
// Add the photon denom metadata to the bank module store | ||
setPhotonDenomMetadata(ctx, keepers.BankKeeper) | ||
ctx.Logger().Info("Upgrade complete") | ||
return vm, nil | ||
} | ||
} | ||
|
||
func setPhotonDenomMetadata(ctx sdk.Context, bk bankkeeper.Keeper) { | ||
ctx.Logger().Info("Adding photon denom metadata...") | ||
bk.SetDenomMetaData(ctx, banktypes.Metadata{ | ||
Base: "uphoton", | ||
Display: "photon", | ||
Name: "AtomOne Photon", | ||
Symbol: "PHOTON", | ||
Description: "The fee token of AtomOne Hub", | ||
DenomUnits: []*banktypes.DenomUnit{ | ||
{ | ||
Denom: "uphoton", | ||
Exponent: 0, | ||
Aliases: []string{ | ||
"microphoton", | ||
}, | ||
}, | ||
{ | ||
Denom: "mphoton", | ||
Exponent: 3, | ||
Aliases: []string{ | ||
"milliphoton", | ||
}, | ||
}, | ||
{ | ||
Denom: "photon", | ||
Exponent: 6, | ||
}, | ||
}, | ||
}) | ||
ctx.Logger().Info("Photon denom metadata added") | ||
} |
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
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