Skip to content

Commit d35e91c

Browse files
MarcoFalkevijaydasmp
authored andcommitted
Merge bitcoin#15492: [rpc] remove deprecated generate method
07cae52 [wallet] remove unused GetScriptForMining (Sjors Provoost) 8bb3e4c [rpc] remove deprecated generate method (Sjors Provoost) Pull request description: As announced in v0.18, the wallet generate rpc method is deprecated and will be fully removed in v0.19. Clients should transition to using the node rpc method `generatetoaddress`. Tree-SHA512: 9e5e913b59f3e18440b2b7b356124c7b87ad19f81a1ab6ada06a6c396b84e734895465f569296f1ba8c12abf74863bab5fd77765c9e806c239713aa83a59485f
1 parent 40ce137 commit d35e91c

File tree

5 files changed

+11
-78
lines changed

5 files changed

+11
-78
lines changed

doc/release-notes-15492.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Deprecated or removed RPCs
2+
--------------------------
3+
- The wallet's `generate` RPC method was deprecated in v0.18 and has now
4+
been fully removed. This RPC is only used for
5+
testing, but its implementation reached across multiple subsystems
6+
(wallet and mining), so it has been removed to simplify the
7+
wallet-node interface. Projects that are using `generate` for testing
8+
purposes should transition to using the `generatetoaddress` RPC, which
9+
does not require or use the wallet component. Calling
10+
`generatetoaddress` with an address returned by the `getnewaddress`
11+
RPC gives the same functionality as the old `generate` RPC.

src/rpc/client.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
3030
{
3131
{ "setmocktime", 0, "timestamp" },
3232
#if ENABLE_MINER
33-
{ "generate", 0, "nblocks" },
34-
{ "generate", 1, "maxtries" },
3533
{ "generatetoaddress", 0, "nblocks" },
3634
{ "generatetoaddress", 2, "maxtries" },
3735
#endif // ENABLE_MINER

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <node/transaction.h>
1818
#include <policy/feerate.h>
1919
#include <policy/fees.h>
20-
#include <rpc/mining.h>
2120
#include <rpc/rawtransaction.h>
2221
#include <rpc/server.h>
2322
#include <rpc/util.h>
@@ -3533,63 +3532,6 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
35333532
return SignTransaction(pwallet->chain(), mtx, request.params[1], pwallet, false, request.params[2]);
35343533
}
35353534

3536-
#if ENABLE_MINER
3537-
UniValue generate(const JSONRPCRequest& request)
3538-
{
3539-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
3540-
CWallet* const pwallet = wallet.get();
3541-
3542-
3543-
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
3544-
return NullUniValue;
3545-
}
3546-
3547-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
3548-
throw std::runtime_error(
3549-
RPCHelpMan{"generate",
3550-
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n",
3551-
{
3552-
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
3553-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
3554-
},
3555-
RPCResult{
3556-
"[ blockhashes ] (array) hashes of blocks generated\n"
3557-
},
3558-
RPCExamples{
3559-
"\nGenerate 11 blocks\n"
3560-
+ HelpExampleCli("generate", "11")
3561-
},
3562-
}.ToString());
3563-
}
3564-
3565-
int num_generate = request.params[0].get_int();
3566-
uint64_t max_tries = 1000000;
3567-
if (!request.params[1].isNull()) {
3568-
max_tries = request.params[1].get_int();
3569-
}
3570-
3571-
std::shared_ptr<CReserveScript> coinbase_script;
3572-
pwallet->GetScriptForMining(coinbase_script);
3573-
3574-
// If the keypool is exhausted, no script is returned at all. Catch this.
3575-
if (!coinbase_script) {
3576-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
3577-
}
3578-
3579-
//throw an error if no script was provided
3580-
if (coinbase_script->reserveScript.empty()) {
3581-
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
3582-
}
3583-
3584-
return generateBlocks(coinbase_script, num_generate, max_tries, true);
3585-
}
3586-
#else
3587-
UniValue generate(const JSONRPCRequest& request)
3588-
{
3589-
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This call is not available because RPC miner isn't compiled");
3590-
}
3591-
#endif //ENABLE_MINING
3592-
35933535
static UniValue rescanblockchain(const JSONRPCRequest& request)
35943536
{
35953537
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -4205,11 +4147,6 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
42054147
static const CRPCCommand commands[] =
42064148
{ // category name actor (function) argNames
42074149
// --------------------- ------------------------ ----------------------- ----------
4208-
#if ENABLE_MINER
4209-
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
4210-
#else
4211-
{ "hidden", "generate", &generate, {"nblocks","maxtries"} }, // Hidden as it isn't functional, just an error to let people know if miner isn't compiled
4212-
#endif //ENABLE_MINER
42134150
{ "hidden", "instantsendtoaddress", &instantsendtoaddress, {} },
42144151
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
42154152
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options"} },

src/wallet/wallet.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,17 +4600,6 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
46004600
}
46014601
}
46024602

4603-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4604-
{
4605-
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
4606-
CPubKey pubkey;
4607-
if (!rKey->GetReservedKey(pubkey, false))
4608-
return;
4609-
4610-
script = rKey;
4611-
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
4612-
}
4613-
46144603
void CWallet::LockCoin(const COutPoint& output)
46154604
{
46164605
AssertLockHeld(cs_wallet); // setLockedCoins

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,6 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11481148

11491149
const std::string& GetLabelName(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
11501150

1151-
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1152-
11531151
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
11541152
{
11551153
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool

0 commit comments

Comments
 (0)