From 8ce2e61e884b7e422ef2495e84744541f7c7a487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=2E=20Morency?= <1102868+fmorency@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:53:06 -0400 Subject: [PATCH] feat: umfx denom metadata migration (#103) --- Makefile | 2 +- app/upgrades.go | 5 +-- app/upgrades/next/upgrades.go | 57 +++++++++++++++++++++++++++++++++++ app/upgrades/types.go | 4 ++- 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 app/upgrades/next/upgrades.go diff --git a/Makefile b/Makefile index a9397f9..933f2db 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DOCKER := $(shell which docker) LEDGER_ENABLED ?= true BINDIR ?= $(GOPATH)/bin BUILD_DIR = ./build -VERSION = v0.0.1-alpha.17 +VERSION = v0.0.1-alpha.18 export GO111MODULE = on diff --git a/app/upgrades.go b/app/upgrades.go index a55db2d..0415b5b 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -6,11 +6,12 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/liftedinit/manifest-ledger/app/upgrades" + "github.com/liftedinit/manifest-ledger/app/upgrades/next" "github.com/liftedinit/manifest-ledger/app/upgrades/noop" ) // Upgrades list of chain upgrades -var Upgrades []upgrades.Upgrade +var Upgrades = []upgrades.Upgrade{next.NewUpgrade()} // RegisterUpgradeHandlers registers the chain upgrade handlers func (app *ManifestApp) RegisterUpgradeHandlers() { @@ -19,7 +20,7 @@ func (app *ManifestApp) RegisterUpgradeHandlers() { Upgrades = append(Upgrades, noop.NewUpgrade(app.Version())) } - keepers := upgrades.AppKeepers{AccountKeeper: app.AccountKeeper} + keepers := upgrades.AppKeepers{AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper} // register all upgrade handlers for _, upgrade := range Upgrades { app.UpgradeKeeper.SetUpgradeHandler( diff --git a/app/upgrades/next/upgrades.go b/app/upgrades/next/upgrades.go new file mode 100644 index 0000000..0b7f249 --- /dev/null +++ b/app/upgrades/next/upgrades.go @@ -0,0 +1,57 @@ +package next + +import ( + "context" + + storetypes "cosmossdk.io/store/types" + upgradetypes "cosmossdk.io/x/upgrade/types" + + "github.com/cosmos/cosmos-sdk/types/module" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/liftedinit/manifest-ledger/app/upgrades" +) + +func NewUpgrade() upgrades.Upgrade { + return upgrades.Upgrade{ + UpgradeName: "umfx-denom-metadata", + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{ + Added: []string{}, + Deleted: []string{}, + }, + } +} + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *upgrades.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + metadata := banktypes.Metadata{ + Description: "The Manifest Network token", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "umfx", + Exponent: 0, + Aliases: []string{}, + }, + { + Denom: "mfx", + Exponent: 6, + Aliases: []string{}, + }, + }, + Base: "umfx", + Display: "MFX", + Symbol: "MFX", + Name: "Manifest Network Token", + } + + // Set the new metadata in the bank keeper + keepers.BankKeeper.SetDenomMetaData(ctx, metadata) + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 02d31da..39faef4 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -6,10 +6,12 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" ) type AppKeepers struct { - authkeeper.AccountKeeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.BaseKeeper } // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal