Safe Haskell | None |
---|---|
Language | Haskell98 |
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
- 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 {}
- newtype 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.
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.
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.
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
|
Instances
Eq MiningInfo Source # | |
Defined in Network.Bitcoin.Mining | |
Ord MiningInfo Source # | |
Defined in Network.Bitcoin.Mining Methods compare :: MiningInfo -> MiningInfo -> Ordering # (<) :: MiningInfo -> MiningInfo -> Bool # (<=) :: MiningInfo -> MiningInfo -> Bool # (>) :: MiningInfo -> MiningInfo -> Bool # (>=) :: MiningInfo -> MiningInfo -> Bool # max :: MiningInfo -> MiningInfo -> MiningInfo # min :: MiningInfo -> MiningInfo -> MiningInfo # | |
Read MiningInfo Source # | |
Defined in Network.Bitcoin.Mining Methods readsPrec :: Int -> ReadS MiningInfo # readList :: ReadS [MiningInfo] # readPrec :: ReadPrec MiningInfo # readListPrec :: ReadPrec [MiningInfo] # | |
Show MiningInfo Source # | |
Defined in Network.Bitcoin.Mining Methods showsPrec :: Int -> MiningInfo -> ShowS # show :: MiningInfo -> String # showList :: [MiningInfo] -> ShowS # | |
FromJSON MiningInfo Source # | |
Defined in Network.Bitcoin.Mining |
getMiningInfo :: Client -> IO MiningInfo Source #
Returns an object containing mining-related information.
The hash data returned from getWork
.
Constructors
HashData | |
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.
Constructors
Transaction | |
Instances
Eq Transaction Source # | |
Defined in Network.Bitcoin.Mining | |
Ord Transaction Source # | |
Defined in Network.Bitcoin.Mining Methods compare :: Transaction -> Transaction -> Ordering # (<) :: Transaction -> Transaction -> Bool # (<=) :: Transaction -> Transaction -> Bool # (>) :: Transaction -> Transaction -> Bool # (>=) :: Transaction -> Transaction -> Bool # max :: Transaction -> Transaction -> Transaction # min :: Transaction -> Transaction -> Transaction # | |
Read Transaction Source # | |
Defined in Network.Bitcoin.Mining Methods readsPrec :: Int -> ReadS Transaction # readList :: ReadS [Transaction] # readPrec :: ReadPrec Transaction # readListPrec :: ReadPrec [Transaction] # | |
Show Transaction Source # | |
Defined in Network.Bitcoin.Mining Methods showsPrec :: Int -> Transaction -> ShowS # show :: Transaction -> String # showList :: [Transaction] -> ShowS # | |
FromJSON Transaction Source # | |
Defined in Network.Bitcoin.Mining |
newtype CoinBaseAux Source #
Constructors
CoinBaseAux | |
Instances
Eq CoinBaseAux Source # | |
Defined in Network.Bitcoin.Mining | |
Ord CoinBaseAux Source # | |
Defined in Network.Bitcoin.Mining Methods compare :: CoinBaseAux -> CoinBaseAux -> Ordering # (<) :: CoinBaseAux -> CoinBaseAux -> Bool # (<=) :: CoinBaseAux -> CoinBaseAux -> Bool # (>) :: CoinBaseAux -> CoinBaseAux -> Bool # (>=) :: CoinBaseAux -> CoinBaseAux -> Bool # max :: CoinBaseAux -> CoinBaseAux -> CoinBaseAux # min :: CoinBaseAux -> CoinBaseAux -> CoinBaseAux # | |
Read CoinBaseAux Source # | |
Defined in Network.Bitcoin.Mining Methods readsPrec :: Int -> ReadS CoinBaseAux # readList :: ReadS [CoinBaseAux] # readPrec :: ReadPrec CoinBaseAux # readListPrec :: ReadPrec [CoinBaseAux] # | |
Show CoinBaseAux Source # | |
Defined in Network.Bitcoin.Mining Methods showsPrec :: Int -> CoinBaseAux -> ShowS # show :: CoinBaseAux -> String # showList :: [CoinBaseAux] -> ShowS # | |
FromJSON CoinBaseAux Source # | |
Defined in Network.Bitcoin.Mining |
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
|
Instances
getBlockTemplate :: Client -> IO BlockTemplate Source #
Returns data needed to construct a block to work on.