diff --git a/app/upgrades.go b/app/upgrades.go index f1464af68c..12e992b958 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "strings" icqtypes "github.com/strangelove-ventures/async-icq/v6/types" @@ -11,15 +12,19 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper" attributetypes "github.com/provenance-io/provenance/x/attribute/types" "github.com/provenance-io/provenance/x/exchange" "github.com/provenance-io/provenance/x/hold" ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types" + "github.com/provenance-io/provenance/x/marker/types" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" oracletypes "github.com/provenance-io/provenance/x/oracle/types" triggertypes "github.com/provenance-io/provenance/x/trigger/types" @@ -120,7 +125,19 @@ var upgrades = map[string]appUpgrade{ }, Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.StoreKey, hold.ModuleName, exchange.ModuleName}, }, - "saffron-rc2": {}, // upgrade for v1.17.0-rc2 + "saffron-rc2": { + Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { + var err error + vm, err = runModuleMigrations(ctx, app, vm) + if err != nil { + return nil, err + } + + updateIbcMarkerDenomMetadata(ctx, app) + + return vm, nil + }, + }, // upgrade for v1.17.0-rc2 "saffron": { // upgrade for v1.17.0, Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error @@ -361,3 +378,28 @@ func setExchangeParams(ctx sdk.Context, app *App) { } ctx.Logger().Info("Done ensuring exchange module params are set.") } + +// updateIbcMarkerDenomMetadata iterates markers and creates denom metadata for ibc markers +// TODO: Remove with the saffron handlers. +func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) { + app.MarkerKeeper.IterateMarkers(ctx, func(record types.MarkerAccountI) bool { + if strings.HasSuffix(record.GetDenom(), "ibc/") { + denomTrace := transfertypes.ParseDenomTrace(record.GetDenom()) + parts := strings.Split(denomTrace.Path, "/") + if len(parts) == 2 && parts[0] == "transfer" { + chainID := app.Ics20MarkerHooks.GetChainID(ctx, parts[0], parts[1], app.IBCKeeper) + markerMetadata := banktypes.Metadata{ + Base: record.GetDenom(), + Name: chainID + "/" + record.GetDenom(), + Display: chainID + "/" + record.GetDenom(), + Description: record.GetDenom() + " from chain " + chainID, + } + err := app.MarkerKeeper.SetDenomMetaData(ctx, markerMetadata, authtypes.NewModuleAddress(types.ModuleName)) + if err != nil { + panic(fmt.Sprintf("unable to set denom metadata for %v on chain-id %v: %v", record.GetDenom(), chainID, err)) + } + } + } + return false + }) +} diff --git a/x/ibchooks/marker_hooks.go b/x/ibchooks/marker_hooks.go index 660d199068..95d8069b31 100644 --- a/x/ibchooks/marker_hooks.go +++ b/x/ibchooks/marker_hooks.go @@ -114,7 +114,7 @@ func (h MarkerHooks) getExistingSupply(ctx sdktypes.Context, marker *markertypes // addDenomMetaData adds denom metadata for ibc token func (h MarkerHooks) addDenomMetaData(ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper, ibcDenom string, data transfertypes.FungibleTokenPacketData) error { - chainID := h.GetChainID(ctx, packet, ibcKeeper) + chainID := h.GetChainID(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), ibcKeeper) markerMetadata := banktypes.Metadata{ Base: ibcDenom, Name: chainID + "/" + data.Denom, @@ -125,9 +125,9 @@ func (h MarkerHooks) addDenomMetaData(ctx sdktypes.Context, packet exported.Pack } // GetChainID returns the source chain id from packet for a `07-tendermint` client connection or returns `unknown` -func (h MarkerHooks) GetChainID(ctx sdktypes.Context, packet exported.PacketI, ibcKeeper *ibckeeper.Keeper) string { +func (h MarkerHooks) GetChainID(ctx sdktypes.Context, sourcePort, sourceChannel string, ibcKeeper *ibckeeper.Keeper) string { chainID := "unknown" - channel, found := ibcKeeper.ChannelKeeper.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) + channel, found := ibcKeeper.ChannelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { return chainID }