-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat: add pagination and new filters to query orders #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,30 +269,33 @@ func (s *Server) EcoParameters(w http.ResponseWriter, r *http.Request, _ httprou | |
| }) | ||
| } | ||
|
|
||
| // Order gets an order for the specified chain | ||
| // Order gets an order for the specified committee | ||
| func (s *Server) Order(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
| // Invoke helper with the HTTP request, response writer and an inline callback | ||
| s.orderParams(w, r, func(s *fsm.StateMachine, p *orderRequest) (any, lib.ErrorI) { | ||
| orderId, err := lib.StringToBytes(p.OrderId) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return s.GetOrder(orderId, p.ChainId) | ||
| return s.GetOrder(orderId, p.Committee) | ||
| }) | ||
| } | ||
|
|
||
| // Orders retrieves the order book for a committee | ||
| // Orders retrieves the order book for a committee with optional filters and pagination | ||
| func (s *Server) Orders(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
| // Invoke helper with the HTTP request, response writer and an inline callback | ||
| s.heightAndIdParams(w, r, func(s *fsm.StateMachine, id uint64) (any, lib.ErrorI) { | ||
| if id == 0 { | ||
| return s.GetOrderBooks() | ||
| } | ||
| b, err := s.GetOrderBook(id) | ||
| if err != nil { | ||
| return nil, err | ||
| s.ordersParams(w, r, func(s *fsm.StateMachine, req *ordersRequest) (any, lib.ErrorI) { | ||
| // convert seller address if provided | ||
| var sellerAddr []byte | ||
| if req.SellersSendAddress != "" { | ||
| var err lib.ErrorI | ||
| sellerAddr, err = lib.StringToBytes(req.SellersSendAddress) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return &lib.OrderBooks{OrderBooks: []*lib.OrderBook{b}}, nil | ||
| // use paginated query | ||
| return s.GetOrdersPaginated(sellerAddr, req.Committee, req.PageParams) | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -664,8 +667,25 @@ func (s *Server) IndexerBlobsCached(height uint64, delta bool) (*fsm.IndexerBlob | |
|
|
||
| // orderParams is a helper function to abstract common workflows around a callback requiring a state machine and order request | ||
| func (s *Server) orderParams(w http.ResponseWriter, r *http.Request, callback func(s *fsm.StateMachine, request *orderRequest) (any, lib.ErrorI)) { | ||
| // initialize a new orderRequest object | ||
| req := new(orderRequest) | ||
| // execute the callback with the state machine and request | ||
| s.readOnlyStateFromHeightParams(w, r, req, func(state *fsm.StateMachine) (err lib.ErrorI) { | ||
| p, err := callback(state, req) | ||
| if err != nil { | ||
| write(w, err, http.StatusBadRequest) | ||
| return | ||
| } | ||
| write(w, p, http.StatusOK) | ||
| return | ||
| }) | ||
| } | ||
|
|
||
| // ordersParams is a helper function to abstract common workflows around a callback requiring a state machine and orders request | ||
| func (s *Server) ordersParams(w http.ResponseWriter, r *http.Request, callback func(s *fsm.StateMachine, request *ordersRequest) (any, lib.ErrorI)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function is the exact same one as the one above |
||
| // initialize a new ordersRequest object | ||
| req := new(ordersRequest) | ||
| // execute the callback with the state machine and request | ||
| s.readOnlyStateFromHeightParams(w, r, req, func(state *fsm.StateMachine) (err lib.ErrorI) { | ||
| p, err := callback(state, req) | ||
| if err != nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.