Skip to content

Commit 3b06fa9

Browse files
committed
Update serialisation procedure
1 parent e5aa7a5 commit 3b06fa9

File tree

3 files changed

+92
-98
lines changed

3 files changed

+92
-98
lines changed

cabal.project

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ source-repository-package
101101
type: git
102102
location: https://github.com/tweag/cardano-canonical-ledger.git
103103
subdir: scls-cbor
104-
tag: 09f2b80d6d0c7419053e3f9e70ff57acbcff0eec
104+
tag: 13672a64a59d3e8f4b3d7549472ae3cccbdaa3ba
105105

106106
source-repository-package
107107
type: git
108108
location: https://github.com/tweag/cardano-canonical-ledger.git
109109
subdir: scls-format
110-
tag: 09f2b80d6d0c7419053e3f9e70ff57acbcff0eec
110+
tag: 13672a64a59d3e8f4b3d7549472ae3cccbdaa3ba
111111

112112
source-repository-package
113113
type: git
114114
location: https://github.com/tweag/cardano-canonical-ledger.git
115115
subdir: merkle-tree-incremental
116-
tag: 09f2b80d6d0c7419053e3f9e70ff57acbcff0eec
116+
tag: 13672a64a59d3e8f4b3d7549472ae3cccbdaa3ba

eras/conway/impl/scls-export/src/Cardano/Ledger/Export/Namespace/UTxO.hs

Lines changed: 77 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE TypeApplications #-}
12
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE StandaloneDeriving #-}
@@ -13,8 +14,6 @@
1314
module Cardano.Ledger.Export.Namespace.UTxO
1415
( UtxoKey(..)
1516
, UtxoOut(..)
16-
, AddrUtxoIn(..)
17-
, ScriptUtxoIn(..)
1817
, Version(..)
1918
, ToCanonicalCBOR(..)
2019
, FromCanonicalCBOR(..)
@@ -26,27 +25,28 @@ import Cardano.SCLS.CBOR.Canonical.Decoder
2625
import qualified Codec.CBOR.Encoding as E
2726
import qualified Codec.CBOR.Decoding as D
2827
import Cardano.Ledger.Conway (ConwayEra)
29-
import Cardano.Ledger.TxIn (TxIn(..))
28+
import Cardano.Ledger.TxIn (TxIn(..), TxId(..))
3029
import Cardano.Ledger.Core (TxOut(..))
31-
-- import Cardano.Ledger.TxOut (TxOut(..))
3230
import Cardano.Ledger.Compactible
3331
import Cardano.Ledger.Address
3432
import Cardano.Ledger.Credential
3533
import Cardano.Ledger.Keys
3634
import Cardano.Ledger.Hashes
3735
import Cardano.Ledger.Plutus.Data (Datum(..))
3836
import Cardano.Ledger.Plutus.Data (BinaryData)
39-
import Cardano.Ledger.Mary (MaryEra, MaryValue)
37+
import Cardano.Ledger.Mary (MaryValue)
38+
import Cardano.Ledger.Coin (Coin)
39+
import qualified Cardano.Ledger.Coin as Coin
4040
import Cardano.SCLS.Internal.Entry
4141
import Cardano.SCLS.Internal.Version
4242
import Data.Typeable (Typeable)
4343
import qualified Cardano.Ledger.Shelley.TxOut as Shelley
4444
import qualified Cardano.Ledger.Babbage.TxOut as Babbage
4545
import Cardano.Ledger.Allegra.Scripts (Timelock(..))
4646
import Data.MemPack
47-
import Data.Word (Word8, Word16)
48-
import Cardano.Ledger.Alonzo.TxOut (DataHash32, Addr28Extra)
49-
import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose, AsItem, AlonzoScript)
47+
import Data.Word (Word8)
48+
import Cardano.Ledger.Alonzo.TxOut (DataHash32, Addr28Extra, decodeAddress28)
49+
import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose, AsItem, AlonzoScript(..))
5050

5151
-- | Helper that allows us to deriving instances via internal CBOR representation
5252
newtype LedgerCBOR (v::Version) a = LedgerCBOR { unLedgerCBOR :: a }
@@ -70,76 +70,50 @@ instance (MemPack a) => FromCanonicalCBOR V1 (MemPackCBOR a) where
7070
-- | Input wrapper for the keys that are used in utxo namespace
7171
data UtxoKey
7272
= UtxoKeyIn TxIn
73-
-- | UtxoKeyScript ScriptUtxoIn
73+
deriving (Show)
7474

7575
instance Eq UtxoKey where
7676
(UtxoKeyIn txIn1) == (UtxoKeyIn txIn2) = txIn1 == txIn2
77-
-- (UtxoKeyScript script1) == (UtxoKeyScript script2) = undefined script1 script2
78-
-- _ == _ = False
7977

8078
instance Ord UtxoKey where
8179
compare (UtxoKeyIn txIn1) (UtxoKeyIn txIn2) = compare txIn1 txIn2
82-
-- compare (UtxoKeyScript script1) (UtxoKeyScript script2) = undefined script1 script2
83-
-- compare (UtxoKeyIn _) (UtxoKeyScript _) = LT
84-
-- compare (UtxoKeyScript _) (UtxoKeyIn _) = GT
8580

8681
instance IsKey UtxoKey where
8782
keySize = 34
88-
packKeyM (UtxoKeyIn (TxIn a b)) = do
89-
packM a
83+
packKeyM (UtxoKeyIn (TxIn (TxId a) b)) = do
84+
packByteStringM (originalBytes a)
9085
packM b
91-
-- packKeyM (UtxoKeyScript (ScriptUtxoIn purpose hash)) = do
92-
-- undefined purpose hash
9386
unpackKeyM = do
94-
a <- unpackM
87+
a <- unpackM -- FIXME read bytestirng and create unsafe hash
9588
b <- unpackM
9689
return $ UtxoKeyIn (TxIn a b)
97-
-- toKeyBytes v key = toStrictByteString $ toCanonicalCBOR v key
9890

9991
newtype Out = Out (TxOut ConwayEra)
10092
deriving newtype (ToCanonicalCBOR V1, FromCanonicalCBOR V1)
10193

102-
data AddrUtxoIn = AddrUtxoIn { addrUtxoInAddress :: DataHash32, addrUtxoInIndex :: Word16 }
103-
data ScriptUtxoIn = ScriptUtxoIn { scriptUtxoInPurpose :: AlonzoPlutusPurpose AsItem MaryEra, scriptUtxoInHash :: ScriptHash }
104-
10594
-- | Output key that is used in utxo namespace
10695
--
10796
-- Here we follow the current spec, but after benchmarks we can decide that this representation
10897
-- is not efficient and we can replace it with the implementation based on the compact values
10998
data UtxoOut
110-
= UtxoOutShelley (Shelley.ShelleyTxOut MaryEra)
111-
| UtxoOutBabbage (Babbage.BabbageTxOut MaryEra)
99+
= UtxoOutShelley (Shelley.ShelleyTxOut ConwayEra)
100+
| UtxoOutBabbage (Babbage.BabbageTxOut ConwayEra)
112101
| UtxoValue MaryValue
113102

114103
instance ToCanonicalCBOR V1 UtxoKey where
115-
toCanonicalCBOR v (UtxoKeyIn txIn) = E.encodeTag 0 <> toCanonicalCBOR v txIn
116-
-- toCanonicalCBOR v (UtxoKeyScript script) = E.encodeTag 1 <> toCanonicalCBOR v script
117-
118-
119-
instance ToCanonicalCBOR V1 AddrUtxoIn where
120-
toCanonicalCBOR v (AddrUtxoIn addr idx) = toCanonicalCBOR v (addr, idx)
121-
122-
instance FromCanonicalCBOR V1 AddrUtxoIn where
123-
fromCanonicalCBOR = fmap (uncurry AddrUtxoIn) <$> fromCanonicalCBOR
124-
125-
instance ToCanonicalCBOR V1 ScriptUtxoIn where
126-
toCanonicalCBOR v (ScriptUtxoIn purpose hash) = toCanonicalCBOR v (purpose, hash)
127-
128-
instance FromCanonicalCBOR V1 ScriptUtxoIn where
129-
fromCanonicalCBOR = fmap (uncurry ScriptUtxoIn) <$> fromCanonicalCBOR
104+
toCanonicalCBOR v (UtxoKeyIn txIn) = E.encodeInt 0 <> toCanonicalCBOR v txIn
130105

131106
instance FromCanonicalCBOR V1 UtxoKey where
132107
fromCanonicalCBOR = do
133108
tag <- fromCanonicalCBOR
134109
case unVer tag :: Word8 of
135110
0 -> fmap UtxoKeyIn <$> fromCanonicalCBOR
136-
-- 1 -> fmap UtxoKeyScript <$> fromCanonicalCBOR
137111
_ -> fail "Unknown UtxoKey tag"
138112

139113
instance ToCanonicalCBOR V1 UtxoOut where
140-
toCanonicalCBOR v (UtxoOutShelley shelleyOut) = E.encodeTag 1 <> toCanonicalCBOR v shelleyOut
141-
toCanonicalCBOR v (UtxoOutBabbage babbageOut) = E.encodeTag 2 <> toCanonicalCBOR v babbageOut
142-
toCanonicalCBOR v (UtxoValue value) = E.encodeTag 3 <> toCanonicalCBOR v value
114+
toCanonicalCBOR v (UtxoOutShelley shelleyOut) = toCanonicalCBOR v (E.encodeInt 0, toCanonicalCBOR v shelleyOut)
115+
toCanonicalCBOR v (UtxoOutBabbage babbageOut) = toCanonicalCBOR v (E.encodeInt 1, toCanonicalCBOR v babbageOut)
116+
toCanonicalCBOR v (UtxoValue value) = toCanonicalCBOR v (E.encodeInt 2, toCanonicalCBOR v value)
143117

144118
instance FromCanonicalCBOR V1 UtxoOut where
145119
fromCanonicalCBOR = do
@@ -151,12 +125,47 @@ instance FromCanonicalCBOR V1 UtxoOut where
151125
t -> fail $ "Unknown UtxoOut tag: " <> show t
152126

153127
instance ToCanonicalCBOR V1 (Babbage.BabbageTxOut ConwayEra) where
154-
toCanonicalCBOR v (Babbage.TxOutCompact' cAddr form) = E.encodeTag 0 <> toCanonicalCBOR v (cAddr, form)
155-
toCanonicalCBOR v (Babbage.TxOutCompactDH' cAddr form dataHash) = E.encodeTag 1 <> toCanonicalCBOR v (cAddr, form, dataHash)
156-
toCanonicalCBOR v (Babbage.TxOutCompactDatum cAddr form inlineDatum) = E.encodeTag 2 <> toCanonicalCBOR v (cAddr, form, inlineDatum)
157-
toCanonicalCBOR v (Babbage.TxOutCompactRefScript cAddr form datum script) = E.encodeTag 3 <> toCanonicalCBOR v (cAddr, form, datum, script)
158-
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly staking hash28 compact) = E.encodeTag 4 <> toCanonicalCBOR v (staking, hash28, compact)
159-
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly_DataHash32 staking hash28 compact dataHash) = E.encodeTag 5 <> toCanonicalCBOR v (staking, hash28, compact, dataHash)
128+
toCanonicalCBOR v (Babbage.TxOutCompact' cAddr form) =
129+
E.encodeMapLen 2
130+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
131+
<> E.encodeInt 1 <> toCanonicalCBOR v form
132+
toCanonicalCBOR v (Babbage.TxOutCompactDH' cAddr form datum) =
133+
E.encodeMapLen 3
134+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
135+
<> E.encodeInt 1 <> toCanonicalCBOR v form
136+
<> E.encodeInt 2
137+
<> case datum of
138+
hash_ -> toCanonicalCBOR v (0::Int, originalBytes hash_)
139+
toCanonicalCBOR v (Babbage.TxOutCompactDatum cAddr form inlineDatum) =
140+
E.encodeMapLen 3
141+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
142+
<> E.encodeInt 1 <> toCanonicalCBOR v form
143+
<> E.encodeInt 2
144+
<> case inlineDatum of
145+
binaryData -> toCanonicalCBOR v (1::Int, toCanonicalCBOR v (LedgerCBOR @V1 binaryData))
146+
toCanonicalCBOR v (Babbage.TxOutCompactRefScript cAddr form datum script) =
147+
let datumEncoding = case datum of
148+
NoDatum -> (Nothing)
149+
DatumHash dh -> Just (toCanonicalCBOR v (0::Int, originalBytes dh))
150+
Datum binaryData -> Just (toCanonicalCBOR v (1:: Int, toCanonicalCBOR v (LedgerCBOR @V1 binaryData)))
151+
in E.encodeMapLen (3 + (case datumEncoding of Just{} -> 1 ; Nothing -> 0))
152+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
153+
<> E.encodeInt 1 <> toCanonicalCBOR v form
154+
<> case datumEncoding of
155+
Nothing -> mempty
156+
Just enc -> E.encodeInt 2 <> enc
157+
<> E.encodeInt 3 <> toCanonicalCBOR v (LedgerCBOR @V1 script)
158+
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly staking hash28 compactForm) =
159+
let cAddr = unCompactAddr (compactAddr (decodeAddress28 staking hash28))
160+
in E.encodeMapLen 2
161+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
162+
<> E.encodeInt 1 <> toCanonicalCBOR v compactForm
163+
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly_DataHash32 staking hash28 compact dataHash) =
164+
let cAddr = unCompactAddr (compactAddr (decodeAddress28 staking hash28))
165+
in E.encodeMapLen 3
166+
<> E.encodeInt 0 <> toCanonicalCBOR v cAddr
167+
<> E.encodeInt 1 <> toCanonicalCBOR v compact
168+
<> E.encodeInt 2 <> toCanonicalCBOR v (0::Int, dataHash)
160169

161170
instance FromCanonicalCBOR V1 (Babbage.BabbageTxOut ConwayEra) where
162171
fromCanonicalCBOR = do
@@ -169,27 +178,7 @@ instance FromCanonicalCBOR V1 (Babbage.BabbageTxOut ConwayEra) where
169178
5 -> fmap (\(a,b,c,d) -> Babbage.TxOut_AddrHash28_AdaOnly_DataHash32 a b c d) <$> fromCanonicalCBOR
170179
t -> fail $ "Unknown BabbageTxOut tag: " <> show t
171180

172-
instance ToCanonicalCBOR V1 (Babbage.BabbageTxOut MaryEra) where
173-
toCanonicalCBOR v (Babbage.TxOutCompact' cAddr form) = E.encodeTag 0 <> toCanonicalCBOR v (cAddr, form)
174-
toCanonicalCBOR v (Babbage.TxOutCompactDH' cAddr form dataHash) = E.encodeTag 1 <> toCanonicalCBOR v (cAddr, form, dataHash)
175-
toCanonicalCBOR v (Babbage.TxOutCompactDatum cAddr form inlineDatum) = E.encodeTag 2 <> toCanonicalCBOR v (cAddr, form, inlineDatum)
176-
toCanonicalCBOR v (Babbage.TxOutCompactRefScript cAddr form datum script) = E.encodeTag 3 <> toCanonicalCBOR v (cAddr, form, datum, script)
177-
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly staking hash28 compact) = E.encodeTag 4 <> toCanonicalCBOR v (staking, hash28, compact)
178-
toCanonicalCBOR v (Babbage.TxOut_AddrHash28_AdaOnly_DataHash32 staking hash28 compact dataHash) = E.encodeTag 5 <> toCanonicalCBOR v (staking, hash28, compact, dataHash)
179-
180-
instance FromCanonicalCBOR V1 (Babbage.BabbageTxOut MaryEra) where
181-
fromCanonicalCBOR = do
182-
D.decodeTag >>= \case
183-
0 -> fmap (\(c, f) -> Babbage.TxOutCompact' c f) <$> fromCanonicalCBOR
184-
1 -> fmap (\(a,b,c) -> Babbage.TxOutCompactDH' a b c) <$> fromCanonicalCBOR
185-
2 -> fmap (\(a,b,c) -> Babbage.TxOutCompactDatum a b c) <$> fromCanonicalCBOR
186-
3 -> fmap (\(a,b,c,d) -> Babbage.TxOutCompactRefScript a b c d) <$> fromCanonicalCBOR
187-
4 -> fmap (\(a,b,c) -> Babbage.TxOut_AddrHash28_AdaOnly a b c) <$> fromCanonicalCBOR
188-
5 -> fmap (\(a,b,c,d) -> Babbage.TxOut_AddrHash28_AdaOnly_DataHash32 a b c d) <$> fromCanonicalCBOR
189-
t -> fail $ "Unknown BabbageTxOut tag: " <> show t
190-
191-
192-
instance Typeable kr => ToCanonicalCBOR V1 (Credential kr) where
181+
instance ToCanonicalCBOR V1 (Credential kr) where
193182
toCanonicalCBOR v (ScriptHashObj sh) = toCanonicalCBOR v (0::Word8, sh)
194183
toCanonicalCBOR v (KeyHashObj kh) = toCanonicalCBOR v (1::Word8, kh)
195184

@@ -201,15 +190,22 @@ instance Typeable kr => FromCanonicalCBOR V1 (Credential kr) where
201190
1 -> fmap KeyHashObj <$> fromCanonicalCBOR
202191
x -> fail $ "Unknown Credential tag: " <> show x
203192

204-
deriving via (LedgerCBOR v (Shelley.ShelleyTxOut MaryEra)) instance ToCanonicalCBOR v (Shelley.ShelleyTxOut MaryEra)
205-
deriving via (LedgerCBOR v (Shelley.ShelleyTxOut MaryEra)) instance FromCanonicalCBOR v (Shelley.ShelleyTxOut MaryEra)
206-
deriving via (LedgerCBOR v (AlonzoPlutusPurpose AsItem MaryEra)) instance ToCanonicalCBOR v (AlonzoPlutusPurpose AsItem MaryEra)
207-
deriving via (LedgerCBOR v (AlonzoPlutusPurpose AsItem MaryEra)) instance FromCanonicalCBOR v (AlonzoPlutusPurpose AsItem MaryEra)
193+
deriving via (LedgerCBOR v (Shelley.ShelleyTxOut ConwayEra)) instance ToCanonicalCBOR v (Shelley.ShelleyTxOut ConwayEra)
194+
deriving via (LedgerCBOR v (Shelley.ShelleyTxOut ConwayEra)) instance FromCanonicalCBOR v (Shelley.ShelleyTxOut ConwayEra)
208195
deriving via (LedgerCBOR v (AlonzoPlutusPurpose AsItem ConwayEra)) instance ToCanonicalCBOR v (AlonzoPlutusPurpose AsItem ConwayEra)
209196
deriving via (LedgerCBOR v (AlonzoPlutusPurpose AsItem ConwayEra)) instance FromCanonicalCBOR v (AlonzoPlutusPurpose AsItem ConwayEra)
210197
deriving via (MemPackCBOR (AlonzoScript ConwayEra)) instance ToCanonicalCBOR V1 (AlonzoScript ConwayEra)
211198
deriving via (MemPackCBOR (AlonzoScript ConwayEra)) instance FromCanonicalCBOR V1 (AlonzoScript ConwayEra)
212-
deriving via (MemPackCBOR (CompactForm a)) instance (MemPack (CompactForm a)) => ToCanonicalCBOR V1 (CompactForm a)
199+
-- deriving via (MemPackCBOR (CompactForm a)) instance {-# OVERLAPPABLE #-} (MemPack (CompactForm a)) => ToCanonicalCBOR V1 (CompactForm a)
200+
201+
deriving via (LedgerCBOR v MaryValue) instance ToCanonicalCBOR v MaryValue
202+
deriving via (LedgerCBOR v MaryValue) instance FromCanonicalCBOR v MaryValue
203+
instance {-# OVERLAPPING #-} ToCanonicalCBOR version (CompactForm MaryValue) where
204+
toCanonicalCBOR version v = toCanonicalCBOR version (fromCompact v)
205+
206+
instance {-# OVERLAPPING #-} ToCanonicalCBOR v (CompactForm Coin) where
207+
toCanonicalCBOR v (Coin.CompactCoin ci) = toCanonicalCBOR v ci
208+
213209
deriving via (MemPackCBOR (CompactForm a)) instance (MemPack (CompactForm a)) => FromCanonicalCBOR V1 (CompactForm a)
214210
deriving via (MemPackCBOR CompactAddr) instance FromCanonicalCBOR V1 CompactAddr
215211
deriving via (MemPackCBOR CompactAddr) instance ToCanonicalCBOR V1 CompactAddr
@@ -219,22 +215,18 @@ deriving via (LedgerCBOR v TxIn) instance FromCanonicalCBOR v TxIn
219215
deriving via (LedgerCBOR v TxIn) instance ToCanonicalCBOR v TxIn
220216
deriving via (MemPackCBOR DataHash32) instance FromCanonicalCBOR V1 DataHash32
221217
deriving via (MemPackCBOR DataHash32) instance ToCanonicalCBOR V1 DataHash32
222-
deriving via (MemPackCBOR (Timelock MaryEra)) instance ToCanonicalCBOR V1 (Timelock MaryEra)
223-
deriving via (MemPackCBOR (Timelock MaryEra)) instance FromCanonicalCBOR V1 (Timelock MaryEra)
224-
deriving via (LedgerCBOR v MaryValue) instance ToCanonicalCBOR v MaryValue
225-
deriving via (LedgerCBOR v MaryValue) instance FromCanonicalCBOR v MaryValue
218+
deriving via (MemPackCBOR (Timelock ConwayEra)) instance ToCanonicalCBOR V1 (Timelock ConwayEra)
219+
deriving via (MemPackCBOR (Timelock ConwayEra)) instance FromCanonicalCBOR V1 (Timelock ConwayEra)
220+
-- deriving via (LedgerCBOR v MaryValue) instance ToCanonicalCBOR v MaryValue
221+
-- deriving via (LedgerCBOR v MaryValue) instance FromCanonicalCBOR v MaryValue
226222

227223

228-
deriving via (LedgerCBOR v (KeyHash kr)) instance Typeable kr => ToCanonicalCBOR v (KeyHash kr)
224+
deriving via (LedgerCBOR v (KeyHash kr)) instance ToCanonicalCBOR v (KeyHash kr)
229225
deriving via (LedgerCBOR v (KeyHash kr)) instance Typeable kr => FromCanonicalCBOR v (KeyHash kr)
230226
deriving via (LedgerCBOR v (ScriptHash)) instance FromCanonicalCBOR v ScriptHash
231227
deriving via (LedgerCBOR v (ScriptHash)) instance ToCanonicalCBOR v ScriptHash
232-
deriving via (LedgerCBOR v (Datum MaryEra)) instance ToCanonicalCBOR v (Datum MaryEra)
233-
deriving via (LedgerCBOR v (Datum MaryEra)) instance FromCanonicalCBOR v (Datum MaryEra)
234228
deriving via (LedgerCBOR v (Datum ConwayEra)) instance ToCanonicalCBOR v (Datum ConwayEra)
235229
deriving via (LedgerCBOR v (Datum ConwayEra)) instance FromCanonicalCBOR v (Datum ConwayEra)
236-
deriving via (LedgerCBOR v (BinaryData MaryEra)) instance ToCanonicalCBOR v (BinaryData MaryEra)
237-
deriving via (LedgerCBOR v (BinaryData MaryEra)) instance FromCanonicalCBOR v (BinaryData MaryEra)
238230
deriving via (LedgerCBOR v (BinaryData ConwayEra)) instance ToCanonicalCBOR v (BinaryData ConwayEra)
239231
deriving via (LedgerCBOR v (BinaryData ConwayEra)) instance FromCanonicalCBOR v (BinaryData ConwayEra)
240232
deriving via (LedgerCBOR v (SafeHash EraIndependentData)) instance ToCanonicalCBOR v ((SafeHash EraIndependentData))

libs/ledger-state/app-canonical/Main.hs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module Main where
1515
import Control.Exception (throwIO)
1616
import Data.Bifunctor (first)
1717
import Control.Monad
18+
import Data.Function ((&))
19+
import Cardano.SCLS.Internal.Serializer.Dump.Plan
1820
import qualified Data.ByteString.Lazy as LBS
1921
import qualified Data.Text as T
2022
import Cardano.Ledger.Mary (MaryEra)
@@ -112,16 +114,16 @@ main = do
112114
fileName
113115
Mainnet
114116
(SlotNo 1)
115-
$ S.each
116-
[ "utxo" S.:>
117-
S.each
118-
[ ChunkEntry
119-
(UtxoKeyIn txin)
120-
(RawBytes $ toStrictByteString $ toCanonicalCBOR (Proxy :: Proxy V1) $ txout
121-
)
122-
| (txin, txout) <- Map.toList utxo
123-
]
124-
]
117+
(defaultSerializationPlan & addChunks
118+
(S.each
119+
[ "utxo/v0" S.:>
120+
(S.each
121+
[ ChunkEntry
122+
(UtxoKeyIn txin)
123+
(RawBytes $ toStrictByteString $ toCanonicalCBOR (Proxy :: Proxy V1) $ UtxoOutBabbage txout)
124+
| (txin, txout) <- Map.toList utxo
125+
])
126+
]))
125127

126128
data TxIn' = TxIn' TxId Word16
127129

0 commit comments

Comments
 (0)