Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleRpc("getnewaddress", "")); | HelpExampleRpc("getnewaddress", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Parse the label first so we don't generate a key if there's an error | // Parse the label first so we don't generate a key if there's an error | ||||
std::string label; | std::string label; | ||||
if (request.params.size() > 0) { | if (!request.params[0].isNull()) { | ||||
label = LabelFromValue(request.params[0]); | label = LabelFromValue(request.params[0]); | ||||
} | } | ||||
if (!pwallet->IsLocked()) { | if (!pwallet->IsLocked()) { | ||||
pwallet->TopUpKeyPool(); | pwallet->TopUpKeyPool(); | ||||
} | } | ||||
// Generate a new key that is added to wallet | // Generate a new key that is added to wallet | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
static UniValue getrawchangeaddress(const Config &config, | static UniValue getrawchangeaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getrawchangeaddress\n" | "getrawchangeaddress\n" | ||||
"\nReturns a new Bitcoin address, for receiving change.\n" | "\nReturns a new Bitcoin address, for receiving change.\n" | ||||
"This is for use with raw transactions, NOT normal use.\n" | "This is for use with raw transactions, NOT normal use.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The address\n" | "\"address\" (string) The address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getrawchangeaddress", "") + | HelpExampleCli("getrawchangeaddress", "") + | ||||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | |||||
static UniValue listaddressgroupings(const Config &config, | static UniValue listaddressgroupings(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listaddressgroupings\n" | "listaddressgroupings\n" | ||||
"\nLists groups of addresses which have had their common " | "\nLists groups of addresses which have had their common " | ||||
"ownership\n" | "ownership\n" | ||||
"made public by common use as inputs or as the resulting change\n" | "made public by common use as inputs or as the resulting change\n" | ||||
"in past transactions\n" | "in past transactions\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForDestination(dest); | CScript scriptPubKey = GetScriptForDestination(dest); | ||||
if (!IsMine(*pwallet, scriptPubKey)) { | if (!IsMine(*pwallet, scriptPubKey)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); | throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); | ||||
} | } | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | UniValue getreceivedbylabel(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(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 1) { | 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 | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label); | std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label); | ||||
// Tally | // Tally | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (request.params.size() == 0) { | ||||
return ValueFromAmount(pwallet->GetBalance()); | return ValueFromAmount(pwallet->GetBalance()); | ||||
} | } | ||||
const std::string *account = request.params[0].get_str() != "*" | const std::string *account = request.params[0].get_str() != "*" | ||||
? &request.params[0].get_str() | ? &request.params[0].get_str() | ||||
: nullptr; | : nullptr; | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 2 && request.params[2].get_bool()) { | if (!request.params[2].isNull() && request.params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
return ValueFromAmount( | return ValueFromAmount( | ||||
pwallet->GetLegacyBalance(filter, nMinDepth, account)); | pwallet->GetLegacyBalance(filter, nMinDepth, account)); | ||||
} | } | ||||
static UniValue getunconfirmedbalance(const Config &config, | static UniValue getunconfirmedbalance(const Config &config, | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | 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"); | ||||
} | } | ||||
std::string strAccount = LabelFromValue(request.params[0]); | std::string strAccount = LabelFromValue(request.params[0]); | ||||
UniValue sendTo = request.params[1].get_obj(); | UniValue sendTo = request.params[1].get_obj(); | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 2) { | if (!request.params[2].isNull()) { | ||||
nMinDepth = request.params[2].get_int(); | nMinDepth = request.params[2].get_int(); | ||||
} | } | ||||
mapValue_t mapValue; | mapValue_t mapValue; | ||||
if (request.params.size() > 3 && !request.params[3].isNull() && | if (request.params.size() > 3 && !request.params[3].isNull() && | ||||
!request.params[3].get_str().empty()) { | !request.params[3].get_str().empty()) { | ||||
mapValue["comment"] = request.params[3].get_str(); | mapValue["comment"] = request.params[3].get_str(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | tallyitem() { | ||||
fIsWatchonly = false; | fIsWatchonly = false; | ||||
} | } | ||||
}; | }; | ||||
UniValue ListReceived(const Config &config, CWallet *const pwallet, | UniValue ListReceived(const Config &config, CWallet *const pwallet, | ||||
const UniValue ¶ms, bool by_label) { | const UniValue ¶ms, bool by_label) { | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (params.size() > 0) { | if (!params[0].isNull()) { | ||||
nMinDepth = params[0].get_int(); | nMinDepth = params[0].get_int(); | ||||
} | } | ||||
// Whether to include empty labels | // Whether to include empty labels | ||||
bool fIncludeEmpty = false; | bool fIncludeEmpty = false; | ||||
if (params.size() > 1) { | if (!params[1].isNull()) { | ||||
fIncludeEmpty = params[1].get_bool(); | fIncludeEmpty = params[1].get_bool(); | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (!params[2].isNull() && params[2].get_bool()) { | if (!params[2].isNull() && params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | static UniValue listtransactions(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(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strAccount = "*"; | std::string strAccount = "*"; | ||||
if (request.params.size() > 0) { | if (!request.params[0].isNull()) { | ||||
strAccount = request.params[0].get_str(); | strAccount = request.params[0].get_str(); | ||||
} | } | ||||
int nCount = 10; | int nCount = 10; | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
nCount = request.params[1].get_int(); | nCount = request.params[1].get_int(); | ||||
} | } | ||||
int nFrom = 0; | int nFrom = 0; | ||||
if (request.params.size() > 2) { | if (!request.params[2].isNull()) { | ||||
nFrom = request.params[2].get_int(); | nFrom = request.params[2].get_int(); | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 3 && request.params[3].get_bool()) { | if (!request.params[3].isNull() && request.params[3].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
if (nCount < 0) { | if (nCount < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); | ||||
} | } | ||||
if (nFrom < 0) { | if (nFrom < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | |||||
static UniValue listsinceblock(const Config &config, | static UniValue listsinceblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp) { | if (request.fHelp || request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listsinceblock ( \"blockhash\" target_confirmations " | "listsinceblock ( \"blockhash\" target_confirmations " | ||||
"include_watchonly)\n" | "include_watchonly)\n" | ||||
"\nGet all transactions in blocks since block [blockhash], or all " | "\nGet all transactions in blocks since block [blockhash], or all " | ||||
"transactions if omitted\n" | "transactions if omitted\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"blockhash\" (string, optional) The block hash to " | "1. \"blockhash\" (string, optional) The block hash to " | ||||
"list transactions since\n" | "list transactions since\n" | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
const CBlockIndex *pindex = nullptr; | const CBlockIndex *pindex = nullptr; | ||||
int target_confirms = 1; | int target_confirms = 1; | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 0) { | if (!request.params[0].isNull()) { | ||||
uint256 blockId; | uint256 blockId; | ||||
blockId.SetHex(request.params[0].get_str()); | blockId.SetHex(request.params[0].get_str()); | ||||
BlockMap::iterator it = mapBlockIndex.find(blockId); | BlockMap::iterator it = mapBlockIndex.find(blockId); | ||||
if (it != mapBlockIndex.end()) { | if (it != mapBlockIndex.end()) { | ||||
pindex = it->second; | pindex = it->second; | ||||
if (chainActive[pindex->nHeight] != pindex) { | if (chainActive[pindex->nHeight] != pindex) { | ||||
// the block being asked for is a part of a deactivated chain; | // the block being asked for is a part of a deactivated chain; | ||||
// we don't want to depend on its perceived height in the block | // we don't want to depend on its perceived height in the block | ||||
// chain, we want to instead use the last common ancestor | // chain, we want to instead use the last common ancestor | ||||
pindex = chainActive.FindFork(pindex); | pindex = chainActive.FindFork(pindex); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
target_confirms = request.params[1].get_int(); | target_confirms = request.params[1].get_int(); | ||||
if (target_confirms < 1) { | if (target_confirms < 1) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); | ||||
} | } | ||||
} | } | ||||
if (request.params.size() > 2 && request.params[2].get_bool()) { | if (request.params.size() > 2 && request.params[2].get_bool()) { | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | static UniValue gettransaction(const Config &config, | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, 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.size() > 1 && 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; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
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 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
HelpExampleRpc("keypoolrefill", "")); | HelpExampleRpc("keypoolrefill", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, 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.size() > 0) { | 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."); | ||||
} | } | ||||
kpSize = (unsigned int)request.params[0].get_int(); | kpSize = (unsigned int)request.params[0].get_int(); | ||||
} | } | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
▲ Show 20 Lines • Show All 970 Lines • ▼ Show 20 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
int changePosition = -1; | int changePosition = -1; | ||||
bool lockUnspents = false; | bool lockUnspents = false; | ||||
bool reserveChangeKey = true; | bool reserveChangeKey = true; | ||||
UniValue subtractFeeFromOutputs; | UniValue subtractFeeFromOutputs; | ||||
std::set<int> setSubtractFeeFromOutputs; | std::set<int> setSubtractFeeFromOutputs; | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
if (request.params[1].type() == UniValue::VBOOL) { | if (request.params[1].type() == UniValue::VBOOL) { | ||||
// backward compatibility bool only fallback | // backward compatibility bool only fallback | ||||
coinControl.fAllowWatchOnly = request.params[1].get_bool(); | coinControl.fAllowWatchOnly = request.params[1].get_bool(); | ||||
} else { | } else { | ||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); | ||||
UniValue options = request.params[1]; | UniValue options = request.params[1]; | ||||
▲ Show 20 Lines • Show All 396 Lines • Show Last 20 Lines |