@@ -49,7 +49,8 @@ wsApp ::
49
49
IsChainState tx =>
50
50
Party ->
51
51
Tracer IO APIServerLog ->
52
- TVar [TimedServerOutput tx ] ->
52
+ -- | Get next sequence number.
53
+ STM IO Natural ->
53
54
(ClientInput tx -> IO () ) ->
54
55
-- | Read model to enhance 'Greetings' messages with 'HeadStatus'.
55
56
Projection STM. STM (ServerOutput tx ) HeadStatus ->
@@ -58,18 +59,19 @@ wsApp ::
58
59
TChan (TimedServerOutput tx ) ->
59
60
PendingConnection ->
60
61
IO ()
61
- wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pending = do
62
+ wsApp party tracer nextSeq callback headStatusP snapshotUtxoP responseChannel pending = do
62
63
traceWith tracer NewAPIConnection
63
64
let path = requestPath $ pendingRequest pending
64
65
queryParams <- uriQuery <$> mkURIBs path
65
66
con <- acceptRequest pending
66
67
chan <- STM. atomically $ dupTChan responseChannel
67
68
69
+ -- FIXME: No support of history forwarding anymore (disabled because of memory growing too much)
68
70
-- api client can decide if they want to see the past history of server outputs
69
- unless (shouldNotServeHistory queryParams) $
70
- forwardHistory con
71
+ -- unless (shouldNotServeHistory queryParams) $
72
+ -- forwardHistory con
71
73
72
- forwardGreetingOnly con
74
+ sendGreetings con
73
75
74
76
let outConfig = mkServerOutputConfig queryParams
75
77
@@ -79,8 +81,8 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
79
81
-- NOTE: We will add a 'Greetings' message on each API server start. This is
80
82
-- important to make sure the latest configured 'party' is reaching the
81
83
-- client.
82
- forwardGreetingOnly con = do
83
- seq <- atomically $ nextSequenceNumber history
84
+ sendGreetings con = do
85
+ seq <- atomically nextSeq
84
86
headStatus <- atomically getLatestHeadStatus
85
87
snapshotUtxo <- atomically getLatestSnapshotUtxo
86
88
time <- getCurrentTime
@@ -114,11 +116,11 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
114
116
queryP = QueryParam k v
115
117
in if queryP `elem` qp then WithoutUTxO else WithUTxO
116
118
117
- shouldNotServeHistory qp =
118
- flip any qp $ \ case
119
- (QueryParam key val)
120
- | key == [queryKey |history|] -> val == [queryValue |no|]
121
- _other -> False
119
+ -- shouldNotServeHistory qp =
120
+ -- flip any qp $ \case
121
+ -- (QueryParam key val)
122
+ -- | key == [queryKey|history|] -> val == [queryValue|no|]
123
+ -- _other -> False
122
124
123
125
sendOutputs chan con outConfig = forever $ do
124
126
response <- STM. atomically $ readTChan chan
@@ -139,18 +141,12 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
139
141
-- message to memory
140
142
let clientInput = decodeUtf8With lenientDecode $ toStrict msg
141
143
time <- getCurrentTime
142
- seq <- atomically $ nextSequenceNumber history
144
+ seq <- atomically nextSeq
143
145
let timedOutput = TimedServerOutput {output = InvalidInput @ tx e clientInput, time, seq }
144
146
sendTextData con $ Aeson. encode timedOutput
145
147
traceWith tracer (APIInvalidInput e clientInput)
146
148
147
- forwardHistory con = do
148
- hist <- STM. atomically (readTVar history)
149
- let encodeAndReverse xs serverOutput = Aeson. encode serverOutput : xs
150
- sendTextDatas con $ foldl' encodeAndReverse [] hist
151
-
152
- nextSequenceNumber :: TVar [TimedServerOutput tx ] -> STM. STM Natural
153
- nextSequenceNumber historyList =
154
- STM. readTVar historyList >>= \ case
155
- [] -> pure 0
156
- (TimedServerOutput {seq } : _) -> pure (seq + 1 )
149
+ -- forwardHistory con = do
150
+ -- hist <- STM.atomically (readTVar history)
151
+ -- let encodeAndReverse xs serverOutput = Aeson.encode serverOutput : xs
152
+ -- sendTextDatas con $ foldl' encodeAndReverse [] hist
0 commit comments