Skip to content

Commit 722f609

Browse files
committed
[RSC-281] Use UtxoAsBalances to serialize Utxo
1 parent 571eeb4 commit 722f609

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/RSCoin/Bank/AcidState.hs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,28 @@ import Control.Lens (Getter, to, view)
5050
import Control.Monad.Reader (ask)
5151
import Control.Monad.Trans (MonadIO)
5252
import Data.Acid (EventResult, EventState, Query,
53-
QueryEvent, UpdateEvent,
54-
makeAcidic)
53+
QueryEvent, UpdateEvent, makeAcidic)
5554
import Data.Aeson (encode, object, (.=))
55+
import Data.ByteString.Lazy.Char8 as BS hiding (filter, map)
5656
import Data.Maybe (fromMaybe)
5757
import qualified Data.Set as Set
5858
import Data.Text (Text)
59-
import Data.ByteString.Lazy.Char8 as BS hiding (map, filter)
6059
import Formatting (bprint, stext, (%))
6160
import Safe (headMay)
6261

63-
import Serokell.AcidState (ExtendedState,
64-
closeExtendedState,
62+
import Serokell.AcidState (ExtendedState, closeExtendedState,
6563
openLocalExtendedState,
66-
openMemoryExtendedState,
67-
queryExtended,
68-
tidyExtendedState,
69-
updateExtended)
70-
import Serokell.AcidState.Statistics (StoragePart (..),
71-
estimateMemoryUsage)
64+
openMemoryExtendedState, queryExtended,
65+
tidyExtendedState, updateExtended)
66+
import Serokell.AcidState.Statistics (StoragePart (..), estimateMemoryUsage)
7267
import Serokell.Data.Memory.Units (Byte, memory)
7368
import Serokell.Util.Text (listBuilderJSONIndent, show')
7469

75-
import RSCoin.Core (ActionLog,
76-
AddressToTxStrategyMap,
77-
Explorer, Explorers, HBlock,
78-
MintetteId, Mintettes, PeriodId,
79-
PublicKey)
70+
import RSCoin.Core (ActionLog, AddressToTxStrategyMap,
71+
Explorer, Explorers, HBlock, MintetteId,
72+
Mintettes, PeriodId, PublicKey)
8073
import qualified RSCoin.Core as C
74+
import RSCoin.Core.AesonJS (utxoAsBalances)
8175

8276
import qualified RSCoin.Bank.Storage as BS
8377

@@ -184,7 +178,7 @@ dumpUtxo fp outputFp = do
184178
state <- openState False fp
185179
utxo <- query state GetUtxo
186180
BS.writeFile outputFp . encode $ object
187-
[ "utxo" .= utxo
181+
[ "utxo" .= utxoAsBalances utxo
188182
]
189183
pure ()
190184

src/RSCoin/Bank/Storage/Storage.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE FlexibleInstances #-}
2-
{-# LANGUAGE TypeSynonymInstances #-}
32
{-# LANGUAGE TemplateHaskell #-}
3+
{-# LANGUAGE TypeSynonymInstances #-}
44

55
-- | Storage containing whole bank's data.
66

@@ -24,13 +24,10 @@ module RSCoin.Bank.Storage.Storage
2424
) where
2525

2626
import Control.Lens (makeLenses)
27-
import Data.Aeson (ToJSON, toJSON, object, (.=))
28-
import qualified Data.HashMap.Strict as HM
2927
import Data.SafeCopy (base, deriveSafeCopy)
3028
import Data.Typeable (Typeable)
3129

3230
import qualified RSCoin.Core as C
33-
import RSCoin.Core.AesonJS ()
3431

3532
import qualified RSCoin.Bank.Storage.Addresses as AS
3633
import qualified RSCoin.Bank.Storage.Explorers as ES
@@ -61,15 +58,6 @@ data Storage = Storage
6158
$(makeLenses ''Storage)
6259
$(deriveSafeCopy 0 'base ''Storage)
6360

64-
instance ToJSON C.Utxo where
65-
toJSON = toJSON . map toAddrCoin . HM.toList
66-
where
67-
toAddrCoin ((_, _, coin), addr) =
68-
object
69-
[ "address" .= C.getAddress addr
70-
, "coin" .= coin
71-
]
72-
7361
-- | Make empty storage
7462
mkStorage :: Storage
7563
mkStorage =

0 commit comments

Comments
 (0)