@@ -2341,13 +2341,14 @@ UniValue listunspent(const UniValue& params, bool fHelp)
23412341 " \n Result\n "
23422342 " [ (array of json object)\n "
23432343 " {\n "
2344- " \" txid\" : \" txid\" , (string) the transaction id \n "
2344+ " \" txid\" : \" txid\" , (string) the transaction id \n "
23452345 " \" vout\" : n, (numeric) the vout value\n "
2346- " \" address\" : \" address\" , (string) the bitcoin address\n "
2347- " \" account\" : \" account\" , (string) DEPRECATED. The associated account, or \"\" for the default account\n "
2348- " \" scriptPubKey\" : \" key\" , (string) the script key\n "
2346+ " \" address\" : \" address\" , (string) the bitcoin address\n "
2347+ " \" account\" : \" account\" , (string) DEPRECATED. The associated account, or \"\" for the default account\n "
2348+ " \" scriptPubKey\" : \" key\" , (string) the script key\n "
23492349 " \" amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + " \n "
23502350 " \" confirmations\" : n, (numeric) The number of confirmations\n "
2351+ " \" redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n "
23512352 " \" spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n "
23522353 " \" solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n "
23532354 " }\n "
@@ -2393,38 +2394,34 @@ UniValue listunspent(const UniValue& params, bool fHelp)
23932394 if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
23942395 continue ;
23952396
2396- if (setAddress.size ()) {
2397- CTxDestination address;
2398- if (!ExtractDestination (out.tx ->vout [out.i ].scriptPubKey , address))
2399- continue ;
2397+ CTxDestination address;
2398+ const CScript& scriptPubKey = out.tx ->vout [out.i ].scriptPubKey ;
2399+ bool fValidAddress = ExtractDestination (scriptPubKey, address);
24002400
2401- if (!setAddress.count (address))
2402- continue ;
2403- }
2401+ if (setAddress.size () && (!fValidAddress || !setAddress.count (address)))
2402+ continue ;
24042403
2405- CAmount nValue = out.tx ->vout [out.i ].nValue ;
2406- const CScript& pk = out.tx ->vout [out.i ].scriptPubKey ;
24072404 UniValue entry (UniValue::VOBJ);
24082405 entry.push_back (Pair (" txid" , out.tx ->GetHash ().GetHex ()));
24092406 entry.push_back (Pair (" vout" , out.i ));
2410- CTxDestination address;
2411- if (ExtractDestination (out. tx -> vout [out. i ]. scriptPubKey , address) ) {
2407+
2408+ if (fValidAddress ) {
24122409 entry.push_back (Pair (" address" , CBitcoinAddress (address).ToString ()));
2410+
24132411 if (pwalletMain->mapAddressBook .count (address))
24142412 entry.push_back (Pair (" account" , pwalletMain->mapAddressBook [address].name ));
2415- }
2416- entry.push_back (Pair (" scriptPubKey" , HexStr (pk.begin (), pk.end ())));
2417- if (pk.IsPayToScriptHash ()) {
2418- CTxDestination address;
2419- if (ExtractDestination (pk, address)) {
2413+
2414+ if (scriptPubKey.IsPayToScriptHash ()) {
24202415 const CScriptID& hash = boost::get<CScriptID>(address);
24212416 CScript redeemScript;
24222417 if (pwalletMain->GetCScript (hash, redeemScript))
24232418 entry.push_back (Pair (" redeemScript" , HexStr (redeemScript.begin (), redeemScript.end ())));
24242419 }
24252420 }
2426- entry.push_back (Pair (" amount" ,ValueFromAmount (nValue)));
2427- entry.push_back (Pair (" confirmations" ,out.nDepth ));
2421+
2422+ entry.push_back (Pair (" scriptPubKey" , HexStr (scriptPubKey.begin (), scriptPubKey.end ())));
2423+ entry.push_back (Pair (" amount" , ValueFromAmount (out.tx ->vout [out.i ].nValue )));
2424+ entry.push_back (Pair (" confirmations" , out.nDepth ));
24282425 entry.push_back (Pair (" spendable" , out.fSpendable ));
24292426 entry.push_back (Pair (" solvable" , out.fSolvable ));
24302427 results.push_back (entry);
0 commit comments