Skip to content

Commit

Permalink
Switch Conway TxDats witnesses to use a set tag 258
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Jan 24, 2024
1 parent cbc84a0 commit f26eab5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import Cardano.Ledger.Binary (
Decoder,
EncCBOR (..),
EncCBORGroup (..),
Encoding,
ToCBOR (..),
allowTag,
decodeList,
Expand Down Expand Up @@ -275,14 +276,14 @@ isEmptyTxWitness (getMemoRawType -> AlonzoTxWitsRaw a b c d (Redeemers e)) =
Set.null a && Set.null b && Map.null c && nullDats d && Map.null e

-- =====================================================
newtype TxDatsRaw era = TxDatsRaw (Map (DataHash (EraCrypto era)) (Data era))
newtype TxDatsRaw era = TxDatsRaw {unTxDatsRaw :: Map (DataHash (EraCrypto era)) (Data era)}
deriving (Generic, Typeable, Eq)
deriving newtype (NoThunks, NFData)

deriving instance HashAlgorithm (HASH (EraCrypto era)) => Show (TxDatsRaw era)

instance (Typeable era, EncCBOR (Data era)) => EncCBOR (TxDatsRaw era) where
encCBOR (TxDatsRaw m) = encCBOR $ Map.elems m
encCBOR = encodeWithSetTag . Map.elems . unTxDatsRaw

pattern TxDats' :: Map (DataHash (EraCrypto era)) (Data era) -> TxDats era
pattern TxDats' m <- (getMemoRawType -> TxDatsRaw m)
Expand All @@ -306,7 +307,11 @@ instance Era era => DecCBOR (Annotator (TxDatsRaw era)) where
decCBOR =
ifDecoderVersionAtLeast
(natVersion @9)
(mapTraverseableDecoderA (decodeNonEmptyList decCBOR) (TxDatsRaw . keyBy hashData . NE.toList))
( allowTag setTag
>> mapTraverseableDecoderA
(decodeNonEmptyList decCBOR)
(TxDatsRaw . keyBy hashData . NE.toList)
)
(mapTraverseableDecoderA (decodeList decCBOR) (TxDatsRaw . keyBy hashData))
{-# INLINE decCBOR #-}

Expand Down Expand Up @@ -508,11 +513,6 @@ instance AlonzoEraScript era => EncCBOR (AlonzoTxWitsRaw era) where
!> Omit nullDats (Key 4 $ To dats)
!> Omit nullRedeemers (Key 5 $ To rdmrs)
where
encodeWithSetTag xs =
ifEncodingVersionAtLeast
(natVersion @9)
(encodeTag setTag <> encCBOR xs)
(encCBOR xs)
encodePlutus ::
PlutusLanguage l =>
SLanguage l ->
Expand Down Expand Up @@ -700,3 +700,10 @@ mapTraverseableDecoderA ::
(f a -> m b) ->
Decoder s (Annotator (m b))
mapTraverseableDecoderA decList transformList = fmap transformList . sequence <$> decList

encodeWithSetTag :: EncCBOR a => a -> Encoding
encodeWithSetTag xs =
ifEncodingVersionAtLeast
(natVersion @9)
(encodeTag setTag <> encCBOR xs)
(encCBOR xs)
2 changes: 1 addition & 1 deletion eras/conway/impl/cddl-files/conway.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ transaction_witness_set =
, ? 1: nonempty_set<native_script>
, ? 2: nonempty_set<bootstrap_witness>
, ? 3: nonempty_set<plutus_v1_script>
, ? 4: [+ plutus_data ]
, ? 4: nonempty_set<plutus_data>
, ? 5: redeemers
, ? 6: nonempty_set<plutus_v2_script>
, ? 7: nonempty_set<plutus_v3_script>
Expand Down

0 comments on commit f26eab5

Please sign in to comment.