From aa87b062fe11058c34d0663b7262fc35e94d4e16 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 25 May 2023 15:40:59 +0530 Subject: [PATCH 01/25] Feat 17: Hackage readiness - breaking change - making names according to schema --- src/Maestro/API/Scripts.hs | 4 ++-- src/Maestro/Client/Scripts.hs | 2 +- src/Maestro/Types/Address.hs | 5 ++--- src/Maestro/Types/Common.hs | 16 ++++++++-------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Maestro/API/Scripts.hs b/src/Maestro/API/Scripts.hs index 256d729..84b6586 100644 --- a/src/Maestro/API/Scripts.hs +++ b/src/Maestro/API/Scripts.hs @@ -1,7 +1,7 @@ module Maestro.API.Scripts where import Data.Text (Text) -import Maestro.Types.Common (ReferenceScript) +import Maestro.Types.Common (Script) import Servant.API import Servant.API.Generic @@ -11,5 +11,5 @@ newtype ScriptsAPI route = _scriptByHash :: route :- Capture "script_hash" Text - :> Get '[JSON] ReferenceScript + :> Get '[JSON] Script } deriving Generic diff --git a/src/Maestro/Client/Scripts.hs b/src/Maestro/Client/Scripts.hs index 0f8d8a7..df3e9a3 100644 --- a/src/Maestro/Client/Scripts.hs +++ b/src/Maestro/Client/Scripts.hs @@ -15,5 +15,5 @@ scriptsClient :: MaestroEnv -> ScriptsAPI (AsClientT IO) scriptsClient = fromServant . _scripts . apiClient -- | Get information about the script from it's hash. -getScriptByHash :: MaestroEnv -> Text -> IO ReferenceScript +getScriptByHash :: MaestroEnv -> Text -> IO Script getScriptByHash = _scriptByHash . scriptsClient diff --git a/src/Maestro/Types/Address.hs b/src/Maestro/Types/Address.hs index abbd987..b99d0d3 100644 --- a/src/Maestro/Types/Address.hs +++ b/src/Maestro/Types/Address.hs @@ -1,15 +1,14 @@ module Maestro.Types.Address where import Deriving.Aeson -import Maestro.Types.Common (DatumOption, MaestroAsset, - ReferenceScript) +import Maestro.Types.Common (DatumOption, MaestroAsset, Script) data AddressUtxo = AddressUtxo { _addressUtxoIndex :: !Int , _addressUtxoTxHash :: !String , _addressUtxoAssets :: ![MaestroAsset] , _addressUtxoDatum :: !(Maybe DatumOption) - , _addressUtxoReferenceScript :: !(Maybe ReferenceScript) + , _addressUtxoReferenceScript :: !(Maybe Script) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) diff --git a/src/Maestro/Types/Common.hs b/src/Maestro/Types/Common.hs index 5613400..adf887f 100644 --- a/src/Maestro/Types/Common.hs +++ b/src/Maestro/Types/Common.hs @@ -15,7 +15,7 @@ module Maestro.Types.Common DatumOptionType (..), DatumOption (..), ScriptType (..), - ReferenceScript (..), + Script (..), MaestroAsset (..), Utxo (..), TxCbor (..), @@ -119,16 +119,16 @@ data ScriptType = Native | PlutusV1 | PlutusV2 (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[LowerAll]] ScriptType -data ReferenceScript = ReferenceScript - { _refScriptBytes :: !(Maybe Text), - _refScriptHash :: !Text, - _refScriptJson :: !(Maybe Aeson.Value), - _refScriptType :: !ScriptType +data Script = Script + { _scriptBytes :: !(Maybe Text), + _scriptHash :: !Text, + _scriptJson :: !(Maybe Aeson.Value), + _scriptType :: !ScriptType } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_refScript", LowerFirst]] ReferenceScript + via CustomJSON '[FieldLabelModifier '[StripPrefix "_script", LowerFirst]] Script data MaestroAsset = MaestroAsset { _maestroAssetQuantity :: !Integer, @@ -146,7 +146,7 @@ data Utxo = Utxo _utxoAssets :: ![MaestroAsset], _utxoDatum :: !(Maybe DatumOption), _utxoIndex :: !Natural, - _utxoReferenceScript :: !(Maybe ReferenceScript), + _utxoReferenceScript :: !(Maybe Script), _utxoTxHash :: !Text } deriving stock (Show, Eq, Generic) From 940f8064fd6beca2bb19636bb3dbe5bf42fe9100 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 25 May 2023 15:48:02 +0530 Subject: [PATCH 02/25] Feat 17: Hackage readiness - breaking change - making names according to schema --- test/Maestro/Test/Transaction.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Maestro/Test/Transaction.hs b/test/Maestro/Test/Transaction.hs index def0292..1094b27 100644 --- a/test/Maestro/Test/Transaction.hs +++ b/test/Maestro/Test/Transaction.hs @@ -103,10 +103,10 @@ txUtxoExpected = } , _utxoReferenceScript = - Just ReferenceScript - { _refScriptHash = "3a888d65f16790950a72daee1f63aa05add6d268434107cfa5b67712" - , _refScriptBytes = Just "480100002221200101" - , _refScriptType = PlutusV2 - , _refScriptJson = Nothing + Just Script + { _scriptHash = "3a888d65f16790950a72daee1f63aa05add6d268434107cfa5b67712" + , _scriptBytes = Just "480100002221200101" + , _scriptType = PlutusV2 + , _scriptJson = Nothing } } From cd5383107af98c86e5d47e329db812bbe03a6e20 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 25 May 2023 16:18:27 +0530 Subject: [PATCH 03/25] Feat 17: Hackage readiness - breaking change - making names according to schema --- cabal.project | 1 - maestro-sdk.cabal | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 cabal.project diff --git a/cabal.project b/cabal.project deleted file mode 100644 index e6fdbad..0000000 --- a/cabal.project +++ /dev/null @@ -1 +0,0 @@ -packages: . diff --git a/maestro-sdk.cabal b/maestro-sdk.cabal index 2230d5c..1dc5138 100644 --- a/maestro-sdk.cabal +++ b/maestro-sdk.cabal @@ -85,7 +85,7 @@ library , servant-client , servant-client-core , text - , time ^>= 1.12.1 + , time , http-client , http-client-tls , http-api-data From 9b035b66c8c28495f11ae04c876de001950389d3 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 25 May 2023 18:50:50 +0530 Subject: [PATCH 04/25] Feat 17: Hackage readiness - updated base urls --- src/Maestro/Client/Env.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Maestro/Client/Env.hs b/src/Maestro/Client/Env.hs index f2ccf64..66f4e36 100644 --- a/src/Maestro/Client/Env.hs +++ b/src/Maestro/Client/Env.hs @@ -21,15 +21,14 @@ newtype MaestroEnv = MaestroEnv data MaestroNetwork = Mainnet | Preprod maestroBaseUrl :: MaestroNetwork -> String -maestroBaseUrl Preprod = "https://preprod.gomaestro-api.org/" -maestroBaseUrl Mainnet = "https://mainnet.gomaestro-api.org/" +maestroBaseUrl Preprod = "https://preprod.gomaestro-api.org/v0" +maestroBaseUrl Mainnet = "https://mainnet.gomaestro-api.org/v0" mkMaestroEnv :: MaestroToken -> MaestroNetwork -> IO MaestroEnv mkMaestroEnv token nid = do clientEnv <- servantClientEnv token $ maestroBaseUrl nid pure $ MaestroEnv {_maeClientEnv = clientEnv} - servantClientEnv :: MaestroToken -> String -> IO Servant.ClientEnv servantClientEnv token url = do baseUrl <- Servant.parseBaseUrl url From 0eba7446506852906083844df6c40abd30e555e8 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Thu, 25 May 2023 19:19:11 +0530 Subject: [PATCH 05/25] Feat 17: Hackage readiness - import all clients in a single client file --- maestro-sdk.cabal | 1 + src/Maestro/Client.hs | 28 ++++++++++++++++++++-------- src/Maestro/Client/Accounts.hs | 16 ++++++++-------- src/Maestro/Client/Address.hs | 18 +++++++++--------- src/Maestro/Client/Assets.hs | 18 +++++++++--------- src/Maestro/Client/Core.hs | 13 +++++++++++++ src/Maestro/Client/Datum.hs | 2 +- src/Maestro/Client/Epochs.hs | 2 +- src/Maestro/Client/General.hs | 2 +- src/Maestro/Client/Pools.hs | 18 +++++++++--------- src/Maestro/Client/Scripts.hs | 2 +- src/Maestro/Client/Transaction.hs | 18 +++++++++--------- 12 files changed, 82 insertions(+), 56 deletions(-) create mode 100644 src/Maestro/Client/Core.hs diff --git a/maestro-sdk.cabal b/maestro-sdk.cabal index 1dc5138..41c2f05 100644 --- a/maestro-sdk.cabal +++ b/maestro-sdk.cabal @@ -50,6 +50,7 @@ library Maestro.API.Transaction Maestro.Client + Maestro.Client.Core Maestro.Client.Datum Maestro.Client.Env Maestro.Client.Epochs diff --git a/src/Maestro/Client.hs b/src/Maestro/Client.hs index 0fe91c5..897d2bf 100644 --- a/src/Maestro/Client.hs +++ b/src/Maestro/Client.hs @@ -1,13 +1,25 @@ module Maestro.Client ( - apiClient + module Maestro.Client.Accounts + , module Maestro.Client.Address + , module Maestro.Client.Assets + , module Maestro.Client.Datum + , module Maestro.Client.Env + , module Maestro.Client.Epochs + , module Maestro.Client.General + , module Maestro.Client.Pools + , module Maestro.Client.Scripts + , module Maestro.Client.Transaction ) where -import Control.Exception (throwIO) -import Maestro.API -import Maestro.Client.Env -import Servant.Client -import Servant.Client.Generic -apiClient :: MaestroEnv -> MaestroApi (AsClientT IO) -apiClient MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either throwIO pure +import Maestro.Client.Accounts +import Maestro.Client.Address +import Maestro.Client.Assets +import Maestro.Client.Datum +import Maestro.Client.Env +import Maestro.Client.Epochs +import Maestro.Client.General +import Maestro.Client.Pools +import Maestro.Client.Scripts +import Maestro.Client.Transaction diff --git a/src/Maestro/Client/Accounts.hs b/src/Maestro/Client/Accounts.hs index 6781fca..10456c3 100644 --- a/src/Maestro/Client/Accounts.hs +++ b/src/Maestro/Client/Accounts.hs @@ -1,13 +1,13 @@ module Maestro.Client.Accounts where -import Maestro.API -import Maestro.API.Accounts -import Maestro.Client -import Maestro.Client.Env -import Maestro.Types -import Maestro.Util.Pagination (Page) -import Servant.API.Generic -import Servant.Client +import Maestro.API +import Maestro.API.Accounts +import Maestro.Client.Core +import Maestro.Client.Env +import Maestro.Types +import Maestro.Util.Pagination (Page) +import Servant.API.Generic +import Servant.Client accountsClient :: MaestroEnv -> AccountsAPI (AsClientT IO) accountsClient = fromServant . _accounts . apiClient diff --git a/src/Maestro/Client/Address.hs b/src/Maestro/Client/Address.hs index c14744c..f31d731 100644 --- a/src/Maestro/Client/Address.hs +++ b/src/Maestro/Client/Address.hs @@ -1,14 +1,14 @@ module Maestro.Client.Address where -import Data.Text (Text) -import Maestro.API -import Maestro.API.Address -import Maestro.Client -import Maestro.Client.Env -import Maestro.Types.Address -import Maestro.Util.Pagination (Page) -import Servant.API.Generic -import Servant.Client +import Data.Text (Text) +import Maestro.API +import Maestro.API.Address +import Maestro.Client.Core +import Maestro.Client.Env +import Maestro.Types.Address +import Maestro.Util.Pagination (Page) +import Servant.API.Generic +import Servant.Client addressClient :: MaestroEnv -> AddressAPI (AsClientT IO) addressClient = fromServant . _address . apiClient diff --git a/src/Maestro/Client/Assets.hs b/src/Maestro/Client/Assets.hs index 3459fe4..4091e0e 100644 --- a/src/Maestro/Client/Assets.hs +++ b/src/Maestro/Client/Assets.hs @@ -1,14 +1,14 @@ module Maestro.Client.Assets where -import Maestro.API (_assets) -import Maestro.API.Assets -import Maestro.Client -import Maestro.Client.Env -import Maestro.Types.Assets -import Maestro.Types.Common -import Maestro.Util.Pagination (Page) -import Servant.API.Generic -import Servant.Client +import Maestro.API (_assets) +import Maestro.API.Assets +import Maestro.Client.Core +import Maestro.Client.Env +import Maestro.Types.Assets +import Maestro.Types.Common +import Maestro.Util.Pagination (Page) +import Servant.API.Generic +import Servant.Client assetClient :: MaestroEnv -> AssetsAPI (AsClientT IO) assetClient = fromServant . _assets . apiClient diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs new file mode 100644 index 0000000..6e175ea --- /dev/null +++ b/src/Maestro/Client/Core.hs @@ -0,0 +1,13 @@ +module Maestro.Client.Core + ( + apiClient + ) where + +import Control.Exception (throwIO) +import Maestro.API +import Maestro.Client.Env +import Servant.Client +import Servant.Client.Generic + +apiClient :: MaestroEnv -> MaestroApi (AsClientT IO) +apiClient MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either throwIO pure diff --git a/src/Maestro/Client/Datum.hs b/src/Maestro/Client/Datum.hs index 78a3733..ad865bf 100644 --- a/src/Maestro/Client/Datum.hs +++ b/src/Maestro/Client/Datum.hs @@ -5,7 +5,7 @@ module Maestro.Client.Datum import Data.Text (Text) import Maestro.API (_datum) import Maestro.API.Datum -import Maestro.Client +import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types import Servant.API.Generic diff --git a/src/Maestro/Client/Epochs.hs b/src/Maestro/Client/Epochs.hs index 4606e5e..8e00db1 100644 --- a/src/Maestro/Client/Epochs.hs +++ b/src/Maestro/Client/Epochs.hs @@ -5,7 +5,7 @@ module Maestro.Client.Epochs import Maestro.API (_epochs) import Maestro.API.Epochs -import Maestro.Client +import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types import Servant.API.Generic diff --git a/src/Maestro/Client/General.hs b/src/Maestro/Client/General.hs index d58ebda..806c946 100644 --- a/src/Maestro/Client/General.hs +++ b/src/Maestro/Client/General.hs @@ -7,7 +7,7 @@ module Maestro.Client.General import Maestro.API (_general) import Maestro.API.General -import Maestro.Client +import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types.General import Servant.API.Generic diff --git a/src/Maestro/Client/Pools.hs b/src/Maestro/Client/Pools.hs index c569469..0415ea2 100644 --- a/src/Maestro/Client/Pools.hs +++ b/src/Maestro/Client/Pools.hs @@ -10,15 +10,15 @@ module Maestro.Client.Pools ) where -import Maestro.API -import Maestro.API.Pool -import Maestro.Client -import Maestro.Client.Env -import Maestro.Types.Common -import Maestro.Types.Pool -import Maestro.Util.Pagination (Page) -import Servant.API.Generic -import Servant.Client +import Maestro.API +import Maestro.API.Pool +import Maestro.Client.Core +import Maestro.Client.Env +import Maestro.Types.Common +import Maestro.Types.Pool +import Maestro.Util.Pagination (Page) +import Servant.API.Generic +import Servant.Client poolsClient :: MaestroEnv -> PoolAPI (AsClientT IO) poolsClient = fromServant . _pools . apiClient diff --git a/src/Maestro/Client/Scripts.hs b/src/Maestro/Client/Scripts.hs index df3e9a3..ff30abb 100644 --- a/src/Maestro/Client/Scripts.hs +++ b/src/Maestro/Client/Scripts.hs @@ -5,7 +5,7 @@ module Maestro.Client.Scripts import Data.Text (Text) import Maestro.API (_scripts) import Maestro.API.Scripts -import Maestro.Client +import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types import Servant.API.Generic diff --git a/src/Maestro/Client/Transaction.hs b/src/Maestro/Client/Transaction.hs index 8608876..4a32361 100644 --- a/src/Maestro/Client/Transaction.hs +++ b/src/Maestro/Client/Transaction.hs @@ -7,15 +7,15 @@ module Maestro.Client.Transaction ) where -import qualified Data.ByteString as BS -import Data.Text (Text) -import Maestro.API (_tx) -import Maestro.API.Transaction -import Maestro.Client -import Maestro.Client.Env -import Maestro.Types.Common -import Servant.API.Generic -import Servant.Client +import qualified Data.ByteString as BS +import Data.Text (Text) +import Maestro.API (_tx) +import Maestro.API.Transaction +import Maestro.Client.Core +import Maestro.Client.Env +import Maestro.Types.Common +import Servant.API.Generic +import Servant.Client txClient :: MaestroEnv -> TxAPI (AsClientT IO) txClient = fromServant . _tx . apiClient From 18461dca8b551b0e212bd0fc575db020e3c6789f Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 26 May 2023 19:45:37 +0530 Subject: [PATCH 06/25] Feat 17: Hackage readiness - Proper error responses --- maestro-exe/Main.hs | 10 +++--- maestro-sdk.cabal | 1 + src/Maestro/Client.hs | 2 ++ src/Maestro/Client/Core.hs | 74 ++++++++++++++++++++++++++++++++++++-- src/Maestro/Types.hs | 2 ++ 5 files changed, 81 insertions(+), 8 deletions(-) diff --git a/maestro-exe/Main.hs b/maestro-exe/Main.hs index fb7ffb9..37d0d33 100644 --- a/maestro-exe/Main.hs +++ b/maestro-exe/Main.hs @@ -1,20 +1,20 @@ module Main (main) where -import qualified Data.Text as T +import qualified Data.Text as T import Maestro.Client.Env import Maestro.Run.Datum import Maestro.Run.Epochs import Maestro.Run.Pools import Maestro.Run.Scripts import Maestro.Run.Tx -import System.Environment (getEnv) +import System.Environment (getEnv) main :: IO () main = do - apiId <- maestroId - env <- mkMaestroEnv (T.pack apiId) Preprod + apiKey <- maestroKey + env <- mkMaestroEnv (T.pack apiKey) Preprod runPoolsAPI env runTxApi env runEpochsAPI env @@ -22,4 +22,4 @@ main = do runScriptsAPI env where - maestroId = getEnv "MAESTRO_API_KEY" + maestroKey = getEnv "MAESTRO_API_KEY" diff --git a/maestro-sdk.cabal b/maestro-sdk.cabal index 41c2f05..faa892b 100644 --- a/maestro-sdk.cabal +++ b/maestro-sdk.cabal @@ -89,6 +89,7 @@ library , time , http-client , http-client-tls + , http-types , http-api-data , data-default-class diff --git a/src/Maestro/Client.hs b/src/Maestro/Client.hs index 897d2bf..3465e20 100644 --- a/src/Maestro/Client.hs +++ b/src/Maestro/Client.hs @@ -3,6 +3,7 @@ module Maestro.Client module Maestro.Client.Accounts , module Maestro.Client.Address , module Maestro.Client.Assets + , module Maestro.Client.Core , module Maestro.Client.Datum , module Maestro.Client.Env , module Maestro.Client.Epochs @@ -16,6 +17,7 @@ module Maestro.Client import Maestro.Client.Accounts import Maestro.Client.Address import Maestro.Client.Assets +import Maestro.Client.Core import Maestro.Client.Datum import Maestro.Client.Env import Maestro.Client.Epochs diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index 6e175ea..b327b46 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -1,13 +1,81 @@ +{-# LANGUAGE DeriveAnyClass #-} + module Maestro.Client.Core ( - apiClient + ApiError (..) + , apiClient + , MaestroError (..) + , fromServantClientError ) where -import Control.Exception (throwIO) +import Control.Exception (Exception, throwIO) +import Data.Aeson (decode) +import Data.Text (Text) +import Deriving.Aeson import Maestro.API import Maestro.Client.Env +import Maestro.Types.Common (LowerFirst) +import Network.HTTP.Types import Servant.Client import Servant.Client.Generic +-- | In cases of failure, at times, Maestro returns a JSON object with an error message. +data ApiError = ApiError + { -- | The error type (corresponding to status code). Optional as it is not always present. + _apiErrorError :: !(Maybe Text) + , -- | The error message. + _apiErrorMessage :: !Text + , -- | The HTTP status code. Optional as it is not always present. + _apiErrorCode :: !(Maybe Word) + } + deriving stock (Show, Eq, Generic) + deriving + (FromJSON, ToJSON) + via CustomJSON '[FieldLabelModifier '[StripPrefix "_apiError", LowerFirst]] ApiError + +-- | Maestro errors. +data MaestroError = + MaestroError !Text + -- ^ Other Maestro error. + | MaestroBadRequest !Text + -- ^ 400 status code. + | MaestroApiKeyMissing !Text + -- ^ 401 status code. + | MaestroNotFound + -- ^ 404 status code. + | MaestroUnsupportedMediaType + -- ^ 415 status code. + | MaestroUsageLimitReached + -- ^ 429 status code. + | MaestroInternalError !Text + -- ^ 500 status code. + | ServantClientError !ClientError + -- ^ When `ClientError` is not of form `FailureResponse`. + deriving (Eq, Show, Exception) + +fromServantClientError :: ClientError -> MaestroError +fromServantClientError e = case e of + FailureResponse _bUrl (Response s _ _ body) + | s == status400 -> + MaestroBadRequest (withMessage body) + | s == status401 -> + MaestroApiKeyMissing (withMessage body) + | s == status404 -> + MaestroNotFound + | s == status415 -> + MaestroUnsupportedMediaType + | s == status429 -> + MaestroUsageLimitReached + | s == status500 -> + MaestroInternalError (withMessage body) + | otherwise -> + MaestroError (withMessage body) + _anyOtherFailure -> ServantClientError e + where + withMessage body = + case decode body of + Just (ae :: ApiError) -> _apiErrorMessage ae + Nothing -> mempty + apiClient :: MaestroEnv -> MaestroApi (AsClientT IO) -apiClient MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either throwIO pure +apiClient MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either (throwIO . fromServantClientError) pure diff --git a/src/Maestro/Types.hs b/src/Maestro/Types.hs index e2fa7d0..1490438 100644 --- a/src/Maestro/Types.hs +++ b/src/Maestro/Types.hs @@ -9,6 +9,7 @@ module Maestro.Types , module Maestro.Types.Common , module Maestro.Types.General , module Maestro.Types.Pool + , Page (..) ) where import Maestro.Types.Accounts @@ -19,3 +20,4 @@ import Maestro.Types.Datum import Maestro.Types.Epochs import Maestro.Types.General import Maestro.Types.Pool +import Maestro.Util.Pagination (Page (..)) From edf589ae18aa29e85be9cc12d806a84ec0675f80 Mon Sep 17 00:00:00 2001 From: Piyush thapa Date: Fri, 26 May 2023 20:43:40 +0545 Subject: [PATCH 07/25] fix flake --- Setup.hs | 6 ++++ flake.lock | 89 ++++++++++++++++------------------------------------- flake.nix | 6 +++- nix/hix.nix | 12 +++----- 4 files changed, 42 insertions(+), 71 deletions(-) create mode 100644 Setup.hs diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..6fa548c --- /dev/null +++ b/Setup.hs @@ -0,0 +1,6 @@ +module Main (main) where + +import Distribution.Simple + +main :: IO () +main = defaultMain diff --git a/flake.lock b/flake.lock index 4641635..c0ef77f 100644 --- a/flake.lock +++ b/flake.lock @@ -190,15 +190,12 @@ } }, "flake-utils": { - "inputs": { - "systems": "systems" - }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", "type": "github" }, "original": { @@ -209,16 +206,15 @@ }, "flake-utils_2": { "locked": { - "lastModified": 1679360468, - "narHash": "sha256-LGnza3cfXF10Biw3ZTg0u9o9t7s680Ww200t5KkHTh8=", - "owner": "hamishmack", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", "repo": "flake-utils", - "rev": "e1ea268ff47ad475443dbabcd54744b4e5b9d4f5", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { - "owner": "hamishmack", - "ref": "hkm/nested-hydraJobs", + "owner": "numtide", "repo": "flake-utils", "type": "github" } @@ -292,11 +288,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1683159976, - "narHash": "sha256-bEfhRqQjRvYzaNu8vvHZAa31u+8DNYoRlPpQZPrnqbk=", + "lastModified": 1677630516, + "narHash": "sha256-zSsakVyoSuoJWoMtPtm/HlDuGNQ6Exr7AD062KxHwVw=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "525f5a74cbaacd76cf8e005de2ee99f1d544568a", + "rev": "42c981d6ed46749fde63652865ee6159a207c315", "type": "github" }, "original": { @@ -316,7 +312,6 @@ "flake-utils": "flake-utils_2", "ghc-8.6.5-iohk": "ghc-8.6.5-iohk", "hackage": "hackage", - "hls-1.10": "hls-1.10", "hpc-coveralls": "hpc-coveralls", "hydra": "hydra", "iserv-proxy": "iserv-proxy", @@ -335,11 +330,11 @@ "tullia": "tullia" }, "locked": { - "lastModified": 1683195635, - "narHash": "sha256-1mXduNH0Fc/1jEIhy/UaAp7IOe5XwicoYC2GTkUfsp8=", + "lastModified": 1677631875, + "narHash": "sha256-nLOvHsuUYMNu7btpDV0YlF+9b0ZoSUDC2dZJOCkmxk4=", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "e491253ba13b8145bcaa8f9af6e41b7ff2c96087", + "rev": "cc6bc46e13f74ce50ff9ad2d38194a774c7d1fbd", "type": "github" }, "original": { @@ -348,23 +343,6 @@ "type": "github" } }, - "hls-1.10": { - "flake": false, - "locked": { - "lastModified": 1680000865, - "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", - "owner": "haskell", - "repo": "haskell-language-server", - "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "1.10.0.0", - "repo": "haskell-language-server", - "type": "github" - } - }, "hpc-coveralls": { "flake": false, "locked": { @@ -665,11 +643,11 @@ }, "nixpkgs-2205": { "locked": { - "lastModified": 1682600000, - "narHash": "sha256-ha4BehR1dh8EnXSoE1m/wyyYVvHI9txjW4w5/oxsW5Y=", + "lastModified": 1672580127, + "narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "50fc86b75d2744e1ab3837ef74b53f103a9b55a0", + "rev": "0874168639713f547c05947c76124f78441ea46c", "type": "github" }, "original": { @@ -681,11 +659,11 @@ }, "nixpkgs-2211": { "locked": { - "lastModified": 1682682915, - "narHash": "sha256-haR0u/j/nUvlMloYlaOYq1FMXTvkNHw+wGxc+0qXisM=", + "lastModified": 1675730325, + "narHash": "sha256-uNvD7fzO5hNlltNQUAFBPlcEjNG5Gkbhl/ROiX+GZU4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "09f1b33fcc0f59263137e23e935c1bb03ec920e4", + "rev": "b7ce17b1ebf600a72178f6302c77b6382d09323f", "type": "github" }, "original": { @@ -713,11 +691,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1682656005, - "narHash": "sha256-fYplYo7so1O+rSQ2/aS+SbTPwLTeoUXk4ekKNtSl4P8=", + "lastModified": 1675758091, + "narHash": "sha256-7gFSQbSVAFUHtGCNHPF7mPc5CcqDk9M2+inlVPZSneg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6806b63e824f84b0f0e60b6d660d4ae753de0477", + "rev": "747927516efcb5e31ba03b7ff32f61f6d47e7d87", "type": "github" }, "original": { @@ -819,11 +797,11 @@ "stackage": { "flake": false, "locked": { - "lastModified": 1683072567, - "narHash": "sha256-kDkNkFaSIaEmqrxxZK+d7CGHfXzrL6xHqJsU4QjTNkU=", + "lastModified": 1677543037, + "narHash": "sha256-7CPQZZafTQiw7YL+a2KCamb9a3PU0do9iZKy1AaRkBo=", "owner": "input-output-hk", "repo": "stackage.nix", - "rev": "ed8c3c6c0346de0d62671abafb5977ab48a48266", + "rev": "f4d29fa4403f45541d9f3993523df6027c21fe90", "type": "github" }, "original": { @@ -877,21 +855,6 @@ "type": "github" } }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "tullia": { "inputs": { "nix-nomad": "nix-nomad", diff --git a/flake.nix b/flake.nix index 2c01fa5..0e616ee 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,10 @@ outputs = { self, nixpkgs, flake-utils, haskellNix }: let supportedSystems = [ - "x86_64-linux" "x86_64-darwin" + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" ]; in flake-utils.lib.eachSystem supportedSystems (system: @@ -31,6 +34,7 @@ # This sets the flake to use the IOG nix cache. # Nix should ask for permission before using it, # but remove it here if you do not want it to. + extra-substituters = ["https://cache.iog.io"]; allow-import-from-derivation = "true"; }; } diff --git a/nix/hix.nix b/nix/hix.nix index 33b8182..11a595b 100644 --- a/nix/hix.nix +++ b/nix/hix.nix @@ -10,11 +10,9 @@ # ]); # Tools to include in the development shell - shell = { - tools = { - cabal = "latest"; - hlint = "3.4.1"; - haskell-language-server = { version = "1.8.0.0"; index-state = "2022-12-17T00:00:00Z"; }; - }; - }; + shell.tools.cabal = "latest"; + shell.tools.hlint = "3.4.1"; + shell.tools.haskell-language-server = { version = "1.8.0.0"; index-state = "2022-12-17T00:00:00Z"; }; + + shell.buildInputs = with pkgs; [zlib zlib.dev zlib.out]; } From 400c7f334495827b36f0e6e1a9c1e82af0f694e7 Mon Sep 17 00:00:00 2001 From: Piyush thapa Date: Fri, 26 May 2023 20:44:04 +0545 Subject: [PATCH 08/25] add content-type header in request --- src/Maestro/Client/Env.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maestro/Client/Env.hs b/src/Maestro/Client/Env.hs index 66f4e36..a6a8096 100644 --- a/src/Maestro/Client/Env.hs +++ b/src/Maestro/Client/Env.hs @@ -37,4 +37,4 @@ servantClientEnv token url = do pure $ Servant.mkClientEnv manager baseUrl where - addTokenHeader req = pure $ req {requestHeaders = [("api-key", encodeUtf8 token)]} + addTokenHeader req = pure $ req {requestHeaders = [("api-key", encodeUtf8 token), ("Content-Type", "application/json")]} From 2a363b41c61f4a02113a8dec8024789c90b5c6da Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 26 May 2023 21:18:20 +0530 Subject: [PATCH 09/25] Feat 17: Hackage readiness - Proper error responses --- src/Maestro/API/Address.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Maestro/API/Address.hs b/src/Maestro/API/Address.hs index 04f14f0..352a672 100644 --- a/src/Maestro/API/Address.hs +++ b/src/Maestro/API/Address.hs @@ -9,13 +9,13 @@ import Servant.API.Generic data AddressAPI route = AddressAPI { - _addressesUtxos + _addressesUtxos :: route :- "utxos" :> QueryParam "resolve_datums" Bool :> QueryParam "with_cbor" Bool :> Pagination - :> ReqBody '[JSON][Text] + :> ReqBody '[JSON] [Text] :> Post '[JSON] [AddressUtxo] , _addressUtxo From db00f6bf228e0f248570c02ee354e83b9d2a98cc Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 29 May 2023 16:50:24 +0530 Subject: [PATCH 10/25] Feat 17: Hackage readiness - Change names according to schema + bug fix in Utxo type --- src/Maestro/API/Accounts.hs | 10 ++--- src/Maestro/API/Address.hs | 7 +-- src/Maestro/API/Assets.hs | 14 +++--- src/Maestro/Client/Accounts.hs | 11 +++-- src/Maestro/Client/Address.hs | 7 +-- src/Maestro/Client/Assets.hs | 14 +++--- src/Maestro/Types/Accounts.hs | 34 ++++++++------ src/Maestro/Types/Address.hs | 22 +++------ src/Maestro/Types/Assets.hs | 82 +++++++++++++++++----------------- 9 files changed, 98 insertions(+), 103 deletions(-) diff --git a/src/Maestro/API/Accounts.hs b/src/Maestro/API/Accounts.hs index b96a40e..3a14cd6 100644 --- a/src/Maestro/API/Accounts.hs +++ b/src/Maestro/API/Accounts.hs @@ -11,7 +11,7 @@ data AccountsAPI route = AccountsAPI _account :: route :- Capture "stake_addr" String - :> Get '[JSON] AccountsInfo + :> Get '[JSON] AccountInfo , _accountAddresses :: route @@ -25,7 +25,7 @@ data AccountsAPI route = AccountsAPI :- Capture "stake_addr" String :> "assets" :> Pagination - :> Get '[JSON] [AccountsAssets] + :> Get '[JSON] [Asset] , _accountsHistory :: route @@ -33,20 +33,20 @@ data AccountsAPI route = AccountsAPI :> "history" :> QueryParam "epoch_no" EpochNo :> Pagination - :> Get '[JSON] [AccountsHistory] + :> Get '[JSON] [AccountHistory] , _accountsReward :: route :- Capture "stake_addr" String :> "rewards" :> Pagination - :> Get '[JSON] [AccountsRewards] + :> Get '[JSON] [AccountReward] , _accountsUpdates :: route :- Capture "stake_addr" String :> "updates" :> Pagination - :> Get '[JSON] [AccountsUpdates] + :> Get '[JSON] [AccountUpdate] } deriving (Generic) diff --git a/src/Maestro/API/Address.hs b/src/Maestro/API/Address.hs index 352a672..1397269 100644 --- a/src/Maestro/API/Address.hs +++ b/src/Maestro/API/Address.hs @@ -2,6 +2,7 @@ module Maestro.API.Address where import Data.Text (Text) import Maestro.Types.Address +import Maestro.Types.Common (Utxo) import Maestro.Util.Pagination import Servant.API import Servant.API.Generic @@ -16,7 +17,7 @@ data AddressAPI route = AddressAPI :> QueryParam "with_cbor" Bool :> Pagination :> ReqBody '[JSON] [Text] - :> Post '[JSON] [AddressUtxo] + :> Post '[JSON] [Utxo] , _addressUtxo :: route @@ -25,14 +26,14 @@ data AddressAPI route = AddressAPI :> QueryParam "resolve_datums" Bool :> QueryParam "with_cbor" Bool :> Pagination - :> Get '[JSON] [AddressUtxo] + :> Get '[JSON] [Utxo] , _addressUtxoRefs :: route :- Capture "address" Text :> "utxo_refs" :> Pagination - :> Get '[JSON] [AddressUtxoRef] + :> Get '[JSON] [UtxoRef] , _addressTransactionCount :: route diff --git a/src/Maestro/API/Assets.hs b/src/Maestro/API/Assets.hs index 5e35c3d..53cced3 100644 --- a/src/Maestro/API/Assets.hs +++ b/src/Maestro/API/Assets.hs @@ -12,7 +12,7 @@ data AssetsAPI route = AssetsAPI :- "policy" :> Capture "policy" PolicyId :> Pagination - :> Get '[JSON] [MaestroAssetInfo], + :> Get '[JSON] [AssetInfo], _assetPolicyAddress :: route :- "policy" @@ -26,18 +26,18 @@ data AssetsAPI route = AssetsAPI :> Capture "policy" PolicyId :> "txs" :> Pagination - :> Get '[JSON] [MaestroAssetTx], + :> Get '[JSON] [AssetTx], _assetPolicyUtxos :: route :- "policy" :> Capture "policy" PolicyId :> "utxos" :> Pagination - :> Get '[JSON] [MaestroAssetUtxo], + :> Get '[JSON] [AssetUtxo], _assetDetail :: route :- Capture "asset" AssetId - :> Get '[JSON] MaestroAssetInfo, + :> Get '[JSON] AssetInfo, _assetAddresses :: route :- Capture "asset" AssetId @@ -51,19 +51,19 @@ data AssetsAPI route = AssetsAPI :> QueryParam "from_height" Integer :> Pagination :> QueryParam "order" Order - :> Get '[JSON] [MaestroAssetTx], + :> Get '[JSON] [AssetTx], _assetUpdates :: route :- Capture "asset" AssetId :> "updates" :> Pagination :> QueryParam "order" Order - :> Get '[JSON] [MaestroAssetUpdates], + :> Get '[JSON] [MintingTx], _assetUtxos :: route :- Capture "asset" AssetId :> "utxos" :> Pagination - :> Get '[JSON] [MaestroAssetUtxo] + :> Get '[JSON] [AssetUtxo] } deriving (Generic) diff --git a/src/Maestro/Client/Accounts.hs b/src/Maestro/Client/Accounts.hs index 10456c3..f173344 100644 --- a/src/Maestro/Client/Accounts.hs +++ b/src/Maestro/Client/Accounts.hs @@ -5,27 +5,26 @@ import Maestro.API.Accounts import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types -import Maestro.Util.Pagination (Page) import Servant.API.Generic import Servant.Client accountsClient :: MaestroEnv -> AccountsAPI (AsClientT IO) accountsClient = fromServant . _accounts . apiClient -getAccount :: MaestroEnv -> String -> IO AccountsInfo +getAccount :: MaestroEnv -> String -> IO AccountInfo getAccount = _account . accountsClient listAccountAddresses :: MaestroEnv -> String -> Page -> IO [String] listAccountAddresses = _accountAddresses . accountsClient -listAccountAssets :: MaestroEnv -> String -> Page -> IO [AccountsAssets] +listAccountAssets :: MaestroEnv -> String -> Page -> IO [Asset] listAccountAssets = _accountAssets . accountsClient -listAccountHistory :: MaestroEnv -> String -> Maybe EpochNo -> Page -> IO [AccountsHistory] +listAccountHistory :: MaestroEnv -> String -> Maybe EpochNo -> Page -> IO [AccountHistory] listAccountHistory = _accountsHistory . accountsClient -listAccountRewards :: MaestroEnv -> String -> Page -> IO [AccountsRewards] +listAccountRewards :: MaestroEnv -> String -> Page -> IO [AccountReward] listAccountRewards = _accountsReward . accountsClient -listAccountUpdates :: MaestroEnv -> String -> Page -> IO [AccountsUpdates] +listAccountUpdates :: MaestroEnv -> String -> Page -> IO [AccountUpdate] listAccountUpdates = _accountsUpdates . accountsClient diff --git a/src/Maestro/Client/Address.hs b/src/Maestro/Client/Address.hs index f31d731..83d01f9 100644 --- a/src/Maestro/Client/Address.hs +++ b/src/Maestro/Client/Address.hs @@ -6,6 +6,7 @@ import Maestro.API.Address import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types.Address +import Maestro.Types.Common (Utxo) import Maestro.Util.Pagination (Page) import Servant.API.Generic import Servant.Client @@ -26,7 +27,7 @@ utxosForMultiAddresses :: Page -> -- | List of Address in bech32 format to fetch utxo from [Text] -> - IO [AddressUtxo] + IO [Utxo] utxosForMultiAddresses = _addressesUtxos . addressClient -- | @@ -41,7 +42,7 @@ utxosForAddress :: Maybe Bool -> -- | The pagination attributes Page -> - IO [AddressUtxo] + IO [Utxo] utxosForAddress = _addressUtxo . addressClient -- | @@ -52,7 +53,7 @@ getUtxoRef :: Text -> -- | The pagination attributes Page -> - IO [AddressUtxoRef] + IO [UtxoRef] getUtxoRef = _addressUtxoRefs . addressClient -- | diff --git a/src/Maestro/Client/Assets.hs b/src/Maestro/Client/Assets.hs index 4091e0e..7c6c4ec 100644 --- a/src/Maestro/Client/Assets.hs +++ b/src/Maestro/Client/Assets.hs @@ -22,7 +22,7 @@ listAssetInfoByPolicyId :: PolicyId -> -- | Pagination Page -> - IO [MaestroAssetInfo] + IO [AssetInfo] listAssetInfoByPolicyId = _assetPolicyInfo . assetClient -- | @@ -46,7 +46,7 @@ listTxByPolicyId :: PolicyId -> -- | Pagination Page -> - IO [MaestroAssetTx] + IO [AssetTx] listTxByPolicyId = _assetPolicyTxs . assetClient -- | @@ -58,7 +58,7 @@ listUtxosByPolicyId :: PolicyId -> -- | Pagination Page -> - IO [MaestroAssetUtxo] + IO [AssetUtxo] listUtxosByPolicyId = _assetPolicyUtxos . assetClient -- | @@ -68,7 +68,7 @@ getAssetDetail :: MaestroEnv -> -- | Asset, encoded as concatenation of hex of policy ID and asset name AssetId -> - IO MaestroAssetInfo + IO AssetInfo getAssetDetail = _assetDetail . assetClient -- | @@ -94,7 +94,7 @@ listAssetTx :: -- | The Pagination Page -> Maybe Order -> - IO [MaestroAssetTx] + IO [AssetTx] listAssetTx = _assetTxs . assetClient -- | @@ -108,7 +108,7 @@ listAssetUpdates :: Page -> -- | The order in which the results are sorted (by block height) Maybe Order -> - IO [MaestroAssetUpdates] + IO [MintingTx] listAssetUpdates = _assetUpdates . assetClient -- | @@ -120,5 +120,5 @@ listAssetUtxos :: AssetId -> -- | The Pagination Page -> - IO [MaestroAssetUtxo] + IO [AssetUtxo] listAssetUtxos = _assetUtxos . assetClient diff --git a/src/Maestro/Types/Accounts.hs b/src/Maestro/Types/Accounts.hs index ca1bcb1..9433302 100644 --- a/src/Maestro/Types/Accounts.hs +++ b/src/Maestro/Types/Accounts.hs @@ -1,10 +1,16 @@ -module Maestro.Types.Accounts where +module Maestro.Types.Accounts + ( AccountInfo (..) + , Asset (..) + , AccountHistory (..) + , AccountReward (..) + , AccountUpdate (..) + ) where import Deriving.Aeson -- | Information about an account -data AccountsInfo = AccountsInfo - { _accountInfoDelegatedPool :: !String +data AccountInfo = AccountInfo + { _accountInfoDelegatedPool :: !String , _accountInfoRegistered :: !Bool , _accountInfoRewardsAvailable :: !Integer , _accountInfoStakeAddress :: !String @@ -15,30 +21,30 @@ data AccountsInfo = AccountsInfo } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountInfo", CamelToSnake]] AccountsInfo + via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountInfo", CamelToSnake]] AccountInfo -- | Information about an Account Assets -data AccountsAssets = AccountsAssets - { _accountAssetQuantity :: !Integer - , _accountAssetUnit :: !String +data Asset = Asset + { _assetQuantity :: !Integer + , _assetUnit :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountAsset", CamelToSnake]] AccountsAssets + via CustomJSON '[FieldLabelModifier '[StripPrefix "_asset", CamelToSnake]] Asset -- | Information about an Account Assets -data AccountsHistory = AccountsHistory +data AccountHistory = AccountHistory { _accountHistoryActiveStake :: !Integer , _accountHistoryEpochNo :: !Integer , _accountHistoryPoolId :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountHistory", CamelToSnake]] AccountsHistory + via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountHistory", CamelToSnake]] AccountHistory -- | Information about an Account Assets -data AccountsRewards = AccountsRewards +data AccountReward = AccountReward { _accountRewardAmount :: !Integer , _accountRewardEarnedEpoch :: !Integer , _accountRewardPoolId :: !String @@ -47,10 +53,10 @@ data AccountsRewards = AccountsRewards } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountReward", CamelToSnake]] AccountsRewards + via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountReward", CamelToSnake]] AccountReward -- | Information about an Account Assets -data AccountsUpdates = AccountsUpdates +data AccountUpdate = AccountUpdate { _accountUpdateAbsSlot :: !Integer , _accountUpdateAction :: !String , _accountUpdateEpoch :: !Integer @@ -58,4 +64,4 @@ data AccountsUpdates = AccountsUpdates } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountUpdate", CamelToSnake]] AccountsUpdates + via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountUpdate", CamelToSnake]] AccountUpdate diff --git a/src/Maestro/Types/Address.hs b/src/Maestro/Types/Address.hs index b99d0d3..34e3de9 100644 --- a/src/Maestro/Types/Address.hs +++ b/src/Maestro/Types/Address.hs @@ -1,30 +1,18 @@ module Maestro.Types.Address where import Deriving.Aeson -import Maestro.Types.Common (DatumOption, MaestroAsset, Script) -data AddressUtxo = AddressUtxo - { _addressUtxoIndex :: !Int - , _addressUtxoTxHash :: !String - , _addressUtxoAssets :: ![MaestroAsset] - , _addressUtxoDatum :: !(Maybe DatumOption) - , _addressUtxoReferenceScript :: !(Maybe Script) - } - deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressUtxo", CamelToSnake]] AddressUtxo - -newtype AddressTxCount = AddressTxCount +newtype AddressTxCount = AddressTxCount { _addressTxCount :: Int } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressTx", CamelToSnake]] AddressTxCount -data AddressUtxoRef = AddressUtxoRef - { _addressUtxoRefIndex :: !Int - , _addressUtxoRefTxHash :: !String +data UtxoRef = UtxoRef + { _utxoRefIndex :: !Int + , _utxoRefTxHash :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressUtxoRef", CamelToSnake]] AddressUtxoRef + via CustomJSON '[FieldLabelModifier '[StripPrefix "_utxoRef", CamelToSnake]] UtxoRef diff --git a/src/Maestro/Types/Assets.hs b/src/Maestro/Types/Assets.hs index bc6aa96..3b0dce9 100644 --- a/src/Maestro/Types/Assets.hs +++ b/src/Maestro/Types/Assets.hs @@ -4,69 +4,69 @@ import qualified Data.Aeson as Aeson import Deriving.Aeson import Maestro.Types.Common (MaestroAsset) -data MaestroTokenRegistryMetadata = MaestroTokenRegistryMetadata - { _maeTokenRegDecimals :: !Integer - , _maeTokenRegDescription :: !String - , _maeTokenRegLogo :: !String - , _maeTokenRegName :: !String - , _maeTokenRegTicker :: !String - , _maeTokenRegUrl :: !String +data TokenRegistryMetadata = TokenRegistryMetadata + { _tokenRegMetDecimals :: !Integer + , _tokenRegMetDescription :: !String + , _tokenRegMetLogo :: !String + , _tokenRegMetName :: !String + , _tokenRegMetTicker :: !String + , _tokenRegMetUrl :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeTokenReg", CamelToSnake]] MaestroTokenRegistryMetadata + via CustomJSON '[FieldLabelModifier '[StripPrefix "_tokenRegMet", CamelToSnake]] TokenRegistryMetadata -newtype MaestroAssetStandard = MaestroAssetStandard - { _maeAssetStdCip25Metadata :: Maybe Aeson.Value +newtype AssetStandards = AssetStandards + { _assetStandardsCip25Metadata :: Maybe Aeson.Value } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeAssetStd", CamelToSnake]] MaestroAssetStandard + via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetStandards", CamelToSnake]] AssetStandards -data MaestroAssetInfo = MaestroAssetInfo - { _maeAssetInfoAssetName :: !String - , _maeAssetInfoAssetNameAscii :: !String - , _maeAssetInfoAssetStandards :: !MaestroAssetStandard - , _maeAssetInfoBurnTxCount :: !Integer - , _maeAssetInfoFingerprint :: !String - , _maeAssetInfoFirstMintTime :: !Integer - , _maeAssetInfoFirstMintTx :: !String - , _maeAssetInfoLatestMintTxMetadata :: !(Maybe Aeson.Value) - , _maeAssetInfoMintTxCount :: !Integer - , _maeAssetInfoTokenRegistryMetadata :: !(Maybe MaestroTokenRegistryMetadata) - , _maeAssetInfoTotalSupply :: !Integer +data AssetInfo = AssetInfo + { _assetInfoAssetName :: !String + , _assetInfoAssetNameAscii :: !String + , _assetInfoAssetStandards :: !AssetStandards + , _assetInfoBurnTxCount :: !Integer + , _assetInfoFingerprint :: !String + , _assetInfoFirstMintTime :: !Integer + , _assetInfoFirstMintTx :: !String + , _assetInfoLatestMintTxMetadata :: !(Maybe Aeson.Value) + , _assetInfoMintTxCount :: !Integer + , _assetInfoTokenRegistryMetadata :: !(Maybe TokenRegistryMetadata) + , _assetInfoTotalSupply :: !Integer } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeAssetInfo", CamelToSnake]] MaestroAssetInfo + via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetInfo", CamelToSnake]] AssetInfo -data MaestroAssetTx = MaestroAssetTx - { _maeAssetBlockHeight :: !Integer - , _maeAssetEpochNo :: !Integer - , _maeAssetTxHash :: !String +data AssetTx = AssetTx + { _assetTxBlockHeight :: !Integer + , _assetTxEpochNo :: !Integer + , _assetTxTxHash :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeAsset", CamelToSnake]] MaestroAssetTx + via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetTx", CamelToSnake]] AssetTx -data MaestroAssetUtxo = MaestroAssetUtxo - { _maeAssetUtxoAddress :: !String - , _maeAssetUtxoAssets :: !(Maybe [MaestroAsset]) - , _maeAssetUtxoIndex :: !Int - , _maeAssetUtxoTxHash :: !String +data AssetUtxo = AssetUtxo + { _assetUtxoAddress :: !String + , _assetUtxoAssets :: !(Maybe [MaestroAsset]) + , _assetUtxoIndex :: !Int + , _assetUtxoTxHash :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeAssetUtxo", CamelToSnake]] MaestroAssetUtxo + via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetUtxo", CamelToSnake]] AssetUtxo -data MaestroAssetUpdates = MaestroAssetUpdates - { _maeAssetUpdateBlockTimestamp :: !Integer - , _maeAssetUpdateMetadata :: !(Maybe Aeson.Value) - , _maeAssetUpdateMintAmount :: !Integer - , _maeAssetUpdateTxHash :: !String +data MintingTx = MintingTx + { _mintingTxBlockTimestamp :: !Integer + , _mintingTxMetadata :: !(Maybe Aeson.Value) + , _mintingTxMintAmount :: !Integer + , _mintingTxTxHash :: !String } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maeAssetUpdate", CamelToSnake]] MaestroAssetUpdates + via CustomJSON '[FieldLabelModifier '[StripPrefix "_mintingTx", CamelToSnake]] MintingTx From acb92bc7101a0536cdbef250573d0beae75e0be0 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 29 May 2023 19:21:59 +0530 Subject: [PATCH 11/25] Feat 17: Hackage readiness - More instances for number wrappers --- maestro-exe/Maestro/Run/Pools.hs | 1 - src/Maestro/Types/Common.hs | 8 +- src/Maestro/Types/Epochs.hs | 3 +- src/Maestro/Types/General.hs | 2 +- src/Maestro/Types/Pool.hs | 144 +++++++++++++++---------------- 5 files changed, 79 insertions(+), 79 deletions(-) diff --git a/maestro-exe/Maestro/Run/Pools.hs b/maestro-exe/Maestro/Run/Pools.hs index 68831b5..c034bf5 100644 --- a/maestro-exe/Maestro/Run/Pools.hs +++ b/maestro-exe/Maestro/Run/Pools.hs @@ -3,7 +3,6 @@ module Maestro.Run.Pools where import Maestro.Client.Env import Maestro.Client.Pools import Maestro.Types -import Maestro.Util.Pagination poolId :: Bech32StringOf PoolId poolId = "pool1rkfs9glmfva3jd0q9vnlqvuhnrflpzj4l07u6sayfx5k7d788us" diff --git a/src/Maestro/Types/Common.hs b/src/Maestro/Types/Common.hs index adf887f..3333977 100644 --- a/src/Maestro/Types/Common.hs +++ b/src/Maestro/Types/Common.hs @@ -41,8 +41,8 @@ data Tx -- | Index of UTxO in a transaction outputs. newtype TxIndex = TxIndex Natural - deriving stock (Eq, Show, Generic) - deriving newtype (FromHttpApiData, ToHttpApiData, FromJSON, ToJSON) + deriving stock (Eq, Ord, Show, Generic) + deriving newtype (Num, Enum, Real, Integral, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON) -- | Minting policy ID. newtype PolicyId = PolicyId Text @@ -74,8 +74,8 @@ newtype AbsoluteSlot = AbsoluteSlot {unAbsoluteSlot :: Natural} -- | Block Height newtype BlockHeight = BlockHeight {unBlockHeight :: Natural} - deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) + deriving stock (Show, Eq, Ord, Generic) + deriving newtype (Num, Enum, Real, Integral, FromJSON, ToJSON) -- | Hash of the block. newtype BlockHash = BlockHash {unBlockHash :: String} diff --git a/src/Maestro/Types/Epochs.hs b/src/Maestro/Types/Epochs.hs index 06797cd..2c01bdd 100644 --- a/src/Maestro/Types/Epochs.hs +++ b/src/Maestro/Types/Epochs.hs @@ -11,7 +11,8 @@ import Numeric.Natural (Natural) import Text.Read (readMaybe) -- | Sum of all the fees within the epoch in lovelaces. -newtype EpochInfoFees = EpochInfoFees Natural deriving newtype (Eq, Show) +newtype EpochInfoFees = EpochInfoFees Natural + deriving newtype (Eq, Ord, Show, Num, Enum, Real, Integral) instance ToJSON EpochInfoFees where toEncoding = toEncoding . show diff --git a/src/Maestro/Types/General.hs b/src/Maestro/Types/General.hs index b5cc003..7f7580d 100644 --- a/src/Maestro/Types/General.hs +++ b/src/Maestro/Types/General.hs @@ -52,7 +52,7 @@ newtype SystemStart = SystemStart { _systemStartTime :: LocalTime } -- | The 0-based index for the Ourboros time slot. newtype SlotNo = SlotNo {unSlotNo :: Word64} deriving stock (Eq, Ord, Show, Generic) - deriving newtype (Enum, Bounded, Num, ToJSON, FromJSON) + deriving newtype (Num, Bounded, Enum, Real, Integral, FromJSON, ToJSON) -- | Network era summary. data EraSummary = EraSummary diff --git a/src/Maestro/Types/Pool.hs b/src/Maestro/Types/Pool.hs index a117cb0..0b5a259 100644 --- a/src/Maestro/Types/Pool.hs +++ b/src/Maestro/Types/Pool.hs @@ -14,11 +14,11 @@ module Maestro.Types.Pool ) where -import Data.Text (Text) -import Data.Time.Clock.POSIX (POSIXTime) -import Deriving.Aeson -import GHC.Natural (Natural) -import Maestro.Types.Common +import Data.Text (Text) +import Data.Time.Clock.POSIX (POSIXTime) +import Deriving.Aeson +import GHC.Natural (Natural) +import Maestro.Types.Common data PoolId @@ -34,7 +34,7 @@ data PoolUpdateTx data Pool = Pool { _plPoolIdBech32 :: !(Bech32StringOf PoolId), - _plTicker :: !(Maybe String) + _plTicker :: !(Maybe String) } deriving stock (Show, Eq, Generic) deriving @@ -43,17 +43,17 @@ data Pool = Pool data PoolBlock = PoolBlock { -- | Absolute slot of the block - _poolBlkAbsSlot :: !(Maybe AbsoluteSlot), + _poolBlkAbsSlot :: !(Maybe AbsoluteSlot), -- | The Block Hash - _poolBlkBlockHash :: !BlockHash, + _poolBlkBlockHash :: !BlockHash, -- | The Block Height i.e Block Number _poolBlkBlockHeight :: !BlockHeight, -- | UNIX timestamp when the block was mined - _poolBlkBlockTime :: !POSIXTime, + _poolBlkBlockTime :: !POSIXTime, -- | Epoch number - _poolBlkEpochNo :: !(Maybe EpochNo), + _poolBlkEpochNo :: !(Maybe EpochNo), -- | Epoch Slot - _poolBlkEpochSlot :: !(Maybe EpochSize) + _poolBlkEpochSlot :: !(Maybe EpochSize) } deriving stock (Show, Eq, Generic) deriving @@ -63,13 +63,13 @@ data PoolBlock = PoolBlock -- | Information summary of a delegator data DelegatorInfo = DelegatorInfo { -- | Epoch at which the delegation becomes active - _delegatorActiveEpochNo :: !(Maybe EpochNo), + _delegatorActiveEpochNo :: !(Maybe EpochNo), -- | Delegator live stake - _delegatorAmount :: !(Maybe Natural), + _delegatorAmount :: !(Maybe Natural), -- | Transaction hash relating to the most recent delegation _delegatorLatestDelegationTxHash :: !(Maybe TxHash), -- | Bech32 encoded stake address (reward address) - _delegatorStakeAddress :: !(Maybe (Bech32StringOf Stake)) + _delegatorStakeAddress :: !(Maybe (Bech32StringOf Stake)) } deriving stock (Show, Eq, Generic) deriving @@ -77,33 +77,33 @@ data DelegatorInfo = DelegatorInfo via CustomJSON '[FieldLabelModifier '[StripPrefix "_delegator", CamelToSnake]] DelegatorInfo newtype ActiveStake = ActiveStake {unActiveStake :: Natural} - deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) + deriving stock (Show, Eq, Ord, Generic) + deriving newtype (Num, Enum, Real, Integral, FromJSON, ToJSON) -- | Per-epoch history of a stake pool data PoolHistory = PoolHistory { -- | Active stake in the epoch - _poolHstActiveStake :: !(Maybe ActiveStake), + _poolHstActiveStake :: !(Maybe ActiveStake), -- | Pool active stake as percentage of total active stake _poolHstActiveStakePct :: !(Maybe String), -- | Blocks created in the epoch - _poolHstBlockCnt :: !(Maybe Natural), + _poolHstBlockCnt :: !(Maybe Natural), -- | Total rewards earned by pool delegators for the epoch - _poolHstDelegRewards :: !Natural, + _poolHstDelegRewards :: !Natural, -- | Total Delegators in the epoch - _poolHstDelegatorCnt :: !(Maybe Natural), + _poolHstDelegatorCnt :: !(Maybe Natural), -- | The Epoch number - _poolHstEpochNo :: !EpochNo, + _poolHstEpochNo :: !EpochNo, -- | Annual return percentage for delegators for the epoch - _poolHstEpochRos :: !String, + _poolHstEpochRos :: !String, -- | Pool fixed cost - _poolHstFixedCost :: !Natural, + _poolHstFixedCost :: !Natural, -- | Pool margin - _poolHstMargin :: !(Maybe Double), + _poolHstMargin :: !(Maybe Double), -- | Fees collected for the epoch - _poolHstPoolFees :: !Natural, + _poolHstPoolFees :: !Natural, -- | Pool saturation percent - _poolHstSaturationPct :: !(Maybe String) + _poolHstSaturationPct :: !(Maybe String) } deriving stock (Show, Eq, Generic) deriving @@ -111,11 +111,11 @@ data PoolHistory = PoolHistory via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolHst", CamelToSnake]] PoolHistory data PoolRelayInfo = PoolRelayInfo - { _poolRelInfoDns :: !(Maybe String), + { _poolRelInfoDns :: !(Maybe String), _poolRelInfoIpv4 :: !(Maybe String), _poolRelInfoIpv6 :: !(Maybe String), _poolRelInfoPort :: !(Maybe Int), - _poolRelInfoSrv :: !(Maybe String) + _poolRelInfoSrv :: !(Maybe String) } deriving stock (Show, Eq, Generic) deriving @@ -127,11 +127,11 @@ data PoolMetaJson = PoolMetaJson { -- | Pool description _poolMetaJsonDescription :: !(Maybe Text), -- | Pool home page URL - _poolMetaJsonHomepage :: !(Maybe String), + _poolMetaJsonHomepage :: !(Maybe String), -- | Pool name - _poolMetaJsonName :: !String, + _poolMetaJsonName :: !String, -- | Pool ticker symbol - _poolMetaJsonTicker :: !(Maybe String) + _poolMetaJsonTicker :: !(Maybe String) } deriving stock (Show, Eq, Generic) deriving @@ -141,11 +141,11 @@ data PoolMetaJson = PoolMetaJson -- | Metadata associated with a stake pool data PoolMetadata = PoolMetadata { -- | Hash of the pool metadata - _poolMetadataMetaHash :: !(Maybe String), + _poolMetadataMetaHash :: !(Maybe String), -- | JSON metadata associated with a stake pool - _poolMetadataMetaJson :: !(Maybe PoolMetaJson), + _poolMetadataMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolMetadataMetaUrl :: !(Maybe String), + _poolMetadataMetaUrl :: !(Maybe String), -- | Bech32 encoded pool ID _poolMetadataPoolIdBech32 :: !(Bech32StringOf PoolId) } @@ -156,53 +156,53 @@ data PoolMetadata = PoolMetadata data PoolInfo = PoolInfo { -- | Epoch when the update takes effect - _poolInfActiveEpochNo :: !EpochNo, + _poolInfActiveEpochNo :: !EpochNo, -- | Active stake - _poolInfActiveStake :: !(Maybe Natural), + _poolInfActiveStake :: !(Maybe Natural), -- | Number of blocks created - _poolInfBlockCount :: !(Maybe Natural), + _poolInfBlockCount :: !(Maybe Natural), -- | Pool fixed cost - _poolInfFixedCost :: !Natural, + _poolInfFixedCost :: !Natural, -- | Number of current delegators _poolInfLiveDelegators :: !Natural, -- | Account balance of pool owners - _poolInfLivePledge :: !(Maybe Natural), + _poolInfLivePledge :: !(Maybe Natural), -- | Live saturation _poolInfLiveSaturation :: !(Maybe String), -- | Live stake - _poolInfLiveStake :: !(Maybe Integer), + _poolInfLiveStake :: !(Maybe Integer), -- | Pool margin - _poolInfMargin :: !Double, + _poolInfMargin :: !Double, -- | Hash of the pool metadata - _poolInfMetaHash :: !(Maybe String), + _poolInfMetaHash :: !(Maybe String), -- | JSON metadata associated with a stake pool - _poolInfMetaJson :: !(Maybe PoolMetaJson), + _poolInfMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolInfMetaUrl :: !(Maybe String), + _poolInfMetaUrl :: !(Maybe String), -- | Pool operational certificate - _poolInfOpCert :: !(Maybe String), + _poolInfOpCert :: !(Maybe String), -- | Operational certificate counter - _poolInfOpCertCounter :: !(Maybe Integer), + _poolInfOpCertCounter :: !(Maybe Integer), -- | List of stake keys which control the pool - _poolInfOwners :: ![String], + _poolInfOwners :: ![String], -- | Pool pledge - _poolInfPledge :: !Integer, + _poolInfPledge :: !Integer, -- | Bech32 encoded pool ID - _poolInfPoolIdBech32 :: !(Bech32StringOf PoolId), + _poolInfPoolIdBech32 :: !(Bech32StringOf PoolId), -- | Hex encoded pool ID - _poolInfPoolIdHex :: !(HexStringOf PoolId), + _poolInfPoolIdHex :: !(HexStringOf PoolId), -- | Status of the pool - _poolInfPoolStatus :: !(Maybe String), + _poolInfPoolStatus :: !(Maybe String), -- | Stake pool relay - _poolInfRelays :: ![PoolRelayInfo], + _poolInfRelays :: ![PoolRelayInfo], -- | Epoch at which the pool will be retired - _poolInfRetiringEpoch :: !(Maybe EpochNo), + _poolInfRetiringEpoch :: !(Maybe EpochNo), -- | Reward address associated with the pool - _poolInfRewardAddr :: !(Maybe (Bech32StringOf PoolId)), + _poolInfRewardAddr :: !(Maybe (Bech32StringOf PoolId)), -- | Pool stake share - _poolInfSigma :: !(Maybe String), + _poolInfSigma :: !(Maybe String), -- | VRF key hash - _poolInfVrfKeyHash :: !(HashStringOf VrfKey) + _poolInfVrfKeyHash :: !(HashStringOf VrfKey) } deriving stock (Show, Eq, Generic) deriving @@ -212,7 +212,7 @@ data PoolInfo = PoolInfo -- | Relay declared by a stake pool data PoolRelay = PoolRelay { _poolRelPoolIdBech32 :: !(Bech32StringOf PoolId), - _poolRelRelays :: ![PoolRelayInfo] + _poolRelRelays :: ![PoolRelayInfo] } deriving stock (Show, Eq, Generic) deriving @@ -224,37 +224,37 @@ data PoolUpdates = PoolUpdates { -- | Epoch when the update takes effect _poolUpdateActiveEpochNo :: !EpochNo, -- | UNIX timestamp of the block containing the transaction - _poolUpdateBlockTime :: !(Maybe POSIXTime), + _poolUpdateBlockTime :: !(Maybe POSIXTime), -- | Pool fixed cost - _poolUpdateFixedCost :: !Natural, + _poolUpdateFixedCost :: !Natural, -- | Pool margin - _poolUpdateMargin :: !Double, + _poolUpdateMargin :: !Double, -- | Hash of the pool metadata - _poolUpdateMetaHash :: !(Maybe (HashStringOf PoolMeta)), + _poolUpdateMetaHash :: !(Maybe (HashStringOf PoolMeta)), -- | JSON metadata associated with a stake pool - _poolUpdateMetaJson :: !(Maybe PoolMetaJson), + _poolUpdateMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolUpdateMetaUrl :: !(Maybe String), + _poolUpdateMetaUrl :: !(Maybe String), -- | List of stake keys which control the pool - _poolUpdateOwners :: ![String], + _poolUpdateOwners :: ![String], -- | Pool pledge - _poolUpdatePledge :: !Integer, + _poolUpdatePledge :: !Integer, -- | Bech32 encoded pool ID - _poolUpdatePoolIdBech32 :: !(Bech32StringOf PoolId), + _poolUpdatePoolIdBech32 :: !(Bech32StringOf PoolId), -- | Hex encoded pool ID - _poolUpdatePoolIdHex :: !(HexStringOf PoolId), + _poolUpdatePoolIdHex :: !(HexStringOf PoolId), -- | Status of the pool - _poolUpdatePoolStatus :: !(Maybe String), + _poolUpdatePoolStatus :: !(Maybe String), -- | Stake pool relay - _poolUpdateRelays :: ![PoolRelayInfo], + _poolUpdateRelays :: ![PoolRelayInfo], -- | Epoch at which the pool will be retired _poolUpdateRetiringEpoch :: !(Maybe String), -- | Reward address associated with the pool - _poolUpdateRewardAddr :: !(Maybe (Bech32StringOf Reward)), + _poolUpdateRewardAddr :: !(Maybe (Bech32StringOf Reward)), -- | Transaction hash for the transaction which contained the update - _poolUpdateTxHash :: !(HashStringOf PoolUpdateTx), + _poolUpdateTxHash :: !(HashStringOf PoolUpdateTx), -- | VRF key hash - _poolUpdateVrfKeyHash :: !(HashStringOf VrfKey) + _poolUpdateVrfKeyHash :: !(HashStringOf VrfKey) } deriving stock (Show, Eq, Generic) deriving From 26dc846195493347af5dec8094f88ac63d0af83b Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 29 May 2023 21:17:44 +0530 Subject: [PATCH 12/25] Feat 17: Hackage readiness - allPages + new place for pagination utilities --- maestro-exe/Maestro/Run/Datum.hs | 3 +-- maestro-exe/Maestro/Run/Epochs.hs | 3 +-- maestro-exe/Maestro/Run/Pools.hs | 3 +-- maestro-exe/Maestro/Run/Scripts.hs | 3 +-- maestro-exe/Maestro/Run/Tx.hs | 3 +-- maestro-sdk.cabal | 3 +-- src/Maestro/API/Accounts.hs | 2 +- src/Maestro/API/Address.hs | 2 +- src/Maestro/API/Assets.hs | 2 +- src/Maestro/API/Pool.hs | 2 +- src/Maestro/Client/Address.hs | 5 ++--- src/Maestro/Client/Assets.hs | 3 +-- src/Maestro/Client/Core.hs | 10 ++++++---- src/Maestro/{Util => Client/Core}/Pagination.hs | 17 +++++++++++++++-- src/Maestro/Client/Pools.hs | 1 - src/Maestro/Types.hs | 2 -- 16 files changed, 34 insertions(+), 30 deletions(-) rename src/Maestro/{Util => Client/Core}/Pagination.hs (67%) diff --git a/maestro-exe/Maestro/Run/Datum.hs b/maestro-exe/Maestro/Run/Datum.hs index a96256b..5d7c855 100644 --- a/maestro-exe/Maestro/Run/Datum.hs +++ b/maestro-exe/Maestro/Run/Datum.hs @@ -1,7 +1,6 @@ module Maestro.Run.Datum where -import Maestro.Client.Datum -import Maestro.Client.Env +import Maestro.Client import Text.Printf (printf) runDatumAPI :: MaestroEnv -> IO () diff --git a/maestro-exe/Maestro/Run/Epochs.hs b/maestro-exe/Maestro/Run/Epochs.hs index e25ac0f..2a08084 100644 --- a/maestro-exe/Maestro/Run/Epochs.hs +++ b/maestro-exe/Maestro/Run/Epochs.hs @@ -1,7 +1,6 @@ module Maestro.Run.Epochs where -import Maestro.Client.Env -import Maestro.Client.Epochs +import Maestro.Client runEpochsAPI :: MaestroEnv -> IO () runEpochsAPI mEnv = do diff --git a/maestro-exe/Maestro/Run/Pools.hs b/maestro-exe/Maestro/Run/Pools.hs index c034bf5..09de9eb 100644 --- a/maestro-exe/Maestro/Run/Pools.hs +++ b/maestro-exe/Maestro/Run/Pools.hs @@ -1,7 +1,6 @@ module Maestro.Run.Pools where -import Maestro.Client.Env -import Maestro.Client.Pools +import Maestro.Client import Maestro.Types poolId :: Bech32StringOf PoolId diff --git a/maestro-exe/Maestro/Run/Scripts.hs b/maestro-exe/Maestro/Run/Scripts.hs index a451b51..ad64052 100644 --- a/maestro-exe/Maestro/Run/Scripts.hs +++ b/maestro-exe/Maestro/Run/Scripts.hs @@ -1,7 +1,6 @@ module Maestro.Run.Scripts where -import Maestro.Client.Env -import Maestro.Client.Scripts +import Maestro.Client import Text.Printf (printf) runScriptsAPI :: MaestroEnv -> IO () diff --git a/maestro-exe/Maestro/Run/Tx.hs b/maestro-exe/Maestro/Run/Tx.hs index f88aa00..1a7df5a 100644 --- a/maestro-exe/Maestro/Run/Tx.hs +++ b/maestro-exe/Maestro/Run/Tx.hs @@ -1,7 +1,6 @@ module Maestro.Run.Tx where -import Maestro.Client.Env -import Maestro.Client.Transaction +import Maestro.Client import Maestro.Types txHash :: HashStringOf Tx diff --git a/maestro-sdk.cabal b/maestro-sdk.cabal index faa892b..d516d17 100644 --- a/maestro-sdk.cabal +++ b/maestro-sdk.cabal @@ -51,6 +51,7 @@ library Maestro.Client Maestro.Client.Core + Maestro.Client.Core.Pagination Maestro.Client.Datum Maestro.Client.Env Maestro.Client.Epochs @@ -72,8 +73,6 @@ library Maestro.Types.General Maestro.Types.Pool - Maestro.Util.Pagination - -- other-modules: -- other-extensions: build-depends: diff --git a/src/Maestro/API/Accounts.hs b/src/Maestro/API/Accounts.hs index 3a14cd6..f477c74 100644 --- a/src/Maestro/API/Accounts.hs +++ b/src/Maestro/API/Accounts.hs @@ -2,7 +2,7 @@ module Maestro.API.Accounts where import Maestro.Types.Accounts import Maestro.Types.Common -import Maestro.Util.Pagination +import Maestro.Client.Core.Pagination import Servant.API import Servant.API.Generic diff --git a/src/Maestro/API/Address.hs b/src/Maestro/API/Address.hs index 1397269..362a175 100644 --- a/src/Maestro/API/Address.hs +++ b/src/Maestro/API/Address.hs @@ -3,7 +3,7 @@ module Maestro.API.Address where import Data.Text (Text) import Maestro.Types.Address import Maestro.Types.Common (Utxo) -import Maestro.Util.Pagination +import Maestro.Client.Core.Pagination import Servant.API import Servant.API.Generic diff --git a/src/Maestro/API/Assets.hs b/src/Maestro/API/Assets.hs index 53cced3..d8b2250 100644 --- a/src/Maestro/API/Assets.hs +++ b/src/Maestro/API/Assets.hs @@ -2,7 +2,7 @@ module Maestro.API.Assets where import Maestro.Types.Assets import Maestro.Types.Common -import Maestro.Util.Pagination +import Maestro.Client.Core.Pagination import Servant.API import Servant.API.Generic diff --git a/src/Maestro/API/Pool.hs b/src/Maestro/API/Pool.hs index 6fe411f..f217152 100644 --- a/src/Maestro/API/Pool.hs +++ b/src/Maestro/API/Pool.hs @@ -1,7 +1,7 @@ module Maestro.API.Pool where import Maestro.Types -import Maestro.Util.Pagination +import Maestro.Client.Core.Pagination import Servant.API import Servant.API.Generic diff --git a/src/Maestro/Client/Address.hs b/src/Maestro/Client/Address.hs index 83d01f9..8d0d76e 100644 --- a/src/Maestro/Client/Address.hs +++ b/src/Maestro/Client/Address.hs @@ -1,13 +1,12 @@ module Maestro.Client.Address where -import Data.Text (Text) +import Data.Text (Text) import Maestro.API import Maestro.API.Address import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types.Address -import Maestro.Types.Common (Utxo) -import Maestro.Util.Pagination (Page) +import Maestro.Types.Common (Utxo) import Servant.API.Generic import Servant.Client diff --git a/src/Maestro/Client/Assets.hs b/src/Maestro/Client/Assets.hs index 7c6c4ec..e1a1789 100644 --- a/src/Maestro/Client/Assets.hs +++ b/src/Maestro/Client/Assets.hs @@ -1,12 +1,11 @@ module Maestro.Client.Assets where -import Maestro.API (_assets) +import Maestro.API (_assets) import Maestro.API.Assets import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types.Assets import Maestro.Types.Common -import Maestro.Util.Pagination (Page) import Servant.API.Generic import Servant.Client diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index b327b46..e09bae1 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -6,15 +6,17 @@ module Maestro.Client.Core , apiClient , MaestroError (..) , fromServantClientError + , module Maestro.Client.Core.Pagination ) where -import Control.Exception (Exception, throwIO) -import Data.Aeson (decode) -import Data.Text (Text) +import Control.Exception (Exception, throwIO) +import Data.Aeson (decode) +import Data.Text (Text) import Deriving.Aeson import Maestro.API +import Maestro.Client.Core.Pagination import Maestro.Client.Env -import Maestro.Types.Common (LowerFirst) +import Maestro.Types.Common (LowerFirst) import Network.HTTP.Types import Servant.Client import Servant.Client.Generic diff --git a/src/Maestro/Util/Pagination.hs b/src/Maestro/Client/Core/Pagination.hs similarity index 67% rename from src/Maestro/Util/Pagination.hs rename to src/Maestro/Client/Core/Pagination.hs index 36bc35d..aeffc0f 100644 --- a/src/Maestro/Util/Pagination.hs +++ b/src/Maestro/Client/Core/Pagination.hs @@ -5,8 +5,9 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -module Maestro.Util.Pagination where +module Maestro.Client.Core.Pagination where +import Data.Default.Class import Data.Proxy (Proxy (..)) import Servant.API (QueryParam, (:>)) import Servant.Client.Core (Client, HasClient, clientWithRoute, @@ -22,12 +23,25 @@ data Page = Page maxPageResult :: Int maxPageResult = 100 +instance Default Page where + def = Page maxPageResult 1 page :: Int -> Page page n | n >= 1 = Page maxPageResult n | otherwise = error "Page number not in range [1..]" +-- Utility for querying all results from a paged endpoint. +allPages :: (Monad m, Foldable t, Monoid (t a)) => (Page -> m (t a)) -> m (t a) +allPages act = fetch 1 + where + fetch pageNo = do + xs <- act $ Page maxPageResult pageNo + if length xs < maxPageResult then + pure xs + else do + next <- fetch $ pageNo + 1 + pure $ xs <> next -- Note: In case of list, concatenation takes linear time in the number of elements of the first list, thus, `xs` should come before. data Pagination @@ -36,7 +50,6 @@ type PaginationApi api = :> QueryParam "page" Int :> api - instance HasClient m api => HasClient m (Pagination :> api) where type Client m (Pagination :> api) = Page -> Client m api diff --git a/src/Maestro/Client/Pools.hs b/src/Maestro/Client/Pools.hs index 0415ea2..41b2a73 100644 --- a/src/Maestro/Client/Pools.hs +++ b/src/Maestro/Client/Pools.hs @@ -16,7 +16,6 @@ import Maestro.Client.Core import Maestro.Client.Env import Maestro.Types.Common import Maestro.Types.Pool -import Maestro.Util.Pagination (Page) import Servant.API.Generic import Servant.Client diff --git a/src/Maestro/Types.hs b/src/Maestro/Types.hs index 1490438..e2fa7d0 100644 --- a/src/Maestro/Types.hs +++ b/src/Maestro/Types.hs @@ -9,7 +9,6 @@ module Maestro.Types , module Maestro.Types.Common , module Maestro.Types.General , module Maestro.Types.Pool - , Page (..) ) where import Maestro.Types.Accounts @@ -20,4 +19,3 @@ import Maestro.Types.Datum import Maestro.Types.Epochs import Maestro.Types.General import Maestro.Types.Pool -import Maestro.Util.Pagination (Page (..)) From 9e11a6fe5bc57498b3374a6219c887efc6931357 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Tue, 30 May 2023 19:22:45 +0530 Subject: [PATCH 13/25] Feat 17: Hackage readiness - plethora of fixes --- maestro-exe/Maestro/Run/Pools.hs | 4 +- maestro-exe/Maestro/Run/Tx.hs | 2 +- src/Maestro/API/Accounts.hs | 17 +++---- src/Maestro/API/Assets.hs | 17 +++---- src/Maestro/API/Pool.hs | 4 +- src/Maestro/API/Transaction.hs | 2 +- src/Maestro/Client/Accounts.hs | 13 +++--- src/Maestro/Client/Assets.hs | 7 +-- src/Maestro/Client/Pools.hs | 4 +- src/Maestro/Client/Transaction.hs | 2 +- src/Maestro/Types/Accounts.hs | 41 ++++++++--------- src/Maestro/Types/Address.hs | 6 ++- src/Maestro/Types/Assets.hs | 71 +++++++++++++++++++---------- src/Maestro/Types/Common.hs | 21 ++++----- src/Maestro/Types/General.hs | 4 +- src/Maestro/Types/Pool.hs | 76 +++++++++++++++---------------- test/Maestro/Test/Pool.hs | 54 +++++++++++----------- test/Maestro/Test/Transaction.hs | 18 ++++---- 18 files changed, 193 insertions(+), 170 deletions(-) diff --git a/maestro-exe/Maestro/Run/Pools.hs b/maestro-exe/Maestro/Run/Pools.hs index 09de9eb..d767b60 100644 --- a/maestro-exe/Maestro/Run/Pools.hs +++ b/maestro-exe/Maestro/Run/Pools.hs @@ -40,10 +40,10 @@ runPoolsAPI mEnv = do updates <- runPoolInfo mEnv putStrLn $ "fetched pool Updates: \n " ++ show updates -runPoolUpdates :: MaestroEnv -> IO [PoolUpdates] +runPoolUpdates :: MaestroEnv -> IO [PoolUpdate] runPoolUpdates mEnv = poolUpdates mEnv poolId -runListPools :: MaestroEnv -> IO [Pool] +runListPools :: MaestroEnv -> IO [PoolListInfo] runListPools mEnv = listPools mEnv (Page 1 1) runPoolBlocks :: MaestroEnv -> IO [PoolBlock] diff --git a/maestro-exe/Maestro/Run/Tx.hs b/maestro-exe/Maestro/Run/Tx.hs index 1a7df5a..73acec3 100644 --- a/maestro-exe/Maestro/Run/Tx.hs +++ b/maestro-exe/Maestro/Run/Tx.hs @@ -20,7 +20,7 @@ runTxApi mEnv = do utxo <- runTxUtxo mEnv putStrLn $ "fetched Tx Utxos: \n " ++ show utxo -runTxAddress :: MaestroEnv -> IO TxAddress +runTxAddress :: MaestroEnv -> IO UtxoAddress runTxAddress mEnv = txAddress mEnv txHash $ TxIndex 0 runTxCbor :: MaestroEnv -> IO TxCbor diff --git a/src/Maestro/API/Accounts.hs b/src/Maestro/API/Accounts.hs index f477c74..4262273 100644 --- a/src/Maestro/API/Accounts.hs +++ b/src/Maestro/API/Accounts.hs @@ -1,8 +1,9 @@ module Maestro.API.Accounts where +import Data.Text (Text) +import Maestro.Client.Core.Pagination import Maestro.Types.Accounts import Maestro.Types.Common -import Maestro.Client.Core.Pagination import Servant.API import Servant.API.Generic @@ -10,26 +11,26 @@ data AccountsAPI route = AccountsAPI { _account :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> Get '[JSON] AccountInfo , _accountAddresses :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> "addresses" :> Pagination - :> Get '[JSON] [String] + :> Get '[JSON] [Text] , _accountAssets :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> "assets" :> Pagination :> Get '[JSON] [Asset] , _accountsHistory :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> "history" :> QueryParam "epoch_no" EpochNo :> Pagination @@ -37,14 +38,14 @@ data AccountsAPI route = AccountsAPI , _accountsReward :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> "rewards" :> Pagination :> Get '[JSON] [AccountReward] , _accountsUpdates :: route - :- Capture "stake_addr" String + :- Capture "stake_addr" Text :> "updates" :> Pagination :> Get '[JSON] [AccountUpdate] diff --git a/src/Maestro/API/Assets.hs b/src/Maestro/API/Assets.hs index d8b2250..1c03736 100644 --- a/src/Maestro/API/Assets.hs +++ b/src/Maestro/API/Assets.hs @@ -1,10 +1,11 @@ module Maestro.API.Assets where -import Maestro.Types.Assets -import Maestro.Types.Common -import Maestro.Client.Core.Pagination -import Servant.API -import Servant.API.Generic +import Data.Text (Text) +import Maestro.Client.Core.Pagination +import Maestro.Types.Assets +import Maestro.Types.Common +import Servant.API +import Servant.API.Generic data AssetsAPI route = AssetsAPI { _assetPolicyInfo :: @@ -19,7 +20,7 @@ data AssetsAPI route = AssetsAPI :> Capture "policy" PolicyId :> "addresses" :> Pagination - :> Get '[JSON] [String], + :> Get '[JSON] [Text], _assetPolicyTxs :: route :- "policy" @@ -33,7 +34,7 @@ data AssetsAPI route = AssetsAPI :> Capture "policy" PolicyId :> "utxos" :> Pagination - :> Get '[JSON] [AssetUtxo], + :> Get '[JSON] [PolicyUtxo], _assetDetail :: route :- Capture "asset" AssetId @@ -43,7 +44,7 @@ data AssetsAPI route = AssetsAPI :- Capture "asset" AssetId :> "addresses" :> Pagination - :> Get '[JSON] [String], + :> Get '[JSON] [Text], _assetTxs :: route :- Capture "asset" AssetId diff --git a/src/Maestro/API/Pool.hs b/src/Maestro/API/Pool.hs index f217152..ef38cbb 100644 --- a/src/Maestro/API/Pool.hs +++ b/src/Maestro/API/Pool.hs @@ -9,7 +9,7 @@ data PoolAPI route = PoolAPI { _listPools :: route :- Pagination - :> Get '[JSON] [Pool], + :> Get '[JSON] [PoolListInfo], _poolBlocks :: route :- Capture "pool_id" (Bech32StringOf PoolId) @@ -51,6 +51,6 @@ data PoolAPI route = PoolAPI route :- Capture "pool_id" (Bech32StringOf PoolId) :> "updates" - :> Get '[JSON] [PoolUpdates] + :> Get '[JSON] [PoolUpdate] } deriving (Generic) diff --git a/src/Maestro/API/Transaction.hs b/src/Maestro/API/Transaction.hs index 1ef8477..8efccb3 100644 --- a/src/Maestro/API/Transaction.hs +++ b/src/Maestro/API/Transaction.hs @@ -49,7 +49,7 @@ data TxAPI route = TxAPI :> "outputs" :> Capture "index" TxIndex :> "address" - :> Get '[JSON] TxAddress, + :> Get '[JSON] UtxoAddress, _txUtxo :: route :- "transactions" diff --git a/src/Maestro/Client/Accounts.hs b/src/Maestro/Client/Accounts.hs index f173344..4ce7080 100644 --- a/src/Maestro/Client/Accounts.hs +++ b/src/Maestro/Client/Accounts.hs @@ -1,5 +1,6 @@ module Maestro.Client.Accounts where +import Data.Text (Text) import Maestro.API import Maestro.API.Accounts import Maestro.Client.Core @@ -11,20 +12,20 @@ import Servant.Client accountsClient :: MaestroEnv -> AccountsAPI (AsClientT IO) accountsClient = fromServant . _accounts . apiClient -getAccount :: MaestroEnv -> String -> IO AccountInfo +getAccount :: MaestroEnv -> Text -> IO AccountInfo getAccount = _account . accountsClient -listAccountAddresses :: MaestroEnv -> String -> Page -> IO [String] +listAccountAddresses :: MaestroEnv -> Text -> Page -> IO [Text] listAccountAddresses = _accountAddresses . accountsClient -listAccountAssets :: MaestroEnv -> String -> Page -> IO [Asset] +listAccountAssets :: MaestroEnv -> Text -> Page -> IO [Asset] listAccountAssets = _accountAssets . accountsClient -listAccountHistory :: MaestroEnv -> String -> Maybe EpochNo -> Page -> IO [AccountHistory] +listAccountHistory :: MaestroEnv -> Text -> Maybe EpochNo -> Page -> IO [AccountHistory] listAccountHistory = _accountsHistory . accountsClient -listAccountRewards :: MaestroEnv -> String -> Page -> IO [AccountReward] +listAccountRewards :: MaestroEnv -> Text -> Page -> IO [AccountReward] listAccountRewards = _accountsReward . accountsClient -listAccountUpdates :: MaestroEnv -> String -> Page -> IO [AccountUpdate] +listAccountUpdates :: MaestroEnv -> Text -> Page -> IO [AccountUpdate] listAccountUpdates = _accountsUpdates . accountsClient diff --git a/src/Maestro/Client/Assets.hs b/src/Maestro/Client/Assets.hs index e1a1789..3abf7f1 100644 --- a/src/Maestro/Client/Assets.hs +++ b/src/Maestro/Client/Assets.hs @@ -1,5 +1,6 @@ module Maestro.Client.Assets where +import Data.Text (Text) import Maestro.API (_assets) import Maestro.API.Assets import Maestro.Client.Core @@ -33,7 +34,7 @@ listAssetAddressByPolicyId :: PolicyId -> -- | Pagination Page -> - IO [String] + IO [Text] listAssetAddressByPolicyId = _assetPolicyAddress . assetClient -- | @@ -57,7 +58,7 @@ listUtxosByPolicyId :: PolicyId -> -- | Pagination Page -> - IO [AssetUtxo] + IO [PolicyUtxo] listUtxosByPolicyId = _assetPolicyUtxos . assetClient -- | @@ -78,7 +79,7 @@ listAssetAddresses :: -- | Asset, encoded as concatenation of hex of policy ID and asset name AssetId -> Page -> - IO [String] + IO [Text] listAssetAddresses = _assetAddresses . assetClient -- | diff --git a/src/Maestro/Client/Pools.hs b/src/Maestro/Client/Pools.hs index 41b2a73..bb04872 100644 --- a/src/Maestro/Client/Pools.hs +++ b/src/Maestro/Client/Pools.hs @@ -23,7 +23,7 @@ poolsClient :: MaestroEnv -> PoolAPI (AsClientT IO) poolsClient = fromServant . _pools . apiClient -- | Returns a list of currently registered stake pools -listPools :: MaestroEnv -> Page -> IO [Pool] +listPools :: MaestroEnv -> Page -> IO [PoolListInfo] listPools = _listPools . poolsClient -- | Return information about blocks minted by a given pool for all epochs @@ -52,5 +52,5 @@ poolRelays :: MaestroEnv -> Bech32StringOf PoolId -> IO [PoolRelay] poolRelays = _poolRelays . poolsClient -- | Returns a list of updates relating to the specified pool -poolUpdates :: MaestroEnv -> Bech32StringOf PoolId -> IO [PoolUpdates] +poolUpdates :: MaestroEnv -> Bech32StringOf PoolId -> IO [PoolUpdate] poolUpdates = _poolUpdates . poolsClient diff --git a/src/Maestro/Client/Transaction.hs b/src/Maestro/Client/Transaction.hs index 4a32361..8d9fe9d 100644 --- a/src/Maestro/Client/Transaction.hs +++ b/src/Maestro/Client/Transaction.hs @@ -62,7 +62,7 @@ txAddress :: HashStringOf Tx -> -- | The Transaction Output Index TxIndex -> - IO TxAddress + IO UtxoAddress txAddress = _txAddressApi . txClient -- | diff --git a/src/Maestro/Types/Accounts.hs b/src/Maestro/Types/Accounts.hs index 9433302..a3c631f 100644 --- a/src/Maestro/Types/Accounts.hs +++ b/src/Maestro/Types/Accounts.hs @@ -1,19 +1,21 @@ module Maestro.Types.Accounts ( AccountInfo (..) - , Asset (..) , AccountHistory (..) , AccountReward (..) , AccountUpdate (..) ) where +import Data.Text (Text) import Deriving.Aeson +import Maestro.Types.Common (EpochNo, LowerFirst) +import Maestro.Types.General (SlotNo) -- | Information about an account data AccountInfo = AccountInfo - { _accountInfoDelegatedPool :: !String + { _accountInfoDelegatedPool :: !(Maybe Text) , _accountInfoRegistered :: !Bool , _accountInfoRewardsAvailable :: !Integer - , _accountInfoStakeAddress :: !String + , _accountInfoStakeAddress :: !Text , _accountInfoTotalBalance :: !Integer , _accountInfoTotalRewarded :: !Integer , _accountInfoTotalWithdrawn :: !Integer @@ -24,20 +26,11 @@ data AccountInfo = AccountInfo via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountInfo", CamelToSnake]] AccountInfo --- | Information about an Account Assets -data Asset = Asset - { _assetQuantity :: !Integer - , _assetUnit :: !String - } - deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_asset", CamelToSnake]] Asset - -- | Information about an Account Assets data AccountHistory = AccountHistory { _accountHistoryActiveStake :: !Integer - , _accountHistoryEpochNo :: !Integer - , _accountHistoryPoolId :: !String + , _accountHistoryEpochNo :: !EpochNo + , _accountHistoryPoolId :: !(Maybe Text) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) @@ -46,21 +39,25 @@ data AccountHistory = AccountHistory -- | Information about an Account Assets data AccountReward = AccountReward { _accountRewardAmount :: !Integer - , _accountRewardEarnedEpoch :: !Integer - , _accountRewardPoolId :: !String - , _accountRewardSpendableEpoch :: !Integer - , _accountRewardType :: !String + , _accountRewardEarnedEpoch :: !EpochNo + , _accountRewardPoolId :: !Text + , _accountRewardSpendableEpoch :: !EpochNo + , _accountRewardType :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_accountReward", CamelToSnake]] AccountReward +data AccountAction = Registration | Deregistration | Delegation | Withdrawal + deriving stock (Show, Eq, Generic) + deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[LowerFirst]] AccountAction + -- | Information about an Account Assets data AccountUpdate = AccountUpdate - { _accountUpdateAbsSlot :: !Integer - , _accountUpdateAction :: !String - , _accountUpdateEpoch :: !Integer - , _accountUpdateTxHash :: !String + { _accountUpdateAbsSlot :: !SlotNo + , _accountUpdateAction :: !AccountAction + , _accountUpdateEpoch :: !EpochNo + , _accountUpdateTxHash :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) diff --git a/src/Maestro/Types/Address.hs b/src/Maestro/Types/Address.hs index 34e3de9..1c92918 100644 --- a/src/Maestro/Types/Address.hs +++ b/src/Maestro/Types/Address.hs @@ -1,6 +1,8 @@ module Maestro.Types.Address where +import Data.Text (Text) import Deriving.Aeson +import GHC.Natural (Natural) newtype AddressTxCount = AddressTxCount { _addressTxCount :: Int @@ -10,8 +12,8 @@ newtype AddressTxCount = AddressTxCount via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressTx", CamelToSnake]] AddressTxCount data UtxoRef = UtxoRef - { _utxoRefIndex :: !Int - , _utxoRefTxHash :: !String + { _utxoRefIndex :: !Natural + , _utxoRefTxHash :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) diff --git a/src/Maestro/Types/Assets.hs b/src/Maestro/Types/Assets.hs index 3b0dce9..53d9696 100644 --- a/src/Maestro/Types/Assets.hs +++ b/src/Maestro/Types/Assets.hs @@ -1,24 +1,28 @@ module Maestro.Types.Assets where -import qualified Data.Aeson as Aeson +import qualified Data.Aeson as Aeson +import Data.Text (Text) +import Data.Time.Clock.POSIX (POSIXTime) import Deriving.Aeson -import Maestro.Types.Common (MaestroAsset) +import GHC.Natural (Natural) +import Maestro.Types.Common (BlockHeight, EpochNo, LowerFirst) data TokenRegistryMetadata = TokenRegistryMetadata { _tokenRegMetDecimals :: !Integer - , _tokenRegMetDescription :: !String - , _tokenRegMetLogo :: !String - , _tokenRegMetName :: !String - , _tokenRegMetTicker :: !String - , _tokenRegMetUrl :: !String + , _tokenRegMetDescription :: !Text + , _tokenRegMetLogo :: !Text + , _tokenRegMetName :: !Text + , _tokenRegMetTicker :: !Text + , _tokenRegMetUrl :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_tokenRegMet", CamelToSnake]] TokenRegistryMetadata -newtype AssetStandards = AssetStandards - { _assetStandardsCip25Metadata :: Maybe Aeson.Value +data AssetStandards = AssetStandards + { _assetStandardsCip25Metadata :: !(Maybe Aeson.Value) + , _assetStandardsCip68Metadata :: !(Maybe Aeson.Value) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) @@ -26,15 +30,15 @@ newtype AssetStandards = AssetStandards data AssetInfo = AssetInfo - { _assetInfoAssetName :: !String - , _assetInfoAssetNameAscii :: !String + { _assetInfoAssetName :: !Text + , _assetInfoAssetNameAscii :: !(Maybe Text) , _assetInfoAssetStandards :: !AssetStandards , _assetInfoBurnTxCount :: !Integer - , _assetInfoFingerprint :: !String - , _assetInfoFirstMintTime :: !Integer - , _assetInfoFirstMintTx :: !String + , _assetInfoFingerprint :: !Text + , _assetInfoFirstMintTime :: !POSIXTime + , _assetInfoFirstMintTx :: !Text , _assetInfoLatestMintTxMetadata :: !(Maybe Aeson.Value) - , _assetInfoMintTxCount :: !Integer + , _assetInfoMintTxCount :: !Natural , _assetInfoTokenRegistryMetadata :: !(Maybe TokenRegistryMetadata) , _assetInfoTotalSupply :: !Integer } @@ -43,29 +47,48 @@ data AssetInfo = AssetInfo via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetInfo", CamelToSnake]] AssetInfo data AssetTx = AssetTx - { _assetTxBlockHeight :: !Integer - , _assetTxEpochNo :: !Integer - , _assetTxTxHash :: !String + { _assetTxBlockHeight :: !BlockHeight + , _assetTxEpochNo :: !EpochNo + , _assetTxTxHash :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetTx", CamelToSnake]] AssetTx data AssetUtxo = AssetUtxo - { _assetUtxoAddress :: !String - , _assetUtxoAssets :: !(Maybe [MaestroAsset]) - , _assetUtxoIndex :: !Int - , _assetUtxoTxHash :: !String + { _assetUtxoAddress :: !Text + , _assetUtxoAmount :: !Integer + , _assetUtxoIndex :: !Natural + , _assetUtxoTxHash :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetUtxo", CamelToSnake]] AssetUtxo +data AssetInPolicy = AssetInPolicy + { _assetInPolicyName :: !Text + , _assetInPolicyQuantity :: !Integer + } + deriving stock (Show, Eq, Generic) + deriving + (FromJSON, ToJSON) + via CustomJSON '[FieldLabelModifier '[StripPrefix "_assetInPolicy", LowerFirst]] AssetInPolicy + +data PolicyUtxo = PolicyUtxo + { _policyUtxoAddress :: !Text + , _policyUtxoAssets :: ![AssetInPolicy] + , _policyUtxoIndex :: !Natural + , _policyUtxoTxHash :: !Text + } + deriving stock (Show, Eq, Generic) + deriving (FromJSON, ToJSON) + via CustomJSON '[FieldLabelModifier '[StripPrefix "_policyUtxo", CamelToSnake]] PolicyUtxo + data MintingTx = MintingTx - { _mintingTxBlockTimestamp :: !Integer + { _mintingTxBlockTimestamp :: !POSIXTime , _mintingTxMetadata :: !(Maybe Aeson.Value) , _mintingTxMintAmount :: !Integer - , _mintingTxTxHash :: !String + , _mintingTxTxHash :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) diff --git a/src/Maestro/Types/Common.hs b/src/Maestro/Types/Common.hs index 3333977..a198b07 100644 --- a/src/Maestro/Types/Common.hs +++ b/src/Maestro/Types/Common.hs @@ -16,10 +16,10 @@ module Maestro.Types.Common DatumOption (..), ScriptType (..), Script (..), - MaestroAsset (..), + Asset (..), Utxo (..), TxCbor (..), - TxAddress (..), + UtxoAddress (..), Order (..), LowerFirst, ) @@ -78,7 +78,7 @@ newtype BlockHeight = BlockHeight {unBlockHeight :: Natural} deriving newtype (Num, Enum, Real, Integral, FromJSON, ToJSON) -- | Hash of the block. -newtype BlockHash = BlockHash {unBlockHash :: String} +newtype BlockHash = BlockHash {unBlockHash :: Text} deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) @@ -130,20 +130,19 @@ data Script = Script (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_script", LowerFirst]] Script -data MaestroAsset = MaestroAsset - { _maestroAssetQuantity :: !Integer, - _maestroAssetUnit :: !(Maybe String), - _maestroAssetName :: !(Maybe String) +data Asset = Asset + { _assetQuantity :: !Integer + , _assetUnit :: !Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_maestroAsset", CamelToSnake]] MaestroAsset + via CustomJSON '[FieldLabelModifier '[StripPrefix "_asset", CamelToSnake]] Asset -- | Transaction output data Utxo = Utxo { _utxoAddress :: !Text, - _utxoAssets :: ![MaestroAsset], + _utxoAssets :: ![Asset], _utxoDatum :: !(Maybe DatumOption), _utxoIndex :: !Natural, _utxoReferenceScript :: !(Maybe Script), @@ -160,11 +159,11 @@ newtype TxCbor = TxCbor {_txCbor :: Text} (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_tx", LowerFirst]] TxCbor -newtype TxAddress = TxAddress {_txAddress :: Text} +newtype UtxoAddress = UtxoAddress {_utxoAddressAddress :: Text} deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_tx", LowerFirst]] TxAddress + via CustomJSON '[FieldLabelModifier '[StripPrefix "_utxoAddress", LowerFirst]] UtxoAddress data Order = Ascending | Descending diff --git a/src/Maestro/Types/General.hs b/src/Maestro/Types/General.hs index 7f7580d..f55e611 100644 --- a/src/Maestro/Types/General.hs +++ b/src/Maestro/Types/General.hs @@ -172,9 +172,9 @@ data ProtocolParameters = ProtocolParameters { _protocolParametersProtocolVersion :: !ProtocolVersion -- ^ See `ProtocolVersion`. , _protocolParametersMinFeeConstant :: !Natural - -- ^ The linear factor for the minimum fee calculation for given epoch /AKA/ @min_fee_a@ and @tx_fee_fixed@. + -- ^ The linear factor for the minimum fee calculation for given epoch /AKA/ @min_fee_b@ and @tx_fee_fixed@. , _protocolParametersMinFeeCoefficient :: !Natural - -- ^ The constant factor for the minimum fee calculation /AKA/ @min_fee_b@ and @tx_fee_per_byte@. + -- ^ The constant factor for the minimum fee calculation /AKA/ @min_fee_a@ and @tx_fee_per_byte@. , _protocolParametersMaxBlockBodySize :: !Natural -- ^ Maximum block body size. , _protocolParametersMaxBlockHeaderSize :: !Natural diff --git a/src/Maestro/Types/Pool.hs b/src/Maestro/Types/Pool.hs index 0b5a259..13fa772 100644 --- a/src/Maestro/Types/Pool.hs +++ b/src/Maestro/Types/Pool.hs @@ -1,15 +1,15 @@ module Maestro.Types.Pool ( ActiveStake (..), DelegatorInfo (..), - Pool (..), + PoolListInfo (..), PoolBlock (..), PoolHistory (..), PoolInfo (..), PoolMetadata (..), PoolMetaJson (..), PoolRelay (..), - PoolRelayInfo (..), - PoolUpdates (..), + Relay (..), + PoolUpdate (..), PoolId, ) where @@ -32,14 +32,14 @@ data PoolMeta data PoolUpdateTx -data Pool = Pool - { _plPoolIdBech32 :: !(Bech32StringOf PoolId), - _plTicker :: !(Maybe String) +data PoolListInfo = PoolListInfo + { _poolListInfoPoolIdBech32 :: !(Bech32StringOf PoolId), + _poolListInfoTicker :: !(Maybe Text) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_pl", CamelToSnake]] Pool + via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolListInfo", CamelToSnake]] PoolListInfo data PoolBlock = PoolBlock { -- | Absolute slot of the block @@ -85,7 +85,7 @@ data PoolHistory = PoolHistory { -- | Active stake in the epoch _poolHstActiveStake :: !(Maybe ActiveStake), -- | Pool active stake as percentage of total active stake - _poolHstActiveStakePct :: !(Maybe String), + _poolHstActiveStakePct :: !(Maybe Text), -- | Blocks created in the epoch _poolHstBlockCnt :: !(Maybe Natural), -- | Total rewards earned by pool delegators for the epoch @@ -95,7 +95,7 @@ data PoolHistory = PoolHistory -- | The Epoch number _poolHstEpochNo :: !EpochNo, -- | Annual return percentage for delegators for the epoch - _poolHstEpochRos :: !String, + _poolHstEpochRos :: !Text, -- | Pool fixed cost _poolHstFixedCost :: !Natural, -- | Pool margin @@ -103,35 +103,35 @@ data PoolHistory = PoolHistory -- | Fees collected for the epoch _poolHstPoolFees :: !Natural, -- | Pool saturation percent - _poolHstSaturationPct :: !(Maybe String) + _poolHstSaturationPct :: !(Maybe Text) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolHst", CamelToSnake]] PoolHistory -data PoolRelayInfo = PoolRelayInfo - { _poolRelInfoDns :: !(Maybe String), - _poolRelInfoIpv4 :: !(Maybe String), - _poolRelInfoIpv6 :: !(Maybe String), - _poolRelInfoPort :: !(Maybe Int), - _poolRelInfoSrv :: !(Maybe String) +data Relay = Relay + { _relayDns :: !(Maybe Text), + _relayIpv4 :: !(Maybe Text), + _relayIpv6 :: !(Maybe Text), + _relayPort :: !(Maybe Int), + _relaySrv :: !(Maybe Text) } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolRelInfo", CamelToSnake]] PoolRelayInfo + via CustomJSON '[FieldLabelModifier '[StripPrefix "_relay", CamelToSnake]] Relay -- | JSON metadata associated with a stake pool data PoolMetaJson = PoolMetaJson { -- | Pool description _poolMetaJsonDescription :: !(Maybe Text), -- | Pool home page URL - _poolMetaJsonHomepage :: !(Maybe String), + _poolMetaJsonHomepage :: !(Maybe Text), -- | Pool name - _poolMetaJsonName :: !String, + _poolMetaJsonName :: !Text, -- | Pool ticker symbol - _poolMetaJsonTicker :: !(Maybe String) + _poolMetaJsonTicker :: !(Maybe Text) } deriving stock (Show, Eq, Generic) deriving @@ -141,11 +141,11 @@ data PoolMetaJson = PoolMetaJson -- | Metadata associated with a stake pool data PoolMetadata = PoolMetadata { -- | Hash of the pool metadata - _poolMetadataMetaHash :: !(Maybe String), + _poolMetadataMetaHash :: !(Maybe Text), -- | JSON metadata associated with a stake pool _poolMetadataMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolMetadataMetaUrl :: !(Maybe String), + _poolMetadataMetaUrl :: !(Maybe Text), -- | Bech32 encoded pool ID _poolMetadataPoolIdBech32 :: !(Bech32StringOf PoolId) } @@ -168,23 +168,23 @@ data PoolInfo = PoolInfo -- | Account balance of pool owners _poolInfLivePledge :: !(Maybe Natural), -- | Live saturation - _poolInfLiveSaturation :: !(Maybe String), + _poolInfLiveSaturation :: !(Maybe Text), -- | Live stake _poolInfLiveStake :: !(Maybe Integer), -- | Pool margin _poolInfMargin :: !Double, -- | Hash of the pool metadata - _poolInfMetaHash :: !(Maybe String), + _poolInfMetaHash :: !(Maybe Text), -- | JSON metadata associated with a stake pool _poolInfMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolInfMetaUrl :: !(Maybe String), + _poolInfMetaUrl :: !(Maybe Text), -- | Pool operational certificate - _poolInfOpCert :: !(Maybe String), + _poolInfOpCert :: !(Maybe Text), -- | Operational certificate counter _poolInfOpCertCounter :: !(Maybe Integer), -- | List of stake keys which control the pool - _poolInfOwners :: ![String], + _poolInfOwners :: ![Text], -- | Pool pledge _poolInfPledge :: !Integer, -- | Bech32 encoded pool ID @@ -192,15 +192,15 @@ data PoolInfo = PoolInfo -- | Hex encoded pool ID _poolInfPoolIdHex :: !(HexStringOf PoolId), -- | Status of the pool - _poolInfPoolStatus :: !(Maybe String), + _poolInfPoolStatus :: !(Maybe Text), -- | Stake pool relay - _poolInfRelays :: ![PoolRelayInfo], + _poolInfRelays :: ![Relay], -- | Epoch at which the pool will be retired _poolInfRetiringEpoch :: !(Maybe EpochNo), -- | Reward address associated with the pool _poolInfRewardAddr :: !(Maybe (Bech32StringOf PoolId)), -- | Pool stake share - _poolInfSigma :: !(Maybe String), + _poolInfSigma :: !(Maybe Text), -- | VRF key hash _poolInfVrfKeyHash :: !(HashStringOf VrfKey) } @@ -212,7 +212,7 @@ data PoolInfo = PoolInfo -- | Relay declared by a stake pool data PoolRelay = PoolRelay { _poolRelPoolIdBech32 :: !(Bech32StringOf PoolId), - _poolRelRelays :: ![PoolRelayInfo] + _poolRelRelays :: ![Relay] } deriving stock (Show, Eq, Generic) deriving @@ -220,7 +220,7 @@ data PoolRelay = PoolRelay via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolRel", CamelToSnake]] PoolRelay -- | Update to a stake pool -data PoolUpdates = PoolUpdates +data PoolUpdate = PoolUpdate { -- | Epoch when the update takes effect _poolUpdateActiveEpochNo :: !EpochNo, -- | UNIX timestamp of the block containing the transaction @@ -234,9 +234,9 @@ data PoolUpdates = PoolUpdates -- | JSON metadata associated with a stake pool _poolUpdateMetaJson :: !(Maybe PoolMetaJson), -- | URL pointing to the pool metadata - _poolUpdateMetaUrl :: !(Maybe String), + _poolUpdateMetaUrl :: !(Maybe Text), -- | List of stake keys which control the pool - _poolUpdateOwners :: ![String], + _poolUpdateOwners :: ![Text], -- | Pool pledge _poolUpdatePledge :: !Integer, -- | Bech32 encoded pool ID @@ -244,11 +244,11 @@ data PoolUpdates = PoolUpdates -- | Hex encoded pool ID _poolUpdatePoolIdHex :: !(HexStringOf PoolId), -- | Status of the pool - _poolUpdatePoolStatus :: !(Maybe String), + _poolUpdatePoolStatus :: !(Maybe Text), -- | Stake pool relay - _poolUpdateRelays :: ![PoolRelayInfo], + _poolUpdateRelays :: ![Relay], -- | Epoch at which the pool will be retired - _poolUpdateRetiringEpoch :: !(Maybe String), + _poolUpdateRetiringEpoch :: !(Maybe Text), -- | Reward address associated with the pool _poolUpdateRewardAddr :: !(Maybe (Bech32StringOf Reward)), -- | Transaction hash for the transaction which contained the update @@ -259,4 +259,4 @@ data PoolUpdates = PoolUpdates deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) - via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolUpdate", CamelToSnake]] PoolUpdates + via CustomJSON '[FieldLabelModifier '[StripPrefix "_poolUpdate", CamelToSnake]] PoolUpdate diff --git a/test/Maestro/Test/Pool.hs b/test/Maestro/Test/Pool.hs index 0d53df0..b2b2017 100644 --- a/test/Maestro/Test/Pool.hs +++ b/test/Maestro/Test/Pool.hs @@ -64,17 +64,17 @@ poolsSample = [r| ] |] -poolsExpected :: [Pool] +poolsExpected :: [PoolListInfo] poolsExpected = [ - Pool { - _plPoolIdBech32 = "pool12584mjtgz3fhgpx823qht56gycnfnezg6aqqthazv4qdxkd5c46", - _plTicker = Just "DOLCA" + PoolListInfo { + _poolListInfoPoolIdBech32 = "pool12584mjtgz3fhgpx823qht56gycnfnezg6aqqthazv4qdxkd5c46", + _poolListInfoTicker = Just "DOLCA" }, - Pool { - _plPoolIdBech32 = "pool125kh7e0y9lwya4sz5etmsk7hvga9jtfpuhw00vz9zvk6sh8xh5r", - _plTicker = Just "CHOCO" + PoolListInfo { + _poolListInfoPoolIdBech32 = "pool125kh7e0y9lwya4sz5etmsk7hvga9jtfpuhw00vz9zvk6sh8xh5r", + _poolListInfoTicker = Just "CHOCO" } ] @@ -283,12 +283,12 @@ poolInfoExpected = ] , _poolInfRelays = [ - PoolRelayInfo - { _poolRelInfoDns = Nothing - , _poolRelInfoSrv = Nothing - , _poolRelInfoIpv4 = Just "202.182.106.104" - , _poolRelInfoIpv6 = Nothing - , _poolRelInfoPort = Just 6000 + Relay + { _relayDns = Nothing + , _relaySrv = Nothing + , _relayIpv4 = Just "202.182.106.104" + , _relayIpv6 = Nothing + , _relayPort = Just 6000 } ] , _poolInfMetaUrl = Just "https://git.io/J0eoF" @@ -370,12 +370,12 @@ poolRelayExpected = { _poolRelPoolIdBech32 = "pool125kh7e0y9lwya4sz5etmsk7hvga9jtfpuhw00vz9zvk6sh8xh5r" , _poolRelRelays = [ - PoolRelayInfo - { _poolRelInfoDns = Nothing - , _poolRelInfoSrv = Nothing - , _poolRelInfoIpv4 = Just "202.182.106.104" - , _poolRelInfoIpv6 = Nothing - , _poolRelInfoPort = Just 6000 + Relay + { _relayDns = Nothing + , _relaySrv = Nothing + , _relayIpv4 = Just "202.182.106.104" + , _relayIpv6 = Nothing + , _relayPort = Just 6000 } ] } @@ -417,10 +417,10 @@ poolUpdatesSample = [r| ] |] -poolUpdatesExpected :: [PoolUpdates] +poolUpdatesExpected :: [PoolUpdate] poolUpdatesExpected = [ - PoolUpdates + PoolUpdate { _poolUpdateTxHash = "58011f2d795af54ab076320d5092a7989efd451eb39c5c64794c7b5eccd9da97" , _poolUpdateBlockTime = Just 1629034536 , _poolUpdatePoolIdBech32 = "pool125kh7e0y9lwya4sz5etmsk7hvga9jtfpuhw00vz9zvk6sh8xh5r" @@ -434,12 +434,12 @@ poolUpdatesExpected = , _poolUpdateOwners = ["stake1uxtdm5q9j89mmme0l6jt9rsap8cn3vjy3eflptx34s2645ge7r9gp"] , _poolUpdateRelays = [ - PoolRelayInfo - { _poolRelInfoDns = Nothing - , _poolRelInfoSrv = Nothing - , _poolRelInfoIpv4 = Just "139.180.198.13" - , _poolRelInfoIpv6 = Nothing - , _poolRelInfoPort = Just 6000 + Relay + { _relayDns = Nothing + , _relaySrv = Nothing + , _relayIpv4 = Just "139.180.198.13" + , _relayIpv6 = Nothing + , _relayPort = Just 6000 } ] , _poolUpdateMetaUrl = Just "https://git.io/J0eoF" diff --git a/test/Maestro/Test/Transaction.hs b/test/Maestro/Test/Transaction.hs index 1094b27..30f2f7a 100644 --- a/test/Maestro/Test/Transaction.hs +++ b/test/Maestro/Test/Transaction.hs @@ -38,8 +38,8 @@ txAddressSample = [r| } |] -txAddressExpected :: TxAddress -txAddressExpected = TxAddress {_txAddress = "addr1wxgg25t3tk30jqzl2elqz94lzgmr8a9c9m5z902ds5sjh0g7uaj8z"} +txAddressExpected :: UtxoAddress +txAddressExpected = UtxoAddress {_utxoAddressAddress = "addr1wxgg25t3tk30jqzl2elqz94lzgmr8a9c9m5z902ds5sjh0g7uaj8z"} txUtxoSample :: ByteString txUtxoSample = [r| @@ -81,16 +81,14 @@ txUtxoExpected = , _utxoIndex = 0 , _utxoAssets = [ - MaestroAsset - { _maestroAssetUnit = Just "lovelace" - , _maestroAssetQuantity = 7280082022 - , _maestroAssetName = Nothing + Asset + { _assetUnit = "lovelace" + , _assetQuantity = 7280082022 } , - MaestroAsset - { _maestroAssetUnit = Just "34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518#4154414441636f696e" - , _maestroAssetQuantity = 10824 - , _maestroAssetName = Nothing + Asset + { _assetUnit = "34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518#4154414441636f696e" + , _assetQuantity = 10824 } ] , _utxoAddress = "addr_test1vpfwv0ezc5g8a4mkku8hhy3y3vp92t7s3ul8g778g5yegsgalc6gc" From 31d38b9695df8b46ff5f7d7c40ded38fbecb5bbf Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 31 May 2023 12:27:50 +0530 Subject: [PATCH 14/25] Feat 17: Hackage readiness - better name for utxos client functions --- src/Maestro/Client/Address.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Maestro/Client/Address.hs b/src/Maestro/Client/Address.hs index 8d0d76e..9081c49 100644 --- a/src/Maestro/Client/Address.hs +++ b/src/Maestro/Client/Address.hs @@ -15,7 +15,7 @@ addressClient = fromServant . _address . apiClient -- | -- Returns list of utxos for multiple addresses -utxosForMultiAddresses :: +utxosAtMultiAddresses :: -- | The Maestro Environment MaestroEnv -> -- | Query param to include the corresponding datums for datum hashes @@ -27,11 +27,11 @@ utxosForMultiAddresses :: -- | List of Address in bech32 format to fetch utxo from [Text] -> IO [Utxo] -utxosForMultiAddresses = _addressesUtxos . addressClient +utxosAtMultiAddresses = _addressesUtxos . addressClient -- | -- Returns list of utxo for specific address -utxosForAddress :: +utxosAtAddress :: MaestroEnv -> -- | The Address in bech32 format Text -> @@ -42,24 +42,24 @@ utxosForAddress :: -- | The pagination attributes Page -> IO [Utxo] -utxosForAddress = _addressUtxo . addressClient +utxosAtAddress = _addressUtxo . addressClient -- | -- Returns list of utxo ref for address -getUtxoRef :: +getRefsAtAddress :: MaestroEnv -> -- | The Address in bech32 format Text -> -- | The pagination attributes Page -> IO [UtxoRef] -getUtxoRef = _addressUtxoRefs . addressClient +getRefsAtAddress = _addressUtxoRefs . addressClient -- | -- Get the transaction count for an address -getTxCount :: +getTxCountForAddress :: MaestroEnv -> -- | The Address in bech32 format Text -> IO [AddressTxCount] -getTxCount = _addressTransactionCount . addressClient +getTxCountForAddress = _addressTransactionCount . addressClient From cc51c4e198b87f8f7c664413b0b8d9291e8296d0 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Wed, 31 May 2023 20:42:09 +0530 Subject: [PATCH 15/25] Feat 17: Hackage readiness - an important fix related to parsing json for constructors --- src/Maestro/Types/Accounts.hs | 2 +- src/Maestro/Types/Common.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Maestro/Types/Accounts.hs b/src/Maestro/Types/Accounts.hs index a3c631f..eae6d23 100644 --- a/src/Maestro/Types/Accounts.hs +++ b/src/Maestro/Types/Accounts.hs @@ -50,7 +50,7 @@ data AccountReward = AccountReward data AccountAction = Registration | Deregistration | Delegation | Withdrawal deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[LowerFirst]] AccountAction + deriving (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[LowerFirst]] AccountAction -- | Information about an Account Assets data AccountUpdate = AccountUpdate diff --git a/src/Maestro/Types/Common.hs b/src/Maestro/Types/Common.hs index a198b07..3c0647b 100644 --- a/src/Maestro/Types/Common.hs +++ b/src/Maestro/Types/Common.hs @@ -100,7 +100,7 @@ newtype HashStringOf a = HashStringOf Text data DatumOptionType = Inline | Hash deriving stock (Show, Eq, Generic) - deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[LowerFirst]] DatumOptionType + deriving (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[LowerFirst]] DatumOptionType data DatumOption = DatumOption { _datumOptionBytes :: !(Maybe Text), From 98c83c06e76b2216d3cca6efd8227b26c485dbd3 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 5 Jun 2023 17:23:03 +0530 Subject: [PATCH 16/25] Feat 17: Hackage readiness - trying not found error response --- src/Maestro/Client/Core.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index e09bae1..d8e0448 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -43,7 +43,7 @@ data MaestroError = -- ^ 400 status code. | MaestroApiKeyMissing !Text -- ^ 401 status code. - | MaestroNotFound + | MaestroNotFound !Text -- ^ 404 status code. | MaestroUnsupportedMediaType -- ^ 415 status code. @@ -63,7 +63,7 @@ fromServantClientError e = case e of | s == status401 -> MaestroApiKeyMissing (withMessage body) | s == status404 -> - MaestroNotFound + MaestroNotFound (withMessage body) | s == status415 -> MaestroUnsupportedMediaType | s == status429 -> From daf3f3e4007a28a2269590fff924b00ac1ac5a2a Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 5 Jun 2023 17:57:20 +0530 Subject: [PATCH 17/25] Feat 17: Hackage readiness - reverting from not found error response --- src/Maestro/Client/Core.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index d8e0448..e09bae1 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -43,7 +43,7 @@ data MaestroError = -- ^ 400 status code. | MaestroApiKeyMissing !Text -- ^ 401 status code. - | MaestroNotFound !Text + | MaestroNotFound -- ^ 404 status code. | MaestroUnsupportedMediaType -- ^ 415 status code. @@ -63,7 +63,7 @@ fromServantClientError e = case e of | s == status401 -> MaestroApiKeyMissing (withMessage body) | s == status404 -> - MaestroNotFound (withMessage body) + MaestroNotFound | s == status415 -> MaestroUnsupportedMediaType | s == status429 -> From d5be24c509265375b190479e4de2f445bdd330d5 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Tue, 6 Jun 2023 12:20:02 +0530 Subject: [PATCH 18/25] Feat 17: Hackage readiness --- src/Maestro/Client/Core.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index e09bae1..3626a36 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -63,7 +63,7 @@ fromServantClientError e = case e of | s == status401 -> MaestroApiKeyMissing (withMessage body) | s == status404 -> - MaestroNotFound + ServantClientError e | s == status415 -> MaestroUnsupportedMediaType | s == status429 -> From dcc29f91e0be7367a439d02665b9bfec4316ca49 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Tue, 6 Jun 2023 14:09:40 +0530 Subject: [PATCH 19/25] Feat 17: Hackage readiness --- src/Maestro/Client/Core.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index 3626a36..e09bae1 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -63,7 +63,7 @@ fromServantClientError e = case e of | s == status401 -> MaestroApiKeyMissing (withMessage body) | s == status404 -> - ServantClientError e + MaestroNotFound | s == status415 -> MaestroUnsupportedMediaType | s == status429 -> From becb7296cd7716d79fe23b08387bc715479e2b4d Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 9 Jun 2023 19:41:25 +0530 Subject: [PATCH 20/25] Feat 17: Hackage readiness - An important fix/change: New route to pass for api key instead of it being overridden in each request --- src/Maestro/API.hs | 9 +++++---- src/Maestro/Client/Accounts.hs | 2 +- src/Maestro/Client/Address.hs | 2 +- src/Maestro/Client/Assets.hs | 2 +- src/Maestro/Client/Core.hs | 10 +++++++--- src/Maestro/Client/Datum.hs | 2 +- src/Maestro/Client/Env.hs | 24 ++++++++++-------------- src/Maestro/Client/Epochs.hs | 2 +- src/Maestro/Client/General.hs | 2 +- src/Maestro/Client/Pools.hs | 2 +- src/Maestro/Client/Scripts.hs | 2 +- src/Maestro/Client/Transaction.hs | 2 +- 12 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/Maestro/API.hs b/src/Maestro/API.hs index b265938..0388599 100644 --- a/src/Maestro/API.hs +++ b/src/Maestro/API.hs @@ -1,6 +1,6 @@ module Maestro.API where -import Data.Proxy (Proxy (..)) +import Data.Text (Text) import Maestro.API.Accounts import Maestro.API.Address import Maestro.API.Assets @@ -13,7 +13,7 @@ import Maestro.API.Transaction import Servant.API import Servant.API.Generic -data MaestroApi route = Routes +data MaestroApiV0 route = MaestroApiV0 { _accounts :: route :- "accounts" :> ToServantApi AccountsAPI , _address :: route :- "addresses" :> ToServantApi AddressAPI , _assets :: route :- "assets" :> ToServantApi AssetsAPI @@ -25,5 +25,6 @@ data MaestroApi route = Routes , _scripts :: route :- "scripts" :> ToServantApi ScriptsAPI } deriving Generic -api :: Proxy (ToServantApi MaestroApi) -api = genericApi (Proxy :: Proxy MaestroApi) +newtype MaestroApiV0Auth route = MaestroApiV0Auth + { _apiV0 :: route :- Header' '[Required] "api-key" Text :> ToServantApi MaestroApiV0 } + deriving Generic diff --git a/src/Maestro/Client/Accounts.hs b/src/Maestro/Client/Accounts.hs index 4ce7080..88966a2 100644 --- a/src/Maestro/Client/Accounts.hs +++ b/src/Maestro/Client/Accounts.hs @@ -10,7 +10,7 @@ import Servant.API.Generic import Servant.Client accountsClient :: MaestroEnv -> AccountsAPI (AsClientT IO) -accountsClient = fromServant . _accounts . apiClient +accountsClient = fromServant . _accounts . apiV0Client getAccount :: MaestroEnv -> Text -> IO AccountInfo getAccount = _account . accountsClient diff --git a/src/Maestro/Client/Address.hs b/src/Maestro/Client/Address.hs index 9081c49..d1683b8 100644 --- a/src/Maestro/Client/Address.hs +++ b/src/Maestro/Client/Address.hs @@ -11,7 +11,7 @@ import Servant.API.Generic import Servant.Client addressClient :: MaestroEnv -> AddressAPI (AsClientT IO) -addressClient = fromServant . _address . apiClient +addressClient = fromServant . _address . apiV0Client -- | -- Returns list of utxos for multiple addresses diff --git a/src/Maestro/Client/Assets.hs b/src/Maestro/Client/Assets.hs index 3abf7f1..9c7d616 100644 --- a/src/Maestro/Client/Assets.hs +++ b/src/Maestro/Client/Assets.hs @@ -11,7 +11,7 @@ import Servant.API.Generic import Servant.Client assetClient :: MaestroEnv -> AssetsAPI (AsClientT IO) -assetClient = fromServant . _assets . apiClient +assetClient = fromServant . _assets . apiV0Client -- | -- Returns list of Information about the assets of the given policy ID diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index e09bae1..eb03d52 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -3,7 +3,7 @@ module Maestro.Client.Core ( ApiError (..) - , apiClient + , apiV0Client , MaestroError (..) , fromServantClientError , module Maestro.Client.Core.Pagination @@ -18,6 +18,7 @@ import Maestro.Client.Core.Pagination import Maestro.Client.Env import Maestro.Types.Common (LowerFirst) import Network.HTTP.Types +import Servant.API (fromServant) import Servant.Client import Servant.Client.Generic @@ -79,5 +80,8 @@ fromServantClientError e = case e of Just (ae :: ApiError) -> _apiErrorMessage ae Nothing -> mempty -apiClient :: MaestroEnv -> MaestroApi (AsClientT IO) -apiClient MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either (throwIO . fromServantClientError) pure +apiV0ClientAuth :: MaestroEnv -> MaestroApiV0Auth (AsClientT IO) +apiV0ClientAuth MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either (throwIO . fromServantClientError) pure + +apiV0Client :: MaestroEnv -> MaestroApiV0 (AsClientT IO) +apiV0Client mEnv@MaestroEnv {..} = fromServant $ _apiV0 (apiV0ClientAuth mEnv) _maeToken diff --git a/src/Maestro/Client/Datum.hs b/src/Maestro/Client/Datum.hs index ad865bf..58a6c55 100644 --- a/src/Maestro/Client/Datum.hs +++ b/src/Maestro/Client/Datum.hs @@ -12,7 +12,7 @@ import Servant.API.Generic import Servant.Client datumClient :: MaestroEnv -> DatumAPI (AsClientT IO) -datumClient = fromServant . _datum . apiClient +datumClient = fromServant . _datum . apiV0Client -- | Get information about the datum from it's hash. getDatumByHash :: MaestroEnv -> Text -> IO Datum diff --git a/src/Maestro/Client/Env.hs b/src/Maestro/Client/Env.hs index a6a8096..c3763b0 100644 --- a/src/Maestro/Client/Env.hs +++ b/src/Maestro/Client/Env.hs @@ -6,16 +6,16 @@ module Maestro.Client.Env ) where import Data.Text (Text) -import Data.Text.Encoding (encodeUtf8) -import Network.HTTP.Client (managerModifyRequest, requestHeaders) -import Network.HTTP.Client.TLS (newTlsManagerWith, tlsManagerSettings) +import Network.HTTP.Client (newManager) +import Network.HTTP.Client.TLS (tlsManagerSettings) import qualified Servant.Client as Servant type MaestroToken = Text -newtype MaestroEnv = MaestroEnv - { _maeClientEnv :: Servant.ClientEnv +data MaestroEnv = MaestroEnv + { _maeClientEnv :: !Servant.ClientEnv + , _maeToken :: !MaestroToken } data MaestroNetwork = Mainnet | Preprod @@ -26,15 +26,11 @@ maestroBaseUrl Mainnet = "https://mainnet.gomaestro-api.org/v0" mkMaestroEnv :: MaestroToken -> MaestroNetwork -> IO MaestroEnv mkMaestroEnv token nid = do - clientEnv <- servantClientEnv token $ maestroBaseUrl nid - pure $ MaestroEnv {_maeClientEnv = clientEnv} + clientEnv <- servantClientEnv $ maestroBaseUrl nid + pure $ MaestroEnv { _maeClientEnv = clientEnv, _maeToken = token } -servantClientEnv :: MaestroToken -> String -> IO Servant.ClientEnv -servantClientEnv token url = do +servantClientEnv :: String -> IO Servant.ClientEnv +servantClientEnv url = do baseUrl <- Servant.parseBaseUrl url - manager <- newTlsManagerWith $ tlsManagerSettings {managerModifyRequest = addTokenHeader} - + manager <- newManager tlsManagerSettings pure $ Servant.mkClientEnv manager baseUrl - - where - addTokenHeader req = pure $ req {requestHeaders = [("api-key", encodeUtf8 token), ("Content-Type", "application/json")]} diff --git a/src/Maestro/Client/Epochs.hs b/src/Maestro/Client/Epochs.hs index 8e00db1..d3a07b6 100644 --- a/src/Maestro/Client/Epochs.hs +++ b/src/Maestro/Client/Epochs.hs @@ -12,7 +12,7 @@ import Servant.API.Generic import Servant.Client epochsClient :: MaestroEnv -> EpochsAPI (AsClientT IO) -epochsClient = fromServant . _epochs . apiClient +epochsClient = fromServant . _epochs . apiV0Client -- | Get information about the current epoch. getCurrentEpoch :: MaestroEnv -> IO CurrentEpochInfo diff --git a/src/Maestro/Client/General.hs b/src/Maestro/Client/General.hs index 806c946..30103c3 100644 --- a/src/Maestro/Client/General.hs +++ b/src/Maestro/Client/General.hs @@ -14,7 +14,7 @@ import Servant.API.Generic import Servant.Client generalClient :: MaestroEnv -> GeneralAPI (AsClientT IO) -generalClient = fromServant . _general . apiClient +generalClient = fromServant . _general . apiV0Client -- | Get details about the latest block of the network. getChainTip :: MaestroEnv -> IO ChainTip diff --git a/src/Maestro/Client/Pools.hs b/src/Maestro/Client/Pools.hs index bb04872..d6f0057 100644 --- a/src/Maestro/Client/Pools.hs +++ b/src/Maestro/Client/Pools.hs @@ -20,7 +20,7 @@ import Servant.API.Generic import Servant.Client poolsClient :: MaestroEnv -> PoolAPI (AsClientT IO) -poolsClient = fromServant . _pools . apiClient +poolsClient = fromServant . _pools . apiV0Client -- | Returns a list of currently registered stake pools listPools :: MaestroEnv -> Page -> IO [PoolListInfo] diff --git a/src/Maestro/Client/Scripts.hs b/src/Maestro/Client/Scripts.hs index ff30abb..6bd2f38 100644 --- a/src/Maestro/Client/Scripts.hs +++ b/src/Maestro/Client/Scripts.hs @@ -12,7 +12,7 @@ import Servant.API.Generic import Servant.Client scriptsClient :: MaestroEnv -> ScriptsAPI (AsClientT IO) -scriptsClient = fromServant . _scripts . apiClient +scriptsClient = fromServant . _scripts . apiV0Client -- | Get information about the script from it's hash. getScriptByHash :: MaestroEnv -> Text -> IO Script diff --git a/src/Maestro/Client/Transaction.hs b/src/Maestro/Client/Transaction.hs index 8d9fe9d..43f0929 100644 --- a/src/Maestro/Client/Transaction.hs +++ b/src/Maestro/Client/Transaction.hs @@ -18,7 +18,7 @@ import Servant.API.Generic import Servant.Client txClient :: MaestroEnv -> TxAPI (AsClientT IO) -txClient = fromServant . _tx . apiClient +txClient = fromServant . _tx . apiV0Client -- | -- Submit a signed and serialized transaction to the network. From bc8dea60af5f2c3b0ecd8fc35d32d8ccd4cb1816 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 9 Jun 2023 19:48:17 +0530 Subject: [PATCH 21/25] Feat 17: Hackage readiness - atlas compatibility --- src/Maestro/Client/Core.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index eb03d52..02287f4 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -18,7 +18,7 @@ import Maestro.Client.Core.Pagination import Maestro.Client.Env import Maestro.Types.Common (LowerFirst) import Network.HTTP.Types -import Servant.API (fromServant) +import Servant.API.Generic (fromServant) import Servant.Client import Servant.Client.Generic From 6160bb109debeb9a44ceddfd4746f4ee5cfa9345 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 9 Jun 2023 20:57:43 +0530 Subject: [PATCH 22/25] Feat 17: Hackage readiness - error parsing in case only string is returned --- src/Maestro/Client/Core.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Maestro/Client/Core.hs b/src/Maestro/Client/Core.hs index 02287f4..4f7ea44 100644 --- a/src/Maestro/Client/Core.hs +++ b/src/Maestro/Client/Core.hs @@ -78,7 +78,10 @@ fromServantClientError e = case e of withMessage body = case decode body of Just (ae :: ApiError) -> _apiErrorMessage ae - Nothing -> mempty + Nothing -> + case decode body of + Just (m :: Text) -> m + Nothing -> mempty apiV0ClientAuth :: MaestroEnv -> MaestroApiV0Auth (AsClientT IO) apiV0ClientAuth MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either (throwIO . fromServantClientError) pure From cab2f2a7a12ce7e3da6f08c32a6f5fe187d7a73d Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 12 Jun 2023 09:37:27 +0530 Subject: [PATCH 23/25] Feat 17: Hackage readiness - txmanager submit endpoint --- src/Maestro/API.hs | 20 +++++++++-------- src/Maestro/API/Transaction.hs | 35 ++++++------------------------ src/Maestro/API/TxManager.hs | 15 +++++++++++++ src/Maestro/Client/Transaction.hs | 14 +----------- src/Maestro/Client/TxManager.hs | 27 +++++++++++++++++++++++ src/Maestro/Types/Common.hs | 36 ++++++++++++++++++++++++------- 6 files changed, 88 insertions(+), 59 deletions(-) create mode 100644 src/Maestro/API/TxManager.hs create mode 100644 src/Maestro/Client/TxManager.hs diff --git a/src/Maestro/API.hs b/src/Maestro/API.hs index 0388599..0b7c9b0 100644 --- a/src/Maestro/API.hs +++ b/src/Maestro/API.hs @@ -10,19 +10,21 @@ import Maestro.API.General import Maestro.API.Pool import Maestro.API.Scripts import Maestro.API.Transaction +import Maestro.API.TxManager import Servant.API import Servant.API.Generic data MaestroApiV0 route = MaestroApiV0 - { _accounts :: route :- "accounts" :> ToServantApi AccountsAPI - , _address :: route :- "addresses" :> ToServantApi AddressAPI - , _assets :: route :- "assets" :> ToServantApi AssetsAPI - , _general :: route :- ToServantApi GeneralAPI - , _pools :: route :- "pools" :> ToServantApi PoolAPI - , _tx :: route :- ToServantApi TxAPI - , _epochs :: route :- "epochs" :> ToServantApi EpochsAPI - , _datum :: route :- "datum" :> ToServantApi DatumAPI - , _scripts :: route :- "scripts" :> ToServantApi ScriptsAPI + { _accounts :: route :- "accounts" :> ToServantApi AccountsAPI + , _address :: route :- "addresses" :> ToServantApi AddressAPI + , _assets :: route :- "assets" :> ToServantApi AssetsAPI + , _general :: route :- ToServantApi GeneralAPI + , _pools :: route :- "pools" :> ToServantApi PoolAPI + , _tx :: route :- ToServantApi TxAPI + , _epochs :: route :- "epochs" :> ToServantApi EpochsAPI + , _datum :: route :- "datum" :> ToServantApi DatumAPI + , _scripts :: route :- "scripts" :> ToServantApi ScriptsAPI + , _txManager :: route :- "txmanager" :> ToServantApi TxManagerAPI } deriving Generic newtype MaestroApiV0Auth route = MaestroApiV0Auth diff --git a/src/Maestro/API/Transaction.hs b/src/Maestro/API/Transaction.hs index 8efccb3..ad07994 100644 --- a/src/Maestro/API/Transaction.hs +++ b/src/Maestro/API/Transaction.hs @@ -1,36 +1,13 @@ module Maestro.API.Transaction where -import qualified Data.ByteString as BS -import qualified Data.ByteString.Lazy as LBS -import qualified Data.Text as T -import Maestro.Types.Common -import Servant.API -import Servant.API.Generic - -data CBORStream - -instance Accept CBORStream where - contentType _ = "application/cbor" - -instance MimeRender CBORStream BS.ByteString where - mimeRender _ = LBS.fromStrict - -instance MimeRender CBORStream LBS.ByteString where - mimeRender _ = id - -instance MimeUnrender CBORStream BS.ByteString where - mimeUnrender _ = Right . LBS.toStrict - -instance MimeUnrender CBORStream LBS.ByteString where - mimeUnrender _ = Right +import qualified Data.ByteString as BS +import qualified Data.Text as T +import Maestro.Types.Common +import Servant.API +import Servant.API.Generic data TxAPI route = TxAPI - { _monitorTxSubmit :: - route - :- "transactions" - :> ReqBody' '[Required] '[CBORStream] BS.ByteString - :> Post '[JSON] T.Text, - _submitTx :: + { _submitTx :: route :- "submit" :> "tx" diff --git a/src/Maestro/API/TxManager.hs b/src/Maestro/API/TxManager.hs new file mode 100644 index 0000000..9f99d15 --- /dev/null +++ b/src/Maestro/API/TxManager.hs @@ -0,0 +1,15 @@ +module Maestro.API.TxManager where + +import qualified Data.ByteString as BS +import qualified Data.Text as T +import Maestro.Types.Common +import Servant.API +import Servant.API.Generic + +newtype TxManagerAPI route = TxManagerAPI + { _monitorTxSubmit :: + route + :- ReqBody' '[Required] '[CBORStream] BS.ByteString + :> Post '[JSON] T.Text + } + deriving (Generic) diff --git a/src/Maestro/Client/Transaction.hs b/src/Maestro/Client/Transaction.hs index 43f0929..4fe43a3 100644 --- a/src/Maestro/Client/Transaction.hs +++ b/src/Maestro/Client/Transaction.hs @@ -1,6 +1,5 @@ module Maestro.Client.Transaction - ( submitAndMonitorTx, - submitTx, + ( submitTx, txCbor, txAddress, txUtxo, @@ -20,17 +19,6 @@ import Servant.Client txClient :: MaestroEnv -> TxAPI (AsClientT IO) txClient = fromServant . _tx . apiV0Client --- | --- Submit a signed and serialized transaction to the network. --- A transaction submited with this endpoint will be monitored by Maestro. -submitAndMonitorTx :: - -- | The Maestro Environment - MaestroEnv -> - -- | CBOR encoded Transaction - BS.ByteString -> - IO Text -submitAndMonitorTx = _monitorTxSubmit . txClient - -- | -- Submit a signed and serialized transaction to the network. -- Interaction with this endpoint is identical to IOG's Cardano Submit API and will not be monitored by Maestro. diff --git a/src/Maestro/Client/TxManager.hs b/src/Maestro/Client/TxManager.hs new file mode 100644 index 0000000..3b00a32 --- /dev/null +++ b/src/Maestro/Client/TxManager.hs @@ -0,0 +1,27 @@ +module Maestro.Client.Transaction + ( submitAndMonitorTx + ) +where + +import qualified Data.ByteString as BS +import Data.Text (Text) +import Maestro.API (_txManager) +import Maestro.API.TxManager +import Maestro.Client.Core +import Maestro.Client.Env +import Servant.API.Generic +import Servant.Client + +txClient :: MaestroEnv -> TxManagerAPI (AsClientT IO) +txClient = fromServant . _txManager . apiV0Client + +-- | +-- Submit a signed and serialized transaction to the network. +-- A transaction submited with this endpoint will be monitored by Maestro. +submitAndMonitorTx :: + -- | The Maestro Environment + MaestroEnv -> + -- | CBOR encoded Transaction + BS.ByteString -> + IO Text +submitAndMonitorTx = _monitorTxSubmit . txClient diff --git a/src/Maestro/Types/Common.hs b/src/Maestro/Types/Common.hs index 3c0647b..9cc4db5 100644 --- a/src/Maestro/Types/Common.hs +++ b/src/Maestro/Types/Common.hs @@ -3,6 +3,7 @@ module Maestro.Types.Common TxIndex (..), PolicyId (..), AssetId (..), + CBORStream, EpochNo (..), EpochSize (..), AbsoluteSlot (..), @@ -25,16 +26,18 @@ module Maestro.Types.Common ) where -import qualified Data.Aeson as Aeson -import Data.Char (toLower) +import qualified Data.Aeson as Aeson +import qualified Data.ByteString as BS +import qualified Data.ByteString.Lazy as LBS +import Data.Char (toLower) import Data.Default.Class -import Data.String (IsString) -import Data.Text (Text) -import qualified Data.Text as T -import Data.Word (Word64) +import Data.String (IsString) +import Data.Text (Text) +import qualified Data.Text as T +import Data.Word (Word64) import Deriving.Aeson -import GHC.Natural (Natural) -import Web.HttpApiData +import GHC.Natural (Natural) +import Servant.API -- | Phantom datatype to be used with constructors like `HashStringOf`. data Tx @@ -178,6 +181,23 @@ instance Show Order where show Ascending = "asc" show Descending = "desc" +data CBORStream + +instance Accept CBORStream where + contentType _ = "application/cbor" + +instance MimeRender CBORStream BS.ByteString where + mimeRender _ = LBS.fromStrict + +instance MimeRender CBORStream LBS.ByteString where + mimeRender _ = id + +instance MimeUnrender CBORStream BS.ByteString where + mimeUnrender _ = Right . LBS.toStrict + +instance MimeUnrender CBORStream LBS.ByteString where + mimeUnrender _ = Right + -- | Will lower the first character for your type. data LowerFirst From f00f66243726654871d82d74967644011692fc18 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 12 Jun 2023 12:29:31 +0530 Subject: [PATCH 24/25] Feat 17: Hackage readiness - important fix related to submission of tx --- src/Maestro/API/Transaction.hs | 2 +- src/Maestro/API/TxManager.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Maestro/API/Transaction.hs b/src/Maestro/API/Transaction.hs index ad07994..293e523 100644 --- a/src/Maestro/API/Transaction.hs +++ b/src/Maestro/API/Transaction.hs @@ -12,7 +12,7 @@ data TxAPI route = TxAPI :- "submit" :> "tx" :> ReqBody' '[Required] '[CBORStream] BS.ByteString - :> Post '[JSON] T.Text, + :> PostAccepted '[JSON] T.Text, _txCborApi :: route :- "transactions" diff --git a/src/Maestro/API/TxManager.hs b/src/Maestro/API/TxManager.hs index 9f99d15..df2fd43 100644 --- a/src/Maestro/API/TxManager.hs +++ b/src/Maestro/API/TxManager.hs @@ -10,6 +10,6 @@ newtype TxManagerAPI route = TxManagerAPI { _monitorTxSubmit :: route :- ReqBody' '[Required] '[CBORStream] BS.ByteString - :> Post '[JSON] T.Text + :> PostAccepted '[JSON] T.Text } deriving (Generic) From 3a1db63862b2e6ef4af35c8bb9db37d0050bec84 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 12 Jun 2023 12:48:43 +0530 Subject: [PATCH 25/25] Feat 17: Hackage readiness - txManager module addition --- maestro-sdk.cabal | 2 ++ src/Maestro/Client.hs | 2 ++ src/Maestro/Client/TxManager.hs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/maestro-sdk.cabal b/maestro-sdk.cabal index d516d17..682c993 100644 --- a/maestro-sdk.cabal +++ b/maestro-sdk.cabal @@ -48,6 +48,7 @@ library Maestro.API.Pool Maestro.API.Scripts Maestro.API.Transaction + Maestro.API.TxManager Maestro.Client Maestro.Client.Core @@ -62,6 +63,7 @@ library Maestro.Client.Pools Maestro.Client.Scripts Maestro.Client.Transaction + Maestro.Client.TxManager Maestro.Types Maestro.Types.Accounts diff --git a/src/Maestro/Client.hs b/src/Maestro/Client.hs index 3465e20..74d270f 100644 --- a/src/Maestro/Client.hs +++ b/src/Maestro/Client.hs @@ -11,6 +11,7 @@ module Maestro.Client , module Maestro.Client.Pools , module Maestro.Client.Scripts , module Maestro.Client.Transaction + , module Maestro.Client.TxManager ) where @@ -25,3 +26,4 @@ import Maestro.Client.General import Maestro.Client.Pools import Maestro.Client.Scripts import Maestro.Client.Transaction +import Maestro.Client.TxManager diff --git a/src/Maestro/Client/TxManager.hs b/src/Maestro/Client/TxManager.hs index 3b00a32..f0a76a7 100644 --- a/src/Maestro/Client/TxManager.hs +++ b/src/Maestro/Client/TxManager.hs @@ -1,4 +1,4 @@ -module Maestro.Client.Transaction +module Maestro.Client.TxManager ( submitAndMonitorTx ) where