PRCYCoin  2.0.0.7rc1
P2P Digital Currency
util.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2018 The PIVX developers
5 // Copyright (c) 2018-2020 The DAPS Project developers
6 // Distributed under the MIT software license, see the accompanying
7 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "config/prcycoin-config.h"
11 #endif
12 
13 #include "util.h"
14 
15 #include "allocators.h"
16 #include "chainparamsbase.h"
17 #include "random.h"
18 #include "sync.h"
19 #include "utilstrencodings.h"
20 #include "utiltime.h"
21 
22 #include <stdarg.h>
23 
24 #include <boost/date_time/posix_time/posix_time.hpp>
25 #include <openssl/bio.h>
26 #include <openssl/buffer.h>
27 #include <openssl/evp.h>
28 #include "pubkey.h"
29 #include "key.h"
30 #include "secp256k1.h"
31 
32 
33 #ifndef WIN32
34 // for posix_fallocate
35 #ifdef __linux__
36 
37 #ifdef _POSIX_C_SOURCE
38 #undef _POSIX_C_SOURCE
39 #endif
40 
41 #define _POSIX_C_SOURCE 200112L
42 
43 #endif // __linux__
44 
45 #include <algorithm>
46 #include <fcntl.h>
47 #include <sys/resource.h>
48 #include <sys/stat.h>
49 
50 #else
51 
52 #ifdef _MSC_VER
53 #pragma warning(disable : 4786)
54 #pragma warning(disable : 4804)
55 #pragma warning(disable : 4805)
56 #pragma warning(disable : 4717)
57 #endif
58 
59 #ifndef NOMINMAX
60 #define NOMINMAX
61 #endif
62 
63 #include <io.h> /* for _commit */
64 #include <shlobj.h>
65 #endif
66 
67 #ifdef HAVE_SYS_PRCTL_H
68 #include <sys/prctl.h>
69 #endif
70 
71 #include <boost/algorithm/string/case_conv.hpp> // for to_lower()
72 #include <boost/algorithm/string/join.hpp>
73 #include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
74 #include <boost/program_options/detail/config_file.hpp>
75 #include <boost/program_options/parsers.hpp>
76 #include <boost/thread.hpp>
77 #include <openssl/conf.h>
78 #include <openssl/crypto.h>
79 #include <openssl/rand.h>
80 
81 // Work around clang compilation problem in Boost 1.46:
82 // /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
83 // See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
84 // http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
85 namespace boost
86 {
87 namespace program_options
88 {
89 std::string to_internal(const std::string&);
90 }
91 
92 } // namespace boost
93 
94 
95 // PRCY only features
96 // Masternode
97 bool fMasterNode = false;
98 std::string strMasterNodePrivKey = "";
99 std::string strMasterNodeAddr = "";
100 bool fLiteMode = false;
101 // SwiftX
102 bool fEnableSwiftTX = true;
104 
105 int64_t enforceMasternodePaymentsTime = 4085657524;
106 bool fSucessfullyLoaded = false;
108 std::vector<int64_t> obfuScationDenominations;
109 std::string strBudgetMode = "";
110 
111 std::map<std::string, std::string> mapArgs;
112 std::map<std::string, std::vector<std::string> > mapMultiArgs;
113 
114 bool fDaemon = false;
115 std::string strMiscWarning;
116 
118 static RecursiveMutex** ppmutexOpenSSL;
119 void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
120 {
121  if (mode & CRYPTO_LOCK) {
122  ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
123  } else {
124  LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
125  }
126 }
127 
128 // Init
129 class CInit
130 {
131 public:
133  {
134  // Init OpenSSL library multithreading support
135  ppmutexOpenSSL = (RecursiveMutex**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(RecursiveMutex*));
136  for (int i = 0; i < CRYPTO_num_locks(); i++)
137  ppmutexOpenSSL[i] = new RecursiveMutex();
138  CRYPTO_set_locking_callback(locking_callback);
139 
140  // OpenSSL can optionally load a config file which lists optional loadable modules and engines.
141  // We don't use them so we don't require the config. However some of our libs may call functions
142  // which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
143  // or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
144  // that the config appears to have been loaded and there are no modules/engines available.
145  OPENSSL_no_config();
146 
147 #ifdef WIN32
148  // Seed OpenSSL PRNG with current contents of the screen
149  RAND_screen();
150 #endif
151 
152  // Seed OpenSSL PRNG with performance counter
153  RandAddSeed();
154  }
156  {
157  // Securely erase the memory used by the PRNG
158  RAND_cleanup();
159  // Shutdown OpenSSL library multithreading support
160  CRYPTO_set_locking_callback(NULL);
161  for (int i = 0; i < CRYPTO_num_locks(); i++)
162  delete ppmutexOpenSSL[i];
163  OPENSSL_free(ppmutexOpenSSL);
164  }
166 
167 std::string FilterInjection(const std::string& str)
168 {
169  //std::cout << "filtering" << std::endl;
170  int n = str.length();
171  char char_array[n + 1];
172  strcpy(char_array, str.c_str());
173 
174  for (int i = 0; i < n; i++) {
175  if (char_array[i] == '\r' || char_array[i] == '\t' || char_array[i] == '\0')
176  char_array[i] = ' ';
177  else if (char_array[i] == '\n') {
178  if (i == n - 1)
179  continue;
180  char_array[i] = ' ';
181  }
182  else if (char_array[i] == '%' || char_array[i] == '&' || char_array[i] == '<' ||
183  char_array[i] == '>' || char_array[i] == '\"' || char_array[i] == '\'')
184  char_array[i] = '$';
185  }
186 
187  std::string result(char_array);
188  return result;
189 }
190 
192 static bool InterpretBool(const std::string& strValue)
193 {
194  if (strValue.empty())
195  return true;
196  return (atoi(strValue) != 0);
197 }
198 
200 static void InterpretNegativeSetting(std::string& strKey, std::string& strValue)
201 {
202  if (strKey.length()>3 && strKey[0]=='-' && strKey[1]=='n' && strKey[2]=='o') {
203  strKey = "-" + strKey.substr(3);
204  strValue = InterpretBool(strValue) ? "0" : "1";
205  }
206 }
207 
208 void ParseParameters(int argc, const char* const argv[])
209 {
210  mapArgs.clear();
211  mapMultiArgs.clear();
212 
213  for (int i = 1; i < argc; i++) {
214  std::string str(argv[i]);
215  std::string strValue;
216  size_t is_index = str.find('=');
217  if (is_index != std::string::npos) {
218  strValue = str.substr(is_index + 1);
219  str = str.substr(0, is_index);
220  }
221 #ifdef WIN32
222  boost::to_lower(str);
223  if (boost::algorithm::starts_with(str, "/"))
224  str = "-" + str.substr(1);
225 #endif
226 
227  if (str[0] != '-')
228  break;
229 
230  // Interpret --foo as -foo.
231  // If both --foo and -foo are set, the last takes effect.
232  if (str.length() > 1 && str[1] == '-')
233  str = str.substr(1);
234  InterpretNegativeSetting(str, strValue);
235 
236  mapArgs[str] = strValue;
237  mapMultiArgs[str].push_back(strValue);
238  }
239 }
240 
241 std::string GetArg(const std::string& strArg, const std::string& strDefault)
242 {
243  if (mapArgs.count(strArg))
244  return mapArgs[strArg];
245  return strDefault;
246 }
247 
248 int64_t GetArg(const std::string& strArg, int64_t nDefault)
249 {
250  if (mapArgs.count(strArg))
251  return atoi64(mapArgs[strArg]);
252  return nDefault;
253 }
254 
255 bool GetBoolArg(const std::string& strArg, bool fDefault)
256 {
257  if (mapArgs.count(strArg))
258  return InterpretBool(mapArgs[strArg]);
259  return fDefault;
260 }
261 
262 bool SoftSetArg(const std::string& strArg, const std::string& strValue)
263 {
264  if (mapArgs.count(strArg))
265  return false;
266  mapArgs[strArg] = strValue;
267  return true;
268 }
269 
270 bool SoftSetBoolArg(const std::string& strArg, bool fValue)
271 {
272  if (fValue)
273  return SoftSetArg(strArg, std::string("1"));
274  else
275  return SoftSetArg(strArg, std::string("0"));
276 }
277 
278 static const int screenWidth = 79;
279 static const int optIndent = 2;
280 static const int msgIndent = 7;
281 
282 std::string HelpMessageGroup(const std::string &message) {
283  return std::string(message) + std::string("\n\n");
284 }
285 
286 std::string HelpMessageOpt(const std::string &option, const std::string &message) {
287  return std::string(optIndent,' ') + std::string(option) +
288  std::string("\n") + std::string(msgIndent,' ') +
289  FormatParagraph(message, screenWidth - msgIndent, msgIndent) +
290  std::string("\n\n");
291 }
292 
293 static std::string FormatException(const std::exception* pex, const char* pszThread)
294 {
295 #ifdef WIN32
296  char pszModule[MAX_PATH] = "";
297  GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
298 #else
299  const char* pszModule = "prcycoin";
300 #endif
301  if (pex)
302  return strprintf(
303  "EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, pszThread);
304  else
305  return strprintf(
306  "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
307 }
308 
309 void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
310 {
311  std::string message = FormatException(pex, pszThread);
312  LogPrintf("\n\n************************\n%s\n", message);
313  fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
314  strMiscWarning = message;
315 }
316 
318 {
319 // Windows < Vista: C:\Documents and Settings\Username\Application Data\PRCYcoin
320 // Windows >= Vista: C:\Users\Username\AppData\Roaming\PRCYcoin
321 // Mac: ~/Library/Application Support/PRCYcoin
322 // Unix: ~/.prcycoin
323 #ifdef WIN32
324  // Windows
325  return GetSpecialFolderPath(CSIDL_APPDATA) / "PRCYcoin";
326 #else
327  fs::path pathRet;
328  char* pszHome = getenv("HOME");
329  if (pszHome == NULL || strlen(pszHome) == 0)
330  pathRet = fs::path("/");
331  else
332  pathRet = fs::path(pszHome);
333 #ifdef MAC_OSX
334  // Mac
335  pathRet /= "Library/Application Support";
336  TryCreateDirectory(pathRet);
337  return pathRet / "PRCYcoin";
338 #else
339  // Unix
340  return pathRet / ".prcycoin";
341 #endif
342 #endif
343 }
344 
345 static fs::path pathCached;
346 static fs::path pathCachedNetSpecific;
347 static RecursiveMutex csPathCached;
348 
349 const fs::path& GetDataDir(bool fNetSpecific)
350 {
351  LOCK(csPathCached);
352 
353  fs::path& path = fNetSpecific ? pathCachedNetSpecific : pathCached;
354 
355  // This can be called during exceptions by LogPrintf(), so we cache the
356  // value so we don't have to do memory allocations after that.
357  if (!path.empty())
358  return path;
359 
360  if (mapArgs.count("-datadir")) {
361  path = fs::system_complete(mapArgs["-datadir"]);
362  if (!fs::is_directory(path)) {
363  path = "";
364  return path;
365  }
366  } else {
367  path = GetDefaultDataDir();
368  }
369  if (fNetSpecific)
370  path /= BaseParams().DataDir();
371 
372  fs::create_directories(path);
373 
374  return path;
375 }
376 
378 {
379  pathCached = fs::path();
380  pathCachedNetSpecific = fs::path();
381 }
382 
383 fs::path GetConfigFile()
384 {
385  fs::path pathConfigFile(GetArg("-conf", "prcycoin.conf"));
386  return AbsPathForConfigVal(pathConfigFile, false);
387 }
388 
390 {
391  fs::path pathConfigFile(GetArg("-mnconf", "masternode.conf"));
392  return AbsPathForConfigVal(pathConfigFile);
393 }
394 
395 void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
396  std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet)
397 {
398  fs::ifstream streamConfig(GetConfigFile());
399  if (!streamConfig.good()) {
400  // Create empty prcycoin.conf if it does not exist
401  FILE* configFile = fsbridge::fopen(GetConfigFile(), "a");
402  if (configFile != NULL)
403  fclose(configFile);
404  return; // Nothing to read, so just return
405  }
406 
407  std::set<std::string> setOptions;
408  setOptions.insert("*");
409 
410  for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) {
411  // Don't overwrite existing settings so command line settings override prcycoin.conf
412  std::string strKey = std::string("-") + it->string_key;
413  std::string strValue = it->value[0];
414  InterpretNegativeSetting(strKey, strValue);
415  if (mapSettingsRet.count(strKey) == 0)
416  mapSettingsRet[strKey] = strValue;
417  mapMultiSettingsRet[strKey].push_back(strValue);
418  }
419  // If datadir is changed in .conf file:
421 }
422 
423 fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
424 {
425  if (path.is_absolute()) {
426  return path;
427  }
428  return fs::absolute(path, GetDataDir(net_specific));
429 }
430 
431 #ifndef WIN32
432 fs::path GetPidFile()
433 {
434  fs::path pathPidFile(GetArg("-pid", "prcycoind.pid"));
435  return AbsPathForConfigVal(pathPidFile);
436 }
437 
438 void CreatePidFile(const fs::path& path, pid_t pid)
439 {
440  FILE* file = fsbridge::fopen(path, "w");
441  if (file) {
442  fprintf(file, "%d\n", pid);
443  fclose(file);
444  }
445 }
446 #endif
447 
448 bool RenameOver(fs::path src, fs::path dest)
449 {
450 #ifdef WIN32
451  return MoveFileExA(src.string().c_str(), dest.string().c_str(),
452  MOVEFILE_REPLACE_EXISTING) != 0;
453 #else
454  int rc = std::rename(src.string().c_str(), dest.string().c_str());
455  return (rc == 0);
456 #endif /* WIN32 */
457 }
458 
464 bool TryCreateDirectory(const fs::path& p)
465 {
466  try {
467  return fs::create_directory(p);
468  } catch (const fs::filesystem_error&) {
469  if (!fs::exists(p) || !fs::is_directory(p))
470  throw;
471  }
472 
473  // create_directory didn't create the directory, it had to have existed already
474  return false;
475 }
476 
477 void FileCommit(FILE* fileout)
478 {
479  fflush(fileout); // harmless if redundantly called
480 #ifdef WIN32
481  HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fileout));
482  FlushFileBuffers(hFile);
483 #else
484 #if defined(__linux__) || defined(__NetBSD__)
485  fdatasync(fileno(fileout));
486 #elif defined(MAC_OSX) && defined(F_FULLFSYNC)
487  fcntl(fileno(fileout), F_FULLFSYNC, 0);
488 #else
489  fsync(fileno(fileout));
490 #endif
491 #endif
492 }
493 
494 bool TruncateFile(FILE* file, unsigned int length)
495 {
496 #if defined(WIN32)
497  return _chsize(_fileno(file), length) == 0;
498 #else
499  return ftruncate(fileno(file), length) == 0;
500 #endif
501 }
502 
508 {
509 #if defined(WIN32)
510  return 2048;
511 #else
512  struct rlimit limitFD;
513  if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
514  if (limitFD.rlim_cur < (rlim_t)nMinFD) {
515  limitFD.rlim_cur = nMinFD;
516  if (limitFD.rlim_cur > limitFD.rlim_max)
517  limitFD.rlim_cur = limitFD.rlim_max;
518  setrlimit(RLIMIT_NOFILE, &limitFD);
519  getrlimit(RLIMIT_NOFILE, &limitFD);
520  }
521  return limitFD.rlim_cur;
522  }
523  return nMinFD; // getrlimit failed, assume it's fine
524 #endif
525 }
526 
531 void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
532 {
533 #if defined(WIN32)
534  // Windows-specific version
535  HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
536  LARGE_INTEGER nFileSize;
537  int64_t nEndPos = (int64_t)offset + length;
538  nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
539  nFileSize.u.HighPart = nEndPos >> 32;
540  SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
541  SetEndOfFile(hFile);
542 #elif defined(MAC_OSX)
543  // OSX specific version
544  fstore_t fst;
545  fst.fst_flags = F_ALLOCATECONTIG;
546  fst.fst_posmode = F_PEOFPOSMODE;
547  fst.fst_offset = 0;
548  fst.fst_length = (off_t)offset + length;
549  fst.fst_bytesalloc = 0;
550  if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
551  fst.fst_flags = F_ALLOCATEALL;
552  fcntl(fileno(file), F_PREALLOCATE, &fst);
553  }
554  ftruncate(fileno(file), fst.fst_length);
555 #elif defined(__linux__)
556  // Version using posix_fallocate
557  off_t nEndPos = (off_t)offset + length;
558  posix_fallocate(fileno(file), 0, nEndPos);
559 #else
560  // Fallback version
561  // TODO: just write one byte per block
562  static const char buf[65536] = {};
563  fseek(file, offset, SEEK_SET);
564  while (length > 0) {
565  unsigned int now = 65536;
566  if (length < now)
567  now = length;
568  fwrite(buf, 1, now, file); // allowed to fail; this function is advisory anyway
569  length -= now;
570  }
571 #endif
572 }
573 
574 #ifdef WIN32
575 fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
576 {
577  char pszPath[MAX_PATH] = "";
578 
579  if (SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate)) {
580  return fs::path(pszPath);
581  }
582 
583  LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
584  return fs::path("");
585 }
586 #endif
587 
588 fs::path GetTempPath()
589 {
590  return fs::temp_directory_path();
591 }
592 
593 void runCommand(std::string strCommand)
594 {
595  int nErr = ::system(strCommand.c_str());
596  if (nErr)
597  LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);
598 }
599 
601 {
602 // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
603 // may be invalid, in which case the "C" locale is used as fallback.
604 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
605  try {
606  std::locale(""); // Raises a runtime error if current locale is invalid
607  } catch (const std::runtime_error&) {
608  setenv("LC_ALL", "C", 1);
609  }
610 #endif
611  // The path locale is lazy initialized and to avoid deinitialization errors
612  // in multithreading environments, it is set explicitly by the main thread.
613  // A dummy locale is used to extract the internal default locale, used by
614  // fs::path, which is then used to explicitly imbue the path.
615  std::locale loc = fs::path::imbue(std::locale::classic());
616  fs::path::imbue(loc);
617 }
618 
619 bool PointHashingSuccessively(const CPubKey& pk, const unsigned char* tweak, unsigned char* out) {
620  unsigned char pubData[65];
621  uint256 hash = pk.GetHash();
622  pubData[0] = *(pk.begin());
623  memcpy(pubData + 1, hash.begin(), 32);
624  CPubKey newPubKey(pubData, pubData + 33);
625  memcpy(out, newPubKey.begin(), newPubKey.size());
626  while (!secp256k1_ec_pubkey_tweak_mul(out, newPubKey.size(), tweak)) {
627  hash = newPubKey.GetHash();
628  pubData[0] = *(newPubKey.begin());
629  memcpy(pubData + 1, hash.begin(), 32);
630  newPubKey.Set(pubData, pubData + 33);
631  memcpy(out, newPubKey.begin(), newPubKey.size());
632  }
633  return true;
634 }
635 
637 {
638 #ifdef WIN32
639  // Initialize Windows Sockets
640  WSADATA wsadata;
641  int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
642  if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
643  return false;
644 #endif
645  return true;
646 }
647 
648 void SetThreadPriority(int nPriority)
649 {
650 #ifdef WIN32
651  SetThreadPriority(GetCurrentThread(), nPriority);
652 #else // WIN32
653 #ifdef PRIO_THREAD
654  setpriority(PRIO_THREAD, 0, nPriority);
655 #else // PRIO_THREAD
656  setpriority(PRIO_PROCESS, 0, nPriority);
657 #endif // PRIO_THREAD
658 #endif // WIN32
659 }
GetTempPath
fs::path GetTempPath()
Definition: util.cpp:588
utiltime.h
SetupEnvironment
void SetupEnvironment()
Definition: util.cpp:600
SoftSetBoolArg
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: util.cpp:270
SetupNetworking
bool SetupNetworking()
Definition: util.cpp:636
RecursiveMutex
AnnotatedMixin< std::recursive_mutex > RecursiveMutex
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:108
HelpMessageGroup
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:282
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:13
ReadConfigFile
void ReadConfigFile(std::map< std::string, std::string > &mapSettingsRet, std::map< std::string, std::vector< std::string > > &mapMultiSettingsRet)
Definition: util.cpp:395
RandAddSeed
void RandAddSeed()
Definition: random.cpp:130
base_uint::begin
unsigned char * begin()
Definition: arith_uint256.h:240
sync.h
mapArgs
std::map< std::string, std::string > mapArgs
Definition: util.cpp:111
CPubKey::Set
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
Definition: pubkey.h:71
chainparamsbase.h
HelpMessageOpt
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: util.cpp:286
FileCommit
void FileCommit(FILE *fileout)
Definition: util.cpp:477
RaiseFileDescriptorLimit
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
Definition: util.cpp:507
locking_callback
void locking_callback(int mode, int i, const char *file, int line) NO_THREAD_SAFETY_ANALYSIS
Definition: util.cpp:119
strMiscWarning
std::string strMiscWarning
Definition: util.cpp:115
AnnotatedMixin< std::recursive_mutex >
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:15
SetThreadPriority
void SetThreadPriority(int nPriority)
Definition: util.cpp:648
TruncateFile
bool TruncateFile(FILE *file, unsigned int length)
Definition: util.cpp:494
SoftSetArg
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
Definition: util.cpp:262
pubkey.h
nSwiftTXDepth
int nSwiftTXDepth
Definition: util.cpp:103
CInit
Definition: util.cpp:129
fMasterNode
bool fMasterNode
Definition: util.cpp:97
GetPidFile
fs::path GetPidFile()
Definition: util.cpp:432
PrintExceptionContinue
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: util.cpp:309
atoi
int atoi(const std::string &str)
Definition: utilstrencodings.cpp:587
CBaseChainParams::DataDir
const std::string & DataDir() const
Definition: chainparamsbase.h:26
obfuScationDenominations
std::vector< int64_t > obfuScationDenominations
All denominations used by obfuscation.
Definition: util.cpp:108
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:95
strBudgetMode
std::string strBudgetMode
Definition: util.cpp:109
ENTER_CRITICAL_SECTION
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:189
NO_THREAD_SAFETY_ANALYSIS
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:52
random.h
CInit::~CInit
~CInit()
Definition: util.cpp:155
strMasterNodeAddr
std::string strMasterNodeAddr
Definition: util.cpp:99
secp256k1.h
fEnableSwiftTX
bool fEnableSwiftTX
Definition: util.cpp:102
prcycoin-config.h
fDaemon
bool fDaemon
Definition: util.cpp:114
fLiteMode
bool fLiteMode
Definition: util.cpp:100
AbsPathForConfigVal
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
Definition: util.cpp:423
CPubKey::GetHash
uint256 GetHash() const
Get the 256-bit hash of this public key.
Definition: pubkey.h:149
GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:255
secp256k1_ec_pubkey_tweak_mul
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(unsigned char *pubkey, int pubkeylen, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3)
Tweak a public key by multiplying it with tweak.
Definition: secp256k1.c:281
allocators.h
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
PointHashingSuccessively
bool PointHashingSuccessively(const CPubKey &pk, const unsigned char *tweak, unsigned char *out)
Definition: util.cpp:619
enforceMasternodePaymentsTime
int64_t enforceMasternodePaymentsTime
Definition: util.cpp:105
CPubKey::size
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:94
fSucessfullyLoaded
bool fSucessfullyLoaded
Definition: util.cpp:106
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CInit::CInit
CInit()
Definition: util.cpp:132
instance_of_cinit
class CInit instance_of_cinit
ClearDatadirCache
void ClearDatadirCache()
Definition: util.cpp:377
FormatParagraph
std::string FormatParagraph(const std::string in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
Definition: utilstrencodings.cpp:527
GetConfigFile
fs::path GetConfigFile()
Definition: util.cpp:383
strprintf
#define strprintf
Definition: tinyformat.h:1056
atoi64
int64_t atoi64(const char *psz)
Definition: utilstrencodings.cpp:569
key.h
CreatePidFile
void CreatePidFile(const fs::path &path, pid_t pid)
Definition: util.cpp:438
GetDefaultDataDir
fs::path GetDefaultDataDir()
Definition: util.cpp:317
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
AllocateFileRange
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
Definition: util.cpp:531
strMasterNodePrivKey
std::string strMasterNodePrivKey
Definition: util.cpp:98
BaseParams
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
Definition: chainparamsbase.cpp:60
LOCK
#define LOCK(cs)
Definition: sync.h:182
ParseParameters
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:208
RenameOver
bool RenameOver(fs::path src, fs::path dest)
Definition: util.cpp:448
GetDataDir
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:349
GetMasternodeConfigFile
fs::path GetMasternodeConfigFile()
Definition: util.cpp:389
runCommand
void runCommand(std::string strCommand)
Definition: util.cpp:593
LEAVE_CRITICAL_SECTION
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:195
utilstrencodings.h
mapMultiArgs
std::map< std::string, std::vector< std::string > > mapMultiArgs
Definition: util.cpp:112
GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:241
util.h
MAX_PATH
#define MAX_PATH
Definition: compat.h:65
TryCreateDirectory
bool TryCreateDirectory(const fs::path &p)
Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
Definition: util.cpp:464
FilterInjection
std::string FilterInjection(const std::string &str)
Definition: util.cpp:167