@@ -888,6 +888,7 @@ struct ImportData
888888 // Output data
889889 std::set<CScript> import_scripts;
890890 std::map<CKeyID, bool > used_keys; // !< Import these private keys if available (the value indicates whether if the key is required for solvability)
891+ std::map<CKeyID, KeyOriginInfo> key_origins;
891892};
892893
893894enum class ScriptContext
@@ -1158,7 +1159,7 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
11581159 }
11591160
11601161 std::copy (out_keys.pubkeys .begin (), out_keys.pubkeys .end (), std::inserter (pubkey_map, pubkey_map.end ()));
1161-
1162+ import_data. key_origins . insert (out_keys. origins . begin (), out_keys. origins . end ());
11621163 for (size_t i = 0 ; i < priv_keys.size (); ++i) {
11631164 const auto & str = priv_keys[i].get_str ();
11641165 CKey key = DecodeSecret (str);
@@ -1261,6 +1262,11 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12611262 if (!pwallet->GetPubKey (id, temp) && !pwallet->AddWatchOnly (GetScriptForRawPubKey (pubkey), timestamp)) {
12621263 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding address to wallet" );
12631264 }
1265+ const auto & key_orig_it = import_data.key_origins .find (id);
1266+ if (key_orig_it != import_data.key_origins .end ()) {
1267+ pwallet->AddKeyOrigin (pubkey, key_orig_it->second );
1268+ }
1269+ pwallet->mapKeyMetadata [id].nCreateTime = timestamp;
12641270 }
12651271
12661272 for (const CScript& script : script_pub_keys) {
0 commit comments