aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2021-02-26 10:07:46 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2021-02-26 10:08:02 +0100
commit8d37841cdf3a35a97ab7baa058dfc72540d1a43a (patch)
treed361bf9bc4f554ef47f7bf06c497c27f66085605
parente49117470b77fb7d53be122c6490ba163c6e304d (diff)
parenta69c3b35f8974b378a87a3e42d331bd4147e07df (diff)
downloadbitcoin-8d37841cdf3a35a97ab7baa058dfc72540d1a43a.tar.xz
Merge #21277: wallet: listdescriptors uses normalized descriptor form
a69c3b35f8974b378a87a3e42d331bd4147e07df wallet: listdescriptors uses normalized descriptor form (Ivan Metlushko) Pull request description: Rationale: show importable descriptors with `listdescriptors` RPC It uses #19136 to derive xpub at the last hardened step. **Before**: ``` [ { "desc": "wpkh(tpubD6NzVbkrYhZ4YUQRJL49TWw1VR5v3QKUNYaGGMUfJUm19x5ZqQ2hEiPiYbAQvD2nHoPGQGPg3snLPM8sjmYpvx7XQhkmyfk8xhsUwKbXzyh/84'/1'/0'/0/*)#p4cn3erf", "timestamp": 1613982591, "active": true, "internal": false, "range": [ 0, 999 ], "next": 0 }, ... ] ``` **After**: ``` [ { "desc": "wpkh([d4ade89c/84'/1'/0']tpubDDUEYcVXy6Vh5meHvcXN3sAr4k3fWwLZGpAHbkAHL8EnkDxp4d99CjNhJHfM2fUJicANvAKnCZS6XaVAgwAeKYc1KesGCN5qbQ25qQHrRxM/0/*)#8wq8rcft", "timestamp": 1613982591, "active": true, "internal": false, "range": [ 0, 999 ], "next": 0 }, ... ] ``` ACKs for top commit: achow101: ACK a69c3b35f8974b378a87a3e42d331bd4147e07df Tree-SHA512: 4f92e726cb8245aa0b520729cfd272945f0c66830f0555544e0618883aca516318543fa6ab1862058c64b4e4ed54ad1da953e032f4846eef7454122031c1b005
-rw-r--r--src/wallet/rpcdump.cpp8
-rwxr-xr-xtest/functional/wallet_listdescriptors.py16
2 files changed, 23 insertions, 1 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 99803a91d2..a2872f10ae 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -1775,6 +1775,8 @@ RPCHelpMan listdescriptors()
throw JSONRPCError(RPC_WALLET_ERROR, "listdescriptors is not available for non-descriptor wallets");
}
+ EnsureWalletIsUnlocked(wallet.get());
+
LOCK(wallet->cs_wallet);
UniValue response(UniValue::VARR);
@@ -1787,7 +1789,11 @@ RPCHelpMan listdescriptors()
UniValue spk(UniValue::VOBJ);
LOCK(desc_spk_man->cs_desc_man);
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
- spk.pushKV("desc", wallet_descriptor.descriptor->ToString());
+ std::string descriptor;
+ if (!desc_spk_man->GetDescriptorString(descriptor, false)) {
+ throw JSONRPCError(RPC_WALLET_ERROR, "Can't get normalized descriptor string.");
+ }
+ spk.pushKV("desc", descriptor);
spk.pushKV("timestamp", wallet_descriptor.creation_time);
const bool active = active_spk_mans.count(desc_spk_man) != 0;
spk.pushKV("active", active);
diff --git a/test/functional/wallet_listdescriptors.py b/test/functional/wallet_listdescriptors.py
index 9f8c341bc7..8d02949ff4 100755
--- a/test/functional/wallet_listdescriptors.py
+++ b/test/functional/wallet_listdescriptors.py
@@ -50,6 +50,22 @@ class ListDescriptorsTest(BitcoinTestFramework):
assert item['range'] == [0, 0]
assert item['timestamp'] is not None
+ self.log.info('Test descriptors with hardened derivations are listed in importable form.')
+ xprv = 'tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg'
+ xpub_acc = 'tpubDCMVLhErorrAGfApiJSJzEKwqeaf2z3NrkVMxgYQjZLzMjXMBeRw2muGNYbvaekAE8rUFLftyEar4LdrG2wXyyTJQZ26zptmeTEjPTaATts'
+ hardened_path = '/84\'/1\'/0\''
+ wallet = node.get_wallet_rpc('w2')
+ wallet.importdescriptors([{
+ 'desc': descsum_create('wpkh(' + xprv + hardened_path + '/0/*)'),
+ 'timestamp': 1296688602,
+ }])
+ expected = {'desc': descsum_create('wpkh([80002067' + hardened_path + ']' + xpub_acc + '/0/*)'),
+ 'timestamp': 1296688602,
+ 'active': False,
+ 'range': [0, 0],
+ 'next': 0}
+ assert_equal([expected], wallet.listdescriptors())
+
self.log.info('Test non-active non-range combo descriptor')
node.createwallet(wallet_name='w4', blank=True, descriptors=True)
wallet = node.get_wallet_rpc('w4')