haskoin-store-data 0.41.3 → 0.42.1
raw patch · 3 files changed
+128/−16 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Haskoin.Store.Data: BinfoUnspent :: !TxHash -> !Word32 -> !ByteString -> !Word64 -> !Word32 -> !BinfoTxId -> !Maybe BinfoXPubPath -> BinfoUnspent
+ Haskoin.Store.Data: BinfoUnspents :: [BinfoUnspent] -> BinfoUnspents
+ Haskoin.Store.Data: [getBinfoTxRBF] :: BinfoTx -> !Bool
+ Haskoin.Store.Data: [getBinfoUnspentConfirmations] :: BinfoUnspent -> !Word32
+ Haskoin.Store.Data: [getBinfoUnspentHash] :: BinfoUnspent -> !TxHash
+ Haskoin.Store.Data: [getBinfoUnspentOutputIndex] :: BinfoUnspent -> !Word32
+ Haskoin.Store.Data: [getBinfoUnspentScript] :: BinfoUnspent -> !ByteString
+ Haskoin.Store.Data: [getBinfoUnspentTxIndex] :: BinfoUnspent -> !BinfoTxId
+ Haskoin.Store.Data: [getBinfoUnspentValue] :: BinfoUnspent -> !Word64
+ Haskoin.Store.Data: [getBinfoUnspentXPub] :: BinfoUnspent -> !Maybe BinfoXPubPath
+ Haskoin.Store.Data: binfoUnspentParseJSON :: Network -> Value -> Parser BinfoUnspent
+ Haskoin.Store.Data: binfoUnspentToEncoding :: Network -> BinfoUnspent -> Encoding
+ Haskoin.Store.Data: binfoUnspentToJSON :: Network -> BinfoUnspent -> Value
+ Haskoin.Store.Data: binfoUnspentsParseJSON :: Network -> Value -> Parser BinfoUnspents
+ Haskoin.Store.Data: binfoUnspentsToEncoding :: Network -> BinfoUnspents -> Encoding
+ Haskoin.Store.Data: binfoUnspentsToJSON :: Network -> BinfoUnspents -> Value
+ Haskoin.Store.Data: data BinfoUnspent
+ Haskoin.Store.Data: getBinfoTxId :: Maybe (HashMap TxHash Transaction) -> TxHash -> BinfoTxId
+ Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoUnspent
+ Haskoin.Store.Data: instance Control.DeepSeq.NFData Haskoin.Store.Data.BinfoUnspents
+ Haskoin.Store.Data: instance Data.Serialize.Serialize Haskoin.Store.Data.BinfoUnspent
+ Haskoin.Store.Data: instance Data.Serialize.Serialize Haskoin.Store.Data.BinfoUnspents
+ Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoUnspent
+ Haskoin.Store.Data: instance GHC.Classes.Eq Haskoin.Store.Data.BinfoUnspents
+ Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoUnspent
+ Haskoin.Store.Data: instance GHC.Generics.Generic Haskoin.Store.Data.BinfoUnspents
+ Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoUnspent
+ Haskoin.Store.Data: instance GHC.Show.Show Haskoin.Store.Data.BinfoUnspents
+ Haskoin.Store.Data: newtype BinfoUnspents
- Haskoin.Store.Data: BinfoTx :: !TxHash -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word64 -> !ByteString -> !Word32 -> !BinfoTxId -> !Bool -> !Maybe (Int64, Int64) -> !Word64 -> !Maybe Word32 -> !Maybe Word32 -> [BinfoTxInput] -> [BinfoTxOutput] -> BinfoTx
+ Haskoin.Store.Data: BinfoTx :: !TxHash -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word32 -> !Word64 -> !ByteString -> !Word32 -> !BinfoTxId -> !Bool -> !Bool -> !Maybe (Int64, Int64) -> !Word64 -> !Maybe Word32 -> !Maybe Word32 -> [BinfoTxInput] -> [BinfoTxOutput] -> BinfoTx
Files
- haskoin-store-data.cabal +2/−2
- src/Haskoin/Store/Data.hs +105/−14
- test/Haskoin/Store/DataSpec.hs +21/−0
haskoin-store-data.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 27988a8740b2340e21ae4c0a14ef926f1904d73b09465e41bf6d4a11b9e3c1da+-- hash: 0a701e28ce4d2ba69e0a284d87a37982111d904ea08b16228a83c754194396bf name: haskoin-store-data-version: 0.41.3+version: 0.42.1 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
@@ -93,6 +93,7 @@ , binfoTxIndexBlock , binfoTransactionIndex , BinfoTxId(..)+ , getBinfoTxId , BinfoMultiAddr(..) , binfoMultiAddrToJSON , binfoMultiAddrToEncoding@@ -105,6 +106,14 @@ , BinfoAddr(..) , parseBinfoAddr , BinfoWallet(..)+ , BinfoUnspent(..)+ , binfoUnspentToJSON+ , binfoUnspentToEncoding+ , binfoUnspentParseJSON+ , BinfoUnspents(..)+ , binfoUnspentsToJSON+ , binfoUnspentsToEncoding+ , binfoUnspentsParseJSON , BinfoTx(..) , relevantTxs , toBinfoTx@@ -156,11 +165,11 @@ import Data.Either (fromRight, lefts, rights) import Data.Foldable (toList) import Data.Function (on)-import Data.Hashable (Hashable (..)) import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HashMap import Data.HashSet (HashSet) import qualified Data.HashSet as HashSet+import Data.Hashable (Hashable (..)) import Data.Int (Int64) import qualified Data.IntMap as IntMap import Data.IntMap.Strict (IntMap)@@ -194,6 +203,7 @@ txHashToHex, wrapPubKey, xPubFromJSON, xPubImport, xPubToEncoding, xPubToJSON)+import Text.Printf (printf) import Text.Read (readMaybe) import Web.Scotty.Trans (Parsable (..), ScottyError (..)) @@ -463,7 +473,7 @@ script <- BSS.toShort <$> (o .: "pkscript" >>= jsonHex) addr <- o .: "address" >>= \case Nothing -> return Nothing- Just a -> Just <$> addrFromJSON net a <|> return Nothing+ Just a -> Just <$> addrFromJSON net a <|> return Nothing return Unspent { unspentBlock = block@@ -698,7 +708,7 @@ value <- o .: "value" addr <- o .: "address" >>= \case Nothing -> return Nothing- Just a -> Just <$> addrFromJSON net a <|> return Nothing+ Just a -> Just <$> addrFromJSON net a <|> return Nothing return StoreInput { inputPoint = outpoint@@ -779,7 +789,7 @@ spender <- o .: "spender" addr <- o .: "address" >>= \case Nothing -> return Nothing- Just a -> Just <$> addrFromJSON net a <|> return Nothing+ Just a -> Just <$> addrFromJSON net a <|> return Nothing return StoreOutput { outputAmount = value@@ -1129,12 +1139,12 @@ , "indices" .= object ["change" .= ch, "external" .= ext] ] toEncoding XPubSummary { xPubSummaryConfirmed = c- , xPubSummaryZero = z- , xPubSummaryReceived = r- , xPubUnspentCount = u- , xPubExternalIndex = ext- , xPubChangeIndex = ch- } =+ , xPubSummaryZero = z+ , xPubSummaryReceived = r+ , xPubUnspentCount = u+ , xPubExternalIndex = ext+ , xPubChangeIndex = ch+ } = pairs ( "balance" `pair` pairs ( "confirmed" .= c@@ -1417,8 +1427,7 @@ toEncoding (EventTx h) = pairs ("type" `pair` text "tx" <> "id" `pair` text (txHashToHex h)) toEncoding (EventBlock h) =- pairs- ("type" `pair` text "block" <> "id" `pair` text (blockHashToHex h))+ pairs ("type" `pair` text "block" <> "id" `pair` text (blockHashToHex h)) instance FromJSON Event where parseJSON =@@ -1809,6 +1818,78 @@ getBinfoWalletTotalSent <- o .: "total_sent" return BinfoWallet {..} +data BinfoUnspent+ = BinfoUnspent+ { getBinfoUnspentHash :: !TxHash+ , getBinfoUnspentOutputIndex :: !Word32+ , getBinfoUnspentScript :: !ByteString+ , getBinfoUnspentValue :: !Word64+ , getBinfoUnspentConfirmations :: !Word32+ , getBinfoUnspentTxIndex :: !BinfoTxId+ , getBinfoUnspentXPub :: !(Maybe BinfoXPubPath)+ } deriving (Eq, Show, Generic, Serialize, NFData)++binfoUnspentToJSON :: Network -> BinfoUnspent -> Value+binfoUnspentToJSON net BinfoUnspent{..} =+ object $+ [ "tx_hash_big_endian" .= getBinfoUnspentHash+ , "tx_hash" .= encodeHex (S.encode (getTxHash getBinfoUnspentHash))+ , "tx_output_n" .= getBinfoUnspentOutputIndex+ , "script" .= encodeHex getBinfoUnspentScript+ , "value" .= getBinfoUnspentValue+ , "value_hex" .= (printf "%x" getBinfoUnspentValue :: String)+ , "confirmations" .= getBinfoUnspentConfirmations+ , "tx_index" .= getBinfoUnspentTxIndex+ ] <>+ [ "xpub" .= binfoXPubPathToJSON net x+ | x <- maybeToList getBinfoUnspentXPub+ ]++binfoUnspentToEncoding :: Network -> BinfoUnspent -> Encoding+binfoUnspentToEncoding net BinfoUnspent{..} =+ pairs $+ "tx_hash_big_endian" .= getBinfoUnspentHash <>+ "tx_hash" .= encodeHex (S.encode (getTxHash getBinfoUnspentHash)) <>+ "tx_output_n" .= getBinfoUnspentOutputIndex <>+ "script" .= encodeHex getBinfoUnspentScript <>+ "value" .= getBinfoUnspentValue <>+ "value_hex" .= (printf "%x" getBinfoUnspentValue :: String) <>+ "confirmations" .= getBinfoUnspentConfirmations <>+ "tx_index" .= getBinfoUnspentTxIndex <>+ maybe mempty (("xpub" `pair`) . binfoXPubPathToEncoding net) getBinfoUnspentXPub++binfoUnspentParseJSON :: Network -> Value -> Parser BinfoUnspent+binfoUnspentParseJSON net = withObject "unspent" $ \o -> do+ getBinfoUnspentHash <- o .: "tx_hash_big_endian"+ getBinfoUnspentOutputIndex <- o .: "tx_output_n"+ getBinfoUnspentScript <- maybe mzero return . decodeHex =<< o .: "script"+ getBinfoUnspentValue <- o .: "value"+ getBinfoUnspentConfirmations <- o .: "confirmations"+ getBinfoUnspentTxIndex <- o .: "tx_index"+ getBinfoUnspentXPub <- mapM (binfoXPubPathParseJSON net) =<< o .:? "xpub"+ return BinfoUnspent{..}++newtype BinfoUnspents = BinfoUnspents [BinfoUnspent]+ deriving (Eq, Show, Generic, Serialize, NFData)++binfoUnspentsToJSON :: Network -> BinfoUnspents -> Value+binfoUnspentsToJSON net (BinfoUnspents us) =+ object+ [ "notice" .= T.empty+ , "unspent_outputs" .= map (binfoUnspentToJSON net) us+ ]++binfoUnspentsToEncoding :: Network -> BinfoUnspents -> Encoding+binfoUnspentsToEncoding net (BinfoUnspents us) =+ pairs $+ "notice" .= T.empty <>+ "unspent_outputs" `pair` list (binfoUnspentToEncoding net) us++binfoUnspentsParseJSON :: Network -> Value -> Parser BinfoUnspents+binfoUnspentsParseJSON net = withObject "unspents" $ \o -> do+ us <- mapM (binfoUnspentParseJSON net) =<< o .: "unspent_outputs"+ return (BinfoUnspents us)+ data BinfoTx = BinfoTx { getBinfoTxHash :: !TxHash@@ -1822,6 +1903,7 @@ , getBinfoTxLockTime :: !Word32 , getBinfoTxIndex :: !BinfoTxId , getBinfoTxDoubleSpend :: !Bool+ , getBinfoTxRBF :: !Bool , getBinfoTxResultBal :: !(Maybe (Int64, Int64)) , getBinfoTxTime :: !Word64 , getBinfoTxBlockIndex :: !(Maybe Word32)@@ -1850,10 +1932,13 @@ , "block_height" .= getBinfoTxBlockHeight , "inputs" .= map (binfoTxInputToJSON net) getBinfoTxInputs , "out" .= map (binfoTxOutputToJSON net) getBinfoTxOutputs- ] +++ ] ++ bal ++ rbf+ where+ bal = case getBinfoTxResultBal of Nothing -> [] Just (res, bal) -> ["result" .= res, "balance" .= bal]+ rbf = if getBinfoTxRBF then ["rbf" .= True] else [] binfoTxToEncoding :: Network -> BinfoTx -> Encoding binfoTxToEncoding net BinfoTx {..} =@@ -1874,9 +1959,13 @@ "block_height" .= getBinfoTxBlockHeight <> "inputs" `pair` list (binfoTxInputToEncoding net) getBinfoTxInputs <> "out" `pair` list (binfoTxOutputToEncoding net) getBinfoTxOutputs <>+ bal <> rbf+ where+ bal = case getBinfoTxResultBal of Nothing -> mempty Just (res, bal) -> "result" .= res <> "balance" .= bal+ rbf = if getBinfoTxRBF then "rbf" .= True else mempty binfoTxParseJSON :: Network -> Value -> Parser BinfoTx binfoTxParseJSON net = withObject "tx" $ \o -> do@@ -1896,6 +1985,7 @@ getBinfoTxBlockHeight <- o .: "block_height" getBinfoTxInputs <- o .: "inputs" >>= mapM (binfoTxInputParseJSON net) getBinfoTxOutputs <- o .: "out" >>= mapM (binfoTxOutputParseJSON net)+ getBinfoTxRBF <- o .:? "rbf" .!= False res <- o .:? "result" bal <- o .:? "balance" let getBinfoTxResultBal = (,) <$> res <*> bal@@ -2342,7 +2432,8 @@ , getBinfoTxRelayedBy = "0.0.0.0" , getBinfoTxLockTime = transactionLockTime , getBinfoTxIndex = binfoTransactionIndex (isNothing etxs) t- , getBinfoTxDoubleSpend = transactionRBF+ , getBinfoTxDoubleSpend = transactionDeleted+ , getBinfoTxRBF = transactionRBF , getBinfoTxTime = transactionTime , getBinfoTxBlockIndex = toBinfoBlockIndex t , getBinfoTxBlockHeight = toBinfoBlockIndex t
test/Haskoin/Store/DataSpec.hs view
@@ -57,6 +57,8 @@ , SerialBox (arbitrary :: Gen BinfoTxInput) , SerialBox (arbitrary :: Gen BinfoTx) , SerialBox (arbitrary :: Gen BinfoTxId)+ , SerialBox (arbitrary :: Gen BinfoUnspent)+ , SerialBox (arbitrary :: Gen BinfoUnspents) ] jsonVals :: [JsonBox]@@ -140,6 +142,10 @@ , binfoXPubPathToEncoding , binfoXPubPathParseJSON , arbitraryNetData)+ , NetBox ( binfoUnspentToJSON+ , binfoUnspentToEncoding+ , binfoUnspentParseJSON+ , arbitraryNetData) ] spec :: Spec@@ -456,6 +462,7 @@ getBinfoTxLockTime <- arbitrary getBinfoTxIndex <- arbitrary getBinfoTxDoubleSpend <- arbitrary+ getBinfoTxRBF <- arbitrary getBinfoTxTime <- arbitrary getBinfoTxBlockIndex <- arbitrary getBinfoTxBlockHeight <- arbitrary@@ -532,3 +539,17 @@ binfoTickerLast <- arbitrary binfoTickerSymbol <- cs <$> listOf1 arbitraryUnicodeChar return BinfoTicker{..}++instance Arbitrary BinfoUnspent where+ arbitrary = do+ getBinfoUnspentHash <- arbitraryTxHash+ getBinfoUnspentOutputIndex <- arbitrary+ getBinfoUnspentScript <- B.pack <$> listOf arbitrary+ getBinfoUnspentValue <- arbitrary+ getBinfoUnspentConfirmations <- arbitrary+ getBinfoUnspentTxIndex <- arbitrary+ getBinfoUnspentXPub <- arbitrary+ return BinfoUnspent{..}++instance Arbitrary BinfoUnspents where+ arbitrary = BinfoUnspents <$> arbitrary