Skip to content

Commit

Permalink
Block.hs: deprecate patterns and remove internal usage
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jan 20, 2025
1 parent 93da8ad commit 7f8d417
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cardano-api/internal/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Cardano.Api.Block
, pattern Block
, BlockHeader (..)
, getBlockHeader
, getBlockTxs

-- ** Blocks in the context of a consensus mode
, BlockInMode (..)
Expand Down Expand Up @@ -99,6 +100,7 @@ data Block era where
-> Block era

-- | A block consists of a header and a body containing transactions.
{-# DEPRECATED Block "Use getBlockHeader instead " #-}
pattern Block :: BlockHeader -> [Tx era] -> Block era
pattern Block header txs <- (getBlockHeaderAndTxs -> (header, txs))

Expand Down
16 changes: 10 additions & 6 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ foldBlocks nodeConfigFilePath socketPath validationMode state0 accumulate = hand
-> CSP.ClientStNext n BlockInMode ChainPoint ChainTip IO ()
clientNextN n knownLedgerStates =
CSP.ClientStNext
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode _ (Block (BlockHeader slotNo _ currBlockNo) _)) serverChainTip -> do
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode _ block) serverChainTip -> do
let newLedgerStateE =
applyBlock
env
Expand All @@ -554,7 +554,8 @@ foldBlocks nodeConfigFilePath socketPath validationMode state0 accumulate = hand
case newLedgerStateE of
Left err -> clientIdle_DoneNwithMaybeError n (Just err)
Right newLedgerState -> do
let (knownLedgerStates', committedStates) = pushLedgerState env knownLedgerStates slotNo newLedgerState blockInMode
let BlockHeader slotNo _ currBlockNo = getBlockHeader block
(knownLedgerStates', committedStates) = pushLedgerState env knownLedgerStates slotNo newLedgerState blockInMode
newClientTip = At currBlockNo
newServerTip = fromChainTip serverChainTip

Expand Down Expand Up @@ -729,9 +730,10 @@ chainSyncClientWithLedgerState env ledgerState0 validationMode (CS.ChainSyncClie
)
goClientStNext (Right history) (CS.ClientStNext recvMsgRollForward recvMsgRollBackward) =
CS.ClientStNext
( \blkInMode@(BlockInMode _ (Block (BlockHeader slotNo _ _) _)) tip ->
( \blkInMode@(BlockInMode _ block) tip ->
CS.ChainSyncClient $
let
BlockHeader slotNo _ _ = getBlockHeader block
newLedgerStateE = case Seq.lookup 0 history of
Nothing -> error "Impossible! History should always be non-empty"
Just (_, Left err, _) -> Left err
Expand Down Expand Up @@ -875,8 +877,9 @@ chainSyncClientPipelinedWithLedgerState env ledgerState0 validationMode (CSP.Cha
)
goClientStNext (Right history) n (CSP.ClientStNext recvMsgRollForward recvMsgRollBackward) =
CSP.ClientStNext
( \blkInMode@(BlockInMode _ (Block (BlockHeader slotNo _ _) _)) tip ->
( \blkInMode@(BlockInMode _ block) tip ->
let
BlockHeader slotNo _ _ = getBlockHeader block
newLedgerStateE = case Seq.lookup 0 history of
Nothing -> error "Impossible! History should always be non-empty"
Just (_, Left err, _) -> Left err
Expand Down Expand Up @@ -2173,8 +2176,9 @@ foldEpochState nodeConfigFilePath socketPath validationMode terminationEpoch ini
-> CSP.ClientStNext n BlockInMode ChainPoint ChainTip IO ()
clientNextN n knownLedgerStates =
CSP.ClientStNext
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode era (Block (BlockHeader slotNo _ currBlockNo) _)) serverChainTip -> do
let newLedgerStateE =
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode era block) serverChainTip -> do
let BlockHeader slotNo _ currBlockNo = getBlockHeader block
newLedgerStateE =
applyBlock
env
( maybe
Expand Down
7 changes: 3 additions & 4 deletions cardano-api/test/cardano-api-test/Test/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ prop_roundtrip_txbodycontent_txouts era = H.property $ do
(body, content :: TxBodyContent BuildTx era) <-
shelleyBasedEraConstraints era $ H.forAll $ genValidTxBody era
-- Convert ledger body back via 'getTxBodyContent' and 'fromLedgerTxBody'
let (TxBody content') = body
let content' = getTxBodyContent body
matchTxOuts (txOuts content) (txOuts content')
where
matchTxOuts :: MonadTest m => [TxOut CtxTx era] -> [TxOut CtxTx era] -> m ()
Expand Down Expand Up @@ -84,9 +84,8 @@ prop_roundtrip_txbodycontent_conway_fields = H.property $ do
let sbe = ShelleyBasedEraConway
(body, content) <- H.forAll $ genValidTxBody sbe
-- Convert ledger body back via 'getTxBodyContent' and 'fromLedgerTxBody'
let (TxBody content') = body

let proposals = getProposalProcedures . unFeatured <$> txProposalProcedures content
let content' = getTxBodyContent body
proposals = getProposalProcedures . unFeatured <$> txProposalProcedures content
proposals' = getProposalProcedures . unFeatured <$> txProposalProcedures content'
votes = getVotingProcedures . unFeatured <$> txVotingProcedures content
votes' = getVotingProcedures . unFeatured <$> txVotingProcedures content'
Expand Down

0 comments on commit 7f8d417

Please sign in to comment.