packages feed

haskoin-store 0.52.8 → 0.52.9

raw patch · 3 files changed

+100/−45 lines, 3 filesdep ~haskoin-store-dataPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: haskoin-store-data

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -4,6 +4,12 @@ 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.52.9+### Added+- Add Blockchain.info latest block endpoint.+- Add Blockchain.info unconfirmed-transactions endpoint.+- Add Blockchain.info blocks for one day endpoint.+ ## 0.52.8 ### Fixed - Fix special case for zero limit.
haskoin-store.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: c8fe3483aabbe886987fbd5e92892220278501964337c361013c010df920d472+-- hash: 867ffc0bf512a27313ac551de654cc855e6ed52fb1f5ed2da24761965b5d7e6f  name:           haskoin-store-version:        0.52.8+version:        0.52.9 synopsis:       Storage and index for Bitcoin and Bitcoin Cash description:    Please see the README on GitHub at <https://github.com/haskoin/haskoin-store#readme> category:       Bitcoin, Finance, Network@@ -61,7 +61,7 @@     , hashable >=1.3.0.0     , haskoin-core >=0.19.0     , haskoin-node >=0.17.0-    , haskoin-store-data ==0.52.6+    , haskoin-store-data ==0.52.9     , hedis >=0.12.13     , http-types >=0.12.3     , lens >=4.18.1@@ -115,7 +115,7 @@     , haskoin-core >=0.19.0     , haskoin-node >=0.17.0     , haskoin-store-    , haskoin-store-data ==0.52.6+    , haskoin-store-data ==0.52.9     , hedis >=0.12.13     , http-types >=0.12.3     , lens >=4.18.1@@ -174,7 +174,7 @@     , haskoin-core >=0.19.0     , haskoin-node >=0.17.0     , haskoin-store-    , haskoin-store-data ==0.52.6+    , haskoin-store-data ==0.52.9     , hedis >=0.12.13     , hspec >=2.7.1     , http-types >=0.12.3
src/Haskoin/Store/Web.hs view
@@ -680,7 +680,10 @@     S.get  "/blockchain/unspent" scottyBinfoUnspent     S.get  "/blockchain/rawtx/:txid" scottyBinfoTx     S.get  "/blockchain/rawblock/:block" scottyBinfoBlock+    S.get  "/blockchain/latestblock" scottyBinfoLatest+    S.get  "/blockchain/unconfirmed-transactions" scottyBinfoMempool     S.get  "/blockchain/block-height/:height" scottyBinfoBlockHeight+    S.get  "/blockchain/blocks/:milliseconds" scottyBinfoBlocksDay     S.get  "/blockchain/export-history" scottyBinfoHistory     S.post "/blockchain/export-history" scottyBinfoHistory   where@@ -1555,19 +1558,38 @@ getSymbol :: MonadIO m => WebT m BinfoSymbol getSymbol = uncurry binfoTickerToSymbol <$> getPrice +scottyBinfoBlocksDay :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()+scottyBinfoBlocksDay = do+    setMetrics blockStat 144+    t <- min h . (`div` 1000) <$> S.param "milliseconds"+    ch <- lift $ asks (storeChain . webStore . webConfig)+    m <- blockAtOrBefore ch t+    bs <- go (d t) m+    streamEncoding $ toEncoding $ map toBinfoBlockInfo bs+  where+    h = fromIntegral (maxBound :: H.Timestamp)+    d = subtract (24 * 3600)+    go _ Nothing = return []+    go t (Just b)+        | H.blockTimestamp (blockDataHeader b) <= fromIntegral t =+              return []+        | otherwise = do+              b' <- getBlock (H.prevBlock (blockDataHeader b))+              (b :) <$> go t b'++ scottyMultiAddr :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()-scottyMultiAddr =-    get_addrs >>= \(addrs', xpubs, saddrs, sxpubs, xspecs) ->-    getNumTxId >>= \numtxid ->-    getCashAddr >>= \cashaddr ->-    getSymbol >>= \local ->-    get_offset >>= \offset ->-    get_count >>= \n ->-    get_prune >>= \prune ->-    get_filter >>= \fltr ->+scottyMultiAddr = do+    setMetrics multiaddrStat 1+    (addrs', xpubs, saddrs, sxpubs, xspecs) <- get_addrs+    numtxid <- getNumTxId+    cashaddr <- getCashAddr+    local <- getSymbol+    offset <- getBinfoOffset multiaddrStat+    n <- getBinfoCount+    prune <- get_prune+    fltr <- get_filter     let len = HashSet.size addrs' + HashSet.size xpubs-    in do-    setMetrics multiaddrStat len     xbals <- get_xbals xspecs     xtxns <- get_xpub_tx_count xbals xspecs     let sxbals = subset sxpubs xbals@@ -1655,18 +1677,6 @@             Just p  -> return $ binfoTickerToSymbol code p     get_prune = fmap not $ S.param "no_compact"         `S.rescue` const (return False)-    get_count = do-        d <- lift (asks (maxLimitDefault . webMaxLimits . webConfig))-        x <- lift (asks (maxLimitFull . webMaxLimits . webConfig))-        i <- min x <$> (S.param "n" `S.rescue` const (return d))-        return (fromIntegral i :: Int)-    get_offset = do-        x <- lift (asks (maxLimitOffset . webMaxLimits . webConfig))-        o <- S.param "offset" `S.rescue` const (return 0)-        when (o > x) $-            raise multiaddrStat $-            UserError $ "offset exceeded: " <> show o <> " > " <> show x-        return (fromIntegral o :: Int)     subset ks =         HashMap.filterWithKey (\k _ -> k `HashSet.member` ks)     compute_sxspecs sxpubs =@@ -1744,13 +1754,31 @@       | otherwise = 0     received _ = 0 +getBinfoCount :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m Int+getBinfoCount = do+        d <- lift (asks (maxLimitDefault . webMaxLimits . webConfig))+        x <- lift (asks (maxLimitFull . webMaxLimits . webConfig))+        i <- min x <$> (S.param "n" `S.rescue` const (return d))+        return (fromIntegral i :: Int)++getBinfoOffset :: (MonadUnliftIO m, MonadLoggerIO m)+               => (WebMetrics -> StatDist)+               -> WebT m Int+getBinfoOffset stat = do+        x <- lift (asks (maxLimitOffset . webMaxLimits . webConfig))+        o <- S.param "offset" `S.rescue` const (return 0)+        when (o > x) $+            raise stat $+            UserError $ "offset exceeded: " <> show o <> " > " <> show x+        return (fromIntegral o :: Int)+ scottyRawAddr :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()-scottyRawAddr =-    get_addr >>= \addr ->-    getNumTxId >>= \numtxid ->-    get_offset >>= \off ->-    get_count >>= \n -> do+scottyRawAddr = do     setMetrics rawaddrStat 1+    addr <- get_addr+    numtxid <- getNumTxId+    n <- getBinfoCount+    off <- getBinfoOffset rawaddrStat     bal <- fromMaybe (zeroBalance addr) <$> getBalance addr     net <- lift $ asks (storeNetwork . webStore . webConfig)     let abook = HashMap.singleton addr Nothing@@ -1770,18 +1798,6 @@         case textToAddr net txt of             Nothing -> raise rawaddrStat ThingNotFound             Just a  -> return a-    get_count = do-        d <- lift (asks (maxLimitDefault . webMaxLimits . webConfig))-        x <- lift (asks (maxLimitFull . webMaxLimits . webConfig))-        i <- min x <$> (S.param "limit" `S.rescue` const (return d))-        return $ fromIntegral i-    get_offset = do-        x <- lift (asks (maxLimitOffset . webMaxLimits . webConfig))-        o <- S.param "offset" `S.rescue` const (return 0)-        when (o > x) $-            raise rawaddrStat $-            UserError $ "offset exceeded: " <> show o <> " > " <> show x-        return $ fromIntegral o  scottyShortBal :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m () scottyShortBal =@@ -1868,6 +1884,25 @@             binfo_block = toBinfoBlock block_header binfo_txs next_blocks         return binfo_block +scottyBinfoLatest :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()+scottyBinfoLatest = do+    numtxid <- getNumTxId+    setMetrics blockStat 1+    best <- get_best_block+    let binfoTxIndices = map (encodeBinfoTxId numtxid) (blockDataTxs best)+        binfoHeaderHash = H.headerHash (blockDataHeader best)+        binfoHeaderTime = H.blockTimestamp (blockDataHeader best)+        binfoHeaderIndex = binfoHeaderTime+        binfoHeaderHeight = blockDataHeight best+    streamEncoding $ toEncoding BinfoHeader{..}+  where+    get_best_block =+        getBestBlock >>= \case+        Nothing -> raise blockStat ThingNotFound+        Just bh -> getBlock bh >>= \case+            Nothing -> raise blockStat ThingNotFound+            Just b  -> return b+ scottyBinfoBlock :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m () scottyBinfoBlock =     getNumTxId >>= \numtxid ->@@ -1933,6 +1968,20 @@     hx t = do         setHeaders         S.text . encodeHexLazy . runPutL . serialize $ transactionData t++scottyBinfoMempool :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()+scottyBinfoMempool = do+    setMetrics mempoolStat 1+    numtxid <- getNumTxId+    offset <- getBinfoOffset mempoolStat+    n <- getBinfoCount+    mempool <- getMempool+    let txids = map snd $ take n $ drop offset mempool+    txs <- catMaybes <$> mapM getTransaction txids+    net <- lift $ asks (storeNetwork . webStore . webConfig)+    setHeaders+    let mem = BinfoMempool $ map (toBinfoTxSimple numtxid) txs+    streamEncoding $ binfoMempoolToEncoding net mem  -- GET Network Information --