You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
22cb303 rpc: add missing space in JSON parsing error message, update test (Jon Atack)
bf53ebe test: add multiwallet tests for bitcoin-cli -generate (Jon Atack)
4b859cf cli: add multiwallet capability to GetNewAddress and -generate (Jon Atack)
18f9354 test: add tests for bitcoin-cli -generate (Jon Atack)
4818124 cli: create bitcoin-cli -generate command (Jon Atack)
ff41a36 cli: extract ParseResult() and ParseError() (Jon Atack)
f4185b2 cli: create GenerateToAddressRequestHandler class (Harris)
f7c65a3 cli: create GetNewAddress() (Jon Atack)
9be7fd3 rpc: make generatetoaddress locals const (Jon Atack)
cb00510 rpc: create rpc/mining.h, hoist default max tries values to constant (Jon Atack)
Pull request description:
This PR continues and completes the work begun in bitcoin#17700 working on issue bitcoin#16000 to create a client-side version of RPC `generate`.
Basically, `bitcoin-cli -generate` wraps calling `generatenewaddress` followed by `generatetoaddress [nblocks] [maxtries]` and prints the following:
```
$ bitcoin-cli -generate
{
"address": "bcrt1qn4aszr2y2xvpa70y675a76wsu70wlkwvdyyln6"
"blocks": [
"01d2ebcddf663da90b28da7f6805115e2ba7818f16fe747258836646a43a0bb5",
]
}
$ bitcoin-cli -rpcwallet=wallet-name -generate 3 100
{
"address": "bcrt1q4cunfw0gnsj7g7e6mk0v0uuvvau9mwr09dj45l",
"blocks": [
"7a6650ca5e0c614992ee64fb148a7e5e022af842e4b6003f81abd8baf1e75136",
"01d2ebcddf663da90b28da7f6805115e2ba7818f16fe747258836646a43a0bb5",
"3f8795ec40b1ad812b818c177680841be319a3f6753d4e32dc7dfb5bafe5d00e"
]
}
```
Help doc:
```
$ bitcoin-cli -h | grep -A5 "\-generate"
-generate
Generate blocks immediately, equivalent to RPC generatenewaddress
followed by RPC generatetoaddress. Optional positional arguments
are number of blocks to generate (default: 1) and maximum
iterations to try (default: 1000000), equivalent to RPC
generatetoaddress nblocks and maxtries arguments. Example:
bitcoin-cli -generate 4 1000
```
Quite a bit of test coverage turned out to be needed to cover the change and the different cases (arguments, multiwallet mode) and error-handling.
This PR also improves some things that working on these changes brought to light.
Credit to Harris Brakmić for the initial work in bitcoin#17700.
ACKs for top commit:
adamjonas:
utACK 22cb303
meshcollider:
utACK 22cb303
Tree-SHA512: 94f67f632fe093d076f614e0ecff09ce7342ac6e424579200d5211a6615260e438d857861767fb788950ec6da0b26ef56dc8268c430012a3b3d4822b24ca6fbf
Copy file name to clipboardExpand all lines: src/bitcoin-cli.cpp
+106-32
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@
11
11
#include<clientversion.h>
12
12
#include<optional.h>
13
13
#include<rpc/client.h>
14
+
#include<rpc/mining.h>
14
15
#include<rpc/protocol.h>
15
16
#include<rpc/request.h>
16
17
#include<util/strencodings.h>
@@ -39,6 +40,9 @@ static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
39
40
staticconstbool DEFAULT_NAMED=false;
40
41
staticconstint CONTINUE_EXECUTION=-1;
41
42
43
+
/** Default number of blocks to generate for RPC generatetoaddress. */
44
+
staticconst std::string DEFAULT_NBLOCKS = "1";
45
+
42
46
staticvoidSetupCliArgs()
43
47
{
44
48
SetupHelpOptions(gArgs);
@@ -50,6 +54,7 @@ static void SetupCliArgs()
50
54
gArgs.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
51
55
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
52
56
gArgs.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
57
+
gArgs.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC generatenewaddress followed by RPC generatetoaddress. Optional positional integer arguments are number of blocks to generate (default: %s) and maximum iterations to try (default: %s), equivalent to RPC generatetoaddress nblocks and maxtries arguments. Example: bitcoin-cli -generate 4 1000", DEFAULT_NBLOCKS, DEFAULT_MAX_TRIES), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
53
58
gArgs.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
54
59
SetupChainParamsBaseOptions();
55
60
gArgs.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -286,6 +291,28 @@ class GetinfoRequestHandler: public BaseRequestHandler
if (args.size() > 2) throwstd::runtime_error("too many arguments (maximum 2 for nblocks and maxtries)");
555
+
if (args.size() == 0) {
556
+
args.emplace_back(DEFAULT_NBLOCKS);
557
+
} elseif (args.at(0) == "0") {
558
+
throwstd::runtime_error("the first argument (number of blocks to generate, default: " + DEFAULT_NBLOCKS + ") must be an integer value greater than zero");
559
+
}
560
+
args.emplace(args.begin() + 1, address);
561
+
}
562
+
480
563
staticintCommandLineRPC(int argc, char *argv[])
481
564
{
482
565
std::string strPrint;
@@ -535,6 +618,15 @@ static int CommandLineRPC(int argc, char *argv[])
0 commit comments