Skip to content

Commit ef36172

Browse files
committed
WIP (with conflicts)
1 parent c5fc861 commit ef36172

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
{-# OPTIONS_GHC -fno-warn-deprecations #-}
99
module 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

1515
import 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)
1619
import Data.Bifunctor (first)
1720
import Control.Monad
1821
import Data.Function ((&))
@@ -79,16 +82,21 @@ data Opts = Opts
7982

8083
data Cmd
8184
= CmdCreateFile FilePath FilePath
85+
| CmdCreateStateFile FilePath FilePath
8286
deriving (Show)
8387

8488
optsParser :: Parser Cmd
8589
optsParser = 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

93101
main :: IO ()
94102
main = 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

128176
data TxIn' = TxIn' TxId Word16
129177

libs/ledger-state/ledger-state.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ executable canonical-ledger
9898

9999
build-depends:
100100
base,
101+
aeson,
101102
bytestring,
102103
cardano-ledger-shelley:{cardano-ledger-shelley},
103104
cardano-ledger-babbage:{cardano-ledger-babbage},
@@ -108,7 +109,7 @@ executable canonical-ledger
108109
cardano-ledger-binary,
109110
cardano-ledger-core,
110111
-- cardano-ledger-core,
111-
-- ledger-state,
112+
ledger-state,
112113
base16-bytestring,
113114
containers,
114115
optparse-applicative,

0 commit comments

Comments
 (0)