Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
void EnsureWalletIsUnlocked(CWallet *const pwallet) { | void EnsureWalletIsUnlocked(CWallet *const pwallet) { | ||||
if (pwallet->IsLocked()) { | if (pwallet->IsLocked()) { | ||||
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the " | throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the " | ||||
"wallet passphrase with " | "wallet passphrase with " | ||||
"walletpassphrase first."); | "walletpassphrase first."); | ||||
} | } | ||||
} | } | ||||
void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | static void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
int confirms = wtx.GetDepthInMainChain(); | int confirms = wtx.GetDepthInMainChain(); | ||||
entry.pushKV("confirmations", confirms); | entry.pushKV("confirmations", confirms); | ||||
if (wtx.IsCoinBase()) { | if (wtx.IsCoinBase()) { | ||||
entry.pushKV("generated", true); | entry.pushKV("generated", true); | ||||
} | } | ||||
if (confirms > 0) { | if (confirms > 0) { | ||||
entry.pushKV("blockhash", wtx.hashBlock.GetHex()); | entry.pushKV("blockhash", wtx.hashBlock.GetHex()); | ||||
entry.pushKV("blockindex", wtx.nIndex); | entry.pushKV("blockindex", wtx.nIndex); | ||||
Show All 12 Lines | static void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
entry.pushKV("time", wtx.GetTxTime()); | entry.pushKV("time", wtx.GetTxTime()); | ||||
entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | ||||
for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | ||||
entry.pushKV(item.first, item.second); | entry.pushKV(item.first, item.second); | ||||
} | } | ||||
} | } | ||||
std::string LabelFromValue(const UniValue &value) { | static std::string LabelFromValue(const UniValue &value) { | ||||
std::string label = value.get_str(); | std::string label = value.get_str(); | ||||
if (label == "*") { | if (label == "*") { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | ||||
} | } | ||||
return label; | return label; | ||||
} | } | ||||
static UniValue getnewaddress(const Config &config, | static UniValue getnewaddress(const Config &config, | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (!pwallet->GetLabelDestination(dest, label, bForceNew)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
return dest; | return dest; | ||||
} | } | ||||
UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { | static UniValue getlabeladdress(const Config &config, | ||||
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() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getlabeladdress \"label\"\n" | "getlabeladdress \"label\"\n" | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | static UniValue getrawchangeaddress(const Config &config, | ||||
reservekey.KeepKey(); | reservekey.KeepKey(); | ||||
pwallet->LearnRelatedScripts(vchPubKey, output_type); | pwallet->LearnRelatedScripts(vchPubKey, output_type); | ||||
CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); | CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); | ||||
return EncodeDestination(dest); | return EncodeDestination(dest); | ||||
} | } | ||||
UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | static UniValue setlabel(const Config &config, 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() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return ValueFromAmount(nAmount); | return ValueFromAmount(nAmount); | ||||
} | } | ||||
UniValue getreceivedbylabel(const Config &config, | static UniValue getreceivedbylabel(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() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 527 Lines • ▼ Show 20 Lines | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
UniValue addmultisigaddress(const Config &config, | static UniValue addmultisigaddress(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() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
std::string msg = | std::string msg = | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | struct tallyitem { | ||||
bool fIsWatchonly; | bool fIsWatchonly; | ||||
tallyitem() { | tallyitem() { | ||||
nAmount = Amount::zero(); | nAmount = Amount::zero(); | ||||
nConf = std::numeric_limits<int>::max(); | nConf = std::numeric_limits<int>::max(); | ||||
fIsWatchonly = false; | fIsWatchonly = false; | ||||
} | } | ||||
}; | }; | ||||
UniValue ListReceived(const Config &config, CWallet *const pwallet, | static 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[0].isNull()) { | 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; | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | static UniValue listreceivedbyaddress(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); | ||||
return ListReceived(config, pwallet, request.params, false); | return ListReceived(config, pwallet, request.params, false); | ||||
} | } | ||||
UniValue listreceivedbylabel(const Config &config, | static UniValue listreceivedbylabel(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() > 3) { | if (request.fHelp || request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listreceivedbylabel ( minconf include_empty include_watchonly)\n" | "listreceivedbylabel ( minconf include_empty include_watchonly)\n" | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
* @param pwallet The wallet. | * @param pwallet The wallet. | ||||
* @param wtx The wallet transaction. | * @param wtx The wallet transaction. | ||||
* @param strAccount The account, if any, or "*" for all. | * @param strAccount The account, if any, or "*" for all. | ||||
* @param nMinDepth The minimum confirmation depth. | * @param nMinDepth The minimum confirmation depth. | ||||
* @param fLong Whether to include the JSON version of the transaction. | * @param fLong Whether to include the JSON version of the transaction. | ||||
* @param ret The UniValue into which the result is stored. | * @param ret The UniValue into which the result is stored. | ||||
* @param filter The "is mine" filter bool. | * @param filter The "is mine" filter bool. | ||||
*/ | */ | ||||
void ListTransactions(CWallet *const pwallet, const CWalletTx &wtx, | static void ListTransactions(CWallet *const pwallet, const CWalletTx &wtx, | ||||
const std::string &strAccount, int nMinDepth, bool fLong, | const std::string &strAccount, int nMinDepth, | ||||
UniValue &ret, const isminefilter &filter) { | bool fLong, UniValue &ret, | ||||
const isminefilter &filter) { | |||||
Amount nFee; | Amount nFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | ||||
bool fAllAccounts = (strAccount == std::string("*")); | bool fAllAccounts = (strAccount == std::string("*")); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
WalletTxToJSON(wtx, entry); | WalletTxToJSON(wtx, entry); | ||||
} | } | ||||
ret.push_back(entry); | ret.push_back(entry); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void AcentryToJSON(const CAccountingEntry &acentry, | static void AcentryToJSON(const CAccountingEntry &acentry, | ||||
const std::string &strAccount, UniValue &ret) { | const std::string &strAccount, UniValue &ret) { | ||||
bool fAllAccounts = (strAccount == std::string("*")); | bool fAllAccounts = (strAccount == std::string("*")); | ||||
if (fAllAccounts || acentry.strAccount == strAccount) { | if (fAllAccounts || acentry.strAccount == strAccount) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.pushKV("account", acentry.strAccount); | entry.pushKV("account", acentry.strAccount); | ||||
entry.pushKV("category", "move"); | entry.pushKV("category", "move"); | ||||
entry.pushKV("time", acentry.nTime); | entry.pushKV("time", acentry.nTime); | ||||
entry.pushKV("amount", ValueFromAmount(acentry.nCreditDebit)); | entry.pushKV("amount", ValueFromAmount(acentry.nCreditDebit)); | ||||
▲ Show 20 Lines • Show All 2,240 Lines • ▼ Show 20 Lines | UniValue operator()(const CScriptID &scriptID) const { | ||||
CScript subscript; | CScript subscript; | ||||
if (pwallet && pwallet->GetCScript(scriptID, subscript)) { | if (pwallet && pwallet->GetCScript(scriptID, subscript)) { | ||||
ProcessSubScript(subscript, obj, true); | ProcessSubScript(subscript, obj, true); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
}; | }; | ||||
UniValue DescribeWalletAddress(CWallet *pwallet, const CTxDestination &dest) { | static UniValue DescribeWalletAddress(CWallet *pwallet, | ||||
const CTxDestination &dest) { | |||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
UniValue detail = DescribeAddress(dest); | UniValue detail = DescribeAddress(dest); | ||||
ret.pushKVs(detail); | ret.pushKVs(detail); | ||||
ret.pushKVs( | ret.pushKVs( | ||||
boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest)); | boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest)); | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |