diff --git a/cardano-node/app/reward-history.hs b/cardano-node/app/reward-history.hs index 19a1b4d1c86..e4315063f60 100644 --- a/cardano-node/app/reward-history.hs +++ b/cardano-node/app/reward-history.hs @@ -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 << -- @@ -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 . diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 0fa0d13d8ca..385ce090494 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -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