packages feed

haskoin-store-data 0.44.0 → 0.45.0

raw patch · 4 files changed

+82/−60 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Haskoin.Store.Data: BinfoAddress :: !Address -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> BinfoAddress
- Haskoin.Store.Data: BinfoXPubKey :: !XPubKey -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word32 -> !Word32 -> BinfoAddress
- Haskoin.Store.Data: binfoAddressParseJSON :: Network -> Value -> Parser BinfoAddress
- Haskoin.Store.Data: binfoAddressToEncoding :: Network -> BinfoAddress -> Encoding
- Haskoin.Store.Data: binfoAddressToJSON :: Network -> BinfoAddress -> Value
- Haskoin.Store.Data: data BinfoAddress
- Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoAddress
- Haskoin.Store.Data: instance Data.Serialize.Serialize Haskoin.Store.Data.BinfoAddress
- Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoAddress
- Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoAddress
- Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoAddress
+ Haskoin.Store.Data: BinfoAddrBalance :: !Address -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> BinfoBalance
+ Haskoin.Store.Data: BinfoXPubBalance :: !XPubKey -> !Word64 -> !Word64 -> !Word64 -> !Word64 -> !Word32 -> !Word32 -> BinfoBalance
+ Haskoin.Store.Data: TxIndexConflict :: ![TxHash] -> Except
+ Haskoin.Store.Data: binfoBalanceParseJSON :: Network -> Value -> Parser BinfoBalance
+ Haskoin.Store.Data: binfoBalanceToEncoding :: Network -> BinfoBalance -> Encoding
+ Haskoin.Store.Data: binfoBalanceToJSON :: Network -> BinfoBalance -> Value
+ Haskoin.Store.Data: data BinfoBalance
+ Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoBalance
+ Haskoin.Store.Data: instance Data.Serialize.Serialize Haskoin.Store.Data.BinfoBalance
+ Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoBalance
+ Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoBalance
+ Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoBalance
- Haskoin.Store.Data: BinfoMultiAddr :: ![BinfoAddress] -> !BinfoWallet -> ![BinfoTx] -> !BinfoInfo -> !Bool -> !Bool -> BinfoMultiAddr
+ Haskoin.Store.Data: BinfoMultiAddr :: ![BinfoBalance] -> !BinfoWallet -> ![BinfoTx] -> !BinfoInfo -> !Bool -> !Bool -> BinfoMultiAddr
- Haskoin.Store.Data: [getBinfoAddrBalance] :: BinfoAddress -> !Word64
+ Haskoin.Store.Data: [getBinfoAddrBalance] :: BinfoBalance -> !Word64
- Haskoin.Store.Data: [getBinfoAddrReceived] :: BinfoAddress -> !Word64
+ Haskoin.Store.Data: [getBinfoAddrReceived] :: BinfoBalance -> !Word64
- Haskoin.Store.Data: [getBinfoAddrSent] :: BinfoAddress -> !Word64
+ Haskoin.Store.Data: [getBinfoAddrSent] :: BinfoBalance -> !Word64
- Haskoin.Store.Data: [getBinfoAddrTxCount] :: BinfoAddress -> !Word64
+ Haskoin.Store.Data: [getBinfoAddrTxCount] :: BinfoBalance -> !Word64
- Haskoin.Store.Data: [getBinfoAddress] :: BinfoAddress -> !Address
+ Haskoin.Store.Data: [getBinfoAddress] :: BinfoBalance -> !Address
- Haskoin.Store.Data: [getBinfoMultiAddrAddresses] :: BinfoMultiAddr -> ![BinfoAddress]
+ Haskoin.Store.Data: [getBinfoMultiAddrAddresses] :: BinfoMultiAddr -> ![BinfoBalance]
- Haskoin.Store.Data: [getBinfoXPubAccountIndex] :: BinfoAddress -> !Word32
+ Haskoin.Store.Data: [getBinfoXPubAccountIndex] :: BinfoBalance -> !Word32
- Haskoin.Store.Data: [getBinfoXPubChangeIndex] :: BinfoAddress -> !Word32
+ Haskoin.Store.Data: [getBinfoXPubChangeIndex] :: BinfoBalance -> !Word32
- Haskoin.Store.Data: [getBinfoXPubKey] :: BinfoAddress -> !XPubKey
+ Haskoin.Store.Data: [getBinfoXPubKey] :: BinfoBalance -> !XPubKey
- Haskoin.Store.Data: toBinfoAddrs :: HashMap Address Balance -> HashMap XPubKey [XPubBal] -> HashMap XPubKey Int -> [BinfoAddress]
+ Haskoin.Store.Data: toBinfoAddrs :: HashMap Address Balance -> HashMap XPubKey [XPubBal] -> HashMap XPubKey Int -> [BinfoBalance]

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.45.0+### Added+- Using a tx_index that results in a txid conflict returns a 409 - Conflict.+ ## 0.44.0 ### Changed - Numeric txid now 53 bits long and doesn't return transactions when hashes collide.
haskoin-store-data.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: ecd96d68e6c3b5aae68fb596aa69768a04bd8ec92e079259d9c657a2d273434d+-- hash: 593dbf63f1100ec4da73a86f3fcf7ab620207c88317736c11bc679f543a908bd  name:           haskoin-store-data-version:        0.44.0+version:        0.45.0 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
@@ -88,11 +88,11 @@     , binfoMultiAddrToJSON     , binfoMultiAddrToEncoding     , binfoMultiAddrParseJSON-    , BinfoAddress(..)+    , BinfoBalance(..)     , toBinfoAddrs-    , binfoAddressToJSON-    , binfoAddressToEncoding-    , binfoAddressParseJSON+    , binfoBalanceToJSON+    , binfoBalanceToEncoding+    , binfoBalanceParseJSON     , BinfoAddr(..)     , parseBinfoAddr     , BinfoWallet(..)@@ -1514,6 +1514,7 @@     | UserError !String     | StringError !String     | BlockTooLarge+    | TxIndexConflict ![TxHash]     deriving (Show, Eq, Ord, Serialize, Generic, NFData)  instance Exception Except@@ -1527,35 +1528,51 @@         object $         case e of             ThingNotFound ->-                ["error" .= String "not-found"]+                [ "error" .= String "not-found-or-invalid-arg"+                , "message" .= String "Item not found or argument invalid"+                ]             ServerError ->-                ["error" .= String "server-error"]+                [ "error" .= String "server-error"+                , "message" .= String "Server error" ]             BadRequest ->-                ["error" .= String "bad-request"]+                [ "error" .= String "bad-request"+                , "message" .= String "Invalid request" ]             UserError msg ->                 [ "error" .= String "user-error"-                , "message" .= String (cs msg)-                ]+                , "message" .= String (cs msg) ]             StringError msg ->                 [ "error" .= String "string-error"-                , "message" .= String (cs msg)-                ]+                , "message" .= String (cs msg) ]             BlockTooLarge ->-                ["error" .= String "block-too-large"]+                [ "error" .= String "block-too-large"+                , "message" .= String "Block is too large to get all txs" ]+            TxIndexConflict txids ->+                [ "error" .= String "multiple-tx-index"+                , "message" .= String "Many txs match that tx_index"+                , "txids" .= txids ]  instance FromJSON Except where     parseJSON =         A.withObject "Except" $ \o -> do             ctr <- o .: "error"-            msg <- fromMaybe "" <$> o .:? "message"+            msg <- o .:? "message" .!= ""             case ctr of-                String "not-found"       -> return ThingNotFound-                String "server-error"    -> return ServerError-                String "bad-request"     -> return BadRequest-                String "user-error"      -> return $ UserError msg-                String "string-error"    -> return $ StringError msg-                String "block-too-large" -> return BlockTooLarge-                _                        -> mzero+                String "not-found-or-invalid-arg" ->+                    return ThingNotFound+                String "server-error" ->+                    return ServerError+                String "bad-request" ->+                    return BadRequest+                String "user-error" ->+                    return $ UserError msg+                String "string-error" ->+                    return $ StringError msg+                String "block-too-large" ->+                    return BlockTooLarge+                String "multiple-tx-index" -> do+                    txids <- o .: "txids"+                    return $ TxIndexConflict txids+                _ -> mzero  toIntTxId :: TxHash -> Word64 toIntTxId h =@@ -1598,7 +1615,7 @@  data BinfoMultiAddr     = BinfoMultiAddr-        { getBinfoMultiAddrAddresses    :: ![BinfoAddress]+        { getBinfoMultiAddrAddresses    :: ![BinfoBalance]         , getBinfoMultiAddrWallet       :: !BinfoWallet         , getBinfoMultiAddrTxs          :: ![BinfoTx]         , getBinfoMultiAddrInfo         :: !BinfoInfo@@ -1610,7 +1627,7 @@ binfoMultiAddrToJSON :: Network -> BinfoMultiAddr -> Value binfoMultiAddrToJSON net' BinfoMultiAddr {..} =     object $-        [ "addresses" .= map (binfoAddressToJSON net) getBinfoMultiAddrAddresses+        [ "addresses" .= map (binfoBalanceToJSON net) getBinfoMultiAddrAddresses         , "wallet"    .= getBinfoMultiAddrWallet         , "txs"       .= map (binfoTxToJSON net) getBinfoMultiAddrTxs         , "info"      .= getBinfoMultiAddrInfo@@ -1623,7 +1640,7 @@ binfoMultiAddrParseJSON :: Network -> Value -> Parser BinfoMultiAddr binfoMultiAddrParseJSON net = withObject "multiaddr" $ \o -> do     getBinfoMultiAddrAddresses <--        mapM (binfoAddressParseJSON net) =<< o .: "addresses"+        mapM (binfoBalanceParseJSON net) =<< o .: "addresses"     getBinfoMultiAddrWallet <- o .: "wallet"     getBinfoMultiAddrTxs <-         mapM (binfoTxParseJSON net) =<< o .: "txs"@@ -1643,19 +1660,19 @@         <> if getBinfoMultiAddrCashAddr then "cash_addr" .= True else mempty         )   where-    as = list (binfoAddressToEncoding net) getBinfoMultiAddrAddresses+    as = list (binfoBalanceToEncoding net) getBinfoMultiAddrAddresses     ts = list (binfoTxToEncoding net) getBinfoMultiAddrTxs     net = if not getBinfoMultiAddrCashAddr && net' == bch then btc else net' -data BinfoAddress-    = BinfoAddress+data BinfoBalance+    = BinfoAddrBalance         { getBinfoAddress      :: !Address         , getBinfoAddrTxCount  :: !Word64         , getBinfoAddrReceived :: !Word64         , getBinfoAddrSent     :: !Word64         , getBinfoAddrBalance  :: !Word64         }-    | BinfoXPubKey+    | BinfoXPubBalance         { getBinfoXPubKey          :: !XPubKey         , getBinfoAddrTxCount      :: !Word64         , getBinfoAddrReceived     :: !Word64@@ -1666,8 +1683,8 @@         }     deriving (Eq, Show, Generic, Serialize, NFData) -binfoAddressToJSON :: Network -> BinfoAddress -> Value-binfoAddressToJSON net BinfoAddress {..} =+binfoBalanceToJSON :: Network -> BinfoBalance -> Value+binfoBalanceToJSON net BinfoAddrBalance {..} =     object         [ "address"        .= addrToJSON net getBinfoAddress         , "final_balance"  .= getBinfoAddrBalance@@ -1675,7 +1692,7 @@         , "total_received" .= getBinfoAddrReceived         , "total_sent"     .= getBinfoAddrSent         ]-binfoAddressToJSON net BinfoXPubKey {..} =+binfoBalanceToJSON net BinfoXPubBalance {..} =     object         [ "address"        .= xPubToJSON net getBinfoXPubKey         , "change_index"   .= getBinfoXPubChangeIndex@@ -1686,8 +1703,8 @@         , "total_sent"     .= getBinfoAddrSent         ] -binfoAddressParseJSON :: Network -> Value -> Parser BinfoAddress-binfoAddressParseJSON net = withObject "address" $ \o -> x o <|> a o+binfoBalanceParseJSON :: Network -> Value -> Parser BinfoBalance+binfoBalanceParseJSON net = withObject "address" $ \o -> x o <|> a o   where     x o = do         getBinfoXPubKey <- xPubFromJSON net =<< o .: "address"@@ -1697,17 +1714,17 @@         getBinfoAddrTxCount <- o .: "n_tx"         getBinfoAddrReceived <- o .: "total_received"         getBinfoAddrSent <- o .: "total_sent"-        return BinfoXPubKey{..}+        return BinfoXPubBalance{..}     a o = do         getBinfoAddress <- addrFromJSON net =<< o .: "address"         getBinfoAddrBalance <- o .: "final_balance"         getBinfoAddrTxCount <- o .: "n_tx"         getBinfoAddrReceived <- o .: "total_received"         getBinfoAddrSent <- o .: "total_sent"-        return BinfoAddress{..}+        return BinfoAddrBalance{..} -binfoAddressToEncoding :: Network -> BinfoAddress -> Encoding-binfoAddressToEncoding net BinfoAddress {..} =+binfoBalanceToEncoding :: Network -> BinfoBalance -> Encoding+binfoBalanceToEncoding net BinfoAddrBalance {..} =     pairs         (  "address"         `pair` addrToEncoding net getBinfoAddress         <> "final_balance"   .= getBinfoAddrBalance@@ -1715,7 +1732,7 @@         <> "total_received"  .= getBinfoAddrReceived         <> "total_sent"      .= getBinfoAddrSent         )-binfoAddressToEncoding net BinfoXPubKey {..} =+binfoBalanceToEncoding net BinfoXPubBalance {..} =     pairs         (  "address"         `pair` xPubToEncoding net getBinfoXPubKey         <> "change_index"    .= getBinfoXPubChangeIndex@@ -2280,7 +2297,7 @@ toBinfoAddrs :: HashMap Address Balance              -> HashMap XPubKey [XPubBal]              -> HashMap XPubKey Int-             -> [BinfoAddress]+             -> [BinfoBalance] toBinfoAddrs only_addrs only_xpubs xpub_txs =     xpub_bals <> addr_bals   where@@ -2300,14 +2317,14 @@                 Just i  -> fromIntegral i             ax = foldl max 0 (map (i 0) xs)             cx = foldl max 0 (map (i 1) xs)-        in BinfoXPubKey{ getBinfoXPubKey = k-                       , getBinfoAddrTxCount = count-                       , getBinfoAddrReceived = received-                       , getBinfoAddrSent = sent-                       , getBinfoAddrBalance = bal-                       , getBinfoXPubAccountIndex = ax-                       , getBinfoXPubChangeIndex = cx-                       }+        in BinfoXPubBalance{ getBinfoXPubKey = k+                           , getBinfoAddrTxCount = count+                           , getBinfoAddrReceived = received+                           , getBinfoAddrSent = sent+                           , getBinfoAddrBalance = bal+                           , getBinfoXPubAccountIndex = ax+                           , getBinfoXPubChangeIndex = cx+                           }     xpub_bals = map (uncurry xpub_bal) (HashMap.toList only_xpubs)     addr_bals =         let f Balance{..} =@@ -2316,12 +2333,12 @@                     recv = balanceTotalReceived                     tx_count = balanceTxCount                     bal = balanceAmount + balanceZero-                in BinfoAddress{ getBinfoAddress = addr-                               , getBinfoAddrTxCount = tx_count-                               , getBinfoAddrReceived = recv-                               , getBinfoAddrSent = sent-                               , getBinfoAddrBalance = bal-                               }+                in BinfoAddrBalance{ getBinfoAddress = addr+                                   , getBinfoAddrTxCount = tx_count+                                   , getBinfoAddrReceived = recv+                                   , getBinfoAddrSent = sent+                                   , getBinfoAddrBalance = bal+                                   }          in map f $ HashMap.elems only_addrs  toBinfoTxSimple :: Bool
test/Haskoin/Store/DataSpec.hs view
@@ -49,7 +49,7 @@     , SerialBox (arbitrary :: Gen (RawResultList BlockData))     , SerialBox (arbitrary :: Gen Except)     , SerialBox (arbitrary :: Gen BinfoWallet)-    , SerialBox (arbitrary :: Gen BinfoAddress)+    , SerialBox (arbitrary :: Gen BinfoBalance)     , SerialBox (arbitrary :: Gen BinfoBlockInfo)     , SerialBox (arbitrary :: Gen BinfoXPubPath)     , SerialBox (arbitrary :: Gen BinfoSpender)@@ -122,9 +122,9 @@              , binfoMultiAddrToEncoding              , binfoMultiAddrParseJSON              , arbitraryNetData)-    , NetBox ( binfoAddressToJSON-             , binfoAddressToEncoding-             , binfoAddressParseJSON+    , NetBox ( binfoBalanceToJSON+             , binfoBalanceToEncoding+             , binfoBalanceParseJSON              , arbitraryNetData)     , NetBox ( binfoTxToJSON              , binfoTxToEncoding@@ -393,6 +393,7 @@         , UserError <$> arbitrary         , StringError <$> arbitrary         , return BlockTooLarge+        , TxIndexConflict <$> listOf1 arbitraryTxHash         ]  ---------------------------------------@@ -415,7 +416,7 @@         getBinfoMultiAddrCashAddr <- arbitrary         return BinfoMultiAddr {..} -instance Arbitrary BinfoAddress where+instance Arbitrary BinfoBalance where     arbitrary = do         getBinfoAddress <- arbitraryAddress         getBinfoAddrTxCount <- arbitrary@@ -425,7 +426,7 @@         getBinfoXPubKey <- snd <$> arbitraryXPubKey         getBinfoXPubAccountIndex <- arbitrary         getBinfoXPubChangeIndex <- arbitrary-        elements [BinfoAddress {..}, BinfoXPubKey {..}]+        elements [BinfoAddrBalance {..}, BinfoXPubBalance {..}]  instance Arbitrary BinfoWallet where     arbitrary = do