Skip to content

Commit 0e25624

Browse files
committed
Block.hs: deprecate patterns and remove internal usage
1 parent 93da8ad commit 0e25624

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

cardano-api/internal/Cardano/Api/Block.hs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Cardano.Api.Block
1919
, pattern Block
2020
, BlockHeader (..)
2121
, getBlockHeader
22+
, getBlockTxs
2223

2324
-- ** Blocks in the context of a consensus mode
2425
, BlockInMode (..)
@@ -99,6 +100,7 @@ data Block era where
99100
-> Block era
100101

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

cardano-api/internal/Cardano/Api/LedgerState.hs

+10-6
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ foldBlocks nodeConfigFilePath socketPath validationMode state0 accumulate = hand
540540
-> CSP.ClientStNext n BlockInMode ChainPoint ChainTip IO ()
541541
clientNextN n knownLedgerStates =
542542
CSP.ClientStNext
543-
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode _ (Block (BlockHeader slotNo _ currBlockNo) _)) serverChainTip -> do
543+
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode _ block) serverChainTip -> do
544544
let newLedgerStateE =
545545
applyBlock
546546
env
@@ -554,7 +554,8 @@ foldBlocks nodeConfigFilePath socketPath validationMode state0 accumulate = hand
554554
case newLedgerStateE of
555555
Left err -> clientIdle_DoneNwithMaybeError n (Just err)
556556
Right newLedgerState -> do
557-
let (knownLedgerStates', committedStates) = pushLedgerState env knownLedgerStates slotNo newLedgerState blockInMode
557+
let BlockHeader slotNo _ currBlockNo = getBlockHeader block
558+
(knownLedgerStates', committedStates) = pushLedgerState env knownLedgerStates slotNo newLedgerState blockInMode
558559
newClientTip = At currBlockNo
559560
newServerTip = fromChainTip serverChainTip
560561

@@ -729,9 +730,10 @@ chainSyncClientWithLedgerState env ledgerState0 validationMode (CS.ChainSyncClie
729730
)
730731
goClientStNext (Right history) (CS.ClientStNext recvMsgRollForward recvMsgRollBackward) =
731732
CS.ClientStNext
732-
( \blkInMode@(BlockInMode _ (Block (BlockHeader slotNo _ _) _)) tip ->
733+
( \blkInMode@(BlockInMode _ block) tip ->
733734
CS.ChainSyncClient $
734735
let
736+
BlockHeader slotNo _ _ = getBlockHeader block
735737
newLedgerStateE = case Seq.lookup 0 history of
736738
Nothing -> error "Impossible! History should always be non-empty"
737739
Just (_, Left err, _) -> Left err
@@ -875,8 +877,9 @@ chainSyncClientPipelinedWithLedgerState env ledgerState0 validationMode (CSP.Cha
875877
)
876878
goClientStNext (Right history) n (CSP.ClientStNext recvMsgRollForward recvMsgRollBackward) =
877879
CSP.ClientStNext
878-
( \blkInMode@(BlockInMode _ (Block (BlockHeader slotNo _ _) _)) tip ->
880+
( \blkInMode@(BlockInMode _ block) tip ->
879881
let
882+
BlockHeader slotNo _ _ = getBlockHeader block
880883
newLedgerStateE = case Seq.lookup 0 history of
881884
Nothing -> error "Impossible! History should always be non-empty"
882885
Just (_, Left err, _) -> Left err
@@ -2173,8 +2176,9 @@ foldEpochState nodeConfigFilePath socketPath validationMode terminationEpoch ini
21732176
-> CSP.ClientStNext n BlockInMode ChainPoint ChainTip IO ()
21742177
clientNextN n knownLedgerStates =
21752178
CSP.ClientStNext
2176-
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode era (Block (BlockHeader slotNo _ currBlockNo) _)) serverChainTip -> do
2177-
let newLedgerStateE =
2179+
{ CSP.recvMsgRollForward = \blockInMode@(BlockInMode era block) serverChainTip -> do
2180+
let BlockHeader slotNo _ currBlockNo = getBlockHeader block
2181+
newLedgerStateE =
21782182
applyBlock
21792183
env
21802184
( maybe

cardano-api/src/Cardano/Api.hs

-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ module Cardano.Api
267267

268268
-- ** Blocks in the context of an era
269269
, Block (..)
270-
, pattern Block
271270
, BlockHeader (..)
272271
, getBlockHeader
273272

cardano-api/test/cardano-api-test/Test/Cardano/Api/TxBody.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ prop_roundtrip_txbodycontent_txouts era = H.property $ do
3535
(body, content :: TxBodyContent BuildTx era) <-
3636
shelleyBasedEraConstraints era $ H.forAll $ genValidTxBody era
3737
-- Convert ledger body back via 'getTxBodyContent' and 'fromLedgerTxBody'
38-
let (TxBody content') = body
38+
let content' = getTxBodyContent body
3939
matchTxOuts (txOuts content) (txOuts content')
4040
where
4141
matchTxOuts :: MonadTest m => [TxOut CtxTx era] -> [TxOut CtxTx era] -> m ()
@@ -84,9 +84,8 @@ prop_roundtrip_txbodycontent_conway_fields = H.property $ do
8484
let sbe = ShelleyBasedEraConway
8585
(body, content) <- H.forAll $ genValidTxBody sbe
8686
-- Convert ledger body back via 'getTxBodyContent' and 'fromLedgerTxBody'
87-
let (TxBody content') = body
88-
89-
let proposals = getProposalProcedures . unFeatured <$> txProposalProcedures content
87+
let content' = getTxBodyContent body
88+
proposals = getProposalProcedures . unFeatured <$> txProposalProcedures content
9089
proposals' = getProposalProcedures . unFeatured <$> txProposalProcedures content'
9190
votes = getVotingProcedures . unFeatured <$> txVotingProcedures content
9291
votes' = getVotingProcedures . unFeatured <$> txVotingProcedures content'

0 commit comments

Comments
 (0)