Skip to content

Commit 7aa0d8a

Browse files
committed
Merge #21063: wallet, rpc: update listdescriptors response format
2e5f7de wallet, rpc: update listdescriptors response format (Ivan Metlushko) Pull request description: Update `listdescriptors` response format according to [RPC interface guidelines](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#rpc-interface-guidelines). This is a follow up for #20226 **Before:** ``` Result: [ (json array) Response is an array of descriptor objects { (json object) "desc" : "str", (string) Descriptor string representation "timestamp" : n, (numeric) The creation time of the descriptor "active" : true|false, (boolean) Activeness flag "internal" : true|false, (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors "range" : [ (json array, optional) Defined only for ranged descriptors n, (numeric) Range start inclusive n (numeric) Range end inclusive ], "next" : n (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors }, ... ] ``` **After:** ``` Result: { (json object) "wallet_name" : "str", (string) Name of wallet this operation was performed on "descriptors" : [ (json array) Array of descriptor objects { (json object) "desc" : "str", (string) Descriptor string representation "timestamp" : n, (numeric) The creation time of the descriptor "active" : true|false, (boolean) Activeness flag "internal" : true|false, (boolean, optional) Whether this is internal or external descriptor; defined only for active descriptors "range" : [ (json array, optional) Defined only for ranged descriptors n, (numeric) Range start inclusive n (numeric) Range end inclusive ], "next" : n (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors }, ... ] } ``` ACKs for top commit: achow101: re-ACK 2e5f7de meshcollider: utACK 2e5f7de jonatack: re-ACK 2e5f7de Tree-SHA512: 49bf73e46e2a61003ce594a4bfc506eb9592ccb799c2909c43a1a527490a4b4009f78dc09f3d47b4e945d3d7bb3cd2632cf48c5ace5feed5066158cc010dddc1
2 parents 66daf4c + 2e5f7de commit 7aa0d8a

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/wallet/rpcdump.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,22 +1737,23 @@ RPCHelpMan listdescriptors()
17371737
"listdescriptors",
17381738
"\nList descriptors imported into a descriptor-enabled wallet.",
17391739
{},
1740-
RPCResult{
1741-
RPCResult::Type::ARR, "", "Response is an array of descriptor objects",
1740+
RPCResult{RPCResult::Type::OBJ, "", "", {
1741+
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
1742+
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
17421743
{
17431744
{RPCResult::Type::OBJ, "", "", {
17441745
{RPCResult::Type::STR, "desc", "Descriptor string representation"},
17451746
{RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
17461747
{RPCResult::Type::BOOL, "active", "Activeness flag"},
1747-
{RPCResult::Type::BOOL, "internal", true, "Whether this is internal or external descriptor; defined only for active descriptors"},
1748+
{RPCResult::Type::BOOL, "internal", true, "Whether this is an internal or external descriptor; defined only for active descriptors"},
17481749
{RPCResult::Type::ARR_FIXED, "range", true, "Defined only for ranged descriptors", {
17491750
{RPCResult::Type::NUM, "", "Range start inclusive"},
17501751
{RPCResult::Type::NUM, "", "Range end inclusive"},
17511752
}},
17521753
{RPCResult::Type::NUM, "next", true, "The next index to generate addresses from; defined only for ranged descriptors"},
17531754
}},
1754-
}
1755-
},
1755+
}}
1756+
}},
17561757
RPCExamples{
17571758
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
17581759
},
@@ -1769,7 +1770,7 @@ RPCHelpMan listdescriptors()
17691770

17701771
LOCK(wallet->cs_wallet);
17711772

1772-
UniValue response(UniValue::VARR);
1773+
UniValue descriptors(UniValue::VARR);
17731774
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
17741775
for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
17751776
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
@@ -1798,9 +1799,13 @@ RPCHelpMan listdescriptors()
17981799
spk.pushKV("range", range);
17991800
spk.pushKV("next", wallet_descriptor.next_index);
18001801
}
1801-
response.push_back(spk);
1802+
descriptors.push_back(spk);
18021803
}
18031804

1805+
UniValue response(UniValue::VOBJ);
1806+
response.pushKV("wallet_name", wallet->GetName());
1807+
response.pushKV("descriptors", descriptors);
1808+
18041809
return response;
18051810
},
18061811
};

test/functional/wallet_listdescriptors.py

Lines changed: 25 additions & 14 deletions
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)