haskoin-store 0.38.0 → 0.38.1
raw patch · 2 files changed
+33/−32 lines, 2 filesdep ~haskoin-storedep ~haskoin-store-data
Dependency ranges changed: haskoin-store, haskoin-store-data
Files
- haskoin-store.cabal +6/−6
- src/Haskoin/Store/Web.hs +27/−26
haskoin-store.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: b1a8d34c8b0abb61f5882a9454a5c93e684db97d46d01e20eb7bc24cfc02c188+-- hash: 2634f3871c33f6dba54c93ffab3a2f2f1f8ff5eb9bc8559216a0367cc2c421f6 name: haskoin-store-version: 0.38.0+version: 0.38.1 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@@ -53,7 +53,7 @@ , hashable >=1.3.0.0 , haskoin-core >=0.13.6 , haskoin-node >=0.14.1- , haskoin-store-data ==0.38.0+ , haskoin-store-data ==0.38.1 , hedis >=0.12.13 , http-types >=0.12.3 , monad-logger >=0.3.32@@ -96,7 +96,7 @@ , haskoin-core >=0.13.6 , haskoin-node >=0.14.1 , haskoin-store- , haskoin-store-data ==0.38.0+ , haskoin-store-data ==0.38.1 , monad-logger >=0.3.32 , mtl >=2.2.2 , nqe >=0.6.1@@ -135,8 +135,8 @@ , hashable >=1.3.0.0 , haskoin-core >=0.13.6 , haskoin-node >=0.14.1- , haskoin-store ==0.38.0- , haskoin-store-data ==0.38.0+ , haskoin-store ==0.38.1+ , haskoin-store-data ==0.38.1 , hedis >=0.12.13 , hspec >=2.7.1 , http-types >=0.12.3
src/Haskoin/Store/Web.hs view
@@ -15,7 +15,8 @@ , runWeb ) where -import Conduit ()+import Conduit (await, runConduit, takeC, yield,+ (.|)) import Control.Applicative ((<|>)) import Control.Monad (forever, unless, when, (<=<)) import Control.Monad.Logger (MonadLoggerIO, logErrorS,@@ -35,6 +36,7 @@ import Data.Char (isSpace) import Data.Default (Default (..)) import Data.Function ((&))+import qualified Data.HashSet as HashSet import Data.List (nub) import Data.Maybe (catMaybes, fromMaybe, listToMaybe, mapMaybe)@@ -656,39 +658,38 @@ GenericResult <$> cbAfterHeight (fromIntegral height) txid -- | Check if any of the ancestors of this transaction is a coinbase after the--- specified height. Returns'Nothing' if answer cannot be computed before+-- specified height. Returns 'Nothing' if answer cannot be computed before -- hitting limits. cbAfterHeight :: (MonadIO m, StoreReadBase m) => H.BlockHeight -> TxHash -> m (Maybe Bool)-cbAfterHeight height begin =- go (10000 :: Int) [begin] -- Depth first search+cbAfterHeight height txid =+ inputs 10000 HashSet.empty HashSet.empty [txid] where- go 0 _ = return Nothing -- We searched too far. Return Nothing.- go _ [] = return $ Just False -- Nothing left to search.- go i (txid:xs) =- getTransaction txid >>= \case- Nothing -> return Nothing -- Error. Bail out.- Just tx- | cbCheck tx -> return $ Just True -- Stop everything. Return.- | heightCheck tx -> go i xs -- Continue search sideways- | otherwise -> do- let is = outPointHash . inputPoint <$> transactionInputs tx- -- We have to search down and search sideways- go (i - 1) is `returnOr` go i xs- cbCheck tx =- any isCoinbase (transactionInputs tx) &&- blockRefHeight (transactionBlock tx) > height- heightCheck tx =+ inputs 0 _ _ [] = return Nothing+ inputs i is ns [] =+ let is' = HashSet.union is ns+ ns' = HashSet.empty+ ts = HashSet.toList (HashSet.difference ns is)+ in case ts of+ [] -> return (Just False)+ _ -> inputs i is' ns' ts+ inputs i is ns (t:ts) = getTransaction t >>= \case+ Nothing -> return Nothing+ Just tx | height_check tx ->+ if cb_check tx+ then return (Just True)+ else let ns' = HashSet.union (ins tx) ns+ in inputs (i - 1) is ns' ts+ | otherwise -> inputs (i - 1) is ns ts+ cb_check = any isCoinbase . transactionInputs+ ins = HashSet.fromList . map (outPointHash . inputPoint) . transactionInputs+ height_check tx = case transactionBlock tx of- BlockRef thisHeight _ -> thisHeight <= height- _ -> False- returnOr a b =- a >>= \case- Just True -> return $ Just True -- Bubble up this result- _ -> b+ BlockRef h _ -> h > height+ _ -> True -- POST Transaction --