package services import ( "time" "ripple/config" "ripple/helpers" "ripple/state" "ripple/types" ) const autoCancelInterval = 1 * time.Minute func (pm *PaymentManager) AutoCancelRoutine() { now := time.Now() for paymentID, payment := range pm.st.Storage.Payments { if !payment.Committed() { continue } if payment.Counterpart == (types.UserIdentifier{}) && payment.Outgoing != (types.UserIdentifier{}) { continue } if now.Sub(time.Unix(payment.CreatedAt, 0)) <= config.Timeout { continue } payment.Status = state.Cancel pm.st.Storage.Payments[paymentID] = payment ok, nextHop, instr := helpers.BuildCancelAuto(paymentID, payment) if ok { pm.lockstep.Enqueue(nextHop, instr) } } } func (pm *PaymentManager) RunAutoCancelRoutine() { for { pm.AutoCancelCh <- struct{}{} time.Sleep(autoCancelInterval) } }