Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
}

// Range check
std::optional<bool> is_ranged;
int64_t range_start = 0, range_end = 1, next_index = 0;
if (!parsed_descs.at(0)->IsRange() && data.exists("range")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Range should not be specified for an un-ranged descriptor");
Expand All @@ -1501,6 +1502,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
range_end = wallet.m_keypool_size;
}
next_index = range_start;
is_ranged = true;

if (data.exists("next_index")) {
next_index = data["next_index"].getInt<int64_t>();
Expand All @@ -1522,12 +1524,13 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
}

// Ranged descriptors should not have a label
if (data.exists("range") && data.exists("label")) {
if (is_ranged.has_value() && is_ranged.value() && data.exists("label")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Ranged descriptors should not have a label");
}

bool desc_internal = internal.has_value() && internal.value();
// Internal addresses should not have a label either
if (internal && data.exists("label")) {
if (desc_internal && data.exists("label")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
}

Expand All @@ -1543,7 +1546,6 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c

for (size_t j = 0; j < parsed_descs.size(); ++j) {
auto parsed_desc = std::move(parsed_descs[j]);
bool desc_internal = internal.has_value() && internal.value();
if (parsed_descs.size() == 2) {
desc_internal = j == 1;
} else if (parsed_descs.size() > 2) {
Expand Down
13 changes: 13 additions & 0 deletions test/functional/wallet_importdescriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def run_test(self):
error_code=-8,
error_message="Internal addresses should not have a label")

self.log.info("External non-ranged addresses can have labels")
self.test_importdesc({**import_request, "internal": False}, success=True)

self.log.info("Internal addresses should be detected as such")
key = get_generate_key()
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + ")"),
Expand Down Expand Up @@ -219,6 +222,16 @@ def run_test(self):
error_code=-8,
error_message='Ranged descriptors should not have a label')

self.log.info("Ranged descriptors cannot have labels - even if range not provided by user and only implied by asterisk (*)")
self.test_importdesc({"desc":descsum_create("wpkh(" + xpub + "/100/0/*)"),
"timestamp": "now",
"label": "test",
"active": True},
success=False,
warnings=['Range not given, using default keypool range'],
error_code=-8,
error_message='Ranged descriptors should not have a label')

self.log.info("Private keys required for private keys enabled wallet")
self.test_importdesc({"desc":descsum_create(desc),
"timestamp": "now",
Expand Down
3 changes: 2 additions & 1 deletion test/functional/wallet_rescan_unconfirmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def run_test(self):
assert tx_parent_to_reorg["txid"] in node.getrawmempool()

self.log.info("Import descriptor wallet on another node")
descriptors_to_import = [{"desc": w0.getaddressinfo(parent_address)['parent_desc'], "timestamp": 0, "label": "w0 import"}]
# descriptor is ranged - label not allowed
descriptors_to_import = [{"desc": w0.getaddressinfo(parent_address)['parent_desc'], "timestamp": 0}]

node.createwallet(wallet_name="w1", disable_private_keys=True)
w1 = node.get_wallet_rpc("w1")
Expand Down