@@ -32,9 +32,11 @@ import qualified Cardano.Crypto.Hash as Hash
3232import Cardano.Ledger.Alonzo.Era
3333import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx (.. ), IsValid (.. ), alonzoSegwitTx )
3434import Cardano.Ledger.Binary (
35+ Annotated (.. ),
3536 Annotator ,
3637 DecCBOR (.. ),
3738 EncCBORGroup (.. ),
39+ decodeAnnotated ,
3840 encCBOR ,
3941 encodeFoldableEncoder ,
4042 encodeFoldableMapEncoder ,
@@ -44,14 +46,14 @@ import Cardano.Ledger.Binary (
4446 withSlice ,
4547 )
4648import Cardano.Ledger.Core
47- import Cardano.Ledger.Shelley.BlockChain (constructMetadata )
49+ import Cardano.Ledger.Shelley.BlockChain (constructMetadata , indexLookupSeq )
4850import Control.Monad (unless )
4951import Data.ByteString (ByteString )
5052import Data.ByteString.Builder (shortByteString , toLazyByteString )
5153import qualified Data.ByteString.Lazy as BSL
5254import Data.Coerce (coerce )
5355import qualified Data.Map.Strict as Map
54- import Data.Maybe.Strict (strictMaybeToMaybe )
56+ import Data.Maybe.Strict (maybeToStrictMaybe , strictMaybeToMaybe )
5557import Data.Proxy (Proxy (.. ))
5658import qualified Data.Sequence as Seq
5759import Data.Sequence.Strict (StrictSeq )
@@ -230,6 +232,65 @@ instance AlonzoEraTx era => DecCBOR (Annotator (AlonzoTxSeq era)) where
230232 <*> auxDataAnn
231233 <*> isValAnn
232234
235+ instance
236+ ( AlonzoEraTx era
237+ , DecCBOR (TxBody era )
238+ , DecCBOR (TxWits era )
239+ , DecCBOR (TxAuxData era )
240+ ) =>
241+ DecCBOR (AlonzoTxSeq era )
242+ where
243+ decCBOR = do
244+ Annotated bodies bodiesBs <- decodeAnnotated decCBOR
245+ Annotated wits witsBs <- decodeAnnotated decCBOR
246+ Annotated auxDataMap auxDataBs <- decodeAnnotated decCBOR
247+ let b = length bodies
248+ inRange x = (0 <= x) && (x <= (b - 1 ))
249+ w = length wits
250+ unless
251+ (all inRange (Map. keysSet auxDataMap))
252+ ( fail
253+ ( " Some Auxiliarydata index is not in the range: 0 .. "
254+ ++ show (b - 1 )
255+ )
256+ )
257+ let auxData = maybeToStrictMaybe <$> indexLookupSeq b auxDataMap
258+ Annotated isValidIdxs isValidBs <- decodeAnnotated decCBOR
259+ let vs = alignedValidFlags b isValidIdxs
260+ unless
261+ (b == w)
262+ ( fail $
263+ " different number of transaction bodies ("
264+ <> show b
265+ <> " ) and witness sets ("
266+ <> show w
267+ <> " )"
268+ )
269+ unless
270+ (all inRange isValidIdxs)
271+ ( fail
272+ ( " Some IsValid index is not in the range: 0 .. "
273+ ++ show (b - 1 )
274+ ++ " , "
275+ ++ show isValidIdxs
276+ )
277+ )
278+ let mkTx body wt isValid ad =
279+ mkBasicTx body
280+ & witsTxL .~ wt
281+ & auxDataTxL .~ ad
282+ & isValidTxL .~ isValid
283+ let txs =
284+ StrictSeq. forceToStrict $
285+ Seq. zipWith4 mkTx bodies wits vs auxData
286+ pure $
287+ AlonzoTxSeqRaw
288+ txs
289+ bodiesBs
290+ witsBs
291+ auxDataBs
292+ isValidBs
293+
233294--------------------------------------------------------------------------------
234295-- Internal utility functions
235296--------------------------------------------------------------------------------
0 commit comments