mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-05-17 23:56:39 +00:00
wallet, rpc: update listdescriptors response format
This commit is contained in:
parent
461f0c781e
commit
2e5f7def22
@ -1747,22 +1747,23 @@ RPCHelpMan listdescriptors()
|
|||||||
"listdescriptors",
|
"listdescriptors",
|
||||||
"\nList descriptors imported into a descriptor-enabled wallet.",
|
"\nList descriptors imported into a descriptor-enabled wallet.",
|
||||||
{},
|
{},
|
||||||
RPCResult{
|
RPCResult{RPCResult::Type::OBJ, "", "", {
|
||||||
RPCResult::Type::ARR, "", "Response is an array of descriptor objects",
|
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
|
||||||
|
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
|
||||||
{
|
{
|
||||||
{RPCResult::Type::OBJ, "", "", {
|
{RPCResult::Type::OBJ, "", "", {
|
||||||
{RPCResult::Type::STR, "desc", "Descriptor string representation"},
|
{RPCResult::Type::STR, "desc", "Descriptor string representation"},
|
||||||
{RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
|
{RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
|
||||||
{RPCResult::Type::BOOL, "active", "Activeness flag"},
|
{RPCResult::Type::BOOL, "active", "Activeness flag"},
|
||||||
{RPCResult::Type::BOOL, "internal", true, "Whether this is internal or external descriptor; defined only for active descriptors"},
|
{RPCResult::Type::BOOL, "internal", true, "Whether this is an internal or external descriptor; defined only for active descriptors"},
|
||||||
{RPCResult::Type::ARR_FIXED, "range", true, "Defined only for ranged descriptors", {
|
{RPCResult::Type::ARR_FIXED, "range", true, "Defined only for ranged descriptors", {
|
||||||
{RPCResult::Type::NUM, "", "Range start inclusive"},
|
{RPCResult::Type::NUM, "", "Range start inclusive"},
|
||||||
{RPCResult::Type::NUM, "", "Range end inclusive"},
|
{RPCResult::Type::NUM, "", "Range end inclusive"},
|
||||||
}},
|
}},
|
||||||
{RPCResult::Type::NUM, "next", true, "The next index to generate addresses from; defined only for ranged descriptors"},
|
{RPCResult::Type::NUM, "next", true, "The next index to generate addresses from; defined only for ranged descriptors"},
|
||||||
}},
|
}},
|
||||||
}
|
}}
|
||||||
},
|
}},
|
||||||
RPCExamples{
|
RPCExamples{
|
||||||
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
|
HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
|
||||||
},
|
},
|
||||||
@ -1779,7 +1780,7 @@ RPCHelpMan listdescriptors()
|
|||||||
|
|
||||||
LOCK(wallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
|
|
||||||
UniValue response(UniValue::VARR);
|
UniValue descriptors(UniValue::VARR);
|
||||||
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
|
const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
|
||||||
for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
|
for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
|
||||||
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
|
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
|
||||||
@ -1808,9 +1809,13 @@ RPCHelpMan listdescriptors()
|
|||||||
spk.pushKV("range", range);
|
spk.pushKV("range", range);
|
||||||
spk.pushKV("next", wallet_descriptor.next_index);
|
spk.pushKV("next", wallet_descriptor.next_index);
|
||||||
}
|
}
|
||||||
response.push_back(spk);
|
descriptors.push_back(spk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue response(UniValue::VOBJ);
|
||||||
|
response.pushKV("wallet_name", wallet->GetName());
|
||||||
|
response.pushKV("descriptors", descriptors);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -36,15 +36,16 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.log.info('Test the command for empty descriptors wallet.')
|
self.log.info('Test the command for empty descriptors wallet.')
|
||||||
node.createwallet(wallet_name='w2', blank=True, descriptors=True)
|
node.createwallet(wallet_name='w2', blank=True, descriptors=True)
|
||||||
assert_equal(0, len(node.get_wallet_rpc('w2').listdescriptors()))
|
assert_equal(0, len(node.get_wallet_rpc('w2').listdescriptors()['descriptors']))
|
||||||
|
|
||||||
self.log.info('Test the command for a default descriptors wallet.')
|
self.log.info('Test the command for a default descriptors wallet.')
|
||||||
node.createwallet(wallet_name='w3', descriptors=True)
|
node.createwallet(wallet_name='w3', descriptors=True)
|
||||||
result = node.get_wallet_rpc('w3').listdescriptors()
|
result = node.get_wallet_rpc('w3').listdescriptors()
|
||||||
assert_equal(6, len(result))
|
assert_equal("w3", result['wallet_name'])
|
||||||
assert_equal(6, len([d for d in result if d['active']]))
|
assert_equal(6, len(result['descriptors']))
|
||||||
assert_equal(3, len([d for d in result if d['internal']]))
|
assert_equal(6, len([d for d in result['descriptors'] if d['active']]))
|
||||||
for item in result:
|
assert_equal(3, len([d for d in result['descriptors'] if d['internal']]))
|
||||||
|
for item in result['descriptors']:
|
||||||
assert item['desc'] != ''
|
assert item['desc'] != ''
|
||||||
assert item['next'] == 0
|
assert item['next'] == 0
|
||||||
assert item['range'] == [0, 0]
|
assert item['range'] == [0, 0]
|
||||||
@ -59,12 +60,17 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
|||||||
'desc': descsum_create('wpkh(' + xprv + hardened_path + '/0/*)'),
|
'desc': descsum_create('wpkh(' + xprv + hardened_path + '/0/*)'),
|
||||||
'timestamp': 1296688602,
|
'timestamp': 1296688602,
|
||||||
}])
|
}])
|
||||||
expected = {'desc': descsum_create('wpkh([80002067' + hardened_path + ']' + xpub_acc + '/0/*)'),
|
expected = {
|
||||||
'timestamp': 1296688602,
|
'wallet_name': 'w2',
|
||||||
'active': False,
|
'descriptors': [
|
||||||
'range': [0, 0],
|
{'desc': descsum_create('wpkh([80002067' + hardened_path + ']' + xpub_acc + '/0/*)'),
|
||||||
'next': 0}
|
'timestamp': 1296688602,
|
||||||
assert_equal([expected], wallet.listdescriptors())
|
'active': False,
|
||||||
|
'range': [0, 0],
|
||||||
|
'next': 0},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
assert_equal(expected, wallet.listdescriptors())
|
||||||
|
|
||||||
self.log.info('Test non-active non-range combo descriptor')
|
self.log.info('Test non-active non-range combo descriptor')
|
||||||
node.createwallet(wallet_name='w4', blank=True, descriptors=True)
|
node.createwallet(wallet_name='w4', blank=True, descriptors=True)
|
||||||
@ -73,9 +79,14 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
|||||||
'desc': descsum_create('combo(' + node.get_deterministic_priv_key().key + ')'),
|
'desc': descsum_create('combo(' + node.get_deterministic_priv_key().key + ')'),
|
||||||
'timestamp': 1296688602,
|
'timestamp': 1296688602,
|
||||||
}])
|
}])
|
||||||
expected = [{'active': False,
|
expected = {
|
||||||
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
|
'wallet_name': 'w4',
|
||||||
'timestamp': 1296688602}]
|
'descriptors': [
|
||||||
|
{'active': False,
|
||||||
|
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
|
||||||
|
'timestamp': 1296688602},
|
||||||
|
]
|
||||||
|
}
|
||||||
assert_equal(expected, wallet.listdescriptors())
|
assert_equal(expected, wallet.listdescriptors())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user