@@ -1784,34 +1784,59 @@ RPCHelpMan listdescriptors()
1784
1784
1785
1785
LOCK (wallet->cs_wallet );
1786
1786
1787
- UniValue descriptors (UniValue::VARR);
1788
1787
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans ();
1788
+
1789
+ struct WalletDescInfo {
1790
+ std::string descriptor;
1791
+ uint64_t creation_time;
1792
+ bool active;
1793
+ std::optional<bool > internal;
1794
+ std::optional<std::pair<int64_t ,int64_t >> range;
1795
+ int64_t next_index;
1796
+ };
1797
+
1798
+ std::vector<WalletDescInfo> wallet_descriptors;
1789
1799
for (const auto & spk_man : wallet->GetAllScriptPubKeyMans ()) {
1790
1800
const auto desc_spk_man = dynamic_cast <DescriptorScriptPubKeyMan*>(spk_man);
1791
1801
if (!desc_spk_man) {
1792
1802
throw JSONRPCError (RPC_WALLET_ERROR, " Unexpected ScriptPubKey manager type." );
1793
1803
}
1794
- UniValue spk (UniValue::VOBJ);
1795
1804
LOCK (desc_spk_man->cs_desc_man );
1796
1805
const auto & wallet_descriptor = desc_spk_man->GetWalletDescriptor ();
1797
1806
std::string descriptor;
1798
-
1799
1807
if (!desc_spk_man->GetDescriptorString (descriptor, priv)) {
1800
1808
throw JSONRPCError (RPC_WALLET_ERROR, " Can't get descriptor string." );
1801
1809
}
1802
- spk.pushKV (" desc" , descriptor);
1803
- spk.pushKV (" timestamp" , wallet_descriptor.creation_time );
1804
- spk.pushKV (" active" , active_spk_mans.count (desc_spk_man) != 0 );
1805
- const auto internal = wallet->IsInternalScriptPubKeyMan (desc_spk_man);
1806
- if (internal.has_value ()) {
1807
- spk.pushKV (" internal" , *internal);
1810
+ const bool is_range = wallet_descriptor.descriptor ->IsRange ();
1811
+ wallet_descriptors.push_back ({
1812
+ descriptor,
1813
+ wallet_descriptor.creation_time ,
1814
+ active_spk_mans.count (desc_spk_man) != 0 ,
1815
+ wallet->IsInternalScriptPubKeyMan (desc_spk_man),
1816
+ is_range ? std::optional (std::make_pair (wallet_descriptor.range_start , wallet_descriptor.range_end )) : std::nullopt,
1817
+ wallet_descriptor.next_index
1818
+ });
1819
+ }
1820
+
1821
+ std::sort (wallet_descriptors.begin (), wallet_descriptors.end (), [](const auto & a, const auto & b) {
1822
+ return a.descriptor < b.descriptor ;
1823
+ });
1824
+
1825
+ UniValue descriptors (UniValue::VARR);
1826
+ for (const WalletDescInfo& info : wallet_descriptors) {
1827
+ UniValue spk (UniValue::VOBJ);
1828
+ spk.pushKV (" desc" , info.descriptor );
1829
+ spk.pushKV (" timestamp" , info.creation_time );
1830
+ spk.pushKV (" active" , info.active );
1831
+ if (info.internal .has_value ()) {
1832
+ spk.pushKV (" internal" , info.internal .value ());
1808
1833
}
1809
- if (wallet_descriptor. descriptor -> IsRange ()) {
1834
+ if (info. range . has_value ()) {
1810
1835
UniValue range (UniValue::VARR);
1811
- range.push_back (wallet_descriptor. range_start );
1812
- range.push_back (wallet_descriptor. range_end - 1 );
1836
+ range.push_back (info. range -> first );
1837
+ range.push_back (info. range -> second - 1 );
1813
1838
spk.pushKV (" range" , range);
1814
- spk.pushKV (" next" , wallet_descriptor .next_index );
1839
+ spk.pushKV (" next" , info .next_index );
1815
1840
}
1816
1841
descriptors.push_back (spk);
1817
1842
}
0 commit comments