Communicate with a Bitcoin daemon over JSON RPC
- data Auth = Auth {}
- data Address
- mkAddress :: String -> Maybe Address
- type Amount = Fixed Satoshi
- type Account = String
- type MinConf = Integer
- data AddressValidation
- isValid :: AddressValidation -> Bool
- isMine :: AddressValidation -> Bool
- account :: AddressValidation -> Account
- data BitcoinException = BitcoinApiError Int String
- getBalance :: Auth -> Account -> MinConf -> IO Amount
- getBlockCount :: Auth -> IO Integer
- getConnectionCount :: Auth -> IO Integer
- getDifficulty :: Auth -> IO Double
- getGenerate :: Auth -> IO Bool
- getHashesPerSec :: Auth -> IO Integer
- getReceivedByAccount :: Auth -> Account -> MinConf -> IO Amount
- getReceivedByAddress :: Auth -> Address -> MinConf -> IO Amount
- validateAddress :: Auth -> Address -> IO AddressValidation
- isValidAddress :: Auth -> Address -> IO Bool
- callApi :: Auth -> String -> [Value] -> IO Value
Types
Represents a Bitcoin receiving address. Construct one with
mkAddress
.
data AddressValidation Source
Encapsulates address validation results from validateAddress
isValid :: AddressValidation -> BoolSource
Is the address valid?
isMine :: AddressValidation -> BoolSource
Does the address belong to my wallet?
account :: AddressValidation -> AccountSource
To which account does this address belong?
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
.
Individual API methods
getBalance :: Auth -> Account -> MinConf -> IO AmountSource
Returns the balance of a specific Bitcoin account
getBlockCount :: Auth -> IO IntegerSource
Returns the number of blocks in the longest block chain
getConnectionCount :: Auth -> IO IntegerSource
Returns the number of connections to other nodes
getDifficulty :: Auth -> IO DoubleSource
Returns the proof-of-work difficulty as a multiple of the minimum difficulty
getGenerate :: Auth -> IO BoolSource
Indicates whether the node is generating or not
getHashesPerSec :: Auth -> IO IntegerSource
Returns a recent hashes per second performance measurement while generating
getReceivedByAccount :: Auth -> Account -> MinConf -> IO AmountSource
Returns the total amount received by addresses with
account
in transactions with at least minconf
confirmations
getReceivedByAddress :: Auth -> Address -> MinConf -> IO AmountSource
Returns the total amount received by an address in transactions
with at least minconf
confirmations.
validateAddress :: Auth -> Address -> IO AddressValidationSource
Return information about an address. If the address is invalid or doesn't belong to us, the account name is the empty string.
isValidAddress :: Auth -> Address -> IO BoolSource
Returns true if the RPC says the address is valid.
Use this function until mkAddress
verifies address checksums
Low-level API
:: Auth | authentication credentials for bitcoind |
-> String | command name |
-> [Value] | command arguments |
-> IO Value |
callApi
is a low-level interface for making authenticated API
calls to a Bitcoin daemon. The first argument specifies
authentication details (URL, username, password) and is often
curried for convenience:
callBtc = callApi $ Auth "http://127.0.0.1:8332" "user" "password"
The second argument is the command name. The third argument provides parameters for the API call.
let result = callBtc "getbalance" ["account-name", Number 6]
On error, throws a BitcoinException