Skip to content

Commit c2becc7

Browse files
Soupstrawlehins
andcommitted
Update eras/babbage/impl/src/Cardano/Ledger/Babbage/Translation.hs
Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
1 parent 3028227 commit c2becc7

File tree

13 files changed

+194
-205
lines changed

13 files changed

+194
-205
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.9.0.0
44

5+
* Add `invalidBeforeL`, `invalidHereAfterL`
56
* Add `basicAllegraTxBody`
67
* Add `TxLevel` argument to `Tx` and `TxBody`
78
* Add `HasEraTxLevel` instances for `Tx` and `TxBody`

eras/allegra/impl/src/Cardano/Ledger/Allegra/Scripts.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module Cardano.Ledger.Allegra.Scripts (
5555
upgradeMultiSig,
5656
lteNegInfty,
5757
ltePosInfty,
58+
invalidBeforeL,
59+
invalidHereAfterL,
5860
) where
5961

6062
import Cardano.Ledger.Allegra.Era (AllegraEra)
@@ -109,6 +111,7 @@ import Data.Sequence.Strict as Seq (StrictSeq (Empty, (:<|)))
109111
import qualified Data.Sequence.Strict as SSeq
110112
import qualified Data.Set as Set (Set, member)
111113
import GHC.Generics (Generic)
114+
import Lens.Micro (Lens', lens)
112115
import NoThunks.Class (NoThunks (..))
113116

114117
-- | ValidityInterval is a half open interval. Closed on the bottom, open on the top.
@@ -119,6 +122,32 @@ data ValidityInterval = ValidityInterval
119122
}
120123
deriving (Ord, Eq, Generic, Show, NoThunks, NFData)
121124

125+
-- | Lens to access the 'invalidBefore' field of a 'ValidityInterval' as a 'Maybe SlotNo'.
126+
invalidBeforeL :: Lens' ValidityInterval (Maybe SlotNo)
127+
invalidBeforeL = lens g s
128+
where
129+
g :: ValidityInterval -> Maybe SlotNo
130+
g (ValidityInterval ma _) =
131+
case ma of
132+
SNothing -> Nothing
133+
SJust a -> Just a
134+
135+
s :: ValidityInterval -> Maybe SlotNo -> ValidityInterval
136+
s (ValidityInterval _ b) a = ValidityInterval (maybe SNothing SJust a) b
137+
138+
-- | Lens to access the 'invalidHereAfter' field of a 'ValidityInterval' as a 'Maybe SlotNo'.
139+
invalidHereAfterL :: Lens' ValidityInterval (Maybe SlotNo)
140+
invalidHereAfterL = lens g s
141+
where
142+
g :: ValidityInterval -> Maybe SlotNo
143+
g (ValidityInterval _ mb) =
144+
case mb of
145+
SNothing -> Nothing
146+
SJust b -> Just b
147+
148+
s :: ValidityInterval -> Maybe SlotNo -> ValidityInterval
149+
s (ValidityInterval ma _) = ValidityInterval ma . maybe SNothing SJust
150+
122151
encodeVI :: ValidityInterval -> Encode ('Closed 'Dense) ValidityInterval
123152
encodeVI (ValidityInterval f t) = Rec ValidityInterval !> To f !> To t
124153

eras/allegra/impl/src/Cardano/Ledger/Allegra/Translation.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut)
3131
import Cardano.Ledger.Shelley.TxWits (ShelleyTxWits)
3232
import Data.Coerce (coerce)
3333
import qualified Data.Map.Strict as Map
34-
import Data.Typeable (Typeable)
3534

3635
--------------------------------------------------------------------------------
3736
-- Translation from Shelley to Allegra
@@ -72,8 +71,8 @@ instance TranslateEra AllegraEra NewEpochState where
7271
stashedAVVMAddresses = ()
7372
}
7473

75-
instance Typeable l => TranslateEra AllegraEra (Tx l) where
76-
type TranslationError AllegraEra (Tx l) = DecoderError
74+
instance TranslateEra AllegraEra (Tx TopTx) where
75+
type TranslationError AllegraEra (Tx TopTx) = DecoderError
7776
translateEra _ctx = translateEraThroughCBOR "ShelleyTx"
7877

7978
--------------------------------------------------------------------------------

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ type ScriptIntegrityHash = SafeHash EraIndependentScriptIntegrity
127127
class (MaryEraTxBody era, AlonzoEraTxOut era) => AlonzoEraTxBody era where
128128
collateralInputsTxBodyL :: Lens' (TxBody TopTx era) (Set TxIn)
129129

130-
reqSignerHashesTxBodyL :: AtMostEra "Conway" era => Lens' (TxBody l era) (Set (KeyHash 'Witness))
130+
reqSignerHashesTxBodyL :: AtMostEra "Conway" era => Lens' (TxBody l era) (Set (KeyHash 'Guard))
131131

132132
reqSignerHashesTxBodyG ::
133133
SimpleGetter (TxBody l era) (Set (KeyHash Guard))

eras/babbage/impl/src/Cardano/Ledger/Babbage/Translation.hs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE DerivingStrategies #-}
22
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
34
{-# LANGUAGE LambdaCase #-}
45
{-# LANGUAGE MultiParamTypeClasses #-}
56
{-# LANGUAGE OverloadedStrings #-}
@@ -28,7 +29,6 @@ import Cardano.Ledger.Shelley.LedgerState (
2829
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..))
2930
import Data.Coerce (coerce)
3031
import qualified Data.Map.Strict as Map
31-
import Data.Typeable (Typeable)
3232
import Lens.Micro
3333

3434
--------------------------------------------------------------------------------
@@ -59,25 +59,24 @@ instance TranslateEra BabbageEra NewEpochState where
5959
, stashedAVVMAddresses = ()
6060
}
6161

62-
instance Typeable l => TranslateEra BabbageEra (Tx l) where
63-
type TranslationError BabbageEra (Tx l) = DecoderError
62+
instance TranslateEra BabbageEra (Tx TopTx) where
63+
type TranslationError BabbageEra (Tx TopTx) = DecoderError
6464
translateEra _ctxt tx =
65-
withTopTxLevelOnly tx $ \tx' ->
66-
do
67-
-- Note that this does not preserve the hidden bytes field of the transaction.
68-
-- This is under the premise that this is irrelevant for TxInBlocks, which are
69-
-- not transmitted as contiguous chunks.
70-
txBody <- translateEraThroughCBOR "TxBody" $ tx' ^. bodyTxL
71-
txWits <- translateEraThroughCBOR "TxWitness" $ tx' ^. witsTxL
72-
auxData <- case tx' ^. auxDataTxL of
73-
SNothing -> pure SNothing
74-
SJust auxData -> SJust <$> translateEraThroughCBOR "AuxData" auxData
75-
let validating = tx' ^. isValidTxL
76-
pure . asSTxTopLevel $
77-
mkBasicTx txBody
78-
& witsTxL .~ txWits
79-
& auxDataTxL .~ auxData
80-
& isValidTxL .~ validating
65+
withTopTxLevelOnly tx $ \tx' -> do
66+
-- Note that this does not preserve the hidden bytes field of the transaction.
67+
-- This is under the premise that this is irrelevant for TxInBlocks, which are
68+
-- not transmitted as contiguous chunks.
69+
txBody <- translateEraThroughCBOR "TxBody" $ tx' ^. bodyTxL
70+
txWits <- translateEraThroughCBOR "TxWitness" $ tx' ^. witsTxL
71+
auxData <- case tx' ^. auxDataTxL of
72+
SNothing -> pure SNothing
73+
SJust auxData -> SJust <$> translateEraThroughCBOR "AuxData" auxData
74+
let validating = tx' ^. isValidTxL
75+
pure . asSTxTopLevel $
76+
mkBasicTx txBody
77+
& witsTxL .~ txWits
78+
& auxDataTxL .~ auxData
79+
& isValidTxL .~ validating
8180

8281
--------------------------------------------------------------------------------
8382
-- Auxiliary instances and functions

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,9 @@ ledgerTransition ::
365365
, State (EraRule "UTXOW" era) ~ UTxOState era
366366
, State (EraRule "CERTS" era) ~ CertState era
367367
, State (EraRule "GOV" era) ~ Proposals era
368-
, State (someLEDGER era) ~ LedgerState era
369368
, Environment (EraRule "UTXOW" era) ~ UtxoEnv era
370369
, Environment (EraRule "GOV" era) ~ GovEnv era
371370
, Environment (EraRule "CERTS" era) ~ CertsEnv era
372-
, Environment (someLEDGER era) ~ LedgerEnv era
373371
, Signal (EraRule "UTXOW" era) ~ Tx TopTx era
374372
, Signal (EraRule "CERTS" era) ~ Seq (TxCert era)
375373
, Signal (EraRule "GOV" era) ~ GovSignal era
@@ -378,7 +376,6 @@ ledgerTransition ::
378376
, ConwayEraCertState era
379377
, EraRule "LEDGER" era ~ someLEDGER era
380378
, InjectRuleFailure "LEDGER" ShelleyLedgerPredFailure era
381-
, PredicateFailure (someLEDGER era) ~ ConwayLedgerPredFailure era
382379
) =>
383380
TransitionRule (someLEDGER era)
384381
ledgerTransition = do

eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/Translation.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE FlexibleInstances #-}
12
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE MultiParamTypeClasses #-}
34
{-# LANGUAGE NamedFieldPuns #-}
@@ -50,13 +51,12 @@ import Cardano.Ledger.Shelley.LedgerState (
5051
import Data.Coerce (coerce)
5152
import Data.Default (Default (..))
5253
import qualified Data.Map.Strict as Map
53-
import Data.Typeable (Typeable)
5454
import Lens.Micro ((&), (.~), (^.))
5555

5656
type instance TranslationContext DijkstraEra = DijkstraGenesis
5757

58-
instance Typeable l => TranslateEra DijkstraEra (Tx l) where
59-
type TranslationError DijkstraEra (Tx l) = DecoderError
58+
instance TranslateEra DijkstraEra (Tx TopTx) where
59+
type TranslationError DijkstraEra (Tx TopTx) = DecoderError
6060
translateEra _ctxt tx = case toSTxLevel tx of
6161
STopTxOnly -> do
6262
-- Note that this does not preserve the hidden bytes field of the transaction.

eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/Tx.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Cardano.Ledger.Binary (
4444
decodeNullMaybe,
4545
encodeListLen,
4646
encodeNullMaybe,
47+
encodeNullStrictMaybe,
4748
serialize,
4849
)
4950
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<*!))
@@ -335,10 +336,10 @@ toCBORForMempoolSubmission = \case
335336
!> To dtBody
336337
!> To dtWits
337338
!> To dtIsValid
338-
!> E (encodeNullMaybe encCBOR . strictMaybeToMaybe) dtAuxData
339+
!> E (encodeNullStrictMaybe encCBOR) dtAuxData
339340
DijkstraSubTx {dstBody, dstWits, dstAuxData} ->
340341
encode $
341342
Rec DijkstraSubTx
342343
!> To dstBody
343344
!> To dstWits
344-
!> E (encodeNullMaybe encCBOR . strictMaybeToMaybe) dstAuxData
345+
!> E (encodeNullStrictMaybe encCBOR) dstAuxData

0 commit comments

Comments
 (0)