@@ -656,43 +656,38 @@ UniValue importwallet(const JSONRPCRequest& request)
656
656
CPubKey pubkey = key.GetPubKey ();
657
657
assert (key.VerifyPubKey (pubkey));
658
658
CKeyID keyid = pubkey.GetID ();
659
- if (pwallet->HaveKey (keyid)) {
660
- pwallet->WalletLogPrintf (" Skipping import of %s (key already present)\n " , EncodeDestination (PKHash (keyid)));
661
- continue ;
662
- }
659
+
663
660
pwallet->WalletLogPrintf (" Importing %s...\n " , EncodeDestination (PKHash (keyid)));
664
- if (!pwallet->AddKeyPubKey (key, pubkey)) {
661
+
662
+ if (!pwallet->ImportPrivKeys ({{keyid, key}}, time)) {
663
+ pwallet->WalletLogPrintf (" Error importing key for %s\n " , EncodeDestination (PKHash (keyid)));
665
664
fGood = false ;
666
665
continue ;
667
666
}
668
- pwallet-> mapKeyMetadata [keyid]. nCreateTime = time;
667
+
669
668
if (has_label)
670
669
pwallet->SetAddressBook (PKHash (keyid), label, " receive" );
670
+
671
671
nTimeBegin = std::min (nTimeBegin, time);
672
672
progress++;
673
673
}
674
674
for (const auto & script_pair : scripts) {
675
675
pwallet->chain ().showProgress (" " , std::max (50 , std::min (75 , (int )((progress / total) * 100 ) + 50 )), false );
676
676
const CScript& script = script_pair.first ;
677
677
int64_t time = script_pair.second ;
678
- CScriptID id (script);
679
- if (pwallet->HaveCScript (id)) {
680
- pwallet->WalletLogPrintf (" Skipping import of %s (script already present)\n " , HexStr (script));
681
- continue ;
682
- }
683
- if (!pwallet->AddCScript (script)) {
678
+
679
+ if (!pwallet->ImportScripts ({script}, time)) {
684
680
pwallet->WalletLogPrintf (" Error importing script %s\n " , HexStr (script));
685
681
fGood = false ;
686
682
continue ;
687
683
}
688
684
if (time > 0 ) {
689
- pwallet->m_script_metadata [id].nCreateTime = time;
690
685
nTimeBegin = std::min (nTimeBegin, time);
691
686
}
687
+
692
688
progress++;
693
689
}
694
690
pwallet->chain ().showProgress (" " , 100 , false ); // hide progress dialog in GUI
695
- pwallet->UpdateTimeFirstKey (nTimeBegin);
696
691
}
697
692
pwallet->chain ().showProgress (" " , 100 , false ); // hide progress dialog in GUI
698
693
RescanWallet (*pwallet, reserver, nTimeBegin, false /* update */ );
0 commit comments