Skip to content

Commit c0a92e3

Browse files
committed
Bump hydra-node to v1.2.0; Add Blockfrost query layer option
1 parent dc91566 commit c0a92e3

File tree

15 files changed

+162
-67
lines changed

15 files changed

+162
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of Hydra-based applications.
2525
| hydra-sdk | hydra-node | cardano-node |
2626
| ----------- | ------------ | ------------ |
2727
| **`1.0.0`** | **`0.19.0`** | **`10.1.2`** |
28-
| **`2.0.0`** | **`1.1.0`** | **`10.5.3`** |
28+
| **`2.0.0`** | **`1.2.0`** | **`10.5.3`** |
2929

3030

3131
## Preliminaries

example/minimal/docker/cluster/config-a.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
"persistDir": "hydra-persist",
88
"hydraSigningKey": "keys/hydra-a.sk",
99
"cardanoSigningKey": "keys/cardano-a.sk",
10-
"network": {
11-
"tag": "Testnet",
12-
"magic": 1
10+
"queryLayer": {
11+
"tag": "CardanoNode",
12+
"nodeSocket": "node-ipc/node.socket",
13+
"network": {
14+
"tag": "Testnet",
15+
"magic": 1
16+
}
1317
},
14-
"nodeSocket": "node-ipc/node.socket",
1518
"pparams": "protocol-parameters.json",
1619
"hydraScripts": [
17-
"152cfeb309be439f3e8a8940bd9e46ba634e469702370789b03bb53219fa42f9",
18-
"d69468c6ea65aee0b1595d25fb8d16b5d32feb20749936a8fd82b112032f4d5f",
19-
"828ff89d3f65ddb600ab8091a4ee27661277029ae5ec0c39457b271db9766c6f"
20+
"ba97aaa648271c75604e66e3a4e00da49bdcaca9ba74d9031ab4c08f736e1c12",
21+
"ff046eba10b9b0f90683bf5becbd6afa496059fc1cf610e798cfe778d85b70ba",
22+
"4bb8c01290599cc9de195b586ee1eb73422b00198126f51f52b00a8e35da9ce3"
2023
],
2124
"contestPeriodSec": 60,
2225
"peers": [
@@ -27,7 +30,7 @@
2730
}
2831
]
2932
},
30-
"blockfrostApiKey": "preprodq4qb2xZcZk6LUFk36DmEcxIFRM8DRwkV",
33+
"blockfrostApiKeyFile": "blockfrost.txt",
3134
"logLevel": "trace",
3235
"ctlLogLevel": "warn",
3336
"commitOutRef": null

example/minimal/docker/cluster/config-b.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
"persistDir": "hydra-persist",
88
"hydraSigningKey": "keys/hydra-b.sk",
99
"cardanoSigningKey": "keys/cardano-b.sk",
10-
"network": {
11-
"tag": "Testnet",
12-
"magic": 1
10+
"queryLayer": {
11+
"tag": "CardanoNode",
12+
"nodeSocket": "node-ipc/node.socket",
13+
"network": {
14+
"tag": "Testnet",
15+
"magic": 1
16+
}
1317
},
14-
"nodeSocket": "node-ipc/node.socket",
1518
"pparams": "protocol-parameters.json",
1619
"hydraScripts": [
17-
"152cfeb309be439f3e8a8940bd9e46ba634e469702370789b03bb53219fa42f9",
18-
"d69468c6ea65aee0b1595d25fb8d16b5d32feb20749936a8fd82b112032f4d5f",
19-
"828ff89d3f65ddb600ab8091a4ee27661277029ae5ec0c39457b271db9766c6f"
20+
"ba97aaa648271c75604e66e3a4e00da49bdcaca9ba74d9031ab4c08f736e1c12",
21+
"ff046eba10b9b0f90683bf5becbd6afa496059fc1cf610e798cfe778d85b70ba",
22+
"4bb8c01290599cc9de195b586ee1eb73422b00198126f51f52b00a8e35da9ce3"
2023
],
2124
"contestPeriodSec": 60,
2225
"peers": [
@@ -27,7 +30,7 @@
2730
}
2831
]
2932
},
30-
"blockfrostApiKey": "preprodq4qb2xZcZk6LUFk36DmEcxIFRM8DRwkV",
33+
"blockfrostApiKeyFile": "blockfrost.txt",
3134
"logLevel": "trace",
3235
"ctlLogLevel": "warn",
3336
"commitOutRef": null

example/minimal/docker/node/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ RUN npx --no-install spago install
2121
COPY example/minimal/src src
2222
COPY example/minimal/app app
2323
COPY example/minimal/protocol-parameters.json .
24+
COPY example/minimal/blockfrost.txt .
2425
RUN npx --no-install spago build
2526

26-
RUN curl -LO https://github.com/input-output-hk/hydra/releases/download/1.1.0/hydra-x86_64-linux-1.1.0.zip
27-
RUN unzip -d /usr/local/bin/ hydra-x86_64-linux-1.1.0.zip
27+
ARG HYDRA_VERSION=1.2.0
28+
RUN curl -LO https://github.com/input-output-hk/hydra/releases/download/${HYDRA_VERSION}/hydra-x86_linux-${HYDRA_VERSION}.zip
29+
RUN unzip -d /usr/local/bin/ hydra-x86_linux-${HYDRA_VERSION}.zip
2830
RUN chmod +x /usr/local/bin/hydra-node
2931

3032
ENTRYPOINT ["npx", "--no-install", "spago", "-q", "run", "--main", "HydraSdk.Example.Minimal.Main", "--exec-args"]

example/minimal/spago.dhall

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
, "maybe"
1717
, "monad-logger"
1818
, "newtype"
19+
, "node-buffer"
1920
, "node-child-process"
21+
, "node-fs"
22+
, "node-path"
2023
, "node-process"
2124
, "ordered-collections"
2225
, "posix-types"
2326
, "prelude"
2427
, "profunctor-lenses"
2528
, "quickcheck"
2629
, "refs"
30+
, "strings"
2731
, "transformers"
2832
, "tuples"
2933
, "uint"

example/minimal/src/App.purs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module HydraSdk.Example.Minimal.App
1515

1616
import Prelude
1717

18-
import Cardano.Types (TransactionInput, TransactionOutput)
18+
import Cardano.Types (NetworkId(MainnetId, TestnetId), TransactionInput, TransactionOutput)
1919
import Contract.Config
2020
( ContractParams
2121
, PrivatePaymentKeySource(PrivatePaymentKeyFile)
@@ -39,7 +39,9 @@ import Ctl.Internal.ServerConfig (blockfrostPublicSanchonetServerConfig)
3939
import Data.Log.Formatter.Pretty (prettyFormatter)
4040
import Data.Log.Message (Message)
4141
import Data.Maybe (Maybe(Just, Nothing), maybe)
42+
import Data.String (take, trim) as String
4243
import Data.Tuple (Tuple(Tuple))
44+
import Data.Tuple.Nested (type (/\), (/\))
4345
import Effect (Effect)
4446
import Effect.AVar (AVar)
4547
import Effect.Aff (Aff, launchAff)
@@ -58,6 +60,8 @@ import HydraSdk.Types
5860
, emptySnapshot
5961
, networkToNetworkId
6062
)
63+
import Node.Encoding (Encoding(UTF8))
64+
import Node.FS.Sync (readTextFile)
6165

6266
type AppM (a :: Type) = LoggerT (ReaderT AppState Aff) a
6367

@@ -109,9 +113,9 @@ setUtxoSnapshot snapshot =
109113
=<< asks _.utxoSnapshot
110114

111115
initApp :: DelegateServerConfig -> Aff AppState
112-
initApp config@{ hydraNodeStartupParams: { network, cardanoSigningKey }, commitOutRef } = do
113-
backendParams <- liftEffect mkBackendParams
114-
contractEnv <- mkContractEnv $ contractParams backendParams
116+
initApp config@{ hydraNodeStartupParams: { cardanoSigningKey }, commitOutRef } = do
117+
networkId /\ backendParams <- liftEffect mkBackendParams
118+
contractEnv <- mkContractEnv $ contractParams backendParams networkId
115119
commitUtxo <- runContractInEnv contractEnv do
116120
oref <- maybe getCollateral pure commitOutRef
117121
resolveCommitOutRef oref
@@ -134,29 +138,31 @@ initApp config@{ hydraNodeStartupParams: { network, cardanoSigningKey }, commitO
134138
=<< getUtxo oref
135139
)
136140

137-
mkBackendParams :: Effect ProviderBackendParams
141+
mkBackendParams :: Effect (NetworkId /\ ProviderBackendParams)
138142
mkBackendParams = do
139-
blockfrostConfig <-
140-
case network of
141-
Mainnet -> pure blockfrostPublicMainnetServerConfig
142-
Testnet { magic } ->
143-
case magic of
144-
1 -> pure blockfrostPublicPreprodServerConfig
145-
2 -> pure blockfrostPublicPreviewServerConfig
146-
4 -> pure blockfrostPublicSanchonetServerConfig
147-
_ ->
148-
throw $ "mkBackendParams: unsupported testnet network with magic: "
149-
<> show magic
150-
pure $ mkBlockfrostBackendParams
143+
blockfrostApiKey <- String.trim <$> readTextFile UTF8 config.blockfrostApiKeyFile
144+
let networkPrefix = String.take 7 blockfrostApiKey
145+
networkId /\ blockfrostConfig <-
146+
case networkPrefix of
147+
"mainnet" ->
148+
pure $ MainnetId /\ blockfrostPublicMainnetServerConfig
149+
"preprod" ->
150+
pure $ TestnetId /\ blockfrostPublicPreprodServerConfig
151+
"preview" ->
152+
pure $ TestnetId /\ blockfrostPublicPreviewServerConfig
153+
_ ->
154+
throw $ "mkBackendParams: unsupported network. Blockfrost API key prefix: "
155+
<> networkPrefix
156+
pure $ networkId /\ mkBlockfrostBackendParams
151157
{ blockfrostConfig
152-
, blockfrostApiKey: config.blockfrostApiKey
158+
, blockfrostApiKey: Just blockfrostApiKey
153159
, confirmTxDelay: defaultConfirmTxDelay
154160
}
155161

156-
contractParams :: ProviderBackendParams -> ContractParams
157-
contractParams backendParams =
162+
contractParams :: ProviderBackendParams -> NetworkId -> ContractParams
163+
contractParams backendParams networkId =
158164
{ backendParams
159-
, networkId: networkToNetworkId network
165+
, networkId
160166
, logLevel: config.ctlLogLevel
161167
, walletSpec: Just $ UseKeys (PrivatePaymentKeyFile cardanoSigningKey) Nothing Nothing
162168
, customLogger: Nothing

example/minimal/src/Config.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import Effect (Effect)
1616
import Effect.Exception (throw)
1717
import HydraSdk.Lib (caDecodeFile, logLevelCodec, orefCodec)
1818
import HydraSdk.Process (HydraNodeStartupParams, hydraNodeStartupParamsCodec)
19+
import Node.Path (FilePath)
1920
import Node.Process (argv)
2021

2122
type DelegateServerConfig =
2223
{ hydraNodeStartupParams :: HydraNodeStartupParams
23-
, blockfrostApiKey :: Maybe String
24+
, blockfrostApiKeyFile :: FilePath
2425
, logLevel :: LogLevel
2526
, ctlLogLevel :: LogLevel
2627
, commitOutRef :: Maybe TransactionInput
@@ -30,7 +31,7 @@ delegateServerConfigCodec :: CA.JsonCodec DelegateServerConfig
3031
delegateServerConfigCodec =
3132
CA.object "DelegateServerConfig" $ CAR.record
3233
{ hydraNodeStartupParams: hydraNodeStartupParamsCodec
33-
, blockfrostApiKey: CA.maybe CA.string
34+
, blockfrostApiKeyFile: CA.string
3435
, logLevel: logLevelCodec
3536
, ctlLogLevel: logLevelCodec
3637
, commitOutRef: CA.maybe orefCodec

example/minimal/src/Contract/L2.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ placeArbitraryDatumL2 snapshotUtxos = withPatchedGetUtxoByOrefQuery snapshotUtxo
6666
withPatchedGetUtxoByOrefQuery :: forall (a :: Type). UtxoMap -> Contract a -> Contract a
6767
withPatchedGetUtxoByOrefQuery snapshotUtxos =
6868
local \env -> env
69-
{ provider = env.provider
69+
{ provider = env.provider
7070
{ getUtxoByOref = \oref ->
7171
maybe (env.provider.getUtxoByOref oref) (pure <<< Right <<< Just) $
72-
Map.lookup oref snapshotUtxos
72+
Map.lookup oref snapshotUtxos
7373
}
7474
}

flake.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
cardano-node.follows = "ctl/cardano-node";
1212
ctl.url = "github:Plutonomicon/cardano-transaction-lib/8ba78bf6f1fc3016844cdb95ce8dcde3f0f99927";
1313
hydra = {
14-
url = "github:input-output-hk/hydra/1.1.0";
14+
url = "github:input-output-hk/hydra/1.2.0";
1515
inputs.cardano-node.follows = "cardano-node";
1616
};
1717
hydra-fixtures = {
18-
url = "github:input-output-hk/hydra/1.1.0";
18+
url = "github:input-output-hk/hydra/1.2.0";
1919
flake = false;
2020
};
2121
};

0 commit comments

Comments
 (0)