network-bitcoin-1.9.1: An interface to bitcoind.

Safe HaskellNone
LanguageHaskell98

Network.Bitcoin.Wallet

Description

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.

Synopsis

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.

Constructors

BitcoindInfo 

Fields

getBitcoindInfo :: Client -> IO BitcoindInfo Source #

Returns an object containing various state info.

Availability: < 0.16

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.

sendToAddress Source #

Arguments

:: 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.

Constructors

AddressInfo 

Fields

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.

type Signature = HexString Source #

A signature is a base-64 encoded string.

signMessage Source #

Arguments

:: 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.

verifyMessage Source #

Arguments

:: 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.

getReceivedByAddress' Source #

Arguments

:: 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.

getReceivedByAccount' Source #

Arguments

:: 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.

getBalance'' Source #

Arguments

:: 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.

moveBitcoins Source #

Arguments

:: 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.

sendFromAccount Source #

Arguments

:: 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.

sendMany Source #

Arguments

:: 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.

estimateSmartFee :: Client -> Word32 -> Maybe EstimationMode -> IO Double Source #

Estimate the fee per kb to send a transaction

data ReceivedByAddress Source #

Information on how much was received by a given address.

Constructors

ReceivedByAddress 

Fields

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.

listReceivedByAddress' Source #

Arguments

:: 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 #

Constructors

ReceivedByAccount 

Fields

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.

listReceivedByAccount' Source #

Arguments

:: 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.

listTransactions Source #

Arguments

:: Client 
-> Account

Limits the BlockTransaction returned to those from or to the given Account.

-> Int

Limits the number of BlockTransaction returned.

-> Int

Number of most recent transactions to skip.

-> IO (Vector SimpleTransaction) 

Returns transactions from the blockchain.

listTransactions' Source #

Arguments

:: Client 
-> Maybe Account

Limits the BlockTransaction returned to those from or to the given Account. If Nothing all accounts are included in the query.

-> Maybe Int

Limits the number of BlockTransaction returned. If Nothing all transactions are returned.

-> Maybe Int

Number of most recent transactions to skip.

-> IO (Vector SimpleTransaction) 

Returns transactions from the blockchain.

listAccounts Source #

Arguments

:: 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.

importAddress Source #

Arguments

:: Client 
-> Address

Address to import

-> Maybe Account

Optional account, default ""

-> Maybe Bool

Optional rescan the blockchain, default true

-> IO () 

Import an address

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.

Constructors

SimpleTransaction 

Fields

data TransactionCategory Source #

listSinceBlock Source #

Arguments

:: Client 
-> BlockHash

The hash of the first block to list.

-> Maybe Int

The minimum number of confirmations before a transaction can be returned as sbLastBlockHash. This does not in any way affect which transactions are returned (see https://github.com/bitcoin/bitcoin/pull/199#issuecomment-1514952)

-> IO SinceBlock 

Gets all transactions in blocks since the given block.

listSinceBlock' Source #

Arguments

:: 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 sbLastBlockHash. This does not in any way affect which transactions are returned (see https://github.com/bitcoin/bitcoin/pull/199#issuecomment-1514952)

-> 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.

Constructors

DetailedTransaction 

Fields

data DetailedTransactionDetails Source #

Constructors

DetailedTransactionDetails 

Fields

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.

unlockWallet Source #

Arguments

:: 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.

changePassword Source #

Arguments

:: Client 
-> Text

The old password.

-> Text

The new password.

-> IO () 

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.

isAddressValid :: Client -> Address -> IO Bool Source #

Checks if a given address is a valid one.