Merge branch 'master' of github.com:novacoin-project/novacoin
authorCryptoManiac <balthazar@yandex.ru>
Tue, 29 Mar 2016 01:23:11 +0000 (04:23 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 29 Mar 2016 01:23:11 +0000 (04:23 +0300)
1  2 
src/bitcoinrpc.cpp
src/main.cpp
src/rpcwallet.cpp
src/wallet.cpp

diff --combined src/bitcoinrpc.cpp
@@@ -173,7 -173,7 +173,7 @@@ string CRPCTable::help(string strComman
          // We already filter duplicates, but these deprecated screw up the sort order
          if (strMethod.find("label") != string::npos)
              continue;
-         if (strCommand != "" && strMethod != strCommand)
+         if (!strCommand.empty() && strMethod != strCommand)
              continue;
          try
          {
          {
              // Help text is returned in an exception
              string strHelp = string(e.what());
-             if (strCommand == "")
+             if (strCommand.empty())
                  if (strHelp.find('\n') != string::npos)
                      strHelp = strHelp.substr(0, strHelp.find('\n'));
              strRet += strHelp + "\n";
          }
      }
-     if (strRet == "")
+     if (strRet.empty())
          strRet = strprintf("help: unknown command: %s\n", strCommand.c_str());
      strRet = strRet.substr(0,strRet.size()-1);
      return strRet;
@@@ -297,7 -297,6 +297,7 @@@ static const CRPCCommand vRPCCommands[
      { "submitblock",            &submitblock,            false,  false },
      { "listsinceblock",         &listsinceblock,         false,  false },
      { "dumpprivkey",            &dumpprivkey,            false,  false },
 +    { "dumppem",                &dumppem,                true,   false },
      { "dumpwallet",             &dumpwallet,             true,   false },
      { "importwallet",           &importwallet,           false,  false },
      { "importprivkey",          &importprivkey,          false,  false },
@@@ -467,7 -466,7 +467,7 @@@ int ReadHTTPHeader(std::basic_istream<c
  int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet)
  {
      mapHeadersRet.clear();
-     strMessageRet = "";
+     strMessageRet.clear();
  
      // Read status
      int nProto = 0;
@@@ -783,7 -782,7 +783,7 @@@ void ThreadRPCServer2(void* parg
      printf("ThreadRPCServer started\n");
  
      strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
-     if (mapArgs["-rpcpassword"] == "")
+     if (mapArgs["-rpcpassword"].empty())
      {
          unsigned char rand_pwd[32];
          RAND_bytes(rand_pwd, 32);
@@@ -1086,7 -1085,7 +1086,7 @@@ json_spirit::Value CRPCTable::execute(c
  
      // Observe safe mode
      string strWarning = GetWarnings("rpc");
-     if (strWarning != "" && !GetBoolArg("-disablesafemode") &&
+     if (!strWarning.empty() && !GetBoolArg("-disablesafemode") &&
          !pcmd->okSafeMode)
          throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning);
  
  
  Object CallRPC(const string& strMethod, const Array& params)
  {
-     if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
+     if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty())
          throw runtime_error(strprintf(
              _("You must set rpcpassword=<password> in the configuration file:\n%s\n"
                "If the file does not exist, create it with owner-readable-only file permissions."),
@@@ -1300,7 -1299,7 +1300,7 @@@ int CommandLineRPC(int argc, char *argv
          {
              // Result
              if (result.type() == null_type)
-                 strPrint = "";
+                 strPrint.clear();
              else if (result.type() == str_type)
                  strPrint = result.get_str();
              else
          PrintException(NULL, "CommandLineRPC()");
      }
  
-     if (strPrint != "")
+     if (!strPrint.empty())
      {
          fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
      }
diff --combined src/main.cpp
@@@ -2508,7 -2508,7 +2508,7 @@@ bool static ReserealizeBlockSignature(C
          return true;
      }
  
 -    return CKey::ReserealizeSignature(pblock->vchBlockSig);
 +    return CPubKey::ReserealizeSignature(pblock->vchBlockSig);
  }
  
  bool static IsCanonicalBlockSignature(CBlock* pblock)
@@@ -2667,8 -2667,8 +2667,8 @@@ bool CBlock::CheckBlockSignature() cons
      if (whichType == TX_PUBKEY)
      {
          valtype& vchPubKey = vSolutions[0];
 -        CKey key;
 -        if (!key.SetPubKey(vchPubKey))
 +        CPubKey key(vchPubKey);
 +        if (!key.IsValid())
              return false;
          return key.Verify(GetHash(), vchBlockSig);
      }
@@@ -3037,7 -3037,7 +3037,7 @@@ string GetWarnings(string strFor
          strRPC = "test";
  
      // Misc warnings like out of disk space and clock is wrong
-     if (strMiscWarning != "")
+     if (!strMiscWarning.empty())
      {
          nPriority = 1000;
          strStatusBar = strMiscWarning;
diff --combined src/rpcwallet.cpp
@@@ -350,7 -350,7 +350,7 @@@ Value sendtoaddress(const Array& params
          throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
  
      string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
-     if (strError != "")
+     if (!strError.empty())
          throw JSONRPCError(RPC_WALLET_ERROR, strError);
  
      return wtx.GetHash().GetHex();
@@@ -451,11 -451,11 +451,11 @@@ Value verifymessage(const Array& params
      ss << strMessageMagic;
      ss << strMessage;
  
 -    CKey key;
 +    CPubKey key;
      if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
          return false;
  
 -    return (key.GetPubKey().GetID() == keyID);
 +    return (key.GetID() == keyID);
  }
  
  
@@@ -738,7 -738,7 +738,7 @@@ Value sendfrom(const Array& params, boo
  
      // Send
      string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx);
-     if (strError != "")
+     if (!strError.empty())
          throw JSONRPCError(RPC_WALLET_ERROR, strError);
  
      return wtx.GetHash().GetHex();
@@@ -843,7 -843,7 +843,7 @@@ Value addmultisigaddress(const Array& p
                        "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired));
      if (keys.size() > 16)
          throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number");
 -    std::vector<CKey> pubkeys;
 +    std::vector<CPubKey> pubkeys;
      pubkeys.resize(keys.size());
      for (unsigned int i = 0; i < keys.size(); i++)
      {
              if (!pwalletMain->GetPubKey(keyID, vchPubKey))
                  throw runtime_error(
                      strprintf("no full public key for address %s",ks.c_str()));
 -            if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey))
 +            if (!vchPubKey.IsValid())
                  throw runtime_error(" Invalid public key: "+ks);
 +            pubkeys[i] = vchPubKey;
          }
  
          // Case 2: hex public key
          else if (IsHex(ks))
          {
              CPubKey vchPubKey(ParseHex(ks));
 -            if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey))
 +            if (!vchPubKey.IsValid())
                  throw runtime_error(" Invalid public key: "+ks);
 +             pubkeys[i] = vchPubKey;
          }
          else
          {
@@@ -1069,7 -1067,7 +1069,7 @@@ void ListTransactions(const CWalletTx& 
      bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY);
  
      // Generated blocks assigned to account ""
-     if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == ""))
+     if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty()))
      {
          Object entry;
          entry.push_back(Pair("account", string("")));
@@@ -1692,7 -1690,7 +1692,7 @@@ public
          obj.push_back(Pair("isscript", false));
          if (mine == MINE_SPENDABLE) {
              pwalletMain->GetPubKey(keyID, vchPubKey);
 -            obj.push_back(Pair("pubkey", HexStr(vchPubKey.Raw())));
 +            obj.push_back(Pair("pubkey", HexStr(vchPubKey.begin(), vchPubKey.end())));
              obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
          }
          return obj;
@@@ -1888,9 -1886,8 +1888,9 @@@ Value makekeypair(const Array& params, 
  
      bool fCompressed;
      CSecret vchSecret = key.GetSecret(fCompressed);
 +    CPubKey vchPubKey = key.GetPubKey();
      result.push_back(Pair("Secret", HexStr<CSecret::iterator>(vchSecret.begin(), vchSecret.end())));
 -    result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw())));
 +    result.push_back(Pair("PublicKey", HexStr(vchPubKey.begin(), vchPubKey.end())));
      return result;
  }
  
@@@ -1973,8 -1970,8 +1973,8 @@@ Value adjustmalleablepubkey(const Array
      malleablePubKey.GetVariant(R, vchPubKeyVariant);
  
      Object result;
 -    result.push_back(Pair("R", HexStr(R.Raw())));
 -    result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.Raw())));
 +    result.push_back(Pair("R", HexStr(R.begin(), R.end())));
 +    result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.begin(), vchPubKeyVariant.end())));
      result.push_back(Pair("KeyVariantID", CBitcoinAddress(vchPubKeyVariant.GetID()).ToString()));
  
      return result;
diff --combined src/wallet.cpp
@@@ -12,7 -12,6 +12,7 @@@
  #include "kernel.h"
  #include "coincontrol.h"
  #include <boost/algorithm/string/replace.hpp>
 +#include <openssl/bio.h>
  
  #include "main.h"
  
@@@ -517,19 -516,6 +517,19 @@@ bool CWallet::DecryptWallet(const Secur
      return true;
  }
  
 +bool CWallet::GetPEM(const CKeyID &keyID, const std::string &fileName, const SecureString &strPassKey) const
 +{
 +    BIO *pemOut = BIO_new_file(fileName.c_str(), "w");
 +    if (pemOut == NULL)
 +        return error("GetPEM() : failed to create file %s\n", fileName.c_str());
 +    CKey key;
 +    if (!GetKey(keyID, key))
 +        return error("GetPEM() : failed to get key for address=%s\n", CBitcoinAddress(keyID).ToString().c_str());
 +    bool result = key.WritePEM(pemOut, strPassKey);
 +    BIO_free(pemOut);
 +    return result;
 +}
 +
  int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
  {
      int64_t nRet = nOrderPosNext++;
@@@ -956,7 -942,7 +956,7 @@@ void CWalletTx::GetAccountAmounts(cons
      list<pair<CBitcoinAddress, int64_t> > listSent;
      GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter);
  
-     if (strAccount == "")
+     if (strAccount.empty())
          nGenerated = allGeneratedMature;
      if (strAccount == strSentAccount)
      {