packages feed

haskoin-store 0.20.1 → 0.20.2

raw patch · 4 files changed

+39/−71 lines, 4 files

Files

CHANGELOG.md view
@@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.20.2+### Changed+- Filter xpub address balances on web API to show only addresses that have been used.++### Removed+- Remove paths and addresses from xpub summary.+ ## 0.20.1 ### Changed - Refactor code greatly.
haskoin-store.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: b3d80fe4a3c3b83bcc166865f4e64defe65034ed9969a2f79de8605982483af5+-- hash: fab6c7b80d147905eae85dd49155972d155bc89744e0be0dd5c3d8fc9dabb4e2  name:           haskoin-store-version:        0.20.1+version:        0.20.2 synopsis:       Storage and index for Bitcoin and Bitcoin Cash description:    Store blocks, transactions, and balances for Bitcoin or Bitcoin Cash, and make that information via REST API. category:       Bitcoin, Finance, Network
src/Network/Haskoin/Store/Common.hs view
@@ -6,10 +6,9 @@  import           Conduit                   (ConduitT, dropC, mapC, takeC) import           Control.Applicative       ((<|>))-import           Control.Arrow             (first) import           Control.DeepSeq           (NFData) import           Control.Exception         (Exception)-import           Control.Monad             (forM, guard, mzero)+import           Control.Monad             (guard, mzero) import           Control.Monad.Trans       (lift) import           Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT) import           Data.Aeson                (Encoding, ToJSON (..), Value (..),@@ -23,8 +22,6 @@ import           Data.Default              (Default (..)) import           Data.Function             (on) import           Data.Hashable             (Hashable)-import           Data.HashMap.Strict       (HashMap)-import qualified Data.HashMap.Strict       as M import qualified Data.IntMap               as I import           Data.IntMap.Strict        (IntMap) import           Data.List                 (nub, partition, sortBy)@@ -34,8 +31,7 @@                                             getListOf, getShortByteString,                                             getWord32be, getWord64be, getWord8,                                             putListOf, putShortByteString,-                                            putWord32be, putWord64be, putWord8,-                                            runGet, runPut)+                                            putWord32be, putWord64be, putWord8) import qualified Data.Serialize            as S import           Data.String.Conversions   (cs) import qualified Data.Text.Encoding        as T@@ -217,11 +213,8 @@                 else (xbs <>) <$> derive_until_gap m as2     xPubSummary :: XPubSpec -> m XPubSummary     xPubSummary xpub = do-        bs <- xPubBals xpub-        let f XPubBal {xPubBalPath = p, xPubBal = Balance {balanceAddress = a}} =-                (a, p)-            pm = M.fromList $ map f bs-            ex = foldl max 0 [i | XPubBal {xPubBalPath = [0, i]} <- bs]+        bs <- filter (not . nullBalance . xPubBal) <$> xPubBals xpub+        let ex = foldl max 0 [i | XPubBal {xPubBalPath = [0, i]} <- bs]             ch = foldl max 0 [i | XPubBal {xPubBalPath = [1, i]} <- bs]             uc =                 sum@@ -242,7 +235,6 @@                 , xPubSummaryZero = sum (map (balanceZero . xPubBal) bs)                 , xPubSummaryReceived = rx                 , xPubUnspentCount = uc-                , xPubSummaryPaths = pm                 , xPubChangeIndex = ch                 , xPubExternalIndex = ex                 }@@ -1161,73 +1153,40 @@         , xPubUnspentCount     :: !Word64         , xPubExternalIndex    :: !Word32         , xPubChangeIndex      :: !Word32-        , xPubSummaryPaths     :: !(HashMap Address [KeyIndex])         }-    deriving (Eq, Show, Generic, NFData)+    deriving (Eq, Show, Generic, Serialize, NFData) -xPubSummaryPairs :: A.KeyValue kv => Network -> XPubSummary -> [kv]-xPubSummaryPairs net XPubSummary { xPubSummaryConfirmed = c-                                 , xPubSummaryZero = z-                                 , xPubSummaryReceived = r-                                 , xPubUnspentCount = u-                                 , xPubSummaryPaths = ps-                                 , xPubExternalIndex = ext-                                 , xPubChangeIndex = ch-                                 } =+xPubSummaryPairs :: A.KeyValue kv => XPubSummary -> [kv]+xPubSummaryPairs XPubSummary { xPubSummaryConfirmed = c+                               , xPubSummaryZero = z+                               , xPubSummaryReceived = r+                               , xPubUnspentCount = u+                               , xPubExternalIndex = ext+                               , xPubChangeIndex = ch+                               } =     [ "balance" .=       object-          [ "confirmed" .= c-          , "unconfirmed" .= z-          , "received" .= r-          , "utxo" .= u-          ]+          ["confirmed" .= c, "unconfirmed" .= z, "received" .= r, "utxo" .= u]     , "indices" .= object ["change" .= ch, "external" .= ext]-    , "paths" .= object (mapMaybe (uncurry f) (M.toList ps))     ]-  where-    f a p = (.= p) <$> addrToString net a -xPubSummaryToJSON :: Network -> XPubSummary -> Value-xPubSummaryToJSON net = object . xPubSummaryPairs net+xPubSummaryToJSON :: XPubSummary -> Value+xPubSummaryToJSON = object . xPubSummaryPairs -xPubSummaryToEncoding :: Network -> XPubSummary -> Encoding-xPubSummaryToEncoding net = pairs . mconcat . xPubSummaryPairs net+xPubSummaryToEncoding :: XPubSummary -> Encoding+xPubSummaryToEncoding = pairs . mconcat . xPubSummaryPairs +instance ToJSON XPubSummary where+    toJSON = xPubSummaryToJSON+    toEncoding = xPubSummaryToEncoding+ instance JsonSerial XPubSummary where-    jsonSerial = xPubSummaryToEncoding-    jsonValue = xPubSummaryToJSON+    jsonSerial _ = xPubSummaryToEncoding+    jsonValue _ = xPubSummaryToJSON  instance BinSerial XPubSummary where-    binSerial net XPubSummary { xPubSummaryConfirmed = c-                              , xPubSummaryZero = z-                              , xPubSummaryReceived = r-                              , xPubUnspentCount = u-                              , xPubExternalIndex = ext-                              , xPubChangeIndex = ch-                              , xPubSummaryPaths = ps-                              } = do-        put c-        put z-        put r-        put u-        put ext-        put ch-        put (map (first (runPut . binSerial net)) (M.toList ps))-    binDeserial net = do-        c <- get-        z <- get-        r <- get-        u <- get-        ext <- get-        ch <- get-        ps <- get-        let xs = map (first (runGet (binDeserial net))) ps-        ys <--            forM xs $ \(k, v) ->-                case k of-                    Right a -> return (a, v)-                    Left _  -> mzero-        return $ XPubSummary c z r u ext ch (M.fromList ys)+    binSerial _ = put+    binDeserial _ = get  data HealthCheck =     HealthCheck
src/Network/Haskoin/Store/Web.hs view
@@ -82,9 +82,11 @@                                                      TxAfterHeight (..),                                                      TxData (..), TxId (..),                                                      UnixTime, Unspent,+                                                     XPubBal (..),                                                      XPubSpec (..), applyOffset,                                                      blockAtOrBefore,                                                      getTransaction, isCoinbase,+                                                     nullBalance,                                                      transactionData) import           Network.Haskoin.Store.Data.RocksDB (withRocksDB) import           Network.HTTP.Types                 (Status (..), status400,@@ -528,7 +530,7 @@     setHeaders     xpub <- parseXpub net     proto <- setupBin-    res <- xPubBals xpub+    res <- filter (not . nullBalance . xPubBal) <$> xPubBals xpub     protoSerial net proto res  scottyXpubTxs :: MonadLoggerIO m => Network -> MaxLimits -> Bool -> WebT m ()@@ -664,7 +666,7 @@     runner <- askRunInIO     S.scottyT port (runner . withRocksDB bdb) $ do         case req_logger of-            Just m -> S.middleware m+            Just m  -> S.middleware m             Nothing -> return ()         S.defaultHandler (defHandler net)         S.get "/block/best" $ scottyBestBlock net limits False