package handler import ( "encoding/binary" "ripple/commands" "ripple/lockstep" "ripple/services" "ripple/state" "ripple/types" ) type CounterpartHandlers struct { st *state.State lockstep *lockstep.Lockstep pm *services.PaymentManager } func NewCounterpartHandlers( st *state.State, lockstep *lockstep.Lockstep, pm *services.PaymentManager, ) *CounterpartHandlers { return &CounterpartHandlers{ st: st, lockstep: lockstep, pm: pm, } } func (h *CounterpartHandlers) FindPath(args []byte) { h.pm.ForwardFindPath(h.st.Memory.Payment) } func (h *CounterpartHandlers) CommitPayment(args []byte) { pf, ok := h.st.Memory.GetPathfinding(h.st.Memory.Payment) if !ok { return } if pf.Counterpart == (types.UserIdentifier{}) || pf.Amount >= 0 || !pf.Commit { return } argsBuf := make([]byte, 40) copy(argsBuf[:32], h.st.Memory.Payment[:]) binary.BigEndian.PutUint64(argsBuf[32:], uint64(-pf.Amount)) h.lockstep.Enqueue(pf.Outgoing, types.Instruction{ Command: commands.LOCKSTEP_COMMIT_PAYMENT, Arguments: argsBuf, }) } func (h *CounterpartHandlers) FinalizePayment(args []byte) { payment, ok := h.st.Storage.Payments[h.st.Memory.Payment] if !ok || payment.Incoming != (types.UserIdentifier{}) || payment.Cancel { return } h.lockstep.Enqueue(payment.Outgoing, types.Instruction{ Command: commands.LOCKSTEP_FINALIZE_PAYMENT, Arguments: h.st.Memory.Payment[:], }) }