Safe Haskell | None |
---|
A Haskell binding to the bitcoind server.
- data Auth = Auth {}
- data BitcoinException
- type HexString = Text
- type TransactionID = HexString
- data Satoshi = Satoshi
- type BTC = Fixed Satoshi
- type Account = Text
- type Address = HexString
- data ScriptSig
- getBlockCount :: Auth -> IO Integer
- getDifficulty :: Auth -> IO Integer
- setTransactionFee :: Auth -> BTC -> IO ()
- getRawMemoryPool :: Auth -> IO (Vector TransactionID)
- type BlockHash = HexString
- getBlockHash :: Auth -> Integer -> IO BlockHash
- data Block = Block {
- blockHash :: BlockHash
- blkConfirmations :: Integer
- blkSize :: Integer
- blkHeight :: Integer
- blkVersion :: Integer
- merkleRoot :: BlockHash
- subTransactions :: Vector TransactionID
- blkTime :: Integer
- blkNonce :: Integer
- blkBits :: HexString
- blkDifficulty :: Integer
- nextBlock :: Maybe BlockHash
- prevBlock :: Maybe BlockHash
- getBlock :: Auth -> BlockHash -> IO Block
- data OutputSetInfo = OutputSetInfo {}
- getOutputSetInfo :: Auth -> IO OutputSetInfo
- data OutputInfo = OutputInfo {}
- getOutputInfo :: Auth -> TransactionID -> Integer -> IO OutputInfo
- importPrivateKey :: Auth -> PrivateKey -> Maybe Account -> IO ()
- dumpPrivateKey :: Auth -> Address -> IO PrivateKey
- getGenerate :: Auth -> IO Bool
- setGenerate :: Auth -> Bool -> Maybe Int -> IO ()
- getHashesPerSec :: Auth -> IO Integer
- data MiningInfo = MiningInfo {}
- getMiningInfo :: Auth -> IO MiningInfo
- data HashData = HashData {}
- getWork :: Auth -> IO HashData
- solveBlock :: Auth -> HexString -> IO Bool
- data Transaction = Transaction {}
- data CoinBaseAux = CoinBaseAux {}
- data BlockTemplate = BlockTemplate {
- blockVersion :: Integer
- previousBlockHash :: HexString
- transactionsToInclude :: Vector Transaction
- coinBaseAux :: CoinBaseAux
- coinBaseValue :: Integer
- btTarget :: HexString
- minTime :: Integer
- nonceRange :: HexString
- sigopLimit :: Integer
- sizeLimit :: Integer
- curTime :: Integer
- btBits :: HexString
- btHeight :: Integer
- getBlockTemplate :: Auth -> IO BlockTemplate
- submitBlock :: Auth -> HexString -> IO Bool
- getConnectionCount :: Auth -> IO Integer
- data PeerInfo = PeerInfo {}
- getPeerInfo :: Auth -> IO PeerInfo
- type RawTransaction = HexString
- getRawTransaction :: Auth -> TransactionID -> IO RawTransaction
- data TxIn
- = TxCoinbase { }
- | TxIn { }
- data TxnOutputType
- data ScriptPubKey
- data TxOut = TxOut {}
- data BlockInfo
- = ConfirmedBlock { }
- | UnconfirmedBlock
- data RawTransactionInfo = RawTransactionInfo {}
- getRawTransactionInfo :: Auth -> TransactionID -> IO RawTransactionInfo
- data UnspentTransaction = UnspentTransaction {}
- listUnspent :: Auth -> Maybe Int -> Maybe Int -> Vector Address -> IO (Vector UnspentTransaction)
- createRawTransaction :: Auth -> Vector UnspentTransaction -> Vector (Address, BTC) -> IO HexString
- data DecodedRawTransaction = DecodedRawTransaction {}
- decodeRawTransaction :: Auth -> RawTransaction -> IO DecodedRawTransaction
- data WhoCanPay
- = All
- | AllOrAnyoneCanPay
- | None
- | NoneOrAnyoneCanPay
- | Single
- | SingleOrAnyoneCanPay
- data RawSignedTransaction = RawSignedTransaction {}
- signRawTransaction :: Auth -> RawTransaction -> Maybe (Vector UnspentTransaction) -> Maybe (Vector HexString) -> Maybe WhoCanPay -> IO RawSignedTransaction
- sendRawTransaction :: Auth -> RawTransaction -> IO TransactionID
- data BitcoindInfo = BitcoindInfo {
- bitcoinVersion :: Integer
- protocolVersion :: Integer
- walletVersion :: Integer
- balance :: BTC
- numBlocks :: Integer
- numConnections :: Integer
- proxy :: Text
- generationDifficulty :: Double
- onTestNetwork :: Bool
- keyPoolOldest :: Integer
- keyPoolSize :: Integer
- transactionFeePaid :: BTC
- unlockedUntil :: Maybe Integer
- bitcoindErrors :: Text
- getBitcoindInfo :: Auth -> IO BitcoindInfo
- getNewAddress :: Auth -> Maybe Account -> IO Address
- getAccountAddress :: Auth -> Account -> IO Address
- getAccount :: Auth -> Address -> IO Account
- setAccount :: Auth -> Address -> Account -> IO ()
- getAddressByAccount :: Auth -> Account -> IO (Vector Address)
- sendToAddress :: Auth -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
- data AddressInfo = AddressInfo {}
- listAddressGroupings :: Auth -> IO (Vector (Vector AddressInfo))
- type Signature = HexString
- signMessage :: Auth -> Address -> Text -> IO Signature
- verifyMessage :: Auth -> Address -> Signature -> Text -> IO Bool
- getReceivedByAddress :: Auth -> Address -> IO BTC
- getReceivedByAddress' :: Auth -> Address -> Int -> IO BTC
- getReceivedByAccount :: Auth -> Account -> IO BTC
- getReceivedByAccount' :: Auth -> Account -> Int -> IO BTC
- getBalance :: Auth -> IO BTC
- getBalance' :: Auth -> Account -> IO BTC
- getBalance'' :: Auth -> Account -> Int -> IO BTC
- moveBitcoins :: Auth -> Account -> Account -> BTC -> Text -> IO ()
- sendFromAccount :: Auth -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
- sendMany :: Auth -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID
- data ReceivedByAddress = ReceivedByAddress {}
- listReceivedByAddress :: Auth -> IO (Vector ReceivedByAddress)
- listReceivedByAddress' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAddress)
- data ReceivedByAccount = ReceivedByAccount {}
- listReceivedByAccount :: Auth -> IO (Vector ReceivedByAccount)
- listReceivedByAccount' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAccount)
- backupWallet :: Auth -> FilePath -> IO ()
- keyPoolRefill :: Auth -> IO ()
- unlockWallet :: Auth -> Text -> Integer -> IO ()
- lockWallet :: Auth -> IO ()
- changePassword :: Auth -> Text -> Text -> IO ()
- encryptWallet :: Auth -> Text -> IO ()
- isAddressValid :: Auth -> Address -> IO Bool
Common Types
data BitcoinException Source
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.
BitcoinApiError Int Text | A |
BitcoinResultTypeError ByteString | The raw JSON returned, if we can't figure out what actually went wrong. |
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 TransactionID = HexStringSource
A hexadecimal string representation of a 256-bit unsigned integer.
This integer is a unique transaction identifier.
A satoshi is the smallest subdivision of bitcoins. For the resolution,
use resolution
from Fixed
.
An account on the wallet is just a label to easily specify private keys.
The default account is an empty string.
I don't know what this is. A signature of some sort? If you know, please submit a patch documenting this properly!
Block Chain Operations
getBlockCount :: Auth -> IO IntegerSource
Returns the number of blocks in the longest block chain.
getDifficulty :: Auth -> IO IntegerSource
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
setTransactionFee :: Auth -> BTC -> IO ()Source
Sets the transaction fee will will pay to the network. Values of 0 are rejected.
getRawMemoryPool :: Auth -> IO (Vector TransactionID)Source
Returns all transaction identifiers in the memory pool.
Returns the hash of the block in best-block-chain at the given index.
Information about a given block in the block chain.
Block | |
|
data OutputSetInfo Source
Information on the unspent transaction in the output set.
OutputSetInfo | |
|
getOutputSetInfo :: Auth -> IO OutputSetInfoSource
Returns statistics about the unspent transaction output set.
data OutputInfo Source
Details about an unspent transaction output.
OutputInfo | |
|
:: Auth | |
-> TransactionID | |
-> Integer | The index we're looking at. |
-> IO OutputInfo |
Returns details about an unspent transaction output.
Private Key Operations
:: Auth | |
-> PrivateKey | |
-> Maybe Account | An optional label for the key. |
-> IO () |
Adds a private key (as returned by dumpprivkey) to your wallet.
dumpPrivateKey :: Auth -> Address -> IO PrivateKeySource
Reveals the private key corresponding to the given address.
Mining Operations
Returns whether or not bitcoind is generating bitcoins.
:: Auth | bitcoind RPC authorization |
-> Bool | Turn it on, or turn it off? |
-> Maybe Int | Generation is limited to this number of processors. Set it to Nothing to keep the value at what it was before, Just -1 to use all available cores, and any other value to limit it. |
-> IO () |
Controls whether or not bitcoind is generating bitcoins.
getHashesPerSec :: Auth -> IO IntegerSource
Returns a recent hashes per second performance measurement while generating.
data MiningInfo Source
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.
MiningInfo | |
|
getMiningInfo :: Auth -> IO MiningInfoSource
Returns an object containing mining-related information.
solveBlock :: Auth -> HexString -> IO BoolSource
Tries to solve the given block, and returns true if it was successful.
data CoinBaseAux Source
data BlockTemplate Source
A template for constructing a block to work on.
See https://en.bitcoin.it/wiki/BIP_0022 for the full specification.
BlockTemplate | |
|
getBlockTemplate :: Auth -> IO BlockTemplateSource
Returns data needed to construct a block to work on.
Attempts to submit a new block to the network.
Network Operations
getConnectionCount :: Auth -> IO IntegerSource
Returns the number of connections to other nodes.
Information on a given connected node in the 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!
PeerInfo | |
|
getPeerInfo :: Auth -> IO PeerInfoSource
Returns data about each connected network node.
Raw Transaction Operations
type RawTransaction = HexStringSource
Just like most binary data retrieved from bitcoind, a raw transaction is represented by a hexstring.
This is a serialized, hex-encoded transaction.
getRawTransaction :: Auth -> TransactionID -> IO RawTransactionSource
Get a raw transaction from its unique ID.
A transaction into an account. This can either be a coinbase transaction, or a standard transaction with another account.
TxCoinbase | |
TxIn | |
|
data TxnOutputType Source
The type of a transaction out.
More documentation is needed here. Submit a patch if you know what this is about!
TxnPubKey | JSON of pubkey received. |
TxnPubKeyHash | JSON of pubkeyhash received. |
TxnScriptHash | JSON of scripthash received. |
TxnMultisig | JSON of multisig received. |
data ScriptPubKey Source
A public key of someone we sent money to.
NonStandardScriptPubKey | |
StandardScriptPubKey | |
|
A transaction out of an account.
TxOut | |
|
Information on a single block.
ConfirmedBlock | |
UnconfirmedBlock | An unconfirmed block is boring, but a possibility. |
data RawTransactionInfo Source
The raw transaction info for a given transaction ID.
RawTransactionInfo | |
|
getRawTransactionInfo :: Auth -> TransactionID -> IO RawTransactionInfoSource
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.
:: Auth | |
-> Maybe Int | minconf. Defaults to 1 if |
-> Maybe Int | maxconf. Defaults to 9999999 if |
-> Vector Address | Use |
-> IO (Vector UnspentTransaction) |
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.
:: Auth | |
-> Vector UnspentTransaction | The unspent transactions we'll be using as our output. |
-> Vector (Address, BTC) | The addresses we're sending money to, along with how much each of them gets. |
-> IO HexString |
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.
data DecodedRawTransaction Source
A successfully decoded raw transaction, from a given serialized, hex-encoded transaction.
DecodedRawTransaction | |
|
decodeRawTransaction :: Auth -> RawTransaction -> IO DecodedRawTransactionSource
Decodes a raw transaction into a more accessible data structure.
Who can pay for a given transaction.
data RawSignedTransaction Source
A raw signed transaction contains the raw, signed hexstring and whether or not this transaction has a complete signature set.
:: Auth | |
-> RawTransaction | The raw transaction whose inputs we're signing. |
-> Maybe (Vector UnspentTransaction) | An optional list of previous transaction outputs that this transaction depends on but may not yet be in the block chain. |
-> Maybe (Vector HexString) | An array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction. |
-> Maybe WhoCanPay | Who can pay for this transaction? |
-> IO RawSignedTransaction | Returns |
Sign inputs for a raw transaction.
Wallet Operations
data BitcoindInfo Source
A plethora of information about a bitcoind instance.
BitcoindInfo | |
|
getBitcoindInfo :: Auth -> IO BitcoindInfoSource
Returns an object containing various state info.
getNewAddress :: Auth -> Maybe Account -> IO AddressSource
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.
getAccountAddress :: Auth -> Account -> IO AddressSource
Returns the current Bitcoin address for receiving payments to the given account.
getAccount :: Auth -> Address -> IO AccountSource
Returns the account associated with the given address.
setAccount :: Auth -> Address -> Account -> IO ()Source
Sets the account associated with the given address.
getAddressByAccount :: Auth -> Account -> IO (Vector Address)Source
Returns the list of addresses for the given address.
:: Auth | |
-> Address | Who we're sending to. |
-> BTC | The amount to send. |
-> Maybe Text | An optional comment for the transaction. |
-> Maybe Text | An optional comment-to (who did we sent this to?) for the transaction. |
-> IO TransactionID |
Sends some bitcoins to an address.
data AddressInfo Source
Information on a given address.
Eq AddressInfo | |
Ord AddressInfo | |
Read AddressInfo | |
Show AddressInfo | |
FromJSON AddressInfo | What a silly API. |
listAddressGroupings :: Auth -> IO (Vector (Vector AddressInfo))Source
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.
:: Auth | |
-> Address | The address whose private key we'll use. |
-> Text | The message to sign. |
-> IO Signature |
Sign a message with the private key of an address.
:: Auth | |
-> Address | The address of the original signer. |
-> Signature | The message's signature. |
-> Text | The message. |
-> IO Bool | Was the signature valid? |
Verifies a signed message.
getReceivedByAddress :: Auth -> Address -> IO BTCSource
Returns the total amount received by the given address with at least one confirmation.
:: Auth | |
-> Address | |
-> Int | The minimum number of confirmations needed for a transaction to to count towards the total. |
-> IO BTC |
Returns the total amount received by the given address, with at least the give number of confirmations.
getReceivedByAccount :: Auth -> Account -> IO BTCSource
Returns the total amount received by address with the given account.
:: Auth | |
-> Account | The account in question. |
-> Int | The minimum number of confirmations needed for a transaction to count towards the total. |
-> IO BTC |
Returns the total amount received by addresses with the given account, counting only transactions with the given minimum number of confirmations.
getBalance :: Auth -> IO BTCSource
Returns the server's total available balance.
getBalance' :: Auth -> Account -> IO BTCSource
Returns the balance in the given account, counting only transactions with at least one confirmation.
:: Auth | |
-> Account | |
-> Int | The minimum number of confirmations needed for a transaction to cuont towards the total. |
-> IO BTC |
Returns the balance in the given account, counting only transactions with at least the given number of confirmations.
:: Auth | |
-> Account | From. |
-> Account | To. |
-> BTC | The amount to transfer. |
-> Text | A comment to record for the transaction. |
-> IO () |
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
.
:: Auth | |
-> Account | The account to send from. |
-> Address | The address to send to. |
-> BTC | The amount to send. |
-> Maybe Text | An optional transaction comment. |
-> Maybe Text | An optional comment on who the money is going to. |
-> IO TransactionID |
Sends bitcoins from a given account in our wallet to a given address.
A transaction and sender comment may be optionally provided.
:: Auth | |
-> Account | The account to send from. |
-> Vector (Address, BTC) | The address, and how much to send to each one. |
-> Maybe Text | An optional transaction comment. |
-> IO TransactionID |
Send to a whole bunch of address at once.
data ReceivedByAddress Source
Information on how much was received by a given address.
ReceivedByAddress | |
|
listReceivedByAddress :: Auth -> IO (Vector ReceivedByAddress)Source
Lists the amount received by each address which has received money at some point, counting only transactions with at least one confirmation.
:: Auth | |
-> Int | The minimum number of confirmations before a transaction counts toward the total amount received. |
-> Bool | Should we include addresses with no money received? |
-> IO (Vector ReceivedByAddress) |
List the amount received by each of our addresses, counting only transactions with the given minimum number of confirmations.
data ReceivedByAccount Source
ReceivedByAccount | |
|
listReceivedByAccount :: Auth -> IO (Vector ReceivedByAccount)Source
Lists the amount received by each account which has received money at some point, counting only transactions with at leaset one confirmation.
:: Auth | |
-> Int | The minimum number of confirmations before a transaction counts toward the total received. |
-> Bool | Should we include the accounts with no money received? |
-> IO (Vector ReceivedByAccount) |
List the amount received by each of our accounts, counting only transactions with the given minimum number of confirmations.
backupWallet :: Auth -> FilePath -> IO ()Source
Safely copies wallet.dat to the given destination, which can be either a directory, or a path with filename.
keyPoolRefill :: Auth -> IO ()Source
Fills the keypool.
:: Auth | |
-> Text | The decryption key. |
-> Integer | How long to store the key in memory (in seconds). |
-> IO () |
Stores the wallet decryption key in memory for the given amount of time.
lockWallet :: Auth -> IO ()Source
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.
Changes the wallet passphrase.
encryptWallet :: Auth -> Text -> IO ()Source
Encrypts the wallet with the given passphrase.
WARNING: bitcoind will shut down after calling this method. Don't say I didn't warn you.