Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
- type Client = ByteString -> IO ByteString
- getClient :: String -> ByteString -> ByteString -> IO Client
- 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 :: Client -> IO BitcoindInfo
- getNewAddress :: Client -> Maybe Account -> IO Address
- getAccountAddress :: Client -> Account -> IO Address
- getAccount :: Client -> Address -> IO Account
- setAccount :: Client -> Address -> Account -> IO ()
- getAddressesByAccount :: Client -> Account -> IO (Vector Address)
- sendToAddress :: Client -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
- data AddressInfo = AddressInfo {}
- listAddressGroupings :: Client -> IO (Vector (Vector AddressInfo))
- type Signature = HexString
- signMessage :: Client -> Address -> Text -> IO Signature
- verifyMessage :: Client -> Address -> Signature -> Text -> IO Bool
- getReceivedByAddress :: Client -> Address -> IO BTC
- getReceivedByAddress' :: Client -> Address -> Int -> IO BTC
- getReceivedByAccount :: Client -> Account -> IO BTC
- getReceivedByAccount' :: Client -> Account -> Int -> IO BTC
- getBalance :: Client -> IO BTC
- getBalance' :: Client -> Account -> IO BTC
- getBalance'' :: Client -> Account -> Int -> IO BTC
- moveBitcoins :: Client -> Account -> Account -> BTC -> Text -> IO ()
- sendFromAccount :: Client -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
- sendMany :: Client -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID
- data ReceivedByAddress = ReceivedByAddress {}
- listReceivedByAddress :: Client -> IO (Vector ReceivedByAddress)
- listReceivedByAddress' :: Client -> Int -> Bool -> IO (Vector ReceivedByAddress)
- data ReceivedByAccount = ReceivedByAccount {}
- listReceivedByAccount :: Client -> IO (Vector ReceivedByAccount)
- listReceivedByAccount' :: Client -> Int -> Bool -> IO (Vector ReceivedByAccount)
- listTransactions :: Client -> Account -> Int -> Int -> IO (Vector SimpleTransaction)
- listTransactions' :: Client -> Maybe Account -> Maybe Int -> Maybe Int -> IO (Vector SimpleTransaction)
- listAccounts :: Client -> Maybe Int -> IO (HashMap Account BTC)
- data SinceBlock = SinceBlock {}
- data SimpleTransaction = SimpleTransaction {
- stReceivingAccount :: Account
- stAddress :: Maybe Address
- stCategory :: TransactionCategory
- stFee :: Maybe BTC
- stAmount :: BTC
- stConfirmations :: Maybe Integer
- stBlockHash :: Maybe BlockHash
- stBlockIndex :: Maybe Integer
- stBlockTime :: Maybe POSIXTime
- stTransactionId :: Maybe TransactionID
- stWalletConflicts :: Maybe (Vector TransactionID)
- stTime :: POSIXTime
- stTimeReceived :: Maybe POSIXTime
- stComment :: Maybe Text
- stTo :: Maybe Text
- stOtherAccount :: Maybe Account
- data TransactionCategory
- listSinceBlock :: Client -> BlockHash -> Maybe Int -> IO SinceBlock
- listSinceBlock' :: Client -> Maybe BlockHash -> Maybe Int -> IO SinceBlock
- data DetailedTransaction = DetailedTransaction {
- dtAmount :: BTC
- dtFee :: Maybe BTC
- dtConfirmations :: Maybe Integer
- dtTransactionId :: Maybe TransactionID
- dtWalletConflicts :: Maybe (Vector TransactionID)
- dtTime :: POSIXTime
- dtTimeReceived :: Maybe POSIXTime
- dtComment :: Maybe Text
- dtTo :: Maybe Text
- dtDetails :: Vector DetailedTransactionDetails
- dtHex :: RawTransaction
- data DetailedTransactionDetails = DetailedTransactionDetails {}
- getTransaction :: Client -> TransactionID -> IO DetailedTransaction
- backupWallet :: Client -> FilePath -> IO ()
- keyPoolRefill :: Client -> IO ()
- unlockWallet :: Client -> Text -> Integer -> IO ()
- lockWallet :: Client -> IO ()
- changePassword :: Client -> Text -> Text -> IO ()
- encryptWallet :: Client -> Text -> IO ()
- isAddressValid :: Client -> Address -> IO Bool
Documentation
type Client = ByteString -> IO ByteString Source
Client
describes authentication credentials and host info for
making API requests to the Bitcoin daemon.
getClient :: String -> ByteString -> ByteString -> IO Client Source
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.
data BitcoindInfo Source
A plethora of information about a bitcoind instance.
BitcoindInfo | |
|
getBitcoindInfo :: Client -> IO BitcoindInfo Source
Returns an object containing various state info.
getNewAddress :: Client -> Maybe Account -> IO Address Source
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 :: Client -> Account -> IO Address Source
Returns the current Bitcoin address for receiving payments to the given account.
getAccount :: Client -> Address -> IO Account Source
Returns the account associated with the given address.
setAccount :: Client -> Address -> Account -> IO () Source
Sets the account associated with the given address.
getAddressesByAccount :: Client -> Account -> IO (Vector Address) Source
Returns the list of addresses for the given address.
:: Client | |
-> 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 :: Client -> 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.
:: Client | |
-> 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.
:: Client | |
-> 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 :: Client -> Address -> IO BTC Source
Returns the total amount received by the given address with at least one confirmation.
:: Client | |
-> 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 :: Client -> Account -> IO BTC Source
Returns the total amount received by address with the given account.
:: Client | |
-> 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 :: Client -> IO BTC Source
Returns the server's total available balance.
getBalance' :: Client -> Account -> IO BTC Source
Returns the balance in the given account, counting only transactions with at least one confirmation.
:: Client | |
-> Account | |
-> Int | The minimum number of confirmations needed for a transaction to count towards the total. |
-> IO BTC |
Returns the balance in the given account, counting only transactions with at least the given number of confirmations.
:: Client | |
-> 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
.
:: Client | |
-> 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.
:: Client | |
-> 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 :: Client -> 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.
:: Client | |
-> 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 :: Client -> 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.
:: Client | |
-> 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.
:: Client | |
-> Account | Limits the |
-> Int | Limits the number of |
-> Int | Number of most recent transactions to skip. |
-> IO (Vector SimpleTransaction) |
Returns transactions from the blockchain.
:: Client | |
-> Maybe Account | Limits the |
-> Maybe Int | Limits the number of |
-> Maybe Int | Number of most recent transactions to skip. |
-> IO (Vector SimpleTransaction) |
Returns transactions from the blockchain.
:: Client | |
-> Maybe Int | Minimum number of confirmations required before payments are included in the balance. |
-> IO (HashMap Account BTC) |
List accounts and their current balance.
data SinceBlock Source
data SimpleTransaction Source
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.
SimpleTransaction | |
|
:: Client | |
-> BlockHash | The hash of the first block to list. |
-> Maybe Int | The minimum number of confirmations before a
transaction can be returned as |
-> IO SinceBlock |
Gets all transactions in blocks since the given block.
:: Client | |
-> Maybe BlockHash | The hash of the first block to list. |
-> Maybe Int | The minimum number of confirmations before a
transaction can be returned as |
-> IO SinceBlock |
Gets all transactions in blocks since the given block, or all transactions if ommited.
data DetailedTransaction Source
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.
DetailedTransaction | |
|
data DetailedTransactionDetails Source
DetailedTransactionDetails | |
|
backupWallet :: Client -> FilePath -> IO () Source
Safely copies wallet.dat to the given destination, which can be either a directory, or a path with filename.
keyPoolRefill :: Client -> IO () Source
Fills the keypool.
:: Client | |
-> 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 :: Client -> 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 :: Client -> 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.