Safe Haskell | None |
---|---|
Language | Haskell98 |
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
- type Client = ByteString -> IO ByteString
- getClient :: String -> ByteString -> ByteString -> IO Client
- getGenerate :: Client -> IO Bool
- setGenerate :: Client -> Bool -> Maybe Int -> IO (Maybe [HexString])
- generate :: Client -> Int -> Maybe Int -> IO [HexString]
- generateToAddress :: Client -> Int -> Address -> Maybe Int -> IO [HexString]
- getHashesPerSec :: Client -> IO Integer
- data MiningInfo = MiningInfo {}
- getMiningInfo :: Client -> IO MiningInfo
- data HashData = HashData {}
- getWork :: Client -> IO HashData
- solveBlock :: Client -> HexString -> IO Bool
- data Transaction = Transaction {}
- data CoinBaseAux = CoinBaseAux {}
- data BlockTemplate = BlockTemplate {
- blockVersion :: Integer
- previousBlockHash :: HexString
- transactionsToInclude :: Vector Transaction
- coinBaseAux :: CoinBaseAux
- coinBaseValue :: Integer
- btTarget :: HexString
- minTime :: Integer
- nonceRange :: HexString
- sigopLimit :: Integer
- sizeLimit :: Integer
- curTime :: Integer
- btBits :: HexString
- btHeight :: Integer
- getBlockTemplate :: Client -> IO BlockTemplate
- submitBlock :: Client -> HexString -> IO Bool
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.
Returns whether or not bitcoind is generating bitcoins.
:: 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.
:: 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.
:: 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.
MiningInfo | |
|
Instances
getMiningInfo :: Client -> IO MiningInfo Source #
Returns an object containing mining-related information.
The hash data returned from getWork
.
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.
Instances
data CoinBaseAux Source #
Instances
data BlockTemplate Source #
A template for constructing a block to work on.
See https://en.bitcoin.it/wiki/BIP_0022 for the full specification.
BlockTemplate | |
|
Instances
getBlockTemplate :: Client -> IO BlockTemplate Source #
Returns data needed to construct a block to work on.