package session import ( "net" "ripple/handler" "ripple/transport" "ripple/types" ) type AccountSession struct { transport *transport.AccountTransport cmdHandlers [256]func(types.UserIdentifier, []byte) } func NewAccountSession( transport *transport.AccountTransport, h *handler.AccountHandlers, ) *AccountSession { s := &AccountSession{transport: transport} s.cmdHandlers[0x00] = h.FindPath s.cmdHandlers[0x01] = h.PathRecurse s.cmdHandlers[0x02] = h.PathFound s.cmdHandlers[0x03] = h.PreparePath s.cmdHandlers[0x04] = h.CommitPayment s.cmdHandlers[0x05] = h.SealPayment s.cmdHandlers[0x06] = h.FinalizePayment s.cmdHandlers[0x07] = h.CancelPayment s.cmdHandlers[0x08] = h.CleanupPayment s.cmdHandlers[0x09] = h.AckPreimage s.cmdHandlers[0x0A] = h.SyncPayment s.cmdHandlers[0x0B] = h.AckSync s.cmdHandlers[0x0C] = h.VerifyCommit s.cmdHandlers[0x0D] = h.AckCommit return s } func (s *AccountSession) Receive(tx []byte, addr *net.UDPAddr) (types.Transaction, error) { return s.transport.Receive(tx, addr) } func (s *AccountSession) Dispatch(tx types.Transaction) { if h := s.cmdHandlers[tx.Instruction.Command]; h != nil { h(tx.Identifier, tx.Instruction.Arguments) } }