packages feed

haskoin-store-data 0.47.3 → 0.47.4

raw patch · 4 files changed

+153/−7 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Haskoin.Store.Data: BinfoRawAddr :: !Balance -> ![BinfoTx] -> BinfoRawAddr
+ Haskoin.Store.Data: BinfoShortBal :: !Word64 -> !Word64 -> !Word64 -> BinfoShortBal
+ Haskoin.Store.Data: [binfoShortBalFinal] :: BinfoShortBal -> !Word64
+ Haskoin.Store.Data: [binfoShortBalReceived] :: BinfoShortBal -> !Word64
+ Haskoin.Store.Data: [binfoShortBalTxCount] :: BinfoShortBal -> !Word64
+ Haskoin.Store.Data: [getBinfoRawAddrBalance] :: BinfoRawAddr -> !Balance
+ Haskoin.Store.Data: [getBinfoRawAddrTxs] :: BinfoRawAddr -> ![BinfoTx]
+ Haskoin.Store.Data: binfoBlocksParseJSON :: Network -> Value -> Parser [BinfoBlock]
+ Haskoin.Store.Data: binfoBlocksToEncoding :: Network -> [BinfoBlock] -> Encoding
+ Haskoin.Store.Data: binfoBlocksToJSON :: Network -> [BinfoBlock] -> Value
+ Haskoin.Store.Data: binfoRawAddrParseJSON :: Network -> Value -> Parser BinfoRawAddr
+ Haskoin.Store.Data: binfoRawAddrToEncoding :: Network -> BinfoRawAddr -> Encoding
+ Haskoin.Store.Data: binfoRawAddrToJSON :: Network -> BinfoRawAddr -> Value
+ Haskoin.Store.Data: data BinfoRawAddr
+ Haskoin.Store.Data: data BinfoShortBal
+ Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoRawAddr
+ Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance Data.Aeson.Types.FromJSON.FromJSON Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance Data.Aeson.Types.ToJSON.ToJSON Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoRawAddr
+ Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoRawAddr
+ Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance GHC.Read.Read Haskoin.Store.Data.BinfoShortBal
+ Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoRawAddr
+ Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoShortBal

Files

CHANGELOG.md view
@@ -4,6 +4,19 @@ 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.47.4+### Added+- Implement Blockchain.info block height.+- Implement Blockchain.info raw address.+- Implement Blockchain.info balances.++### Fixed+- Make Blockchain.info unspent endpoint more efficient.+- Make Blockchain.info xpubs endpoint more efficient.++### Changed+- Use compact JSON serialization by default everywhere.+ ## 0.47.3 ### Fixed - Fix serialization bug with unspents.
haskoin-store-data.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 120e101c54350d43b5d4ca62bc4f525b79deb06f7a8344f3b5799d42c8db6a0b+-- hash: 5039966812a0dc31f6bda5c8df1b6ab6acb0ff857df800d52af52c4a60281691  name:           haskoin-store-data-version:        0.47.3+version:        0.47.4 synopsis:       Data for Haskoin Store description:    Please see the README on GitHub at <https://github.com/haskoin/haskoin-store#readme> category:       Bitcoin, Finance, Network
src/Haskoin/Store/Data.hs view
@@ -92,11 +92,16 @@     , binfoMultiAddrToJSON     , binfoMultiAddrToEncoding     , binfoMultiAddrParseJSON+    , BinfoShortBal(..)     , BinfoBalance(..)     , toBinfoAddrs     , binfoBalanceToJSON     , binfoBalanceToEncoding     , binfoBalanceParseJSON+    , BinfoRawAddr(..)+    , binfoRawAddrToJSON+    , binfoRawAddrToEncoding+    , binfoRawAddrParseJSON     , BinfoAddr(..)     , parseBinfoAddr     , BinfoWallet(..)@@ -114,6 +119,9 @@     , binfoBlockToJSON     , binfoBlockToEncoding     , binfoBlockParseJSON+    , binfoBlocksToJSON+    , binfoBlocksToEncoding+    , binfoBlocksParseJSON     , BinfoTx(..)     , relevantTxs     , toBinfoTx@@ -2022,7 +2030,7 @@     deserialize = RawResultList <$> go       where         go = isEmpty >>= \case-            True -> return []+            True  -> return []             False -> (:) <$> deserialize <*> go  instance Serial a => Serialize (RawResultList a) where@@ -2309,6 +2317,100 @@     ts = AE.list (binfoTxToEncoding net) getBinfoMultiAddrTxs     net = if not getBinfoMultiAddrCashAddr && net' == bch then btc else net' +data BinfoRawAddr+    = BinfoRawAddr+      { getBinfoRawAddrBalance :: !Balance+      , getBinfoRawAddrTxs     :: ![BinfoTx]+      }+    deriving (Eq, Show, Generic, NFData)++binfoRawAddrToJSON :: Network -> BinfoRawAddr -> Value+binfoRawAddrToJSON net BinfoRawAddr{..} =+    A.object+    [+        "hash160"        .= (encodeHex . runPutS . serialize <$> h160),+        "address"        .= addrToJSON net balanceAddress,+        "n_tx"           .= balanceTxCount,+        "n_unredeemed"   .= balanceUnspentCount,+        "total_received" .= balanceTotalReceived,+        "total_sent"     .= (balanceTotalReceived - bal),+        "final_balance"  .= bal,+        "txs"            .= map (binfoTxToJSON net) getBinfoRawAddrTxs+    ]+  where+    Balance{..} = getBinfoRawAddrBalance+    bal = balanceAmount + balanceZero+    h160 = case balanceAddress of+               PubKeyAddress h        -> Just h+               ScriptAddress h        -> Just h+               WitnessPubKeyAddress h -> Just h+               _                      -> Nothing++binfoRawAddrToEncoding :: Network -> BinfoRawAddr -> Encoding+binfoRawAddrToEncoding net BinfoRawAddr{..} =+    AE.pairs $+    "hash160"        .= (encodeHex . runPutS . serialize <$> h160) <>+    "address" `AE.pair` addrToEncoding net balanceAddress <>+    "n_tx"           .= balanceTxCount <>+    "n_unredeemed"   .= balanceUnspentCount <>+    "total_received" .= balanceTotalReceived <>+    "total_sent"     .= (balanceTotalReceived - bal) <>+    "final_balance"  .= bal <>+    "txs"     `AE.pair` AE.list (binfoTxToEncoding net) getBinfoRawAddrTxs+  where+    Balance{..} = getBinfoRawAddrBalance+    bal = balanceAmount + balanceZero+    h160 = case balanceAddress of+               PubKeyAddress h        -> Just h+               ScriptAddress h        -> Just h+               WitnessPubKeyAddress h -> Just h+               _                      -> Nothing++binfoRawAddrParseJSON :: Network -> Value -> Parser BinfoRawAddr+binfoRawAddrParseJSON net = A.withObject "balancetxs" $ \o -> do+    balanceAddress <- addrFromJSON net =<< o .: "address"+    balanceAmount <- o .: "final_balance"+    let balanceZero = 0+    balanceUnspentCount <- o .: "n_unredeemed"+    balanceTxCount <- o .: "n_tx"+    balanceTotalReceived <- o .: "total_received"+    txs <- mapM (binfoTxParseJSON net) =<< o .: "txs"+    return+        BinfoRawAddr+        {+            getBinfoRawAddrBalance = Balance{..},+            getBinfoRawAddrTxs = txs+        }++data BinfoShortBal+    = BinfoShortBal+      { binfoShortBalFinal    :: !Word64+      , binfoShortBalTxCount  :: !Word64+      , binfoShortBalReceived :: !Word64+      }+    deriving (Eq, Show, Read, Generic, NFData)++instance ToJSON BinfoShortBal where+    toJSON BinfoShortBal{..} =+        A.object+        [+            "final_balance" .= binfoShortBalFinal,+            "n_tx" .= binfoShortBalTxCount,+            "total_received" .= binfoShortBalReceived+        ]+    toEncoding BinfoShortBal{..} =+        AE.pairs $+        "final_balance" .= binfoShortBalFinal <>+        "n_tx" .= binfoShortBalTxCount <>+        "total_received" .= binfoShortBalReceived++instance FromJSON BinfoShortBal where+    parseJSON = A.withObject "short_balance" $ \o -> do+        binfoShortBalFinal <- o .: "final_balance"+        binfoShortBalTxCount <- o .: "n_tx"+        binfoShortBalReceived <- o .: "total_received"+        return BinfoShortBal{..}+ data BinfoBalance     = BinfoAddrBalance         { getBinfoAddress      :: !Address@@ -2509,6 +2611,19 @@ binfoUnspentsParseJSON net = A.withObject "unspents" $ \o -> do     us <- mapM (binfoUnspentParseJSON net) =<< o .: "unspent_outputs"     return (BinfoUnspents us)++binfoBlocksToJSON :: Network -> [BinfoBlock] -> Value+binfoBlocksToJSON net blocks =+    A.object [ "blocks" .= map (binfoBlockToJSON net) blocks ]++binfoBlocksToEncoding :: Network -> [BinfoBlock] -> Encoding+binfoBlocksToEncoding net blocks =+    AE.pairs $ "blocks" `AE.pair` AE.list (binfoBlockToEncoding net) blocks++binfoBlocksParseJSON :: Network -> Value -> Parser [BinfoBlock]+binfoBlocksParseJSON net =+    A.withObject "blocks" $ \o ->+    mapM (binfoBlockParseJSON net) =<< o .: "blocks"  toBinfoBlock :: BlockData -> [BinfoTx] -> [BlockHash] -> BinfoBlock toBinfoBlock BlockData{..} txs next_blocks =
test/Haskoin/Store/DataSpec.hs view
@@ -71,6 +71,7 @@     , JsonBox (arbitrary :: Gen BinfoSpender)     , JsonBox (arbitrary :: Gen BinfoTicker)     , JsonBox (arbitrary :: Gen BinfoTxId)+    , JsonBox (arbitrary :: Gen BinfoShortBal)     ]  netVals :: [NetBox]@@ -139,6 +140,14 @@              , binfoUnspentToEncoding              , binfoUnspentParseJSON              , arbitraryNetData)+    , NetBox ( binfoBlocksToJSON+             , binfoBlocksToEncoding+             , binfoBlocksParseJSON+             , arbitraryNetData)+    , NetBox ( binfoRawAddrToJSON+             , binfoRawAddrToEncoding+             , binfoRawAddrParseJSON+             , arbitraryNetData)     ]  spec :: Spec@@ -402,12 +411,21 @@     arbitrary = do         getBinfoMultiAddrAddresses <- arbitrary         getBinfoMultiAddrWallet <- arbitrary-        getBinfoMultiAddrTxs <- arbitrary+        getBinfoMultiAddrTxs <- resize 10 arbitrary         getBinfoMultiAddrInfo <- arbitrary         getBinfoMultiAddrRecommendFee <- arbitrary         getBinfoMultiAddrCashAddr <- arbitrary         return BinfoMultiAddr {..} +instance Arbitrary BinfoRawAddr where+    arbitrary = do+        balance <- arbitrary+        txs <- arbitrary+        return $ BinfoRawAddr balance{balanceZero = 0} txs++instance Arbitrary BinfoShortBal where+    arbitrary = BinfoShortBal <$> arbitrary <*> arbitrary <*> arbitrary+ instance Arbitrary BinfoBalance where     arbitrary = do         getBinfoAddress <- arbitraryAddress@@ -446,15 +464,15 @@         getBinfoBlockMain <- arbitrary         getBinfoBlockHeight <- arbitrary         getBinfoBlockWeight <- arbitrary-        getBinfoBlockTx <- arbitrary+        getBinfoBlockTx <- resize 5 arbitrary         return BinfoBlock{..}  instance Arbitrary BinfoTx where     arbitrary = do         getBinfoTxHash <- arbitraryTxHash         getBinfoTxVer <- arbitrary-        getBinfoTxInputs <- resize 10 $ listOf1 arbitrary-        getBinfoTxOutputs <- resize 10 $ listOf1 arbitrary+        getBinfoTxInputs <- resize 5 $ listOf1 arbitrary+        getBinfoTxOutputs <- resize 5 $ listOf1 arbitrary         let getBinfoTxVinSz = fromIntegral (length getBinfoTxInputs)             getBinfoTxVoutSz = fromIntegral (length getBinfoTxOutputs)         getBinfoTxSize <- arbitrary