Skip to content

Commit

Permalink
Merge pull request #31 from maestro-org/30-v1-support
Browse files Browse the repository at this point in the history
Feat 30: V1 endpoints support for Atlas
  • Loading branch information
Vardominator authored Jul 14, 2023
2 parents 33d2a4d + 8180f26 commit deb1e13
Show file tree
Hide file tree
Showing 83 changed files with 1,976 additions and 475 deletions.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,35 @@

1. Add `maestro-sdk` to the `build-depends` of your project.
2. Create a [Maestro API key](https://docs.gomaestro.org/docs/Getting-started/Sign-up-login).
3. Create environment for accessing the API:
```haskell
import Maestro.Client.Env
3. Code below explains sample usage.
```haskell
module Main (main) where

myEnvPreprod <- mkMaestroEnv "Your-API-Key" Preprod
myEnvMainnet <- mkMaestroEnv "Your-API-Key" Mainnet
```
4. Example: chain tip
```haskell
getChainTip myEnvPreprod -- Preprod
getChainTip myEnvMainnet -- Mainnet
```
import Control.Exception (try)
import Maestro.Client.V1 -- @Maestro.Client.V1@ defines all the client utilities to query Maestro API endpoints.
import Maestro.Types.V1 -- @Maestro.Types.V1@ defines all the types used.

Other endpoints in the `General` category can be exmained in the [`Maestro.Client.General`](https://haddock.gomaestro.org/Maestro-Client-General.html) Haddock module.
main :: IO ()
main = do
env <- mkMaestroEnv @'V1 "<Your-API-Key>" Preprod -- This is how we create an environment against which we'll query endpoints.
chainTip :: ChainTip <- getTimestampedData <$> getChainTip env -- Maestro endpoint to get for chain-tip has data & timestamp against which data was calculated. All endpoints which are timestamped, has functions `getTimestampedData` to get for underlying data & `getTimestamp` to get the timestamp.
addressesUTxOs :: Either MaestroError [UtxoWithSlot] <-
try -- To catch for any errors, given in type `MaestroError`.
$ allPages -- Since this endpoint is paged, we have a helper utility `allPages` to accumulate data from all the pages.
$ flip
(
utxosAtMultiAddresses env
(Just True) -- We would like to have datums resolved. This is for @resolve_datums@ query parameter.
(Just False) -- We would not like to include CBOR encodings of the transaction outputs in the response.
) ["addr_test1...", "addr_test1...", "addr_test1..."] -- Mention your list of addresses to query for.
print addressesUTxOs
```

# Documentation

* [SDK Haddock](https://haddock.gomaestro.org/)
* [Maestro public docs](https://docs.gomaestro.org/)
* [Maestro API reference](https://reference.gomaestro.org/)
* [Maestro API reference](https://docs.gomaestro.org/docs/category/rest-api-reference)

# Contributing

Expand Down
20 changes: 20 additions & 0 deletions maestro-exe/Maestro/Run/Address.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Maestro.Run.Address where

import Control.Monad (unless)
import Data.List (sort)
import qualified Data.Text as T (pack)
import Maestro.Client.Env
import qualified Maestro.Client.V0 as V0
import qualified Maestro.Client.V1 as V1
import Maestro.Types.V1.Common (v1UtxoWithSlotToV0)

runAddressAPI :: String -> IO ()
runAddressAPI apiKey = do
mEnvV0 <- mkMaestroEnv @'V0 (T.pack apiKey) Preprod
mEnvV1 <- mkMaestroEnv @'V1 (T.pack apiKey) Preprod
let addrs = undefined -- Mention list of addresses.
utxos <- V0.allPages $ flip (V0.utxosAtMultiAddresses mEnvV0 Nothing Nothing) addrs
let utxosSorted = sort utxos
utxos' <- fmap (fmap v1UtxoWithSlotToV0) $ V1.allPages $ flip (V1.utxosAtMultiAddresses mEnvV1 Nothing Nothing) addrs
let utxos'Sorted = sort utxos'
unless (utxosSorted == utxos'Sorted) $ error "Not same"
4 changes: 2 additions & 2 deletions maestro-exe/Maestro/Run/Datum.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Maestro.Run.Datum where

import Maestro.Client
import Maestro.Client.V0
import Text.Printf (printf)

runDatumAPI :: MaestroEnv -> IO ()
runDatumAPI :: MaestroEnv 'V0 -> IO ()
runDatumAPI mEnv = do
let datumHash = "938dc15a5faa3da8e7f1e3ed8ca50b49248f8fffdfc04ff3cf7dffa0d06343eb" -- Quiet an involved datum.
printf "Fetching datum from hash %s...\n" datumHash
Expand Down
4 changes: 2 additions & 2 deletions maestro-exe/Maestro/Run/Epochs.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Maestro.Run.Epochs where

import Maestro.Client
import Maestro.Client.V0

runEpochsAPI :: MaestroEnv -> IO ()
runEpochsAPI :: MaestroEnv 'V0 -> IO ()
runEpochsAPI mEnv = do
putStrLn "Fetching Current Epoch's Info ..."
currentEpochInfo <- getCurrentEpoch mEnv
Expand Down
9 changes: 9 additions & 0 deletions maestro-exe/Maestro/Run/General.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Maestro.Run.General where

import Maestro.Client.V0
import Text.Printf (printf)

runGeneralAPI :: MaestroEnv 'V0 -> IO ()
runGeneralAPI mEnv = do
chainTip <- getChainTip mEnv
printf "Querying chain-tip, received: ⮯\n%s\n" (show chainTip)
22 changes: 11 additions & 11 deletions maestro-exe/Maestro/Run/Pools.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Maestro.Run.Pools where

import Maestro.Client
import Maestro.Types
import Maestro.Client.V0
import Maestro.Types.V0

poolId :: Bech32StringOf PoolId
poolId = "pool1rkfs9glmfva3jd0q9vnlqvuhnrflpzj4l07u6sayfx5k7d788us"

runPoolsAPI :: MaestroEnv -> IO ()
runPoolsAPI :: MaestroEnv 'V0 -> IO ()
runPoolsAPI mEnv = do
putStrLn "Fetching List Pools ..."
lstPools <- runListPools mEnv
Expand Down Expand Up @@ -40,26 +40,26 @@ runPoolsAPI mEnv = do
updates <- runPoolInfo mEnv
putStrLn $ "fetched pool Updates: \n " ++ show updates

runPoolUpdates :: MaestroEnv -> IO [PoolUpdate]
runPoolUpdates :: MaestroEnv 'V0 -> IO [PoolUpdate]
runPoolUpdates mEnv = poolUpdates mEnv poolId

runListPools :: MaestroEnv -> IO [PoolListInfo]
runListPools :: MaestroEnv 'V0 -> IO [PoolListInfo]
runListPools mEnv = listPools mEnv (Page 1 1)

runPoolBlocks :: MaestroEnv -> IO [PoolBlock]
runPoolBlocks :: MaestroEnv 'V0 -> IO [PoolBlock]
runPoolBlocks mEnv = poolBlocks mEnv poolId (Page 1 1) Nothing (Just Ascending)

runPoolDelegators :: MaestroEnv -> IO [DelegatorInfo]
runPoolDelegators :: MaestroEnv 'V0 -> IO [DelegatorInfo]
runPoolDelegators mEnv = poolDelegators mEnv poolId (Page 1 1)

runPoolHistory :: MaestroEnv -> IO [PoolHistory]
runPoolHistory :: MaestroEnv 'V0 -> IO [PoolHistory]
runPoolHistory mEnv = poolHistory mEnv poolId (Page 1 1) Nothing (Just Ascending)

runPoolInfo :: MaestroEnv -> IO PoolInfo
runPoolInfo :: MaestroEnv 'V0 -> IO PoolInfo
runPoolInfo mEnv = poolInfo mEnv poolId

runPoolMetadata :: MaestroEnv -> IO PoolMetadata
runPoolMetadata :: MaestroEnv 'V0 -> IO PoolMetadata
runPoolMetadata mEnv = poolMetadata mEnv poolId

runPoolRelay :: MaestroEnv -> IO [PoolRelay]
runPoolRelay :: MaestroEnv 'V0 -> IO [PoolRelay]
runPoolRelay mEnv = poolRelays mEnv poolId
6 changes: 3 additions & 3 deletions maestro-exe/Maestro/Run/Scripts.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Maestro.Run.Scripts where

import Maestro.Client
import Text.Printf (printf)
import Maestro.Client.V0
import Text.Printf (printf)

runScriptsAPI :: MaestroEnv -> IO ()
runScriptsAPI :: MaestroEnv 'V0 -> IO ()
runScriptsAPI mEnv = do
let scriptHash = "3a888d65f16790950a72daee1f63aa05add6d268434107cfa5b67712"
printf "Fetching script from hash %s...\n" scriptHash
Expand Down
12 changes: 6 additions & 6 deletions maestro-exe/Maestro/Run/Tx.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Maestro.Run.Tx where

import Maestro.Client
import Maestro.Types
import Maestro.Client.V0
import Maestro.Types.V0

txHash :: HashStringOf Tx
txHash = "7fdf7a20ba50d841344ab0cb368da6a047ce1e2a29b707586f61f0b8fea6bcf2"

runTxApi :: MaestroEnv -> IO ()
runTxApi :: MaestroEnv 'V0 -> IO ()
runTxApi mEnv = do
putStrLn "Fetching Tx Address ..."
txAddr <- runTxAddress mEnv
Expand All @@ -20,11 +20,11 @@ runTxApi mEnv = do
utxo <- runTxUtxo mEnv
putStrLn $ "fetched Tx Utxos: \n " ++ show utxo

runTxAddress :: MaestroEnv -> IO UtxoAddress
runTxAddress :: MaestroEnv 'V0 -> IO UtxoAddress
runTxAddress mEnv = txAddress mEnv txHash $ TxIndex 0

runTxCbor :: MaestroEnv -> IO TxCbor
runTxCbor :: MaestroEnv 'V0 -> IO TxCbor
runTxCbor mEnv = txCbor mEnv txHash

runTxUtxo :: MaestroEnv -> IO Utxo
runTxUtxo :: MaestroEnv 'V0 -> IO Utxo
runTxUtxo mEnv = txUtxo mEnv txHash (TxIndex 0) (Just True) (Just True)
6 changes: 5 additions & 1 deletion maestro-exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Main (main) where

import qualified Data.Text as T
import Maestro.Client.Env
-- import Maestro.Run.Address
import Maestro.Run.Datum
import Maestro.Run.Epochs
import Maestro.Run.General
import Maestro.Run.Pools
import Maestro.Run.Scripts
import Maestro.Run.Tx
Expand All @@ -14,12 +16,14 @@ main :: IO ()

main = do
apiKey <- maestroKey
env <- mkMaestroEnv (T.pack apiKey) Preprod
env <- mkMaestroEnv @'V0 (T.pack apiKey) Preprod
runPoolsAPI env
runTxApi env
runEpochsAPI env
runDatumAPI env
runScriptsAPI env
runGeneralAPI env
-- runAddressAPI apiKey

where
maestroKey = getEnv "MAESTRO_API_KEY"
Loading

0 comments on commit deb1e13

Please sign in to comment.