Skip to content

Commit 1258f44

Browse files
authored
Merge pull request #5413 from IntersectMBO/td/nested-tx-deserializer
Subtransactions CBOR deserializer
2 parents b4a2b3a + 3735a92 commit 1258f44

File tree

13 files changed

+381
-118
lines changed

13 files changed

+381
-118
lines changed

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

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import Cardano.Ledger.Binary (
8080
decodeMapLenOrIndef,
8181
decodeMapLikeEnforceNoDuplicates,
8282
decodeNonEmptyList,
83-
decodeSetLikeEnforceNoDuplicates,
83+
decodeNonEmptySetLikeEnforceNoDuplicatesAnn,
8484
encodeFoldableEncoder,
8585
encodeListLen,
8686
encodeTag,
@@ -317,18 +317,10 @@ noDuplicateNonEmptySetAsMapDecoderAnn ::
317317
(Ord k, DecCBOR (Annotator a)) =>
318318
(a -> (k, v)) ->
319319
Decoder s (Annotator (Map k v))
320-
noDuplicateNonEmptySetAsMapDecoderAnn toKV = do
321-
allowTag setTag
322-
vals <- decodeList decCBOR
323-
pure $ go (Map.empty, 0) vals
324-
where
325-
go (m, n) []
326-
| Map.null m = fail "Empty script Set is not allowed"
327-
| length m /= n = fail "Duplicate elements in the scripts Set were encountered"
328-
| otherwise = pure m
329-
go (!m, !n) (x : xs) = do
330-
(k, v) <- toKV <$> x
331-
go (Map.insert k v m, n + 1) xs
320+
noDuplicateNonEmptySetAsMapDecoderAnn toKV =
321+
decodeNonEmptySetLikeEnforceNoDuplicatesAnn
322+
(\x m -> let (k, v) = toKV x in Map.insert k v m)
323+
(\m -> (Map.size m, m))
332324
{-# INLINE noDuplicateNonEmptySetAsMapDecoderAnn #-}
333325

334326
instance Era era => DecCBOR (Annotator (TxDatsRaw era)) where
@@ -611,18 +603,21 @@ instance
611603
txWitnessField
612604
[]
613605
where
614-
addrWitsSetDecoder :: (Ord a, DecCBOR a) => Decoder s (Annotator (Set a))
615-
addrWitsSetDecoder =
616-
pure <$> do
617-
let
618-
nonEmptyDecoder = do
619-
allowTag setTag
620-
Set.fromList . NE.toList <$> decodeNonEmptyList decCBOR
621-
nonEmptyNoDuplicatesDecoder = do
622-
s <- decodeSetLikeEnforceNoDuplicates Set.insert (\s -> (length s, s)) decCBOR
623-
when (Set.null s) $ fail "Set cannot be empty"
624-
pure s
625-
ifDecoderVersionAtLeast (natVersion @12) nonEmptyNoDuplicatesDecoder nonEmptyDecoder
606+
addrWitsSetDecoder ::
607+
(Ord a, DecCBOR (Annotator a), DecCBOR a) => Decoder s (Annotator (Set a))
608+
addrWitsSetDecoder = do
609+
let
610+
nonEmptyDecoder = do
611+
allowTag setTag
612+
s <- Set.fromList . NE.toList <$> decodeNonEmptyList decCBOR
613+
pure $ pure s
614+
615+
nonEmptyNoDuplicatesDecoder =
616+
decodeNonEmptySetLikeEnforceNoDuplicatesAnn
617+
Set.insert
618+
(\s -> (Set.size s, s))
619+
620+
ifDecoderVersionAtLeast (natVersion @12) nonEmptyNoDuplicatesDecoder nonEmptyDecoder
626621
{-# INLINE addrWitsSetDecoder #-}
627622

628623
txWitnessField :: Word -> Field (Annotator (AlonzoTxWitsRaw era))

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/Annotator.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ instance
141141
auxDataField 2 = field (addPlutusScripts PlutusV1) (D (guardPlutus PlutusV1 >> decCBOR))
142142
auxDataField 3 = field (addPlutusScripts PlutusV2) (D (guardPlutus PlutusV2 >> decCBOR))
143143
auxDataField 4 = field (addPlutusScripts PlutusV3) (D (guardPlutus PlutusV3 >> decCBOR))
144+
auxDataField 5 = field (addPlutusScripts PlutusV4) (D (guardPlutus PlutusV4 >> decCBOR))
144145
auxDataField n = invalidField n
145146

146147
deriving newtype instance (Era era, DecCBOR (NativeScript era)) => DecCBOR (AlonzoTxAuxData era)

eras/dijkstra/impl/cardano-ledger-dijkstra.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ test-suite tests
205205
cardano-ledger-alonzo,
206206
cardano-ledger-babbage:testlib,
207207
cardano-ledger-binary:testlib,
208-
cardano-ledger-conway,
208+
cardano-ledger-conway:{cardano-ledger-conway, testlib},
209209
cardano-ledger-core:{cardano-ledger-core, testlib},
210210
cardano-ledger-dijkstra:{cardano-ledger-dijkstra, testlib},
211211
cardano-ledger-shelley:testlib,

0 commit comments

Comments
 (0)