Skip to content

Commit

Permalink
fix: do not check timelock time if isBCFusionRefund
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Dec 15, 2023
1 parent 5a998b8 commit c7059cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions plugins/tokens/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
logger.Error("ParseKeyRecord error", "error", err)
continue
}
err = timelockKeeper.TimeUnlock(ctx, addr, id)
err = timelockKeeper.TimeUnlock(ctx, addr, id, true)
if err != nil {
logger.Error("TimeUnlock error", "error", err)
continue
Expand All @@ -97,7 +97,7 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
SwapID: swapID,
})
if !result.IsOK() {
logger.Error("Refund error", "swapId", swapID)
logger.Error("Refund error", "swapId", swapID, result.Tags)
continue
}
i++
Expand Down
2 changes: 1 addition & 1 deletion plugins/tokens/timelock/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func handleTimeRelock(ctx sdk.Context, keeper Keeper, msg TimeRelockMsg) sdk.Res
}

func handleTimeUnlock(ctx sdk.Context, keeper Keeper, msg TimeUnlockMsg) sdk.Result {
err := keeper.TimeUnlock(ctx, msg.From, msg.Id)
err := keeper.TimeUnlock(ctx, msg.From, msg.Id, false)
if err != nil {
return err.Result()
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/tokens/timelock/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func (keeper Keeper) TimeLock(ctx sdk.Context, from sdk.AccAddress, description
return record, nil
}

func (keeper Keeper) TimeUnlock(ctx sdk.Context, from sdk.AccAddress, recordId int64) sdk.Error {
func (keeper Keeper) TimeUnlock(ctx sdk.Context, from sdk.AccAddress, recordId int64, isBCFusionRefund bool) sdk.Error {
record, found := keeper.GetTimeLockRecord(ctx, from, recordId)
if !found {
return ErrTimeLockRecordDoesNotExist(DefaultCodespace, from, recordId)
}

if ctx.BlockHeader().Time.Before(record.LockTime) {
if !isBCFusionRefund && ctx.BlockHeader().Time.Before(record.LockTime) {
return ErrCanNotUnlock(DefaultCodespace, fmt.Sprintf("lock time(%s) is after now(%s)",
record.LockTime.UTC().String(), ctx.BlockHeader().Time.UTC().String()))
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/tokens/timelock/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestKeeper_TimeUnlock_RecordNotExist(t *testing.T) {

_, acc := testutils.NewAccount(ctx, accKeeper, 0)

err := keeper.TimeUnlock(ctx, acc.GetAddress(), 1)
err := keeper.TimeUnlock(ctx, acc.GetAddress(), 1, false)
require.NotNil(t, err)
require.Equal(t, err.Code(), CodeTimeLockRecordDoesNotExist)
}
Expand All @@ -169,7 +169,7 @@ func TestKeeper_TimeUnlock_ErrLockTime(t *testing.T) {
record, err := keeper.TimeLock(ctx, acc.GetAddress(), "Test", lockCoins, time.Now().Add(1000*time.Second))
require.Nil(t, err)

err = keeper.TimeUnlock(ctx, acc.GetAddress(), record.Id)
err = keeper.TimeUnlock(ctx, acc.GetAddress(), record.Id, false)
require.NotNil(t, err)
require.Equal(t, err.Code(), CodeCanNotUnlock)
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestKeeper_TimeUnlock_Success(t *testing.T) {
require.Nil(t, err)

ctx = ctx.WithBlockTime(time.Now().Add(2000 * time.Second))
err = keeper.TimeUnlock(ctx, acc.GetAddress(), record.Id)
err = keeper.TimeUnlock(ctx, acc.GetAddress(), record.Id, false)
require.Nil(t, err)
}

Expand Down

0 comments on commit c7059cd

Please sign in to comment.