Skip to content

Commit 1f504d8

Browse files
Remove use of Cardano.Ledger.Babbage.body in favour of bodyTxL. T… (#2480)
…his is deprecated in newer versions of cardano-ledger-api.
1 parent 88183a5 commit 1f504d8

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

hydra-node/src/Hydra/Chain/Direct/Wallet.hs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ import Cardano.Ledger.Api (
4848
pattern SpendingPurpose,
4949
)
5050
import Cardano.Ledger.Api.UTxO (EraUTxO, ScriptsNeeded)
51-
import Cardano.Ledger.Babbage.Tx (body, getLanguageView, hashScriptIntegrity)
52-
import Cardano.Ledger.Babbage.Tx qualified as Babbage
51+
import Cardano.Ledger.Babbage.Tx (getLanguageView, hashScriptIntegrity)
5352
import Cardano.Ledger.Babbage.TxBody qualified as Babbage
5453
import Cardano.Ledger.Babbage.UTxO (getReferenceScripts)
5554
import Cardano.Ledger.BaseTypes qualified as Ledger
@@ -59,7 +58,6 @@ import Cardano.Ledger.Core (
5958
)
6059
import Cardano.Ledger.Core qualified as Core
6160
import Cardano.Ledger.Core qualified as Ledger
62-
import Cardano.Ledger.Hashes (EraIndependentTxBody, HashAnnotated, hashAnnotated)
6361
import Cardano.Ledger.Shelley.API (unUTxO)
6462
import Cardano.Ledger.Shelley.API qualified as Ledger
6563
import Cardano.Ledger.Val (invert)
@@ -209,23 +207,15 @@ applyTxs txs isOurs utxo =
209207
forM_ txs $ \apiTx -> do
210208
-- XXX: Use cardano-api types instead here
211209
let tx = toLedgerTx apiTx
212-
let txId = getTxId tx
213-
modify (`Map.withoutKeys` view inputsTxBodyL (body tx))
210+
let txId = Ledger.txIdTx tx
211+
modify (`Map.withoutKeys` view (bodyTxL . inputsTxBodyL) tx)
214212
let indexedOutputs =
215-
let outs = toList $ body tx ^. outputsTxBodyL
213+
let outs = toList $ view (bodyTxL . outputsTxBodyL) tx
216214
maxIx = fromIntegral $ length outs
217215
in zip [Ledger.TxIx ix | ix <- [0 .. maxIx]] outs
218216
forM_ indexedOutputs $ \(ix, out@(Babbage.BabbageTxOut addr _ _ _)) ->
219217
when (isOurs addr) $ modify (Map.insert (Ledger.TxIn txId ix) out)
220218

221-
getTxId ::
222-
HashAnnotated
223-
(Ledger.TxBody era)
224-
EraIndependentTxBody =>
225-
Babbage.AlonzoTx era ->
226-
Ledger.TxId
227-
getTxId tx = Ledger.TxId $ hashAnnotated (body tx)
228-
229219
-- | This are all the error that can happen during coverFee.
230220
data ErrCoverFee
231221
= ErrNotEnoughFunds ChangeError

hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ isBalanced utxo originalTx balancedTx =
273273
let inp' = knownInputBalance utxo balancedTx
274274
out' = outputBalance balancedTx
275275
out = outputBalance originalTx
276-
fee = (view feeTxBodyL . body) balancedTx
276+
fee = view (bodyTxL . feeTxBodyL) balancedTx
277277
in coin (deltaValue out' inp') == fee
278278
& counterexample ("Fee: " <> show fee)
279279
& counterexample ("Delta value: " <> show (coin $ deltaValue out' inp'))
@@ -347,9 +347,9 @@ genTxsSpending utxo = scale (round @Double . sqrt . fromIntegral) $ do
347347

348348
genUTxO :: Gen (Map TxIn TxOut)
349349
genUTxO = do
350-
tx <- arbitrary `suchThat` (Prelude.not . Prelude.null . view outputsTxBodyL . body)
350+
tx <- arbitrary `suchThat` (Prelude.not . Prelude.null . view (bodyTxL . outputsTxBodyL))
351351
txIn <- toLedgerTxIn <$> genTxIn
352-
let txOut = scaleAda $ Prelude.head $ toList $ body tx ^. outputsTxBodyL
352+
let txOut = scaleAda $ Prelude.head $ toList $ tx ^. (bodyTxL . outputsTxBodyL)
353353
pure $ Map.singleton txIn txOut
354354
where
355355
scaleAda :: TxOut -> TxOut
@@ -358,10 +358,10 @@ genUTxO = do
358358
in BabbageTxOut addr value' datum refScript
359359

360360
genOutputsForInputs :: Tx LedgerEra -> Gen (Map TxIn TxOut)
361-
genOutputsForInputs AlonzoTx{body} = do
362-
let n = Set.size (view inputsTxBodyL body)
361+
genOutputsForInputs tx = do
362+
let n = Set.size (view (bodyTxL . inputsTxBodyL) tx)
363363
outs <- vectorOf n arbitrary
364-
pure $ Map.fromList $ zip (toList (view inputsTxBodyL body)) outs
364+
pure $ Map.fromList $ zip (toList (view (bodyTxL . inputsTxBodyL) tx)) outs
365365

366366
genLedgerTx :: Gen (Tx LedgerEra)
367367
genLedgerTx = do
@@ -374,11 +374,11 @@ genLedgerTx = do
374374

375375
allTxIns :: [Tx LedgerEra] -> Set TxIn
376376
allTxIns txs =
377-
Set.unions (view inputsTxBodyL . body <$> txs)
377+
Set.unions (view (bodyTxL . inputsTxBodyL) <$> txs)
378378

379379
allTxOuts :: [Tx LedgerEra] -> [TxOut]
380380
allTxOuts txs =
381-
toList $ mconcat (view outputsTxBodyL . body <$> txs)
381+
toList $ mconcat (view (bodyTxL . outputsTxBodyL) <$> txs)
382382

383383
isOurs :: Map TxIn TxOut -> Address -> Bool
384384
isOurs utxo addr =
@@ -406,12 +406,12 @@ deltaValue a b
406406

407407
-- | NOTE: This does not account for withdrawals
408408
knownInputBalance :: Map TxIn TxOut -> Tx LedgerEra -> Value LedgerEra
409-
knownInputBalance utxo = foldMap resolve . toList . view inputsTxBodyL . body
409+
knownInputBalance utxo = foldMap resolve . toList . view (bodyTxL . inputsTxBodyL)
410410
where
411411
resolve :: TxIn -> Value LedgerEra
412412
resolve k = maybe zero getValue (Map.lookup k utxo)
413413

414414
-- | NOTE: This does not account for deposits
415415
outputBalance :: Tx LedgerEra -> Value LedgerEra
416416
outputBalance =
417-
foldMap getValue . view outputsTxBodyL . body
417+
foldMap getValue . view (bodyTxL . outputsTxBodyL)

0 commit comments

Comments
 (0)