aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-10-29 02:52:48 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-10-29 02:52:48 +0000
commitdd519206a684c772a4a06ceecc87c665ad09d8be (patch)
tree08535edfd634944708c936fd596f3719ccf191d8 /util.h
parentfa2a0338d3f8b1c3a1d75bff39ff42e436cee0dc (diff)
downloadbitcoin-dd519206a684c772a4a06ceecc87c665ad09d8be.tar.xz
addr relaying fixes, proxy option and privacy patches, detect connect to self, non-final tx locktime changes, fix hide unconfirmed generated
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@18 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'util.h')
-rw-r--r--util.h164
1 files changed, 95 insertions, 69 deletions
diff --git a/util.h b/util.h
index 97617ab490..61f774a8d9 100644
--- a/util.h
+++ b/util.h
@@ -67,15 +67,22 @@ inline T& REF(const T& val)
extern bool fDebug;
+extern bool fPrintToDebugger;
+extern bool fPrintToConsole;
+extern map<string, string> mapArgs;
-void RandAddSeed(bool fPerfmon=false);
+void RandAddSeed();
+void RandAddSeedPerfmon();
int my_snprintf(char* buffer, size_t limit, const char* format, ...);
string strprintf(const char* format, ...);
bool error(const char* format, ...);
void PrintException(std::exception* pex, const char* pszThread);
+void LogException(std::exception* pex, const char* pszThread);
void ParseString(const string& str, char c, vector<string>& v);
string FormatMoney(int64 n, bool fPlus=false);
bool ParseMoney(const char* pszIn, int64& nRet);
+vector<unsigned char> ParseHex(const char* psz);
+vector<unsigned char> ParseHex(const std::string& str);
bool FileExists(const char* psz);
int GetFilesize(FILE* file);
uint64 GetRand(uint64 nMax);
@@ -94,6 +101,7 @@ void AddTimeData(unsigned int ip, int64 nTime);
+
// Wrapper to automatically initialize critical section
// Could use wxCriticalSection for portability, but it doesn't support TryEnterCriticalSection
class CCriticalSection
@@ -156,6 +164,85 @@ public:
+inline int OutputDebugStringF(const char* pszFormat, ...)
+{
+ int ret = 0;
+#ifdef __WXDEBUG__
+ if (!fPrintToConsole)
+ {
+ // print to debug.log
+ FILE* fileout = fopen("debug.log", "a");
+ if (fileout)
+ {
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ ret = vfprintf(fileout, pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ fclose(fileout);
+ }
+ }
+
+ if (fPrintToDebugger)
+ {
+ // accumulate a line at a time
+ static CCriticalSection cs_OutputDebugStringF;
+ CRITICAL_BLOCK(cs_OutputDebugStringF)
+ {
+ static char pszBuffer[50000];
+ static char* pend;
+ if (pend == NULL)
+ pend = pszBuffer;
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ int limit = END(pszBuffer) - pend - 2;
+ int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ if (ret < 0 || ret >= limit)
+ {
+ pend = END(pszBuffer) - 2;
+ *pend++ = '\n';
+ }
+ else
+ pend += ret;
+ *pend = '\0';
+ char* p1 = pszBuffer;
+ char* p2;
+ while (p2 = strchr(p1, '\n'))
+ {
+ p2++;
+ char c = *p2;
+ *p2 = '\0';
+ OutputDebugString(p1);
+ *p2 = c;
+ p1 = p2;
+ }
+ if (p1 != pszBuffer)
+ memmove(pszBuffer, p1, pend - p1 + 1);
+ pend -= (p1 - pszBuffer);
+ }
+ }
+#endif
+
+ if (fPrintToConsole)
+ {
+ // print to console
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ ret = vprintf(pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ }
+ return ret;
+}
+
+
+
+
+
+
+
+
+
+
inline string i64tostr(int64 n)
{
return strprintf("%"PRId64, n);
@@ -205,6 +292,11 @@ string HexStr(const T itbegin, const T itend, bool fSpaces=true)
return str;
}
+inline string HexStr(vector<unsigned char> vch, bool fSpaces=true)
+{
+ return HexStr(vch.begin(), vch.end(), fSpaces);
+}
+
template<typename T>
string HexNumStr(const T itbegin, const T itend, bool f0x=true)
{
@@ -222,75 +314,9 @@ void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSp
printf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
}
-
-
-
-
-
-
-
-inline int OutputDebugStringF(const char* pszFormat, ...)
+inline void PrintHex(vector<unsigned char> vch, const char* pszFormat="%s", bool fSpaces=true)
{
-#ifdef __WXDEBUG__
- // log file
- FILE* fileout = fopen("debug.log", "a");
- if (fileout)
- {
- va_list arg_ptr;
- va_start(arg_ptr, pszFormat);
- vfprintf(fileout, pszFormat, arg_ptr);
- va_end(arg_ptr);
- fclose(fileout);
- }
-
- // accumulate a line at a time
- static CCriticalSection cs_OutputDebugStringF;
- CRITICAL_BLOCK(cs_OutputDebugStringF)
- {
- static char pszBuffer[50000];
- static char* pend;
- if (pend == NULL)
- pend = pszBuffer;
- va_list arg_ptr;
- va_start(arg_ptr, pszFormat);
- int limit = END(pszBuffer) - pend - 2;
- int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);
- va_end(arg_ptr);
- if (ret < 0 || ret >= limit)
- {
- pend = END(pszBuffer) - 2;
- *pend++ = '\n';
- }
- else
- pend += ret;
- *pend = '\0';
- char* p1 = pszBuffer;
- char* p2;
- while (p2 = strchr(p1, '\n'))
- {
- p2++;
- char c = *p2;
- *p2 = '\0';
- OutputDebugString(p1);
- *p2 = c;
- p1 = p2;
- }
- if (p1 != pszBuffer)
- memmove(pszBuffer, p1, pend - p1 + 1);
- pend -= (p1 - pszBuffer);
- return ret;
- }
-#endif
-
- if (!wxTheApp)
- {
- // print to console
- va_list arg_ptr;
- va_start(arg_ptr, pszFormat);
- vprintf(pszFormat, arg_ptr);
- va_end(arg_ptr);
- }
- return 0;
+ printf(pszFormat, HexStr(vch, fSpaces).c_str());
}