Browse Source

Merge #7825: Prevent multiple calls to ExtractDestination

0bf6f30 Prevent multiple calls to ExtractDestination (Pedro Branco)
0.13
Pieter Wuille 9 years ago
parent
commit
f972b04d63
No known key found for this signature in database
GPG Key ID: DBA1A67379A1A931
  1. 27
      src/wallet/rpcwallet.cpp

27
src/wallet/rpcwallet.cpp

@ -2314,6 +2314,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
" \"scriptPubKey\" : \"key\", (string) the script key\n" " \"scriptPubKey\" : \"key\", (string) the script key\n"
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n" " \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n" " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
" \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n" " \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
" }\n" " }\n"
@ -2359,37 +2360,33 @@ UniValue listunspent(const UniValue& params, bool fHelp)
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
continue; continue;
if (setAddress.size()) {
CTxDestination address; CTxDestination address;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) const CScript& scriptPubKey = out.tx->vout[out.i].scriptPubKey;
continue; bool fValidAddress = ExtractDestination(scriptPubKey, address);
if (!setAddress.count(address)) if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
continue; continue;
}
CAmount nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
UniValue entry(UniValue::VOBJ); UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
entry.push_back(Pair("vout", out.i)); entry.push_back(Pair("vout", out.i));
CTxDestination address;
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { if (fValidAddress) {
entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
if (pwalletMain->mapAddressBook.count(address)) if (pwalletMain->mapAddressBook.count(address))
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
}
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); if (scriptPubKey.IsPayToScriptHash()) {
if (pk.IsPayToScriptHash()) {
CTxDestination address;
if (ExtractDestination(pk, address)) {
const CScriptID& hash = boost::get<CScriptID>(address); const CScriptID& hash = boost::get<CScriptID>(address);
CScript redeemScript; CScript redeemScript;
if (pwalletMain->GetCScript(hash, redeemScript)) if (pwalletMain->GetCScript(hash, redeemScript))
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
} }
} }
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
entry.push_back(Pair("amount", ValueFromAmount(out.tx->vout[out.i].nValue)));
entry.push_back(Pair("confirmations", out.nDepth)); entry.push_back(Pair("confirmations", out.nDepth));
entry.push_back(Pair("spendable", out.fSpendable)); entry.push_back(Pair("spendable", out.fSpendable));
entry.push_back(Pair("solvable", out.fSolvable)); entry.push_back(Pair("solvable", out.fSolvable));

Loading…
Cancel
Save