Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 4,085 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); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, | pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, | ||||
nMinimumAmount, nMaximumAmount, nMinimumSumAmount, | nMinimumAmount, nMaximumAmount, | ||||
nMaximumCount, nMinDepth, nMaxDepth); | nMinimumSumAmount, nMaximumCount, nMinDepth, | ||||
nMaxDepth); | |||||
} | |||||
LOCK(pwallet->cs_wallet); | |||||
for (const COutput &out : vecOutputs) { | for (const COutput &out : vecOutputs) { | ||||
CTxDestination address; | CTxDestination address; | ||||
const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | ||||
bool fValidAddress = ExtractDestination(scriptPubKey, address); | bool fValidAddress = ExtractDestination(scriptPubKey, address); | ||||
if (destinations.size() && | if (destinations.size() && | ||||
(!fValidAddress || !destinations.count(address))) { | (!fValidAddress || !destinations.count(address))) { | ||||
continue; | continue; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.pushKV("txid", out.tx->GetId().GetHex()); | entry.pushKV("txid", out.tx->GetId().GetHex()); | ||||
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)); | ||||
if (pwallet->mapAddressBook.count(address)) { | auto i = pwallet->mapAddressBook.find(address); | ||||
entry.pushKV("label", pwallet->mapAddressBook[address].name); | if (i != pwallet->mapAddressBook.end()) { | ||||
entry.pushKV("label", i->second.name); | |||||
if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { | if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { | ||||
entry.pushKV("account", | entry.pushKV("account", i->second.name); | ||||
pwallet->mapAddressBook[address].name); | |||||
} | } | ||||
} | } | ||||
if (scriptPubKey.IsPayToScriptHash()) { | if (scriptPubKey.IsPayToScriptHash()) { | ||||
const CScriptID &hash = boost::get<CScriptID>(address); | const CScriptID &hash = boost::get<CScriptID>(address); | ||||
CScript redeemScript; | CScript redeemScript; | ||||
if (pwallet->GetCScript(hash, redeemScript)) { | if (pwallet->GetCScript(hash, redeemScript)) { | ||||
entry.pushKV("redeemScript", HexStr(redeemScript.begin(), | entry.pushKV("redeemScript", HexStr(redeemScript.begin(), | ||||
▲ Show 20 Lines • Show All 1,309 Lines • Show Last 20 Lines |