haskoin-store-data 0.28.0 → 0.29.0
raw patch · 3 files changed
+22/−19 lines, 3 files
Files
- haskoin-store-data.cabal +2/−2
- src/Haskoin/Store/Data.hs +15/−12
- test/Haskoin/Store/DataSpec.hs +5/−5
haskoin-store-data.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 4fafcd00b7d58feb5972201ca34b9c0654726c69f57b999b6eb365927f8941dd+-- hash: ab67524bd0ec3464f66049a79f72633fac85730c7b5d781b5cdd50a5602528b4 name: haskoin-store-data-version: 0.28.0+version: 0.29.0 synopsis: Data for Haskoin Store description: Data and its (de)serialisation functions for Haskoin Store category: Bitcoin, Finance, Network
src/Haskoin/Store/Data.hs view
@@ -20,7 +20,7 @@ , confirmed -- * Transactions- , BlockTx(..)+ , TxRef(..) , TxData(..) , Transaction(..) , transactionToJSON@@ -102,8 +102,8 @@ import Data.Word (Word32, Word64) import GHC.Generics (Generic) import Haskoin (Address, BlockHash, BlockHeader (..),- BlockHeight, BlockWork, KeyIndex,- Network (..), OutPoint (..),+ BlockHeight, BlockWork, Coin (..),+ KeyIndex, Network (..), OutPoint (..), PubKeyI (..), Tx (..), TxHash (..), TxIn (..), TxOut (..), WitnessStack, XPubKey (..), addrFromJSON,@@ -222,27 +222,27 @@ return MemRef {memRefTime = mempool} -- | Transaction in relation to an address.-data BlockTx = BlockTx- { blockTxBlock :: !BlockRef+data TxRef = TxRef+ { txRefBlock :: !BlockRef -- ^ block information- , blockTxHash :: !TxHash+ , txRefHash :: !TxHash -- ^ transaction hash } deriving (Show, Eq, Ord, Generic, Serialize, Hashable, NFData) -instance ToJSON BlockTx where- toJSON btx = object ["txid" .= blockTxHash btx, "block" .= blockTxBlock btx]+instance ToJSON TxRef where+ toJSON btx = object ["txid" .= txRefHash btx, "block" .= txRefBlock btx] toEncoding btx = pairs- ( "txid" .= blockTxHash btx- <> "block" .= blockTxBlock btx+ ( "txid" .= txRefHash btx+ <> "block" .= txRefBlock btx ) -instance FromJSON BlockTx where+instance FromJSON TxRef where parseJSON = A.withObject "blocktx" $ \o -> do txid <- o .: "txid" block <- o .: "block"- return BlockTx {blockTxBlock = block, blockTxHash = txid}+ return TxRef {txRefBlock = block, txRefHash = txid} -- | Address balance information. data Balance =@@ -331,6 +331,9 @@ , unspentScript :: !ShortByteString , unspentAddress :: !(Maybe Address) } deriving (Show, Eq, Ord, Generic, Hashable, Serialize, NFData)++instance Coin Unspent where+ coinValue = unspentAmount unspentToJSON :: Network -> Unspent -> Value unspentToJSON net u =
test/Haskoin/Store/DataSpec.hs view
@@ -24,7 +24,7 @@ bchRegTest, bchTest, btc, btcRegTest, btcTest, ripemd160, sha256) import Haskoin.Store.Data (Balance (..), BlockData (..),- BlockRef (..), BlockTx (..),+ BlockRef (..), TxRef (..), DeriveType (..), Event (..), HealthCheck (..), PeerInformation (..), Prev (..),@@ -55,7 +55,7 @@ prop "identity for derivation type" $ \x -> testSerial (x :: DeriveType) prop "identity for xpub spec" $ \x -> testSerial (x :: XPubSpec) prop "identity for block ref" $ \x -> testSerial (x :: BlockRef)- prop "identity for block tx" $ \x -> testSerial (x :: BlockTx)+ prop "identity for block tx" $ \x -> testSerial (x :: TxRef) prop "identity for balance" $ \x -> testSerial (x :: Balance) prop "identity for unspent" $ \x -> testSerial (x :: Unspent) prop "identity for block data" $ \x -> testSerial (x :: BlockData)@@ -79,7 +79,7 @@ (balanceToJSON net) (balanceToEncoding net) x- prop "identity for block tx" $ \x -> testJSON (x :: BlockTx)+ prop "identity for block tx" $ \x -> testJSON (x :: TxRef) prop "identity for block ref" $ \x -> testJSON (x :: BlockRef) prop "identity for unspent" . forAll arbitraryNetData $ \(net, x) -> testNetJSON@@ -312,8 +312,8 @@ instance Arbitrary TxId where arbitrary = TxId <$> arbitrary -instance Arbitrary BlockTx where- arbitrary = BlockTx <$> arbitrary <*> arbitrary+instance Arbitrary TxRef where+ arbitrary = TxRef <$> arbitrary <*> arbitrary instance Arbitrary Hash160 where arbitrary = ripemd160 . pack <$> listOf1 arbitrary