@@ -2307,13 +2307,14 @@ UniValue listunspent(const UniValue& params, bool fHelp)
2307
2307
" \n Result\n "
2308
2308
" [ (array of json object)\n "
2309
2309
" {\n "
2310
- " \" txid\" : \" txid\" , (string) the transaction id \n "
2310
+ " \" txid\" : \" txid\" , (string) the transaction id \n "
2311
2311
" \" vout\" : n, (numeric) the vout value\n "
2312
- " \" address\" : \" address\" , (string) the bitcoin address\n "
2313
- " \" account\" : \" account\" , (string) DEPRECATED. The associated account, or \"\" for the default account\n "
2314
- " \" scriptPubKey\" : \" key\" , (string) the script key\n "
2312
+ " \" address\" : \" address\" , (string) the bitcoin address\n "
2313
+ " \" account\" : \" account\" , (string) DEPRECATED. The associated account, or \"\" for the default account\n "
2314
+ " \" scriptPubKey\" : \" key\" , (string) the script key\n "
2315
2315
" \" amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + " \n "
2316
2316
" \" confirmations\" : n, (numeric) The number of confirmations\n "
2317
+ " \" redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n "
2317
2318
" \" spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n "
2318
2319
" \" solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n "
2319
2320
" }\n "
@@ -2359,38 +2360,34 @@ UniValue listunspent(const UniValue& params, bool fHelp)
2359
2360
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
2360
2361
continue ;
2361
2362
2362
- if (setAddress.size ()) {
2363
- CTxDestination address;
2364
- if (!ExtractDestination (out.tx ->vout [out.i ].scriptPubKey , address))
2365
- continue ;
2363
+ CTxDestination address;
2364
+ const CScript& scriptPubKey = out.tx ->vout [out.i ].scriptPubKey ;
2365
+ bool fValidAddress = ExtractDestination (scriptPubKey, address);
2366
2366
2367
- if (!setAddress.count (address))
2368
- continue ;
2369
- }
2367
+ if (setAddress.size () && (!fValidAddress || !setAddress.count (address)))
2368
+ continue ;
2370
2369
2371
- CAmount nValue = out.tx ->vout [out.i ].nValue ;
2372
- const CScript& pk = out.tx ->vout [out.i ].scriptPubKey ;
2373
2370
UniValue entry (UniValue::VOBJ);
2374
2371
entry.push_back (Pair (" txid" , out.tx ->GetHash ().GetHex ()));
2375
2372
entry.push_back (Pair (" vout" , out.i ));
2376
- CTxDestination address;
2377
- if (ExtractDestination (out. tx -> vout [out. i ]. scriptPubKey , address) ) {
2373
+
2374
+ if (fValidAddress ) {
2378
2375
entry.push_back (Pair (" address" , CBitcoinAddress (address).ToString ()));
2376
+
2379
2377
if (pwalletMain->mapAddressBook .count (address))
2380
2378
entry.push_back (Pair (" account" , pwalletMain->mapAddressBook [address].name ));
2381
- }
2382
- entry.push_back (Pair (" scriptPubKey" , HexStr (pk.begin (), pk.end ())));
2383
- if (pk.IsPayToScriptHash ()) {
2384
- CTxDestination address;
2385
- if (ExtractDestination (pk, address)) {
2379
+
2380
+ if (scriptPubKey.IsPayToScriptHash ()) {
2386
2381
const CScriptID& hash = boost::get<CScriptID>(address);
2387
2382
CScript redeemScript;
2388
2383
if (pwalletMain->GetCScript (hash, redeemScript))
2389
2384
entry.push_back (Pair (" redeemScript" , HexStr (redeemScript.begin (), redeemScript.end ())));
2390
2385
}
2391
2386
}
2392
- entry.push_back (Pair (" amount" ,ValueFromAmount (nValue)));
2393
- entry.push_back (Pair (" confirmations" ,out.nDepth ));
2387
+
2388
+ entry.push_back (Pair (" scriptPubKey" , HexStr (scriptPubKey.begin (), scriptPubKey.end ())));
2389
+ entry.push_back (Pair (" amount" , ValueFromAmount (out.tx ->vout [out.i ].nValue )));
2390
+ entry.push_back (Pair (" confirmations" , out.nDepth ));
2394
2391
entry.push_back (Pair (" spendable" , out.fSpendable ));
2395
2392
entry.push_back (Pair (" solvable" , out.fSolvable ));
2396
2393
results.push_back (entry);
0 commit comments