@@ -1609,6 +1609,73 @@ UniValue listreceivedbyaccount(const UniValue& params, bool fHelp)
16091609 return ListReceived (params, true );
16101610}
16111611
1612+ UniValue listcoldutxos (const UniValue& params, bool fHelp )
1613+ {
1614+ if (fHelp || params.size () > 1 )
1615+ throw std::runtime_error (
1616+ " listcoldutxos ( nonWhitelistedOnly )\n "
1617+ " \n List P2CS unspent outputs received by this wallet as cold-staker-\n "
1618+
1619+ " \n Arguments:\n "
1620+ " 1. nonWhitelistedOnly (boolean, optional, default=false) Whether to exclude P2CS from whitelisted delegators.\n "
1621+
1622+ " \n Result:\n "
1623+ " [\n "
1624+ " {\n "
1625+ " \" txid\" : \" true\" , (string) The transaction id of the P2CS utxo\n "
1626+ " \" txidn\" : \" accountname\" , (string) The output number of the P2CS utxo\n "
1627+ " \" amount\" : x.xxx, (numeric) The amount of the P2CS utxo\n "
1628+ " \" confirmations\" : n (numeric) The number of confirmations of the P2CS utxo\n "
1629+ " \" cold-staker\" : n (string) The cold-staker address of the P2CS utxo\n "
1630+ " \" coin-owner\" : n (string) The coin-owner address of the P2CS utxo\n "
1631+ " \" whitelisted\" : n (string) \" true\" /\" false\" coin-owner in delegator whitelist\n "
1632+ " }\n "
1633+ " ,...\n "
1634+ " ]\n "
1635+
1636+ " \n Examples:\n " +
1637+ HelpExampleCli (" listcoldutxos" , " " ) + HelpExampleCli (" listcoldutxos" , " true" ));
1638+
1639+ LOCK2 (cs_main, pwalletMain->cs_wallet );
1640+
1641+ bool fExcludeWhitelisted = false ;
1642+ if (params.size () > 0 )
1643+ fExcludeWhitelisted = params[0 ].get_bool ();
1644+ UniValue results (UniValue::VARR);
1645+
1646+ for (std::map<uint256, CWalletTx>::const_iterator it =
1647+ pwalletMain->mapWallet .begin (); it != pwalletMain->mapWallet .end (); ++it) {
1648+ const uint256& wtxid = it->first ;
1649+ const CWalletTx* pcoin = &(*it).second ;
1650+
1651+ for (unsigned int i = 0 ; i < pcoin->vout .size (); i++) {
1652+ const CTxOut& out = pcoin->vout [i];
1653+ isminetype mine = pwalletMain->IsMine (out);
1654+ if (!bool (mine & ISMINE_COLD) && !bool (mine & ISMINE_SPENDABLE_DELEGATED))
1655+ continue ;
1656+ txnouttype type;
1657+ std::vector<CTxDestination> addresses;
1658+ int nRequired;
1659+ if (!ExtractDestinations (out.scriptPubKey , type, addresses, nRequired))
1660+ continue ;
1661+ const bool fWhitelisted = pwalletMain->mapAddressBook .count (addresses[1 ]) > 0 ;
1662+ if (fExcludeWhitelisted && fWhitelisted )
1663+ continue ;
1664+ UniValue entry (UniValue::VOBJ);
1665+ entry.push_back (Pair (" txid" , wtxid.GetHex ()));
1666+ entry.push_back (Pair (" txidn" , (int )i));
1667+ entry.push_back (Pair (" amount" , ValueFromAmount (out.nValue )));
1668+ entry.push_back (Pair (" confirmations" , pcoin->GetDepthInMainChain (false )));
1669+ entry.push_back (Pair (" cold-staker" , CBitcoinAddress (addresses[0 ]).ToString ()));
1670+ entry.push_back (Pair (" coin-owner" , CBitcoinAddress (addresses[1 ]).ToString ()));
1671+ entry.push_back (Pair (" whitelisted" , fWhitelisted ? " true" : " false" ));
1672+ results.push_back (entry);
1673+ }
1674+ }
1675+
1676+ return results;
1677+ }
1678+
16121679static void MaybePushAddress (UniValue & entry, const CTxDestination &dest)
16131680{
16141681 CBitcoinAddress addr;
0 commit comments