Skip to content

Commit 99a8b60

Browse files
fanquakeknst
authored andcommitted
Merge bitcoin#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 bitcoin#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
1 parent 6ee2c7c commit 99a8b60

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
@@ -1943,22 +1943,23 @@ RPCHelpMan listdescriptors()
19431943
"listdescriptors",
19441944
"\nList descriptors imported into a descriptor-enabled wallet.",
19451945
{},
1946-
RPCResult{
1947-
RPCResult::Type::ARR, "", "Response is an array of descriptor objects",
1946+
RPCResult{RPCResult::Type::OBJ, "", "", {
1947+
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
1948+
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
19481949
{
19491950
{RPCResult::Type::OBJ, "", "", {
19501951
{RPCResult::Type::STR, "desc", "Descriptor string representation"},
19511952
{RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
19521953
{RPCResult::Type::BOOL, "active", "Activeness flag"},
1953-
{RPCResult::Type::BOOL, "internal", true, "Whether this is internal or external descriptor; defined only for active descriptors"},
1954+
{RPCResult::Type::BOOL, "internal", true, "Whether this is an internal or external descriptor; defined only for active descriptors"},
19541955
{RPCResult::Type::ARR_FIXED, "range", true, "Defined only for ranged descriptors", {
19551956
{RPCResult::Type::NUM, "", "Range start inclusive"},
19561957
{RPCResult::Type::NUM, "", "Range end inclusive"},
19571958
}},
19581959
{RPCResult::Type::NUM, "next", true, "The next index to generate addresses from; defined only for ranged descriptors"},
19591960
}},
1960-
}
1961-
},
1961+
}}
1962+
}},
19621963
RPCExamples{
19631964
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
19641965
},
@@ -1975,7 +1976,7 @@ RPCHelpMan listdescriptors()
19751976

19761977
LOCK(wallet->cs_wallet);
19771978

1978-
UniValue response(UniValue::VARR);
1979+
UniValue descriptors(UniValue::VARR);
19791980
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
19801981
for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
19811982
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
@@ -2004,9 +2005,13 @@ RPCHelpMan listdescriptors()
20042005
spk.pushKV("range", range);
20052006
spk.pushKV("next", wallet_descriptor.next_index);
20062007
}
2007-
response.push_back(spk);
2008+
descriptors.push_back(spk);
20082009
}
20092010

2011+
UniValue response(UniValue::VOBJ);
2012+
response.pushKV("wallet_name", wallet->GetName());
2013+
response.pushKV("descriptors", descriptors);
2014+
20102015
return response;
20112016
},
20122017
};

test/functional/wallet_listdescriptors.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ def run_test(self):
3737

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

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

7076
self.log.info('Test non-active non-range combo descriptor')
7177
node.createwallet(wallet_name='w4', blank=True, descriptors=True)
@@ -74,9 +80,14 @@ def run_test(self):
7480
'desc': descsum_create('combo(' + node.get_deterministic_priv_key().key + ')'),
7581
'timestamp': 1296688602,
7682
}])
77-
expected = [{'active': False,
78-
'desc': 'combo(038af19f35924e37ad7c3c8045d1e19b9b90b7310e08b892e620c253a102fe49f0)#2j2j0825',
79-
'timestamp': 1296688602}]
83+
expected = {
84+
'wallet_name': 'w4',
85+
'descriptors': [
86+
{'active': False,
87+
'desc': 'combo(038af19f35924e37ad7c3c8045d1e19b9b90b7310e08b892e620c253a102fe49f0)#2j2j0825',
88+
'timestamp': 1296688602},
89+
]
90+
}
8091
assert_equal(expected, wallet.listdescriptors())
8192

8293

0 commit comments

Comments
 (0)