haskoin-store 0.8.1 → 0.9.0
raw patch · 7 files changed
+46/−15 lines, 7 files
Files
- CHANGELOG.md +6/−0
- app/Main.hs +11/−5
- haskoin-store.cabal +2/−2
- src/Haskoin/Store.hs +2/−0
- src/Network/Haskoin/Store/Data.hs +19/−7
- src/Network/Haskoin/Store/Data/RocksDB.hs +1/−1
- src/Network/Haskoin/Store/Logic.hs +5/−0
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.9.0+### Added+- Version to health check output.+- Block weight for segwit.+- Transaction weight for segwit.+ ## 0.8.1 ### Added - Health check endpoint.
app/Main.hs view
@@ -224,21 +224,22 @@ let d = (db, defaultReadOptions {useSnapshot = Just s}) bh <- MaybeT $ getBestBlock d MaybeT $ getBlock d bh- maybeJSON res+ maybeJSON (blockDataToJSON net <$> res) S.get "/block/:block" $ do block <- param "block" res <- withSnapshot db $ \s -> do let d = (db, defaultReadOptions {useSnapshot = Just s}) getBlock d block- maybeJSON res+ maybeJSON (blockDataToJSON net <$> res) S.get "/block/height/:height" $ do height <- param "height" res <- withSnapshot db $ \s -> do let d = (db, defaultReadOptions {useSnapshot = Just s}) bs <- getBlocksAtHeight d height- catMaybes <$> mapM (getBlock d) bs+ catMaybes <$>+ mapM (fmap (fmap (blockDataToJSON net)) . getBlock d) bs S.json res S.get "/block/heights" $ do heights <- param "heights"@@ -246,14 +247,19 @@ withSnapshot db $ \s -> do let d = (db, defaultReadOptions {useSnapshot = Just s}) bs <- mapM (getBlocksAtHeight d) (nub heights)- mapM (fmap catMaybes . mapM (getBlock d)) bs+ mapM+ (fmap catMaybes .+ mapM (fmap (fmap (blockDataToJSON net)) . getBlock d))+ bs S.json res S.get "/blocks" $ do blocks <- param "blocks" res <- withSnapshot db $ \s -> do let d = (db, defaultReadOptions {useSnapshot = Just s})- mapM (getBlock d) (blocks :: [BlockHash])+ mapM+ (fmap (fmap (blockDataToJSON net)) . getBlock d)+ (blocks :: [BlockHash]) S.json res S.get "/mempool" $ do setHeader "Content-Type" "application/json"
haskoin-store.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: e59ebfda76a739c5ac1d9b30130b098813357c7b5dbf52bf4961d2045739bfb5+-- hash: 6ac575f0a235a7af3c995ba075ee5e8a91f0f70327fe186361fe1da63393e81c name: haskoin-store-version: 0.8.1+version: 0.9.0 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
@@ -47,6 +47,8 @@ , transactionData , isCoinbase , confirmed+ , blockDataToJSON+ , blockDataToEncoding , transactionToJSON , transactionToEncoding , outputToJSON
src/Network/Haskoin/Store/Data.hs view
@@ -25,6 +25,7 @@ import GHC.Generics import Haskoin import Network.Socket (SockAddr)+import Paths_haskoin_store as P import UnliftIO.Exception type UnixTime = Int64@@ -264,13 +265,15 @@ -- ^ block header , blockDataSize :: !Word32 -- ^ size of the block including witnesses+ , blockDataWeight :: !Word32+ -- ^ weight of this block (for segwit networks) , blockDataTxs :: ![TxHash] -- ^ block transactions } deriving (Show, Read, Eq, Ord, Generic, Serialize, Hashable) -- | JSON serialization for 'BlockData'.-blockDataPairs :: A.KeyValue kv => BlockData -> [kv]-blockDataPairs bv =+blockDataPairs :: A.KeyValue kv => Network -> BlockData -> [kv]+blockDataPairs net bv = [ "hash" .= headerHash (blockDataHeader bv) , "height" .= blockDataHeight bv , "mainchain" .= blockDataMainChain bv@@ -282,12 +285,14 @@ , "size" .= blockDataSize bv , "tx" .= blockDataTxs bv , "merkle" .= TxHash (merkleRoot (blockDataHeader bv))- ]+ ] ++ ["weight" .= blockDataWeight bv | getSegWit net] -instance ToJSON BlockData where- toJSON = object . blockDataPairs- toEncoding = pairs . mconcat . blockDataPairs+blockDataToJSON :: Network -> BlockData -> Value+blockDataToJSON net = object . blockDataPairs net +blockDataToEncoding :: Network -> BlockData -> Encoding+blockDataToEncoding net = pairs . mconcat . blockDataPairs net+ -- | Input information. data Input = Coinbase { inputPoint :: !OutPoint@@ -543,7 +548,13 @@ , "deleted" .= transactionDeleted dtx , "time" .= transactionTime dtx ] ++- ["rbf" .= transactionRBF dtx | getReplaceByFee net]+ ["rbf" .= transactionRBF dtx | getReplaceByFee net] +++ ["weight" .= w | getSegWit net]+ where+ w = let b = B.length $ S.encode (transactionData dtx) {txWitness = []}+ x = B.length $ S.encode (transactionData dtx)+ d = x - b+ in b * 4 + d transactionToJSON :: Network -> Transaction -> Value transactionToJSON net = object . transactionPairs net@@ -660,6 +671,7 @@ , "net" .= healthNetwork h , "ok" .= healthOK h , "synced" .= healthSynced h+ , "version" .= P.version ] instance ToJSON HealthCheck where
src/Network/Haskoin/Store/Data/RocksDB.hs view
@@ -19,7 +19,7 @@ import UnliftIO dataVersion :: Word32-dataVersion = 12+dataVersion = 13 data ExceptRocksDB = MempoolTxNotFound
src/Network/Haskoin/Store/Logic.hs view
@@ -233,6 +233,7 @@ , blockDataHeader = nodeHeader n , blockDataSize = fromIntegral (B.length (encode b)) , blockDataTxs = map txHash (blockTxns b)+ , blockDataWeight = fromIntegral w } insertAtHeight i (headerHash (nodeHeader n)) (nodeHeight n) setBest i (headerHash (nodeHeader n))@@ -248,6 +249,10 @@ (sortTxs (blockTxns b)) where br pos = BlockRef {blockRefHeight = nodeHeight n, blockRefPos = pos}+ w = let s = B.length (encode b {blockTxns = map (\t -> t {txWitness = []}) (blockTxns b)})+ x = B.length (encode b)+ d = x - s+ in s * 4 + d sortTxs :: [Tx] -> [Tx] sortTxs [] = []