File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change
1
+ 1.9.1
2
+
3
+ * tries to call 'generate' before falling back to 'generatetoaddress'
4
+
1
5
1.9.0
2
6
3
7
* removes 'generate' rpc call
Original file line number Diff line number Diff line change 1
1
Name : network-bitcoin
2
- Version : 1.9.0
2
+ Version : 1.9.1
3
3
Synopsis : An interface to bitcoind.
4
4
Description :
5
5
This can be used to send Bitcoins, query balances, etc. It
Original file line number Diff line number Diff line change @@ -31,10 +31,15 @@ module Network.Bitcoin.Mining ( Client
31
31
, submitBlock
32
32
) where
33
33
34
+ import Control.Exception (catch , throw )
34
35
import Control.Monad
35
36
import Data.Aeson as A
36
37
import Network.Bitcoin.Internal
37
38
import Network.Bitcoin.Wallet (getNewAddress )
39
+ import Network.HTTP.Client (HttpException (.. ),
40
+ HttpExceptionContent (.. ),
41
+ responseStatus )
42
+ import Network.HTTP.Types (status404 )
38
43
39
44
-- | Returns whether or not bitcoind is generating bitcoins.
40
45
getGenerate :: Client -- ^ bitcoind RPC client
@@ -72,7 +77,13 @@ generate :: Client
72
77
-- hashes of the generated blocks
73
78
-- (may be empty if used with generate 0)
74
79
generate client blocks maxTries =
75
- getNewAddress client Nothing >>= flip (generateToAddress client blocks) maxTries
80
+ callApi client " generate" args `catch` onFail
81
+ where
82
+ args = tj blocks : maybe [] (pure . tj) maxTries
83
+ onFail (HttpExceptionRequest _ (StatusCodeException rsp _))
84
+ | responseStatus rsp == status404
85
+ = getNewAddress client Nothing >>= flip (generateToAddress client blocks) maxTries
86
+ onFail e = throw e
76
87
77
88
-- | The generatetoaddress RPC mines blocks immediately to a specified address.
78
89
-- See https://bitcoin.org/en/developer-reference#generatetoaddress for more details.
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ type RawTransaction = HexString
51
51
getRawTransaction :: Client -> TransactionID -> IO RawTransaction
52
52
getRawTransaction client txid =
53
53
callApi client " getrawtransaction" [ tj txid, tj verbose ]
54
- where verbose = 0 :: Int
54
+ where verbose = False
55
55
56
56
-- | A transaction into an account. This can either be a coinbase transaction,
57
57
-- or a standard transaction with another account.
You can’t perform that action at this time.
0 commit comments