Fix importprivkey issues.
[novacoin.git] / src / rpcdump.cpp
index bb877bf..756863c 100644 (file)
@@ -67,23 +67,22 @@ Value importprivkey(const Array& params, bool fHelp)
     {
         LOCK2(cs_main, pwalletMain->cs_wallet);
 
-        pwalletMain->MarkDirty();
-        pwalletMain->SetAddressBookName(addr, strLabel);
-
         // Don't throw error in case a key is already there
         if (pwalletMain->HaveKey(keyid))
             return Value::null;
 
         pwalletMain->mapKeyMetadata[addr].nCreateTime = 1;
-
         if (!pwalletMain->AddKey(key))
             throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
 
-        // whenever a key is imported, we need to scan the whole chain
-        pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
+        pwalletMain->MarkDirty();
+        pwalletMain->SetAddressBookName(addr, strLabel);
 
-        if (fRescan) 
+        if (fRescan)
         {
+            // whenever a key is imported, we need to scan the whole chain
+            pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
+
             pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
             pwalletMain->ReacceptWalletTransactions();
         }