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.GetPaymentID()) } func (h *CounterpartHandlers) CommitPayment(args []byte) { paymentID := h.st.Memory.GetPaymentID() pf, ok := h.st.Memory.GetPathfinding(paymentID) if !ok { return } if pf.Counterpart == (types.UserIdentifier{}) || pf.Amount >= 0 || !pf.Commit { return } argsBuf := make([]byte, 48) copy(argsBuf[:32], paymentID[:]) binary.BigEndian.PutUint64(argsBuf[32:], uint64(-pf.Amount)) binary.BigEndian.PutUint64(argsBuf[40:], pf.Tax) h.lockstep.Enqueue(pf.Outgoing, types.Instruction{ Command: commands.LOCKSTEP_INIT_PAYMENT, Arguments: argsBuf, }) } func (h *CounterpartHandlers) SealPayment(args []byte) { paymentID := h.st.Memory.GetPaymentID() payment, ok := h.st.Storage.Payments[paymentID] if !ok || payment.Incoming != (types.UserIdentifier{}) || payment.Cancelled() { return } h.lockstep.Enqueue(payment.Outgoing, types.Instruction{ Command: commands.LOCKSTEP_SEAL_PAYMENT, Arguments: paymentID[:], }) }