[input-output-hk/cardano-sl] [CO-347] Wallet’s UTXO histogram view (#3402)

paweljakubas commented on this pull request.

> +
+instance ToJSON UtxoStatistics where
+ toJSON (UtxoStatistics bars allStakes) =
+ let histogramObject = Object . HMS.fromList . map extractBarKey
+ extractBarKey (HistogramBarCount bound stake) = bound .= stake
+ in object [ «histogram» .= histogramObject bars
+ , «allStakes» .= allStakes ]
+
+instance FromJSON UtxoStatistics where
+ parseJSON (Object v) =
+ let histogramListM = case HMS.lookup «histogram» v of
+ Nothing -> empty
+ Just (Object bars) -> do
+ let constructHistogram (key, Number val) =
+ case floatingOrInteger val of
+ Left (_ :: Double) -> error «UtxoStatistics FromJson not integer»

refactored as suggested

Добавить комментарий