haskoin-store 0.6.6 → 0.6.7
raw patch · 4 files changed
+33/−13 lines, 4 files
Files
- CHANGELOG.md +4/−0
- app/Main.hs +1/−1
- haskoin-store.cabal +2/−2
- src/Haskoin/Store.hs +26/−10
CHANGELOG.md view
@@ -4,6 +4,10 @@ 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.6.7+### Changed+- Impose restrictions on recursion for coinbase after height checks.+ ## 0.6.6 ### Added - Check whether a transaction can be traced back to a coinbase after certain height.
app/Main.hs view
@@ -289,7 +289,7 @@ res <- withSnapshot db $ \s -> do let d = (db, defaultReadOptions {useSnapshot = Just s})- cbAfterHeight d height txid+ cbAfterHeight d 100 height txid S.json $ object ["result" .= res] S.get "/transactions" $ do txids <- param "txids"
haskoin-store.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 44214f2f80c61b6b3d5cdcd27689e23458381088f677d27790d326ea21df2da7+-- hash: db673c6b1202a70890532986a1332d88c3463356e623cf7e03853a905961700b name: haskoin-store-version: 0.6.6+version: 0.6.7 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/Haskoin/Store.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -266,16 +267,31 @@ {xPubUnspentPath = pathToList p, xPubUnspent = t} -- | Check if any of the ancestors of this transaction is a coinbase after the--- specified height.-cbAfterHeight :: (Monad m, StoreRead i m) => i -> BlockHeight -> TxHash -> m Bool-cbAfterHeight i h t = fmap (fromMaybe False) . runMaybeT $ do- tx <- MaybeT $ getTransaction i t- if any isCoinbase (transactionInputs tx)- then- return $ blockRefHeight (transactionBlock tx) > h- else do- let ins = nub $ map (outPointHash . inputPoint) (transactionInputs tx)- or <$> mapM (lift . cbAfterHeight i h) ins+-- specified height. Returns 'Nothing' if answer cannot be computed before+-- hitting limits.+cbAfterHeight ::+ (Monad m, StoreRead i m)+ => i+ -> Int+ -> BlockHeight+ -> TxHash+ -> m (Maybe Bool)+cbAfterHeight _ 0 _ _ = return Nothing+cbAfterHeight i d h t =+ runMaybeT $ do+ tx <- MaybeT $ getTransaction i t+ if any isCoinbase (transactionInputs tx)+ then return $ blockRefHeight (transactionBlock tx) > h+ else case transactionBlock tx of+ BlockRef {blockRefHeight = b}+ | b <= h -> return False+ _ -> do+ let ins =+ nub $+ map+ (outPointHash . inputPoint)+ (transactionInputs tx)+ or <$> mapM (MaybeT . cbAfterHeight i (d - 1) h) ins -- Snatched from: -- https://github.com/cblp/conduit-merge/blob/master/src/Data/Conduit/Merge.hs