mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-29 03:02:33 +01:00
Compare commits
2 Commits
b1adab8ac1
...
c224a0a6d8
Author | SHA1 | Date | |
---|---|---|---|
|
c224a0a6d8 | ||
|
c986b43f0c |
@ -1575,14 +1575,6 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
|
|||||||
|
|
||||||
WalletDescriptor w_desc(std::move(parsed_desc), timestamp, range_start, range_end, next_index);
|
WalletDescriptor w_desc(std::move(parsed_desc), timestamp, range_start, range_end, next_index);
|
||||||
|
|
||||||
// Check if the wallet already contains the descriptor
|
|
||||||
auto existing_spk_manager = wallet.GetDescriptorScriptPubKeyMan(w_desc);
|
|
||||||
if (existing_spk_manager) {
|
|
||||||
if (!existing_spk_manager->CanUpdateToWalletDescriptor(w_desc, error)) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add descriptor to the wallet
|
// Add descriptor to the wallet
|
||||||
auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal);
|
auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal);
|
||||||
if (spk_manager == nullptr) {
|
if (spk_manager == nullptr) {
|
||||||
|
@ -2832,7 +2832,7 @@ void DescriptorScriptPubKeyMan::UpdateWalletDescriptor(WalletDescriptor& descrip
|
|||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
std::string error;
|
std::string error;
|
||||||
if (!CanUpdateToWalletDescriptor(descriptor, error)) {
|
if (!CanUpdateToWalletDescriptor(descriptor, error)) {
|
||||||
throw std::runtime_error(std::string(__func__) + ": " + error);
|
throw std::runtime_error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_map_pubkeys.clear();
|
m_map_pubkeys.clear();
|
||||||
|
@ -3909,9 +3909,11 @@ bool CWallet::IsLegacy() const
|
|||||||
|
|
||||||
DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const
|
DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const
|
||||||
{
|
{
|
||||||
for (auto& spk_man_pair : m_spk_managers) {
|
auto spk_man_pair = m_spk_managers.find(desc.id);
|
||||||
|
|
||||||
|
if (spk_man_pair != m_spk_managers.end()) {
|
||||||
// Try to downcast to DescriptorScriptPubKeyMan then check if the descriptors match
|
// Try to downcast to DescriptorScriptPubKeyMan then check if the descriptors match
|
||||||
DescriptorScriptPubKeyMan* spk_manager = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man_pair.second.get());
|
DescriptorScriptPubKeyMan* spk_manager = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man_pair->second.get());
|
||||||
if (spk_manager != nullptr && spk_manager->HasWalletDescriptor(desc)) {
|
if (spk_manager != nullptr && spk_manager->HasWalletDescriptor(desc)) {
|
||||||
return spk_manager;
|
return spk_manager;
|
||||||
}
|
}
|
||||||
|
@ -56,15 +56,20 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
|||||||
if wallet is not None:
|
if wallet is not None:
|
||||||
wrpc = wallet
|
wrpc = wallet
|
||||||
|
|
||||||
result = wrpc.importdescriptors([req])
|
try:
|
||||||
observed_warnings = []
|
result = wrpc.importdescriptors([req])
|
||||||
if 'warnings' in result[0]:
|
except JSONRPCException as e:
|
||||||
observed_warnings = result[0]['warnings']
|
assert_equal(e.error["code"], error_code)
|
||||||
assert_equal("\n".join(sorted(warnings)), "\n".join(sorted(observed_warnings)))
|
assert_equal(e.error['message'], error_message)
|
||||||
assert_equal(result[0]['success'], success)
|
else:
|
||||||
if error_code is not None:
|
observed_warnings = []
|
||||||
assert_equal(result[0]['error']['code'], error_code)
|
if 'warnings' in result[0]:
|
||||||
assert_equal(result[0]['error']['message'], error_message)
|
observed_warnings = result[0]['warnings']
|
||||||
|
assert_equal("\n".join(sorted(warnings)), "\n".join(sorted(observed_warnings)))
|
||||||
|
assert_equal(result[0]['success'], success)
|
||||||
|
if error_code is not None:
|
||||||
|
assert_equal(result[0]['error']['code'], error_code)
|
||||||
|
assert_equal(result[0]['error']['message'], error_message)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.log.info('Setting up wallets')
|
self.log.info('Setting up wallets')
|
||||||
@ -273,11 +278,11 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
|||||||
assert_equal(wpriv.getwalletinfo()['keypoolsize'], 21)
|
assert_equal(wpriv.getwalletinfo()['keypoolsize'], 21)
|
||||||
|
|
||||||
self.test_importdesc({**range_request, "range": [5, 10]}, wallet=wpriv, success=False,
|
self.test_importdesc({**range_request, "range": [5, 10]}, wallet=wpriv, success=False,
|
||||||
error_code=-8, error_message='new range must include current range = [0,20]')
|
error_code=-1, error_message='new range must include current range = [0,20]')
|
||||||
self.test_importdesc({**range_request, "range": [0, 10]}, wallet=wpriv, success=False,
|
self.test_importdesc({**range_request, "range": [0, 10]}, wallet=wpriv, success=False,
|
||||||
error_code=-8, error_message='new range must include current range = [0,20]')
|
error_code=-1, error_message='new range must include current range = [0,20]')
|
||||||
self.test_importdesc({**range_request, "range": [5, 20]}, wallet=wpriv, success=False,
|
self.test_importdesc({**range_request, "range": [5, 20]}, wallet=wpriv, success=False,
|
||||||
error_code=-8, error_message='new range must include current range = [0,20]')
|
error_code=-1, error_message='new range must include current range = [0,20]')
|
||||||
assert_equal(wpriv.getwalletinfo()['keypoolsize'], 21)
|
assert_equal(wpriv.getwalletinfo()['keypoolsize'], 21)
|
||||||
|
|
||||||
self.log.info("Check we can change descriptor internal flag")
|
self.log.info("Check we can change descriptor internal flag")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user