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-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 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 <init.h> | #include <init.h> | ||||
#include <interfaces/chain.h> | |||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <rpc/mining.h> | #include <rpc/mining.h> | ||||
#include <rpc/misc.h> | #include <rpc/misc.h> | ||||
#include <rpc/rawtransaction.h> | #include <rpc/rawtransaction.h> | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The account bitcoin address\n" | "\"address\" (string) The account bitcoin address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaccountaddress", "") + | HelpExampleCli("getaccountaddress", "") + | ||||
HelpExampleCli("getaccountaddress", "\"\"") + | HelpExampleCli("getaccountaddress", "\"\"") + | ||||
HelpExampleCli("getaccountaddress", "\"myaccount\"") + | HelpExampleCli("getaccountaddress", "\"myaccount\"") + | ||||
HelpExampleRpc("getaccountaddress", "\"myaccount\"")); | HelpExampleRpc("getaccountaddress", "\"myaccount\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// Parse the account first so we don't generate a key if there's an error | // Parse the account first so we don't generate a key if there's an error | ||||
std::string account = LabelFromValue(request.params[0]); | std::string account = LabelFromValue(request.params[0]); | ||||
UniValue ret(UniValue::VSTR); | UniValue ret(UniValue::VSTR); | ||||
ret = EncodeDestination(GetLabelDestination(pwallet, account), config); | ret = EncodeDestination(GetLabelDestination(pwallet, account), config); | ||||
return ret; | return ret; | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"\"accountname\" (string) the account address\n" | "\"accountname\" (string) the account address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaccount", | HelpExampleCli("getaccount", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | ||||
HelpExampleRpc("getaccount", | HelpExampleRpc("getaccount", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"the given account\n" | "the given account\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaddressesbyaccount", "\"tabby\"") + | HelpExampleCli("getaddressesbyaccount", "\"tabby\"") + | ||||
HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")); | HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string strAccount = LabelFromValue(request.params[0]); | std::string strAccount = LabelFromValue(request.params[0]); | ||||
// Find all addresses that have the given account | // Find all addresses that have the given account | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const std::pair<const CTxDestination, CAddressBookData> &item : | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
const CTxDestination &dest = item.first; | const CTxDestination &dest = item.first; | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
"dd\", 0.1, \"donation\", \"seans " | "dd\", 0.1, \"donation\", \"seans " | ||||
"outpost\"")); | "outpost\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | ||||
} | } | ||||
// Amount | // Amount | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
HelpExampleCli("listaddressgroupings", "") + | HelpExampleCli("listaddressgroupings", "") + | ||||
HelpExampleRpc("listaddressgroupings", "")); | HelpExampleRpc("listaddressgroupings", "")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
UniValue jsonGroupings(UniValue::VARR); | UniValue jsonGroupings(UniValue::VARR); | ||||
std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | ||||
for (const std::set<CTxDestination> &grouping : | for (const std::set<CTxDestination> &grouping : | ||||
pwallet->GetAddressGroupings()) { | pwallet->GetAddressGroupings()) { | ||||
UniValue jsonGrouping(UniValue::VARR); | UniValue jsonGrouping(UniValue::VARR); | ||||
for (const CTxDestination &address : grouping) { | for (const CTxDestination &address : grouping) { | ||||
UniValue addressInfo(UniValue::VARR); | UniValue addressInfo(UniValue::VARR); | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2) { | ||||
"XX\" \"signature\" \"my " | "XX\" \"signature\" \"my " | ||||
"message\"") + | "message\"") + | ||||
"\nAs json rpc\n" + | "\nAs json rpc\n" + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"signmessage", | "signmessage", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
std::string strMessage = request.params[1].get_str(); | std::string strMessage = request.params[1].get_str(); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(strAddress, config.GetChainParams()); | DecodeDestination(strAddress, config.GetChainParams()); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleRpc("getreceivedbyaddress", | HelpExampleRpc("getreceivedbyaddress", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// Bitcoin address | // Bitcoin address | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")); | HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Get the set of pub keys assigned to label | // Get the set of pub keys assigned to label | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | if (request.fHelp || (request.params.size() > 3)) { | ||||
HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a json rpc call\n" + | HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("getbalance", "\"*\", 6")); | HelpExampleRpc("getbalance", "\"*\", 6")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
const UniValue &account_value = request.params[0]; | const UniValue &account_value = request.params[0]; | ||||
int min_depth = 0; | int min_depth = 0; | ||||
if (IsDeprecatedRPCEnabled(gArgs, "accounts") && !account_value.isNull()) { | if (IsDeprecatedRPCEnabled(gArgs, "accounts") && !account_value.isNull()) { | ||||
// Default min_depth to 1 when an account is provided. | // Default min_depth to 1 when an account is provided. | ||||
min_depth = 1; | min_depth = 1; | ||||
} | } | ||||
Show All 39 Lines | if (request.fHelp || request.params.size() > 0) { | ||||
"getunconfirmedbalance\n" | "getunconfirmedbalance\n" | ||||
"Returns the server's total unconfirmed balance\n"); | "Returns the server's total unconfirmed balance\n"); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | ||||
} | } | ||||
static UniValue movecmd(const Config &config, const JSONRPCRequest &request) { | static UniValue movecmd(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(); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
HelpExampleCli("move", | HelpExampleCli("move", | ||||
"\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") + | "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") + | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"move", | "move", | ||||
"\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")); | "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string strFrom = LabelFromValue(request.params[0]); | std::string strFrom = LabelFromValue(request.params[0]); | ||||
std::string strTo = LabelFromValue(request.params[1]); | std::string strTo = LabelFromValue(request.params[1]); | ||||
Amount nAmount = AmountFromValue(request.params[2]); | Amount nAmount = AmountFromValue(request.params[2]); | ||||
if (nAmount <= Amount::zero()) { | if (nAmount <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
} | } | ||||
if (!request.params[3].isNull()) { | if (!request.params[3].isNull()) { | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
"\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | ||||
"0.01, 6, \"donation\", \"seans outpost\"")); | "0.01, 6, \"donation\", \"seans outpost\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error(help_text); | throw std::runtime_error(help_text); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (pwallet->GetBroadcastTransactions() && !g_connman) { | if (pwallet->GetBroadcastTransactions() && !g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && | if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
"\nAs json rpc call\n" + | "\nAs json rpc call\n" + | ||||
HelpExampleRpc("addmultisigaddress", | HelpExampleRpc("addmultisigaddress", | ||||
"2, " | "2, " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | ||||
throw std::runtime_error(msg); | throw std::runtime_error(msg); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string label; | std::string label; | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
label = LabelFromValue(request.params[2]); | label = LabelFromValue(request.params[2]); | ||||
} | } | ||||
int required = request.params[0].get_int(); | int required = request.params[0].get_int(); | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
"listreceivedbyaddress", | "listreceivedbyaddress", | ||||
"6, true, true, \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")); | "6, true, true, \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
return ListReceived(config, pwallet, request.params, false); | return ListReceived(config, pwallet, request.params, false); | ||||
} | } | ||||
static UniValue listreceivedbylabel(const Config &config, | static UniValue listreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | 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(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 3) { | ||||
HelpExampleCli("listreceivedbylabel", "6 true") + | HelpExampleCli("listreceivedbylabel", "6 true") + | ||||
HelpExampleRpc("listreceivedbylabel", "6, true, true")); | HelpExampleRpc("listreceivedbylabel", "6, true, true")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
return ListReceived(config, pwallet, request.params, true); | return ListReceived(config, pwallet, request.params, true); | ||||
} | } | ||||
static void MaybePushAddress(UniValue &entry, const CTxDestination &dest) { | static void MaybePushAddress(UniValue &entry, const CTxDestination &dest) { | ||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
entry.pushKV("address", EncodeDestination(dest, GetConfig())); | entry.pushKV("address", EncodeDestination(dest, GetConfig())); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 301 Lines • ▼ Show 20 Lines | UniValue listtransactions(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 4) { | if (request.fHelp || request.params.size() > 4) { | ||||
throw std::runtime_error(help_text); | throw std::runtime_error(help_text); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string strAccount = "*"; | std::string strAccount = "*"; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
strAccount = request.params[0].get_str(); | strAccount = request.params[0].get_str(); | ||||
if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && strAccount != "*") { | if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && strAccount != "*") { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Dummy value must be set to \"*\""); | "Dummy value must be set to \"*\""); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 2) { | ||||
HelpExampleCli("listaccounts", "6") + "\nAs json rpc call\n" + | HelpExampleCli("listaccounts", "6") + "\nAs json rpc call\n" + | ||||
HelpExampleRpc("listaccounts", "6")); | HelpExampleRpc("listaccounts", "6")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
nMinDepth = request.params[0].get_int(); | nMinDepth = request.params[0].get_int(); | ||||
} | } | ||||
isminefilter includeWatchonly = ISMINE_SPENDABLE; | isminefilter includeWatchonly = ISMINE_SPENDABLE; | ||||
if (!request.params[1].isNull() && request.params[1].get_bool()) { | if (!request.params[1].isNull() && request.params[1].get_bool()) { | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
"5ef753ee9a7d38571037cdb1a57f663ad" | "5ef753ee9a7d38571037cdb1a57f663ad" | ||||
"\", 6")); | "\", 6")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// Block index of the specified block or the common ancestor, if the block | // Block index of the specified block or the common ancestor, if the block | ||||
// provided was in a deactivated chain. | // provided was in a deactivated chain. | ||||
const CBlockIndex *pindex = nullptr; | const CBlockIndex *pindex = nullptr; | ||||
// Block index of the specified block, even if it's in a deactivated chain. | // Block index of the specified block, even if it's in a deactivated chain. | ||||
const CBlockIndex *paltindex = nullptr; | const CBlockIndex *paltindex = nullptr; | ||||
int target_confirms = 1; | int target_confirms = 1; | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"5b9345e16c5cf302fc80e9d5fbf5d48d" | "5b9345e16c5cf302fc80e9d5fbf5d48d" | ||||
"\"")); | "\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
TxId txid; | TxId txid; | ||||
txid.SetHex(request.params[0].get_str()); | txid.SetHex(request.params[0].get_str()); | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (!request.params[1].isNull() && request.params[1].get_bool()) { | if (!request.params[1].isNull() && request.params[1].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"e2115b9345e16c5cf302fc80e9d5f" | "e2115b9345e16c5cf302fc80e9d5f" | ||||
"bf5d48d\"")); | "bf5d48d\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
TxId txid; | TxId txid; | ||||
txid.SetHex(request.params[0].get_str()); | txid.SetHex(request.params[0].get_str()); | ||||
if (!pwallet->mapWallet.count(txid)) { | if (!pwallet->mapWallet.count(txid)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid or non-wallet transaction id"); | "Invalid or non-wallet transaction id"); | ||||
} | } | ||||
Show All 26 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
HelpExampleCli("backupwallet", "\"backup.dat\"") + | HelpExampleCli("backupwallet", "\"backup.dat\"") + | ||||
HelpExampleRpc("backupwallet", "\"backup.dat\"")); | HelpExampleRpc("backupwallet", "\"backup.dat\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::string strDest = request.params[0].get_str(); | std::string strDest = request.params[0].get_str(); | ||||
if (!pwallet->BackupWallet(strDest)) { | if (!pwallet->BackupWallet(strDest)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); | throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
Show All 21 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
HelpExampleRpc("keypoolrefill", "")); | HelpExampleRpc("keypoolrefill", "")); | ||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: Private keys are disabled for this wallet"); | "Error: Private keys are disabled for this wallet"); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by | // 0 is interpreted by TopUpKeyPool() as the default keypool size given by | ||||
// -keypool | // -keypool | ||||
unsigned int kpSize = 0; | unsigned int kpSize = 0; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
if (request.params[0].get_int() < 0) { | if (request.params[0].get_int() < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected valid size."); | "Invalid parameter, expected valid size."); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nUnlock the wallet for 60 seconds\n" + | "\nUnlock the wallet for 60 seconds\n" + | ||||
HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + | HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + | ||||
"\nLock the wallet again (before 60 seconds)\n" + | "\nLock the wallet again (before 60 seconds)\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" + | HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" + | ||||
HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")); | HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an unencrypted wallet, but " | "Error: running with an unencrypted wallet, but " | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | ||||
"2. \"newpassphrase\" (string) The new passphrase\n" | "2. \"newpassphrase\" (string) The new passphrase\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("walletpassphrasechange", | HelpExampleCli("walletpassphrasechange", | ||||
"\"old one\" \"new one\"") + | "\"old one\" \"new one\"") + | ||||
HelpExampleRpc("walletpassphrasechange", | HelpExampleRpc("walletpassphrasechange", | ||||
"\"old one\", \"new one\"")); | "\"old one\", \"new one\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an unencrypted wallet, but " | "Error: running with an unencrypted wallet, but " | ||||
"walletpassphrasechange was called."); | "walletpassphrasechange was called."); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { | ||||
HelpExampleCli("sendtoaddress", | HelpExampleCli("sendtoaddress", | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + | "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + | ||||
"\nClear the passphrase since we are done before 2 minutes is " | "\nClear the passphrase since we are done before 2 minutes is " | ||||
"up\n" + | "up\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" + | HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" + | ||||
HelpExampleRpc("walletlock", "")); | HelpExampleRpc("walletlock", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an unencrypted wallet, but " | "Error: running with an unencrypted wallet, but " | ||||
"walletlock was called."); | "walletlock was called."); | ||||
Show All 40 Lines | if (!pwallet->IsCrypted() && | ||||
HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + | HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + | ||||
"\nNow we can do something like sign\n" + | "\nNow we can do something like sign\n" + | ||||
HelpExampleCli("signmessage", "\"address\" \"test message\"") + | HelpExampleCli("signmessage", "\"address\" \"test message\"") + | ||||
"\nNow lock the wallet again by removing the passphrase\n" + | "\nNow lock the wallet again by removing the passphrase\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs a json rpc call\n" + | HelpExampleCli("walletlock", "") + "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("encryptwallet", "\"my pass phrase\"")); | HelpExampleRpc("encryptwallet", "\"my pass phrase\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
if (pwallet->IsCrypted()) { | if (pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an encrypted wallet, but " | "Error: running with an encrypted wallet, but " | ||||
"encryptwallet was called."); | "encryptwallet was called."); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"")); | ",\\\"vout\\\":1}]\"")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
RPCTypeCheckArgument(request.params[0], UniValue::VBOOL); | RPCTypeCheckArgument(request.params[0], UniValue::VBOOL); | ||||
bool fUnlock = request.params[0].get_bool(); | bool fUnlock = request.params[0].get_bool(); | ||||
if (request.params[1].isNull()) { | if (request.params[1].isNull()) { | ||||
if (fUnlock) { | if (fUnlock) { | ||||
pwallet->UnlockAllCoins(); | pwallet->UnlockAllCoins(); | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 0) { | ||||
HelpExampleCli("lockunspent", "true " | HelpExampleCli("lockunspent", "true " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nAs a json rpc call\n" + HelpExampleRpc("listlockunspent", "")); | "\nAs a json rpc call\n" + HelpExampleRpc("listlockunspent", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
std::vector<COutPoint> vOutpts; | std::vector<COutPoint> vOutpts; | ||||
pwallet->ListLockedCoins(vOutpts); | pwallet->ListLockedCoins(vOutpts); | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const COutPoint &output : vOutpts) { | for (const COutPoint &output : vOutpts) { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
Show All 27 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"/kB\n" | "/kB\n" | ||||
"\nResult\n" | "\nResult\n" | ||||
"true|false (boolean) Returns true if successful\n" | "true|false (boolean) Returns true if successful\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("settxfee", "0.00001") + | HelpExampleCli("settxfee", "0.00001") + | ||||
HelpExampleRpc("settxfee", "0.00001")); | HelpExampleRpc("settxfee", "0.00001")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
Amount nAmount = AmountFromValue(request.params[0]); | Amount nAmount = AmountFromValue(request.params[0]); | ||||
CFeeRate tx_fee_rate(nAmount, 1000); | CFeeRate tx_fee_rate(nAmount, 1000); | ||||
if (tx_fee_rate == CFeeRate()) { | if (tx_fee_rate == CFeeRate()) { | ||||
// automatic selection | // automatic selection | ||||
} else if (tx_fee_rate < ::minRelayTxFee) { | } else if (tx_fee_rate < ::minRelayTxFee) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
HelpExampleCli("getwalletinfo", "") + | HelpExampleCli("getwalletinfo", "") + | ||||
HelpExampleRpc("getwalletinfo", "")); | HelpExampleRpc("getwalletinfo", "")); | ||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | ||||
obj.pushKV("walletname", pwallet->GetName()); | obj.pushKV("walletname", pwallet->GetName()); | ||||
obj.pushKV("walletversion", pwallet->GetVersion()); | obj.pushKV("walletversion", pwallet->GetVersion()); | ||||
obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | ||||
obj.pushKV("unconfirmed_balance", | obj.pushKV("unconfirmed_balance", | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | static UniValue resendwallettransactions(const Config &config, | ||||
} | } | ||||
if (!g_connman) { | if (!g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
if (!pwallet->GetBroadcastTransactions()) { | if (!pwallet->GetBroadcastTransactions()) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet transaction " | throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet transaction " | ||||
"broadcasting is disabled with " | "broadcasting is disabled with " | ||||
"-walletbroadcast"); | "-walletbroadcast"); | ||||
} | } | ||||
std::vector<uint256> txids = | std::vector<uint256> txids = | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | static UniValue listunspent(const Config &config, | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
UniValue results(UniValue::VARR); | UniValue results(UniValue::VARR); | ||||
std::vector<COutput> vecOutputs; | std::vector<COutput> vecOutputs; | ||||
{ | { | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, | pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, | ||||
nMinimumAmount, nMaximumAmount, | nMinimumAmount, nMaximumAmount, | ||||
nMinimumSumAmount, nMaximumCount, nMinDepth, | nMinimumSumAmount, nMaximumCount, nMinDepth, | ||||
nMaxDepth); | nMaxDepth); | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | RPCTypeCheck(request.params, | ||||
{UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); | {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
// Sign the transaction | // Sign the transaction | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
return SignTransaction(pwallet->chain(), mtx, request.params[1], pwallet, | return SignTransaction(pwallet->chain(), mtx, request.params[1], pwallet, | ||||
false, request.params[2]); | false, request.params[2]); | ||||
} | } | ||||
UniValue generate(const Config &config, const JSONRPCRequest &request) { | UniValue generate(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(); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (!reserver.reserve()) { | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Wallet is currently rescanning. Abort existing rescan or wait."); | "Wallet is currently rescanning. Abort existing rescan or wait."); | ||||
} | } | ||||
CBlockIndex *pindexStart = nullptr; | CBlockIndex *pindexStart = nullptr; | ||||
CBlockIndex *pindexStop = nullptr; | CBlockIndex *pindexStop = nullptr; | ||||
CBlockIndex *pChainTip = nullptr; | CBlockIndex *pChainTip = nullptr; | ||||
{ | { | ||||
LOCK(cs_main); | auto locked_chain = pwallet->chain().lock(); | ||||
pindexStart = chainActive.Genesis(); | pindexStart = chainActive.Genesis(); | ||||
pChainTip = chainActive.Tip(); | pChainTip = chainActive.Tip(); | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
pindexStart = chainActive[request.params[0].get_int()]; | pindexStart = chainActive[request.params[0].get_int()]; | ||||
if (!pindexStart) { | if (!pindexStart) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid start_height"); | "Invalid start_height"); | ||||
Show All 10 Lines | CBlockIndex *pChainTip = nullptr; | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"stop_height must be greater than start_height"); | "stop_height must be greater than start_height"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// We can't rescan beyond non-pruned blocks, stop and throw an error | // We can't rescan beyond non-pruned blocks, stop and throw an error | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
LOCK(cs_main); | auto locked_chain = pwallet->chain().lock(); | ||||
CBlockIndex *block = pindexStop ? pindexStop : pChainTip; | CBlockIndex *block = pindexStop ? pindexStop : pChainTip; | ||||
while (block && block->nHeight >= pindexStart->nHeight) { | while (block && block->nHeight >= pindexStart->nHeight) { | ||||
if (!block->nStatus.hasData()) { | if (!block->nStatus.hasData()) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, | throw JSONRPCError(RPC_MISC_ERROR, | ||||
"Can't rescan beyond pruned data. Use RPC " | "Can't rescan beyond pruned data. Use RPC " | ||||
"call getblockchaininfo to determine your " | "call getblockchaininfo to determine your " | ||||
"pruned height."); | "pruned height."); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Cannot set a HD seed to a wallet with private keys disabled"); | "Cannot set a HD seed to a wallet with private keys disabled"); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | |||||
// Do not do anything to non-HD wallets | // Do not do anything to non-HD wallets | ||||
if (!pwallet->CanSupportFeature(FEATURE_HD)) { | if (!pwallet->CanSupportFeature(FEATURE_HD)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Cannot set a HD seed on a non-HD wallet. Start with " | "Cannot set a HD seed on a non-HD wallet. Start with " | ||||
"-upgradewallet in order to upgrade a non-HD wallet to HD"); | "-upgradewallet in order to upgrade a non-HD wallet to HD"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 400 Lines • Show Last 20 Lines |