Skip to content

Commit 3cb20c0

Browse files
committed
[VD-77] Change bank's state JSON serialization format
1 parent f3c341a commit 3cb20c0

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/Bank/BankOptions.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ data Command
3030
| RemoveExplorer String Int
3131
| DumpStatistics
3232
| DumpUtxo FilePath
33+
| DumpUtxoOld FilePath
3334

3435
data Options = Options
3536
{ cloCommand :: Command
@@ -82,7 +83,12 @@ commandParser =
8283
"dump-state"
8384
(info
8485
dumpStateOpts
85-
(progDesc "Dump current bank state to json")))
86+
(progDesc "Dump current bank state to json")) <>
87+
command
88+
"dump-state-old"
89+
(info
90+
dumpStateOpts
91+
(progDesc "Dump current bank state to json in old format")))
8692
where
8793
mHost = strOption (long "host" <> help "Mintette's host" <> metavar "HOST")
8894
mPort =

src/Bank/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ main = do
6565
B.removeExplorerReq ca bankSecretKey host port
6666
Opts.DumpStatistics -> B.dumpStatisticsReq ca bankSecretKey
6767
Opts.DumpUtxo output -> void $ B.dumpUtxo cloPath output
68+
Opts.DumpUtxoOld output -> void $ B.dumpUtxoOld cloPath output
6869
Opts.Serve -> do
6970
let periodDelta = fromInteger cloPeriodDelta :: Second
7071
B.launchBankReal cloRebuildDB periodDelta cloPath ca bankSecretKey cloPermittedAddrs

src/RSCoin/Bank/AcidState.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module RSCoin.Bank.AcidState
1515
, tidyState
1616
, update
1717
, dumpUtxo
18+
, dumpUtxoOld
1819

1920
-- | Queries
2021
, GetMintettes (..)
@@ -71,7 +72,8 @@ import RSCoin.Core (ActionLog, AddressToTxStrategyMa
7172
Explorer, Explorers, HBlock, MintetteId,
7273
Mintettes, PeriodId, PublicKey)
7374
import qualified RSCoin.Core as C
74-
import RSCoin.Core.AesonJS (utxoAsBalances)
75+
import RSCoin.Core.Aeson (utxoBalances)
76+
import RSCoin.Core.AesonJS (utxoBalancesJS)
7577

7678
import qualified RSCoin.Bank.Storage as BS
7779

@@ -178,7 +180,16 @@ dumpUtxo fp outputFp = do
178180
state <- openState False fp
179181
utxo <- query state GetUtxo
180182
BS.writeFile outputFp . encode $ object
181-
[ "utxo" .= utxoAsBalances utxo
183+
[ "utxo" .= utxoBalances utxo
184+
]
185+
pure ()
186+
187+
dumpUtxoOld :: FilePath -> FilePath -> IO ()
188+
dumpUtxoOld fp outputFp = do
189+
state <- openState False fp
190+
utxo <- query state GetUtxo
191+
BS.writeFile outputFp . encode $ object
192+
[ "utxo" .= utxoBalancesJS utxo
182193
]
183194
pure ()
184195

0 commit comments

Comments
 (0)