-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An interface to bitcoind. -- -- This can be used to send Bitcoins, query balances, etc. It requires -- the Bitcoin daemon to be running and accessible via HTTP. -- --
-- import Network.Bitcoin -- -- main = do -- client <- getClient "http://127.0.0.1:8332" "user" "password" -- balance <- getBalance client -- putStrLn $ show balance ++ " BTC" ---- -- To learn more about Bitcoin, see http://www.bitcoin.org. @package network-bitcoin @version 1.9.1 -- | Contains the common types used through bitcoin RPC calls, that aren't -- specific to a single submodule. module Network.Bitcoin.Types -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | A BitcoinException is thrown when 'callApi encounters an error. -- The API error code is represented as an Int, the message as a -- String. -- -- It may also be thrown when the value returned by the bitcoin API -- wasn't what we expected. -- -- WARNING: Any of the functions in this module's public API may throw -- this exception. You should plan on handling it. data BitcoinException -- | A BitcoinApiError has an error code error message, as returned -- by bitcoind's JSON-RPC response. BitcoinApiError :: Int -> Text -> BitcoinException -- | The raw JSON returned, if we can't figure out what actually went -- wrong. BitcoinResultTypeError :: ByteString -> BitcoinException -- | A string returned by the bitcoind API, representing data as hex. -- -- What that data represents depends on the API call, but should be -- dcumented accordingly. type HexString = Text -- | A hexadecimal string representation of a 256-bit unsigned integer. -- -- This integer is a unique transaction identifier. type TransactionID = HexString -- | A satoshi is the smallest subdivision of bitcoins. For the resolution, -- use resolution from Fixed. data Satoshi Satoshi :: Satoshi -- | The type of bitcoin money, represented with a fixed-point number. type BTC = Fixed Satoshi -- | An account on the wallet is just a label to easily specify private -- keys. -- -- The default account is an empty string. type Account = Text -- | An address for sending or receiving money. type Address = HexString instance GHC.Classes.Eq Network.Bitcoin.Types.BitcoinException instance GHC.Classes.Ord Network.Bitcoin.Types.BitcoinException instance GHC.Read.Read Network.Bitcoin.Types.BitcoinException instance GHC.Show.Show Network.Bitcoin.Types.BitcoinException instance Data.Fixed.HasResolution Network.Bitcoin.Types.Satoshi instance GHC.Exception.Type.Exception Network.Bitcoin.Types.BitcoinException -- | The API exposed in this module should be considered unstable, and is -- subject to change between minor revisions. -- -- If the version number is a.b.c.d, and either a or b changes, then the -- module's whole API may have changed (if only b changes, then it was -- probably a minor change). -- -- If c changed, then only the internal API may change. The rest of the -- module is guaranteed to be stable. -- -- If only d changes, then there were no user-facing code changes made. module Network.Bitcoin.Internal -- | A space efficient, packed, unboxed Unicode text type. data Text -- | Boxed vectors, supporting efficient slicing. data Vector a -- | A type that can be converted from JSON, with the possibility of -- failure. -- -- In many cases, you can get the compiler to generate parsing code for -- you (see below). To begin, let's cover writing an instance by hand. -- -- There are various reasons a conversion could fail. For example, an -- Object could be missing a required key, an Array could -- be of the wrong size, or a value could be of an incompatible type. -- -- The basic ways to signal a failed conversion are as follows: -- --
-- -- Allow ourselves to write Text literals.
-- {-# LANGUAGE OverloadedStrings #-}
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance FromJSON Coord where
-- parseJSON (Object v) = Coord
-- <$> v .: "x"
-- <*> v .: "y"
--
-- -- We do not expect a non-Object value here.
-- -- We could use empty to fail, but typeMismatch
-- -- gives a much more informative error message.
-- parseJSON invalid =
-- prependFailure "parsing Coord failed, "
-- (typeMismatch "Object" invalid)
--
--
-- For this common case of only being concerned with a single type of
-- JSON value, the functions withObject, withScientific,
-- etc. are provided. Their use is to be preferred when possible, since
-- they are more terse. Using withObject, we can rewrite the above
-- instance (assuming the same language extension and data type) as:
--
-- -- instance FromJSON Coord where -- parseJSON = withObject "Coord" $ \v -> Coord -- <$> v .: "x" -- <*> v .: "y" ---- -- Instead of manually writing your FromJSON instance, there are -- two options to do it automatically: -- --
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance FromJSON Coord
--
--
-- The default implementation will be equivalent to parseJSON =
-- genericParseJSON defaultOptions; if you need
-- different options, you can customize the generic decoding by defining:
--
--
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance FromJSON Coord where
-- parseJSON = genericParseJSON customOptions
--
class FromJSON a
parseJSON :: FromJSON a => Value -> Parser a
parseJSONList :: FromJSON a => Value -> Parser [a]
-- | callApi is a low-level interface for making authenticated API
-- calls to a Bitcoin daemon. The first argument specifies rpc client
-- details (URL, username, password)
--
-- The second argument is the command name. The third argument provides
-- parameters for the API call.
--
-- -- genHash = do ---- -- client <- getClient "http://127.0.0.1:8332" "user" -- "password" callApi client "getblockhash" [tj 0] -- -- On error, throws a BitcoinException. callApi :: FromJSON v => Client -> Text -> [Value] -> IO v -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | Used to allow "null" to decode to a tuple. newtype Nil Nil :: () -> Nil [unNil] :: Nil -> () -- | Used to parse "null" or [HexString] newtype NilOrArray NilOrArray :: Maybe [HexString] -> NilOrArray [unArr] :: NilOrArray -> Maybe [HexString] -- | A handy shortcut for toJSON, because I'm lazy. tj :: ToJSON a => a -> Value tjm :: ToJSON a => a -> Maybe a -> Value tja :: ToJSON a => Maybe a -> [Value] -- | A wrapper for a vector of address:amount pairs. The RPC expects that -- as an object of "address":"amount" pairs, instead of a vector. So -- that's what we give them with AddrAddress's ToJSON. newtype AddrAddress AA :: Vector (Address, BTC) -> AddrAddress -- | 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 :: a -> BitcoinRpcError -> BitcoinRpcResponse a [btcResult] :: BitcoinRpcResponse a -> a [btcError] :: BitcoinRpcResponse a -> BitcoinRpcError instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.Bitcoin.Internal.BitcoinRpcResponse a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Network.Bitcoin.Internal.BitcoinRpcResponse a) instance GHC.Read.Read a => GHC.Read.Read (Network.Bitcoin.Internal.BitcoinRpcResponse a) instance GHC.Show.Show a => GHC.Show.Show (Network.Bitcoin.Internal.BitcoinRpcResponse a) instance GHC.Classes.Eq Network.Bitcoin.Internal.BitcoinRpcError instance GHC.Classes.Ord Network.Bitcoin.Internal.BitcoinRpcError instance GHC.Read.Read Network.Bitcoin.Internal.BitcoinRpcError instance GHC.Show.Show Network.Bitcoin.Internal.BitcoinRpcError instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.Internal.AddrAddress instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Internal.NilOrArray instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Internal.Nil instance Data.Aeson.Types.FromJSON.FromJSON a => Data.Aeson.Types.FromJSON.FromJSON (Network.Bitcoin.Internal.BitcoinRpcResponse a) instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Internal.BitcoinRpcError -- | An interface to bitcoind's available raw transaction-related RPC -- calls. The implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcrawtransaction.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. -- -- 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 -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | Just like most binary data retrieved from bitcoind, a raw transaction -- is represented by a hexstring. -- -- This is a serialized, hex-encoded transaction. type RawTransaction = HexString -- | Get a raw transaction from its unique ID. getRawTransaction :: Client -> TransactionID -> IO RawTransaction -- | A transaction into an account. This can either be a coinbase -- transaction, or a standard transaction with another account. data TxIn TxCoinbase :: HexString -> TxIn [txCoinbase] :: TxIn -> HexString TxIn :: TransactionID -> Integer -> ScriptSig -> Integer -> TxIn -- | This transaction's ID. [txInId] :: TxIn -> TransactionID [numOut] :: TxIn -> Integer [scriptSig] :: TxIn -> ScriptSig -- | A transaction sequence number. [txSequence] :: TxIn -> Integer -- | The type of a transaction out. -- -- More documentation is needed here. Submit a patch if you know what -- this is about! data TxnOutputType -- | JSON of "pubkey" received. TxnPubKey :: TxnOutputType -- | JSON of "pubkeyhash" received. TxnPubKeyHash :: TxnOutputType -- | JSON of "scripthash" received. TxnScriptHash :: TxnOutputType -- | JSON of "multisig" received. TxnMultisig :: TxnOutputType -- | A public key of someone we sent money to. data ScriptPubKey NonStandardScriptPubKey :: HexString -> HexString -> ScriptPubKey -- | The JSON "asm" field. [nspkAsm] :: ScriptPubKey -> HexString -- | The JSON "hex" field. [nspkHex] :: ScriptPubKey -> HexString StandardScriptPubKey :: HexString -> HexString -> Integer -> TxnOutputType -> Vector Address -> ScriptPubKey -- | The JSON "asm" field. [sspkAsm] :: ScriptPubKey -> HexString -- | The JSON "hex" field. [sspkHex] :: ScriptPubKey -> HexString -- | The number of required signatures. [requiredSigs] :: ScriptPubKey -> Integer -- | The type of the transaction. [sspkType] :: ScriptPubKey -> TxnOutputType -- | The addresses associated with this key. [sspkAddresses] :: ScriptPubKey -> Vector Address -- | A script signature. data ScriptSig ScriptSig :: HexString -> HexString -> ScriptSig [sigAsm] :: ScriptSig -> HexString [sigHex] :: ScriptSig -> HexString -- | A transaction out of an account. data TxOut TxOut :: BTC -> ScriptPubKey -> TxOut -- | The amount of bitcoin transferred out. [txoutVal] :: TxOut -> BTC -- | The public key of the account we sent the money to. [scriptPubKey] :: TxOut -> ScriptPubKey -- | Information on a single block. data BlockInfo ConfirmedBlock :: Integer -> Integer -> Integer -> BlockInfo -- | The number of confirmations a block has. This will always be >= 1. [confirmations] :: BlockInfo -> Integer [cbTime] :: BlockInfo -> Integer -- | The JSON "blocktime" field. [blockTime] :: BlockInfo -> Integer -- | An unconfirmed block is boring, but a possibility. UnconfirmedBlock :: BlockInfo -- | The raw transaction info for a given transaction ID. data RawTransactionInfo RawTransactionInfo :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> HexString -> BlockInfo -> RawTransactionInfo -- | The raw transaction. [raw] :: RawTransactionInfo -> RawTransaction -- | The transaction version number. [txnVersion] :: RawTransactionInfo -> Integer [txnLockTime] :: RawTransactionInfo -> Integer -- | The vector of transactions in. [vin] :: RawTransactionInfo -> Vector TxIn -- | The vector of transactions out. [vout] :: RawTransactionInfo -> Vector TxOut -- | The hash of the block that was used for this transaction. [rawTxBlockHash] :: RawTransactionInfo -> HexString -- | The transaction's block's info. [rawBlockInfo] :: RawTransactionInfo -> BlockInfo -- | Get raw transaction info for a given transaction ID. The data -- structure returned is quite sprawling and undocumented, so any patches -- to help simplify things would be greatly appreciated. getRawTransactionInfo :: Client -> TransactionID -> IO RawTransactionInfo data UnspentTransaction UnspentTransaction :: TransactionID -> Integer -> Address -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction [unspentTransactionId] :: UnspentTransaction -> TransactionID [outIdx] :: UnspentTransaction -> Integer [unspentAddress] :: UnspentTransaction -> Address [unspentScriptPubKey] :: UnspentTransaction -> HexString [redeemScript] :: UnspentTransaction -> Maybe HexString [unspentAmount] :: UnspentTransaction -> BTC [usConfirmations] :: UnspentTransaction -> Integer -- | Returns an array of unspent transaction outputs with between minconf -- and maxconf (inclusive) confirmations. If addresses are given, the -- result will be filtered to include only those addresses. listUnspent :: Client -> Maybe Int -> Maybe Int -> Vector Address -> IO (Vector UnspentTransaction) -- | Create a transaction spending given inputs, sending to given -- addresses. -- -- Note that the transaction's inputs are not signed, and it is not -- stored in the wallet or transmitted to the network. -- -- Also, there is no checking to see if it's possible to send that much -- to the targets specified. In the future, such a scenario might throw -- an exception. createRawTransaction :: Client -> Vector UnspentTransaction -> Vector (Address, BTC) -> IO HexString -- | A successfully decoded raw transaction, from a given serialized, -- hex-encoded transaction. data DecodedRawTransaction DecodedRawTransaction :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> DecodedRawTransaction -- | The raw transaction. [decRaw] :: DecodedRawTransaction -> RawTransaction -- | The transaction version number. [decTxnVersion] :: DecodedRawTransaction -> Integer [decTxnLockTime] :: DecodedRawTransaction -> Integer -- | The vector of transactions in. [decVin] :: DecodedRawTransaction -> Vector TxIn -- | The vector of transactions out. [decVout] :: DecodedRawTransaction -> Vector TxOut -- | Decodes a raw transaction into a more accessible data structure. decodeRawTransaction :: Client -> RawTransaction -> IO DecodedRawTransaction -- | Who can pay for a given transaction. data WhoCanPay All :: WhoCanPay AllOrAnyoneCanPay :: WhoCanPay None :: WhoCanPay NoneOrAnyoneCanPay :: WhoCanPay Single :: WhoCanPay SingleOrAnyoneCanPay :: WhoCanPay -- | A raw signed transaction contains the raw, signed hexstring and -- whether or not this transaction has a complete signature set. data RawSignedTransaction RawSignedTransaction :: HexString -> Bool -> RawSignedTransaction [rawSigned] :: RawSignedTransaction -> HexString [hasCompleteSigSet] :: RawSignedTransaction -> Bool -- | Sign inputs for a raw transaction. signRawTransaction :: Client -> RawTransaction -> Maybe (Vector UnspentTransaction) -> Maybe (Vector HexString) -> Maybe WhoCanPay -> IO RawSignedTransaction sendRawTransaction :: Client -> RawTransaction -> IO TransactionID instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.UnspentTransaction instance GHC.Show.Show Network.Bitcoin.RawTransaction.UnspentTransaction instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.RawTransactionInfo instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.RawTransactionInfo instance GHC.Read.Read Network.Bitcoin.RawTransaction.RawTransactionInfo instance GHC.Show.Show Network.Bitcoin.RawTransaction.RawTransactionInfo instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.BlockInfo instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.BlockInfo instance GHC.Read.Read Network.Bitcoin.RawTransaction.BlockInfo instance GHC.Show.Show Network.Bitcoin.RawTransaction.BlockInfo instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.TxIn instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.TxIn instance GHC.Read.Read Network.Bitcoin.RawTransaction.TxIn instance GHC.Show.Show Network.Bitcoin.RawTransaction.TxIn instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.ScriptSig instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.ScriptSig instance GHC.Read.Read Network.Bitcoin.RawTransaction.ScriptSig instance GHC.Show.Show Network.Bitcoin.RawTransaction.ScriptSig instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.TxOut instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.TxOut instance GHC.Read.Read Network.Bitcoin.RawTransaction.TxOut instance GHC.Show.Show Network.Bitcoin.RawTransaction.TxOut instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.ScriptPubKey instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.ScriptPubKey instance GHC.Read.Read Network.Bitcoin.RawTransaction.ScriptPubKey instance GHC.Show.Show Network.Bitcoin.RawTransaction.ScriptPubKey instance GHC.Classes.Eq Network.Bitcoin.RawTransaction.TxnOutputType instance GHC.Classes.Ord Network.Bitcoin.RawTransaction.TxnOutputType instance GHC.Read.Read Network.Bitcoin.RawTransaction.TxnOutputType instance GHC.Show.Show Network.Bitcoin.RawTransaction.TxnOutputType instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.RawSignedTransaction instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.RawTransaction.UnspentForSigning instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.DecodedRawTransaction instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.UnspentTransaction instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.RawTransaction.UnspentTransaction instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.RawTransactionInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.BlockInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.TxIn instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.ScriptSig instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.TxOut instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.ScriptPubKey instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.RawTransaction.TxnOutputType -- | An interface to bitcoind's available network-related RPC calls. The -- implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcnet.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. module Network.Bitcoin.Net -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | Returns the number of connections to other nodes. getConnectionCount :: Client -> IO Integer -- | Information about a peer node of the Bitcoin network. -- -- The documentation for this data structure is incomplete, as I honestly -- don't know what some of these fields are for. Patches are welcome! data PeerInfo PeerInfo :: Text -> Text -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Text -> Bool -> Integer -> Integer -> PeerInfo -- | The IP:port of this peer, as a string. [addressName] :: PeerInfo -> Text [services] :: PeerInfo -> Text -- | Relative to the first time we conected with this peer (and in -- milliseconds), the last time we sent this peer any data. [lastSend] :: PeerInfo -> Integer -- | Relative to the first time we connected with this peer (and in -- milliseconds), the last time we sent this peer any data. [lastRecv] :: PeerInfo -> Integer [bytesSent] :: PeerInfo -> Integer [bytesRecv] :: PeerInfo -> Integer -- | How long have we been connected to this peer (in milliseconds). [connectionTime] :: PeerInfo -> Integer -- | The version of the Bitcion client the peer is running. [peerVersion] :: PeerInfo -> Integer -- | The sub-version of the Bitcoin client the peer is running. [peerSubversion] :: PeerInfo -> Text [inbound] :: PeerInfo -> Bool [startingHeight] :: PeerInfo -> Integer -- | How many times has this peer behaved badly? [banScore] :: PeerInfo -> Integer -- | Returns data about all connected peer nodes. getPeerInfo :: Client -> IO [PeerInfo] data AddNodeCommand Add :: AddNodeCommand Remove :: AddNodeCommand OneTry :: AddNodeCommand addNode :: Client -> Text -> AddNodeCommand -> IO () disconnectNode :: Client -> Maybe Text -> Maybe Int -> IO () instance GHC.Classes.Eq Network.Bitcoin.Net.AddNodeCommand instance GHC.Read.Read Network.Bitcoin.Net.AddNodeCommand instance GHC.Show.Show Network.Bitcoin.Net.AddNodeCommand instance GHC.Classes.Eq Network.Bitcoin.Net.PeerInfo instance GHC.Classes.Ord Network.Bitcoin.Net.PeerInfo instance GHC.Read.Read Network.Bitcoin.Net.PeerInfo instance GHC.Show.Show Network.Bitcoin.Net.PeerInfo instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.Net.AddNodeCommand instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Net.PeerInfo -- | An interface to bitcoind's available private key calls. The -- implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcdump.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. module Network.Bitcoin.Dump -- | A textual representation of a bitcoin private key. type PrivateKey = Text -- | Adds a private key (as returned by dumpprivkey) to your wallet. importPrivateKey :: Client -> PrivateKey -> Maybe Account -> IO () -- | Reveals the private key corresponding to the given address. dumpPrivateKey :: Client -> Address -> IO PrivateKey -- | An interface to bitcoind's available block-chain-related RPC calls. -- The implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcblockchain.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. module Network.Bitcoin.BlockChain -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | A hexadecimal string representation of a 256-bit unsigned integer. -- -- This integer is a unique transaction identifier. type TransactionID = HexString -- | The type of bitcoin money, represented with a fixed-point number. type BTC = Fixed Satoshi -- | Returns the number of blocks in the longest block chain. getBlockCount :: Client -> IO BlockHeight -- | Returns the proof-of-work difficulty as a multiple of the minimum -- difficulty. getDifficulty :: Client -> IO Integer -- | Sets the transaction fee will will pay to the network. Values of 0 are -- rejected. setTransactionFee :: Client -> BTC -> IO () -- | Returns all transaction identifiers in the memory pool. getRawMemoryPool :: Client -> IO (Vector TransactionID) -- | The hash of a given block. type BlockHash = HexString type BlockHeight = Integer -- | Returns the hash of the block in best-block-chain at the given index. getBlockHash :: Client -> BlockHeight -> IO BlockHash -- | Information about a given block in the block chain. data Block Block :: BlockHash -> Integer -> Integer -> BlockHeight -> Integer -> BlockHash -> Vector TransactionID -> Integer -> Integer -> HexString -> Double -> Maybe BlockHash -> Maybe BlockHash -> Block [blockHash] :: Block -> BlockHash -- | The number of confirmations the block has. [blkConfirmations] :: Block -> Integer -- | The size of the block. [blkSize] :: Block -> Integer -- | The "height" of the block. TODO: Clarify this. [blkHeight] :: Block -> BlockHeight -- | The version of the block. [blkVersion] :: Block -> Integer -- | The hash of the block at the root of the merkle tree which this block -- belongs to. [merkleRoot] :: Block -> BlockHash -- | Should this be a transaction, or transaction id? [subTransactions] :: Block -> Vector TransactionID -- | The time it was mined. [blkTime] :: Block -> Integer -- | The block's nonce. [blkNonce] :: Block -> Integer [blkBits] :: Block -> HexString -- | How hard was this block to mine? [blkDifficulty] :: Block -> Double -- | A pointer to the next block in the chain. [nextBlock] :: Block -> Maybe BlockHash -- | A pointer to the previous block in the chain. [prevBlock] :: Block -> Maybe BlockHash -- | Returns details of a block with given block-hash. getBlock :: Client -> BlockHash -> IO Block -- | Information on the unspent transaction in the output set. data OutputSetInfo OutputSetInfo :: BlockHash -> BlockHeight -> Integer -> Integer -> Integer -> OutputSetInfo [osiBestBlock] :: OutputSetInfo -> BlockHash -- | The height of the best block chain [osiHeight] :: OutputSetInfo -> BlockHeight -- | The number of transactions in the output set. [numTransactions] :: OutputSetInfo -> Integer -- | The number of outputs for the transactions. [transactionOutputs] :: OutputSetInfo -> Integer -- | The serialized size of the output set. [serializedSize] :: OutputSetInfo -> Integer -- | Returns statistics about the unspent transaction output set. getOutputSetInfo :: Client -> IO OutputSetInfo -- | Details about an unspent transaction output. data OutputInfo OutputInfo :: BlockHash -> Integer -> BTC -> ScriptPubKey -> Maybe Integer -> Bool -> OutputInfo [oiBestBlock] :: OutputInfo -> BlockHash -- | The number of times this transaction has been confirmed. [oiConfirmations] :: OutputInfo -> Integer -- | The amount transferred. [oiAmount] :: OutputInfo -> BTC -- | The public key of the sender. [oiScriptPubKey] :: OutputInfo -> ScriptPubKey -- | The version of this transaction. [oiVersion] :: OutputInfo -> Maybe Integer -- | Is this transaction part of the coin base? [oiCoinBase] :: OutputInfo -> Bool -- | Returns details about an unspent transaction output. getOutputInfo :: Client -> TransactionID -> Integer -> IO (Maybe OutputInfo) instance GHC.Classes.Eq Network.Bitcoin.BlockChain.OutputInfo instance GHC.Classes.Ord Network.Bitcoin.BlockChain.OutputInfo instance GHC.Read.Read Network.Bitcoin.BlockChain.OutputInfo instance GHC.Show.Show Network.Bitcoin.BlockChain.OutputInfo instance GHC.Classes.Eq Network.Bitcoin.BlockChain.OutputSetInfo instance GHC.Classes.Ord Network.Bitcoin.BlockChain.OutputSetInfo instance GHC.Read.Read Network.Bitcoin.BlockChain.OutputSetInfo instance GHC.Show.Show Network.Bitcoin.BlockChain.OutputSetInfo instance GHC.Classes.Eq Network.Bitcoin.BlockChain.Block instance GHC.Classes.Ord Network.Bitcoin.BlockChain.Block instance GHC.Read.Read Network.Bitcoin.BlockChain.Block instance GHC.Show.Show Network.Bitcoin.BlockChain.Block instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.BlockChain.OutputInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.BlockChain.OutputSetInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.BlockChain.Block -- | An interface to bitcoind's available wallet-related RPC calls. The -- implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcwallet.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. -- -- Certain APIs were too complicated for me to write an interface for. If -- you figure them out, then patches are always welcome! They're left in -- the source as comments. module Network.Bitcoin.Wallet -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | A plethora of information about a bitcoind instance. data BitcoindInfo BitcoindInfo :: Integer -> Integer -> Integer -> BTC -> Integer -> Integer -> Text -> Double -> Bool -> Integer -> Integer -> BTC -> Maybe Integer -> Text -> BitcoindInfo -- | What version of bitcoind are we running? [bitcoinVersion] :: BitcoindInfo -> Integer -- | What is bitcoind's current protocol number? [protocolVersion] :: BitcoindInfo -> Integer -- | What version is the wallet? [walletVersion] :: BitcoindInfo -> Integer -- | How much money is currently in the wallet? [balance] :: BitcoindInfo -> BTC -- | The number of blocks in our chain. [numBlocks] :: BitcoindInfo -> Integer -- | How many peers are we connected to? [numConnections] :: BitcoindInfo -> Integer -- | A blank string if we're not using a proxy. [proxy] :: BitcoindInfo -> Text -- | The difficulty multiplier for bitcoin mining operations. [generationDifficulty] :: BitcoindInfo -> Double -- | Are we on the test network (as opposed to the primary bitcoin -- network)? [onTestNetwork] :: BitcoindInfo -> Bool -- | The timestamp of the oldest key in the key pool. [keyPoolOldest] :: BitcoindInfo -> Integer -- | The size of the key pool. [keyPoolSize] :: BitcoindInfo -> Integer -- | How much do we currently pay as a transaction fee? [transactionFeePaid] :: BitcoindInfo -> BTC -- | If the wallet is unlocked, the number of seconds until a re-lock is -- needed. [unlockedUntil] :: BitcoindInfo -> Maybe Integer -- | Any alerts will show up here. This should normally be an empty string. [bitcoindErrors] :: BitcoindInfo -> Text -- | Returns an object containing various state info. -- -- Availability: < 0.16 getBitcoindInfo :: Client -> IO BitcoindInfo -- | Returns a new bitcoin address for receiving payments. -- -- If an account is specified (recommended), the new address is added to -- the address book so payments received with the address will be -- credited to the given account. -- -- If no account is specified, the address will be credited to the -- account whose name is the empty string. i.e. the default account. getNewAddress :: Client -> Maybe Account -> IO Address -- | Returns the current Bitcoin address for receiving payments to the -- given account. getAccountAddress :: Client -> Account -> IO Address -- | Returns the account associated with the given address. getAccount :: Client -> Address -> IO Account -- | Sets the account associated with the given address. setAccount :: Client -> Address -> Account -> IO () -- | Returns the list of addresses for the given address. getAddressesByAccount :: Client -> Account -> IO (Vector Address) -- | Sends some bitcoins to an address. sendToAddress :: Client -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID -- | Information on a given address. data AddressInfo AddressInfo :: Address -> BTC -> Maybe Account -> AddressInfo -- | The address in question. [aiAddress] :: AddressInfo -> Address -- | The address' balance. [aiAmount] :: AddressInfo -> BTC -- | The address' linked account. [aiAccount] :: AddressInfo -> Maybe Account -- | Lists groups of addresses which have had their common ownership made -- public by common use as inputs or as the resulting change in past -- transactions. listAddressGroupings :: Client -> IO (Vector (Vector AddressInfo)) -- | A signature is a base-64 encoded string. type Signature = HexString -- | Sign a message with the private key of an address. signMessage :: Client -> Address -> Text -> IO Signature -- | Verifies a signed message. verifyMessage :: Client -> Address -> Signature -> Text -> IO Bool -- | Returns the total amount received by the given address with at least -- one confirmation. getReceivedByAddress :: Client -> Address -> IO BTC -- | Returns the total amount received by the given address, with at least -- the give number of confirmations. getReceivedByAddress' :: Client -> Address -> Int -> IO BTC -- | Returns the total amount received by address with the given account. getReceivedByAccount :: Client -> Account -> IO BTC -- | Returns the total amount received by addresses with the given account, -- counting only transactions with the given minimum number of -- confirmations. getReceivedByAccount' :: Client -> Account -> Int -> IO BTC -- | Returns the server's total available balance. getBalance :: Client -> IO BTC -- | Returns the balance in the given account, counting only transactions -- with at least one confirmation. getBalance' :: Client -> Account -> IO BTC -- | Returns the balance in the given account, counting only transactions -- with at least the given number of confirmations. getBalance'' :: Client -> Account -> Int -> IO BTC -- | Move bitcoins from one account in your wallet to another. -- -- If you want to send bitcoins to an address not in your wallet, use -- sendFromAccount. moveBitcoins :: Client -> Account -> Account -> BTC -> Text -> IO () -- | Sends bitcoins from a given account in our wallet to a given address. -- -- A transaction and sender comment may be optionally provided. sendFromAccount :: Client -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID -- | Send to a whole bunch of address at once. sendMany :: Client -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID -- | Possible fee estimation modes data EstimationMode Economical :: EstimationMode Conservative :: EstimationMode -- | Estimate the fee per kb to send a transaction estimateSmartFee :: Client -> Word32 -> Maybe EstimationMode -> IO Double -- | Information on how much was received by a given address. data ReceivedByAddress ReceivedByAddress :: Address -> Account -> BTC -> Integer -> ReceivedByAddress -- | The address which the money was deposited to. [recvAddress] :: ReceivedByAddress -> Address -- | The account which this address belongs to. [recvAccount] :: ReceivedByAddress -> Account -- | The amount received. [recvAmount] :: ReceivedByAddress -> BTC -- | The number of confirmations of the most recent included transaction. [recvNumConfirmations] :: ReceivedByAddress -> Integer -- | Lists the amount received by each address which has received money at -- some point, counting only transactions with at least one confirmation. listReceivedByAddress :: Client -> IO (Vector ReceivedByAddress) -- | List the amount received by each of our addresses, counting only -- transactions with the given minimum number of confirmations. listReceivedByAddress' :: Client -> Int -> Bool -> IO (Vector ReceivedByAddress) data ReceivedByAccount ReceivedByAccount :: Account -> BTC -> Integer -> ReceivedByAccount -- | The account we received into. [raccAccount] :: ReceivedByAccount -> Account -- | The mount received. ^ The number of confirmations of the most recent -- included transaction. [raccAmount] :: ReceivedByAccount -> BTC [raccNumConfirmations] :: ReceivedByAccount -> Integer -- | Lists the amount received by each account which has received money at -- some point, counting only transactions with at leaset one -- confirmation. listReceivedByAccount :: Client -> IO (Vector ReceivedByAccount) -- | List the amount received by each of our accounts, counting only -- transactions with the given minimum number of confirmations. listReceivedByAccount' :: Client -> Int -> Bool -> IO (Vector ReceivedByAccount) -- | Returns transactions from the blockchain. listTransactions :: Client -> Account -> Int -> Int -> IO (Vector SimpleTransaction) -- | Returns transactions from the blockchain. listTransactions' :: Client -> Maybe Account -> Maybe Int -> Maybe Int -> IO (Vector SimpleTransaction) -- | List accounts and their current balance. listAccounts :: Client -> Maybe Int -> IO (HashMap Account BTC) -- | Import an address importAddress :: Client -> Address -> Maybe Account -> Maybe Bool -> IO () data SinceBlock SinceBlock :: Vector SimpleTransaction -> BlockHash -> SinceBlock [strransactions] :: SinceBlock -> Vector SimpleTransaction [sbLastBlockHash] :: SinceBlock -> BlockHash -- | 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 :: Account -> Maybe Address -> TransactionCategory -> Maybe BTC -> BTC -> Maybe Integer -> Maybe BlockHash -> Maybe Integer -> Maybe POSIXTime -> Maybe TransactionID -> Maybe (Vector TransactionID) -> POSIXTime -> Maybe POSIXTime -> Maybe Text -> Maybe Text -> Maybe Account -> SimpleTransaction -- | The account name associated with the transaction. The empty string is -- the default account. [stReceivingAccount] :: SimpleTransaction -> Account -- | The bitcoin address of the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [stAddress] :: SimpleTransaction -> Maybe Address -- | The category of the transaction [stCategory] :: SimpleTransaction -> TransactionCategory -- | The fees paid to process the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [stFee] :: SimpleTransaction -> Maybe BTC -- | The amount of bitcoins transferred. [stAmount] :: SimpleTransaction -> BTC -- | The number of confirmations of the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [stConfirmations] :: SimpleTransaction -> Maybe Integer -- | The hash of the block containing the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [stBlockHash] :: SimpleTransaction -> Maybe BlockHash -- | The index of the the block containing the transaction. Is -- Nothing unless trCategory is TCSend or -- TCReceive. [stBlockIndex] :: SimpleTransaction -> Maybe Integer -- | The block time in seconds since epoch (1 Jan 1970 GMT). Is -- Nothing unless trCategory is TCSend or -- TCReceive. [stBlockTime] :: SimpleTransaction -> Maybe POSIXTime -- | The transaction id. Is Nothing unless trCategory is -- TCSend or TCReceive. [stTransactionId] :: SimpleTransaction -> 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] :: SimpleTransaction -> Maybe (Vector TransactionID) -- | The block time in seconds since epoch (1 Jan 1970 GMT). [stTime] :: SimpleTransaction -> POSIXTime [stTimeReceived] :: SimpleTransaction -> Maybe POSIXTime -- | Is Nothing unless a comment is associated with the transaction. [stComment] :: SimpleTransaction -> Maybe Text -- | Is Nothing unless a "to" is associated with the transaction. [stTo] :: SimpleTransaction -> 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] :: SimpleTransaction -> Maybe Account data TransactionCategory TCSend :: TransactionCategory TCOrphan :: TransactionCategory TCImmature :: TransactionCategory TCGenerate :: TransactionCategory TCReceive :: TransactionCategory TCMove :: TransactionCategory TCErrorUnexpected :: Text -> TransactionCategory -- | Gets all transactions in blocks since the given block. listSinceBlock :: Client -> BlockHash -> Maybe Int -> IO SinceBlock -- | Gets all transactions in blocks since the given block, or all -- transactions if ommited. listSinceBlock' :: Client -> Maybe BlockHash -> Maybe Int -> IO SinceBlock -- | 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 :: BTC -> Maybe BTC -> Maybe Integer -> Maybe TransactionID -> Maybe (Vector TransactionID) -> POSIXTime -> Maybe POSIXTime -> Maybe Text -> Maybe Text -> Vector DetailedTransactionDetails -> RawTransaction -> DetailedTransaction -- | The amount of bitcoins transferred. [dtAmount] :: DetailedTransaction -> BTC -- | The fees paid to process the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [dtFee] :: DetailedTransaction -> Maybe BTC -- | The number of confirmations of the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [dtConfirmations] :: DetailedTransaction -> Maybe Integer -- | The transaction id. Is Nothing unless trCategory is -- TCSend or TCReceive. [dtTransactionId] :: DetailedTransaction -> 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] :: DetailedTransaction -> Maybe (Vector TransactionID) -- | The block time in seconds since epoch (1 Jan 1970 GMT). [dtTime] :: DetailedTransaction -> POSIXTime [dtTimeReceived] :: DetailedTransaction -> Maybe POSIXTime -- | Is Nothing unless a comment is associated with the transaction. [dtComment] :: DetailedTransaction -> Maybe Text -- | Is Nothing unless a "to" is associated with the transaction. [dtTo] :: DetailedTransaction -> Maybe Text -- | The details of the transaction. [dtDetails] :: DetailedTransaction -> Vector DetailedTransactionDetails -- | Raw data for the transaction. [dtHex] :: DetailedTransaction -> RawTransaction data DetailedTransactionDetails DetailedTransactionDetails :: Account -> Address -> TransactionCategory -> BTC -> DetailedTransactionDetails -- | The account name associated with the transaction. The empty string is -- the default account. [dtdReceivingAccount] :: DetailedTransactionDetails -> Account -- | The bitcoin address of the transaction. [dtdAddress] :: DetailedTransactionDetails -> Address -- | The category of the transaction [dtdCategory] :: DetailedTransactionDetails -> TransactionCategory -- | The amount of bitcoins transferred. [dtdAmount] :: DetailedTransactionDetails -> BTC getTransaction :: Client -> TransactionID -> IO DetailedTransaction -- | Safely copies wallet.dat to the given destination, which can be either -- a directory, or a path with filename. backupWallet :: Client -> FilePath -> IO () -- | Fills the keypool. keyPoolRefill :: Client -> IO () -- | Stores the wallet decryption key in memory for the given amount of -- time. unlockWallet :: Client -> Text -> Integer -> IO () -- | Removes the wallet encryption key from memory, locking the wallet. -- -- After calling this function, you will need to call unlockWallet -- again before being able to call methods which require the wallet to be -- unlocked. -- -- Note: In future releases, we might introduce an "unlocked" monad, so -- locking and unlocking is automatic. lockWallet :: Client -> IO () -- | Changes the wallet passphrase. changePassword :: Client -> Text -> Text -> IO () -- | Encrypts the wallet with the given passphrase. -- -- WARNING: bitcoind will shut down after calling this method. Don't say -- I didn't warn you. encryptWallet :: Client -> Text -> IO () -- | Checks if a given address is a valid one. isAddressValid :: Client -> Address -> IO Bool instance GHC.Classes.Eq Network.Bitcoin.Wallet.EstimationMode instance GHC.Classes.Eq Network.Bitcoin.Wallet.DetailedTransaction instance GHC.Classes.Ord Network.Bitcoin.Wallet.DetailedTransaction instance GHC.Show.Show Network.Bitcoin.Wallet.DetailedTransaction instance GHC.Classes.Eq Network.Bitcoin.Wallet.DetailedTransactionDetails instance GHC.Classes.Ord Network.Bitcoin.Wallet.DetailedTransactionDetails instance GHC.Show.Show Network.Bitcoin.Wallet.DetailedTransactionDetails instance GHC.Classes.Eq Network.Bitcoin.Wallet.SinceBlock instance GHC.Classes.Ord Network.Bitcoin.Wallet.SinceBlock instance GHC.Show.Show Network.Bitcoin.Wallet.SinceBlock instance GHC.Classes.Eq Network.Bitcoin.Wallet.SimpleTransaction instance GHC.Classes.Ord Network.Bitcoin.Wallet.SimpleTransaction instance GHC.Show.Show Network.Bitcoin.Wallet.SimpleTransaction instance GHC.Classes.Eq Network.Bitcoin.Wallet.TransactionCategory instance GHC.Classes.Ord Network.Bitcoin.Wallet.TransactionCategory instance GHC.Read.Read Network.Bitcoin.Wallet.TransactionCategory instance GHC.Show.Show Network.Bitcoin.Wallet.TransactionCategory instance GHC.Classes.Eq Network.Bitcoin.Wallet.ReceivedByAccount instance GHC.Classes.Ord Network.Bitcoin.Wallet.ReceivedByAccount instance GHC.Read.Read Network.Bitcoin.Wallet.ReceivedByAccount instance GHC.Show.Show Network.Bitcoin.Wallet.ReceivedByAccount instance GHC.Classes.Eq Network.Bitcoin.Wallet.ReceivedByAddress instance GHC.Classes.Ord Network.Bitcoin.Wallet.ReceivedByAddress instance GHC.Read.Read Network.Bitcoin.Wallet.ReceivedByAddress instance GHC.Show.Show Network.Bitcoin.Wallet.ReceivedByAddress instance GHC.Classes.Ord Network.Bitcoin.Wallet.AddressInfo instance GHC.Classes.Eq Network.Bitcoin.Wallet.AddressInfo instance GHC.Read.Read Network.Bitcoin.Wallet.AddressInfo instance GHC.Show.Show Network.Bitcoin.Wallet.AddressInfo instance GHC.Classes.Eq Network.Bitcoin.Wallet.BitcoindInfo instance GHC.Classes.Ord Network.Bitcoin.Wallet.BitcoindInfo instance GHC.Read.Read Network.Bitcoin.Wallet.BitcoindInfo instance GHC.Show.Show Network.Bitcoin.Wallet.BitcoindInfo instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.Wallet.EstimationMode instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.IsValid instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.DetailedTransaction instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.DetailedTransactionDetails instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.SinceBlock instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.SimpleTransaction instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.TransactionCategory instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.ReceivedByAccount instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.ReceivedByAddress instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.AddressInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Wallet.BitcoindInfo -- | An interface to bitcoind's available mining RPC calls. The -- implementation of these functions can be found at -- https://github.com/bitcoin/bitcoin/blob/master/src/rpcmining.cpp. -- -- If any APIs are missing, patches are always welcome. If you look at -- the source of this module, you'll see that the interface code is -- trivial. -- -- Note that it is highly discouraged to use bitcoind for actual bitcoin -- mining. It uses the CPU for mining, which is much, much less power -- efficient than GPU mining. If you're paying for power, you will not -- come out ahead. -- -- Instead, consider using a GPU miner listed at -- https://en.bitcoin.it/wiki/Software#Mining_apps. module Network.Bitcoin.Mining -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | Returns whether or not bitcoind is generating bitcoins. getGenerate :: Client -> IO Bool -- | Controls whether or not bitcoind is generating bitcoins. If bitcoind -- runs in regtest mode the number of generated hashes is returned. See -- https://bitcoin.org/en/developer-reference#setgenerate for more -- details. setGenerate :: Client -> Bool -> Maybe Int -> IO (Maybe [HexString]) -- | The generate RPC nearly instantly generates blocks. See -- https://bitcoin.org/en/developer-reference#generate for more -- details. generate :: Client -> Int -> Maybe Int -> IO [HexString] -- | The generatetoaddress RPC mines blocks immediately to a specified -- address. See -- https://bitcoin.org/en/developer-reference#generatetoaddress -- for more details. generateToAddress :: Client -> Int -> Address -> Maybe Int -> IO [HexString] -- | Returns a recent hashes per second performance measurement while -- generating. getHashesPerSec :: Client -> IO Integer -- | Information related to the current bitcoind mining operation. -- -- If a field is undocumented here, it's because I don't know what it -- means. If you DO know what it means, I'd love it if you would submit a -- patch to help complete this documentation. data MiningInfo MiningInfo :: Integer -> Integer -> Integer -> Double -> Text -> Bool -> Integer -> Integer -> Integer -> Bool -> MiningInfo -- | The number of blocks in our block-chain. [nBlocks] :: MiningInfo -> Integer -- | The size of the current block we're mining. [currentBlockSize] :: MiningInfo -> Integer [currentBlockTransaction] :: MiningInfo -> Integer -- | How difficult mining currently is. [difficulty] :: MiningInfo -> Double -- | Any mining errors that may have come up. [miningErrors] :: MiningInfo -> Text -- | Are we currently generating bitcoins? [isGenerating] :: MiningInfo -> Bool -- | How many processors have we limited bitcoin mining to? [generationProcessorLimit] :: MiningInfo -> Integer -- | How fast is the mining going? [hashesPerSecond] :: MiningInfo -> Integer [pooledTransactions] :: MiningInfo -> Integer -- | Are we on the bitcoin test network (as opposed to the real thing)? [miningOnTestNetwork] :: MiningInfo -> Bool -- | Returns an object containing mining-related information. getMiningInfo :: Client -> IO MiningInfo -- | The hash data returned from getWork. data HashData HashData :: HexString -> HexString -> HexString -> HexString -> HashData [blockData] :: HashData -> HexString -- | Little-endian hash target, formatted as a hexadecimal string. [hdTarget] :: HashData -> HexString [hash1] :: HashData -> HexString [midstate] :: HashData -> HexString -- | Returns formatted hash data to work on. getWork :: Client -> IO HashData -- | Tries to solve the given block, and returns true if it was successful. solveBlock :: Client -> HexString -> IO Bool -- | A transaction to be included in the next block. data Transaction Transaction :: HexString -> HexString -> Vector Integer -> Maybe Integer -> Integer -> Transaction [txnData] :: Transaction -> HexString [txnHash] :: Transaction -> HexString [depends] :: Transaction -> Vector Integer [txnFee] :: Transaction -> Maybe Integer [sigOps] :: Transaction -> Integer newtype CoinBaseAux CoinBaseAux :: HexString -> CoinBaseAux [cbFlags] :: CoinBaseAux -> HexString -- | A template for constructing a block to work on. -- -- See https://en.bitcoin.it/wiki/BIP_0022 for the full -- specification. data BlockTemplate BlockTemplate :: Integer -> HexString -> Vector Transaction -> CoinBaseAux -> Integer -> HexString -> Integer -> HexString -> Integer -> Integer -> Integer -> HexString -> Integer -> BlockTemplate [blockVersion] :: BlockTemplate -> Integer -- | Hash of current highest block. [previousBlockHash] :: BlockTemplate -> HexString -- | Contents of non-coinbase transactions that should be included in the -- next block. [transactionsToInclude] :: BlockTemplate -> Vector Transaction -- | Data that should be included in coinbase. [coinBaseAux] :: BlockTemplate -> CoinBaseAux -- | Maximum allowable input to coinbase transaction, including the -- generation award and transaction fees. [coinBaseValue] :: BlockTemplate -> Integer -- | Hash target. [btTarget] :: BlockTemplate -> HexString -- | Minimum timestamp appropriate for next block. [minTime] :: BlockTemplate -> Integer -- | Range of valid nonces. [nonceRange] :: BlockTemplate -> HexString -- | Limit of sigops in blocks. [sigopLimit] :: BlockTemplate -> Integer -- | Limit of block size. [sizeLimit] :: BlockTemplate -> Integer -- | Current timestamp. [curTime] :: BlockTemplate -> Integer -- | Compressed target of the next block. [btBits] :: BlockTemplate -> HexString -- | Height of the next block. [btHeight] :: BlockTemplate -> Integer -- | Returns data needed to construct a block to work on. getBlockTemplate :: Client -> IO BlockTemplate -- | Attempts to submit a new block to the network. submitBlock :: Client -> HexString -> IO Bool instance GHC.Classes.Eq Network.Bitcoin.Mining.BlockTemplate instance GHC.Classes.Ord Network.Bitcoin.Mining.BlockTemplate instance GHC.Read.Read Network.Bitcoin.Mining.BlockTemplate instance GHC.Show.Show Network.Bitcoin.Mining.BlockTemplate instance GHC.Classes.Eq Network.Bitcoin.Mining.CoinBaseAux instance GHC.Classes.Ord Network.Bitcoin.Mining.CoinBaseAux instance GHC.Read.Read Network.Bitcoin.Mining.CoinBaseAux instance GHC.Show.Show Network.Bitcoin.Mining.CoinBaseAux instance GHC.Classes.Eq Network.Bitcoin.Mining.Transaction instance GHC.Classes.Ord Network.Bitcoin.Mining.Transaction instance GHC.Read.Read Network.Bitcoin.Mining.Transaction instance GHC.Show.Show Network.Bitcoin.Mining.Transaction instance GHC.Classes.Eq Network.Bitcoin.Mining.HashData instance GHC.Classes.Ord Network.Bitcoin.Mining.HashData instance GHC.Read.Read Network.Bitcoin.Mining.HashData instance GHC.Show.Show Network.Bitcoin.Mining.HashData instance GHC.Classes.Eq Network.Bitcoin.Mining.MiningInfo instance GHC.Classes.Ord Network.Bitcoin.Mining.MiningInfo instance GHC.Read.Read Network.Bitcoin.Mining.MiningInfo instance GHC.Show.Show Network.Bitcoin.Mining.MiningInfo instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.StupidReturnValue instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.BlockTemplate instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.CoinBaseAux instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.Transaction instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.HashData instance Data.Aeson.Types.ToJSON.ToJSON Network.Bitcoin.Mining.HashData instance Data.Aeson.Types.FromJSON.FromJSON Network.Bitcoin.Mining.MiningInfo -- | A Haskell binding to the bitcoind server. module Network.Bitcoin -- | Client describes authentication credentials and host info for -- making API requests to the Bitcoin daemon. type Client = ByteString -> IO ByteString -- | getClient takes a url, rpc username, and rpc password and -- returns a Client that can be used to make API calls. Each Client -- encloses a Manager (from http-client) that re-uses connections for -- requests, so long as the same Client is is used for each call. getClient :: String -> ByteString -> ByteString -> IO Client -- | A BitcoinException is thrown when 'callApi encounters an error. -- The API error code is represented as an Int, the message as a -- String. -- -- It may also be thrown when the value returned by the bitcoin API -- wasn't what we expected. -- -- WARNING: Any of the functions in this module's public API may throw -- this exception. You should plan on handling it. data BitcoinException -- | A BitcoinApiError has an error code error message, as returned -- by bitcoind's JSON-RPC response. BitcoinApiError :: Int -> Text -> BitcoinException -- | The raw JSON returned, if we can't figure out what actually went -- wrong. BitcoinResultTypeError :: ByteString -> BitcoinException -- | A string returned by the bitcoind API, representing data as hex. -- -- What that data represents depends on the API call, but should be -- dcumented accordingly. type HexString = Text -- | A hexadecimal string representation of a 256-bit unsigned integer. -- -- This integer is a unique transaction identifier. type TransactionID = HexString -- | A satoshi is the smallest subdivision of bitcoins. For the resolution, -- use resolution from Fixed. data Satoshi Satoshi :: Satoshi -- | The type of bitcoin money, represented with a fixed-point number. type BTC = Fixed Satoshi -- | An account on the wallet is just a label to easily specify private -- keys. -- -- The default account is an empty string. type Account = Text -- | An address for sending or receiving money. type Address = HexString -- | A script signature. data ScriptSig -- | Returns the number of blocks in the longest block chain. getBlockCount :: Client -> IO BlockHeight -- | Returns the proof-of-work difficulty as a multiple of the minimum -- difficulty. getDifficulty :: Client -> IO Integer -- | Sets the transaction fee will will pay to the network. Values of 0 are -- rejected. setTransactionFee :: Client -> BTC -> IO () -- | Returns all transaction identifiers in the memory pool. getRawMemoryPool :: Client -> IO (Vector TransactionID) -- | The hash of a given block. type BlockHash = HexString -- | Returns the hash of the block in best-block-chain at the given index. getBlockHash :: Client -> BlockHeight -> IO BlockHash -- | Information about a given block in the block chain. data Block Block :: BlockHash -> Integer -> Integer -> BlockHeight -> Integer -> BlockHash -> Vector TransactionID -> Integer -> Integer -> HexString -> Double -> Maybe BlockHash -> Maybe BlockHash -> Block [blockHash] :: Block -> BlockHash -- | The number of confirmations the block has. [blkConfirmations] :: Block -> Integer -- | The size of the block. [blkSize] :: Block -> Integer -- | The "height" of the block. TODO: Clarify this. [blkHeight] :: Block -> BlockHeight -- | The version of the block. [blkVersion] :: Block -> Integer -- | The hash of the block at the root of the merkle tree which this block -- belongs to. [merkleRoot] :: Block -> BlockHash -- | Should this be a transaction, or transaction id? [subTransactions] :: Block -> Vector TransactionID -- | The time it was mined. [blkTime] :: Block -> Integer -- | The block's nonce. [blkNonce] :: Block -> Integer [blkBits] :: Block -> HexString -- | How hard was this block to mine? [blkDifficulty] :: Block -> Double -- | A pointer to the next block in the chain. [nextBlock] :: Block -> Maybe BlockHash -- | A pointer to the previous block in the chain. [prevBlock] :: Block -> Maybe BlockHash -- | Returns details of a block with given block-hash. getBlock :: Client -> BlockHash -> IO Block -- | Information on the unspent transaction in the output set. data OutputSetInfo OutputSetInfo :: BlockHash -> BlockHeight -> Integer -> Integer -> Integer -> OutputSetInfo [osiBestBlock] :: OutputSetInfo -> BlockHash -- | The height of the best block chain [osiHeight] :: OutputSetInfo -> BlockHeight -- | The number of transactions in the output set. [numTransactions] :: OutputSetInfo -> Integer -- | The number of outputs for the transactions. [transactionOutputs] :: OutputSetInfo -> Integer -- | The serialized size of the output set. [serializedSize] :: OutputSetInfo -> Integer -- | Returns statistics about the unspent transaction output set. getOutputSetInfo :: Client -> IO OutputSetInfo -- | Details about an unspent transaction output. data OutputInfo OutputInfo :: BlockHash -> Integer -> BTC -> ScriptPubKey -> Maybe Integer -> Bool -> OutputInfo [oiBestBlock] :: OutputInfo -> BlockHash -- | The number of times this transaction has been confirmed. [oiConfirmations] :: OutputInfo -> Integer -- | The amount transferred. [oiAmount] :: OutputInfo -> BTC -- | The public key of the sender. [oiScriptPubKey] :: OutputInfo -> ScriptPubKey -- | The version of this transaction. [oiVersion] :: OutputInfo -> Maybe Integer -- | Is this transaction part of the coin base? [oiCoinBase] :: OutputInfo -> Bool -- | Returns details about an unspent transaction output. getOutputInfo :: Client -> TransactionID -> Integer -> IO (Maybe OutputInfo) -- | Adds a private key (as returned by dumpprivkey) to your wallet. importPrivateKey :: Client -> PrivateKey -> Maybe Account -> IO () -- | Reveals the private key corresponding to the given address. dumpPrivateKey :: Client -> Address -> IO PrivateKey -- | The generate RPC nearly instantly generates blocks. See -- https://bitcoin.org/en/developer-reference#generate for more -- details. generate :: Client -> Int -> Maybe Int -> IO [HexString] -- | The generatetoaddress RPC mines blocks immediately to a specified -- address. See -- https://bitcoin.org/en/developer-reference#generatetoaddress -- for more details. generateToAddress :: Client -> Int -> Address -> Maybe Int -> IO [HexString] -- | Returns whether or not bitcoind is generating bitcoins. getGenerate :: Client -> IO Bool -- | Controls whether or not bitcoind is generating bitcoins. If bitcoind -- runs in regtest mode the number of generated hashes is returned. See -- https://bitcoin.org/en/developer-reference#setgenerate for more -- details. setGenerate :: Client -> Bool -> Maybe Int -> IO (Maybe [HexString]) -- | Returns a recent hashes per second performance measurement while -- generating. getHashesPerSec :: Client -> IO Integer -- | Information related to the current bitcoind mining operation. -- -- If a field is undocumented here, it's because I don't know what it -- means. If you DO know what it means, I'd love it if you would submit a -- patch to help complete this documentation. data MiningInfo MiningInfo :: Integer -> Integer -> Integer -> Double -> Text -> Bool -> Integer -> Integer -> Integer -> Bool -> MiningInfo -- | The number of blocks in our block-chain. [nBlocks] :: MiningInfo -> Integer -- | The size of the current block we're mining. [currentBlockSize] :: MiningInfo -> Integer [currentBlockTransaction] :: MiningInfo -> Integer -- | How difficult mining currently is. [difficulty] :: MiningInfo -> Double -- | Any mining errors that may have come up. [miningErrors] :: MiningInfo -> Text -- | Are we currently generating bitcoins? [isGenerating] :: MiningInfo -> Bool -- | How many processors have we limited bitcoin mining to? [generationProcessorLimit] :: MiningInfo -> Integer -- | How fast is the mining going? [hashesPerSecond] :: MiningInfo -> Integer [pooledTransactions] :: MiningInfo -> Integer -- | Are we on the bitcoin test network (as opposed to the real thing)? [miningOnTestNetwork] :: MiningInfo -> Bool -- | Returns an object containing mining-related information. getMiningInfo :: Client -> IO MiningInfo -- | The hash data returned from getWork. data HashData HashData :: HexString -> HexString -> HexString -> HexString -> HashData [blockData] :: HashData -> HexString -- | Little-endian hash target, formatted as a hexadecimal string. [hdTarget] :: HashData -> HexString [hash1] :: HashData -> HexString [midstate] :: HashData -> HexString -- | Returns formatted hash data to work on. getWork :: Client -> IO HashData -- | Tries to solve the given block, and returns true if it was successful. solveBlock :: Client -> HexString -> IO Bool -- | A transaction to be included in the next block. data Transaction Transaction :: HexString -> HexString -> Vector Integer -> Maybe Integer -> Integer -> Transaction [txnData] :: Transaction -> HexString [txnHash] :: Transaction -> HexString [depends] :: Transaction -> Vector Integer [txnFee] :: Transaction -> Maybe Integer [sigOps] :: Transaction -> Integer newtype CoinBaseAux CoinBaseAux :: HexString -> CoinBaseAux [cbFlags] :: CoinBaseAux -> HexString -- | A template for constructing a block to work on. -- -- See https://en.bitcoin.it/wiki/BIP_0022 for the full -- specification. data BlockTemplate BlockTemplate :: Integer -> HexString -> Vector Transaction -> CoinBaseAux -> Integer -> HexString -> Integer -> HexString -> Integer -> Integer -> Integer -> HexString -> Integer -> BlockTemplate [blockVersion] :: BlockTemplate -> Integer -- | Hash of current highest block. [previousBlockHash] :: BlockTemplate -> HexString -- | Contents of non-coinbase transactions that should be included in the -- next block. [transactionsToInclude] :: BlockTemplate -> Vector Transaction -- | Data that should be included in coinbase. [coinBaseAux] :: BlockTemplate -> CoinBaseAux -- | Maximum allowable input to coinbase transaction, including the -- generation award and transaction fees. [coinBaseValue] :: BlockTemplate -> Integer -- | Hash target. [btTarget] :: BlockTemplate -> HexString -- | Minimum timestamp appropriate for next block. [minTime] :: BlockTemplate -> Integer -- | Range of valid nonces. [nonceRange] :: BlockTemplate -> HexString -- | Limit of sigops in blocks. [sigopLimit] :: BlockTemplate -> Integer -- | Limit of block size. [sizeLimit] :: BlockTemplate -> Integer -- | Current timestamp. [curTime] :: BlockTemplate -> Integer -- | Compressed target of the next block. [btBits] :: BlockTemplate -> HexString -- | Height of the next block. [btHeight] :: BlockTemplate -> Integer -- | Returns data needed to construct a block to work on. getBlockTemplate :: Client -> IO BlockTemplate -- | Attempts to submit a new block to the network. submitBlock :: Client -> HexString -> IO Bool -- | Returns the number of connections to other nodes. getConnectionCount :: Client -> IO Integer -- | Information about a peer node of the Bitcoin network. -- -- The documentation for this data structure is incomplete, as I honestly -- don't know what some of these fields are for. Patches are welcome! data PeerInfo PeerInfo :: Text -> Text -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Text -> Bool -> Integer -> Integer -> PeerInfo -- | The IP:port of this peer, as a string. [addressName] :: PeerInfo -> Text [services] :: PeerInfo -> Text -- | Relative to the first time we conected with this peer (and in -- milliseconds), the last time we sent this peer any data. [lastSend] :: PeerInfo -> Integer -- | Relative to the first time we connected with this peer (and in -- milliseconds), the last time we sent this peer any data. [lastRecv] :: PeerInfo -> Integer [bytesSent] :: PeerInfo -> Integer [bytesRecv] :: PeerInfo -> Integer -- | How long have we been connected to this peer (in milliseconds). [connectionTime] :: PeerInfo -> Integer -- | The version of the Bitcion client the peer is running. [peerVersion] :: PeerInfo -> Integer -- | The sub-version of the Bitcoin client the peer is running. [peerSubversion] :: PeerInfo -> Text [inbound] :: PeerInfo -> Bool [startingHeight] :: PeerInfo -> Integer -- | How many times has this peer behaved badly? [banScore] :: PeerInfo -> Integer -- | Returns data about all connected peer nodes. getPeerInfo :: Client -> IO [PeerInfo] data AddNodeCommand Add :: AddNodeCommand Remove :: AddNodeCommand OneTry :: AddNodeCommand addNode :: Client -> Text -> AddNodeCommand -> IO () disconnectNode :: Client -> Maybe Text -> Maybe Int -> IO () -- | Just like most binary data retrieved from bitcoind, a raw transaction -- is represented by a hexstring. -- -- This is a serialized, hex-encoded transaction. type RawTransaction = HexString -- | Get a raw transaction from its unique ID. getRawTransaction :: Client -> TransactionID -> IO RawTransaction -- | A transaction into an account. This can either be a coinbase -- transaction, or a standard transaction with another account. data TxIn TxCoinbase :: HexString -> TxIn [txCoinbase] :: TxIn -> HexString TxIn :: TransactionID -> Integer -> ScriptSig -> Integer -> TxIn -- | This transaction's ID. [txInId] :: TxIn -> TransactionID [numOut] :: TxIn -> Integer [scriptSig] :: TxIn -> ScriptSig -- | A transaction sequence number. [txSequence] :: TxIn -> Integer -- | The type of a transaction out. -- -- More documentation is needed here. Submit a patch if you know what -- this is about! data TxnOutputType -- | JSON of "pubkey" received. TxnPubKey :: TxnOutputType -- | JSON of "pubkeyhash" received. TxnPubKeyHash :: TxnOutputType -- | JSON of "scripthash" received. TxnScriptHash :: TxnOutputType -- | JSON of "multisig" received. TxnMultisig :: TxnOutputType -- | A public key of someone we sent money to. data ScriptPubKey NonStandardScriptPubKey :: HexString -> HexString -> ScriptPubKey -- | The JSON "asm" field. [nspkAsm] :: ScriptPubKey -> HexString -- | The JSON "hex" field. [nspkHex] :: ScriptPubKey -> HexString StandardScriptPubKey :: HexString -> HexString -> Integer -> TxnOutputType -> Vector Address -> ScriptPubKey -- | The JSON "asm" field. [sspkAsm] :: ScriptPubKey -> HexString -- | The JSON "hex" field. [sspkHex] :: ScriptPubKey -> HexString -- | The number of required signatures. [requiredSigs] :: ScriptPubKey -> Integer -- | The type of the transaction. [sspkType] :: ScriptPubKey -> TxnOutputType -- | The addresses associated with this key. [sspkAddresses] :: ScriptPubKey -> Vector Address -- | A transaction out of an account. data TxOut TxOut :: BTC -> ScriptPubKey -> TxOut -- | The amount of bitcoin transferred out. [txoutVal] :: TxOut -> BTC -- | The public key of the account we sent the money to. [scriptPubKey] :: TxOut -> ScriptPubKey -- | Information on a single block. data BlockInfo ConfirmedBlock :: Integer -> Integer -> Integer -> BlockInfo -- | The number of confirmations a block has. This will always be >= 1. [confirmations] :: BlockInfo -> Integer [cbTime] :: BlockInfo -> Integer -- | The JSON "blocktime" field. [blockTime] :: BlockInfo -> Integer -- | An unconfirmed block is boring, but a possibility. UnconfirmedBlock :: BlockInfo -- | The raw transaction info for a given transaction ID. data RawTransactionInfo RawTransactionInfo :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> HexString -> BlockInfo -> RawTransactionInfo -- | The raw transaction. [raw] :: RawTransactionInfo -> RawTransaction -- | The transaction version number. [txnVersion] :: RawTransactionInfo -> Integer [txnLockTime] :: RawTransactionInfo -> Integer -- | The vector of transactions in. [vin] :: RawTransactionInfo -> Vector TxIn -- | The vector of transactions out. [vout] :: RawTransactionInfo -> Vector TxOut -- | The hash of the block that was used for this transaction. [rawTxBlockHash] :: RawTransactionInfo -> HexString -- | The transaction's block's info. [rawBlockInfo] :: RawTransactionInfo -> BlockInfo -- | Get raw transaction info for a given transaction ID. The data -- structure returned is quite sprawling and undocumented, so any patches -- to help simplify things would be greatly appreciated. getRawTransactionInfo :: Client -> TransactionID -> IO RawTransactionInfo data UnspentTransaction UnspentTransaction :: TransactionID -> Integer -> Address -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction [unspentTransactionId] :: UnspentTransaction -> TransactionID [outIdx] :: UnspentTransaction -> Integer [unspentAddress] :: UnspentTransaction -> Address [unspentScriptPubKey] :: UnspentTransaction -> HexString [redeemScript] :: UnspentTransaction -> Maybe HexString [unspentAmount] :: UnspentTransaction -> BTC [usConfirmations] :: UnspentTransaction -> Integer -- | Returns an array of unspent transaction outputs with between minconf -- and maxconf (inclusive) confirmations. If addresses are given, the -- result will be filtered to include only those addresses. listUnspent :: Client -> Maybe Int -> Maybe Int -> Vector Address -> IO (Vector UnspentTransaction) -- | Create a transaction spending given inputs, sending to given -- addresses. -- -- Note that the transaction's inputs are not signed, and it is not -- stored in the wallet or transmitted to the network. -- -- Also, there is no checking to see if it's possible to send that much -- to the targets specified. In the future, such a scenario might throw -- an exception. createRawTransaction :: Client -> Vector UnspentTransaction -> Vector (Address, BTC) -> IO HexString -- | A successfully decoded raw transaction, from a given serialized, -- hex-encoded transaction. data DecodedRawTransaction DecodedRawTransaction :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> DecodedRawTransaction -- | The raw transaction. [decRaw] :: DecodedRawTransaction -> RawTransaction -- | The transaction version number. [decTxnVersion] :: DecodedRawTransaction -> Integer [decTxnLockTime] :: DecodedRawTransaction -> Integer -- | The vector of transactions in. [decVin] :: DecodedRawTransaction -> Vector TxIn -- | The vector of transactions out. [decVout] :: DecodedRawTransaction -> Vector TxOut -- | Decodes a raw transaction into a more accessible data structure. decodeRawTransaction :: Client -> RawTransaction -> IO DecodedRawTransaction -- | Who can pay for a given transaction. data WhoCanPay All :: WhoCanPay AllOrAnyoneCanPay :: WhoCanPay None :: WhoCanPay NoneOrAnyoneCanPay :: WhoCanPay Single :: WhoCanPay SingleOrAnyoneCanPay :: WhoCanPay -- | A raw signed transaction contains the raw, signed hexstring and -- whether or not this transaction has a complete signature set. data RawSignedTransaction RawSignedTransaction :: HexString -> Bool -> RawSignedTransaction [rawSigned] :: RawSignedTransaction -> HexString [hasCompleteSigSet] :: RawSignedTransaction -> Bool -- | Sign inputs for a raw transaction. signRawTransaction :: Client -> RawTransaction -> Maybe (Vector UnspentTransaction) -> Maybe (Vector HexString) -> Maybe WhoCanPay -> IO RawSignedTransaction sendRawTransaction :: Client -> RawTransaction -> IO TransactionID -- | A plethora of information about a bitcoind instance. data BitcoindInfo BitcoindInfo :: Integer -> Integer -> Integer -> BTC -> Integer -> Integer -> Text -> Double -> Bool -> Integer -> Integer -> BTC -> Maybe Integer -> Text -> BitcoindInfo -- | What version of bitcoind are we running? [bitcoinVersion] :: BitcoindInfo -> Integer -- | What is bitcoind's current protocol number? [protocolVersion] :: BitcoindInfo -> Integer -- | What version is the wallet? [walletVersion] :: BitcoindInfo -> Integer -- | How much money is currently in the wallet? [balance] :: BitcoindInfo -> BTC -- | The number of blocks in our chain. [numBlocks] :: BitcoindInfo -> Integer -- | How many peers are we connected to? [numConnections] :: BitcoindInfo -> Integer -- | A blank string if we're not using a proxy. [proxy] :: BitcoindInfo -> Text -- | The difficulty multiplier for bitcoin mining operations. [generationDifficulty] :: BitcoindInfo -> Double -- | Are we on the test network (as opposed to the primary bitcoin -- network)? [onTestNetwork] :: BitcoindInfo -> Bool -- | The timestamp of the oldest key in the key pool. [keyPoolOldest] :: BitcoindInfo -> Integer -- | The size of the key pool. [keyPoolSize] :: BitcoindInfo -> Integer -- | How much do we currently pay as a transaction fee? [transactionFeePaid] :: BitcoindInfo -> BTC -- | If the wallet is unlocked, the number of seconds until a re-lock is -- needed. [unlockedUntil] :: BitcoindInfo -> Maybe Integer -- | Any alerts will show up here. This should normally be an empty string. [bitcoindErrors] :: BitcoindInfo -> Text -- | Returns an object containing various state info. -- -- Availability: < 0.16 getBitcoindInfo :: Client -> IO BitcoindInfo -- | Returns a new bitcoin address for receiving payments. -- -- If an account is specified (recommended), the new address is added to -- the address book so payments received with the address will be -- credited to the given account. -- -- If no account is specified, the address will be credited to the -- account whose name is the empty string. i.e. the default account. getNewAddress :: Client -> Maybe Account -> IO Address -- | Returns the current Bitcoin address for receiving payments to the -- given account. getAccountAddress :: Client -> Account -> IO Address -- | Returns the account associated with the given address. getAccount :: Client -> Address -> IO Account -- | Sets the account associated with the given address. setAccount :: Client -> Address -> Account -> IO () -- | Returns the list of addresses for the given address. getAddressesByAccount :: Client -> Account -> IO (Vector Address) -- | Sends some bitcoins to an address. sendToAddress :: Client -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID -- | Information on a given address. data AddressInfo AddressInfo :: Address -> BTC -> Maybe Account -> AddressInfo -- | The address in question. [aiAddress] :: AddressInfo -> Address -- | The address' balance. [aiAmount] :: AddressInfo -> BTC -- | The address' linked account. [aiAccount] :: AddressInfo -> Maybe Account -- | Lists groups of addresses which have had their common ownership made -- public by common use as inputs or as the resulting change in past -- transactions. listAddressGroupings :: Client -> IO (Vector (Vector AddressInfo)) -- | A signature is a base-64 encoded string. type Signature = HexString -- | Sign a message with the private key of an address. signMessage :: Client -> Address -> Text -> IO Signature -- | Verifies a signed message. verifyMessage :: Client -> Address -> Signature -> Text -> IO Bool -- | Returns the total amount received by the given address with at least -- one confirmation. getReceivedByAddress :: Client -> Address -> IO BTC -- | Returns the total amount received by the given address, with at least -- the give number of confirmations. getReceivedByAddress' :: Client -> Address -> Int -> IO BTC -- | Returns the total amount received by address with the given account. getReceivedByAccount :: Client -> Account -> IO BTC -- | Returns the total amount received by addresses with the given account, -- counting only transactions with the given minimum number of -- confirmations. getReceivedByAccount' :: Client -> Account -> Int -> IO BTC -- | Returns the server's total available balance. getBalance :: Client -> IO BTC -- | Returns the balance in the given account, counting only transactions -- with at least one confirmation. getBalance' :: Client -> Account -> IO BTC -- | Returns the balance in the given account, counting only transactions -- with at least the given number of confirmations. getBalance'' :: Client -> Account -> Int -> IO BTC -- | Move bitcoins from one account in your wallet to another. -- -- If you want to send bitcoins to an address not in your wallet, use -- sendFromAccount. moveBitcoins :: Client -> Account -> Account -> BTC -> Text -> IO () -- | Sends bitcoins from a given account in our wallet to a given address. -- -- A transaction and sender comment may be optionally provided. sendFromAccount :: Client -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID -- | Send to a whole bunch of address at once. sendMany :: Client -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID -- | Possible fee estimation modes data EstimationMode Economical :: EstimationMode Conservative :: EstimationMode -- | Estimate the fee per kb to send a transaction estimateSmartFee :: Client -> Word32 -> Maybe EstimationMode -> IO Double -- | Information on how much was received by a given address. data ReceivedByAddress ReceivedByAddress :: Address -> Account -> BTC -> Integer -> ReceivedByAddress -- | The address which the money was deposited to. [recvAddress] :: ReceivedByAddress -> Address -- | The account which this address belongs to. [recvAccount] :: ReceivedByAddress -> Account -- | The amount received. [recvAmount] :: ReceivedByAddress -> BTC -- | The number of confirmations of the most recent included transaction. [recvNumConfirmations] :: ReceivedByAddress -> Integer -- | Lists the amount received by each address which has received money at -- some point, counting only transactions with at least one confirmation. listReceivedByAddress :: Client -> IO (Vector ReceivedByAddress) -- | List the amount received by each of our addresses, counting only -- transactions with the given minimum number of confirmations. listReceivedByAddress' :: Client -> Int -> Bool -> IO (Vector ReceivedByAddress) data ReceivedByAccount ReceivedByAccount :: Account -> BTC -> Integer -> ReceivedByAccount -- | The account we received into. [raccAccount] :: ReceivedByAccount -> Account -- | The mount received. ^ The number of confirmations of the most recent -- included transaction. [raccAmount] :: ReceivedByAccount -> BTC [raccNumConfirmations] :: ReceivedByAccount -> Integer -- | Lists the amount received by each account which has received money at -- some point, counting only transactions with at leaset one -- confirmation. listReceivedByAccount :: Client -> IO (Vector ReceivedByAccount) -- | List the amount received by each of our accounts, counting only -- transactions with the given minimum number of confirmations. listReceivedByAccount' :: Client -> Int -> Bool -> IO (Vector ReceivedByAccount) -- | Returns transactions from the blockchain. listTransactions :: Client -> Account -> Int -> Int -> IO (Vector SimpleTransaction) -- | Returns transactions from the blockchain. listTransactions' :: Client -> Maybe Account -> Maybe Int -> Maybe Int -> IO (Vector SimpleTransaction) -- | List accounts and their current balance. listAccounts :: Client -> Maybe Int -> IO (HashMap Account BTC) -- | Import an address importAddress :: Client -> Address -> Maybe Account -> Maybe Bool -> IO () data SinceBlock SinceBlock :: Vector SimpleTransaction -> BlockHash -> SinceBlock [strransactions] :: SinceBlock -> Vector SimpleTransaction [sbLastBlockHash] :: SinceBlock -> BlockHash -- | 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 :: Account -> Maybe Address -> TransactionCategory -> Maybe BTC -> BTC -> Maybe Integer -> Maybe BlockHash -> Maybe Integer -> Maybe POSIXTime -> Maybe TransactionID -> Maybe (Vector TransactionID) -> POSIXTime -> Maybe POSIXTime -> Maybe Text -> Maybe Text -> Maybe Account -> SimpleTransaction -- | The account name associated with the transaction. The empty string is -- the default account. [stReceivingAccount] :: SimpleTransaction -> Account -- | The bitcoin address of the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [stAddress] :: SimpleTransaction -> Maybe Address -- | The category of the transaction [stCategory] :: SimpleTransaction -> TransactionCategory -- | The fees paid to process the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [stFee] :: SimpleTransaction -> Maybe BTC -- | The amount of bitcoins transferred. [stAmount] :: SimpleTransaction -> BTC -- | The number of confirmations of the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [stConfirmations] :: SimpleTransaction -> Maybe Integer -- | The hash of the block containing the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [stBlockHash] :: SimpleTransaction -> Maybe BlockHash -- | The index of the the block containing the transaction. Is -- Nothing unless trCategory is TCSend or -- TCReceive. [stBlockIndex] :: SimpleTransaction -> Maybe Integer -- | The block time in seconds since epoch (1 Jan 1970 GMT). Is -- Nothing unless trCategory is TCSend or -- TCReceive. [stBlockTime] :: SimpleTransaction -> Maybe POSIXTime -- | The transaction id. Is Nothing unless trCategory is -- TCSend or TCReceive. [stTransactionId] :: SimpleTransaction -> 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] :: SimpleTransaction -> Maybe (Vector TransactionID) -- | The block time in seconds since epoch (1 Jan 1970 GMT). [stTime] :: SimpleTransaction -> POSIXTime [stTimeReceived] :: SimpleTransaction -> Maybe POSIXTime -- | Is Nothing unless a comment is associated with the transaction. [stComment] :: SimpleTransaction -> Maybe Text -- | Is Nothing unless a "to" is associated with the transaction. [stTo] :: SimpleTransaction -> 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] :: SimpleTransaction -> Maybe Account data TransactionCategory TCSend :: TransactionCategory TCOrphan :: TransactionCategory TCImmature :: TransactionCategory TCGenerate :: TransactionCategory TCReceive :: TransactionCategory TCMove :: TransactionCategory TCErrorUnexpected :: Text -> TransactionCategory -- | Gets all transactions in blocks since the given block. listSinceBlock :: Client -> BlockHash -> Maybe Int -> IO SinceBlock -- | Gets all transactions in blocks since the given block, or all -- transactions if ommited. listSinceBlock' :: Client -> Maybe BlockHash -> Maybe Int -> IO SinceBlock -- | 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 :: BTC -> Maybe BTC -> Maybe Integer -> Maybe TransactionID -> Maybe (Vector TransactionID) -> POSIXTime -> Maybe POSIXTime -> Maybe Text -> Maybe Text -> Vector DetailedTransactionDetails -> RawTransaction -> DetailedTransaction -- | The amount of bitcoins transferred. [dtAmount] :: DetailedTransaction -> BTC -- | The fees paid to process the transaction. Is Nothing unless -- trCategory is TCSend or TCReceive. [dtFee] :: DetailedTransaction -> Maybe BTC -- | The number of confirmations of the transaction. Is Nothing -- unless trCategory is TCSend or TCReceive. [dtConfirmations] :: DetailedTransaction -> Maybe Integer -- | The transaction id. Is Nothing unless trCategory is -- TCSend or TCReceive. [dtTransactionId] :: DetailedTransaction -> 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] :: DetailedTransaction -> Maybe (Vector TransactionID) -- | The block time in seconds since epoch (1 Jan 1970 GMT). [dtTime] :: DetailedTransaction -> POSIXTime [dtTimeReceived] :: DetailedTransaction -> Maybe POSIXTime -- | Is Nothing unless a comment is associated with the transaction. [dtComment] :: DetailedTransaction -> Maybe Text -- | Is Nothing unless a "to" is associated with the transaction. [dtTo] :: DetailedTransaction -> Maybe Text -- | The details of the transaction. [dtDetails] :: DetailedTransaction -> Vector DetailedTransactionDetails -- | Raw data for the transaction. [dtHex] :: DetailedTransaction -> RawTransaction data DetailedTransactionDetails DetailedTransactionDetails :: Account -> Address -> TransactionCategory -> BTC -> DetailedTransactionDetails -- | The account name associated with the transaction. The empty string is -- the default account. [dtdReceivingAccount] :: DetailedTransactionDetails -> Account -- | The bitcoin address of the transaction. [dtdAddress] :: DetailedTransactionDetails -> Address -- | The category of the transaction [dtdCategory] :: DetailedTransactionDetails -> TransactionCategory -- | The amount of bitcoins transferred. [dtdAmount] :: DetailedTransactionDetails -> BTC getTransaction :: Client -> TransactionID -> IO DetailedTransaction -- | Safely copies wallet.dat to the given destination, which can be either -- a directory, or a path with filename. backupWallet :: Client -> FilePath -> IO () -- | Fills the keypool. keyPoolRefill :: Client -> IO () -- | Stores the wallet decryption key in memory for the given amount of -- time. unlockWallet :: Client -> Text -> Integer -> IO () -- | Removes the wallet encryption key from memory, locking the wallet. -- -- After calling this function, you will need to call unlockWallet -- again before being able to call methods which require the wallet to be -- unlocked. -- -- Note: In future releases, we might introduce an "unlocked" monad, so -- locking and unlocking is automatic. lockWallet :: Client -> IO () -- | Changes the wallet passphrase. changePassword :: Client -> Text -> Text -> IO () -- | Encrypts the wallet with the given passphrase. -- -- WARNING: bitcoind will shut down after calling this method. Don't say -- I didn't warn you. encryptWallet :: Client -> Text -> IO () -- | Checks if a given address is a valid one. isAddressValid :: Client -> Address -> IO Bool