Skip to content

Commit

Permalink
Make reward-history client connect to events firehose
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Sep 22, 2023
1 parent a870c99 commit c7f9cb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cardano-node/app/reward-history.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Cardano.Node.LedgerEvent (foldEvent, filterRewards, parseStakeCredential)
import System.Environment (getArgs)
import System.IO (stdin)
import System.IO (stdin, IOMode(ReadMode))
import Text.Pretty.Simple (pPrint)
import Network.Socket

-- Usage: rewards-history <<<stdin LEDGER-EVENTS] <STAKE-ADDRESS>
--
Expand All @@ -11,9 +12,18 @@ import Text.Pretty.Simple (pPrint)
main :: IO ()
main = do
stakeCredential <- getArgs >>= expectStakeCredential . head
history <- foldEvent (\st -> pure . filterRewards stakeCredential st) mempty stdin
addrInfo <- resolve
putStrLn $ "connecting to " <> show addrInfo
sock <- openSocket addrInfo
connect sock $ addrAddress addrInfo
h <- socketToHandle sock ReadMode

history <- foldEvent (\st -> pure . filterRewards stakeCredential st) mempty h
pPrint history
where
resolve = do
let hints = defaultHints { addrSocketType = Stream, addrFamily = AF_INET }
head <$> getAddrInfo (Just hints) (Just "localhost") (Just "9999")
expectStakeCredential =
maybe (error "invalid / missing stake address as 1st argument") return
.
Expand Down
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ executable reward-history
-rtsopts
build-depends: base >= 4.14 && < 4.17
, cardano-node
, network
, pretty-simple

test-suite cardano-node-test
Expand Down

0 comments on commit c7f9cb2

Please sign in to comment.