package services import ( "time" "ripple/config" "ripple/helpers" ) const cleanupPaymentInterval = config.PenaltyRate func (pm *PaymentManager) CleanupPaymentRoutine() { for paymentID, payment := range pm.st.Storage.Payments { if payment.Syncing() || payment.PenaltyTicker() < payment.Amount { continue } if payment.Committing() { payment.CommitPenalty = payment.Amount } if payment.Incoming.IsSet() { pm.accSender.Send(payment.Incoming, helpers.BuildCleanupPayment(paymentID)) } if payment.Outgoing.IsSet() { payment.FinalizeOut = helpers.CleanupOut(payment) pm.accSender.Send(payment.Outgoing, helpers.BuildCleanupPayment(paymentID)) } payment.Cleanup() pm.st.Storage.Payments[paymentID] = payment pm.st.Save() } } func (pm *PaymentManager) RunCleanupPaymentRoutine() { for { pm.CleanupPaymentCh <- struct{}{} time.Sleep(cleanupPaymentInterval) } }