Skip to content

Commit

Permalink
Update example to test mempool endpoint queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Sep 14, 2024
1 parent e225375 commit c3f5f1c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions blockfrost-client/blockfrost-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ flag Production

common libstuff
default-language: Haskell2010
default-extensions: DuplicateRecordFields
ghc-options: -Wall -Wunused-packages
-fno-specialize
-- ^ this helps quite a lot
Expand Down
48 changes: 43 additions & 5 deletions blockfrost-client/example/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Main
where

import Blockfrost.Client
import Blockfrost.Client hiding (NutLinkAPI(..))
import Control.Monad.IO.Class

main = do
-- reads token from BLOCKFROST_TOKEN_PATH
Expand All @@ -15,8 +16,45 @@ main = do
latestBlocks <- getLatestBlock
(ers :: Either BlockfrostError [AccountReward]) <-
tryError $ getAccountRewards "gonnaFail"

allMempoolTxs <-
getMempoolTransactions prj def def

if null allMempoolTxs
then return $ (latestBlocks, ers, allMempoolTxs, Nothing)
else do let lastTxInMempool = TxHash . unTxHashObject $ last allMempoolTxs
lastMempoolTx <- getMempoolTransaction prj lastTxInMempool

return (latestBlocks, ers, allMempoolTxs, Just lastMempoolTx)

-- variant accepting @Paged@ and @SortOrder@ arguments
-- getAccountRewards' "gonnaFail" (page 10) desc
case res of
Left e -> print e
Right ((latestBlocks, ers, allMempoolTxs, lastMempoolTx)) -> do
print "Latest blocks:"
print latestBlocks
putStrLn ""
print "Account rewards (expected to error):"
print ers
putStrLn ""
print "All mempool transactions (mempool potentially empty):"
print allMempoolTxs
putStrLn ""
print "Last mempool transaction (if any):"
print lastMempoolTx
putStrLn ""

-- variant accepting @Paged@ and @SortOrder@ arguments
-- getAccountRewards' "gonnaFail" (page 10) desc
pure (latestBlocks, ers)
print res
case lastMempoolTx of
Nothing -> print "No mempool transactions found."
Just mempoolTx -> do
let inputs = _inputs mempoolTx
if null inputs
then print "No mempool transactions found" -- Should be impossible
else
do let address = Address . _address $ head inputs
mempoolTxByAddress <- runBlockfrost prj $ getMempoolTransactionsByAddress prj address def def
print "Mempool transactions by address:"
print mempoolTxByAddress


Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Blockfrost.Client.Cardano.Transactions

import Blockfrost.API
import Blockfrost.Client.Types
import Blockfrost.Types
import Blockfrost.Types hiding (MempoolTransaction(..))

transactionsClient :: MonadBlockfrost m => Project -> TransactionsAPI (AsClientT m)
transactionsClient = fromServant . _transactions . cardanoClient
Expand Down

0 comments on commit c3f5f1c

Please sign in to comment.