@@ -1740,3 +1740,72 @@ RPCHelpMan importdescriptors()
17401740},
17411741 };
17421742}
1743+
1744+ RPCHelpMan listdescriptors ()
1745+ {
1746+ return RPCHelpMan{
1747+ " listdescriptors" ,
1748+ " \n List descriptors imported into a descriptor-enabled wallet." ,
1749+ {},
1750+ RPCResult{
1751+ RPCResult::Type::ARR, " " , " Response is an array of descriptor objects" ,
1752+ {
1753+ {RPCResult::Type::OBJ, " " , " " , {
1754+ {RPCResult::Type::STR, " desc" , " Descriptor string representation" },
1755+ {RPCResult::Type::NUM, " timestamp" , " The creation time of the descriptor" },
1756+ {RPCResult::Type::BOOL, " active" , " Activeness flag" },
1757+ {RPCResult::Type::BOOL, " internal" , true , " Whether this is internal or external descriptor; defined only for active descriptors" },
1758+ {RPCResult::Type::ARR_FIXED, " range" , true , " Defined only for ranged descriptors" , {
1759+ {RPCResult::Type::NUM, " " , " Range start inclusive" },
1760+ {RPCResult::Type::NUM, " " , " Range end inclusive" },
1761+ }},
1762+ {RPCResult::Type::NUM, " next" , true , " The next index to generate addresses from; defined only for ranged descriptors" },
1763+ }},
1764+ }
1765+ },
1766+ RPCExamples{
1767+ HelpExampleCli (" listdescriptors" , " " ) + HelpExampleRpc (" listdescriptors" , " " )
1768+ },
1769+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1770+ {
1771+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
1772+ if (!wallet) return NullUniValue;
1773+
1774+ if (!wallet->IsWalletFlagSet (WALLET_FLAG_DESCRIPTORS)) {
1775+ throw JSONRPCError (RPC_WALLET_ERROR, " listdescriptors is not available for non-descriptor wallets" );
1776+ }
1777+
1778+ LOCK (wallet->cs_wallet );
1779+
1780+ UniValue response (UniValue::VARR);
1781+ const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans ();
1782+ for (const auto & spk_man : wallet->GetAllScriptPubKeyMans ()) {
1783+ const auto desc_spk_man = dynamic_cast <DescriptorScriptPubKeyMan*>(spk_man);
1784+ if (!desc_spk_man) {
1785+ throw JSONRPCError (RPC_WALLET_ERROR, " Unexpected ScriptPubKey manager type." );
1786+ }
1787+ UniValue spk (UniValue::VOBJ);
1788+ LOCK (desc_spk_man->cs_desc_man );
1789+ const auto & wallet_descriptor = desc_spk_man->GetWalletDescriptor ();
1790+ spk.pushKV (" desc" , wallet_descriptor.descriptor ->ToString ());
1791+ spk.pushKV (" timestamp" , wallet_descriptor.creation_time );
1792+ const bool active = active_spk_mans.count (desc_spk_man) != 0 ;
1793+ spk.pushKV (" active" , active);
1794+ const auto & type = wallet_descriptor.descriptor ->GetOutputType ();
1795+ if (active && type != nullopt ) {
1796+ spk.pushKV (" internal" , wallet->GetScriptPubKeyMan (*type, true ) == desc_spk_man);
1797+ }
1798+ if (wallet_descriptor.descriptor ->IsRange ()) {
1799+ UniValue range (UniValue::VARR);
1800+ range.push_back (wallet_descriptor.range_start );
1801+ range.push_back (wallet_descriptor.range_end - 1 );
1802+ spk.pushKV (" range" , range);
1803+ spk.pushKV (" next" , wallet_descriptor.next_index );
1804+ }
1805+ response.push_back (spk);
1806+ }
1807+
1808+ return response;
1809+ },
1810+ };
1811+ }
0 commit comments