Skip to content

Commit

Permalink
move active-orders query to the orderbook
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Aug 23, 2024
1 parent 7eb04ae commit 17169ac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 81 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## v25.16.0

- Move active orders query to the passthrough use case

## v25.15.0

- Add query for active orders in the orderbook
Expand Down
4 changes: 1 addition & 3 deletions app/sidecar_query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
passthroughdomain "github.com/osmosis-labs/sqs/domain/passthrough"
"github.com/osmosis-labs/sqs/log"
"github.com/osmosis-labs/sqs/middleware"
orderbookHttpDelivery "github.com/osmosis-labs/sqs/orderbook/delivery/http"

routerHttpDelivery "github.com/osmosis-labs/sqs/router/delivery/http"
routerUseCase "github.com/osmosis-labs/sqs/router/usecase"
Expand Down Expand Up @@ -204,13 +203,12 @@ func NewSideCarQueryServer(appCodec codec.Codec, config domain.Config, logger lo

// HTTP handlers
poolsHttpDelivery.NewPoolsHandler(e, poolsUseCase)
passthroughHttpDelivery.NewPassthroughHandler(e, passthroughUseCase)
passthroughHttpDelivery.NewPassthroughHandler(e, passthroughUseCase, orderBookUseCase)
systemhttpdelivery.NewSystemHandler(e, config, logger, chainInfoUseCase)
if err := tokenshttpdelivery.NewTokensHandler(e, *config.Pricing, tokensUseCase, pricingSimpleRouterUsecase, logger); err != nil {
return nil, err
}
routerHttpDelivery.NewRouterHandler(e, routerUsecase, tokensUseCase, logger)
orderbookHttpDelivery.NewOrderbookHandler(e, orderBookUseCase, logger)

// Create a Numia HTTP client
passthroughConfig := config.Passthrough
Expand Down
74 changes: 0 additions & 74 deletions orderbook/delivery/http/orderbook_handler.go

This file was deleted.

50 changes: 46 additions & 4 deletions passthrough/delivery/http/passthrough_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package http
import (
"net/http"

"github.com/labstack/echo/v4"
deliveryhttp "github.com/osmosis-labs/sqs/delivery/http"
"github.com/osmosis-labs/sqs/domain"
"github.com/osmosis-labs/sqs/domain/mvc"
"github.com/osmosis-labs/sqs/orderbook/types"

"github.com/labstack/echo/v4"
"go.opentelemetry.io/otel/trace"
)

// ResponseError represent the response error struct
Expand All @@ -15,21 +20,24 @@ type ResponseError struct {
// PassthroughHandler is the http handler for passthrough use case
type PassthroughHandler struct {
PUsecase mvc.PassthroughUsecase
OUsecase mvc.OrderBookUsecase
}

const resourcePrefix = "/passthrough"

func formatPoolsResource(resource string) string {
func formatPassthroughResource(resource string) string {
return resourcePrefix + resource
}

// NewPassthroughHandler will initialize the pools/ resources endpoint
func NewPassthroughHandler(e *echo.Echo, ptu mvc.PassthroughUsecase) {
func NewPassthroughHandler(e *echo.Echo, ptu mvc.PassthroughUsecase, ou mvc.OrderBookUsecase) {
handler := &PassthroughHandler{
PUsecase: ptu,
OUsecase: ou,
}

e.GET(formatPoolsResource("/portfolio-assets/:address"), handler.GetPortfolioAssetsByAddress)
e.GET(formatPassthroughResource("/portfolio-assets/:address"), handler.GetPortfolioAssetsByAddress)
e.GET(formatPassthroughResource("/active-orders"), handler.GetActiveOrders)
}

// @Summary Returns portfolio assets associated with the given address by category.
Expand All @@ -56,3 +64,37 @@ func (a *PassthroughHandler) GetPortfolioAssetsByAddress(c echo.Context) error {

return c.JSON(http.StatusOK, portfolioAssetsResult)
}

func (a *PassthroughHandler) GetActiveOrders(c echo.Context) (err error) {
ctx := c.Request().Context()

span := trace.SpanFromContext(ctx)
defer func() {
if err != nil {
span.RecordError(err)
// nolint:errcheck // ignore error
c.JSON(domain.GetStatusCode(err), domain.ResponseError{Message: err.Error()})
}

// Note: we do not end the span here as it is ended in the middleware.
}()

var req types.GetActiveOrdersRequest
if err := deliveryhttp.UnmarshalRequest(c, &req); err != nil {
return c.JSON(http.StatusBadRequest, domain.ResponseError{Message: err.Error()})
}

// Validate the request
if err := req.Validate(); err != nil {
return c.JSON(http.StatusBadRequest, domain.ResponseError{Message: err.Error()})
}

orders, err := a.OUsecase.GetActiveOrders(ctx, req.UserOsmoAddress)
if err != nil {
return c.JSON(http.StatusInternalServerError, domain.ResponseError{Message: err.Error()})
}

resp := types.NewGetAllOrderResponse(orders)

return c.JSON(http.StatusOK, resp)
}

0 comments on commit 17169ac

Please sign in to comment.