This PR continues and completes the work begun in #17700 working on issue #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:
0$ bitcoin-cli -generate
1{
2 "address": "bcrt1qn4aszr2y2xvpa70y675a76wsu70wlkwvdyyln6"
3 "blocks": [
4 "01d2ebcddf663da90b28da7f6805115e2ba7818f16fe747258836646a43a0bb5",
5 ]
6}
7
8$ bitcoin-cli -rpcwallet=wallet-name -generate 3 100
9{
10 "address": "bcrt1q4cunfw0gnsj7g7e6mk0v0uuvvau9mwr09dj45l",
11 "blocks": [
12 "7a6650ca5e0c614992ee64fb148a7e5e022af842e4b6003f81abd8baf1e75136",
13 "01d2ebcddf663da90b28da7f6805115e2ba7818f16fe747258836646a43a0bb5",
14 "3f8795ec40b1ad812b818c177680841be319a3f6753d4e32dc7dfb5bafe5d00e"
15 ]
16}
Help doc:
0$ bitcoin-cli -h | grep -A5 "\-generate"
1 -generate
2 Generate blocks immediately, equivalent to RPC generatenewaddress
3 followed by RPC generatetoaddress. Optional positional arguments
4 are number of blocks to generate (default: 1) and maximum
5 iterations to try (default: 1000000), equivalent to RPC
6 generatetoaddress nblocks and maxtries arguments. Example:
7 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 #17700.