diff --git a/plugins/tokens/plugin.go b/plugins/tokens/plugin.go index 2cc96de93..8b6987ad6 100644 --- a/plugins/tokens/plugin.go +++ b/plugins/tokens/plugin.go @@ -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 @@ -104,7 +104,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++ diff --git a/plugins/tokens/timelock/handler.go b/plugins/tokens/timelock/handler.go index f69741954..ee03c8f4c 100644 --- a/plugins/tokens/timelock/handler.go +++ b/plugins/tokens/timelock/handler.go @@ -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() } diff --git a/plugins/tokens/timelock/keeper.go b/plugins/tokens/timelock/keeper.go index 686f2025e..260ddc4a5 100644 --- a/plugins/tokens/timelock/keeper.go +++ b/plugins/tokens/timelock/keeper.go @@ -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())) } diff --git a/plugins/tokens/timelock/keeper_test.go b/plugins/tokens/timelock/keeper_test.go index a973eed04..4f53c8fce 100644 --- a/plugins/tokens/timelock/keeper_test.go +++ b/plugins/tokens/timelock/keeper_test.go @@ -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) } @@ -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) } @@ -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) }