Merge pull request #355 from svost/c++11
[novacoin.git] / src / rpcdump.cpp
index bb877bf..0ee0f0a 100644 (file)
@@ -60,30 +60,29 @@ Value importprivkey(const Array& params, bool fHelp)
 
     CKey key;
     bool fCompressed;
-    CSecret secret = vchSecret.GetSecret(fCompressed);
+    auto secret = vchSecret.GetSecret(fCompressed);
     key.SetSecret(secret, fCompressed);
-    CKeyID keyid = key.GetPubKey().GetID();
+    auto keyid = key.GetPubKey().GetID();
     CBitcoinAddress addr = CBitcoinAddress(keyid);
     {
         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();
         }
@@ -106,7 +105,7 @@ Value importaddress(const Array& params, bool fHelp)
             throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "It's senseless to import pubkey pair address.");
         script.SetAddress(address);
     } else if (IsHex(params[0].get_str())) {
-        std::vector<unsigned char> data(ParseHex(params[0].get_str()));
+        auto data = ParseHex(params[0].get_str());
         script = CScript(data.begin(), data.end());
     } else
         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Novacoin address or script");
@@ -167,7 +166,7 @@ Value removeaddress(const Array& params, bool fHelp)
             throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey pair addresses aren't supported.");
         script.SetAddress(address);
     } else if (IsHex(params[0].get_str())) {
-        std::vector<unsigned char> data(ParseHex(params[0].get_str()));
+        auto data = ParseHex(params[0].get_str());
         script = CScript(data.begin(), data.end());
     } else
         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script");
@@ -213,7 +212,7 @@ Value dumpprivkey(const Array& params, bool fHelp)
 
     EnsureWalletIsUnlocked();
 
-    string strAddress = params[0].get_str();
+    auto strAddress = params[0].get_str();
     CBitcoinAddress address;
     if (!address.SetString(strAddress))
         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address");
@@ -239,7 +238,7 @@ Value dumppem(const Array& params, bool fHelp)
 
     EnsureWalletIsUnlocked();
 
-    string strAddress = params[0].get_str();
+    auto strAddress = params[0].get_str();
     SecureString strPassKey;
     strPassKey.reserve(100);
     strPassKey = params[2].get_str().c_str();
@@ -304,7 +303,6 @@ Value importmalleablekey(const Array& params, bool fHelp)
             "importmalleablekey <Key data>\n"
             "Imports the private key pair into your wallet.\n");
 
-
     EnsureWalletIsUnlocked();
 
     CMalleableKey mKey;