Skip to content

Commit 8a668d6

Browse files
committed
Feat 30: Pagination checked by querying UTxOs at multiple addresses
1 parent 9972c3d commit 8a668d6

File tree

12 files changed

+150
-22
lines changed

12 files changed

+150
-22
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Maestro.Run.AddressV1 where
2+
3+
import Maestro.Client.V1
4+
5+
runV1AddressAPI :: MaestroEnv -> IO ()
6+
runV1AddressAPI mEnv = do
7+
utxos <- allPages $ (flip $ utxosAtMultiAddresses mEnv Nothing Nothing) ["insert","your", "big", "address", "list", "here"]
8+
putStrLn $ "Received: ⮯\n" ++ show utxos
9+
-- writeFile "allUtxos.txt" $ show utxos

maestro-exe/Main.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
module Main (main) where
22

33
import qualified Data.Text as T
4-
import Maestro.Client.V0
4+
import Maestro.Client.Env
55
import Maestro.Run.Datum
66
import Maestro.Run.Epochs
77
import Maestro.Run.General
88
import Maestro.Run.Pools
99
import Maestro.Run.Scripts
1010
import Maestro.Run.Tx
11+
import Maestro.Run.AddressV1
1112
import System.Environment (getEnv)
1213

1314

1415
main :: IO ()
1516

1617
main = do
1718
apiKey <- maestroKey
19+
apiKeyMain <- maestroMainKey
1820
env <- mkMaestroEnv (T.pack apiKey) Preprod V0
1921
runPoolsAPI env
2022
runTxApi env
2123
runEpochsAPI env
2224
runDatumAPI env
2325
runScriptsAPI env
2426
runGeneralAPI env
27+
env' <- mkMaestroEnv (T.pack apiKeyMain) Mainnet V1
28+
runV1AddressAPI env'
2529

2630
where
2731
maestroKey = getEnv "MAESTRO_API_KEY"
32+
maestroMainKey = getEnv "MAESTRO_MAIN_KEY"

maestro-sdk.cabal

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ library
5555
Maestro.API.V0.Transaction
5656
Maestro.API.V0.TxManager
5757

58+
Maestro.API.V1
59+
Maestro.API.V1.Address
60+
Maestro.API.V1.General
61+
5862
Maestro.Client.Env
5963
Maestro.Client.Error
6064
Maestro.Client.V0
@@ -66,12 +70,16 @@ library
6670
Maestro.Client.V0.Address
6771
Maestro.Client.V0.Assets
6872
Maestro.Client.V0.General
69-
Maestro.Client.V0.Pagination
7073
Maestro.Client.V0.Pools
7174
Maestro.Client.V0.Scripts
7275
Maestro.Client.V0.Transaction
7376
Maestro.Client.V0.TxManager
7477

78+
Maestro.Client.V1
79+
Maestro.Client.V1.Core
80+
Maestro.Client.V1.Core.Pagination
81+
Maestro.Client.V1.Address
82+
7583
Maestro.Types.Common
7684
Maestro.Types.V0
7785
Maestro.Types.V0.Accounts
@@ -83,6 +91,10 @@ library
8391
Maestro.Types.V0.General
8492
Maestro.Types.V0.Pool
8593

94+
Maestro.Types.V1
95+
Maestro.Types.V1.Common
96+
Maestro.Types.V1.General
97+
8698
-- other-modules:
8799
-- other-extensions:
88100
build-depends:
@@ -142,6 +154,7 @@ executable maestro-exe
142154
Maestro.Run.Scripts
143155
Maestro.Run.Tx
144156
Maestro.Run.Epochs
157+
Maestro.Run.AddressV1
145158
-- other-extensions:
146159
hs-source-dirs: maestro-exe
147160
main-is: Main.hs

src/Maestro/API/V1.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module Maestro.API.V1 where
22

33
import Data.Text (Text)
4-
import Maestro.API.V0.General
4+
import Maestro.API.V1.Address
5+
import Maestro.API.V1.General
56
import Servant.API
67
import Servant.API.Generic
78

89
data MaestroApiV1 route = MaestroApiV1
9-
{ _general :: route :- ToServantApi GeneralAPI
10+
{ _general :: route :- ToServantApi GeneralAPI
11+
, _address :: route :- "addresses" :> ToServantApi AddressAPI
1012
} deriving Generic
1113

1214
newtype MaestroApiV1Auth route = MaestroApiV1Auth

src/Maestro/API/V1/Address.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Maestro.API.V1.Address where
2+
3+
import Data.Text (Text)
4+
import Maestro.Client.V1.Core.Pagination
5+
import Maestro.Types.V1
6+
import Servant.API
7+
import Servant.API.Generic
8+
9+
data AddressAPI route = AddressAPI
10+
{
11+
_addressesUtxos
12+
:: route
13+
:- "utxos"
14+
:> QueryParam "resolve_datums" Bool
15+
:> QueryParam "with_cbor" Bool
16+
:> Pagination
17+
:> ReqBody '[JSON] [Text]
18+
:> Post '[JSON] Utxos
19+
20+
} deriving (Generic)

src/Maestro/Client/V1.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
module Maestro.Client.V0
1+
module Maestro.Client.V1
22
( module Maestro.Client.Env
33
, module Maestro.Client.Error
4-
, module Maestro.Client.V0.Core
4+
, module Maestro.Client.V1.Core
5+
, module Maestro.Client.V1.Address
56
) where
67

78

89
import Maestro.Client.Env
910
import Maestro.Client.Error
10-
import Maestro.Client.V0.Core
11+
import Maestro.Client.V1.Address
12+
import Maestro.Client.V1.Core

src/Maestro/Client/V1/Address.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Maestro.Client.V1.Address where
2+
3+
import Data.Text (Text)
4+
import Maestro.API.V1
5+
import Maestro.API.V1.Address
6+
import Maestro.Client.Env
7+
import Maestro.Client.V1.Core
8+
import Maestro.Types.V1
9+
import Servant.API.Generic
10+
import Servant.Client
11+
12+
addressClient :: MaestroEnv -> AddressAPI (AsClientT IO)
13+
addressClient = fromServant . _address . apiV1Client
14+
15+
-- | Returns list of utxos for multiple addresses
16+
utxosAtMultiAddresses ::
17+
-- | The Maestro Environment
18+
MaestroEnv ->
19+
-- | Query param to include the corresponding datums for datum hashes
20+
Maybe Bool ->
21+
-- | Query Param to include the CBOR encodings of the transaction outputs in the response
22+
Maybe Bool ->
23+
-- | The pagination attributes
24+
Cursor ->
25+
-- | List of Address in bech32 format to fetch utxo from
26+
[Text] ->
27+
IO Utxos
28+
utxosAtMultiAddresses = _addressesUtxos . addressClient

src/Maestro/Types/Common.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module Maestro.Types.Common
1818
DatumOption (..),
1919
ScriptType (..),
2020
Script (..),
21-
Asset (..),
2221
TxCbor (..),
2322
UtxoAddress (..),
2423
Order (..),
@@ -138,15 +137,6 @@ data Script = Script
138137
(FromJSON, ToJSON)
139138
via CustomJSON '[FieldLabelModifier '[StripPrefix "_script", LowerFirst]] Script
140139

141-
data Asset = Asset
142-
{ _assetQuantity :: !Integer
143-
, _assetUnit :: !Text
144-
}
145-
deriving stock (Show, Eq, Generic)
146-
deriving
147-
(FromJSON, ToJSON)
148-
via CustomJSON '[FieldLabelModifier '[StripPrefix "_asset", CamelToSnake]] Asset
149-
150140
newtype TxCbor = TxCbor {_txCbor :: Text}
151141
deriving stock (Show, Eq, Generic)
152142
deriving

src/Maestro/Types/V0/Common.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Maestro.Types.V0.Common
2-
( Utxo (..),
2+
( Asset (..),
3+
Utxo (..),
34
module Maestro.Types.Common
45
)
56
where
@@ -9,7 +10,17 @@ import Deriving.Aeson
910
import GHC.Natural (Natural)
1011
import Maestro.Types.Common
1112

12-
-- | Transaction output
13+
-- | Representation of asset in an UTxO.
14+
data Asset = Asset
15+
{ _assetQuantity :: !Integer
16+
, _assetUnit :: !Text
17+
}
18+
deriving stock (Show, Eq, Generic)
19+
deriving
20+
(FromJSON, ToJSON)
21+
via CustomJSON '[FieldLabelModifier '[StripPrefix "_asset", CamelToSnake]] Asset
22+
23+
-- | Transaction output.
1324
data Utxo = Utxo
1425
{ _utxoAddress :: !Text,
1526
_utxoAssets :: ![Asset],

src/Maestro/Types/V1.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
-- | Maestro types
22

33
module Maestro.Types.V1
4-
( module Maestro.Types.V0.Common
5-
, module Maestro.Types.V1.Common
4+
( module Maestro.Types.V1.Common
65
, module Maestro.Types.V1.General
76
) where
87

9-
import Maestro.Types.V0.Common
108
import Maestro.Types.V1.Common
119
import Maestro.Types.V1.General

0 commit comments

Comments
 (0)