From 5e082a63b9fad62fea5a99799f376021ca02f57c Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 6 Mar 2024 13:45:05 +0530 Subject: [PATCH] feat: code refactor, abstract out common path Closes: #21 --- .../src/GeniusYield/Server/Api.hs | 12 ++++--- .../GeniusYield/Server/Dex/PartialOrder.hs | 31 +++++++++---------- web/swagger/api.json | 20 ++++++------ 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/geniusyield-server-lib/src/GeniusYield/Server/Api.hs b/geniusyield-server-lib/src/GeniusYield/Server/Api.hs index decc2f0..75a4ade 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/Api.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/Api.hs @@ -53,10 +53,12 @@ instance Swagger.ToSchema Settings where ------------------------------------------------------------------------------- type GeniusYieldAPI = - "settings" :> Get '[JSON] Settings - :<|> DEXPartialOrderAPI - :<|> MarketsAPI - :<|> TxAPI + "v1" + :> ( "settings" :> Get '[JSON] Settings + :<|> DEXPartialOrderAPI + :<|> MarketsAPI + :<|> TxAPI + ) geniusYieldAPI ∷ Proxy GeniusYieldAPI geniusYieldAPI = Proxy @@ -72,7 +74,7 @@ geniusYieldAPISwagger = .~ "1.0" & info . description - ?~ "This API is used for building and submitting transactions." + ?~ "This API is used to interact with GeniusYield DEX." geniusYieldServer ∷ Ctx → ServerT GeniusYieldAPI IO geniusYieldServer ctx = diff --git a/geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs b/geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs index d9f0c1e..afafe84 100644 --- a/geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs +++ b/geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs @@ -189,21 +189,20 @@ type DEXPartialOrderAPI = "trading_fees" :> Get '[JSON] TradingFees :<|> "orders" - :> "open" - :> "tx" - :> "generate" - :> ReqBody '[JSON] PlaceOrderParameters - :> Post '[JSON] PlaceOrderTransactionDetails - :<|> "orders" - :> "cancel" - :> "tx" - :> "generate" - :> ReqBody '[JSON] CancelOrderParameters - :> Post '[JSON] CancelOrderTransactionDetails - :<|> "orders" - :> Capture "market_id" OrderAssetPair - :> QueryParam "address" GYAddressBech32 - :> Get '[JSON] OrderBookInfo + :> ( "open" + :> "tx" + :> "generate" + :> ReqBody '[JSON] PlaceOrderParameters + :> Post '[JSON] PlaceOrderTransactionDetails + :<|> "cancel" + :> "tx" + :> "generate" + :> ReqBody '[JSON] CancelOrderParameters + :> Post '[JSON] CancelOrderTransactionDetails + :<|> Capture "market_id" OrderAssetPair + :> QueryParam "address" GYAddressBech32 + :> Get '[JSON] OrderBookInfo + ) handleDEXPartialOrder ∷ Ctx → ServerT DEXPartialOrderAPI IO handleDEXPartialOrder ctx = @@ -293,7 +292,7 @@ handleOrders ctx@Ctx {..} orderAssetPair mownAddress = do os -- TODO: Make it strict, likely there is memory leak here. -- TODO: Check if it's implementation is correct. - (bids, asks) = + (!bids, !asks) = Map.foldl' ( \(!accBids, !accAsks) poi@PartialOrderInfo {..} → let buyAP = mkOrderAssetPair poiOfferedAsset poiAskedAsset diff --git a/web/swagger/api.json b/web/swagger/api.json index e1912b2..14d07da 100644 --- a/web/swagger/api.json +++ b/web/swagger/api.json @@ -342,12 +342,12 @@ } }, "info": { - "description": "This API is used for building and submitting transactions.", + "description": "This API is used to interact with GeniusYield DEX.", "title": "Genius Yield Haskell Server API", "version": "1.0" }, "paths": { - "/markets": { + "/v1/markets": { "get": { "produces": [ "application/json;charset=utf-8" @@ -365,7 +365,7 @@ } } }, - "/orders/cancel/tx/generate": { + "/v1/orders/cancel/tx/generate": { "post": { "consumes": [ "application/json;charset=utf-8" @@ -396,7 +396,7 @@ } } }, - "/orders/open/tx/generate": { + "/v1/orders/open/tx/generate": { "post": { "consumes": [ "application/json;charset=utf-8" @@ -427,7 +427,7 @@ } } }, - "/orders/{market_id}": { + "/v1/orders/{market_id}": { "get": { "parameters": [ { @@ -460,7 +460,7 @@ } } }, - "/settings": { + "/v1/settings": { "get": { "produces": [ "application/json;charset=utf-8" @@ -475,7 +475,7 @@ } } }, - "/trading_fees": { + "/v1/trading_fees": { "get": { "produces": [ "application/json;charset=utf-8" @@ -490,7 +490,7 @@ } } }, - "/tx/sign": { + "/v1/tx/sign": { "post": { "consumes": [ "application/json;charset=utf-8" @@ -521,7 +521,7 @@ } } }, - "/tx/sign_and_submit": { + "/v1/tx/sign_and_submit": { "post": { "consumes": [ "application/json;charset=utf-8" @@ -552,7 +552,7 @@ } } }, - "/tx/submit": { + "/v1/tx/submit": { "post": { "consumes": [ "application/json;charset=utf-8"