network-bitcoin-1.4.0: An interface to bitcoind.

Safe HaskellNone

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

data Auth Source

Auth describes authentication credentials for making API requests to the Bitcoin daemon.

Constructors

Auth 

Fields

rpcUrl :: Text

URL, with port, where bitcoind listens

rpcUser :: Text

same as bitcoind's rpcuser config

rpcPassword :: Text

same as bitcoind's rpcpassword config

Instances

data BitcoindInfo Source

A plethora of information about a bitcoind instance.

Constructors

BitcoindInfo 

Fields

bitcoinVersion :: Integer

What version of bitcoind are we running?

protocolVersion :: Integer

What is bitcoind's current protocol number?

walletVersion :: Integer

What version is the wallet?

balance :: BTC

How much money is currently in the wallet?

numBlocks :: Integer

The number of blocks in our chain.

numConnections :: Integer

How many peers are we connected to?

proxy :: Text

A blank string if we're not using a proxy.

generationDifficulty :: Double

The difficulty multiplier for bitcoin mining operations.

onTestNetwork :: Bool

Are we on the test network (as opposed to the primary bitcoin network)?

keyPoolOldest :: Integer

The timestamp of the oldest key in the key pool.

keyPoolSize :: Integer

The size of the key pool.

transactionFeePaid :: BTC

How much do we currently pay as a transaction fee?

unlockedUntil :: Maybe Integer

If the wallet is unlocked, the number of seconds until a re-lock is needed.

bitcoindErrors :: Text

Any alerts will show up here. This should normally be an empty string.

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.

getAddressesByAccount :: Auth -> Account -> IO (Vector Address)Source

Returns the list of addresses for the given address.

sendToAddressSource

Arguments

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

Constructors

AddressInfo 

Fields

aiAddress :: Address

The address in question.

aiAmount :: BTC

The address' balance.

aiAccount :: Maybe Account

The address' linked account.

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.

type Signature = HexStringSource

A signature is a base-64 encoded string.

signMessageSource

Arguments

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

verifyMessageSource

Arguments

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

getReceivedByAddress'Source

Arguments

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

getReceivedByAccount'Source

Arguments

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

getBalance''Source

Arguments

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

moveBitcoinsSource

Arguments

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

sendFromAccountSource

Arguments

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

sendManySource

Arguments

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

Constructors

ReceivedByAddress 

Fields

recvAddress :: Address

The address which the money was deposited to.

recvAccount :: Account

The account which this address belongs to.

recvAmount :: BTC

The amount received.

recvNumConfirmations :: Integer

The number of confirmations of the most recent included transaction.

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.

listReceivedByAddress'Source

Arguments

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

Constructors

ReceivedByAccount 

Fields

raccAccount :: Account

The account we received into.

raccAmount :: BTC

The mount received. ^ The number of confirmations of the most recent included transaction.

raccNumConfirmations :: Integer
 

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.

listReceivedByAccount'Source

Arguments

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

unlockWalletSource

Arguments

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

changePasswordSource

Arguments

:: Auth 
-> Text

The old password.

-> Text

The new password.

-> IO () 

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.

isAddressValid :: Auth -> Address -> IO BoolSource

Checks if a given address is a valid one.