Skip to content

Commit

Permalink
imp: use types.MetadataFromVersion helper function for callback han…
Browse files Browse the repository at this point in the history
…dlers (#4290)
  • Loading branch information
stackman27 authored Aug 14, 2023
1 parent 7dcb9ed commit d9f394b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ func (im IBCMiddleware) OnChanOpenInit(
AppVersion: "",
}
} else {
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &versionMetadata); err != nil {
metadata, err := types.MetadataFromVersion(version)
if err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID,
chanCap, counterparty, version)
}
versionMetadata = metadata
}

if versionMetadata.FeeVersion != types.Version {
Expand Down Expand Up @@ -99,8 +101,8 @@ func (im IBCMiddleware) OnChanOpenTry(
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (string, error) {
var versionMetadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil {
versionMetadata, err := types.MetadataFromVersion(counterpartyVersion)
if err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
Expand Down Expand Up @@ -139,8 +141,8 @@ func (im IBCMiddleware) OnChanOpenAck(
// If handshake was initialized with fee enabled it must complete with fee enabled.
// If handshake was initialized with fee disabled it must complete with fee disabled.
if im.keeper.IsFeeEnabled(ctx, portID, channelID) {
var versionMetadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil {
versionMetadata, err := types.MetadataFromVersion(counterpartyVersion)
if err != nil {
return errorsmod.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion)
}

Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string
return version, true
}

var metadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil {
metadata, err := types.MetadataFromVersion(version)
if err != nil {
panic(fmt.Errorf("unable to unmarshal metadata for fee enabled channel: %w", err))
}

Expand Down

0 comments on commit d9f394b

Please sign in to comment.