Skip to content

Commit

Permalink
Version Wallet API
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Jan 17, 2022
1 parent e729aca commit 49f113b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 78 deletions.
22 changes: 14 additions & 8 deletions marlowe-dashboard-client/generated/Marlowe.purs
Expand Up @@ -24,8 +24,8 @@ import Data.Newtype (unwrap)
import Data.String (joinWith)
import Effect.Aff.Class (class MonadAff, liftAff)
import Marlowe.Run.Dto (WalletIdDto)
import Marlowe.Run.Wallet.API (GetTotalFundsResponse)
import Marlowe.Run.Wallet.CentralizedTestnet.Types
import Marlowe.Run.Wallet.V1.API (GetTotalFundsResponse)
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types
( CheckPostData
, RestoreError
, RestorePostData
Expand Down Expand Up @@ -101,15 +101,15 @@ getApiVersion = do
Left err -> throwError $ { request: affReq, description: DecodingError err }
Right body -> pure body

getApiWalletByWalletidGettotalfunds
getApiWalletV1ByWalletidGettotalfunds
:: forall env m
. HasSPSettings env
=> MonadAsk env m
=> MonadError AjaxError m
=> MonadAff m
=> WalletIdDto
-> m GetTotalFundsResponse
getApiWalletByWalletidGettotalfunds wallet_id = do
getApiWalletV1ByWalletidGettotalfunds wallet_id = do
spSettings <- asks spSettings
let baseURL = spSettings.baseURL
let httpMethod = Left GET
Expand All @@ -129,6 +129,8 @@ getApiWalletByWalletidGettotalfunds wallet_id = do
<> "/"
<> "wallet"
<> "/"
<> "v1"
<> "/"
<> encodeURIComponent (toURLPiece wallet_id)
<> "/"
<> "get-total-funds"
Expand Down Expand Up @@ -160,15 +162,15 @@ getApiWalletByWalletidGettotalfunds wallet_id = do
Left err -> throwError $ { request: affReq, description: DecodingError err }
Right body -> pure body

postApiWalletCentralizedtestnetRestore
postApiWalletV1CentralizedtestnetRestore
:: forall env m
. HasSPSettings env
=> MonadAsk env m
=> MonadError AjaxError m
=> MonadAff m
=> RestorePostData
-> m (Either RestoreError WalletInfo)
postApiWalletCentralizedtestnetRestore reqBody = do
postApiWalletV1CentralizedtestnetRestore reqBody = do
spSettings <- asks spSettings
let baseURL = spSettings.baseURL
let httpMethod = Left POST
Expand All @@ -188,6 +190,8 @@ postApiWalletCentralizedtestnetRestore reqBody = do
<> "/"
<> "wallet"
<> "/"
<> "v1"
<> "/"
<> "centralized-testnet"
<> "/"
<> "restore"
Expand Down Expand Up @@ -223,15 +227,15 @@ postApiWalletCentralizedtestnetRestore reqBody = do
Left err -> throwError $ { request: affReq, description: DecodingError err }
Right body -> pure body

postApiWalletCentralizedtestnetCheckmnemonic
postApiWalletV1CentralizedtestnetCheckmnemonic
:: forall env m
. HasSPSettings env
=> MonadAsk env m
=> MonadError AjaxError m
=> MonadAff m
=> CheckPostData
-> m Boolean
postApiWalletCentralizedtestnetCheckmnemonic reqBody = do
postApiWalletV1CentralizedtestnetCheckmnemonic reqBody = do
spSettings <- asks spSettings
let baseURL = spSettings.baseURL
let httpMethod = Left POST
Expand All @@ -251,6 +255,8 @@ postApiWalletCentralizedtestnetCheckmnemonic reqBody = do
<> "/"
<> "wallet"
<> "/"
<> "v1"
<> "/"
<> "centralized-testnet"
<> "/"
<> "check-mnemonic"
Expand Down
@@ -1,5 +1,5 @@
-- File auto generated by purescript-bridge! --
module Marlowe.Run.Wallet.API where
module Marlowe.Run.Wallet.V1.API where

import Prelude

Expand Down
@@ -1,5 +1,5 @@
-- File auto generated by purescript-bridge! --
module Marlowe.Run.Wallet.CentralizedTestnet.Types where
module Marlowe.Run.Wallet.V1.CentralizedTestnet.Types where

import Prelude

Expand Down
4 changes: 2 additions & 2 deletions marlowe-dashboard-client/src/API/Marlowe/Run/Wallet.purs
Expand Up @@ -10,7 +10,7 @@ import Control.Monad.Error.Class (class MonadError)
import Data.Newtype (unwrap)
import Effect.Aff.Class (class MonadAff)
import Marlowe.Run.Dto (WalletIdDto)
import Marlowe.Run.Wallet.API (GetTotalFundsResponse)
import Marlowe.Run.Wallet.V1.API (GetTotalFundsResponse)
import Servant.PureScript (AjaxError)

getTotalFunds
Expand All @@ -20,4 +20,4 @@ getTotalFunds
=> WalletIdDto
-> m GetTotalFundsResponse
getTotalFunds wallet =
doGetRequest $ "/api/wallet/" <> unwrap wallet <> "/get-total-funds"
doGetRequest $ "/api/wallet/v1/" <> unwrap wallet <> "/get-total-funds"
Expand Up @@ -12,7 +12,7 @@ import Control.Monad.Except (runExceptT)
import Data.Argonaut (encodeJson)
import Data.Argonaut.Decode.Aeson as D
import Effect.Aff.Class (class MonadAff)
import Marlowe.Run.Wallet.CentralizedTestnet.Types
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types
( RestoreError(..)
, RestorePostData(..)
) as BE
Expand Down Expand Up @@ -51,5 +51,5 @@ restoreWallet { walletName, mnemonicPhrase } = do
$ runExceptT
$ doPostRequestWith
{ encode: encodeJson, decode: D.decode (D.either D.value D.value) }
"/api/wallet/centralized-testnet/restore"
"/api/wallet/v1/centralized-testnet/restore"
body
2 changes: 1 addition & 1 deletion marlowe-dashboard-client/src/AppM.purs
Expand Up @@ -27,7 +27,7 @@ import Halogen.Store.Monad
, updateStore
)
import Marlowe (postApiWalletCentralizedtestnetCheckmnemonic)
import Marlowe.Run.Wallet.CentralizedTestnet.Types (CheckPostData(..))
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types (CheckPostData(..))
import Store as Store

newtype AppM a = AppM (ReaderT Env (StoreT Store.Action Store.Store Aff) a)
Expand Down
2 changes: 1 addition & 1 deletion marlowe-dashboard-client/src/Capability/Wallet.purs
Expand Up @@ -23,7 +23,7 @@ import Bridge (toBack, toFront)
import Component.Contacts.Types (WalletId, WalletInfo)
import Control.Monad.Except (lift, runExceptT)
import Halogen (HalogenM)
import Marlowe.Run.Wallet.API as BE
import Marlowe.Run.Wallet.V1.API as BE
import Marlowe.Semantics (Assets)
import Plutus.V1.Ledger.Tx (Tx)
import Types (AjaxResponse)
Expand Down
4 changes: 2 additions & 2 deletions marlowe-dashboard-server/app/PSGenerator.hs
Expand Up @@ -25,8 +25,8 @@ import Language.PureScript.Bridge.PSTypes (psNumber, psString)
import Language.PureScript.Bridge.SumType (equal, genericShow, mkSumType, order)
import Marlowe.Run.API (HTTPAPI)
import Marlowe.Run.Dto
import Marlowe.Run.Wallet.API (GetTotalFundsResponse)
import Marlowe.Run.Wallet.CentralizedTestnet.Types (CheckPostData, RestoreError, RestorePostData)
import Marlowe.Run.Wallet.V1.API (GetTotalFundsResponse)
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types (CheckPostData, RestoreError, RestorePostData)
import Marlowe.Run.WebSocket (StreamToClient, StreamToServer)
import qualified PSGenerator.Common
import Servant.PureScript (HasBridge, Settings, apiModuleName, defaultBridge, defaultSettings, languageBridge,
Expand Down
18 changes: 9 additions & 9 deletions marlowe-dashboard-server/marlowe-dashboard-server.cabal
Expand Up @@ -18,20 +18,20 @@ source-repository head
library
default-extensions: NoImplicitPrelude
exposed-modules:
Marlowe.Run.Server
Marlowe.Run.API
Marlowe.Run.Dto
Marlowe.Run.Wallet.API
Marlowe.Run.Server
Marlowe.Run.Wallet.V1.API
Marlowe.Run.Wallet.V1.CentralizedTestnet.Types
Marlowe.Run.Wallet.V1.Client
Marlowe.Run.WebSocket
Marlowe.Run.Wallet.CentralizedTestnet.Types
Marlowe.Run.Wallet.Client
other-modules:
Paths_marlowe_dashboard_server
Marlowe.Run
Marlowe.Run.Wallet
Marlowe.Run.Wallet.Server
Marlowe.Run.Wallet.CentralizedTestnet.API
Marlowe.Run.Wallet.CentralizedTestnet.Server
Marlowe.Run.Wallet.V1
Marlowe.Run.Wallet.V1.CentralizedTestnet.API
Marlowe.Run.Wallet.V1.CentralizedTestnet.Server
Marlowe.Run.Wallet.V1.Server
Paths_marlowe_dashboard_server
hs-source-dirs:
src
default-language: Haskell2010
Expand Down
31 changes: 0 additions & 31 deletions marlowe-dashboard-server/src/Marlowe/Run.hs
Expand Up @@ -3,40 +3,9 @@
module Marlowe.Run where

import Cardano.Prelude hiding (Handler)
import Data.Aeson as Aeson
import Data.List (stripPrefix)
import Data.String as S
import qualified Data.Text as Text
import Data.Version (showVersion)
import qualified Paths_marlowe_dashboard_server as Package.Paths
import Prelude (userError)

data WBEConfig = WBEConfig { _wbeHost :: String, _wbePort :: Int }
deriving (Eq, Generic, Show)

normalizeFieldLabel prefix label =
maybe label lower1 $ stripPrefix ('_' : prefix) label

lower1 (c:cs) = toLower c : cs
lower1 [] = []

instance FromJSON WBEConfig where
parseJSON = Aeson.genericParseJSON $ Aeson.defaultOptions
{ fieldLabelModifier = normalizeFieldLabel "wbe" }

data AppConfig = AppConfig { _appWbeConfig :: WBEConfig, _appStaticPath :: FilePath }
deriving (Eq, Generic, Show)

instance FromJSON AppConfig where
parseJSON = Aeson.genericParseJSON $ Aeson.defaultOptions
{ fieldLabelModifier = normalizeFieldLabel "app" }

getVersion :: Applicative m => m Text
getVersion = pure $ Text.pack $ showVersion Package.Paths.version

initializeServerContext :: FilePath -> IO AppConfig
initializeServerContext configPath = do
mConfig <- decodeFileStrict configPath
case mConfig of
Just config -> pure config
Nothing -> ioError $ userError "Config file has invalid format"
4 changes: 2 additions & 2 deletions marlowe-dashboard-server/src/Marlowe/Run/API.hs
Expand Up @@ -4,7 +4,7 @@
module Marlowe.Run.API where

import Cardano.Prelude
import qualified Marlowe.Run.Wallet.API as Wallet
import qualified Marlowe.Run.Wallet.V1.API as Wallet
import Servant.API (Get, JSON, PlainText, Raw, (:<|>), (:>))
import Servant.API.WebSocket (WebSocketPending)

Expand All @@ -14,7 +14,7 @@ type API = WebSocketAPI

type HTTPAPI = "api" :>
("version" :> Get '[PlainText, JSON] Text
:<|> "wallet" :> Wallet.API
:<|> "wallet" :> "v1" :> Wallet.API
)

type WebSocketAPI = "ws" :> WebSocketPending
2 changes: 1 addition & 1 deletion marlowe-dashboard-server/src/Marlowe/Run/Server.hs
Expand Up @@ -8,7 +8,7 @@ module Marlowe.Run.Server where
import Cardano.Prelude hiding (Handler)
import Marlowe.Run (getVersion)
import Marlowe.Run.API (API)
import qualified Marlowe.Run.Wallet.Server as Wallet
import qualified Marlowe.Run.Wallet.V1.Server as Wallet
import qualified Marlowe.Run.WebSocket as WS
import Servant (Handler (Handler), Server, ServerError, hoistServer, serveDirectoryFileServer, (:<|>) ((:<|>)))
import Servant.Client (ClientEnv)
Expand Down
Expand Up @@ -6,7 +6,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}

module Marlowe.Run.Wallet where
module Marlowe.Run.Wallet.V1 where

import Cardano.Prelude hiding (Handler)
import qualified Cardano.Wallet.Api.Types as WBE (ApiT (..), ApiWallet (..), ApiWalletAssetsBalance (..),
Expand Down
Expand Up @@ -6,13 +6,13 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeOperators #-}

module Marlowe.Run.Wallet.API where
module Marlowe.Run.Wallet.V1.API where

import Cardano.Prelude
import Data.Aeson (ToJSON)
import Marlowe.Run.Dto (AssetsDto, ToDto (..), WalletIdDto)
import qualified Marlowe.Run.Wallet as Domain
import qualified Marlowe.Run.Wallet.CentralizedTestnet.API as CentralizedTestnet
import qualified Marlowe.Run.Wallet.V1 as Domain
import qualified Marlowe.Run.Wallet.V1.CentralizedTestnet.API as CentralizedTestnet
import Servant.API (Capture, Get, JSON, (:<|>), (:>))

data GetTotalFundsResponse =
Expand Down
Expand Up @@ -2,10 +2,10 @@
{-# LANGUAGE TypeOperators #-}

-- | This module holds the API to access the centralized testnet
module Marlowe.Run.Wallet.CentralizedTestnet.API where
module Marlowe.Run.Wallet.V1.CentralizedTestnet.API where

import Cardano.Prelude
import Marlowe.Run.Wallet.CentralizedTestnet.Types (CheckPostData, RestoreError, RestorePostData)
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types (CheckPostData, RestoreError, RestorePostData)
import Servant.API (JSON, Post, ReqBody, (:<|>), (:>))
-- FIXME: I don't like to use a Mock type here, but we'd need to publish some changes upstream to the PAB to fix this
import Cardano.Wallet.Mock.Types (WalletInfo)
Expand Down
Expand Up @@ -5,7 +5,7 @@
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Marlowe.Run.Wallet.CentralizedTestnet.Server
module Marlowe.Run.Wallet.V1.CentralizedTestnet.Server
( handlers
)
where
Expand All @@ -24,9 +24,9 @@ import Data.String as S
import qualified Data.Text as Text
import Data.Text.Class (FromText (..))
import Ledger (PaymentPubKeyHash (..), PubKeyHash (..))
import Marlowe.Run.Wallet.CentralizedTestnet.API (API)
import Marlowe.Run.Wallet.CentralizedTestnet.Types (CheckPostData (..), RestoreError (..), RestorePostData (..))
import Marlowe.Run.Wallet.Client (callWBE, decodeError)
import Marlowe.Run.Wallet.V1.CentralizedTestnet.API (API)
import Marlowe.Run.Wallet.V1.CentralizedTestnet.Types (CheckPostData (..), RestoreError (..), RestorePostData (..))
import Marlowe.Run.Wallet.V1.Client (callWBE, decodeError)
import PlutusTx.Builtins.Internal (BuiltinByteString (..))
import Servant (ServerT, (:<|>) ((:<|>)), (:>))
import Servant.Client (ClientEnv, ClientError (FailureResponse), ClientM, ResponseF (responseBody), client)
Expand Down
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE DerivingStrategies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Marlowe.Run.Wallet.CentralizedTestnet.Types where
module Marlowe.Run.Wallet.V1.CentralizedTestnet.Types where

import Cardano.Prelude
import Data.Aeson.Types (FromJSON, ToJSON)
Expand Down
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Marlowe.Run.Wallet.Client
module Marlowe.Run.Wallet.V1.Client
( callWBE
, decodeError
)
Expand Down
Expand Up @@ -6,16 +6,16 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}

module Marlowe.Run.Wallet.Server where
module Marlowe.Run.Wallet.V1.Server where

import Cardano.Prelude hiding (Handler)
import qualified Cardano.Wallet.Api.Client as WBE.Api
import qualified Cardano.Wallet.Api.Types as WBE
import Marlowe.Run.Dto (WalletIdDto, dtoHandler)
import Marlowe.Run.Wallet (getTotalFunds)
import Marlowe.Run.Wallet.API (API, GetTotalFundsResponse (..))
import qualified Marlowe.Run.Wallet.CentralizedTestnet.Server as CentralizedTestnet
import Marlowe.Run.Wallet.Client (callWBE)
import Marlowe.Run.Wallet.V1 (getTotalFunds)
import Marlowe.Run.Wallet.V1.API (API, GetTotalFundsResponse (..))
import qualified Marlowe.Run.Wallet.V1.CentralizedTestnet.Server as CentralizedTestnet
import Marlowe.Run.Wallet.V1.Client (callWBE)
import Servant (ServerError, ServerT, err404, (:<|>) ((:<|>)))
import Servant.Client (ClientEnv)

Expand Down

0 comments on commit 49f113b

Please sign in to comment.