packages feed

haskoin-store 0.6.5 → 0.6.6

raw patch · 4 files changed

+28/−2 lines, 4 files

Files

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.6+### Added+- Check whether a transaction can be traced back to a coinbase after certain height.+ ## 0.6.5 ### Changed - Delete transactions in reverse topological order when reverting a block.
app/Main.hs view
@@ -283,6 +283,14 @@                 Nothing -> raise ThingNotFound                 Just x ->                     text . cs . encodeHex $ Serialize.encode (transactionData x)+        S.get "/transaction/:txid/after/:height" $ do+            txid <- param "txid"+            height <- param "height"+            res <-+                withSnapshot db $ \s -> do+                let d = (db, defaultReadOptions {useSnapshot = Just s})+                cbAfterHeight d height txid+            S.json $ object ["result" .= res]         S.get "/transactions" $ do             txids <- param "txids"             res <-
haskoin-store.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5c969c44d301acb86079c09d17e0b11f747975c2f78bd968bae27f268d20f56c+-- hash: 44214f2f80c61b6b3d5cdcd27689e23458381088f677d27790d326ea21df2da7  name:           haskoin-store-version:        0.6.5+version:        0.6.6 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
@@ -62,12 +62,14 @@     , xPubBalToEncoding     , xPubUnspentToJSON     , xPubUnspentToEncoding+    , cbAfterHeight     , mergeSourcesBy     ) where  import           Conduit import           Control.Monad.Except import           Control.Monad.Logger+import           Control.Monad.Trans.Maybe import           Data.Foldable import           Data.Function import           Data.List@@ -262,6 +264,18 @@     f p t =         XPubUnspent             {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  -- Snatched from: -- https://github.com/cblp/conduit-merge/blob/master/src/Data/Conduit/Merge.hs