88{-# OPTIONS_GHC -fno-warn-deprecations #-}
99module Main where
1010
11- -- import Cardano.Ledger.Shelley.LedgerState
11+ import Cardano.Ledger.Shelley.LedgerState
1212-- import Cardano.Ledger.State.Query
13- -- import Cardano.Ledger.State.UTxO
13+ import Cardano.Ledger.State.UTxO
1414
1515import Control.Exception (throwIO )
16+ import qualified Data.Aeson as Aeson
17+ import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
18+ import Data.Aeson.Types (Value )
1619import Data.Bifunctor (first )
1720import Control.Monad
1821import Data.Function ((&) )
@@ -79,16 +82,21 @@ data Opts = Opts
7982
8083data Cmd
8184 = CmdCreateFile FilePath FilePath
85+ | CmdCreateStateFile FilePath FilePath
8286 deriving (Show )
8387
8488optsParser :: Parser Cmd
8589optsParser = hsubparser
86- (command " create" (info createCommand (progDesc " Create canonical file" ))
90+ (command " create" (info createCommand (progDesc " Create canonical file for utxo" ))
91+ <> command " create-state" (info createStateCommand (progDesc " Create canonical file for ledger state" ))
8792 )
8893 where
8994 createCommand = CmdCreateFile
9095 <$> argument str (metavar " UTXO_HEX_FILE" )
9196 <*> argument str (metavar " SCLS_FILE" )
97+ createStateCommand = CmdCreateStateFile
98+ <$> argument str (metavar " STATE_JSON_FILE" )
99+ <*> argument str (metavar " SCLS_FILE" )
92100
93101main :: IO ()
94102main = do
@@ -103,17 +111,31 @@ main = do
103111 )
104112 (header " canonical-state - Tool for working with canonical ledger state representation" )
105113 case cmd of
106- CmdCreateFile utxoFilePath _outputFile -> do
114+ -- cabal run canonical-ledger -- create ~/iohk/chain/mainnet/utxo.hex 1.scls
115+ CmdCreateFile utxoFilePath fileName -> do
107116 putStrLn " Creating file..."
108117 putStrLn $ " Reading UTxO from " ++ utxoFilePath
109118 UTxO utxo <- localReadDecCBORHex utxoFilePath
110119
111- let fileName = " scls-utxo.scls"
112-
113120 External. serialize
114121 fileName
115122 Mainnet
116123 (SlotNo 1 )
124+ <<<<<<< Updated upstream
125+ =======
126+ <<<<<<< Updated upstream
127+ $ S. each
128+ [ " utxo" S. :>
129+ S. each
130+ [ ChunkEntry
131+ (UtxoKeyIn txin)
132+ (RawBytes $ toStrictByteString $ toCanonicalCBOR (Proxy :: Proxy V1 ) $ txout
133+ )
134+ | (txin, txout) <- Map. toList utxo
135+ ]
136+ ]
137+ =======
138+ >>>>>>> Stashed changes
117139 (defaultSerializationPlan & addChunks
118140 (S. each
119141 [ " utxo/v0" S. :>
@@ -124,6 +146,32 @@ main = do
124146 | (txin, txout) <- Map. toList utxo
125147 ])
126148 ]))
149+ <<<<<<< Updated upstream
150+ =======
151+ CmdCreateStateFile stateFilePath _fileName -> do
152+ putStrLn " Creating state file..."
153+ putStrLn $ " Reading State from " ++ stateFilePath
154+ _nes <- readNewEpochState stateFilePath
155+ putStrLn " hohohoho"
156+ -- val <- Aeson.decodeFileStrict stateFilePath
157+ -- print (val :: Maybe (Serialised (Shelley.NewEpochState ConwayEra)))
158+
159+ -- External.serialize
160+ -- fileName
161+ -- Mainnet
162+ -- (SlotNo 1)
163+ -- (defaultSerializationPlan & addChunks
164+ -- (S.each
165+ -- [ "utxo-state/v0" S.:>
166+ -- (S.each
167+ -- [ ChunkEntry
168+ -- (UtxoKeyIn txin)
169+ -- (RawBytes $ toStrictByteString $ toCanonicalCBOR (Proxy :: Proxy V1) $ UtxoOutBabbage txout)
170+ -- | (txin, txout) <- Map.toList utxo
171+ -- ])
172+ -- ]))
173+ >>>>>>> Stashed changes
174+ >>>>>>> Stashed changes
127175
128176data TxIn' = TxIn' TxId Word16
129177
0 commit comments