Skip to content

Commit 81a884b

Browse files
committed
Import private keys from descriptor with importmulti if provided
1 parent a4d1bd1 commit 81a884b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/wallet/rpcdump.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,7 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
11661166

11671167
const UniValue& priv_keys = data.exists("keys") ? data["keys"].get_array() : UniValue();
11681168

1169-
// Expand all descriptors to get public keys and scripts.
1170-
// TODO: get private keys from descriptors too
1169+
// Expand all descriptors to get public keys and scripts, and private keys if available.
11711170
for (int i = range_start; i <= range_end; ++i) {
11721171
FlatSigningProvider out_keys;
11731172
std::vector<CScript> scripts_temp;
@@ -1181,7 +1180,10 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
11811180
import_data.import_scripts.emplace(x.second);
11821181
}
11831182

1183+
parsed_desc->ExpandPrivate(i, keys, out_keys);
1184+
11841185
std::copy(out_keys.pubkeys.begin(), out_keys.pubkeys.end(), std::inserter(pubkey_map, pubkey_map.end()));
1186+
std::copy(out_keys.keys.begin(), out_keys.keys.end(), std::inserter(privkey_map, privkey_map.end()));
11851187
import_data.key_origins.insert(out_keys.origins.begin(), out_keys.origins.end());
11861188
}
11871189

test/functional/wallet_importmulti.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,17 +579,17 @@ def run_test(self):
579579
error_code=-8,
580580
error_message='Descriptor is ranged, please specify the range')
581581

582-
# Test importing of a ranged descriptor without keys
582+
# Test importing of a ranged descriptor with xpriv
583583
self.log.info("Should import the ranged descriptor with specified range as solvable")
584584
self.test_importmulti({"desc": descsum_create(desc),
585585
"timestamp": "now",
586586
"range": 1},
587-
success=True,
588-
warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
587+
success=True)
589588
for address in addresses:
590589
test_address(self.nodes[1],
591-
key.p2sh_p2wpkh_addr,
592-
solvable=True)
590+
address,
591+
solvable=True,
592+
ismine=True)
593593

594594
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": -1},
595595
success=False, error_code=-8, error_message='End of range is too high')

0 commit comments

Comments
 (0)