Skip to content

Commit c72b2c0

Browse files
committed
Block.hs: remove ViewPattern and PatternSynonym
1 parent cd45792 commit c72b2c0

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE LambdaCase #-}
66
{-# LANGUAGE NamedFieldPuns #-}
7-
{-# LANGUAGE PatternSynonyms #-}
87
{-# LANGUAGE RankNTypes #-}
98
{-# LANGUAGE ScopedTypeVariables #-}
109
{-# LANGUAGE StandaloneDeriving #-}
1110
{-# LANGUAGE TypeFamilies #-}
1211
{-# LANGUAGE TypeOperators #-}
13-
{-# LANGUAGE ViewPatterns #-}
1412

1513
-- | Blocks in the blockchain
1614
module Cardano.Api.Block
1715
( -- * Blocks in the context of an era
1816
Block (..)
19-
, pattern Block
2017
, BlockHeader (..)
2118
, getBlockHeader
19+
, getBlockTxs
2220

2321
-- ** Blocks in the context of a consensus mode
2422
, BlockInMode (..)
@@ -98,15 +96,6 @@ data Block era where
9896
-> Consensus.ShelleyBlock (ConsensusProtocol era) (ShelleyLedgerEra era)
9997
-> Block era
10098

101-
-- | A block consists of a header and a body containing transactions.
102-
pattern Block :: BlockHeader -> [Tx era] -> Block era
103-
pattern Block header txs <- (getBlockHeaderAndTxs -> (header, txs))
104-
105-
{-# COMPLETE Block #-}
106-
107-
getBlockHeaderAndTxs :: Block era -> (BlockHeader, [Tx era])
108-
getBlockHeaderAndTxs block = (getBlockHeader block, getBlockTxs block)
109-
11099
-- The GADT in the ShelleyBlock case requires a custom instance
111100
instance Show (Block era) where
112101
showsPrec p (ByronBlock block) =

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

Lines changed: 10 additions & 6 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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)