network-bitcoin-1.7.2: An interface to bitcoind.

Safe HaskellNone
LanguageHaskell98

Network.Bitcoin.Mining

Description

An interface to bitcoind's available mining RPC calls. The implementation of these functions can be found at https://github.com/bitcoin/bitcoin/blob/master/src/rpcmining.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.

Note that it is highly discouraged to use bitcoind for actual bitcoin mining. It uses the CPU for mining, which is much, much less power efficient than GPU mining. If you're paying for power, you will not come out ahead.

Instead, consider using a GPU miner listed at https://en.bitcoin.it/wiki/Software#Mining_apps.

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.

getGenerate Source

Arguments

:: Client

bitcoind RPC client

-> IO Bool 

Returns whether or not bitcoind is generating bitcoins.

setGenerate Source

Arguments

:: Client

bitcoind RPC client

-> Bool

Turn it on, or turn it off?

-> Maybe Int

Generation is limited to this number of processors. Set it to Nothing to keep the value at what it was before, Just -1 to use all available cores, and any other value to limit it.

-> IO () 

Controls whether or not bitcoind is generating bitcoins.

getHashesPerSec :: Client -> IO Integer Source

Returns a recent hashes per second performance measurement while generating.

data MiningInfo Source

Information related to the current bitcoind mining operation.

If a field is undocumented here, it's because I don't know what it means. If you DO know what it means, I'd love it if you would submit a patch to help complete this documentation.

Constructors

MiningInfo 

Fields

nBlocks :: Integer

The number of blocks in our block-chain.

currentBlockSize :: Integer

The size of the current block we're mining.

currentBlockTransaction :: Integer
 
difficulty :: Double

How difficult mining currently is.

miningErrors :: Text

Any mining errors that may have come up.

isGenerating :: Bool

Are we currently generating bitcoins?

generationProcessorLimit :: Integer

How many processors have we limited bitcoin mining to?

hashesPerSecond :: Integer

How fast is the mining going?

pooledTransactions :: Integer
 
miningOnTestNetwork :: Bool

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

getMiningInfo :: Client -> IO MiningInfo Source

Returns an object containing mining-related information.

data HashData Source

The hash data returned from getWork.

Constructors

HashData 

Fields

blockData :: HexString
 
hdTarget :: HexString

Little-endian hash target, formatted as a hexadecimal string.

hash1 :: HexString
 
midstate :: HexString
 

getWork :: Client -> IO HashData Source

Returns formatted hash data to work on.

solveBlock :: Client -> HexString -> IO Bool Source

Tries to solve the given block, and returns true if it was successful.

data Transaction Source

A transaction to be included in the next block.

data BlockTemplate Source

A template for constructing a block to work on.

See https://en.bitcoin.it/wiki/BIP_0022 for the full specification.

Constructors

BlockTemplate 

Fields

blockVersion :: Integer
 
previousBlockHash :: HexString

Hash of current highest block.

transactionsToInclude :: Vector Transaction

Contents of non-coinbase transactions that should be included in the next block.

coinBaseAux :: CoinBaseAux

Data that should be included in coinbase.

coinBaseValue :: Integer

Maximum allowable input to coinbase transaction, including the generation award and transaction fees.

btTarget :: HexString

Hash target.

minTime :: Integer

Minimum timestamp appropriate for next block.

nonceRange :: HexString

Range of valid nonces.

sigopLimit :: Integer

Limit of sigops in blocks.

sizeLimit :: Integer

Limit of block size.

curTime :: Integer

Current timestamp.

btBits :: HexString

Compressed target of the next block.

btHeight :: Integer

Height of the next block.

getBlockTemplate :: Client -> IO BlockTemplate Source

Returns data needed to construct a block to work on.

submitBlock Source

Arguments

:: Client 
-> HexString

The block to submit.

-> IO Bool

Was the block accepted by the network?

Attempts to submit a new block to the network.