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-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 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 "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" // for GetConsensus. | #include "chainparams.h" // for GetConsensus. | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "core_io.h" | #include "core_io.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "net.h" | #include "net.h" | ||||
#include "policy/fees.h" | |||||
#include "policy/policy.h" | |||||
#include "rpc/mining.h" | |||||
#include "rpc/misc.h" | #include "rpc/misc.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "timedata.h" | #include "timedata.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "wallet.h" | #include "wallet.h" | ||||
#include "walletdb.h" | #include "walletdb.h" | ||||
▲ Show 20 Lines • Show All 3,333 Lines • ▼ Show 20 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.push_back(Pair("hex", EncodeHexTx(tx))); | result.push_back(Pair("hex", EncodeHexTx(tx))); | ||||
result.push_back(Pair("changepos", changePosition)); | result.push_back(Pair("changepos", changePosition)); | ||||
result.push_back(Pair("fee", ValueFromAmount(nFeeOut))); | result.push_back(Pair("fee", ValueFromAmount(nFeeOut))); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue generate(const Config &config, const JSONRPCRequest &request) { | |||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | |||||
return NullUniValue; | |||||
} | |||||
if (request.fHelp || request.params.size() < 1 || | |||||
request.params.size() > 2) { | |||||
throw std::runtime_error( | |||||
"generate nblocks ( maxtries )\n" | |||||
"\nMine up to nblocks blocks immediately (before the RPC call " | |||||
"returns) to an address in the wallet.\n" | |||||
"\nArguments:\n" | |||||
"1. nblocks (numeric, required) How many blocks are generated " | |||||
"immediately.\n" | |||||
"2. maxtries (numeric, optional) How many iterations to try " | |||||
"(default = 1000000).\n" | |||||
"\nResult:\n" | |||||
"[ blockhashes ] (array) hashes of blocks generated\n" | |||||
"\nExamples:\n" | |||||
"\nGenerate 11 blocks\n" + | |||||
HelpExampleCli("generate", "11")); | |||||
} | |||||
int num_generate = request.params[0].get_int(); | |||||
uint64_t max_tries = 1000000; | |||||
if (request.params.size() > 1 && !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); | |||||
} | |||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) okSafeMode | // category name actor (function) okSafeMode | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, false, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, false, {"hexstring","options"} }, | ||||
{ "hidden", "resendwallettransactions", resendwallettransactions, true, {} }, | { "hidden", "resendwallettransactions", resendwallettransactions, true, {} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, false, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, false, {"txid"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, true, {"nrequired","keys","account"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, true, {"nrequired","keys","account"} }, | ||||
Show All 25 Lines | static const CRPCCommand commands[] = { | ||||
{ "wallet", "sendmany", sendmany, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | { "wallet", "sendmany", sendmany, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | ||||
{ "wallet", "sendtoaddress", sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | { "wallet", "sendtoaddress", sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | ||||
{ "wallet", "setaccount", setaccount, true, {"address","account"} }, | { "wallet", "setaccount", setaccount, true, {"address","account"} }, | ||||
{ "wallet", "settxfee", settxfee, true, {"amount"} }, | { "wallet", "settxfee", settxfee, true, {"amount"} }, | ||||
{ "wallet", "signmessage", signmessage, true, {"address","message"} }, | { "wallet", "signmessage", signmessage, true, {"address","message"} }, | ||||
{ "wallet", "walletlock", walletlock, true, {} }, | { "wallet", "walletlock", walletlock, true, {} }, | ||||
{ "wallet", "walletpassphrasechange", walletpassphrasechange, true, {"oldpassphrase","newpassphrase"} }, | { "wallet", "walletpassphrasechange", walletpassphrasechange, true, {"oldpassphrase","newpassphrase"} }, | ||||
{ "wallet", "walletpassphrase", walletpassphrase, true, {"passphrase","timeout"} }, | { "wallet", "walletpassphrase", walletpassphrase, true, {"passphrase","timeout"} }, | ||||
{ "generating", "generate", &generate, true, {"nblocks","maxtries"} }, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterWalletRPCCommands(CRPCTable &t) { | void RegisterWalletRPCCommands(CRPCTable &t) { | ||||
if (GetBoolArg("-disablewallet", false)) { | if (GetBoolArg("-disablewallet", false)) { | ||||
return; | return; | ||||
} | } | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |