Skip to content

Commit

Permalink
chore: add logs to refund tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 15, 2024
1 parent 43fad4d commit daa4153
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plugins/tokens/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,33 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
iterator := timelockKeeper.GetTimeLockRecordIterator(ctx)
defer iterator.Close()
i := 0
failedCount := 0
for ; iterator.Valid(); iterator.Next() {
if i >= MaxUnlockItems {
break
}
addr, id, err := timelock.ParseKeyRecord(iterator.Key())
if err != nil {
logger.Error("failed to parse timelock record", "error", err)
failedCount++
continue
}
err = timelockKeeper.TimeUnlock(ctx, addr, id, true)
if err != nil {
logger.Error("failed to unlock the time locks", "error", err)
failedCount++
continue
}
logger.Info("succeed to unlock the time locks", "addr", addr, "id", id)
i++
if i >= MaxUnlockItems {
break
}
}
logger.Info("unlock the time locks done", "blockHeight", ctx.BlockHeight(), "succeed", i, "failed", failedCount)

swapIterator := swapKeeper.GetSwapIterator(ctx)
defer swapIterator.Close()
i = 0
failedCount = 0
for ; swapIterator.Valid(); swapIterator.Next() {
if i >= MaxUnlockItems {
break
}
var automaticSwap swap.AtomicSwap
swapKeeper.CDC().MustUnmarshalBinaryBare(swapIterator.Value(), &automaticSwap)
swapID := swapIterator.Key()[len(swap.HashKey):]
Expand All @@ -106,12 +108,17 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
})
if !result.IsOK() {
logger.Error("failed to refund swap", "swapId", swapID, "result", fmt.Sprintf("%+v", result))
failedCount++
continue
}

logger.Info("succeed to refund swap", "swapId", swapID, "swap", fmt.Sprintf("%+v", swapItem))
i++
if i >= MaxUnlockItems {
break
}
}
logger.Info("refund the swaps done", "blockHeight", ctx.BlockHeight(), "succeed", i, "failed", failedCount)
}

// EndBreatheBlock processes the breathe block lifecycle event.
Expand Down

0 comments on commit daa4153

Please sign in to comment.