@@ -24,10 +24,11 @@ import Hydra.Cardano.Api (
24
24
import Hydra.Cardano.Api qualified as Api
25
25
import Hydra.Chain.Backend (ChainBackend )
26
26
import Hydra.Chain.Backend qualified as Backend
27
+ import Hydra.Chain.Blockfrost (BlockfrostBackend (.. ))
27
28
import Hydra.Chain.Direct (DirectBackend (.. ))
28
29
import Hydra.Cluster.Fixture (KnownNetwork (.. ), toNetworkId )
29
30
import Hydra.Cluster.Util (readConfigFile )
30
- import Hydra.Options (DirectOptions (.. ))
31
+ import Hydra.Options (BlockfrostOptions ( .. ), DirectOptions (.. ))
31
32
import Network.HTTP.Simple (getResponseBody , httpBS , parseRequestThrow )
32
33
import System.Directory (createDirectoryIfMissing , doesFileExist , removeFile )
33
34
import System.Exit (ExitCode (.. ))
@@ -159,6 +160,31 @@ withCardanoNodeDevnet tracer stateDirectory action = do
159
160
args <- setupCardanoDevnet stateDirectory
160
161
withCardanoNode tracer stateDirectory args action
161
162
163
+ withBlockfrostBackend ::
164
+ Tracer IO NodeLog ->
165
+ -- | State directory in which credentials, db & logs are persisted.
166
+ FilePath ->
167
+ (NominalDiffTime -> BlockfrostBackend -> IO a ) ->
168
+ IO a
169
+ withBlockfrostBackend _tracer stateDirectory action = do
170
+ args <- setupCardanoDevnet stateDirectory
171
+ shelleyGenesis <- readFileBS >=> unsafeDecodeJson $ stateDirectory </> nodeShelleyGenesisFile args
172
+ let backend = BlockfrostBackend $ BlockfrostOptions {projectPath = " .." </> Backend. blockfrostProjectPath}
173
+ action (getShelleyGenesisBlockTime shelleyGenesis) backend
174
+
175
+ withBackend ::
176
+ forall a .
177
+ Tracer IO NodeLog ->
178
+ FilePath ->
179
+ (forall backend . ChainBackend backend => NominalDiffTime -> backend -> IO a ) ->
180
+ IO a
181
+ withBackend tracer stateDirectory action = do
182
+ backend <- lookupEnv " HYDRA_BACKEND"
183
+ case backend of
184
+ Just " direct" -> withCardanoNodeDevnet tracer stateDirectory action
185
+ Just " blockfrost" -> withBlockfrostBackend tracer stateDirectory action
186
+ _ -> withCardanoNodeDevnet tracer stateDirectory action
187
+
162
188
-- | Run a cardano-node as normal network participant on a known network.
163
189
withCardanoNodeOnKnownNetwork ::
164
190
Tracer IO NodeLog ->
@@ -320,12 +346,13 @@ withCardanoNode tr stateDirectory args action = do
320
346
else do
321
347
let magic = json ^?! key " networkMagic" . _Number
322
348
Api. Testnet (Api. NetworkMagic $ truncate magic)
323
- -- Read expected time between blocks from shelley genesis
324
- getShelleyGenesisBlockTime :: Value -> NominalDiffTime
325
- getShelleyGenesisBlockTime json = do
326
- let slotLength = json ^?! key " slotLength" . _Number
327
- let activeSlotsCoeff = json ^?! key " activeSlotsCoeff" . _Number
328
- computeBlockTime (realToFrac slotLength) (toRational activeSlotsCoeff)
349
+
350
+ -- Read expected time between blocks from shelley genesis
351
+ getShelleyGenesisBlockTime :: Value -> NominalDiffTime
352
+ getShelleyGenesisBlockTime json = do
353
+ let slotLength = json ^?! key " slotLength" . _Number
354
+ let activeSlotsCoeff = json ^?! key " activeSlotsCoeff" . _Number
355
+ computeBlockTime (realToFrac slotLength) (toRational activeSlotsCoeff)
329
356
330
357
-- | Compute the block time (expected time between blocks) given a slot length
331
358
-- as diff time and active slot coefficient.
0 commit comments