Import private keys from descriptor with importmulti if provided

This commit is contained in:
MeshCollider 2018-12-19 15:56:42 +13:00
parent a4d1bd1a29
commit 81a884bbd0
2 changed files with 9 additions and 7 deletions

View file

@ -1166,8 +1166,7 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
const UniValue& priv_keys = data.exists("keys") ? data["keys"].get_array() : UniValue(); const UniValue& priv_keys = data.exists("keys") ? data["keys"].get_array() : UniValue();
// Expand all descriptors to get public keys and scripts. // Expand all descriptors to get public keys and scripts, and private keys if available.
// TODO: get private keys from descriptors too
for (int i = range_start; i <= range_end; ++i) { for (int i = range_start; i <= range_end; ++i) {
FlatSigningProvider out_keys; FlatSigningProvider out_keys;
std::vector<CScript> scripts_temp; std::vector<CScript> scripts_temp;
@ -1181,7 +1180,10 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
import_data.import_scripts.emplace(x.second); import_data.import_scripts.emplace(x.second);
} }
parsed_desc->ExpandPrivate(i, keys, out_keys);
std::copy(out_keys.pubkeys.begin(), out_keys.pubkeys.end(), std::inserter(pubkey_map, pubkey_map.end())); std::copy(out_keys.pubkeys.begin(), out_keys.pubkeys.end(), std::inserter(pubkey_map, pubkey_map.end()));
std::copy(out_keys.keys.begin(), out_keys.keys.end(), std::inserter(privkey_map, privkey_map.end()));
import_data.key_origins.insert(out_keys.origins.begin(), out_keys.origins.end()); import_data.key_origins.insert(out_keys.origins.begin(), out_keys.origins.end());
} }

View file

@ -579,17 +579,17 @@ class ImportMultiTest(BitcoinTestFramework):
error_code=-8, error_code=-8,
error_message='Descriptor is ranged, please specify the range') error_message='Descriptor is ranged, please specify the range')
# Test importing of a ranged descriptor without keys # Test importing of a ranged descriptor with xpriv
self.log.info("Should import the ranged descriptor with specified range as solvable") self.log.info("Should import the ranged descriptor with specified range as solvable")
self.test_importmulti({"desc": descsum_create(desc), self.test_importmulti({"desc": descsum_create(desc),
"timestamp": "now", "timestamp": "now",
"range": 1}, "range": 1},
success=True, success=True)
warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
for address in addresses: for address in addresses:
test_address(self.nodes[1], test_address(self.nodes[1],
key.p2sh_p2wpkh_addr, address,
solvable=True) solvable=True,
ismine=True)
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": -1}, self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": -1},
success=False, error_code=-8, error_message='End of range is too high') success=False, error_code=-8, error_message='End of range is too high')