-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.cabal | ||
dist-newstyle | ||
dist | ||
dist-* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
{-# LANGUAGE ImportQualifiedPost #-} | ||
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 | ||
import System.Environment (getEnv) | ||
import Control.Concurrent (MVar, ThreadId, newMVar, takeMVar, putMVar, newEmptyMVar, forkFinally) | ||
import Control.Exception (try) | ||
import Maestro.Client.V1 | ||
import Maestro.Types.V1 | ||
import System.Environment (getEnv) | ||
import Data.Text qualified as T | ||
import Control.Monad (void) | ||
import System.IO.Unsafe (unsafePerformIO) | ||
|
||
|
||
main :: IO () | ||
|
||
main = do | ||
apiKey <- maestroKey | ||
env <- mkMaestroEnv @'V0 (T.pack apiKey) Preprod | ||
runPoolsAPI env | ||
runTxApi env | ||
runEpochsAPI env | ||
runDatumAPI env | ||
runScriptsAPI env | ||
runGeneralAPI env | ||
-- runAddressAPI apiKey | ||
maestroKey <- T.pack <$> getEnv "MAESTRO_API_KEY" | ||
env <- mkMaestroEnv @'V1 maestroKey Preprod 50000 | ||
void $ mapM forkChild $ replicate 30 $ task env | ||
waitForChildren | ||
where | ||
task env = do | ||
addressesUTxOs :: Either MaestroError [UtxoWithSlot] <- | ||
try | ||
$ allPages | ||
$ flip | ||
( | ||
utxosAtMultiAddresses env | ||
(Just True) | ||
(Just False) | ||
) ["addr_test1vqj247zdmh7n9g46ukk59k2yxeslevzhah0uj3t0t450x3ggycpxj"] | ||
case addressesUTxOs of | ||
Left err -> print err | ||
Right utxos -> print $ length utxos | ||
|
||
children :: MVar [MVar ()] | ||
children = unsafePerformIO (newMVar []) | ||
|
||
waitForChildren :: IO () | ||
waitForChildren = do | ||
cs <- takeMVar children | ||
case cs of | ||
[] -> return () | ||
m:ms -> do | ||
putMVar children ms | ||
takeMVar m | ||
waitForChildren | ||
|
||
where | ||
maestroKey = getEnv "MAESTRO_API_KEY" | ||
forkChild :: IO () -> IO ThreadId | ||
forkChild io = do | ||
mvar <- newEmptyMVar | ||
childs <- takeMVar children | ||
putMVar children (mvar:childs) | ||
forkFinally io (\_ -> putMVar mvar ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
module Maestro.Client.V1.Core | ||
( apiV1Client | ||
, module Maestro.Client.V1.Core.Pagination | ||
) where | ||
|
||
import Control.Exception (throwIO) | ||
import Control.Retry (retrying, fullJitterBackoff) | ||
import Maestro.API.V1 | ||
import Maestro.Client.Env | ||
import Maestro.Client.Error (fromServantClientError) | ||
import Maestro.Client.Error (fromServantClientError, MaestroError (..)) | ||
import Maestro.Client.V1.Core.Pagination | ||
import Servant.API.Generic (fromServant) | ||
import Servant.Client | ||
import Servant.Client.Generic | ||
|
||
|
||
apiV1ClientAuth :: MaestroEnv 'V1 -> MaestroApiV1Auth (AsClientT IO) | ||
apiV1ClientAuth MaestroEnv{..} = genericClientHoist $ \x -> runClientM x _maeClientEnv >>= either (throwIO . fromServantClientError) pure | ||
apiV1ClientAuth MaestroEnv{..} = | ||
genericClientHoist $ | ||
\x -> | ||
retrying | ||
(fullJitterBackoff _maeBaseDelay) | ||
(\_retryStatus -> \case | ||
Right _ -> pure False | ||
Left clientErr -> case fromServantClientError clientErr of | ||
MaestroUsageLimitReached -> pure True | ||
_ -> pure False | ||
) | ||
(\_ -> runClientM x _maeClientEnv) | ||
>>= either (throwIO . fromServantClientError) pure | ||
|
||
apiV1Client :: MaestroEnv 'V1 -> MaestroApiV1 (AsClientT IO) | ||
apiV1Client mEnv@MaestroEnv {..} = fromServant $ _apiV1 (apiV1ClientAuth mEnv) _maeToken |