Skip to content

Commit f80706b

Browse files
authored
Merge pull request #728 from IntersectMBO/smelc/remove-patterns
Deprecate some patterns, remove their internal use
2 parents b6252fa + 7f8d417 commit f80706b

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

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

Lines changed: 2 additions & 0 deletions
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/Governance/Poll.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{-# LANGUAGE ScopedTypeVariables #-}
88
{-# LANGUAGE TypeApplications #-}
99
{-# LANGUAGE TypeFamilies #-}
10-
{-# LANGUAGE ViewPatterns #-}
1110

1211
-- | An API for driving on-chain poll for SPOs.
1312
--
@@ -341,12 +340,13 @@ verifyPollAnswer
341340
:: GovernancePoll
342341
-> InAnyShelleyBasedEra Tx
343342
-> Either GovernancePollError [Hash PaymentKey]
344-
verifyPollAnswer poll (InAnyShelleyBasedEra _era (getTxBody -> TxBody body)) = do
343+
verifyPollAnswer poll (InAnyShelleyBasedEra _era tx) = do
345344
answer <- extractPollAnswer (txMetadata body)
346345
answer `hasMatchingHash` hashGovernancePoll poll
347346
answer `isAmongAcceptableChoices` govPollAnswers poll
348347
extraKeyWitnesses (txExtraKeyWits body)
349348
where
349+
body = getTxBodyContent $ getTxBody tx
350350
extractPollAnswer = \case
351351
TxMetadataNone ->
352352
Left ErrGovernancePollNoAnswer

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/internal/Cardano/Api/Tx/Body.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,7 @@ createAndValidateTransactionBody
21472147
-> Either TxBodyError (TxBody era)
21482148
createAndValidateTransactionBody = makeShelleyTransactionBody
21492149

2150+
{-# DEPRECATED TxBody "Use getTxBodyContent $ getTxBody instead" #-}
21502151
pattern TxBody :: TxBodyContent ViewTx era -> TxBody era
21512152
pattern TxBody txbodycontent <- (getTxBodyContent -> txbodycontent)
21522153

cardano-api/internal/Cardano/Api/Tx/Sign.hs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ module Cardano.Api.Tx.Sign
5252
-- * Data family instances
5353
, AsType
5454
( AsTx
55-
, AsByronTx
56-
, AsShelleyTx
5755
, AsMaryTx
5856
, AsAllegraTx
5957
, AsAlonzoTx
@@ -185,18 +183,6 @@ instance HasTypeProxy era => HasTypeProxy (Tx era) where
185183
data AsType (Tx era) = AsTx (AsType era)
186184
proxyToAsType _ = AsTx (proxyToAsType (Proxy :: Proxy era))
187185

188-
{-# DEPRECATED AsByronTx "Use AsTx AsByronEra instead." #-}
189-
pattern AsByronTx :: AsType (Tx ByronEra)
190-
pattern AsByronTx = AsTx AsByronEra
191-
192-
{-# COMPLETE AsByronTx #-}
193-
194-
{-# DEPRECATED AsShelleyTx "Use AsTx AsShelleyEra instead." #-}
195-
pattern AsShelleyTx :: AsType (Tx ShelleyEra)
196-
pattern AsShelleyTx = AsTx AsShelleyEra
197-
198-
{-# COMPLETE AsShelleyTx #-}
199-
200186
pattern AsMaryTx :: AsType (Tx MaryEra)
201187
pattern AsMaryTx = AsTx AsMaryEra
202188

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
22
{-# LANGUAGE LambdaCase #-}
33
{-# LANGUAGE TypeFamilies #-}
4-
{-# LANGUAGE ViewPatterns #-}
54

65
-- | Metadata embedded in transactions
76
module Cardano.Api.TxMetadata
@@ -461,12 +460,14 @@ metadataFromJson schema =
461460
return (k', v')
462461

463462
convTopLevelKey :: Aeson.Key -> Either TxMetadataJsonError Word64
464-
convTopLevelKey (Aeson.toText -> k) =
463+
convTopLevelKey key =
465464
case parseAll (pUnsigned <* Atto.endOfInput) k of
466465
Just n
467466
| n <= fromIntegral (maxBound :: Word64) ->
468467
Right (fromIntegral n)
469468
_ -> Left (TxMetadataJsonToplevelBadKey k)
469+
where
470+
k = Aeson.toText key
470471

471472
validateMetadataValue :: TxMetadataValue -> Either TxMetadataRangeError ()
472473
validateMetadataValue v =

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
77
{-# LANGUAGE TypeFamilies #-}
8-
{-# LANGUAGE ViewPatterns #-}
98

109
-- | Currency values
1110
module Cardano.Api.Value
@@ -387,13 +386,15 @@ instance FromJSON ValueNestedRep where
387386
where
388387
parsePid :: (Aeson.Key, Aeson.Value) -> Parser ValueNestedBundle
389388
parsePid ("lovelace", q) = ValueNestedBundleAda <$> parseJSON q
390-
parsePid (Aeson.toText -> pid, quantityBundleJson) = do
389+
parsePid (key, quantityBundleJson) = do
391390
sHash <-
392391
failEitherWith
393392
(\e -> "Failure when deserialising PolicyId: " ++ displayError e)
394393
$ deserialiseFromRawBytesHex AsScriptHash
395394
$ Text.encodeUtf8 pid
396395
ValueNestedBundle (PolicyId sHash) <$> parseJSON quantityBundleJson
396+
where
397+
pid = Aeson.toText key
397398

398399
-- ----------------------------------------------------------------------------
399400
-- Printing and pretty-printing

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)