@@ -5,19 +5,30 @@ module Main where
5
5
6
6
import Hydra.Cardano.Api
7
7
import Hydra.Prelude hiding (encodeUtf8 )
8
+ import Hydra.Prelude qualified as P
8
9
9
10
import Conduit
10
11
import Control.Lens ((^?) )
11
12
import Data.Aeson (eitherDecode' )
12
13
import Data.Aeson.Lens (key , _String )
13
14
import Data.ByteString.Lazy.Char8 qualified as C8
15
+ import Data.Text qualified as T
14
16
import Data.Text.Encoding (encodeUtf8 )
17
+ import GHC.Show (show )
18
+ import Hydra.Chain (ChainEvent (.. ))
19
+ import Hydra.HeadLogic (Effect (.. ), Input (.. ), Outcome (.. ))
15
20
import Hydra.Logging (Envelope (.. ))
16
21
import Hydra.Logging.Messages (HydraLog (.. ))
22
+ import Hydra.Node (HydraNodeLog (.. ))
17
23
18
- newtype Decoded tx
24
+ data Decoded tx
19
25
= DecodedHydraLog Text
20
- deriving newtype (Show )
26
+ | DropLog
27
+ deriving (Eq )
28
+
29
+ instance Show (Decoded tx ) where
30
+ show (DecodedHydraLog txt) = T. unpack txt
31
+ show DropLog = " "
21
32
22
33
main :: IO ()
23
34
main = do
@@ -28,20 +39,51 @@ main = do
28
39
.| mapMC
29
40
( \ l ->
30
41
case l ^? key " message" . _String of
31
- Nothing -> error " Failed to find key 'message' which was expected"
42
+ Nothing -> P. error " Failed to find key 'message' which was expected"
32
43
Just line ->
33
44
let envelope = fromStrict $ encodeUtf8 line
34
45
in case decodeAs envelope (undefined :: Envelope (HydraLog Tx )) of
35
- Left e -> error $ show e <> line
46
+ Left e -> P. error $ P. show e <> line
36
47
Right decoded ->
37
48
case decoded. message of
38
- NodeOptions opt -> pure $ DecodedHydraLog $ " NODE STARTING: " <> show opt
39
- Node msg -> pure $ DecodedHydraLog $ " NODE LOG: " <> show msg
40
- _ -> pure $ DecodedHydraLog " _____"
49
+ NodeOptions opt -> pure $ DecodedHydraLog $ " NODE STARTING: \n " <> P. show opt
50
+ Node msg ->
51
+ case msg of
52
+ BeginInput {input} ->
53
+ case input of
54
+ ClientInput {clientInput} ->
55
+ pure $ DecodedHydraLog $ " NODE LOG: \n " <> P. show clientInput
56
+ NetworkInput {} -> pure DropLog
57
+ ChainInput {chainEvent} ->
58
+ case chainEvent of
59
+ Observation {observedTx} -> pure $ DecodedHydraLog $ " OBESERVATION: " <> P. show observedTx
60
+ Rollback {} -> pure DropLog
61
+ Tick {} -> pure DropLog
62
+ PostTxError {postTxError} ->
63
+ pure $ DecodedHydraLog $ " ERROR: " <> P. show postTxError
64
+ EndInput {} -> pure DropLog
65
+ BeginEffect {effect} ->
66
+ case effect of
67
+ ClientEffect {} -> pure DropLog
68
+ NetworkEffect {message} -> pure $ DecodedHydraLog $ P. show message
69
+ OnChainEffect {postChainTx} -> pure $ DecodedHydraLog $ " POSTING: " <> P. show postChainTx
70
+ EndEffect {} -> pure DropLog
71
+ LogicOutcome {outcome} ->
72
+ case outcome of
73
+ Continue {} -> pure DropLog
74
+ Wait {} -> pure DropLog
75
+ Error {error = err} -> pure $ DecodedHydraLog $ " LOGIC ERROR: " <> P. show err
76
+ DroppedFromQueue {} -> pure DropLog
77
+ LoadingState -> pure $ DecodedHydraLog " Loading state..."
78
+ LoadedState {} -> pure $ DecodedHydraLog " Loaded."
79
+ ReplayingState -> pure $ DecodedHydraLog " Replaying state..."
80
+ Misconfiguration {} -> pure $ DecodedHydraLog " MISCONFIG!"
81
+ _ -> pure DropLog
41
82
)
83
+ .| filterC (\ a -> P. show a /= (" " :: Text ))
42
84
.| sinkList
43
85
forM_ decodedLines $ \ l ->
44
- putTextLn (show l)
86
+ putTextLn (P. show l)
45
87
46
88
decodeAs :: forall a . FromJSON a => C8. ByteString -> a -> Either String a
47
89
decodeAs l _ =
0 commit comments