2626--
2727module Main (main ) where
2828
29+ import Chainweb.BlockHash
2930import Chainweb.BlockHeader
3031import Chainweb.BlockHeaderDB.RemoteDB
3132import Chainweb.BlockHeight
@@ -85,7 +86,7 @@ defaultConfig = Config
8586 { _configLogHandle = Y. StdOut
8687 , _configLogLevel = Y. Info
8788 , _configChainwebVersion = RecapDevelopment
88- , _configChainId = someChainId RecapDevelopment
89+ , _configChainId = withVersion RecapDevelopment someChainId
8990 , _configNode = HostAddress (unsafeHostnameFromText " us1.tn1.chainweb.com" ) 443
9091 , _configPretty = True
9192 , _configOutputs = True
@@ -151,7 +152,6 @@ hostAddressBaseUrl h = BaseUrl
151152
152153devNetDb :: Config -> Manager -> LogFunction -> IO RemoteDb
153154devNetDb c mgr l = mkDb
154- (_configChainwebVersion c)
155155 (_configChainId c)
156156 mgr
157157 l
@@ -160,25 +160,22 @@ devNetDb c mgr l = mkDb
160160-- TreeDB
161161
162162mkDb
163- :: HasChainwebVersion v
164- => HasChainId cid
165- => v
166- -> cid
163+ :: HasChainId cid
164+ => cid
167165 -> Manager
168166 -> LogFunction
169167 -> HostAddress
170168 -> IO RemoteDb
171- mkDb v c mgr logg h = do
169+ mkDb c mgr logg h = do
172170 return $ RemoteDb
173171 (env mgr h)
174172 (ALogFunction logg)
175- (_chainwebVersion v)
176173 (_chainId c)
177174
178175-- -------------------------------------------------------------------------- --
179176-- Payload Data
180177
181- run :: Config -> LogFunction -> IO ()
178+ run :: HasVersion => Config -> LogFunction -> IO ()
182179run config logg = do
183180 mgr <- newTlsManager
184181 txStream config mgr logg
@@ -215,19 +212,20 @@ prettyCommand p (bh, c) = T.decodeUtf8
215212 , " payload" .= either
216213 (const $ String $ _cmdPayload c)
217214 (id @ Value )
218- (eitherDecodeStrict' $ T. encodeUtf8 $ _cmdPayload $ c)
215+ (eitherDecodeStrict' $ T. encodeUtf8 $ _cmdPayload c)
219216 ]
220217
221218txStream
222- :: Config
219+ :: HasVersion
220+ => Config
223221 -> Manager
224222 -> LogFunction
225223 -> S. Stream (Of (BlockHeight , Command T. Text )) IO ()
226224txStream config mgr logg = do
227225 hdb <- liftIO $ devNetDb config mgr logg
228226
229227 c <- liftIO $ devNetCut config mgr
230- let h = _bhwhHash $ _cutHashes c ^?! ix (_configChainId config)
228+ let h = _rankedBlockHashHash $ _cutHashes c ^?! ix (_configChainId config)
231229
232230 getBranch hdb mempty (HS. singleton (UpperBound h))
233231 & S. chain (logg @ T. Text Debug . sshow)
@@ -243,7 +241,7 @@ txStream config mgr logg = do
243241-- -------------------------------------------------------------------------- --
244242-- PayloadWithOutputs
245243
246- runOutputs :: Config -> LogFunction -> IO ()
244+ runOutputs :: HasVersion => Config -> LogFunction -> IO ()
247245runOutputs config logg = do
248246 mgr <- newTlsManager
249247 txOutputsStream config mgr logg
@@ -269,20 +267,21 @@ prettyCommandWithOutputs p (bh, c, o) = T.decodeUtf8
269267 , " payload" .= either
270268 (const $ String $ _cmdPayload c)
271269 (id @ Value )
272- (eitherDecodeStrict' $ T. encodeUtf8 $ _cmdPayload $ c)
270+ (eitherDecodeStrict' $ T. encodeUtf8 $ _cmdPayload c)
273271 , " output" .= J. toJsonViaEncode o
274272 ]
275273
276274txOutputsStream
277- :: Config
275+ :: HasVersion
276+ => Config
278277 -> Manager
279278 -> LogFunction
280279 -> S. Stream (Of (BlockHeight , Command T. Text , CommandResult T. Text )) IO ()
281280txOutputsStream config mgr logg = do
282281 hdb <- liftIO $ devNetDb config mgr logg
283282
284283 cut <- liftIO $ devNetCut config mgr
285- let h = _bhwhHash $ _cutHashes cut ^?! ix (_configChainId config)
284+ let h = _rankedBlockHashHash $ _cutHashes cut ^?! ix (_configChainId config)
286285
287286 getBranch hdb mempty (HS. singleton (UpperBound h))
288287 & S. chain (logg @ T. Text Debug . sshow)
@@ -303,55 +302,64 @@ txOutputsStream config mgr logg = do
303302-- -------------------------------------------------------------------------- --
304303-- Cut
305304
306- devNetCut :: Config -> Manager -> IO CutHashes
307- devNetCut config mgr = runClientM ( cutGetClient ver) (env mgr node) >>= \ case
305+ devNetCut :: HasVersion => Config -> Manager -> IO CutHashes
306+ devNetCut config mgr = runClientM cutGetClient (env mgr node) >>= \ case
308307 Left e -> error (show e)
309308 Right x -> return x
310309 where
311- ver = _configChainwebVersion config
312310 node = _configNode config
313311
314312-- -------------------------------------------------------------------------- --
315313-- Payloads
316314
317- devNetPayload :: Config -> Manager -> BlockHeight -> BlockPayloadHash -> IO PayloadData
318- devNetPayload config mgr h x = runClientM (payloadClient ver cid x (Just h)) (env mgr node) >>= \ case
315+ devNetPayload
316+ :: HasVersion
317+ => Config
318+ -> Manager
319+ -> BlockHeight
320+ -> BlockPayloadHash
321+ -> IO PayloadData
322+ devNetPayload config mgr h x = runClientM (payloadClient cid x (Just h)) (env mgr node) >>= \ case
319323 Left e -> error (show e)
320324 Right a -> return a
321325 where
322326 cid = _configChainId config
323- ver = _configChainwebVersion config
324327 node = _configNode config
325328
326- devNetPayloadWithOutput :: Config -> Manager -> BlockHeight -> BlockPayloadHash -> IO PayloadWithOutputs
329+ devNetPayloadWithOutput
330+ :: HasVersion
331+ => Config
332+ -> Manager
333+ -> BlockHeight
334+ -> BlockPayloadHash
335+ -> IO PayloadWithOutputs
327336devNetPayloadWithOutput config mgr h x
328- = runClientM (outputsClient ver cid x (Just h)) (env mgr node) >>= \ case
337+ = runClientM (outputsClient cid x (Just h)) (env mgr node) >>= \ case
329338 Left e -> error (show e)
330339 Right a -> return a
331340 where
332341 cid = _configChainId config
333- ver = _configChainwebVersion config
334342 node = _configNode config
335343
336344-- -------------------------------------------------------------------------- --
337345-- Main
338346
339347mainWithConfig :: Config -> IO ()
340- mainWithConfig config = withLog $ \ logger -> do
348+ mainWithConfig config = withLog $ \ logger -> withVersion ver $ do
341349 let logg :: LogFunction
342350 logg = logFunction $ logger
343351 & addLabel (" host" , toText $ _configNode config)
344352 & addLabel (" version" , toText $ _versionName $ _configChainwebVersion config)
345353 & addLabel (" chain" , toText $ _configChainId config)
346354 liftIO $ do
347- registerVersion (_configChainwebVersion config)
348355 if _configOutputs config
349356 then runOutputs config logg
350357 else run config logg
351358
352359 where
360+ ver = _configChainwebVersion config
353361 logconfig = Y. defaultLogConfig
354- & Y. logConfigLogger . Y. loggerConfigThreshold .~ ( _configLogLevel config)
362+ & Y. logConfigLogger . Y. loggerConfigThreshold .~ _configLogLevel config
355363 & Y. logConfigBackend . Y. handleBackendConfigHandle .~ _configLogHandle config
356364 withLog inner = Y. withHandleBackend_ logText (logconfig ^. Y. logConfigBackend)
357365 $ \ backend -> Y. withLogger (logconfig ^. Y. logConfigLogger) backend inner
0 commit comments