Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 548 Lines • ▼ Show 20 Lines | for (const std::set<CTxDestination> &grouping : | ||||
for (const CTxDestination &address : grouping) { | for (const CTxDestination &address : grouping) { | ||||
UniValue addressInfo(UniValue::VARR); | UniValue addressInfo(UniValue::VARR); | ||||
addressInfo.push_back(EncodeDestination(address, config)); | addressInfo.push_back(EncodeDestination(address, config)); | ||||
addressInfo.push_back(ValueFromAmount(balances[address])); | addressInfo.push_back(ValueFromAmount(balances[address])); | ||||
const auto *address_book_entry = | const auto *address_book_entry = | ||||
pwallet->FindAddressBookEntry(address); | pwallet->FindAddressBookEntry(address); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
addressInfo.push_back(address_book_entry->name); | addressInfo.push_back(address_book_entry->GetLabel()); | ||||
} | } | ||||
jsonGrouping.push_back(addressInfo); | jsonGrouping.push_back(addressInfo); | ||||
} | } | ||||
jsonGroupings.push_back(jsonGrouping); | jsonGroupings.push_back(jsonGrouping); | ||||
} | } | ||||
return jsonGroupings; | return jsonGroupings; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 702 Lines • ▼ Show 20 Lines | if (has_filtered_address) { | ||||
} | } | ||||
} | } | ||||
for (auto item_it = start; item_it != end; ++item_it) { | for (auto item_it = start; item_it != end; ++item_it) { | ||||
if (item_it->second.IsChange()) { | if (item_it->second.IsChange()) { | ||||
continue; | continue; | ||||
} | } | ||||
const CTxDestination &address = item_it->first; | const CTxDestination &address = item_it->first; | ||||
const std::string &label = item_it->second.name; | const std::string &label = item_it->second.GetLabel(); | ||||
std::map<CTxDestination, tallyitem>::iterator it = | std::map<CTxDestination, tallyitem>::iterator it = | ||||
mapTally.find(address); | mapTally.find(address); | ||||
if (it == mapTally.end() && !fIncludeEmpty) { | if (it == mapTally.end() && !fIncludeEmpty) { | ||||
continue; | continue; | ||||
} | } | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
int nConf = std::numeric_limits<int>::max(); | int nConf = std::numeric_limits<int>::max(); | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | if (!filter_label) { | ||||
entry.pushKV("involvesWatchonly", true); | entry.pushKV("involvesWatchonly", true); | ||||
} | } | ||||
MaybePushAddress(entry, s.destination); | MaybePushAddress(entry, s.destination); | ||||
entry.pushKV("category", "send"); | entry.pushKV("category", "send"); | ||||
entry.pushKV("amount", ValueFromAmount(-s.amount)); | entry.pushKV("amount", ValueFromAmount(-s.amount)); | ||||
const auto *address_book_entry = | const auto *address_book_entry = | ||||
pwallet->FindAddressBookEntry(s.destination); | pwallet->FindAddressBookEntry(s.destination); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
entry.pushKV("label", address_book_entry->name); | entry.pushKV("label", address_book_entry->GetLabel()); | ||||
} | } | ||||
entry.pushKV("vout", s.vout); | entry.pushKV("vout", s.vout); | ||||
entry.pushKV("fee", ValueFromAmount(-1 * nFee)); | entry.pushKV("fee", ValueFromAmount(-1 * nFee)); | ||||
if (fLong) { | if (fLong) { | ||||
WalletTxToJSON(pwallet->chain(), locked_chain, wtx, entry); | WalletTxToJSON(pwallet->chain(), locked_chain, wtx, entry); | ||||
} | } | ||||
entry.pushKV("abandoned", wtx.isAbandoned()); | entry.pushKV("abandoned", wtx.isAbandoned()); | ||||
ret.push_back(entry); | ret.push_back(entry); | ||||
} | } | ||||
} | } | ||||
// Received | // Received | ||||
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { | if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
for (const COutputEntry &r : listReceived) { | for (const COutputEntry &r : listReceived) { | ||||
std::string label; | std::string label; | ||||
const auto *address_book_entry = | const auto *address_book_entry = | ||||
pwallet->FindAddressBookEntry(r.destination); | pwallet->FindAddressBookEntry(r.destination); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
label = address_book_entry->name; | label = address_book_entry->GetLabel(); | ||||
} | } | ||||
if (filter_label && label != *filter_label) { | if (filter_label && label != *filter_label) { | ||||
continue; | continue; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
if (involvesWatchonly || | if (involvesWatchonly || | ||||
(pwallet->IsMine(r.destination) & ISMINE_WATCH_ONLY)) { | (pwallet->IsMine(r.destination) & ISMINE_WATCH_ONLY)) { | ||||
entry.pushKV("involvesWatchonly", true); | entry.pushKV("involvesWatchonly", true); | ||||
▲ Show 20 Lines • Show All 2,000 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
entry.pushKV("vout", out.i); | entry.pushKV("vout", out.i); | ||||
if (fValidAddress) { | if (fValidAddress) { | ||||
entry.pushKV("address", EncodeDestination(address, config)); | entry.pushKV("address", EncodeDestination(address, config)); | ||||
const auto *address_book_entry = | const auto *address_book_entry = | ||||
pwallet->FindAddressBookEntry(address); | pwallet->FindAddressBookEntry(address); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
entry.pushKV("label", address_book_entry->name); | entry.pushKV("label", address_book_entry->GetLabel()); | ||||
} | } | ||||
const SigningProvider *provider = | const SigningProvider *provider = | ||||
pwallet->GetSigningProvider(scriptPubKey); | pwallet->GetSigningProvider(scriptPubKey); | ||||
if (provider) { | if (provider) { | ||||
if (scriptPubKey.IsPayToScriptHash()) { | if (scriptPubKey.IsPayToScriptHash()) { | ||||
const CScriptID &hash = | const CScriptID &hash = | ||||
CScriptID(boost::get<ScriptHash>(address)); | CScriptID(boost::get<ScriptHash>(address)); | ||||
▲ Show 20 Lines • Show All 590 Lines • ▼ Show 20 Lines | static UniValue DescribeWalletAddress(CWallet *pwallet, | ||||
return ret; | return ret; | ||||
} | } | ||||
/** Convert CAddressBookData to JSON record. */ | /** Convert CAddressBookData to JSON record. */ | ||||
static UniValue AddressBookDataToJSON(const CAddressBookData &data, | static UniValue AddressBookDataToJSON(const CAddressBookData &data, | ||||
const bool verbose) { | const bool verbose) { | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
if (verbose) { | if (verbose) { | ||||
ret.pushKV("name", data.name); | ret.pushKV("name", data.GetLabel()); | ||||
} | } | ||||
ret.pushKV("purpose", data.purpose); | ret.pushKV("purpose", data.purpose); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | UniValue getaddressinfo(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 136 Lines • ▼ Show 20 Lines | UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | ||||
UniValue detail = DescribeWalletAddress(pwallet, dest); | UniValue detail = DescribeWalletAddress(pwallet, dest); | ||||
ret.pushKVs(detail); | ret.pushKVs(detail); | ||||
// Return label field if existing. Currently only one label can be | // Return label field if existing. Currently only one label can be | ||||
// associated with an address, so the label should be equivalent to the | // associated with an address, so the label should be equivalent to the | ||||
// value of the name key/value pair in the labels array below. | // value of the name key/value pair in the labels array below. | ||||
const auto *address_book_entry = pwallet->FindAddressBookEntry(dest); | const auto *address_book_entry = pwallet->FindAddressBookEntry(dest); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
ret.pushKV("label", address_book_entry->name); | ret.pushKV("label", address_book_entry->GetLabel()); | ||||
} | } | ||||
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey)); | ret.pushKV("ischange", pwallet->IsChange(scriptPubKey)); | ||||
ScriptPubKeyMan *spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey); | ScriptPubKeyMan *spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey); | ||||
if (spk_man) { | if (spk_man) { | ||||
if (const CKeyMetadata *meta = spk_man->GetMetadata(dest)) { | if (const CKeyMetadata *meta = spk_man->GetMetadata(dest)) { | ||||
ret.pushKV("timestamp", meta->nCreateTime); | ret.pushKV("timestamp", meta->nCreateTime); | ||||
Show All 15 Lines | UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | ||||
// | // | ||||
// DEPRECATED: The previous behavior of returning an array containing a JSON | // DEPRECATED: The previous behavior of returning an array containing a JSON | ||||
// object of `name` and `purpose` key/value pairs has been deprecated. | // object of `name` and `purpose` key/value pairs has been deprecated. | ||||
UniValue labels(UniValue::VARR); | UniValue labels(UniValue::VARR); | ||||
if (address_book_entry) { | if (address_book_entry) { | ||||
if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) { | if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) { | ||||
labels.push_back(AddressBookDataToJSON(*address_book_entry, true)); | labels.push_back(AddressBookDataToJSON(*address_book_entry, true)); | ||||
} else { | } else { | ||||
labels.push_back(address_book_entry->name); | labels.push_back(address_book_entry->GetLabel()); | ||||
} | } | ||||
} | } | ||||
ret.pushKV("labels", std::move(labels)); | ret.pushKV("labels", std::move(labels)); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getaddressesbylabel(const Config &config, | UniValue getaddressesbylabel(const Config &config, | ||||
Show All 30 Lines | UniValue getaddressesbylabel(const Config &config, | ||||
// Find all addresses that have the given label | // Find all addresses that have the given label | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
std::set<std::string> addresses; | std::set<std::string> addresses; | ||||
for (const std::pair<const CTxDestination, CAddressBookData> &item : | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
pwallet->m_address_book) { | pwallet->m_address_book) { | ||||
if (item.second.IsChange()) { | if (item.second.IsChange()) { | ||||
continue; | continue; | ||||
} | } | ||||
if (item.second.name == label) { | if (item.second.GetLabel() == label) { | ||||
std::string address = EncodeDestination(item.first, config); | std::string address = EncodeDestination(item.first, config); | ||||
// CWallet::m_address_book is not expected to contain duplicate | // CWallet::m_address_book is not expected to contain duplicate | ||||
// address strings, but build a separate set as a precaution just in | // address strings, but build a separate set as a precaution just in | ||||
// case it does. | // case it does. | ||||
bool unique = addresses.emplace(address).second; | bool unique = addresses.emplace(address).second; | ||||
CHECK_NONFATAL(unique); | CHECK_NONFATAL(unique); | ||||
// UniValue::pushKV checks if the key exists in O(N) | // UniValue::pushKV checks if the key exists in O(N) | ||||
// and since duplicate addresses are unexpected (checked with | // and since duplicate addresses are unexpected (checked with | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | UniValue listlabels(const Config &config, const JSONRPCRequest &request) { | ||||
// Add to a set to sort by label name, then insert into Univalue array | // Add to a set to sort by label name, then insert into Univalue array | ||||
std::set<std::string> label_set; | std::set<std::string> label_set; | ||||
for (const std::pair<const CTxDestination, CAddressBookData> &entry : | for (const std::pair<const CTxDestination, CAddressBookData> &entry : | ||||
pwallet->m_address_book) { | pwallet->m_address_book) { | ||||
if (entry.second.IsChange()) { | if (entry.second.IsChange()) { | ||||
continue; | continue; | ||||
} | } | ||||
if (purpose.empty() || entry.second.purpose == purpose) { | if (purpose.empty() || entry.second.purpose == purpose) { | ||||
label_set.insert(entry.second.name); | label_set.insert(entry.second.GetLabel()); | ||||
} | } | ||||
} | } | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const std::string &name : label_set) { | for (const std::string &name : label_set) { | ||||
ret.push_back(name); | ret.push_back(name); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines |