Skip to content

Commit c9f0295

Browse files
committed
[wallet] Deprecate the generate RPC method
1 parent aab8172 commit c9f0295

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

doc/release-notes-14468.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Wallet `generate` RPC method deprecated
2+
---------------------------------------
3+
4+
The wallet's `generate` RPC method has been deprecated and will be fully
5+
removed in v0.19.
6+
7+
`generate` is only used for testing. The RPC call reaches across multiple
8+
subsystems (wallet and mining), so is deprecated to simplify the wallet-node
9+
interface. Projects that are using `generate` for testing purposes should
10+
transition to using the `generatetoaddress` call, which does not require or use
11+
the wallet component. Calling `generatetoaddress` with an address returned by
12+
`getnewaddress` gives the same functionality as the old `generate` method.
13+
14+
To continue using `generate` in v0.18, restart bitcoind with the
15+
`-deprecatedrpc=generate` configuration.

src/wallet/rpcwallet.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,12 @@ UniValue generate(const JSONRPCRequest& request)
32893289
);
32903290
}
32913291

3292+
if (!IsDeprecatedRPCEnabled("generate")) {
3293+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "The wallet generate rpc method is deprecated and will be fully removed in v0.19. "
3294+
"To use generate in v0.18, restart bitcoind with -deprecatedrpc=generate.\n"
3295+
"Clients should transition to using the node rpc method generatetoaddress\n");
3296+
}
3297+
32923298
int num_generate = request.params[0].get_int();
32933299
uint64_t max_tries = 1000000;
32943300
if (!request.params[1].isNull()) {

test/functional/rpc_deprecated.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test deprecation of RPC calls."""
66
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import assert_raises_rpc_error
78

89
class DeprecatedRpcTest(BitcoinTestFramework):
910
def set_test_params(self):
1011
self.num_nodes = 2
1112
self.setup_clean_chain = True
12-
self.extra_args = [[], ["-deprecatedrpc=validateaddress"]]
13+
self.extra_args = [[], ["-deprecatedrpc=generate"]]
14+
15+
def skip_test_if_missing_module(self):
16+
# The generate RPC method requires the wallet to be compiled
17+
self.skip_if_no_wallet()
1318

1419
def run_test(self):
1520
# This test should be used to verify correct behaviour of deprecated
@@ -18,7 +23,10 @@ def run_test(self):
1823
# self.log.info("Make sure that -deprecatedrpc=createmultisig allows it to take addresses")
1924
# assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, [self.nodes[0].getnewaddress()])
2025
# self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
21-
pass
26+
27+
self.log.info("Test generate RPC")
28+
assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
29+
self.nodes[1].generate(1)
2230

2331
if __name__ == '__main__':
2432
DeprecatedRpcTest().main()

0 commit comments

Comments
 (0)