4
4
{-# LANGUAGE DerivingVia #-}
5
5
{-# LANGUAGE FlexibleContexts #-}
6
6
{-# LANGUAGE FlexibleInstances #-}
7
+ {-# LANGUAGE InstanceSigs #-}
7
8
{-# LANGUAGE MultiParamTypeClasses #-}
8
9
{-# LANGUAGE OverloadedStrings #-}
9
10
{-# LANGUAGE PatternSynonyms #-}
@@ -39,11 +40,13 @@ import Cardano.Ledger.BaseTypes (
39
40
strictMaybeToMaybe ,
40
41
)
41
42
import Cardano.Ledger.Binary (
43
+ Annotated (.. ),
42
44
Annotator (.. ),
43
45
DecCBOR (decCBOR ),
44
46
Decoder ,
45
47
EncCBOR (.. ),
46
48
EncCBORGroup (.. ),
49
+ decodeAnnotated ,
47
50
encodeFoldableEncoder ,
48
51
encodeFoldableMapEncoder ,
49
52
encodePreEncoded ,
@@ -52,7 +55,7 @@ import Cardano.Ledger.Binary (
52
55
)
53
56
import Cardano.Ledger.Core
54
57
import Cardano.Ledger.Shelley.Era (ShelleyEra )
55
- import Cardano.Ledger.Shelley.Tx (ShelleyTx , segwitTx )
58
+ import Cardano.Ledger.Shelley.Tx (ShelleyTx , segwitTx , segwitTxXXX )
56
59
import Cardano.Ledger.Slot (SlotNo (.. ))
57
60
import Control.Monad (unless )
58
61
import Data.ByteString (ByteString )
@@ -188,55 +191,104 @@ bbHash (TxSeq' _ bodies wits md) =
188
191
hashPart = Hash. hashToBytes . hashStrict . BSL. toStrict
189
192
190
193
-- | Given a size and a mapping from indices to maybe metadata,
191
- -- return a sequence whose size is the size paramater and
194
+ -- return a sequence whose size is the size parameter and
192
195
-- whose non-Nothing values correspond to the values in the mapping.
193
196
constructMetadata ::
194
- forall era .
195
197
Int ->
196
198
Map Int (Annotator (TxAuxData era )) ->
197
199
Seq (Maybe (Annotator (TxAuxData era )))
198
- constructMetadata n md = fmap (`Map.lookup` md) (Seq. fromList [0 .. n - 1 ])
200
+ constructMetadata = indexLookupSeq
201
+
202
+ indexLookupSeq :: Int -> Map Int a -> Seq (Maybe a )
203
+ indexLookupSeq n md = fmap (`Map.lookup` md) (Seq. fromList [0 .. n - 1 ])
204
+
205
+ instance
206
+ ( EraTx era
207
+ , DecCBOR (TxBody era )
208
+ , DecCBOR (TxWits era )
209
+ , DecCBOR (TxAuxData era )
210
+ ) =>
211
+ DecCBOR (ShelleyTxSeq era )
212
+ where
213
+ decCBOR = do
214
+ Annotated (bodies :: Seq (TxBody era )) bodiesBS <- decodeAnnotated decCBOR
215
+ let b = length bodies
216
+ Annotated (wits :: Seq (TxWits era )) witsBS <- decodeAnnotated decCBOR
217
+ Annotated (metadataMap :: Map Int (TxAuxData era )) metadataBS <-
218
+ decodeAnnotated decCBOR
219
+ let metadata = indexLookupSeq b metadataMap
220
+ let txs = StrictSeq. forceToStrict $ Seq. zipWith3 segwitTxXXX bodies wits metadata
221
+ pure $ TxSeq' txs bodiesBS witsBS metadataBS
199
222
200
223
-- | The parts of the Tx in Blocks that have to have DecCBOR(Annotator x) instances.
201
224
-- These are exactly the parts that are SafeToHash.
202
225
-- | Decode a TxSeq, used in decoding a Block.
226
+ txXXX ::
227
+ forall era .
228
+ ( EraTx era
229
+ , DecCBOR (TxBody era )
230
+ , DecCBOR (TxWits era )
231
+ , DecCBOR (TxAuxData era )
232
+ ) =>
233
+ Bool ->
234
+ forall s .
235
+ Decoder s (Annotator (ShelleyTxSeq era ))
236
+ txXXX _ = do
237
+ d <- decCBOR @ (ShelleyTxSeq era )
238
+ pure undefined
239
+
203
240
txSeqDecoder ::
204
241
forall era .
205
- EraTx era =>
242
+ ( EraTx era
243
+ , DecCBOR (TxBody era )
244
+ , DecCBOR (TxWits era )
245
+ , DecCBOR (TxAuxData era )
246
+ ) =>
206
247
Bool ->
207
248
forall s .
208
249
Decoder s (Annotator (ShelleyTxSeq era ))
209
- txSeqDecoder lax = do
210
- (bodies, bodiesAnn) <- withSlice decCBOR
211
- (wits, witsAnn) <- withSlice decCBOR
212
- let b = length bodies
213
- inRange x = (0 <= x) && (x <= (b - 1 ))
214
- w = length wits
215
- (metadata, metadataAnn) <- withSlice $
216
- do
217
- m <- decCBOR
218
- unless -- TODO this PR introduces this new test, That didn't used to run in the Shelley
219
- (lax || all inRange (Map. keysSet m)) -- Era, Is it possible there might be some blocks, that should have been caught on the chain?
220
- (fail (" Some Auxiliarydata index is not in the range: 0 .. " ++ show (b - 1 )))
221
- pure (constructMetadata @ era b m)
250
+ txSeqDecoder _ = do
251
+ d <- decCBOR @ (ShelleyTxSeq era )
252
+ pure $ pure $ d
222
253
223
- unless
224
- (lax || b == w)
225
- ( fail $
226
- " different number of transaction bodies ("
227
- <> show b
228
- <> " ) and witness sets ("
229
- <> show w
230
- <> " )"
231
- )
254
+ -- txSeqDecoder lax = do
255
+ -- (bodies, bodiesAnn) <- withSlice decCBOR
256
+ -- (wits, witsAnn) <- withSlice decCBOR
257
+ -- let b = length bodies
258
+ -- inRange x = (0 <= x) && (x <= (b - 1))
259
+ -- w = length wits
260
+ -- (metadata, metadataAnn) <- withSlice $
261
+ -- do
262
+ -- m <- decCBOR
263
+ -- unless -- TODO this PR introduces this new test, That didn't used to run in the Shelley
264
+ -- (lax || all inRange (Map.keysSet m)) -- Era, Is it possible there might be some blocks, that should have been caught on the chain?
265
+ -- (fail ("Some Auxiliarydata index is not in the range: 0 .. " ++ show (b - 1)))
266
+ -- pure (constructMetadata @era b m)
232
267
233
- let txns =
234
- sequenceA $
235
- StrictSeq. forceToStrict $
236
- Seq. zipWith3 segwitTx bodies wits metadata
237
- pure $ TxSeq' <$> txns <*> bodiesAnn <*> witsAnn <*> metadataAnn
268
+ -- unless
269
+ -- (lax || b == w)
270
+ -- ( fail $
271
+ -- "different number of transaction bodies ("
272
+ -- <> show b
273
+ -- <> ") and witness sets ("
274
+ -- <> show w
275
+ -- <> ")"
276
+ -- )
238
277
239
- instance EraTx era => DecCBOR (Annotator (ShelleyTxSeq era )) where
278
+ -- let txns =
279
+ -- sequenceA $
280
+ -- StrictSeq.forceToStrict $
281
+ -- Seq.zipWith3 segwitTx bodies wits metadata
282
+ -- pure $ TxSeq' <$> txns <*> bodiesAnn <*> witsAnn <*> metadataAnn
283
+
284
+ instance
285
+ ( EraTx era
286
+ , DecCBOR (TxBody era )
287
+ , DecCBOR (TxWits era )
288
+ , DecCBOR (TxAuxData era )
289
+ ) =>
290
+ DecCBOR (Annotator (ShelleyTxSeq era ))
291
+ where
240
292
decCBOR = txSeqDecoder False
241
293
242
294
slotToNonce :: SlotNo -> Nonce
0 commit comments