network-bitcoin-1.8.3: 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. If bitcoind runs in regtest mode instead of the number of processors, this specifies the number of hashes to generate.

-> IO (Maybe [HexString]) 

Controls whether or not bitcoind is generating bitcoins. If bitcoind runs in regtest mode the number of generated hashes is returned. See https://bitcoin.org/en/developer-reference#setgenerate for more details.

generate Source #

Arguments

:: Client 
-> Int

The number of blocks to generate. The RPC call will not return until all blocks have been generated or the maxium number of iterations has been reached

-> Maybe Int

The maximum number of iterations that are tried to create the requested number of blocks. Default is 1000000

-> IO [HexString]

An array containing the block header hashes of the generated blocks (may be empty if used with generate 0)

The generate RPC nearly instantly generates blocks. See https://bitcoin.org/en/developer-reference#generate for more details.

generateToAddress Source #

Arguments

:: Client 
-> Int

The number of blocks to generate. The RPC call will not return until all blocks have been generated or the maxium number of iterations has been reached

-> Address

The address to send the newly generated Bitcoin to

-> Maybe Int

The maximum number of iterations that are tried to create the requested number of blocks. Default is 1000000

-> IO [HexString] 

The generatetoaddress RPC mines blocks immediately to a specified address. See https://bitcoin.org/en/developer-reference#generatetoaddress for more details.

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

getMiningInfo :: Client -> IO MiningInfo Source #

Returns an object containing mining-related information.

data HashData Source #

The hash data returned from getWork.

Constructors

HashData 

Fields

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

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.