network-bitcoin-1.2.1: An interface to bitcoind.

Safe HaskellNone



The API exposed in this module should be considered unstable, and is subject to change between minor revisions.

If the version number is a.b.c.d, and either a or b changes, then the module's whole API may have changed (if only b changes, then it was probably a minor change).

If c changed, then only the internal API may change. The rest of the module is guaranteed to be stable.

If only d changes, then there were no user-facing code changes made.



data Text

A space efficient, packed, unboxed Unicode text type.

data Vector a

Boxed vectors, supporting efficient slicing.

class FromJSON a where

A type that can be converted from JSON, with the possibility of failure.

When writing an instance, use empty, mzero, or fail to make a conversion fail, e.g. if an Object is missing a required key, or the value is of the wrong type.

An example type and instance:

{-# LANGUAGE OverloadedStrings #-}

data Coord { x :: Double, y :: Double }

instance FromJSON Coord where
   parseJSON (Object v) = Coord    <$>
                          v .: "x" <*>
                          v .: "y"

-- A non-Object value is of the wrong type, so use mzero to fail.
   parseJSON _          = mzero

Note the use of the OverloadedStrings language extension which enables Text values to be written as string literals.

Instead of manually writing your FromJSON instance, there are three options to do it automatically:

  • Data.Aeson.TH provides template-haskell functions which will derive an instance at compile-time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
  • Data.Aeson.Generic provides a generic fromJSON function that parses to any type which is an instance of Data.
  • If your compiler has support for the DeriveGeneric and DefaultSignatures language extensions, parseJSON will have a default generic implementation.

To use this, simply add a deriving Generic clause to your datatype and declare a FromJSON instance for your datatype without giving a definition for parseJSON.

For example the previous example can be simplified to just:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics

data Coord { x :: Double, y :: Double } deriving Generic

instance FromJSON Coord


parseJSON :: Value -> Parser a


FromJSON Bool 
FromJSON Char 
FromJSON Double 
FromJSON Float 
FromJSON Int 
FromJSON Int8 
FromJSON Int16 
FromJSON Int32 
FromJSON Int64 
FromJSON Integer 
FromJSON Word 
FromJSON Word8 
FromJSON Word16 
FromJSON Word32 
FromJSON Word64 
FromJSON () 
FromJSON ByteString 
FromJSON Number 
FromJSON Text 
FromJSON DotNetTime 
FromJSON Value 
FromJSON ByteString 
FromJSON Text 
FromJSON IntSet 
FromJSON ZonedTime 
FromJSON ScriptSig 
FromJSON Nil 
FromJSON OutputInfo 
FromJSON OutputSetInfo 
FromJSON Block 
FromJSON BlockTemplate 
FromJSON CoinBaseAux 
FromJSON Transaction 
FromJSON HashData 
FromJSON MiningInfo 
FromJSON PeerInfo 
FromJSON RawSignedTransaction 
FromJSON DecodedRawTransaction 
FromJSON UnspentTransaction 
FromJSON RawTransactionInfo 
FromJSON BlockInfo 
FromJSON TxOut 
FromJSON ScriptPubKey 
FromJSON TxnOutputType 
FromJSON TxIn 
FromJSON ReceivedByAccount 
FromJSON ReceivedByAddress 
FromJSON AddressInfo

What a silly API.

FromJSON BitcoindInfo 
FromJSON [Char] 
FromJSON a => FromJSON [a] 
FromJSON (Ratio Integer) 
FromJSON a => FromJSON (Maybe a) 
HasResolution a => FromJSON (Fixed a) 
FromJSON a => FromJSON (Dual a) 
FromJSON a => FromJSON (First a) 
FromJSON a => FromJSON (Last a) 
FromJSON a => FromJSON (IntMap a) 
(Ord a, FromJSON a) => FromJSON (Set a) 
(Eq a, Hashable a, FromJSON a) => FromJSON (HashSet a) 
FromJSON a => FromJSON (Vector a) 
(Vector Vector a, FromJSON a) => FromJSON (Vector a) 
(Storable a, FromJSON a) => FromJSON (Vector a) 
(Prim a, FromJSON a) => FromJSON (Vector a) 
(FromJSON a, FromJSON b) => FromJSON (Either a b) 
(FromJSON a, FromJSON b) => FromJSON (a, b) 
FromJSON v => FromJSON (HashMap String v) 
FromJSON v => FromJSON (HashMap ByteString v) 
FromJSON v => FromJSON (HashMap Text v) 
FromJSON v => FromJSON (HashMap ByteString v) 
FromJSON v => FromJSON (HashMap Text v) 
FromJSON v => FromJSON (Map String v) 
FromJSON v => FromJSON (Map ByteString v) 
FromJSON v => FromJSON (Map Text v) 
FromJSON v => FromJSON (Map ByteString v) 
FromJSON v => FromJSON (Map Text v) 
(FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) 
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) 



:: FromJSON v 
=> Auth

authentication credentials for bitcoind

-> Text

command name

-> [Value]

command arguments

-> IO v 

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 "" "user" "password"

The second argument is the command name. The third argument provides parameters for the API call.

 let result = callBtc "getbalance" [ tj "account-name", tj 6 ]

On error, throws a BitcoinException.

callApi' :: Auth -> ByteString -> IO ByteStringSource

The no conversion needed implementation of callApi. THis lets us inline and specialize callApi for its parameters, while keeping the bulk of the work in this function shared.

data Nil Source

Used to allow null to decode to a tuple.




unNil :: ()


tj :: ToJSON a => a -> ValueSource

A handy shortcut for toJSON, because I'm lazy.

newtype AddrAddress Source

A wrapper for a vector of address:amount pairs. The RPC expects that as an object of address:amount pairs, instead of a vector. So that's what we give them with AddrAddress's ToJSON.


AA (Vector (Address, BTC))