Skip to content

Commit

Permalink
Update call sites of queryXXX functions in hydra-cluster
Browse files Browse the repository at this point in the history
Following the previous commit we need to specify now explicitly that we
are interested in querying the latest point / tip.
  • Loading branch information
ch1bo committed Jun 3, 2022
1 parent 3326d98 commit 26e1b30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 10 additions & 10 deletions hydra-cluster/src/CardanoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ buildScriptAddress script networkId =
let hashed = hashScript script
in makeShelleyAddress networkId (PaymentCredentialByScript hashed) NoStakeAddress

queryStakePools :: NetworkId -> FilePath -> IO (Set PoolId)
queryStakePools networkId socket =
queryStakePools :: NetworkId -> FilePath -> QueryPoint -> IO (Set PoolId)
queryStakePools networkId socket queryPoint =
let query =
QueryInEra
AlonzoEraInCardanoMode
( QueryInShelleyBasedEra
ShelleyBasedEraAlonzo
QueryStakePools
)
in runQuery networkId socket query
in runQuery networkId socket queryPoint query >>= throwOnEraMismatch

-- | Build a "raw" transaction from a bunch of inputs, outputs and fees.
buildRaw :: [TxIn] -> [TxOut CtxTx] -> Lovelace -> Either TxBodyError TxBody
Expand Down Expand Up @@ -74,11 +74,11 @@ build ::
[TxOut CtxTx] ->
IO (Either TxBodyErrorAutoBalance TxBody)
build networkId socket changeAddress ins collateral outs = do
pparams <- queryProtocolParameters networkId socket
systemStart <- querySystemStart networkId socket
eraHistory <- queryEraHistory networkId socket
stakePools <- queryStakePools networkId socket
utxo <- queryUTxOByTxIn networkId socket (map fst ins)
pparams <- queryProtocolParameters networkId socket QueryTip
systemStart <- querySystemStart networkId socket QueryTip
eraHistory <- queryEraHistory networkId socket QueryTip
stakePools <- queryStakePools networkId socket QueryTip
utxo <- queryUTxOByTxIn networkId socket QueryTip (map fst ins)
pure $
second balancedTxBody $
makeTransactionBodyAutoBalance
Expand Down Expand Up @@ -186,7 +186,7 @@ waitForPayment networkId socket amount addr =
go
where
go = do
utxo <- queryUTxO networkId socket [addr]
utxo <- queryUTxO networkId socket QueryTip [addr]
let expectedPayment = selectPayment utxo
if expectedPayment /= mempty
then pure $ UTxO expectedPayment
Expand Down Expand Up @@ -225,7 +225,7 @@ waitForTransaction networkId socket tx =
where
ins = Map.keys (UTxO.toMap $ utxoFromTx tx)
go = do
utxo <- queryUTxOByTxIn networkId socket ins
utxo <- queryUTxOByTxIn networkId socket QueryTip ins
if null utxo
then go
else pure utxo
Expand Down
3 changes: 2 additions & 1 deletion hydra-cluster/src/CardanoCluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import qualified Cardano.Api.UTxO as UTxO
import Cardano.Ledger.Keys (VKey (VKey))
import CardanoClient (
CardanoClientException,
QueryPoint (QueryTip),
build,
buildAddress,
queryUTxO,
Expand Down Expand Up @@ -168,7 +169,7 @@ seedFromFaucet networkId (RunningNode _ nodeSocket) receivingVerificationKey lov
submit networkId nodeSocket (sign faucetSk body)

findUTxO faucetVk = do
faucetUTxO <- queryUTxO networkId nodeSocket [buildAddress faucetVk networkId]
faucetUTxO <- queryUTxO networkId nodeSocket QueryTip [buildAddress faucetVk networkId]
let foundUTxO = find (\(_i, o) -> txOutLovelace o >= lovelace) $ UTxO.pairs faucetUTxO
case foundUTxO of
Just o -> pure o
Expand Down
3 changes: 2 additions & 1 deletion hydra-cluster/test/Test/DirectChainSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Hydra.Prelude
import Test.Hydra.Prelude

import CardanoClient (
QueryPoint (QueryTip),
buildAddress,
queryTip,
queryUTxO,
Expand Down Expand Up @@ -112,7 +113,7 @@ spec = around showLogsOnFailure $ do
let aliceAddress = buildAddress aliceCardanoVk defaultNetworkId

-- Expect that alice got her committed value back
utxo <- queryUTxO defaultNetworkId nodeSocket [aliceAddress]
utxo <- queryUTxO defaultNetworkId nodeSocket QueryTip [aliceAddress]
let aliceValues = txOutValue <$> toList utxo
aliceValues `shouldContain` [lovelaceToValue aliceCommitment]

Expand Down

0 comments on commit 26e1b30

Please sign in to comment.