@@ -23,7 +23,6 @@ import Control.Concurrent.Class.MonadSTM (
23
23
import Control.Exception (IOException )
24
24
import Control.Monad.Trans.Except (runExcept )
25
25
import Hydra.Cardano.Api (
26
- AnyCardanoEra (.. ),
27
26
BlockInMode (.. ),
28
27
CardanoEra (.. ),
29
28
ChainPoint ,
@@ -35,9 +34,6 @@ import Hydra.Cardano.Api (
35
34
LocalChainSyncClient (.. ),
36
35
LocalNodeClientProtocols (.. ),
37
36
LocalNodeConnectInfo (.. ),
38
- NetworkId ,
39
- QueryInShelleyBasedEra (.. ),
40
- SocketPath ,
41
37
Tx ,
42
38
TxInMode (.. ),
43
39
TxValidationErrorInCardanoMode ,
@@ -56,11 +52,7 @@ import Hydra.Chain (
56
52
currentState ,
57
53
)
58
54
import Hydra.Chain.CardanoClient (
59
- QueryException (.. ),
60
55
QueryPoint (.. ),
61
- queryCurrentEraExpr ,
62
- queryInShelleyBasedEraExpr ,
63
- runQueryExpr ,
64
56
)
65
57
import Hydra.Chain.Direct.Handlers (
66
58
ChainSyncHandler ,
@@ -75,7 +67,6 @@ import Hydra.Chain.Direct.State (
75
67
ChainContext (.. ),
76
68
ChainStateAt (.. ),
77
69
)
78
- import Hydra.Chain.Direct.TimeHandle (queryTimeHandle )
79
70
import Hydra.Chain.Direct.Wallet (
80
71
TinyWallet (.. ),
81
72
WalletInfoOnChain (.. ),
@@ -84,9 +75,8 @@ import Hydra.Chain.Direct.Wallet (
84
75
import Hydra.Logging (Tracer , traceWith )
85
76
import Hydra.Node (BackendOps (.. ))
86
77
import Hydra.Node.Util (readKeyPair )
87
- import Hydra.Options (CardanoChainConfig (.. ), DirectChainConfig (.. ))
78
+ import Hydra.Options (CardanoChainConfig (.. ), ChainBackend (.. ))
88
79
import Hydra.Tx (Party )
89
- import Ouroboros.Consensus.Cardano.Block (EraMismatch (.. ))
90
80
import Ouroboros.Consensus.HardFork.History qualified as Consensus
91
81
import Ouroboros.Network.Magic (NetworkMagic (.. ))
92
82
import Ouroboros.Network.Protocol.ChainSync.Client (
@@ -156,7 +146,7 @@ mkTinyWallet tracer config = do
156
146
157
147
withDirectChain ::
158
148
Tracer IO DirectChainLog ->
159
- DirectChainConfig ->
149
+ CardanoChainConfig ->
160
150
ChainContext ->
161
151
TinyWallet IO ->
162
152
-- | Chain state loaded from persistence.
@@ -167,12 +157,12 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
167
157
let persistedPoint = recordedAt (currentState chainStateHistory)
168
158
queue <- newTQueueIO
169
159
-- Select a chain point from which to start synchronizing
170
- chainPoint <- maybe (queryTip networkId nodeSocket ) pure $ do
160
+ chainPoint <- maybe (queryTip chainBackend ) pure $ do
171
161
(max <$> startChainFrom <*> persistedPoint)
172
162
<|> persistedPoint
173
163
<|> startChainFrom
174
164
175
- let getTimeHandle = queryTimeHandle networkId nodeSocket
165
+ let getTimeHandle = queryTimeHandle chainBackend
176
166
localChainState <- newLocalChainState chainStateHistory
177
167
let chainHandle =
178
168
mkChain
@@ -187,18 +177,21 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
187
177
res <-
188
178
race
189
179
( 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
193
186
)
194
187
(action chainHandle)
195
188
case res of
196
189
Left () -> error " 'connectTo' cannot terminate but did?"
197
190
Right a -> pure a
198
191
where
199
- DirectChainConfig {networkId, nodeSocket , startChainFrom} = config
192
+ CardanoChainConfig {chainBackend , startChainFrom} = config
200
193
201
- connectInfo =
194
+ connectInfo networkId nodeSocket =
202
195
LocalNodeConnectInfo
203
196
{ -- REVIEW: This was 432000 before, but all usages in the
204
197
-- cardano-node repository are using this value. This is only
@@ -229,14 +222,10 @@ withDirectChain tracer config ctx wallet chainStateHistory callback action = do
229
222
throwIO $
230
223
ConnectException
231
224
{ ioException
232
- , nodeSocket
233
- , networkId
234
225
}
235
226
236
- data ConnectException = ConnectException
227
+ newtype ConnectException = ConnectException
237
228
{ ioException :: IOException
238
- , nodeSocket :: SocketPath
239
- , networkId :: NetworkId
240
229
}
241
230
deriving stock (Show )
242
231
0 commit comments