Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: solve the problem of "/" parsing error in classID " #51

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}