Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <chainparams.h> // for GetConsensus. | #include <chainparams.h> // for GetConsensus. | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <rpc/mining.h> | |||||
#include <rpc/rawtransaction_util.h> | #include <rpc/rawtransaction_util.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <util/bip32.h> | #include <util/bip32.h> | ||||
#include <util/error.h> | #include <util/error.h> | ||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
▲ Show 20 Lines • Show All 3,825 Lines • ▼ Show 20 Lines | for (const CTxIn &txin : mtx.vin) { | ||||
coins[txin.prevout]; | coins[txin.prevout]; | ||||
} | } | ||||
pwallet->chain().findCoins(coins); | pwallet->chain().findCoins(coins); | ||||
return SignTransaction(mtx, request.params[1], pwallet, coins, false, | return SignTransaction(mtx, request.params[1], pwallet, coins, false, | ||||
request.params[2]); | request.params[2]); | ||||
} | } | ||||
UniValue generate(const Config &config, const JSONRPCRequest &request) { | |||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | |||||
return NullUniValue; | |||||
} | |||||
RPCHelpMan{ | |||||
"generate", | |||||
"\nMine up to nblocks blocks immediately (before the RPC call returns) " | |||||
"to an address in the wallet.\n", | |||||
{ | |||||
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, | |||||
"How many blocks are generated immediately."}, | |||||
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", | |||||
"How many iterations to try."}, | |||||
}, | |||||
RPCResult{"[ blockhashes ] (array) hashes of blocks generated\n"}, | |||||
RPCExamples{"\nGenerate 11 blocks\n" + | |||||
HelpExampleCli("generate", "11")}} | |||||
.Check(request); | |||||
if (!IsDeprecatedRPCEnabled(gArgs, "generate")) { | |||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, | |||||
"The wallet generate rpc method is deprecated and " | |||||
"will be fully removed in v0.22. " | |||||
"To use generate in v0.21, restart bitcoind with " | |||||
"-deprecatedrpc=generate.\n" | |||||
"Clients should transition to using the node rpc " | |||||
"method generatetoaddress\n"); | |||||
} | |||||
int num_generate = request.params[0].get_int(); | |||||
uint64_t max_tries = 1000000; | |||||
if (!request.params[1].isNull()) { | |||||
max_tries = request.params[1].get_int(); | |||||
} | |||||
std::shared_ptr<CReserveScript> coinbase_script; | |||||
pwallet->GetScriptForMining(coinbase_script); | |||||
// If the keypool is exhausted, no script is returned at all. Catch this. | |||||
if (!coinbase_script) { | |||||
throw JSONRPCError( | |||||
RPC_WALLET_KEYPOOL_RAN_OUT, | |||||
"Error: Keypool ran out, please call keypoolrefill first"); | |||||
} | |||||
// throw an error if no script was provided | |||||
if (coinbase_script->reserveScript.empty()) { | |||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); | |||||
} | |||||
return generateBlocks(config, coinbase_script, num_generate, max_tries, | |||||
true); | |||||
} | |||||
UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 824 Lines • ▼ Show 20 Lines | static UniValue walletcreatefundedpsbt(const Config &config, | ||||
result.pushKV("changepos", change_position); | result.pushKV("changepos", change_position); | ||||
return result; | return result; | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "generating", "generate", generate, {"nblocks","maxtries"} }, | |||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, {"txid"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label"} }, | ||||
{ "wallet", "backupwallet", backupwallet, {"destination"} }, | { "wallet", "backupwallet", backupwallet, {"destination"} }, | ||||
{ "wallet", "createwallet", createwallet, {"wallet_name", "disable_private_keys", "blank", "passphrase", "avoid_reuse"} }, | { "wallet", "createwallet", createwallet, {"wallet_name", "disable_private_keys", "blank", "passphrase", "avoid_reuse"} }, | ||||
{ "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | ||||
{ "wallet", "getaddressesbylabel", getaddressesbylabel, {"label"} }, | { "wallet", "getaddressesbylabel", getaddressesbylabel, {"label"} }, | ||||
{ "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | { "wallet", "getaddressinfo", getaddressinfo, {"address"} }, | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |