Skip to content

Commit 2e5f7de

Browse files
committed
wallet, rpc: update listdescriptors response format
1 parent 461f0c7 commit 2e5f7de

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/wallet/rpcdump.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -1747,22 +1747,23 @@ RPCHelpMan listdescriptors()
17471747
"listdescriptors",
17481748
"\nList descriptors imported into a descriptor-enabled wallet.",
17491749
{},
1750-
RPCResult{
1751-
RPCResult::Type::ARR, "", "Response is an array of descriptor objects",
1750+
RPCResult{RPCResult::Type::OBJ, "", "", {
1751+
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
1752+
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
17521753
{
17531754
{RPCResult::Type::OBJ, "", "", {
17541755
{RPCResult::Type::STR, "desc", "Descriptor string representation"},
17551756
{RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
17561757
{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::BOOL, "internal", true, "Whether this is an internal or external descriptor; defined only for active descriptors"},
17581759
{RPCResult::Type::ARR_FIXED, "range", true, "Defined only for ranged descriptors", {
17591760
{RPCResult::Type::NUM, "", "Range start inclusive"},
17601761
{RPCResult::Type::NUM, "", "Range end inclusive"},
17611762
}},
17621763
{RPCResult::Type::NUM, "next", true, "The next index to generate addresses from; defined only for ranged descriptors"},
17631764
}},
1764-
}
1765-
},
1765+
}}
1766+
}},
17661767
RPCExamples{
17671768
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
17681769
},
@@ -1779,7 +1780,7 @@ RPCHelpMan listdescriptors()
17791780

17801781
LOCK(wallet->cs_wallet);
17811782

1782-
UniValue response(UniValue::VARR);
1783+
UniValue descriptors(UniValue::VARR);
17831784
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
17841785
for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
17851786
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
@@ -1808,9 +1809,13 @@ RPCHelpMan listdescriptors()
18081809
spk.pushKV("range", range);
18091810
spk.pushKV("next", wallet_descriptor.next_index);
18101811
}
1811-
response.push_back(spk);
1812+
descriptors.push_back(spk);
18121813
}
18131814

1815+
UniValue response(UniValue::VOBJ);
1816+
response.pushKV("wallet_name", wallet->GetName());
1817+
response.pushKV("descriptors", descriptors);
1818+
18141819
return response;
18151820
},
18161821
};

test/functional/wallet_listdescriptors.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ def run_test(self):
3636

3737
self.log.info('Test the command for empty descriptors wallet.')
3838
node.createwallet(wallet_name='w2', blank=True, descriptors=True)
39-
assert_equal(0, len(node.get_wallet_rpc('w2').listdescriptors()))
39+
assert_equal(0, len(node.get_wallet_rpc('w2').listdescriptors()['descriptors']))
4040

4141
self.log.info('Test the command for a default descriptors wallet.')
4242
node.createwallet(wallet_name='w3', descriptors=True)
4343
result = node.get_wallet_rpc('w3').listdescriptors()
44-
assert_equal(6, len(result))
45-
assert_equal(6, len([d for d in result if d['active']]))
46-
assert_equal(3, len([d for d in result if d['internal']]))
47-
for item in result:
44+
assert_equal("w3", result['wallet_name'])
45+
assert_equal(6, len(result['descriptors']))
46+
assert_equal(6, len([d for d in result['descriptors'] if d['active']]))
47+
assert_equal(3, len([d for d in result['descriptors'] if d['internal']]))
48+
for item in result['descriptors']:
4849
assert item['desc'] != ''
4950
assert item['next'] == 0
5051
assert item['range'] == [0, 0]
@@ -59,12 +60,17 @@ def run_test(self):
5960
'desc': descsum_create('wpkh(' + xprv + hardened_path + '/0/*)'),
6061
'timestamp': 1296688602,
6162
}])
62-
expected = {'desc': descsum_create('wpkh([80002067' + hardened_path + ']' + xpub_acc + '/0/*)'),
63-
'timestamp': 1296688602,
64-
'active': False,
65-
'range': [0, 0],
66-
'next': 0}
67-
assert_equal([expected], wallet.listdescriptors())
63+
expected = {
64+
'wallet_name': 'w2',
65+
'descriptors': [
66+
{'desc': descsum_create('wpkh([80002067' + hardened_path + ']' + xpub_acc + '/0/*)'),
67+
'timestamp': 1296688602,
68+
'active': False,
69+
'range': [0, 0],
70+
'next': 0},
71+
],
72+
}
73+
assert_equal(expected, wallet.listdescriptors())
6874

6975
self.log.info('Test non-active non-range combo descriptor')
7076
node.createwallet(wallet_name='w4', blank=True, descriptors=True)
@@ -73,9 +79,14 @@ def run_test(self):
7379
'desc': descsum_create('combo(' + node.get_deterministic_priv_key().key + ')'),
7480
'timestamp': 1296688602,
7581
}])
76-
expected = [{'active': False,
77-
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
78-
'timestamp': 1296688602}]
82+
expected = {
83+
'wallet_name': 'w4',
84+
'descriptors': [
85+
{'active': False,
86+
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
87+
'timestamp': 1296688602},
88+
]
89+
}
7990
assert_equal(expected, wallet.listdescriptors())
8091

8192

0 commit comments

Comments
 (0)