Fix importprivkey issues.
authorCryptoManiac <balthazar@yandex.ru>
Sun, 3 Apr 2016 23:26:33 +0000 (02:26 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Sun, 3 Apr 2016 23:26:33 +0000 (02:26 +0300)
1) Handle parameters correctly;
2) Create label entry for a newly imported private key.

src/bitcoinrpc.cpp
src/rpcdump.cpp

index 60baac0..b32b86e 100644 (file)
@@ -1256,6 +1256,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
     if (strMethod == "keypoolrefill"          && n > 0) ConvertTo<int64_t>(params[0]);
     if (strMethod == "keypoolreset"           && n > 0) ConvertTo<int64_t>(params[0]);
     if (strMethod == "importaddress"          && n > 2) ConvertTo<bool>(params[2]);
+    if (strMethod == "importprivkey"          && n > 2) ConvertTo<bool>(params[2]);
 
     return params;
 }
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();
         }