Skip to content

Commit

Permalink
fix metadata migration in ibc
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Oct 29, 2024
1 parent acfe0dd commit c466991
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions modules/apps/transfer/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (m Migrator) MigrateDenomMetadata(ctx sdk.Context) error {
func(dt internaltypes.DenomTrace) (stop bool) {
// check if the metadata for the given denom trace does not already exist
if !m.keeper.bankKeeper.HasDenomMetaData(ctx, dt.IBCDenom()) {
m.keeper.setDenomMetadataWithDenomTrace(ctx, dt)
denom := m.keeper.bankKeeper.GetDenomMetaData(ctx, dt.IBCDenom())
m.keeper.setDenomMetadataWithDenomTrace(ctx, dt, denom)
}
return false
})
Expand Down Expand Up @@ -146,15 +147,19 @@ func (k Keeper) iterateDenomTraces(ctx context.Context, cb func(denomTrace inter
}

// setDenomMetadataWithDenomTrace sets an IBC token's denomination metadata
func (k Keeper) setDenomMetadataWithDenomTrace(ctx sdk.Context, denomTrace internaltypes.DenomTrace) {
func (k Keeper) setDenomMetadataWithDenomTrace(ctx sdk.Context, denomTrace internaltypes.DenomTrace, denomMetadata banktypes.Metadata) {
var du = make([]*banktypes.DenomUnit, 0, len(denomMetadata.DenomUnits))

for _, dunit := range denomMetadata.DenomUnits {
du = append(du, &banktypes.DenomUnit{
Denom: dunit.Denom,
Exponent: dunit.Exponent,
Aliases: dunit.Aliases,
})
}
metadata := banktypes.Metadata{
Description: fmt.Sprintf("IBC token from %s", denomTrace.GetFullDenomPath()),
DenomUnits: []*banktypes.DenomUnit{
{
Denom: denomTrace.BaseDenom,
Exponent: 0,
},
},
DenomUnits: du,
// Setting base as IBC hash denom since bank keepers's SetDenomMetadata uses
// Base as key path and the IBC hash is what gives this token uniqueness
// on the executing chain
Expand Down
1 change: 1 addition & 0 deletions modules/apps/transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type BankKeeper interface {
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
HasDenomMetaData(ctx context.Context, denom string) bool
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata)
GetDenomMetaData(ctx context.Context, denom string) banktypes.Metadata
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}
Expand Down

0 comments on commit c466991

Please sign in to comment.