@@ -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
334326instance 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 ))
0 commit comments