Skip to content

Commit

Permalink
Revert "fix: solve the problem of "/" parsing error in classID "
Browse files Browse the repository at this point in the history
  • Loading branch information
taramakage authored Oct 20, 2023
1 parent ec385f7 commit 4cc6272
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
return err
}

voucherClassID, err := k.GetVoucherClassID(ctx, data.ClassId)
if err != nil {
return err
}
classTrace := types.ParseClassTrace(data.ClassId)
voucherClassID := classTrace.IBCClassID()
if types.IsAwayFromOrigin(packet.GetSourcePort(), packet.GetSourceChannel(), data.ClassId) {
for _, tokenID := range data.TokenIds {
if err := k.nftKeeper.Transfer(ctx, voucherClassID, tokenID, "", sender); err != nil {
Expand Down Expand Up @@ -341,11 +339,7 @@ func (k Keeper) processReceivedPacket(ctx sdk.Context, packet channeltypes.Packe
if err != nil {
return err
}

voucherClassID, err := k.GetVoucherClassID(ctx, unprefixedClassID)
if err != nil {
return err
}
voucherClassID := types.ParseClassTrace(unprefixedClassID).IBCClassID()

escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel())
for i, tokenID := range data.TokenIds {
Expand All @@ -363,24 +357,3 @@ func (k Keeper) processReceivedPacket(ctx sdk.Context, packet channeltypes.Packe
}
return nil
}

func (k Keeper) GetVoucherClassID(ctx sdk.Context, classID string) (string, error) {

// If "/" is not included after removing the prefix,
// it means that nft has returned to the initial chain, and the classID after removing the prefix is the real classID
if !strings.Contains(classID, "/") {
return classID, nil
}

// If "/" is included after removing the prefix, there are two situations:
// 1. The original classID itself contains "/",
// 2. The current nft returns to the relay chain, not the original chain

// First deal with case 1, if the classID can be found, return the result
if k.nftKeeper.HasClass(ctx, classID) {
return classID, nil
}

// If not found, generate classID according to classTrace
return types.ParseClassTrace(classID).IBCClassID(), nil
}

0 comments on commit 4cc6272

Please sign in to comment.