Merge branch 'master' of https://github.com/bitcoin/bitcoin
authorWladimir J. van der Laan <laanwj@gmail.com>
Sat, 6 Aug 2011 16:45:15 +0000 (18:45 +0200)
committerWladimir J. van der Laan <laanwj@gmail.com>
Sat, 6 Aug 2011 16:45:15 +0000 (18:45 +0200)
1  2 
src/bitcoinrpc.cpp
src/init.cpp
src/util.h

diff --combined src/bitcoinrpc.cpp
@@@ -49,13 -49,13 +49,13 @@@ Object JSONRPCError(int code, const str
  }
  
  
 -void PrintConsole(const char* format, ...)
 +void PrintConsole(const std::string &format, ...)
  {
      char buffer[50000];
      int limit = sizeof(buffer);
      va_list arg_ptr;
      va_start(arg_ptr, format);
 -    int ret = _vsnprintf(buffer, limit, format, arg_ptr);
 +    int ret = _vsnprintf(buffer, limit, format.c_str(), arg_ptr);
      va_end(arg_ptr);
      if (ret < 0 || ret >= limit)
      {
@@@ -342,21 -342,19 +342,19 @@@ Value getnewaddress(const Array& params
          strAccount = AccountFromValue(params[0]);
  
      // Generate a new key that is added to wallet
-     string strAddress = CBitcoinAddress(pwalletMain->GetOrReuseKeyFromPool()).ToString();
+     CBitcoinAddress address(pwalletMain->GetOrReuseKeyFromPool());
  
      // This could be done in the same main CS as GetKeyFromKeyPool.
      CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook)
-        pwalletMain->SetAddressBookName(strAddress, strAccount);
+        pwalletMain->SetAddressBookName(address, strAccount);
  
-     return strAddress;
+     return address.ToString();
  }
  
  
  // requires cs_main, cs_mapWallet, cs_mapAddressBook locks
  CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
  {
-     string strAddress;
      CWalletDB walletdb(pwalletMain->strWalletFile);
  
      CAccount account;
              else
              {
                  account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool();
-                 string strAddress = CBitcoinAddress(account.vchPubKey).ToString();
-                 pwalletMain->SetAddressBookName(strAddress, strAccount);
+                 pwalletMain->SetAddressBookName(CBitcoinAddress(account.vchPubKey), strAccount);
                  walletdb.WriteAccount(strAccount, account);
              }
          }
@@@ -434,8 -431,7 +431,7 @@@ Value setaccount(const Array& params, b
              "setaccount <bitcoinaddress> <account>\n"
              "Sets the account associated with the given address.");
  
-     string strAddress = params[0].get_str();
-     CBitcoinAddress address(strAddress);
+     CBitcoinAddress address(params[0].get_str());
      if (!address.IsValid())
          throw JSONRPCError(-5, "Invalid bitcoin address");
  
                  GetAccountAddress(strOldAccount, true);
          }
  
-         pwalletMain->SetAddressBookName(strAddress, strAccount);
+         pwalletMain->SetAddressBookName(address, strAccount);
      }
  
      return Value::null;
@@@ -470,8 -466,9 +466,9 @@@ Value getaccount(const Array& params, b
              "getaccount <bitcoinaddress>\n"
              "Returns the account associated with the given address.");
  
-     string strAddress = params[0].get_str();
-     CBitcoinAddress address(strAddress);
+     CBitcoinAddress address(params[0].get_str());
+     if (!address.IsValid())
+         throw JSONRPCError(-5, "Invalid bitcoin address");
  
      string strAccount;
      CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook)
@@@ -536,7 -533,9 +533,9 @@@ Value sendtoaddress(const Array& params
              "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n"
              "<amount> is a real and is rounded to the nearest 0.00000001");
  
-     string strAddress = params[0].get_str();
+     CBitcoinAddress address(params[0].get_str());
+     if (!address.IsValid())
+         throw JSONRPCError(-5, "Invalid bitcoin address");
  
      // Amount
      int64 nAmount = AmountFromValue(params[1]);
          if(pwalletMain->IsLocked())
              throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect.");
  
-         string strError = pwalletMain->SendMoneyToBitcoinAddress(strAddress, nAmount, wtx);
+         string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx);
          if (strError != "")
              throw JSONRPCError(-4, strError);
      }
@@@ -807,7 -806,9 +806,9 @@@ Value sendfrom(const Array& params, boo
              "<amount> is a real and is rounded to the nearest 0.00000001");
  
      string strAccount = AccountFromValue(params[0]);
-     string strAddress = params[1].get_str();
+     CBitcoinAddress address(params[1].get_str());
+     if (!address.IsValid())
+         throw JSONRPCError(-5, "Invalid bitcoin address");
      int64 nAmount = AmountFromValue(params[2]);
      int nMinDepth = 1;
      if (params.size() > 3)
              throw JSONRPCError(-6, "Account has insufficient funds");
  
          // Send
-         string strError = pwalletMain->SendMoneyToBitcoinAddress(strAddress, nAmount, wtx);
+         string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx);
          if (strError != "")
              throw JSONRPCError(-4, strError);
      }
@@@ -1538,8 -1539,7 +1539,7 @@@ Value validateaddress(const Array& para
              "validateaddress <bitcoinaddress>\n"
              "Return information about <bitcoinaddress>.");
  
-     string strAddress = params[0].get_str();
-     CBitcoinAddress address(strAddress);
+     CBitcoinAddress address(params[0].get_str());
      bool isValid = address.IsValid();
  
      Object ret;
@@@ -1742,7 -1742,7 +1742,7 @@@ string pAllowInSafeMode[] 
      "getinfo",
      "getnewaddress",
      "getaccountaddress",
-     "setlabel",
+     "setlabel", // deprecated
      "getaccount",
      "getlabel", // deprecated
      "getaddressesbyaccount",
@@@ -2373,7 -2373,7 +2373,7 @@@ int CommandLineRPC(int argc, char *argv
          if (strMethod == "getreceivedbyaccount"   && n > 1) ConvertTo<boost::int64_t>(params[1]);
          if (strMethod == "getreceivedbylabel"     && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated
          if (strMethod == "getallreceived"         && n > 0) ConvertTo<boost::int64_t>(params[0]); // deprecated
-         if (strMethod == "getallreceived"         && n > 1) ConvertTo<bool>(params[1]);
+         if (strMethod == "getallreceived"         && n > 1) ConvertTo<bool>(params[1]); // deprecated
          if (strMethod == "listreceivedbyaddress"  && n > 0) ConvertTo<boost::int64_t>(params[0]);
          if (strMethod == "listreceivedbyaddress"  && n > 1) ConvertTo<bool>(params[1]);
          if (strMethod == "listreceivedbyaccount"  && n > 0) ConvertTo<boost::int64_t>(params[0]);
diff --combined src/init.cpp
@@@ -3,7 -3,7 +3,7 @@@
  // file license.txt or http://www.opensource.org/licenses/mit-license.php.
  #include "headers.h"
  #include "db.h"
 -#include "rpc.h"
 +#include "bitcoinrpc.h"
  #include "net.h"
  #include "init.h"
  #include "strlcpy.h"
@@@ -79,7 -79,7 +79,7 @@@ void HandleSIGTERM(int
  //
  // Start
  //
 -#ifndef GUI
 +#if !defined(QT_GUI) && !defined(GUI)
  int main(int argc, char* argv[])
  {
      bool fRet = false;
@@@ -239,14 -239,16 +239,15 @@@ bool AppInit2(int argc, char* argv[]
          fServer = GetBoolArg("-server");
  
      /* force fServer when running without GUI */
 -#ifndef GUI
 +#if !defined(QT_GUI) && !defined(GUI)
      fServer = true;
  #endif
 -
      fPrintToConsole = GetBoolArg("-printtoconsole");
      fPrintToDebugger = GetBoolArg("-printtodebugger");
  
      fTestNet = GetBoolArg("-testnet");
-     fNoListen = GetBoolArg("-nolisten");
+     bool fTOR = (fUseProxy && addrProxy.port == htons(9050));
+     fNoListen = GetBoolArg("-nolisten") || fTOR;
      fLogTimestamps = GetBoolArg("-logtimestamps");
  
      for (int i = 1; i < argc; i++)
      strErrors = "";
      int64 nStart;
  
 +    InitMessage("Loading addresses...");
      printf("Loading addresses...\n");
      nStart = GetTimeMillis();
      if (!LoadAddresses())
          strErrors += _("Error loading addr.dat      \n");
      printf(" addresses   %15"PRI64d"ms\n", GetTimeMillis() - nStart);
  
 +    InitMessage("Loading block index...");
      printf("Loading block index...\n");
      nStart = GetTimeMillis();
      if (!LoadBlockIndex())
          strErrors += _("Error loading blkindex.dat      \n");
      printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
  
 +    InitMessage("Loading wallet...");
      printf("Loading wallet...\n");
      nStart = GetTimeMillis();
      bool fFirstRun;
      }
      if (pindexBest != pindexRescan)
      {
 +        InitMessage("Rescanning...");
          printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
          nStart = GetTimeMillis();
          pwalletMain->ScanForWalletTransactions(pindexRescan, true);
          printf(" rescan      %15"PRI64d"ms\n", GetTimeMillis() - nStart);
      }
  
 +    InitMessage("Done loading");
      printf("Done loading\n");
  
          //// debug print
          SetStartOnSystemStartup(true);
  #endif
  
 -#ifndef GUI
 +#if !defined(QT_GUI) && !defined(GUI)
      while (1)
          Sleep(5000);
  #endif
diff --combined src/util.h
@@@ -64,7 -64,7 +64,7 @@@ typedef unsigned long long  uint64
  #endif
  
  // This is needed because the foreach macro can't get over the comma in pair<t1, t2>
 -#define PAIRTYPE(t1, t2)    pair<t1, t2>
 +#define PAIRTYPE(t1, t2)    std::pair<t1, t2>
  
  // Used to bypass the rule against non-const reference to temporary
  // where it makes sense with wrappers such as CFlatData or CTxDB
@@@ -139,7 -139,8 +139,7 @@@ inline int myclosesocket(SOCKET& hSocke
      return ret;
  }
  #define closesocket(s)      myclosesocket(s)
 -
 -#ifndef GUI
 +#if !defined(QT_GUI) && !defined(GUI)
  inline const char* _(const char* psz)
  {
      return psz;
  
  
  
 -
  extern std::map<std::string, std::string> mapArgs;
  extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
  extern bool fDebug;
@@@ -174,8 -176,8 +174,8 @@@ void RandAddSeed()
  void RandAddSeedPerfmon();
  int OutputDebugStringF(const char* pszFormat, ...);
  int my_snprintf(char* buffer, size_t limit, const char* format, ...);
 -std::string strprintf(const char* format, ...);
 -bool error(const char* format, ...);
 +std::string strprintf(const std::string &format, ...);
 +bool error(const std::string &format, ...);
  void LogException(std::exception* pex, const char* pszThread);
  void PrintException(std::exception* pex, const char* pszThread);
  void PrintExceptionContinue(std::exception* pex, const char* pszThread);
@@@ -621,7 -623,10 +621,10 @@@ inline pthread_t CreateThread(void(*pfn
          return (pthread_t)0;
      }
      if (!fWantHandle)
+     {
+         pthread_detach(hthread);
          return (pthread_t)-1;
+     }
      return hthread;
  }