Fix dangling payments (#58)

This commit is contained in:
Pietralberto Mazza
2023-12-12 15:11:25 +01:00
committed by GitHub
parent 3985bd4e14
commit 6d00ee280c

View File

@@ -53,10 +53,6 @@ func (m *paymentsMap) pop(num int64) []domain.Payment {
m.lock.Lock()
defer m.lock.Unlock()
if num < 0 || num > int64(len(m.payments)) {
num = int64(len(m.payments))
}
paymentsByTime := make([]timedPayment, 0, len(m.payments))
for _, p := range m.payments {
// Skip payments without registered receivers.
@@ -73,6 +69,10 @@ func (m *paymentsMap) pop(num int64) []domain.Payment {
return paymentsByTime[i].timestamp.Before(paymentsByTime[j].timestamp)
})
if num < 0 || num > int64(len(paymentsByTime)) {
num = int64(len(paymentsByTime))
}
payments := make([]domain.Payment, 0, num)
for _, p := range paymentsByTime[:num] {
payments = append(payments, p.Payment)