Skip to content

Commit

Permalink
Merge pull request #15 from bianjieai/dreamer/fix-class-id
Browse files Browse the repository at this point in the history
fix: solve the problem of "/" parsing error in classID
  • Loading branch information
towerkyoto authored Oct 20, 2023
2 parents fa7bd3f + a05e416 commit ec385f7
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
return err
}

classTrace := types.ParseClassTrace(data.ClassId)
voucherClassID := classTrace.IBCClassID()
voucherClassID, err := k.GetVoucherClassID(ctx, data.ClassId)
if err != nil {
return err
}
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 @@ -339,7 +341,11 @@ func (k Keeper) processReceivedPacket(ctx sdk.Context, packet channeltypes.Packe
if err != nil {
return err
}
voucherClassID := types.ParseClassTrace(unprefixedClassID).IBCClassID()

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

escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel())
for i, tokenID := range data.TokenIds {
Expand All @@ -357,3 +363,24 @@ 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 ec385f7

Please sign in to comment.