walletrpc: reject listdes with priv key on w-only wallets
This commit is contained in:
1 parent
9e5e9824f1
commit
ed945a6854
2 files changed
+7
-5
No files matched your search
@@ -17,6 +17,7 @@
|
|||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
|
#include <util/check.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
@@ -493,6 +494,9 @@ RPCHelpMan listdescriptors()
|
|||||||
if (!wallet) return UniValue::VNULL;
|
if (!wallet) return UniValue::VNULL;
|
||||||
|
|
||||||
const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
|
const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
|
||||||
|
if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && priv) {
|
||||||
|
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get private descriptor string for watch-only wallets");
|
||||||
|
}
|
||||||
if (priv) {
|
if (priv) {
|
||||||
EnsureWalletIsUnlocked(*wallet);
|
EnsureWalletIsUnlocked(*wallet);
|
||||||
}
|
}
|
||||||
@@ -519,9 +523,7 @@ RPCHelpMan listdescriptors()
|
|||||||
LOCK(desc_spk_man->cs_desc_man);
|
LOCK(desc_spk_man->cs_desc_man);
|
||||||
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
|
const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
|
||||||
std::string descriptor;
|
std::string descriptor;
|
||||||
if (!desc_spk_man->GetDescriptorString(descriptor, priv)) {
|
CHECK_NONFATAL(desc_spk_man->GetDescriptorString(descriptor, priv));
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get descriptor string.");
|
|
||||||
}
|
|
||||||
const bool is_range = wallet_descriptor.descriptor->IsRange();
|
const bool is_range = wallet_descriptor.descriptor->IsRange();
|
||||||
wallet_descriptors.push_back({
|
wallet_descriptors.push_back({
|
||||||
descriptor,
|
descriptor,
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
|||||||
'desc': descsum_create('wpkh(' + xpub_acc + ')'),
|
'desc': descsum_create('wpkh(' + xpub_acc + ')'),
|
||||||
'timestamp': TIME_GENESIS_BLOCK,
|
'timestamp': TIME_GENESIS_BLOCK,
|
||||||
}])
|
}])
|
||||||
assert_raises_rpc_error(-4, 'Can\'t get descriptor string', watch_only_wallet.listdescriptors, True)
|
assert_raises_rpc_error(-4, 'Can\'t get private descriptor string for watch-only wallets', watch_only_wallet.listdescriptors, True)
|
||||||
|
|
||||||
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)
|
node.createwallet(wallet_name='w4', blank=True)
|
||||||
@@ -122,7 +122,7 @@ class ListDescriptorsTest(BitcoinTestFramework):
|
|||||||
{'active': False,
|
{'active': False,
|
||||||
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
|
'desc': 'combo(0227d85ba011276cf25b51df6a188b75e604b38770a462b2d0e9fb2fc839ef5d3f)#np574htj',
|
||||||
'timestamp': TIME_GENESIS_BLOCK},
|
'timestamp': TIME_GENESIS_BLOCK},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
assert_equal(expected, wallet.listdescriptors())
|
assert_equal(expected, wallet.listdescriptors())
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user