network-bitcoin 1.3.0 → 1.4.0
raw patch · 6 files changed
+122/−46 lines, 6 filesdep +QuickCheckdep +network-bitcoinnew-component:exe:network-bitcoin-testsPVP ok
version bump matches the API change (PVP)
Dependencies added: QuickCheck, network-bitcoin
API changes (from Hackage documentation)
- Network.Bitcoin.BlockChain: ScriptSig :: HexString -> HexString -> ScriptSig
- Network.Bitcoin.BlockChain: data ScriptSig
- Network.Bitcoin.BlockChain: sigAsm :: ScriptSig -> HexString
- Network.Bitcoin.BlockChain: sigHex :: ScriptSig -> HexString
- Network.Bitcoin.Types: ScriptSig :: HexString -> HexString -> ScriptSig
- Network.Bitcoin.Types: data ScriptSig
- Network.Bitcoin.Types: instance Eq ScriptSig
- Network.Bitcoin.Types: instance FromJSON ScriptSig
- Network.Bitcoin.Types: instance Ord ScriptSig
- Network.Bitcoin.Types: instance Read ScriptSig
- Network.Bitcoin.Types: instance Show ScriptSig
- Network.Bitcoin.Types: sigAsm :: ScriptSig -> HexString
- Network.Bitcoin.Types: sigHex :: ScriptSig -> HexString
+ Network.Bitcoin: unspentAddress :: UnspentTransaction -> Address
+ Network.Bitcoin.Internal: BitcoinRpcResponse :: a -> BitcoinRpcError -> BitcoinRpcResponse a
+ Network.Bitcoin.Internal: btcError :: BitcoinRpcResponse a -> BitcoinRpcError
+ Network.Bitcoin.Internal: btcResult :: BitcoinRpcResponse a -> a
+ Network.Bitcoin.Internal: data BitcoinRpcResponse a
+ Network.Bitcoin.RawTransaction: instance Eq ScriptSig
+ Network.Bitcoin.RawTransaction: instance Eq UnspentTransaction
+ Network.Bitcoin.RawTransaction: instance FromJSON ScriptSig
+ Network.Bitcoin.RawTransaction: instance Ord ScriptSig
+ Network.Bitcoin.RawTransaction: instance Read ScriptSig
+ Network.Bitcoin.RawTransaction: instance Show ScriptSig
+ Network.Bitcoin.RawTransaction: instance Show UnspentTransaction
+ Network.Bitcoin.RawTransaction: unspentAddress :: UnspentTransaction -> Address
- Network.Bitcoin: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptSig -> Integer -> Bool -> OutputInfo
+ Network.Bitcoin: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptPubKey -> Integer -> Bool -> OutputInfo
- Network.Bitcoin: UnspentTransaction :: TransactionID -> Integer -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
+ Network.Bitcoin: UnspentTransaction :: TransactionID -> Integer -> Address -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
- Network.Bitcoin: oiScriptPubKey :: OutputInfo -> ScriptSig
+ Network.Bitcoin: oiScriptPubKey :: OutputInfo -> ScriptPubKey
- Network.Bitcoin.BlockChain: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptSig -> Integer -> Bool -> OutputInfo
+ Network.Bitcoin.BlockChain: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptPubKey -> Integer -> Bool -> OutputInfo
- Network.Bitcoin.BlockChain: oiScriptPubKey :: OutputInfo -> ScriptSig
+ Network.Bitcoin.BlockChain: oiScriptPubKey :: OutputInfo -> ScriptPubKey
- Network.Bitcoin.RawTransaction: UnspentTransaction :: TransactionID -> Integer -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
+ Network.Bitcoin.RawTransaction: UnspentTransaction :: TransactionID -> Integer -> Address -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
Files
- network-bitcoin.cabal +22/−4
- src/Network/Bitcoin/BlockChain.hs +3/−3
- src/Network/Bitcoin/Internal.hs +7/−6
- src/Network/Bitcoin/RawTransaction.hs +38/−17
- src/Network/Bitcoin/Types.hs +1/−16
- src/Test/Main.hs +51/−0
network-bitcoin.cabal view
@@ -1,5 +1,5 @@ Name: network-bitcoin-Version: 1.3.0+Version: 1.4.0 Synopsis: An interface to bitcoind. Description: This can be used to send Bitcoins, query balances, etc. It@@ -24,7 +24,7 @@ Homepage: http://github.com/wowus/network-bitcoin Bug-reports: http://github.com/wowus/network-bitcoin/issues Copyright: 2012 Michael Hendricks <michael@ndrix.org>- 2012 Clark Gaebel <cgaebel@uwaterloo.ca>+ 2013 Clark Gaebel <cgaebel@uwaterloo.ca> Stability: experimental Homepage: http://github.com/mndrix/network-bitcoin Bug-reports: http://github.com/wowus/network-bitcoin/issues@@ -60,5 +60,23 @@ base == 4.* Source-repository head- type: git- location: git://github.com/wowus/network-bitcoin.git+ type: git+ location: git://github.com/wowus/network-bitcoin.git++Executable network-bitcoin-tests+ hs-source-dirs: src+ ghc-options: -Wall+ main-is: Test/Main.hs+ build-depends:+ aeson >= 0.6.1 && < 0.7,+ bytestring >= 0.9 && < 0.11,+ attoparsec == 0.10.*,+ unordered-containers >= 0.2,+ HTTP >= 4000,+ network >= 2.3,+ text >= 0.11,+ vector >= 0.10,+ base == 4.*,+ QuickCheck == 2.5.*,+ network-bitcoin+
src/Network/Bitcoin/BlockChain.hs view
@@ -9,7 +9,6 @@ module Network.Bitcoin.BlockChain ( Auth(..) , TransactionID , BTC- , ScriptSig(..) , getBlockCount , getDifficulty , setTransactionFee@@ -28,6 +27,7 @@ import Control.Monad import Data.Aeson import Network.Bitcoin.Internal+import Network.Bitcoin.RawTransaction -- | Returns the number of blocks in the longest block chain. getBlockCount :: Auth -> IO Integer@@ -139,7 +139,7 @@ -- | The amount transferred. , oiAmount :: BTC -- | The public key of the sender.- , oiScriptPubKey :: ScriptSig+ , oiScriptPubKey :: ScriptPubKey -- | The version of this transaction. , oiVersion :: Integer -- | Is this transaction part of the coin base?@@ -150,7 +150,7 @@ instance FromJSON OutputInfo where parseJSON (Object o) = OutputInfo <$> o .: "bestblock" <*> o .: "confirmations"- <*> o .: "amount"+ <*> o .: "value" <*> o .: "scriptPubKey" <*> o .: "version" <*> o .: "coinbase"
src/Network/Bitcoin/Internal.hs view
@@ -19,6 +19,7 @@ , Nil(..) , tj , AddrAddress(..)+ , BitcoinRpcResponse(..) ) where import Control.Applicative@@ -96,12 +97,12 @@ callApi auth cmd params = readVal =<< callApi' auth jsonRpcReqBody where readVal bs = case decode' bs of- Just r@(BitcoinRpcResponse {btcError=NoError})- -> return $ btcResult r- Just (BitcoinRpcResponse {btcError=BitcoinRpcError code msg})- -> throw $ BitcoinApiError code msg- Nothing- -> throw $ BitcoinResultTypeError bs+ Just r@(BitcoinRpcResponse {btcError=NoError})+ -> return $ btcResult r+ Just (BitcoinRpcResponse {btcError=BitcoinRpcError code msg})+ -> throw $ BitcoinApiError code msg+ Nothing+ -> throw $ BitcoinResultTypeError bs jsonRpcReqBody = encode $ object [ "jsonrpc" .= ("2.0" :: Text) , "method" .= cmd
src/Network/Bitcoin/RawTransaction.hs view
@@ -11,12 +11,12 @@ -- Also, documentation for this module is scarce. I would love the addition -- of more documentation by anyone who knows what these things are. module Network.Bitcoin.RawTransaction ( Auth(..)- , ScriptSig(..) , RawTransaction , getRawTransaction , TxIn(..) , TxnOutputType(..) , ScriptPubKey(..)+ , ScriptSig(..) , TxOut(..) , BlockInfo(..) , RawTransactionInfo(..)@@ -93,6 +93,27 @@ | otherwise = mzero parseJSON _ = mzero ++-- | A transaction out of an account.+data TxOut =+ TxOut { -- | The amount of bitcoin transferred out.+ txoutVal :: BTC+ -- | The public key of the account we sent the money to.+ , scriptPubKey :: ScriptPubKey+ }+ deriving ( Show, Read, Ord, Eq )++instance FromJSON TxOut where+ parseJSON (Object o) = TxOut <$> o .: "value"+ <*> o .: "scriptPubKey"+ parseJSON _ = mzero++-- * Scripts+-- A script is a complex bitcoin construct that provides the creation+-- of Contracts.+-- See <https://en.bitcoin.it/wiki/Script> and <https://en.bitcoin.it/wiki/Contracts>.+-- It consists of two parts - a public key and a signature.+ -- | A public key of someone we sent money to. data ScriptPubKey = NonStandardScriptPubKey { -- | The JSON "asm" field. nspkAsm :: HexString@@ -124,20 +145,18 @@ <*> o .: "hex" parseJSON _ = mzero --- | A transaction out of an account.-data TxOut =- TxOut { -- | The amount of bitcoin transferred out.- txoutVal :: BTC- -- | The public key of the account we sent the money to.- , scriptPubKey :: ScriptPubKey- }+-- | A script signature.+data ScriptSig = ScriptSig { sigAsm :: HexString+ , sigHex :: HexString+ } deriving ( Show, Read, Ord, Eq ) -instance FromJSON TxOut where- parseJSON (Object o) = TxOut <$> o .: "value"- <*> o .: "scriptPubKey"+instance FromJSON ScriptSig where+ parseJSON (Object o) = ScriptSig <$> o .: "asm"+ <*> o .: "hex" parseJSON _ = mzero + -- | Information on a single block. data BlockInfo = ConfirmedBlock { -- | The number of confirmations a block has. -- This will always be >= 1.@@ -201,16 +220,18 @@ data UnspentTransaction = UnspentTransaction { unspentTransactionId :: TransactionID- , outIdx :: Integer- , unspentScriptPubKey :: HexString- , redeemScript :: Maybe HexString- , unspentAmount :: BTC- , usConfirmations :: Integer- }+ , outIdx :: Integer+ , unspentAddress :: Address+ , unspentScriptPubKey :: HexString+ , redeemScript :: Maybe HexString+ , unspentAmount :: BTC+ , usConfirmations :: Integer+ } deriving ( Show, Eq ) instance FromJSON UnspentTransaction where parseJSON (Object o) = UnspentTransaction <$> o .: "txid" <*> o .: "vout"+ <*> o .: "address" <*> o .: "scriptPubKey" <*> o .:? "redeemScript" <*> o .: "amount"
src/Network/Bitcoin/Types.hs view
@@ -10,13 +10,9 @@ , BTC , Account , Address- , ScriptSig(..) ) where -import Control.Applicative import Control.Exception-import Control.Monad-import Data.Aeson import Data.Fixed import Data.Text ( Text ) import Data.Typeable@@ -76,19 +72,8 @@ -- | An address for sending or receiving money. type Address = HexString --- | I don't know what this is. A signature of some sort? If you know, please--- submit a patch documenting this properly!-data ScriptSig = ScriptSig { sigAsm :: HexString- , sigHex :: HexString- }- deriving ( Show, Read, Ord, Eq )--instance FromJSON ScriptSig where- parseJSON (Object o) = ScriptSig <$> o .: "asm"- <*> o .: "hex"- parseJSON _ = mzero- -- | An account on the wallet is just a label to easily specify private keys. -- -- The default account is an empty string. type Account = Text+
+ src/Test/Main.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where+++import Test.QuickCheck+import Test.QuickCheck.Monadic+import Network.Bitcoin+import Data.Aeson+import Data.Vector ( empty, mapM )+++main :: IO ()+main = mapM_ qcOnce [ canGetInfo+ , canListUnspent+ , canGetOutputInfo+ ]+++qcOnce :: Property -> IO ()+qcOnce = quickCheckWith stdArgs { maxSuccess = 1+ , maxSize = 1+ , maxDiscardRatio = 1+ }+++auth :: Auth+auth = Auth "http://localhost:18332" "bitcoinrpc" "bitcoinrpcpassword"+++canGetInfo :: Property+canGetInfo = monadicIO $ do+ info <- run $ getBitcoindInfo auth+ let checks = [ bitcoinVersion info > 80000+ , onTestNetwork info+ , bitcoindErrors info == ""+ ]+ assert $ and checks+++canListUnspent :: Property+canListUnspent = monadicIO $ do+ _ <- run $ listUnspent auth Nothing Nothing Data.Vector.empty+ assert True+++canGetOutputInfo :: Property+canGetOutputInfo = monadicIO $ do+ info <- run $ getOutputInfo auth "ab8e26fd95fa371ac15b43684d0c6797fb573757095e7d763ba86ad315f7db04" 1+ _ <- run $ print info+ assert True