mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-26 09:24:41 +01:00
bugfix: do not reset index if no payment was handled
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@@ -38,19 +39,18 @@ public class Payments {
|
||||
return;
|
||||
}
|
||||
paymentOptionals = grpcPayments.getAllPaymentsAfter(offsetSettledPayments).orElse(List.of());
|
||||
long maxIndex = getMaxIndexAllSettled(paymentOptionals);
|
||||
OptionalLong maxIndex = getMaxIndexAllSettled(paymentOptionals);
|
||||
dao.save(paymentOptionals.stream().flatMap(Optional::stream).toList());
|
||||
dao.setAllSettledIndexOffset(maxIndex);
|
||||
maxIndex.ifPresent(dao::setAllSettledIndexOffset);
|
||||
} while (paymentOptionals.size() == grpcPayments.getLimit());
|
||||
|
||||
}
|
||||
|
||||
private static long getMaxIndexAllSettled(List<Optional<Payment>> paymentOptionals) {
|
||||
private static OptionalLong getMaxIndexAllSettled(List<Optional<Payment>> paymentOptionals) {
|
||||
return paymentOptionals.stream()
|
||||
.takeWhile(Optional::isPresent)
|
||||
.flatMap(Optional::stream)
|
||||
.mapToLong(Payment::index)
|
||||
.max()
|
||||
.orElse(0L);
|
||||
.max();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,15 @@ class PaymentsTest {
|
||||
inOrder.verify(dao).setAllSettledIndexOffset(PAYMENT.index());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keeps_index_after_saving_if_no_payments_are_settled() {
|
||||
when(grpcPayments.getAllPaymentsAfter(ALL_SETTLED_INDEX_OFFSET)).thenReturn(
|
||||
Optional.of(List.of(Optional.empty(), Optional.empty(), Optional.empty()))
|
||||
).thenReturn(Optional.of(List.of()));
|
||||
payments.loadOldSettledPayments();
|
||||
verify(dao, never()).setAllSettledIndexOffset(anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignores_non_settled_payments() {
|
||||
when(grpcPayments.getAllPaymentsAfter(ALL_SETTLED_INDEX_OFFSET)).thenReturn(
|
||||
|
||||
Reference in New Issue
Block a user