package services import ( "time" "ripple/bug" "ripple/config" "ripple/lockstep" "ripple/state" "ripple/transport" "ripple/types" ) type PaymentManager struct { st *state.State d *transport.Data lockstep *lockstep.Lockstep accSender *transport.AccountTransport CancelFailsafeCh chan struct{} FeeFailsafeCh chan struct{} ScheduleFeeCh chan struct{} } func NewPaymentManager( st *state.State, d *transport.Data, lockstep *lockstep.Lockstep, accSender *transport.AccountTransport, ) *PaymentManager { m := &PaymentManager{ st: st, d: d, lockstep: lockstep, accSender: accSender, CancelFailsafeCh: make(chan struct{}), FeeFailsafeCh: make(chan struct{}), ScheduleFeeCh: make(chan struct{}), } go m.RunCancelPaymentFailsafe() go m.RunPaymentFeeFailsafe() go m.RunCollectFees() return m } func (m *PaymentManager) InitPayment( identifier types.UserIdentifier, port int, secretKey [32]byte, amount int64, tax uint64, ) { delete(m.st.Memory.Pathfinding, m.st.Memory.GetPaymentID()) m.d.AddCounterpart(identifier, port, secretKey) m.st.Memory.Preimage = secretKey m.st.Memory.Pathfinding[m.st.Memory.GetPaymentID()] = state.Pathfinding{ Amount: amount, Tax: tax, Timeout: time.Now().Add(config.Timeout).Unix(), Counterpart: identifier, } } func (m *PaymentManager) AddPathfinding(paymentID [32]byte, amount int64, tax uint64, id types.UserIdentifier) bool { if _, ok := m.st.Memory.Pathfinding[paymentID]; ok { panic(bug.BugStateViolated) } if len(m.st.Memory.Pathfinding) >= config.BufferSize { return false } newPath := state.Pathfinding{ Amount: amount, Tax: tax, Timeout: time.Now().Add(config.Timeout).Unix(), } if amount < 0 { newPath.Incoming = id } else { newPath.Outgoing = id } m.st.Memory.Pathfinding[paymentID] = newPath return true } //func (m *PaymentManager) RemovePath(paymentID [32]byte) { // m.st.Memory.RemovePathfinding(paymentID) //}