Skip to content

Commit

Permalink
feat: umfx denom metadata migration (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency authored Oct 24, 2024
1 parent 51a03df commit 8ce2e61
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand Down
57 changes: 57 additions & 0 deletions app/upgrades/next/upgrades.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 3 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ce2e61

Please sign in to comment.