packages feed

network-bitcoin 1.8.1 → 1.8.3

raw patch · 11 files changed

+277/−229 lines, 11 filesdep +network-uridep ~attoparsecnew-uploader

Dependencies added: network-uri

Dependency ranges changed: attoparsec

Files

network-bitcoin.cabal view
@@ -1,5 +1,5 @@ Name:                network-bitcoin-Version:             1.8.1+Version:             1.8.3 Synopsis:            An interface to bitcoind. Description:     This can be used to send Bitcoins, query balances, etc.  It@@ -20,14 +20,11 @@ Author:              Michael Hendricks <michael@ndrix.org>                      Clark Gaebel <cgaebel@uwaterloo.ca> Maintainer:          Clark Gaebel <cgaebel@uwaterloo.ca>-Stability:           experimental-Homepage:            http://github.com/wowus/network-bitcoin-Bug-reports:         http://github.com/wowus/network-bitcoin/issues+Homepage:            http://github.com/cgaebel/network-bitcoin+Bug-reports:         http://github.com/cgaebel/network-bitcoin/issues Copyright:           2012 Michael Hendricks <michael@ndrix.org>                      2013 Clark Gaebel <cgaebel@uwaterloo.ca> Stability:           experimental-Homepage:            http://github.com/mndrix/network-bitcoin-Bug-reports:         http://github.com/wowus/network-bitcoin/issues Category:            Network Build-type:          Simple Cabal-version:       >=1.8@@ -52,7 +49,7 @@     aeson >= 0.8,     bytestring >= 0.9 && < 0.11,     cookie >= 0.4,-    attoparsec == 0.12.*,+    attoparsec >= 0.12,     unordered-containers >= 0.2,     HTTP >= 4000,     http-types >= 0.8.5,@@ -61,21 +58,23 @@     vector >= 0.10,     base == 4.*,     time >= 1.4.2,-    http-client >= 0.4.6+    http-client >= 0.4.6,+    network-uri  Source-repository head   type: git   location: git://github.com/wowus/network-bitcoin.git -Executable network-bitcoin-tests+Test-suite network-bitcoin-tests   hs-source-dirs: src   ghc-options: -Wall   main-is: Test/Main.hs+  type: exitcode-stdio-1.0   build-depends:     aeson >= 0.8,     bytestring >= 0.9 && < 0.11,     cookie >= 0.4,-    attoparsec == 0.12.*,+    attoparsec >= 0.12,     unordered-containers >= 0.2,     HTTP >= 4000,     http-types >= 0.8.5,
src/Network/Bitcoin.hs view
@@ -100,6 +100,7 @@     , listTransactions     , listTransactions'     , listAccounts+    , importAddress     , SinceBlock(..)     , SimpleTransaction(..)     , TransactionCategory(..)@@ -117,10 +118,10 @@     , isAddressValid     ) where -import Network.Bitcoin.Types-import Network.Bitcoin.BlockChain-import Network.Bitcoin.Dump-import Network.Bitcoin.Mining-import Network.Bitcoin.Net-import Network.Bitcoin.RawTransaction-import Network.Bitcoin.Wallet+import           Network.Bitcoin.BlockChain+import           Network.Bitcoin.Dump+import           Network.Bitcoin.Mining+import           Network.Bitcoin.Net+import           Network.Bitcoin.RawTransaction+import           Network.Bitcoin.Types+import           Network.Bitcoin.Wallet
src/Network/Bitcoin/BlockChain.hs view
@@ -23,11 +23,10 @@                                   , getOutputInfo                                   ) where -import Control.Applicative-import Control.Monad-import Data.Aeson-import Network.Bitcoin.Internal-import Network.Bitcoin.RawTransaction+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 :: Client -> IO Integer@@ -60,31 +59,31 @@ getBlockHash client idx = callApi client "getblockhash" [ tj idx ]  -- | Information about a given block in the block chain.-data Block = Block { blockHash :: BlockHash+data Block = Block { blockHash        :: BlockHash                    -- | The number of confirmations the block has.                    , blkConfirmations :: Integer                    -- | The size of the block.-                   , blkSize :: Integer+                   , blkSize          :: Integer                    -- | The "height" of the block. TODO: Clarify this.-                   , blkHeight :: Integer+                   , blkHeight        :: Integer                    -- | The version of the block.-                   , blkVersion :: Integer+                   , blkVersion       :: Integer                    -- | The hash of the block at the root of the merkle tree                    --   which this block belongs to.-                   , merkleRoot :: BlockHash+                   , merkleRoot       :: BlockHash                    -- | Should this be a transaction, or transaction id?-                   , subTransactions :: Vector TransactionID+                   , subTransactions  :: Vector TransactionID                    -- | The time it was mined.-                   , blkTime :: Integer+                   , blkTime          :: Integer                    -- | The block's nonce.-                   , blkNonce :: Integer-                   , blkBits :: HexString+                   , blkNonce         :: Integer+                   , blkBits          :: HexString                    -- | How hard was this block to mine?-                   , blkDifficulty :: Integer+                   , blkDifficulty    :: Integer                    -- | A pointer to the next block in the chain.-                   , nextBlock :: Maybe BlockHash+                   , nextBlock        :: Maybe BlockHash                    -- | A pointer to the previous block in the chain.-                   , prevBlock :: Maybe BlockHash+                   , prevBlock        :: Maybe BlockHash                    }     deriving ( Show, Read, Ord, Eq ) @@ -110,13 +109,13 @@  -- | Information on the unspent transaction in the output set. data OutputSetInfo =-    OutputSetInfo { osiBestBlock :: BlockHash+    OutputSetInfo { osiBestBlock       :: BlockHash                   -- | The number of transactions in the output set.-                  , numTransactions :: Integer+                  , numTransactions    :: Integer                   -- | The number of outputs for the transactions.                   , transactionOutputs :: Integer                   -- | The serialized size of the output set.-                  , serializedSize :: Integer+                  , serializedSize     :: Integer                   }     deriving ( Show, Read, Ord, Eq ) @@ -133,17 +132,17 @@  -- | Details about an unspent transaction output. data OutputInfo =-    OutputInfo { oiBestBlock :: BlockHash+    OutputInfo { oiBestBlock     :: BlockHash                -- | The number of times this transaction has been confirmed.                , oiConfirmations :: Integer                -- | The amount transferred.-               , oiAmount :: BTC+               , oiAmount        :: BTC                -- | The public key of the sender.-               , oiScriptPubKey :: ScriptPubKey+               , oiScriptPubKey  :: ScriptPubKey                -- | The version of this transaction.-               , oiVersion :: Integer+               , oiVersion       :: Integer                -- | Is this transaction part of the coin base?-               , oiCoinBase :: Bool+               , oiCoinBase      :: Bool                }     deriving ( Show, Read, Ord, Eq ) 
src/Network/Bitcoin/Dump.hs view
@@ -10,8 +10,7 @@                             , dumpPrivateKey                             ) where -import Control.Applicative-import Network.Bitcoin.Internal+import           Network.Bitcoin.Internal  -- | A textual representation of a bitcoin private key. type PrivateKey = Text
src/Network/Bitcoin/Internal.hs view
@@ -25,16 +25,15 @@                                 , BitcoinRpcResponse(..)                                 ) where -import           Control.Applicative import           Control.Exception import           Control.Monad import           Data.Aeson+import qualified Data.ByteString           as BS import           Data.Maybe-import           Data.Vector ( Vector )-import qualified Data.Vector          as V+import           Data.Text                 (Text)+import           Data.Vector               (Vector)+import qualified Data.Vector               as V import           Network.Bitcoin.Types-import qualified Data.ByteString      as BS-import           Data.Text ( Text ) import           Network.HTTP.Client import           Network.HTTP.Types.Header @@ -53,8 +52,8 @@  -- | A response from bitcoind will contain the result of the JSON-RPC call, and --   an error. The error should be null if a valid response was received.-data BitcoinRpcResponse a = BitcoinRpcResponse { btcResult  :: a-                                               , btcError   :: BitcoinRpcError+data BitcoinRpcResponse a = BitcoinRpcResponse { btcResult :: a+                                               , btcError  :: BitcoinRpcError                                                }     deriving ( Show, Read, Ord, Eq ) 
src/Network/Bitcoin/Mining.hs view
@@ -16,6 +16,8 @@                               , getClient                               , getGenerate                               , setGenerate+                              , generate+                              , generateToAddress                               , getHashesPerSec                               , MiningInfo(..)                               , getMiningInfo@@ -29,10 +31,9 @@                               , submitBlock                               ) where -import Data.Aeson as A-import Control.Applicative-import Control.Monad-import Network.Bitcoin.Internal+import           Control.Monad+import           Data.Aeson               as A+import           Network.Bitcoin.Internal  -- | Returns whether or not bitcoind is generating bitcoins. getGenerate :: Client -- ^ bitcoind RPC client@@ -56,6 +57,41 @@ setGenerate client onOff (Just limit) =     unArr <$> callApi client "setgenerate" [ tj onOff, tj limit ] +-- | The generate RPC nearly instantly generates blocks.+--   See https://bitcoin.org/en/developer-reference#generate for more details.+generate :: Client+         -> Int -- ^ The number of blocks to generate.+                --   The RPC call will not return until all+                --   blocks have been generated or the maxium+                --   number of iterations has been reached+         -> Maybe Int -- ^ The maximum number of iterations that+                      --   are tried to create the requested number+                      --   of blocks. Default is 1000000+         -> IO [HexString] -- ^ An array containing the block header+                           --   hashes of the generated blocks+                           --   (may be empty if used with generate 0)+generate client blocks Nothing =+    callApi client "generate" [ tj blocks ]+generate client blocks (Just maxTries) =+    callApi client "generate" [ tj blocks, tj maxTries]++-- | The generatetoaddress RPC mines blocks immediately to a specified address.+--   See https://bitcoin.org/en/developer-reference#generatetoaddress for more details.+generateToAddress :: Client+                  -> Int -- ^ The number of blocks to generate.+                         --   The RPC call will not return until all+                         --   blocks have been generated or the maxium+                         --   number of iterations has been reached+                  -> Address -- ^ The address to send the newly generated Bitcoin to+                  -> Maybe Int -- ^ The maximum number of iterations that+                               --   are tried to create the requested number+                               --   of blocks. Default is 1000000+                  -> IO [HexString]+generateToAddress client blocks address Nothing =+    callApi client "generatetoaddress" [ tj blocks, tj address ]+generateToAddress client blocks address (Just maxTries) =+    callApi client "generatetoaddress" [ tj blocks, tj address, tj maxTries ]+ -- | Returns a recent hashes per second performance measurement while --   generating. getHashesPerSec :: Client -> IO Integer@@ -69,24 +105,24 @@ data MiningInfo =     MiningInfo {                -- | The number of blocks in our block-chain.-                 nBlocks :: Integer+                 nBlocks                  :: Integer                -- | The size of the current block we're mining.-               , currentBlockSize :: Integer-               , currentBlockTransaction :: Integer+               , currentBlockSize         :: Integer+               , currentBlockTransaction  :: Integer                -- | How difficult mining currently is.-               , difficulty :: Double+               , difficulty               :: Double                -- | Any mining errors that may have come up.-               , miningErrors :: Text+               , miningErrors             :: Text                -- | Are we currently generating bitcoins?-               , isGenerating :: Bool+               , isGenerating             :: Bool                -- | How many processors have we limited bitcoin mining to?                , generationProcessorLimit :: Integer                -- | How fast is the mining going?-               , hashesPerSecond :: Integer-               , pooledTransactions :: Integer+               , hashesPerSecond          :: Integer+               , pooledTransactions       :: Integer                -- | Are we on the bitcoin test network (as opposed to the real                --   thing)?-               , miningOnTestNetwork :: Bool+               , miningOnTestNetwork      :: Bool                }     deriving ( Show, Read, Ord, Eq ) @@ -111,9 +147,9 @@ data HashData =     HashData { blockData :: HexString              -- | Little-endian hash target, formatted as a hexadecimal string.-             , hdTarget :: HexString-             , hash1 :: HexString-             , midstate :: HexString+             , hdTarget  :: HexString+             , hash1     :: HexString+             , midstate  :: HexString              }     deriving ( Show, Read, Ord, Eq ) @@ -159,39 +195,39 @@  instance FromJSON CoinBaseAux where     parseJSON (Object o) = CoinBaseAux <$> o .: "flags"-    parseJSON _ = mzero+    parseJSON _          = mzero  -- | A template for constructing a block to work on. -- --   See <https://en.bitcoin.it/wiki/BIP_0022> for the full specification. data BlockTemplate =-    BlockTemplate { blockVersion :: Integer+    BlockTemplate { blockVersion          :: Integer                   -- | Hash of current highest block.-                  , previousBlockHash :: HexString+                  , previousBlockHash     :: HexString                   -- | Contents of non-coinbase transactions that should be                   --   included in the next block.                   , transactionsToInclude :: Vector Transaction                   -- | Data that should be included in coinbase.-                  , coinBaseAux :: CoinBaseAux+                  , coinBaseAux           :: CoinBaseAux                   -- | Maximum allowable input to coinbase transaction,                   --   including the generation award and transaction fees.-                  , coinBaseValue :: Integer+                  , coinBaseValue         :: Integer                   -- | Hash target.-                  , btTarget :: HexString+                  , btTarget              :: HexString                   -- | Minimum timestamp appropriate for next block.-                  , minTime :: Integer+                  , minTime               :: Integer                   -- | Range of valid nonces.-                  , nonceRange :: HexString+                  , nonceRange            :: HexString                   -- | Limit of sigops in blocks.-                  , sigopLimit :: Integer+                  , sigopLimit            :: Integer                   -- | Limit of block size.-                  , sizeLimit :: Integer+                  , sizeLimit             :: Integer                   -- | Current timestamp.-                  , curTime :: Integer+                  , curTime               :: Integer                   -- | Compressed target of the next block.-                  , btBits :: HexString+                  , btBits                :: HexString                   -- | Height of the next block.-                  , btHeight :: Integer+                  , btHeight              :: Integer                   }     deriving ( Show, Read, Ord, Eq ) @@ -223,7 +259,7 @@  instance FromJSON StupidReturnValue where     parseJSON Null = return $ SRV True-    parseJSON _ = return $ SRV False+    parseJSON _    = return $ SRV False  -- | Attempts to submit a new block to the network. submitBlock :: Client
src/Network/Bitcoin/Net.hs view
@@ -13,10 +13,9 @@                            , getPeerInfo                            ) where -import Control.Applicative-import Control.Monad-import Data.Aeson-import Network.Bitcoin.Internal+import           Control.Monad+import           Data.Aeson+import           Network.Bitcoin.Internal  -- | Returns the number of connections to other nodes. getConnectionCount :: Client -> IO Integer@@ -28,28 +27,28 @@ --   don't know what some of these fields are for. Patches are welcome! data PeerInfo =     PeerInfo { -- | The IP:port of this peer, as a string.-               addressName :: Text-             , services :: Text+               addressName    :: Text+             , services       :: Text              -- | Relative to the first time we conected with this peer (and in              -- milliseconds), the last time we sent this peer any data.-             , lastSend :: Integer+             , lastSend       :: Integer              -- | Relative to the first time we connected with this peer              --   (and in milliseconds), the last time we sent this peer any              --   data.-             , lastRecv :: Integer-             , bytesSent :: Integer-             , bytesRecv :: Integer+             , lastRecv       :: Integer+             , bytesSent      :: Integer+             , bytesRecv      :: Integer               -- | How long have we been connected to this peer (in               --   milliseconds).              , connectionTime :: Integer              -- | The version of the Bitcion client the peer is running.-             , peerVersion :: Integer+             , peerVersion    :: Integer              -- | The sub-version of the Bitcoin client the peer is running.              , peerSubversion :: Text-             , inbound :: Bool+             , inbound        :: Bool              , startingHeight :: Integer              -- | How many times has this peer behaved badly?-             , banScore :: Integer+             , banScore       :: Integer              }     deriving ( Show, Read, Ord, Eq ) 
src/Network/Bitcoin/RawTransaction.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE RecordWildCards   #-} {-# OPTIONS_GHC -Wall #-} -- | An interface to bitcoind's available raw transaction-related RPC calls. --   The implementation of these functions can be found at@@ -58,9 +58,9 @@ data TxIn = TxCoinbase { txCoinbase :: HexString                        }           | TxIn { -- | This transaction's ID.-                   txInId :: TransactionID-                 , numOut :: Integer-                 , scriptSig :: ScriptSig+                   txInId     :: TransactionID+                 , numOut     :: Integer+                 , scriptSig  :: ScriptSig                  -- | A transaction sequence number.                  , txSequence :: Integer                  }@@ -98,7 +98,7 @@ -- | A transaction out of an account. data TxOut =     TxOut { -- | The amount of bitcoin transferred out.-            txoutVal :: BTC+            txoutVal     :: BTC           -- | The public key of the account we sent the money to.           , scriptPubKey :: ScriptPubKey           }@@ -122,13 +122,13 @@                                             , nspkHex :: HexString                                             }                   | StandardScriptPubKey { -- | The JSON "asm" field.-                                           sspkAsm :: HexString+                                           sspkAsm       :: HexString                                          -- | The JSON "hex" field.-                                         , sspkHex :: HexString+                                         , sspkHex       :: HexString                                          -- | The number of required signatures.-                                         , requiredSigs :: Integer+                                         , requiredSigs  :: Integer                                          -- | The type of the transaction.-                                         , sspkType :: TxnOutputType+                                         , sspkType      :: TxnOutputType                                          -- | The addresses associated with this key.                                          , sspkAddresses :: Vector Address                                          }@@ -163,9 +163,9 @@                                   --   This will always be >= 1.                                   confirmations :: Integer                                 --   The JSON "time" field".-                                , cbTime :: Integer+                                , cbTime        :: Integer                                 -- | The JSON "blocktime" field.-                                , blockTime :: Integer+                                , blockTime     :: Integer                                 }                | UnconfirmedBlock                -- ^ An unconfirmed block is boring, but a possibility.@@ -185,19 +185,19 @@ -- | The raw transaction info for a given transaction ID. data RawTransactionInfo =     RawTransactionInfo { -- | The raw transaction.-                         raw :: RawTransaction+                         raw            :: RawTransaction                        -- | The transaction version number.-                       , txnVersion :: Integer-                       , txnLockTime :: Integer+                       , txnVersion     :: Integer+                       , txnLockTime    :: Integer                        -- | The vector of transactions in.-                       , vin :: Vector TxIn+                       , vin            :: Vector TxIn                        -- | The vector of transactions out.-                       , vout :: Vector TxOut+                       , vout           :: Vector TxOut                        -- | The hash of the block that was used for this                        --   transaction.                        , rawTxBlockHash :: HexString                        -- | The transaction's block's info.-                       , rawBlockInfo :: BlockInfo+                       , rawBlockInfo   :: BlockInfo                        }     deriving ( Show, Read, Ord, Eq ) @@ -280,14 +280,14 @@ --   hex-encoded transaction. data DecodedRawTransaction =     DecodedRawTransaction { -- | The raw transaction.-                            decRaw :: RawTransaction+                            decRaw         :: RawTransaction                           -- | The transaction version number.-                          , decTxnVersion :: Integer+                          , decTxnVersion  :: Integer                           , decTxnLockTime :: Integer                           -- | The vector of transactions in.-                          , decVin :: Vector TxIn+                          , decVin         :: Vector TxIn                           -- | The vector of transactions out.-                          , decVout :: Vector TxOut+                          , decVout        :: Vector TxOut                           }  instance FromJSON DecodedRawTransaction where@@ -328,17 +328,17 @@                | SingleOrAnyoneCanPay  toString :: WhoCanPay -> Text-toString All = "ALL"-toString AllOrAnyoneCanPay = "ALL|ANYONECANPAY"-toString None = "NONE"-toString NoneOrAnyoneCanPay = "NONE|ANYONECANPAY"-toString Single = "SINGLE"+toString All                  = "ALL"+toString AllOrAnyoneCanPay    = "ALL|ANYONECANPAY"+toString None                 = "NONE"+toString NoneOrAnyoneCanPay   = "NONE|ANYONECANPAY"+toString Single               = "SINGLE" toString SingleOrAnyoneCanPay = "SINGLE|ANYONECANPAY"  -- | A raw signed transaction contains the raw, signed hexstring and whether or --   not this transaction has a complete signature set. data RawSignedTransaction =-    RawSignedTransaction { rawSigned :: HexString+    RawSignedTransaction { rawSigned         :: HexString                          , hasCompleteSigSet :: Bool                          } 
src/Network/Bitcoin/Types.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings  #-} {-# OPTIONS_GHC -Wall #-} -- | Contains the common types used through bitcoin RPC calls, that aren't --   specific to a single submodule.@@ -12,11 +13,11 @@                              , Address                              ) where -import Control.Exception-import Data.Fixed-import Data.Text ( Text )-import Data.Typeable+import           Control.Exception import qualified Data.ByteString.Lazy as BL+import           Data.Fixed+import           Data.Text            (Text)+import           Data.Typeable  -- | 'Client' describes authentication credentials and host info for -- making API requests to the Bitcoin daemon.
src/Network/Bitcoin/Wallet.hs view
@@ -45,6 +45,7 @@                               , listTransactions                               , listTransactions'                               , listAccounts+                              , importAddress                               , SinceBlock(..)                               , SimpleTransaction(..)                               , TransactionCategory(..)@@ -62,52 +63,51 @@                               , isAddressValid                               ) where -import Control.Applicative-import Control.Monad-import Data.Aeson as A-import qualified Data.HashMap.Lazy as HM-import Data.Maybe-import Data.Text-import Data.Time.Clock.POSIX-import Data.Vector as V hiding ((++))-import Network.Bitcoin.BlockChain (BlockHash)-import Network.Bitcoin.Internal-import Network.Bitcoin.RawTransaction (RawTransaction)+import           Control.Monad+import           Data.Aeson                     as A+import qualified Data.HashMap.Lazy              as HM+import           Data.Maybe+import           Data.Text+import           Data.Time.Clock.POSIX+import           Data.Vector                    as V hiding ((++))+import           Network.Bitcoin.BlockChain     (BlockHash)+import           Network.Bitcoin.Internal+import           Network.Bitcoin.RawTransaction (RawTransaction)  -- | A plethora of information about a bitcoind instance. data BitcoindInfo =     BitcoindInfo {                  -- | What version of bitcoind are we running?-                   bitcoinVersion :: Integer+                   bitcoinVersion       :: Integer                  -- | What is bitcoind's current protocol number?-                 , protocolVersion :: Integer+                 , protocolVersion      :: Integer                  -- | What version is the wallet?-                 , walletVersion :: Integer+                 , walletVersion        :: Integer                  -- | How much money is currently in the wallet?-                 , balance :: BTC+                 , balance              :: BTC                  -- | The number of blocks in our chain.-                 , numBlocks :: Integer+                 , numBlocks            :: Integer                  -- | How many peers are we connected to?-                 , numConnections :: Integer+                 , numConnections       :: Integer                  -- | A blank string if we're not using a proxy.-                 , proxy :: Text+                 , proxy                :: Text                  -- | The difficulty multiplier for bitcoin mining operations.                  , generationDifficulty :: Double                  -- | Are we on the test network (as opposed to the primary                  --   bitcoin network)?-                 , onTestNetwork :: Bool+                 , onTestNetwork        :: Bool                  -- | The timestamp of the oldest key in the key pool.-                 , keyPoolOldest :: Integer+                 , keyPoolOldest        :: Integer                  -- | The size of the key pool.-                 , keyPoolSize :: Integer+                 , keyPoolSize          :: Integer                  -- | How much do we currently pay as a transaction fee?-                 , transactionFeePaid :: BTC+                 , transactionFeePaid   :: BTC                  -- | If the wallet is unlocked, the number of seconds until a                  --   re-lock is needed.-                 , unlockedUntil :: Maybe Integer+                 , unlockedUntil        :: Maybe Integer                  -- | Any alerts will show up here. This should normally be an                  --   empty string.-                 , bitcoindErrors :: Text+                 , bitcoindErrors       :: Text                  }     deriving ( Show, Read, Ord, Eq ) @@ -344,11 +344,11 @@ -- | Information on how much was received by a given address. data ReceivedByAddress =     ReceivedByAddress { -- | The address which the money was deposited to.-                        recvAddress :: Address+                        recvAddress          :: Address                       -- | The account which this address belongs to.-                      , recvAccount :: Account+                      , recvAccount          :: Account                       -- | The amount received.-                      , recvAmount  :: BTC+                      , recvAmount           :: BTC                       -- | The number of confirmations of the most recent                       --   included transaction.                       , recvNumConfirmations :: Integer@@ -382,9 +382,9 @@     callApi client "listreceivedbyaddress" [ tj minconf, tj includeEmpty ]  data ReceivedByAccount =-    ReceivedByAccount { raccAccount :: Account+    ReceivedByAccount { raccAccount          :: Account                       -- ^ The account we received into.-                      , raccAmount  :: BTC+                      , raccAmount           :: BTC                       -- ^ The mount received.                       -- ^ The number of confirmations of the most recent                       --   included transaction.@@ -415,68 +415,68 @@                        -> IO (Vector ReceivedByAccount) listReceivedByAccount' client minconf includeEmpty =     callApi client "listreceivedbyaccount" [ tj minconf, tj includeEmpty ]-     -data SinceBlock = -    SinceBlock { strransactions :: Vector SimpleTransaction++data SinceBlock =+    SinceBlock { strransactions  :: Vector SimpleTransaction                , sbLastBlockHash :: BlockHash                }     deriving ( Show, Ord, Eq )-    + instance FromJSON SinceBlock where     parseJSON (Object o) = SinceBlock <$> o .:  "transactions"                                       <*> o .:  "lastblock"     parseJSON _ = mzero --- | Data type for simple transactions. Rules involving 'Maybe' are ---   indications of the most probable value only when the transaction is +-- | Data type for simple transactions. Rules involving 'Maybe' are+--   indications of the most probable value only when the transaction is --   obtained from 'listTransactions' or 'listSinceBlock' are their associated --   methods. They are never enforced on this side. data SimpleTransaction =     SimpleTransaction {-        -- | The account name associated with the transaction. The empty string +        -- | The account name associated with the transaction. The empty string         --   is the default account.           stReceivingAccount :: Account-        -- | The bitcoin address of the transaction. Is 'Nothing' unless +        -- | The bitcoin address of the transaction. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , stAddress :: Maybe Address+        , stAddress          :: Maybe Address         -- | The category of the transaction-        , stCategory :: TransactionCategory-        -- | The fees paid to process the transaction. Is 'Nothing' unless +        , stCategory         :: TransactionCategory+        -- | The fees paid to process the transaction. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , stFee :: Maybe BTC+        , stFee              :: Maybe BTC         -- | The amount of bitcoins transferred.-        , stAmount :: BTC+        , stAmount           :: BTC         -- | The number of confirmations of the transaction. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , stConfirmations :: Maybe Integer-        -- | The hash of the block containing the transaction. Is 'Nothing' +        , stConfirmations    :: Maybe Integer+        -- | The hash of the block containing the transaction. Is 'Nothing'         --   unless 'trCategory' is 'TCSend' or 'TCReceive'.-        , stBlockHash :: Maybe BlockHash+        , stBlockHash        :: Maybe BlockHash         -- | The index of the the block containing the transaction. Is 'Nothing'         --   unless  'trCategory' is 'TCSend' or 'TCReceive'.-        , stBlockIndex :: Maybe Integer-        -- | The block time in seconds since epoch (1 Jan 1970 GMT). Is +        , stBlockIndex       :: Maybe Integer+        -- | The block time in seconds since epoch (1 Jan 1970 GMT). Is         --   'Nothing' unless 'trCategory' is 'TCSend' or 'TCReceive'.-        , stBlockTime :: Maybe POSIXTime-        -- | The transaction id. Is 'Nothing' unless +        , stBlockTime        :: Maybe POSIXTime+        -- | The transaction id. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , stTransactionId :: Maybe TransactionID-        -- | The list of transaction ids containing the same data as the -        --   original transaction (See ID-malleation bug). Is 'Nothing' unless +        , stTransactionId    :: Maybe TransactionID+        -- | The list of transaction ids containing the same data as the+        --   original transaction (See ID-malleation bug). Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , stWalletConflicts :: Maybe (Vector TransactionID)+        , stWalletConflicts  :: Maybe (Vector TransactionID)         -- | The block time in seconds since epoch (1 Jan 1970 GMT).-        , stTime :: POSIXTime-        , stTimeReceived :: Maybe POSIXTime+        , stTime             :: POSIXTime+        , stTimeReceived     :: Maybe POSIXTime         -- | Is 'Nothing' unless a comment is associated with the transaction.-        , stComment :: Maybe Text+        , stComment          :: Maybe Text         -- | Is 'Nothing' unless a \"to\" is associated with the transaction.-        , stTo :: Maybe Text-        -- | The account the funds came from (for receiving funds, positive -        --   amounts), or went to (for sending funds, negative amounts). Is +        , stTo               :: Maybe Text+        -- | The account the funds came from (for receiving funds, positive+        --   amounts), or went to (for sending funds, negative amounts). Is         --   'Nothing' unless 'trCategory' is 'TCMove'.-        , stOtherAccount :: Maybe Account+        , stOtherAccount     :: Maybe Account         }     deriving ( Show, Ord, Eq ) @@ -521,7 +521,7 @@               createTC "move"     = TCMove               createTC uc         = TCErrorUnexpected uc     parseJSON _ = mzero-    + -- | Gets all transactions in blocks since the given block. listSinceBlock :: Client                -> BlockHash@@ -529,13 +529,13 @@                -> Maybe Int                -- ^ The minimum number of confirmations before a                --   transaction can be returned as 'sbLastBlockHash'. This does-               --   not in any way affect which transactions are returned +               --   not in any way affect which transactions are returned                --   (see https://github.com/bitcoin/bitcoin/pull/199#issuecomment-1514952)                -> IO (SinceBlock) listSinceBlock client blockHash conf =     listSinceBlock' client (Just blockHash) conf --- | Gets all transactions in blocks since the given block, or all +-- | Gets all transactions in blocks since the given block, or all --   transactions if ommited. listSinceBlock' :: Client                 -> Maybe BlockHash@@ -543,22 +543,22 @@                 -> Maybe Int                 -- ^ The minimum number of confirmations before a                 --   transaction can be returned as 'sbLastBlockHash'. This does-                --   not in any way affect which transactions are returned +                --   not in any way affect which transactions are returned                 --   (see https://github.com/bitcoin/bitcoin/pull/199#issuecomment-1514952)                 -> IO (SinceBlock) listSinceBlock' client mblockHash mminConf =     callApi client "listsinceblock" $ tja mblockHash ++ tja mminConf-        -    ++ -- | Returns transactions from the blockchain. listTransactions :: Client                  -> Account-                 -- ^ Limits the 'BlockTransaction' returned to those from or to +                 -- ^ Limits the 'BlockTransaction' returned to those from or to                  --   the given 'Account'.                  -> Int                  -- ^ Limits the number of 'BlockTransaction' returned.                  -> Int-                 -- ^ Number of most recent transactions to skip. +                 -- ^ Number of most recent transactions to skip.                  -> IO (Vector SimpleTransaction) listTransactions client account size from =     listTransactions' client (Just account) (Just size) (Just from)@@ -566,14 +566,14 @@ -- | Returns transactions from the blockchain. listTransactions' :: Client                   -> Maybe Account-                  -- ^ Limits the 'BlockTransaction' returned to those from or to -                  --   the given 'Account'. If 'Nothing' all accounts are +                  -- ^ Limits the 'BlockTransaction' returned to those from or to+                  --   the given 'Account'. If 'Nothing' all accounts are                   --   included in the query.                   -> Maybe Int-                  -- ^ Limits the number of 'BlockTransaction' returned. If +                  -- ^ Limits the number of 'BlockTransaction' returned. If                   --   'Nothing' all transactions are returned.                   -> Maybe Int-                  -- ^ Number of most recent transactions to skip. +                  -- ^ Number of most recent transactions to skip.                   -> IO (Vector SimpleTransaction) listTransactions' client maccount mcount mfrom =     callApi client "listtransactions" $ [ tjm "*" maccount ] ++ tja mcount ++ tja mfrom@@ -582,44 +582,59 @@ -- | List accounts and their current balance. listAccounts :: Client              -> Maybe Int-             -- ^ Minimum number of confirmations required before payments are +             -- ^ Minimum number of confirmations required before payments are              --   included in the balance.              -> IO (HM.HashMap Account BTC)-listAccounts client mconf = +listAccounts client mconf =     callApi client "listaccounts" [ tjm 1 mconf ] --- | Data type for detailed transactions. Rules involving 'trCategory' are ---   indications of the most probable value only when the transaction is ++-- | Import an address+importAddress :: Client+              -> Address+              -- ^ Address to import+              -> Maybe Account+              -- ^ Optional account, default ""+              -> Maybe Bool+              -- ^ Optional rescan the blockchain, default true+              -> IO ()+importAddress client addr macct mrescan =+    unNil <$> callApi client "importaddress"+        ([ tj addr ] ++ tja macct ++ tja mrescan)+++-- | Data type for detailed transactions. Rules involving 'trCategory' are+--   indications of the most probable value only when the transaction is --   obtained from 'listTransactions' or 'listSinceBlock' are their associated --   methods. data DetailedTransaction =     DetailedTransaction {         -- | The amount of bitcoins transferred.-          dtAmount :: BTC-        -- | The fees paid to process the transaction. Is 'Nothing' unless +          dtAmount          :: BTC+        -- | The fees paid to process the transaction. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , dtFee :: Maybe BTC+        , dtFee             :: Maybe BTC         -- | The number of confirmations of the transaction. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , dtConfirmations :: Maybe Integer-        -- | The transaction id. Is 'Nothing' unless +        , dtConfirmations   :: Maybe Integer+        -- | The transaction id. Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.-        , dtTransactionId :: Maybe TransactionID-        -- | The list of transaction ids containing the same data as the -        --   original transaction (See ID-malleation bug). Is 'Nothing' unless +        , dtTransactionId   :: Maybe TransactionID+        -- | The list of transaction ids containing the same data as the+        --   original transaction (See ID-malleation bug). Is 'Nothing' unless         --   'trCategory' is 'TCSend' or 'TCReceive'.         , dtWalletConflicts :: Maybe (Vector TransactionID)         -- | The block time in seconds since epoch (1 Jan 1970 GMT).-        , dtTime :: POSIXTime-        , dtTimeReceived :: Maybe POSIXTime+        , dtTime            :: POSIXTime+        , dtTimeReceived    :: Maybe POSIXTime         -- | Is 'Nothing' unless a comment is associated with the transaction.-        , dtComment :: Maybe Text+        , dtComment         :: Maybe Text         -- | Is 'Nothing' unless a \"to\" is associated with the transaction.-        , dtTo :: Maybe Text+        , dtTo              :: Maybe Text         -- | The details of the transaction.-        , dtDetails :: Vector DetailedTransactionDetails+        , dtDetails         :: Vector DetailedTransactionDetails         -- | Raw data for the transaction.-        , dtHex :: RawTransaction+        , dtHex             :: RawTransaction         }     deriving ( Show, Ord, Eq ) @@ -638,21 +653,21 @@         <*> o .:  "details"         <*> o .:  "hex"     parseJSON _ = mzero-    + data DetailedTransactionDetails =     DetailedTransactionDetails {-        -- | The account name associated with the transaction. The empty string +        -- | The account name associated with the transaction. The empty string         --   is the default account.           dtdReceivingAccount :: Account         -- | The bitcoin address of the transaction.-        , dtdAddress :: Address+        , dtdAddress          :: Address         -- | The category of the transaction-        , dtdCategory :: TransactionCategory+        , dtdCategory         :: TransactionCategory         -- | The amount of bitcoins transferred.-        , dtdAmount :: BTC+        , dtdAmount           :: BTC         }     deriving ( Show, Ord, Eq )-    + instance FromJSON DetailedTransactionDetails where     parseJSON (Object o) = DetailedTransactionDetails <$> o .:  "account"                                                       <*> o .:  "address"@@ -660,10 +675,10 @@                                                       <*> o .:  "amount"     parseJSON _ = mzero -getTransaction :: Client +getTransaction :: Client                -> TransactionID                -> IO (DetailedTransaction)-getTransaction client txid = +getTransaction client txid =     callApi client "gettransaction" [ tj txid ]  @@ -725,7 +740,7 @@  instance FromJSON IsValid where     parseJSON (Object o) = IsValid <$> o .: "isvalid"-    parseJSON _ = mzero+    parseJSON _          = mzero  -- | Checks if a given address is a valid one. isAddressValid :: Client -> Address -> IO Bool
src/Test/Main.hs view
@@ -3,10 +3,10 @@ module Main where  -import Test.QuickCheck-import Test.QuickCheck.Monadic-import Network.Bitcoin-import Data.Vector ( empty )+import           Data.Vector             (empty)+import           Network.Bitcoin+import           Test.QuickCheck+import           Test.QuickCheck.Monadic   main :: IO ()