@@ -23,7 +23,6 @@ import Control.Concurrent.Class.MonadSTM (
2323import Control.Exception (IOException )
2424import Control.Monad.Trans.Except (runExcept )
2525import Hydra.Cardano.Api (
26- AnyCardanoEra (.. ),
2726 BlockInMode (.. ),
2827 CardanoEra (.. ),
2928 ChainPoint ,
@@ -35,9 +34,6 @@ import Hydra.Cardano.Api (
3534 LocalChainSyncClient (.. ),
3635 LocalNodeClientProtocols (.. ),
3736 LocalNodeConnectInfo (.. ),
38- NetworkId ,
39- QueryInShelleyBasedEra (.. ),
40- SocketPath ,
4137 Tx ,
4238 TxInMode (.. ),
4339 TxValidationErrorInCardanoMode ,
@@ -56,11 +52,7 @@ import Hydra.Chain (
5652 currentState ,
5753 )
5854import Hydra.Chain.CardanoClient (
59- QueryException (.. ),
6055 QueryPoint (.. ),
61- queryCurrentEraExpr ,
62- queryInShelleyBasedEraExpr ,
63- runQueryExpr ,
6456 )
6557import Hydra.Chain.Direct.Handlers (
6658 ChainSyncHandler ,
@@ -75,7 +67,6 @@ import Hydra.Chain.Direct.State (
7567 ChainContext (.. ),
7668 ChainStateAt (.. ),
7769 )
78- import Hydra.Chain.Direct.TimeHandle (queryTimeHandle )
7970import Hydra.Chain.Direct.Wallet (
8071 TinyWallet (.. ),
8172 WalletInfoOnChain (.. ),
@@ -84,9 +75,8 @@ import Hydra.Chain.Direct.Wallet (
8475import Hydra.Logging (Tracer , traceWith )
8576import Hydra.Node (BackendOps (.. ))
8677import Hydra.Node.Util (readKeyPair )
87- import Hydra.Options (CardanoChainConfig (.. ), DirectChainConfig (.. ))
78+ import Hydra.Options (CardanoChainConfig (.. ), ChainBackend (.. ))
8879import Hydra.Tx (Party )
89- import Ouroboros.Consensus.Cardano.Block (EraMismatch (.. ))
9080import Ouroboros.Consensus.HardFork.History qualified as Consensus
9181import Ouroboros.Network.Magic (NetworkMagic (.. ))
9282import Ouroboros.Network.Protocol.ChainSync.Client (
@@ -156,7 +146,7 @@ mkTinyWallet tracer config = do
156146
157147withDirectChain ::
158148 Tracer IO DirectChainLog ->
159- DirectChainConfig ->
149+ CardanoChainConfig ->
160150 ChainContext ->
161151 TinyWallet IO ->
162152 -- | Chain state loaded from persistence.
@@ -167,12 +157,12 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
167157 let persistedPoint = recordedAt (currentState chainStateHistory)
168158 queue <- newTQueueIO
169159 -- Select a chain point from which to start synchronizing
170- chainPoint <- maybe (queryTip networkId nodeSocket ) pure $ do
160+ chainPoint <- maybe (queryTip chainBackend ) pure $ do
171161 (max <$> startChainFrom <*> persistedPoint)
172162 <|> persistedPoint
173163 <|> startChainFrom
174164
175- let getTimeHandle = queryTimeHandle networkId nodeSocket
165+ let getTimeHandle = queryTimeHandle chainBackend
176166 localChainState <- newLocalChainState chainStateHistory
177167 let chainHandle =
178168 mkChain
@@ -187,18 +177,21 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
187177 res <-
188178 race
189179 ( handle onIOException $
190- connectToLocalNode
191- connectInfo
192- (clientProtocols chainPoint queue handler)
180+ case chainBackend of
181+ DirectBackend {networkId, nodeSocket} ->
182+ connectToLocalNode
183+ (connectInfo networkId nodeSocket)
184+ (clientProtocols chainPoint queue handler)
185+ BlockfrostBackend {} -> undefined
193186 )
194187 (action chainHandle)
195188 case res of
196189 Left () -> error " 'connectTo' cannot terminate but did?"
197190 Right a -> pure a
198191 where
199- DirectChainConfig {networkId, nodeSocket , startChainFrom} = config
192+ CardanoChainConfig {chainBackend , startChainFrom} = config
200193
201- connectInfo =
194+ connectInfo networkId nodeSocket =
202195 LocalNodeConnectInfo
203196 { -- REVIEW: This was 432000 before, but all usages in the
204197 -- cardano-node repository are using this value. This is only
@@ -229,14 +222,10 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
229222 throwIO $
230223 ConnectException
231224 { ioException
232- , nodeSocket
233- , networkId
234225 }
235226
236- data ConnectException = ConnectException
227+ newtype ConnectException = ConnectException
237228 { ioException :: IOException
238- , nodeSocket :: SocketPath
239- , networkId :: NetworkId
240229 }
241230 deriving stock (Show )
242231
0 commit comments