From d7083c233df8d39c607794ec85c58df57c606cab Mon Sep 17 00:00:00 2001 From: John Doering Date: Fri, 12 Nov 2021 16:20:27 +0000 Subject: [PATCH 1/9] Numerous Small Improvements --- phoenixcoin-qt.pro | 31 ++-- src/addrman.cpp | 2 +- src/addrman.h | 7 +- src/alert.cpp | 8 +- src/alert.h | 5 +- src/allocators.h | 65 +++---- src/base58.h | 7 +- src/bignum.h | 3 +- src/checkpoints.cpp | 4 +- src/compat.h | 2 +- src/crypter.cpp | 9 +- src/crypter.h | 2 +- src/datatypes.h | 16 +- src/db.cpp | 11 +- src/db.h | 9 +- src/init.cpp | 57 +++--- src/init.h | 6 +- src/irc.cpp | 3 - src/key.h | 9 +- src/main.cpp | 100 ++++++----- src/main.h | 212 +++++++++++------------ src/makefile.mingw | 14 +- src/net.cpp | 46 +++-- src/net.h | 15 +- src/netbase.cpp | 12 +- src/netbase.h | 1 + src/noui.cpp | 19 +- src/ntp.cpp | 8 +- src/ntp.h | 4 + src/protocol.cpp | 13 +- src/protocol.h | 7 +- src/qt/aboutdialog.cpp | 6 +- src/qt/addressbookpage.cpp | 19 +- src/qt/addresstablemodel.cpp | 9 +- src/qt/amountfield.cpp | 17 +- src/qt/askpassphrasedialog.cpp | 11 +- src/qt/blockexplorer.cpp | 13 +- src/qt/clientmodel.cpp | 14 +- src/qt/coincontrol.cpp | 26 ++- src/qt/coincontrol.h | 2 + src/qt/coinunits.cpp | 9 +- src/qt/csvmodelwriter.cpp | 4 +- src/qt/editaddressdialog.cpp | 10 +- src/qt/forms/aboutdialog.ui | 2 +- src/qt/gui.cpp | 62 ++++--- src/qt/guiutil.cpp | 14 +- src/qt/guiutil.h | 6 +- src/qt/macdockiconhandler.mm | 5 +- src/qt/monitoreddatamapper.cpp | 4 +- src/qt/notificator.cpp | 5 +- src/qt/optionsdialog.cpp | 15 +- src/qt/optionsmodel.cpp | 10 +- src/qt/overviewpage.cpp | 9 +- src/qt/phoenixcoin.cpp | 37 ++-- src/qt/qrcodedialog.cpp | 19 +- src/qt/qtipcserver.cpp | 20 +-- src/qt/qvalidatedlineedit.cpp | 3 +- src/qt/rpcconsole.cpp | 35 ++-- src/qt/sendcoinsdialog.cpp | 24 ++- src/qt/sendcoinsentry.cpp | 10 +- src/qt/signverifymessagedialog.cpp | 23 +-- src/qt/strings.cpp | 1 + src/qt/trafficgraphwidget.cpp | 6 +- src/qt/transactiondesc.cpp | 12 +- src/qt/transactiondescdialog.cpp | 7 +- src/qt/transactionfilterproxy.cpp | 6 +- src/qt/transactionrecord.cpp | 7 +- src/qt/transactionrecord.h | 4 +- src/qt/transactiontablemodel.cpp | 25 ++- src/qt/transactionview.cpp | 30 ++-- src/qt/walletmodel.cpp | 20 ++- src/qt/walletmodel.h | 3 +- src/qt/walletmodeltransaction.cpp | 3 + src/qt/walletmodeltransaction.h | 5 +- src/qt/walletstyles.cpp | 2 - src/qt/walletstyles.h | 2 + src/rpcblockchain.cpp | 85 +++------ src/rpcdump.cpp | 50 +++--- src/rpcmain.cpp | 128 +++++++++----- src/rpcmain.h | 65 ++++--- src/rpcmining.cpp | 80 ++++++--- src/rpcnet.cpp | 25 +-- src/rpcrawtransaction.cpp | 66 ++++--- src/rpcwallet.cpp | 269 +++++++++++++++++------------ src/script.cpp | 21 +-- src/script.h | 3 +- src/serialize.h | 10 +- src/sync.cpp | 6 +- src/sync.h | 3 - src/ui_interface.h | 6 +- src/uint256.h | 5 +- src/util.cpp | 158 ++++++++--------- src/util.h | 104 +++++------ src/version.cpp | 1 + src/version.h | 9 +- src/wallet.cpp | 55 +++--- src/wallet.h | 8 +- src/walletdb.cpp | 22 +-- src/walletdb.h | 4 +- 99 files changed, 1259 insertions(+), 1207 deletions(-) diff --git a/phoenixcoin-qt.pro b/phoenixcoin-qt.pro index 380c66c0..3d1e2221 100644 --- a/phoenixcoin-qt.pro +++ b/phoenixcoin-qt.pro @@ -19,9 +19,9 @@ greaterThan(QT_MAJOR_VERSION, 4): { # Dependency library locations can be customized with: # BOOST_INCLUDE_PATH, BOOST_LIB_PATH, BDB_INCLUDE_PATH, # BDB_LIB_PATH, OPENSSL_INCLUDE_PATH and OPENSSL_LIB_PATH respectively -win32:BOOST_LIB_SUFFIX=-mgw49-mt-x64-1_70 -win32:BOOST_INCLUDE_PATH="/home/Administrator/boost-1.70" -win32:BOOST_LIB_PATH="/home/Administrator/boost-1.70/stage/lib" +win32:BOOST_LIB_SUFFIX=-mgw49-mt-x64-1_77 +win32:BOOST_INCLUDE_PATH="/home/Administrator/boost-1.77" +win32:BOOST_LIB_PATH="/home/Administrator/boost-1.77/stage/lib" win32:BDB_INCLUDE_PATH="/home/Administrator/db-5.3.28/build_unix" win32:BDB_LIB_PATH="/home/Administrator/db-5.3.28/build_unix" win32:OPENSSL_INCLUDE_PATH="/home/Administrator/openssl-1.0.2u/include" @@ -120,7 +120,6 @@ contains(USE_DBUS, 1) { # or: qmake "USE_IPV6=0" (compiled and disabled by default) # or: qmake "USE_IPV6=-" (not compiled) contains(USE_IPV6, -) { - message(Building without IPv6 support) message("Building without IPv6 support$$escape_expand(\\n)") } else { message("Building with the IPv6 support$$escape_expand(\\n)") @@ -130,14 +129,14 @@ contains(USE_IPV6, -) { DEFINES += USE_IPV6=$$USE_IPV6 } -contains(PHOENIXCOIN_NEED_QT_PLUGINS, 1) { - DEFINES += PHOENIXCOIN_NEED_QT_PLUGINS +contains(NEED_QT_PLUGINS, 1) { + DEFINES += NEED_QT_PLUGINS QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs qtaccessiblewidgets } # regenerate src/build.h -!windows|contains(USE_BUILD_INFO, 1) { +!win32|contains(USE_BUILD_INFO, 1) { genbuild.depends = FORCE genbuild.commands = cd $$PWD; /bin/sh share/genbuild.sh $$OUT_PWD/build/build.h genbuild.target = $$OUT_PWD/build/build.h @@ -323,16 +322,6 @@ SOURCES += src/qt/qrcodedialog.cpp FORMS += src/qt/forms/qrcodedialog.ui } -contains(PHOENIXCOIN_QT_TEST, 1) { -SOURCES += src/qt/test/test_main.cpp \ - src/qt/test/uritests.cpp -HEADERS += src/qt/test/uritests.h -DEPENDPATH += src/qt/test -QT += testlib -TARGET = phoenixcoin-qt_test -DEFINES += PHOENIXCOIN_QT_TEST -} - CODECFORTR = UTF-8 # for lrelease/lupdate @@ -354,11 +343,11 @@ QMAKE_EXTRA_COMPILERS += TSQM # "Other files" to show in Qt Creator OTHER_FILES += \ - doc/*.rst doc/*.txt doc/README README.md res/phoenixcoin-qt.rc src/test/*.cpp src/test/*.h src/qt/test/*.cpp src/qt/test/*.h + doc/*.rst doc/*.txt doc/README README.md res/phoenixcoin-qt.rc -windows:RC_FILE = src/qt/res/phoenixcoin-qt.rc +win32:RC_FILE = src/qt/res/phoenixcoin-qt.rc -windows:!contains(MINGW_THREAD_BUGFIX, 0) { +win32:!contains(MINGW_THREAD_BUGFIX, 0) { # At least qmake's win32-g++-cross profile is missing the -lmingwthrd # thread-safety flag. GCC has -mthreads to enable this, but it doesn't # work with static linking. -lmingwthrd must come BEFORE -lmingw, so @@ -369,7 +358,7 @@ windows:!contains(MINGW_THREAD_BUGFIX, 0) { QMAKE_LIBS_QT_ENTRY = -lmingwthrd $$QMAKE_LIBS_QT_ENTRY } -!windows:!macx { +!win32:!macx { DEFINES += LINUX LIBS += -lrt } diff --git a/src/addrman.cpp b/src/addrman.cpp index 63d2c54d..c5851f2d 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -4,9 +4,9 @@ #include -#include "util.h" #include "netbase.h" #include "protocol.h" +#include "util.h" #include "addrman.h" using namespace std; diff --git a/src/addrman.h b/src/addrman.h index 95356456..280fb773 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -10,12 +10,15 @@ #include #include "sync.h" +#include "protocol.h" +#include "netbase.h" #include +extern int64 GetAdjustedTime(); + /** Extended statistics about a CAddress */ -class CAddrInfo : public CAddress -{ +class CAddrInfo : public CAddress { private: // where knowledge about this address first came from CNetAddr source; diff --git a/src/alert.cpp b/src/alert.cpp index 3610e432..874625e8 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -2,12 +2,12 @@ // Alert system // -#include - #include #include #include +#include + #include "key.h" #include "sync.h" #include "net.h" @@ -51,8 +51,8 @@ std::string CUnsignedAlert::ToString() const return strprintf( "CAlert(\n" " nVersion = %d\n" - " nRelayUntil = %" PRI64d"\n" - " nExpiration = %" PRI64d"\n" + " nRelayUntil = %" PRI64d "\n" + " nExpiration = %" PRI64d "\n" " nID = %d\n" " nCancel = %d\n" " setCancel = %s\n" diff --git a/src/alert.h b/src/alert.h index 5b9c7bdd..819e6122 100644 --- a/src/alert.h +++ b/src/alert.h @@ -10,9 +10,10 @@ #include #include -#include "uint256.h" -#include "util.h" +#include "datatypes.h" +#include "serialize.h" +class uint256; class CNode; /** Alerts are for notifying old versions if they become too obsolete and diff --git a/src/allocators.h b/src/allocators.h index 4a6248c7..5e9aa9e4 100644 --- a/src/allocators.h +++ b/src/allocators.h @@ -6,33 +6,23 @@ #ifndef ALLOCATORS_H #define ALLOCATORS_H -#include -#include -#include // for OPENSSL_cleanse() - #include #include #include #include -#ifdef WINDOWS -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif -#define _WIN32_WINNT 0x0501 -#define WIN32_LEAN_AND_MEAN 1 -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -// This is used to attempt to keep keying material out of swap -// Note that VirtualLock does not provide this as a guarantee on Windows, -// but, in practice, memory that has been VirtualLock'd almost never gets written to -// the pagefile except in rare circumstances where memory is extremely low. -#else +#include + +#include + +#include /* for OPENSSL_cleanse() */ + +#include "compat.h" + +#ifndef WINDOWS #include -#include // for PAGESIZE -#include // for sysconf +#include /* for PAGESIZE */ +#include /* for PAGESIZE through sysconf() */ #endif /** @@ -120,19 +110,20 @@ template class LockedPageManagerBase }; /** Determine system page size in bytes */ -static inline size_t GetSystemPageSize() -{ +static inline size_t GetSystemPageSize() { size_t page_size; -#ifdef WINDOWS +#if defined(WINDOWS) SYSTEM_INFO sSysInfo; GetSystemInfo(&sSysInfo); page_size = sSysInfo.dwPageSize; -#elif defined(PAGESIZE) // defined in limits.h +#elif defined(PAGESIZE) + /* Should be defined in limits.h */ page_size = PAGESIZE; -#else // assume some POSIX OS +#else + /* Try sysconf() otherwise */ page_size = sysconf(_SC_PAGESIZE); #endif - return page_size; + return(page_size); } /** @@ -204,19 +195,15 @@ struct secure_allocator : public std::allocator template struct rebind { typedef secure_allocator<_Other> other; }; - T* allocate(std::size_t n, const void *hint = 0) - { + T* allocate(std::size_t n, const void *hint = 0) { T *p; p = std::allocator::allocate(n, hint); - if (p != NULL) - LockedPageManager::instance.LockRange(p, sizeof(T) * n); - return p; + if(p) LockedPageManager::instance.LockRange(p, sizeof(T) * n); + return(p); } - void deallocate(T* p, std::size_t n) - { - if (p != NULL) - { + void deallocate(T* p, std::size_t n) { + if(p) { OPENSSL_cleanse(p, sizeof(T) * n); LockedPageManager::instance.UnlockRange(p, sizeof(T) * n); } @@ -248,10 +235,8 @@ struct zero_after_free_allocator : public std::allocator template struct rebind { typedef zero_after_free_allocator<_Other> other; }; - void deallocate(T* p, std::size_t n) - { - if (p != NULL) - OPENSSL_cleanse(p, sizeof(T) * n); + void deallocate(T *p, std::size_t n) { + if(p) OPENSSL_cleanse(p, sizeof(T) * n); std::allocator::deallocate(p, n); } }; diff --git a/src/base58.h b/src/base58.h index f6464dee..269950d1 100644 --- a/src/base58.h +++ b/src/base58.h @@ -177,9 +177,8 @@ class CBase58Data { } ~CBase58Data() { - // zero the memory, as it may contain sensitive data - if(!vchData.empty()) - memset(&vchData[0], 0, vchData.size()); + /* Zero the memory, as it may contain sensitive data */ + if(!vchData.empty()) OPENSSL_cleanse((void *) &vchData[0], vchData.size()); } void SetData(int nVersionIn, const void* pdata, size_t nSize) { @@ -205,7 +204,7 @@ class CBase58Data { nVersion = vchTemp[0]; vchData.resize(vchTemp.size() - 1); if(!vchData.empty()) - memcpy(&vchData[0], &vchTemp[1], vchData.size()); + memcpy(&vchData[0], &vchTemp[1], vchData.size()); OPENSSL_cleanse(&vchTemp[0], vchData.size()); return(true); } diff --git a/src/bignum.h b/src/bignum.h index c8cb8caf..25c37b57 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -13,7 +13,8 @@ #include #include -#include "util.h" +#include "uint256.h" +#include "serialize.h" /** Errors thrown by the bignum class */ class bignum_error : public std::runtime_error { diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index ae2ce0ae..b1d7f8f5 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -5,10 +5,10 @@ #include // for 'map_list_of()' #include +#include "uint256.h" #include "checkpoints.h" -#include "main.h" -#include "uint256.h" +extern bool fTestNet; namespace Checkpoints { diff --git a/src/compat.h b/src/compat.h index 0b486c3d..14d2a789 100644 --- a/src/compat.h +++ b/src/compat.h @@ -17,7 +17,7 @@ #undef _WIN32_WINNT #endif #define _WIN32_WINNT 0x0501 -#define WIN32_LEAN_AND_MEAN 1 +#define WIN32_LEAN_AND_MEAN #ifndef NOMINMAX #define NOMINMAX #endif diff --git a/src/crypter.cpp b/src/crypter.cpp index 8f001305..7dbe4547 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -2,17 +2,14 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include #include #include -#ifdef WINDOWS -#include -#endif - #include "crypter.h" +#include +#include + bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod) { if(nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE) return(false); diff --git a/src/crypter.h b/src/crypter.h index c27499c5..9db164d7 100644 --- a/src/crypter.h +++ b/src/crypter.h @@ -8,8 +8,8 @@ #include #include "allocators.h" /* for SecureString */ -#include "key.h" #include "serialize.h" +#include "key.h" const unsigned int WALLET_CRYPTO_KEY_SIZE = 32; const unsigned int WALLET_CRYPTO_SALT_SIZE = 8; diff --git a/src/datatypes.h b/src/datatypes.h index dab792a7..6f86ffb5 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -34,19 +34,19 @@ typedef unsigned long long int uint64; /* uint64_t */ #if defined(_MSC_VER) || defined(__MSVCRT__) /* (s)size_t and ptrdiff_t have the same size specifier in MSVC: * http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx */ -#define PRIszx "Ix" -#define PRIszu "Iu" #define PRIszd "Id" -#define PRIpdx "Ix" -#define PRIpdu "Iu" +#define PRIszu "Iu" +#define PRIszx "Ix" #define PRIpdd "Id" +#define PRIpdu "Iu" +#define PRIpdx "Ix" #else /* C99 standard */ -#define PRIszx "zx" -#define PRIszu "zu" #define PRIszd "zd" -#define PRIpdx "tx" -#define PRIpdu "tu" +#define PRIszu "zu" +#define PRIszx "zx" #define PRIpdd "td" +#define PRIpdu "tu" +#define PRIpdx "tx" #endif /* _MSC_VER */ #endif /* DATATYPES_H */ diff --git a/src/db.cpp b/src/db.cpp index e6fd6a8c..f3e5c4e3 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -5,6 +5,10 @@ #include +#ifndef WINDOWS +#include "sys/stat.h" +#endif + #include #include #include @@ -13,10 +17,6 @@ #include "main.h" #include "db.h" -#ifndef WINDOWS -#include "sys/stat.h" -#endif - using namespace std; using namespace boost; @@ -462,7 +462,8 @@ void CDBEnv::Flush(bool fShutdown) else mi++; } - printf("DBFlush(%s)%s ended %15" PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); + printf("DBFlush(%s)%s ended %15" PRI64d "ms\n", fShutdown ? "true" : "false", + fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp; diff --git a/src/db.h b/src/db.h index 549a3104..3cb0826b 100644 --- a/src/db.h +++ b/src/db.h @@ -6,6 +6,8 @@ #ifndef DB_H #define DB_H +#include + #include #include @@ -13,7 +15,10 @@ #include #include -#include "main.h" +#include "sync.h" +#include "serialize.h" +#include "bignum.h" +#include "uint256.h" class CAddress; class CAddrMan; @@ -22,9 +27,9 @@ class CDiskBlockIndex; class CDiskTxPos; class CMasterKey; class COutPoint; +class CTransaction; class CTxIndex; class CWallet; -class CWalletTx; extern unsigned int nWalletDBUpdated; diff --git a/src/init.cpp b/src/init.cpp index f43bba95..06c93f47 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -7,33 +7,33 @@ #include #include -#include "util.h" -#include "init.h" -#include "db.h" -#include "walletdb.h" -#include "net.h" -#include "rpcmain.h" -#include "ui_interface.h" +#ifndef WINDOWS +#include +#endif + #include #include #include #include #include + #include #ifdef USE_UPNP #include #endif -#ifndef WINDOWS -#include -#endif +#include "db.h" +#include "wallet.h" +#include "util.h" +#include "rpcmain.h" +#include "init.h" using namespace std; using namespace boost; -CWallet* pwalletMain; +CWallet *pwalletMain; CClientUIInterface uiInterface; uint nMsgSleep; @@ -46,16 +46,14 @@ uint opt_flags = 0; // Shutdown // -void ExitTimeout(void* parg) -{ +void ExitTimeout(void *parg) { #ifdef WINDOWS Sleep(5000); ExitProcess(0); #endif } -void StartShutdown() -{ +void StartShutdown() { #ifdef QT_GUI /* Ensure we leave the Qt main loop for a clean GUI exit * (Shutdown() is called in phoenixcoin.cpp afterwards) */ @@ -66,8 +64,7 @@ void StartShutdown() #endif } -void Shutdown(void* parg) -{ +void Shutdown(void *parg) { static CCriticalSection cs_Shutdown; static bool fTaken; @@ -113,13 +110,11 @@ void Shutdown(void* parg) } } -void HandleSIGTERM(int) -{ +void HandleSIGTERM(int) { fRequestShutdown = true; } -void HandleSIGHUP(int) -{ +void HandleSIGHUP(int) { fReopenDebugLog = true; } @@ -701,7 +696,7 @@ bool AppInit2() printf("Shutdown requested. Exiting.\n"); return false; } - printf(" block index %15" PRI64d"ms\n", GetTimeMillis() - nStart); + printf(" block index %15" PRI64d "ms\n", GetTimeMillis() - nStart); if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree")) { @@ -793,7 +788,7 @@ bool AppInit2() } printf("%s", strErrors.str().c_str()); - printf(" wallet %15" PRI64d"ms\n", GetTimeMillis() - nStart); + printf(" wallet %15" PRI64d "ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); @@ -813,7 +808,7 @@ bool AppInit2() 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); + printf(" rescan %15" PRI64d "ms\n", GetTimeMillis() - nStart); } // ********************************************************* Step 9: import blocks @@ -854,8 +849,8 @@ bool AppInit2() printf("Invalid or missing peers.dat; recreating\n"); } - printf("Loaded %i addresses from peers.dat %" PRI64d"ms\n", - addrman.size(), GetTimeMillis() - nStart); + printf("Loaded %i addresses from peers.dat %" PRI64d "ms\n", + addrman.size(), GetTimeMillis() - nStart); // ********************************************************* Step 11: start node @@ -865,11 +860,11 @@ bool AppInit2() RandAddSeedPerfmon(); //// debug print - printf("mapBlockIndex.size() = %" PRIszu"\n", mapBlockIndex.size()); - printf("nBestHeight = %d\n", nBestHeight); - printf("setKeyPool.size() = %" PRIszu"\n", pwalletMain->setKeyPool.size()); - printf("mapWallet.size() = %" PRIszu"\n", pwalletMain->mapWallet.size()); - printf("mapAddressBook.size() = %" PRIszu"\n", pwalletMain->mapAddressBook.size()); + printf("mapBlockIndex.size() = %" PRIszu "\n", mapBlockIndex.size()); + printf("nBestHeight = %d\n", nBestHeight); + printf("setKeyPool.size() = %" PRIszu "\n", pwalletMain->setKeyPool.size()); + printf("mapWallet.size() = %" PRIszu "\n", pwalletMain->mapWallet.size()); + printf("mapAddressBook.size() = %" PRIszu "\n", pwalletMain->mapAddressBook.size()); if (!NewThread(StartNode, NULL)) InitError(_("Error: could not start node")); diff --git a/src/init.h b/src/init.h index ac5d0c8d..e6027cb9 100644 --- a/src/init.h +++ b/src/init.h @@ -8,12 +8,8 @@ #include -#include "wallet.h" - -extern CWallet* pwalletMain; - void StartShutdown(); -void Shutdown(void* parg); +void Shutdown(void *parg); bool AppInit2(); std::string HelpMessage(); diff --git a/src/irc.cpp b/src/irc.cpp index bb298b35..dca2f881 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -19,9 +19,6 @@ int nGotIRCAddresses = 0; void ThreadIRCSeed2(void* parg); - - - #pragma pack(push, 1) struct ircaddr { diff --git a/src/key.h b/src/key.h index 54c19013..22f49a8a 100644 --- a/src/key.h +++ b/src/key.h @@ -10,15 +10,14 @@ #include #include -#include "allocators.h" -#include "serialize.h" -#include "uint256.h" -#include "util.h" - #if (OPENSSL_VERSION_NUMBER < 0x10100000L) #include // for EC_KEY definition #endif +#include "allocators.h" +#include "serialize.h" +#include "util.h" + // secp160k1 // const unsigned int PRIVATE_KEY_SIZE = 192; // const unsigned int PUBLIC_KEY_SIZE = 41; diff --git a/src/main.cpp b/src/main.cpp index 01a06e21..982a4eae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,18 +16,18 @@ #include #include -#include "util.h" #include "init.h" #include "alert.h" -#include "db.h" #include "checkpoints.h" -#include "ui_interface.h" +#include "db.h" +#include "wallet.h" +#include "util.h" #include "main.h" using namespace std; using namespace boost; - +extern CWallet *pwalletMain; // // Global state @@ -200,20 +200,21 @@ bool AddOrphanTx(const CDataStream& vMsg) // have been mined or received. // 10,000 orphans, each of which is at most 5,000 bytes big is // at most 500 megabytes of orphans: - if (pvMsg->size() > 5000) - { - printf("ignoring large orphan tx (size: %" PRIszu", hash: %s)\n", pvMsg->size(), hash.ToString().substr(0,10).c_str()); - delete pvMsg; - return false; + if(pvMsg->size() > 5000) { + printf("ignoring large orphan tx (size: %" PRIszu ", hash: %s)\n", pvMsg->size(), + hash.ToString().substr(0,10).c_str()); + delete(pvMsg); + return(false); } mapOrphanTransactions[hash] = pvMsg; BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(make_pair(hash, pvMsg)); - printf("stored orphan tx %s (mapsz %" PRIszu")\n", hash.ToString().substr(0,10).c_str(), - mapOrphanTransactions.size()); - return true; + printf("stored orphan tx %s (mapsz %" PRIszu ")\n", hash.ToString().substr(0,10).c_str(), + mapOrphanTransactions.size()); + + return(true); } static void EraseOrphanTx(uint256 hash) @@ -620,9 +621,10 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, // Don't accept it if it can't get into a block int64 txMinFee = tx.GetMinFee(nSize, true, GMF_RELAY); - if(nFees < txMinFee) - return(error("CTxMemPool::accept() : not enough fees for tx %s, %" PRI64d " < %" PRI64d, - hash.ToString().c_str(), nFees, txMinFee)); + if(nFees < txMinFee) { + return(error("CTxMemPool::accept() : not enough fees for tx %s, " \ + "%" PRI64d " < %" PRI64d "", hash.ToString().c_str(), nFees, txMinFee)); + } // Continuously rate-limit free transactions // This mitigates 'penny-flooding' -- sending thousands of free transactions just to @@ -673,10 +675,10 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - printf("CTxMemPool::accept() : accepted %s (poolsz %" PRIszu")\n", - hash.ToString().substr(0,10).c_str(), - mapTx.size()); - return true; + printf("CTxMemPool::accept() : accepted %s (poolsz %" PRIszu ")\n", + hash.ToString().substr(0,10).c_str(), mapTx.size()); + + return(true); } bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMissingInputs) @@ -1336,7 +1338,11 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTes // Revisit this if/when transaction replacement is implemented and allows // adding inputs: fInvalid = true; - return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %" PRIszu" %" PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + return(DoS(100, error("FetchInputs() : %s prevout.n out of range %d " \ + "%" PRIszu " %" PRIszu " prev tx %s\n%s", + GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), + txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), + txPrev.ToString().c_str()))); } } @@ -1404,8 +1410,14 @@ bool CTransaction::ConnectInputs(MapPrevTx inputs, CTxIndex& txindex = inputs[prevout.hash].first; CTransaction& txPrev = inputs[prevout.hash].second; - if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) - return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %" PRIszu" %" PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + if((prevout.n >= txPrev.vout.size()) || (prevout.n >= txindex.vSpent.size())) { + return(DoS(100, + error("ConnectInputs() : %s prevout.n out of range %d " \ + "%" PRIszu " %" PRIszu " prev tx %s\n%s", + GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), + txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), + txPrev.ToString().c_str()))); + } // If prev is coinbase, check that it's matured if (txPrev.IsCoinBase()) @@ -1634,7 +1646,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) } if(vtx[0].GetValueOut() > GetProofOfWorkReward(pindex->nHeight, nFees)) { - return(error("ConnectBlock() : coin base pays too much (actual=%" PRI64d" vs limit=%" PRI64d")", + return(error("ConnectBlock() : coin base pays too much (actual=%" PRI64d " vs limit=%" PRI64d ")", vtx[0].GetValueOut(), GetProofOfWorkReward(pindex->nHeight, nFees))); } @@ -1694,8 +1706,12 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) vConnect.push_back(pindex); reverse(vConnect.begin(), vConnect.end()); - printf("REORGANIZE: Disconnect %" PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); - printf("REORGANIZE: Connect %" PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Disconnect %" PRIszu " blocks; %s..%s\n", + vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), + pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Connect %" PRIszu " blocks; %s..%s\n", + vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), + pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); // Disconnect shorter branch vector vResurrect; @@ -1822,8 +1838,8 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) pindexIntermediate = pindexIntermediate->pprev; } - if (!vpindexSecondary.empty()) - printf("Postponing %" PRIszu" reconnects\n", vpindexSecondary.size()); + if(!vpindexSecondary.empty()) + printf("Postponing %" PRIszu " reconnects\n", vpindexSecondary.size()); // Switch to new best branch if (!Reorganize(txdb, pindexIntermediate)) @@ -2469,7 +2485,7 @@ void PrintBlockTree() // print item CBlock block; block.ReadFromDisk(pindex); - printf("%d (%u,%u) %s %s tx %" PRIszu"", + printf("%d (%u,%u) %s %s tx %" PRIszu "", pindex->nHeight, pindex->nFile, pindex->nBlockPos, block.GetHash().ToString().substr(0,20).c_str(), DateTimeStrFormat(block.GetBlockTime()).c_str(), @@ -2550,8 +2566,10 @@ bool LoadExternalBlockFile(FILE* fileIn) __PRETTY_FUNCTION__); } } - printf("Loaded %i blocks from external file in %" PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); - return nLoaded > 0; + printf("Loaded %i blocks from external file in %" PRI64d "ms\n", + nLoaded, GetTimeMillis() - nStart); + + return(nLoaded > 0); } @@ -2658,8 +2676,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { static map mapReuseKey; RandAddSeedPerfmon(); - if (fDebug) - printf("received: %s (%" PRIszu" bytes)\n", strCommand.c_str(), vRecv.size()); + + if(fDebug) + printf("received: %s (%" PRIszu " bytes)\n", strCommand.c_str(), vRecv.size()); + if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { printf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -2850,10 +2870,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { vector vInv; vRecv >> vInv; - if (vInv.size() > MAX_INV_SZ) - { + if(vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message inv size() = %" PRIszu"", vInv.size()); + return(error("message inv size() = %" PRIszu "", vInv.size())); } // find last block in inv vector @@ -2900,14 +2919,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { vector vInv; vRecv >> vInv; - if (vInv.size() > MAX_INV_SZ) - { + if(vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message getdata size() = %" PRIszu"", vInv.size()); + return(error("message getdata size() = %" PRIszu "", vInv.size())); } - if (fDebugNet || (vInv.size() != 1)) - printf("received getdata (%" PRIszu" invsz)\n", vInv.size()); + if(fDebugNet || (vInv.size() != 1)) + printf("received getdata (%" PRIszu " invsz)\n", vInv.size()); BOOST_FOREACH(const CInv& inv, vInv) { @@ -3853,7 +3871,7 @@ CBlock *CreateNewBlock(CReserveKey &reservekey) { nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - printf("CreateNewBlock(): total size %" PRI64u"\n", nBlockSize); + printf("CreateNewBlock(): total size %" PRI64u "\n", nBlockSize); pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pindexPrev->nHeight + 1, nFees); diff --git a/src/main.h b/src/main.h index 109ccc2c..6632c97d 100644 --- a/src/main.h +++ b/src/main.h @@ -18,6 +18,7 @@ #include "sync.h" #include "net.h" #include "script.h" + #include "neoscrypt.h" class CWallet; @@ -222,209 +223,199 @@ class CDiskTxPos }; - /** An inpoint - a combination of a transaction and an index n into its vin */ -class CInPoint -{ +class CInPoint { public: - CTransaction* ptx; - unsigned int n; + CTransaction *ptx; + uint n; CInPoint() { SetNull(); } - CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; } + CInPoint(CTransaction *ptxIn, uint nIn) { ptx = ptxIn; n = nIn; } void SetNull() { ptx = NULL; n = std::numeric_limits::max(); } - bool IsNull() const { return (ptx == NULL && n == std::numeric_limits::max()); } + bool IsNull() const { + return(!ptx && (n == std::numeric_limits::max())); + } }; - /** An outpoint - a combination of a transaction hash and an index n into its vout */ -class COutPoint -{ +class COutPoint { public: uint256 hash; - unsigned int n; + uint n; COutPoint() { SetNull(); } - COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; } + COutPoint(uint256 hashIn, uint nIn) { hash = hashIn; n = nIn; } IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); ) void SetNull() { hash = 0; n = std::numeric_limits::max(); } - bool IsNull() const { return (hash == 0 && n == std::numeric_limits::max()); } + bool IsNull() const { + return(!hash && (n == std::numeric_limits::max())); + } - friend bool operator<(const COutPoint& a, const COutPoint& b) - { - return (a.hash < b.hash || (a.hash == b.hash && a.n < b.n)); + friend bool operator<(const COutPoint &a, const COutPoint &b) { + return((a.hash < b.hash) || (a.hash == b.hash && a.n < b.n)); } - friend bool operator==(const COutPoint& a, const COutPoint& b) - { - return (a.hash == b.hash && a.n == b.n); + friend bool operator==(const COutPoint &a, const COutPoint &b) { + return((a.hash == b.hash) && (a.n == b.n)); } - friend bool operator!=(const COutPoint& a, const COutPoint& b) - { - return !(a == b); + friend bool operator!=(const COutPoint &a, const COutPoint &b) { + return(!(a == b)); } - std::string ToString() const - { - return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n); + std::string ToString() const { + return(strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n)); } - void print() const - { + void print() const { printf("%s\n", ToString().c_str()); } }; - - /** An input of a transaction. It contains the location of the previous * transaction's output that it claims and a signature that matches the * output's public key. */ -class CTxIn -{ +class CTxIn { public: COutPoint prevout; CScript scriptSig; - unsigned int nSequence; + uint nSequence; - CTxIn() - { - nSequence = std::numeric_limits::max(); + CTxIn() { + nSequence = std::numeric_limits::max(); } - explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits::max()) - { + explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), + uint nSequenceIn=std::numeric_limits::max()) { prevout = prevoutIn; scriptSig = scriptSigIn; nSequence = nSequenceIn; } - CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits::max()) - { + CTxIn(uint256 hashPrevTx, uint nOut, CScript scriptSigIn=CScript(), + uint nSequenceIn=std::numeric_limits::max()) { prevout = COutPoint(hashPrevTx, nOut); scriptSig = scriptSigIn; nSequence = nSequenceIn; } - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE( READWRITE(prevout); READWRITE(scriptSig); READWRITE(nSequence); ) - bool IsFinal() const - { - return (nSequence == std::numeric_limits::max()); + bool IsFinal() const { + return(nSequence == std::numeric_limits::max()); } - friend bool operator==(const CTxIn& a, const CTxIn& b) - { - return (a.prevout == b.prevout && - a.scriptSig == b.scriptSig && - a.nSequence == b.nSequence); + friend bool operator==(const CTxIn &a, const CTxIn &b) { + return((a.prevout == b.prevout) && (a.scriptSig == b.scriptSig) && + (a.nSequence == b.nSequence)); } - friend bool operator!=(const CTxIn& a, const CTxIn& b) - { - return !(a == b); + friend bool operator!=(const CTxIn &a, const CTxIn &b) { + return(!(a == b)); } - std::string ToString() const - { + std::string ToStringShort() const { + return(strprintf(" %s %d", prevout.hash.ToString().c_str(), prevout.n)); + } + + std::string ToString() const { std::string str; str += "CTxIn("; str += prevout.ToString(); - if (prevout.IsNull()) - str += strprintf(", coinbase %s", HexStr(scriptSig).c_str()); - else - str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str()); - if (nSequence != std::numeric_limits::max()) + if(prevout.IsNull()) { + str += strprintf(", coin base %s", HexStr(scriptSig).c_str()); + } else { + str += strprintf(", scriptSig=%s", + scriptSig.ToString().substr(0,24).c_str()); + } + if(nSequence != std::numeric_limits::max()) { str += strprintf(", nSequence=%u", nSequence); + } str += ")"; - return str; + return(str); } - void print() const - { + void print() const { printf("%s\n", ToString().c_str()); } }; - - /** An output of a transaction. It contains the public key that the next input * must be able to sign with to claim it. */ -class CTxOut -{ +class CTxOut { public: int64 nValue; CScript scriptPubKey; - CTxOut() - { + CTxOut() { SetNull(); } - CTxOut(int64 nValueIn, CScript scriptPubKeyIn) - { + CTxOut(int64 nValueIn, CScript scriptPubKeyIn) { nValue = nValueIn; scriptPubKey = scriptPubKeyIn; } - IMPLEMENT_SERIALIZE - ( + IMPLEMENT_SERIALIZE( READWRITE(nValue); READWRITE(scriptPubKey); ) - void SetNull() - { + void SetNull() { nValue = -1; scriptPubKey.clear(); } - bool IsNull() - { - return (nValue == -1); + bool IsNull() const { + return(nValue == -1); } - uint256 GetHash() const - { - return SerializeHash(*this); + void SetEmpty() { + nValue = 0; + scriptPubKey.clear(); } - friend bool operator==(const CTxOut& a, const CTxOut& b) - { - return (a.nValue == b.nValue && - a.scriptPubKey == b.scriptPubKey); + bool IsEmpty() const { + return(!nValue && scriptPubKey.empty()); } - friend bool operator!=(const CTxOut& a, const CTxOut& b) - { - return !(a == b); + uint256 GetHash() const { + return(SerializeHash(*this)); } - std::string ToString() const - { - if (scriptPubKey.size() < 6) - return "CTxOut(error)"; - return strprintf("CTxOut(nValue=%" PRI64d".%08" PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); + friend bool operator==(const CTxOut &a, const CTxOut &b) { + return((a.nValue == b.nValue) && (a.scriptPubKey == b.scriptPubKey)); } - void print() const - { - printf("%s\n", ToString().c_str()); + friend bool operator!=(const CTxOut &a, const CTxOut &b) { + return(!(a == b)); + } + + std::string ToStringShort() const { + return(strprintf(" out %s %s", FormatMoney(nValue).c_str(), + scriptPubKey.ToString().substr(0, 10).c_str())); } -}; + std::string ToString() const { + if(IsEmpty()) return("CTxOut(empty)"); + if(scriptPubKey.size() < 6) return("CTxOut(error)"); + return(strprintf("CTxOut(nValue=%s, scriptPubKey=%s)", + FormatMoney(nValue).c_str(), scriptPubKey.ToString().c_str())); + } + void print() const { + printf("%s\n", ToString().c_str()); + } +}; enum GetMinFee_mode @@ -636,15 +627,12 @@ class CTransaction } - std::string ToString() const - { + std::string ToString() const { std::string str; - str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%" PRIszu", vout.size=%" PRIszu", nLockTime=%u)\n", - GetHash().ToString().substr(0,10).c_str(), - nVersion, - vin.size(), - vout.size(), - nLockTime); + str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%" PRIszu ", " \ + "vout.size=%" PRIszu ", nLockTime=%u)\n", + GetHash().ToString().substr(0,10).c_str(), nVersion, vin.size(), + vout.size(), nLockTime); for (unsigned int i = 0; i < vin.size(); i++) str += " " + vin[i].ToString() + "\n"; for (unsigned int i = 0; i < vout.size(); i++) @@ -1053,15 +1041,13 @@ class CBlock - void print() const - { - printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%" PRIszu")\n", - GetHash().ToString().substr(0,20).c_str(), - nVersion, - hashPrevBlock.ToString().substr(0,20).c_str(), - hashMerkleRoot.ToString().substr(0,10).c_str(), - nTime, nBits, nNonce, - vtx.size()); + void print() const { + printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, " \ + "nBits=%08x, nNonce=%u, vtx=%" PRIszu ")\n", + GetHash().ToString().substr(0,20).c_str(), nVersion, + hashPrevBlock.ToString().substr(0,20).c_str(), + hashMerkleRoot.ToString().substr(0,10).c_str(), + nTime, nBits, nNonce, vtx.size()); for (unsigned int i = 0; i < vtx.size(); i++) { printf(" "); diff --git a/src/makefile.mingw b/src/makefile.mingw index bebd9c9e..3659fe7e 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -9,21 +9,21 @@ CC = gcc CFLAGS = -O2 -fomit-frame-pointer INCLUDEPATHS= \ - -I"/home/Administrator/boost-1.70" \ + -I"/home/Administrator/boost-1.77" \ -I"/home/Administrator/db-5.3.28/build_unix" \ -I"/home/Administrator/openssl-1.0.2u/include" LIBPATHS= \ - -L"/home/Administrator/boost-1.70/stage/lib" \ + -L"/home/Administrator/boost-1.77/stage/lib" \ -L"/home/Administrator/db-5.3.28/build_unix" \ -L"/home/Administrator/openssl-1.0.2u" LIBS= \ - -l boost_system-mgw49-mt-x64-1_70 \ - -l boost_filesystem-mgw49-mt-x64-1_70 \ - -l boost_program_options-mgw49-mt-x64-1_70 \ - -l boost_thread-mgw49-mt-x64-1_70 \ - -l boost_chrono-mgw49-mt-x64-1_70 \ + -l boost_system-mgw49-mt-x64-1_77 \ + -l boost_filesystem-mgw49-mt-x64-1_77 \ + -l boost_program_options-mgw49-mt-x64-1_77 \ + -l boost_thread-mgw49-mt-x64-1_77 \ + -l boost_chrono-mgw49-mt-x64-1_77 \ -l db_cxx \ -l ssl \ -l crypto diff --git a/src/net.cpp b/src/net.cpp index 33a4fe0d..02919658 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -5,15 +5,6 @@ #include -#include "init.h" -#include "irc.h" -#include "db.h" -#include "net.h" -#include "addrman.h" -#include "ntp.h" -#include "strlcpy.h" -#include "ui_interface.h" - #ifdef WINDOWS #include #endif @@ -25,12 +16,23 @@ #include #endif +#include "strlcpy.h" +#include "init.h" +#include "irc.h" +#include "addrman.h" +#include "ntp.h" +#include "db.h" +#include "ui_interface.h" +#include "main.h" +#include "net.h" + using namespace std; using namespace boost; static const int MAX_OUTBOUND_CONNECTIONS = 32; extern uint nMsgSleep; +extern CWallet *pwalletMain; void ThreadMessageHandler2(void* parg); void ThreadSocketHandler2(void* parg); @@ -148,9 +150,9 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer) return ret; } -bool RecvLine(SOCKET hSocket, string& strLine) -{ +bool RecvLine(SOCKET hSocket, string &strLine) { strLine.clear(); + while(true) { char c; int nBytes = recv(hSocket, &c, 1, 0); @@ -893,12 +895,13 @@ void ThreadSocketHandler2(void* parg) CDataStream& vRecv = pnode->vRecv; unsigned int nPos = vRecv.size(); - if (nPos > ReceiveBufferSize()) { - if (!pnode->fDisconnect) - printf("socket recv flood control disconnect (%" PRIszu" bytes)\n", vRecv.size()); + if(nPos > ReceiveBufferSize()) { + if(!pnode->fDisconnect) { + printf("socket recv flood control disconnect (%" PRIszu " bytes)\n", + vRecv.size()); + } pnode->CloseSocketDisconnect(); - } - else { + } else { // typical socket buffer is 8K-64K char pchBuf[0x10000]; int nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), MSG_DONTWAIT); @@ -1325,8 +1328,8 @@ void DumpAddresses() CAddrDB adb; adb.Write(addrman); - printf("Flushed %d addresses to peers.dat %" PRI64d"ms\n", - addrman.size(), GetTimeMillis() - nStart); + printf("Flushed %d addresses to peers.dat %" PRI64d "ms\n", + addrman.size(), GetTimeMillis() - nStart); } void ThreadDumpAddress2(void* parg) @@ -1746,12 +1749,7 @@ void ThreadMessageHandler2(void* parg) } - - - - -bool BindListenPort(const CService &addrBind, string& strError) -{ +bool BindListenPort(const CService &addrBind, string &strError) { strError.clear(); int nOne = 1; diff --git a/src/net.h b/src/net.h index 4b59ef54..61e9df04 100644 --- a/src/net.h +++ b/src/net.h @@ -14,17 +14,18 @@ #include #include -#include -#include - #ifndef WINDOWS #include #endif +#include +#include + #include "mruset.h" #include "netbase.h" #include "protocol.h" #include "addrman.h" +#include "util.h" #include @@ -33,8 +34,6 @@ class CNode; class CBlockIndex; extern int nBestHeight; - - inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); } inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); } @@ -345,8 +344,10 @@ class CNode // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent int64& nRequestTime = mapAlreadyAskedFor[inv]; - if (fDebugNet) - printf("askfor %s %" PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); + if(fDebugNet) { + printf("askfor %s %" PRI64d " (%s)\n", inv.ToString().c_str(), nRequestTime, + DateTimeStrFormat("%H:%M:%S", nRequestTime / 1000000).c_str()); + } // Make sure not to reuse time indexes to keep things in the same order int64 nNow = (GetTime() - 1) * 1000000; diff --git a/src/netbase.cpp b/src/netbase.cpp index 1bcb590a..f42e7693 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -5,18 +5,18 @@ #include -#include "util.h" -#include "sync.h" -#include "compat.h" -#include "netbase.h" - #ifndef WINDOWS #include #endif -#include "strlcpy.h" #include // for to_lower() +#include "strlcpy.h" +#include "compat.h" +#include "sync.h" +#include "netbase.h" +#include "util.h" + using namespace std; // Settings diff --git a/src/netbase.h b/src/netbase.h index 0a3aa00c..d57d0c79 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -9,6 +9,7 @@ #include #include +#include "compat.h" #include "serialize.h" extern int nConnectTimeout; diff --git a/src/noui.cpp b/src/noui.cpp index 405b0970..3e3569eb 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -3,25 +3,24 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "init.h" -#include "ui_interface.h" - #include +#include + +#include "ui_interface.h" -static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style) -{ +static int noui_ThreadSafeMessageBox(const std::string &message, + const std::string &caption, int style) { printf("%s: %s\n", caption.c_str(), message.c_str()); fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str()); - return 4; + return(4); } -static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption) -{ - return true; +static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string &strCaption) { + return(true); } void noui_connect() { - /* Connect Phoenixcoin signal handlers */ + /* Connect signal handlers */ uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); uiInterface.ThreadSafeAskFee.connect(noui_ThreadSafeAskFee); } diff --git a/src/ntp.cpp b/src/ntp.cpp index f628fffb..6f90c33c 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -2,6 +2,9 @@ * Copyright (c) 2018 John Doering */ +#include +#include + #ifdef WINDOWS #include #else @@ -13,13 +16,10 @@ #include #endif -#include -#include - -#include "util.h" #include "netbase.h" #include "net.h" #include "ui_interface.h" +#include "util.h" using namespace std; diff --git a/src/ntp.h b/src/ntp.h index fb805792..e1fcc173 100644 --- a/src/ntp.h +++ b/src/ntp.h @@ -3,10 +3,14 @@ #include +#include "datatypes.h" + extern std::string strTrustedNTP; extern int64 nNtpOffset; extern bool fNtpWarning; +class CNetAddr; + /* Get time from a random server and return its IP address */ int64 NtpGetTime(CNetAddr &ip); diff --git a/src/protocol.cpp b/src/protocol.cpp index fe40222a..4c1addee 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -3,16 +3,15 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "util.h" -#include "netbase.h" -#include "protocol.h" - #ifndef WINDOWS -# include +#include #endif -static const char* ppszTypeName[] = -{ +#include "netbase.h" +#include "util.h" +#include "protocol.h" + +static const char *ppszTypeName[] = { "ERROR", "tx", "block", diff --git a/src/protocol.h b/src/protocol.h index fcf8323a..80536982 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -3,17 +3,14 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __cplusplus -# error This header can only be compiled as C++. -#endif - #ifndef PROTOCOL_H #define PROTOCOL_H #include -#include "uint256.h" #include "serialize.h" +#include "uint256.h" +#include "netbase.h" extern bool fTestNet; diff --git a/src/qt/aboutdialog.cpp b/src/qt/aboutdialog.cpp index 0b98befe..89c2712c 100644 --- a/src/qt/aboutdialog.cpp +++ b/src/qt/aboutdialog.cpp @@ -1,8 +1,8 @@ +#include "version.h" + +#include "clientmodel.h" #include "aboutdialog.h" #include "ui_aboutdialog.h" -#include "clientmodel.h" - -#include "version.h" AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index a2f5331c..0c14da18 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -1,13 +1,3 @@ -#include "addressbookpage.h" -#include "ui_addressbookpage.h" - -#include "addresstablemodel.h" -#include "optionsmodel.h" -#include "gui.h" -#include "editaddressdialog.h" -#include "csvmodelwriter.h" -#include "guiutil.h" - #include #include #include @@ -17,6 +7,15 @@ #include "qrcodedialog.h" #endif +#include "gui.h" +#include "guiutil.h" +#include "csvmodelwriter.h" +#include "optionsmodel.h" +#include "editaddressdialog.h" +#include "addresstablemodel.h" +#include "addressbookpage.h" +#include "ui_addressbookpage.h" + AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : QDialog(parent), ui(new Ui::AddressBookPage), diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 22b379c5..65d98552 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -1,12 +1,11 @@ -#include "addresstablemodel.h" -#include "guiutil.h" -#include "walletmodel.h" +#include #include "wallet.h" #include "base58.h" -#include -#include +#include "guiutil.h" +#include "walletmodel.h" +#include "addresstablemodel.h" const QString AddressTableModel::Send = "S"; const QString AddressTableModel::Receive = "R"; diff --git a/src/qt/amountfield.cpp b/src/qt/amountfield.cpp index 1da5c7ec..af481e3a 100644 --- a/src/qt/amountfield.cpp +++ b/src/qt/amountfield.cpp @@ -1,18 +1,15 @@ -#include "amountfield.h" -#include "qvaluecombobox.h" -#include "coinunits.h" -#include "guiconstants.h" - -#include -#include -#include +#include #include #include #include -#include -#include + #include +#include "qvaluecombobox.h" +#include "coinunits.h" +#include "guiconstants.h" +#include "amountfield.h" + AmountField::AmountField(QWidget *parent): QWidget(parent), amount(0), diff --git a/src/qt/askpassphrasedialog.cpp b/src/qt/askpassphrasedialog.cpp index e33c0a0d..8ccf2646 100644 --- a/src/qt/askpassphrasedialog.cpp +++ b/src/qt/askpassphrasedialog.cpp @@ -1,12 +1,11 @@ -#include "askpassphrasedialog.h" -#include "ui_askpassphrasedialog.h" +#include +#include +#include #include "guiconstants.h" #include "walletmodel.h" - -#include -#include -#include +#include "askpassphrasedialog.h" +#include "ui_askpassphrasedialog.h" AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) : QDialog(parent), diff --git a/src/qt/blockexplorer.cpp b/src/qt/blockexplorer.cpp index 0c119582..bedd3cfd 100644 --- a/src/qt/blockexplorer.cpp +++ b/src/qt/blockexplorer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 John Doering + * Copyright (c) 2016-2021 John Doering * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,15 +24,16 @@ * SUCH DAMAGE. */ -#include "blockexplorer.h" -#include "ui_blockexplorer.h" -#include "clientmodel.h" +#include +#include + #include "base58.h" #include "uint256.h" #include "main.h" -#include -#include +#include "clientmodel.h" +#include "blockexplorer.h" +#include "ui_blockexplorer.h" double GetDifficulty(const CBlockIndex *pindex); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index b1b383ef..7c5ae15a 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -1,15 +1,15 @@ -#include "clientmodel.h" -#include "guiconstants.h" -#include "optionsmodel.h" -#include "addresstablemodel.h" -#include "transactiontablemodel.h" +#include +#include #include "alert.h" #include "main.h" #include "ui_interface.h" -#include -#include +#include "clientmodel.h" +#include "guiconstants.h" +#include "optionsmodel.h" +#include "addresstablemodel.h" +#include "transactiontablemodel.h" static const int64 nClientStartupTime = GetTime(); diff --git a/src/qt/coincontrol.cpp b/src/qt/coincontrol.cpp index 6a9d23e9..a7b6d096 100644 --- a/src/qt/coincontrol.cpp +++ b/src/qt/coincontrol.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2013 Cozz Lovan - * Copyright (c) 2014-2019 John Doering + * Copyright (c) 2014-2021 John Doering * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,29 +25,25 @@ * SUCH DAMAGE. */ -#include "coincontrol.h" -#include "ui_coincontrol.h" - -#include "init.h" -#include "coinunits.h" -#include "walletmodel.h" -#include "addresstablemodel.h" -#include "optionsmodel.h" -#include "guiutil.h" - -#include -#include -#include #include #include #include #include #include -#include #include #include #include +#include "base58.h" + +#include "coinunits.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "addresstablemodel.h" +#include "walletmodel.h" +#include "coincontrol.h" +#include "ui_coincontrol.h" + using namespace std; QList CoinControl::payAmounts; diff --git a/src/qt/coincontrol.h b/src/qt/coincontrol.h index 594fd54e..10564e7c 100644 --- a/src/qt/coincontrol.h +++ b/src/qt/coincontrol.h @@ -11,6 +11,8 @@ #include #include +#include "wallet.h" + namespace Ui { class CoinControl; } diff --git a/src/qt/coinunits.cpp b/src/qt/coinunits.cpp index 9946ed34..26862c81 100644 --- a/src/qt/coinunits.cpp +++ b/src/qt/coinunits.cpp @@ -1,12 +1,9 @@ -#include "coinunits.h" - #include +#include "coinunits.h" + CoinUnits::CoinUnits(QObject *parent): - QAbstractListModel(parent), - unitlist(availableUnits()) -{ -} + QAbstractListModel(parent), unitlist(availableUnits()) { } QList CoinUnits::availableUnits() { QList unitlist; diff --git a/src/qt/csvmodelwriter.cpp b/src/qt/csvmodelwriter.cpp index 8a50bbab..7529dba1 100644 --- a/src/qt/csvmodelwriter.cpp +++ b/src/qt/csvmodelwriter.cpp @@ -1,9 +1,9 @@ -#include "csvmodelwriter.h" - #include #include #include +#include "csvmodelwriter.h" + CSVModelWriter::CSVModelWriter(const QString &filename, QObject *parent) : QObject(parent), filename(filename), model(0) diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 5db125d3..cebfd449 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -1,11 +1,11 @@ -#include "editaddressdialog.h" -#include "ui_editaddressdialog.h" -#include "addresstablemodel.h" -#include "guiutil.h" - #include #include +#include "addresstablemodel.h" +#include "guiutil.h" +#include "editaddressdialog.h" +#include "ui_editaddressdialog.h" + EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) : QDialog(parent), ui(new Ui::EditAddressDialog), mapper(0), mode(mode), model(0) diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui index 098e2645..6f49f35c 100644 --- a/src/qt/forms/aboutdialog.ui +++ b/src/qt/forms/aboutdialog.ui @@ -93,7 +93,7 @@ Copyright © 2009-2012 The Bitcoin Developers -Copyright © 2013-2019 The Phoenixcoin Developers +Copyright © 2013-2021 The Phoenixcoin Developers diff --git a/src/qt/gui.cpp b/src/qt/gui.cpp index d96e8816..ba2418be 100644 --- a/src/qt/gui.cpp +++ b/src/qt/gui.cpp @@ -5,46 +5,17 @@ * The Bitcoin Developers 2011-2012 */ -#include "gui.h" -#include "transactiontablemodel.h" -#include "addressbookpage.h" -#include "sendcoinsdialog.h" -#include "signverifymessagedialog.h" -#include "optionsdialog.h" -#include "aboutdialog.h" -#include "clientmodel.h" -#include "walletmodel.h" -#include "editaddressdialog.h" -#include "optionsmodel.h" -#include "transactiondescdialog.h" -#include "addresstablemodel.h" -#include "transactionview.h" -#include "overviewpage.h" -#include "coinunits.h" -#include "guiconstants.h" -#include "askpassphrasedialog.h" -#include "notificator.h" -#include "guiutil.h" -#include "rpcconsole.h" -#include "blockexplorer.h" - -#ifdef Q_OS_MAC -#include "macdockiconhandler.h" -#endif +#include #include #include #include #include #include -#include #include #include #include #include -#include -#include -#include #include #include #include @@ -52,8 +23,6 @@ #include #include #include -#include -#include #if (QT_VERSION < 0x050000) #include @@ -63,7 +32,34 @@ #include #endif -#include +#include "util.h" + +#include "coinunits.h" +#include "overviewpage.h" +#include "notificator.h" +#include "rpcconsole.h" +#include "blockexplorer.h" +#include "addressbookpage.h" +#include "transactionview.h" +#include "aboutdialog.h" +#include "optionsdialog.h" +#include "sendcoinsdialog.h" +#include "editaddressdialog.h" +#include "askpassphrasedialog.h" +#include "transactiondescdialog.h" +#include "signverifymessagedialog.h" +#include "optionsmodel.h" +#include "clientmodel.h" +#include "walletmodel.h" +#include "addresstablemodel.h" +#include "transactiontablemodel.h" +#include "guiconstants.h" +#include "guiutil.h" +#include "gui.h" + +#ifdef Q_OS_MAC +#include "macdockiconhandler.h" +#endif GUI::GUI(QWidget *parent): QMainWindow(parent), diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 5a13bfbf..dff763f7 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1,8 +1,11 @@ +#include +#include + #include #include #include #include -#include // For Qt::escape +#include #include #include #include @@ -17,16 +20,13 @@ #include #endif -#include -#include - +#include "init.h" /* for HelpMessage() */ #include "util.h" -#include "init.h" -#include "guiutil.h" +#include "coinunits.h" #include "addressvalidator.h" #include "walletmodel.h" -#include "coinunits.h" +#include "guiutil.h" #ifdef WINDOWS #include diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index debbc6b9..fca544ee 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -16,14 +16,14 @@ QT_END_NAMESPACE class SendCoinsRecipient; -/* Utility functions used by the Phoenixcoin Qt UI */ +/* Utility functions used by the Qt GUI */ namespace GUIUtil { // Create human-readable string from date QString dateTimeStr(const QDateTime &datetime); QString dateTimeStr(qint64 nTime); - /* Render Phoenixcoin addresses in the monospace font */ + /* Render addresses in the monospace font */ QFont AddressFont(); // Set up widgets for address and amounts @@ -115,6 +115,6 @@ namespace GUIUtil { QString uiOptions; }; -} // namespace GUIUtil +} #endif /* GUIUTIL_H */ diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index 746368e3..fc881021 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -1,9 +1,8 @@ - -#include "macdockiconhandler.h" - #include #include +#include "macdockiconhandler.h" + extern void qt_mac_set_dock_menu(QMenu*); #undef slots diff --git a/src/qt/monitoreddatamapper.cpp b/src/qt/monitoreddatamapper.cpp index 88948d07..121cefe2 100644 --- a/src/qt/monitoreddatamapper.cpp +++ b/src/qt/monitoreddatamapper.cpp @@ -1,9 +1,9 @@ -#include "monitoreddatamapper.h" - #include #include #include +#include "monitoreddatamapper.h" + MonitoredDataMapper::MonitoredDataMapper(QObject *parent) : QDataWidgetMapper(parent) { diff --git a/src/qt/notificator.cpp b/src/qt/notificator.cpp index d0765c05..c3098f65 100644 --- a/src/qt/notificator.cpp +++ b/src/qt/notificator.cpp @@ -1,16 +1,15 @@ -#include "notificator.h" - #include #include #include #include #include -#include #include #include #include #include +#include "notificator.h" + #ifdef USE_DBUS #include diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 6e8e58d5..ce67eff2 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -1,5 +1,7 @@ -#include "optionsdialog.h" -#include "ui_optionsdialog.h" +#include +#include +#include +#include #include "compat.h" #include "netbase.h" @@ -8,13 +10,8 @@ #include "walletstyles.h" #include "monitoreddatamapper.h" #include "optionsmodel.h" - -#include -#include -#include -#include -#include -#include +#include "optionsdialog.h" +#include "ui_optionsdialog.h" OptionsDialog::OptionsDialog(QWidget *parent) : QDialog(parent), diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 6b7107fb..4642bc9e 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -1,11 +1,11 @@ -#include "optionsmodel.h" -#include "coinunits.h" -#include "guiutil.h" +#include #include "init.h" -#include "walletdb.h" +#include "wallet.h" -#include +#include "guiutil.h" +#include "coinunits.h" +#include "optionsmodel.h" int nQtStyle; diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 33faee45..53471a2c 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -1,5 +1,5 @@ -#include "overviewpage.h" -#include "ui_overviewpage.h" +#include +#include #include "walletmodel.h" #include "coinunits.h" @@ -8,9 +8,8 @@ #include "transactionfilterproxy.h" #include "guiutil.h" #include "guiconstants.h" - -#include -#include +#include "overviewpage.h" +#include "ui_overviewpage.h" #define DECORATION_SIZE 64 #define NUM_ITEMS 6 diff --git a/src/qt/phoenixcoin.cpp b/src/qt/phoenixcoin.cpp index 328177a6..2237b9d4 100644 --- a/src/qt/phoenixcoin.cpp +++ b/src/qt/phoenixcoin.cpp @@ -1,28 +1,33 @@ /* * W.J. van der Laan 2011-2012 */ -#include "gui.h" -#include "clientmodel.h" -#include "walletmodel.h" -#include "optionsmodel.h" -#include "guiutil.h" -#include "guiconstants.h" - -#include "init.h" -#include "ui_interface.h" -#include "qtipcserver.h" #include #include -#if (QT_VERSION < 0x050000) -#include -#endif #include #include #include #include -#if defined(PHOENIXCOIN_NEED_QT_PLUGINS) && !defined(_PHOENIXCOIN_QT_PLUGINS_INCLUDED) -#define _PHOENIXCOIN_QT_PLUGINS_INCLUDED + +#if (QT_VERSION < 0x050000) +#include +#endif + +#include "init.h" +#include "ui_interface.h" +#include "util.h" +#include "main.h" + +#include "gui.h" +#include "guiutil.h" +#include "guiconstants.h" +#include "qtipcserver.h" +#include "clientmodel.h" +#include "walletmodel.h" +#include "optionsmodel.h" + +#if defined(NEED_QT_PLUGINS) && !defined(_QT_PLUGINS_INCLUDED) +#define _QT_PLUGINS_INCLUDED #define __INSURE__ #include Q_IMPORT_PLUGIN(qcncodecs) @@ -32,6 +37,8 @@ Q_IMPORT_PLUGIN(qkrcodecs) Q_IMPORT_PLUGIN(qtaccessiblewidgets) #endif +extern CWallet *pwalletMain; + // Need a global reference for the notifications to find the GUI static GUI *guiref; static QSplashScreen *splashref; diff --git a/src/qt/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp index fbf2c889..0736cbf1 100644 --- a/src/qt/qrcodedialog.cpp +++ b/src/qt/qrcodedialog.cpp @@ -1,18 +1,18 @@ -#include "qrcodedialog.h" -#include "ui_qrcodedialog.h" - -#include "coinunits.h" -#include "guiconstants.h" -#include "guiutil.h" -#include "optionsmodel.h" - #include + #if (QT_VERSION < 0x050000) #include #endif #include +#include "coinunits.h" +#include "guiconstants.h" +#include "guiutil.h" +#include "optionsmodel.h" +#include "qrcodedialog.h" +#include "ui_qrcodedialog.h" + QRCodeDialog::QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent) : QDialog(parent), ui(new Ui::QRCodeDialog), @@ -54,8 +54,7 @@ void QRCodeDialog::genCode() { QString uri = getURI(); - if (!uri.empty()) - { + if(!uri.empty()) { ui->lblQRCode->setText(""); QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1); diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 7c5001b2..c511dd69 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -2,21 +2,21 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include +#include +#include #include -#if defined(WINDOWS) && BOOST_VERSION == 104900 -#define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME -#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME -#endif -#include "qtipcserver.h" -#include "guiconstants.h" #include "ui_interface.h" #include "util.h" -#include -#include -#include -#include +#include "qtipcserver.h" +#include "guiconstants.h" + +#if defined(WIN32) +#define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME +#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME +#endif #if defined(WINDOWS) && (!defined(BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME) || !defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) || BOOST_VERSION < 104900) #warning Compiling without BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME and BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME uncommented in boost/interprocess/detail/tmp_dir_helpers.hpp or using a boost version before 1.49 may have unintended results see svn.boost.org/trac/boost/ticket/5392 diff --git a/src/qt/qvalidatedlineedit.cpp b/src/qt/qvalidatedlineedit.cpp index 8ca230c9..aaf5139f 100644 --- a/src/qt/qvalidatedlineedit.cpp +++ b/src/qt/qvalidatedlineedit.cpp @@ -1,6 +1,5 @@ -#include "qvalidatedlineedit.h" - #include "guiconstants.h" +#include "qvalidatedlineedit.h" QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) : QLineEdit(parent), valid(true) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 560ad4c0..be8a103f 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1,25 +1,23 @@ -#include "rpcconsole.h" -#include "ui_rpcconsole.h" - -#include "clientmodel.h" -#include "guiutil.h" - -#include "datatypes.h" -#include "rpcmain.h" - #include -#include #include -#include #include +#include #if (QT_VERSION < 0x050000) #include #endif -#include #include +#ifndef Q_MOC_RUN +#include "rpcmain.h" +#endif + +#include "clientmodel.h" +#include "guiutil.h" +#include "rpcconsole.h" +#include "ui_rpcconsole.h" + // TODO: make it possible to filter out categories (esp debug messages when implemented) // TODO: receive errors and debug messages through ClientModel @@ -164,12 +162,15 @@ void RPCExecutor::request(const QString &command) RPCConvertValues(args[0], std::vector(args.begin() + 1, args.end()))); // Format result reply - if (result.type() == json_spirit::null_type) + if(result.type() == json_spirit::null_type) { strPrint.clear(); - else if (result.type() == json_spirit::str_type) - strPrint = result.get_str(); - else - strPrint = write_string(result, true); + } else { + if(result.type() == json_spirit::str_type) { + strPrint = result.get_str(); + } else { + strPrint = write_string(result, true); + } + } emit reply(RPCConsole::CMD_REPLY, QString::fromStdString(strPrint)); } diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 7e4eb8a6..daac5437 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -1,23 +1,21 @@ -#include "sendcoinsdialog.h" -#include "ui_sendcoinsdialog.h" +#include +#include -#include "init.h" #include "base58.h" -#include "walletmodel.h" -#include "addresstablemodel.h" +#include "init.h" + #include "coinunits.h" +#include "coincontrol.h" +#include "guiutil.h" #include "addressbookpage.h" +#include "addresstablemodel.h" #include "optionsmodel.h" +#include "walletmodel.h" +#include "walletmodeltransaction.h" #include "sendcoinsentry.h" -#include "guiutil.h" #include "askpassphrasedialog.h" -#include "coincontrol.h" - -#include -#include -#include -#include -#include +#include "sendcoinsdialog.h" +#include "ui_sendcoinsdialog.h" SendCoinsDialog::SendCoinsDialog(QWidget *parent) : QDialog(parent), diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 4ffdb967..c75cdd83 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -1,14 +1,14 @@ -#include "sendcoinsentry.h" -#include "ui_sendcoinsentry.h" +#include +#include + #include "guiutil.h" #include "coinunits.h" #include "addressbookpage.h" #include "walletmodel.h" #include "optionsmodel.h" #include "addresstablemodel.h" - -#include -#include +#include "sendcoinsentry.h" +#include "ui_sendcoinsentry.h" SendCoinsEntry::SendCoinsEntry(QWidget *parent) : QFrame(parent), diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp index 71b9b311..4f427588 100644 --- a/src/qt/signverifymessagedialog.cpp +++ b/src/qt/signverifymessagedialog.cpp @@ -1,19 +1,20 @@ -#include "signverifymessagedialog.h" -#include "ui_signverifymessagedialog.h" +#include +#include + +#include -#include "addressbookpage.h" #include "base58.h" -#include "guiutil.h" -#include "init.h" -#include "main.h" -#include "optionsmodel.h" -#include "walletmodel.h" #include "wallet.h" +#include "main.h" -#include -#include +#include "guiutil.h" +#include "walletmodel.h" +#include "optionsmodel.h" +#include "addressbookpage.h" +#include "signverifymessagedialog.h" +#include "ui_signverifymessagedialog.h" -#include +extern CWallet *pwalletMain; SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) : QDialog(parent), diff --git a/src/qt/strings.cpp b/src/qt/strings.cpp index 5543900f..66989c70 100644 --- a/src/qt/strings.cpp +++ b/src/qt/strings.cpp @@ -1,4 +1,5 @@ #include + // Automatically generated by extract_strings.py #ifdef __GNUC__ #define UNUSED __attribute__((unused)) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 7930ec1d..45ed521f 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -1,12 +1,12 @@ -#include "trafficgraphwidget.h" -#include "clientmodel.h" +#include #include #include #include #include -#include +#include "clientmodel.h" +#include "trafficgraphwidget.h" #define DESIRED_SAMPLES 600 diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 70299bff..51e2b7d6 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -1,15 +1,15 @@ -#include "transactiondesc.h" +#include #include "guiutil.h" -#include "coinunits.h" -#include "main.h" -#include "wallet.h" +#include "base58.h" #include "db.h" +#include "wallet.h" #include "ui_interface.h" -#include "base58.h" -#include +#include "coinunits.h" +#include "transactionrecord.h" +#include "transactiondesc.h" QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) { diff --git a/src/qt/transactiondescdialog.cpp b/src/qt/transactiondescdialog.cpp index 3bd4808c..58026f3f 100644 --- a/src/qt/transactiondescdialog.cpp +++ b/src/qt/transactiondescdialog.cpp @@ -1,9 +1,8 @@ -#include "transactiondescdialog.h" -#include "ui_transactiondescdialog.h" +#include #include "transactiontablemodel.h" - -#include +#include "transactiondescdialog.h" +#include "ui_transactiondescdialog.h" TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *parent) : QDialog(parent), diff --git a/src/qt/transactionfilterproxy.cpp b/src/qt/transactionfilterproxy.cpp index 16fb4dab..b1148a4a 100644 --- a/src/qt/transactionfilterproxy.cpp +++ b/src/qt/transactionfilterproxy.cpp @@ -1,9 +1,9 @@ -#include "transactionfilterproxy.h" -#include "transactiontablemodel.h" +#include #include -#include +#include "transactiontablemodel.h" +#include "transactionfilterproxy.h" // Earliest date that can be represented (far in the past) const QDateTime TransactionFilterProxy::MIN_DATE = QDateTime::fromTime_t(0); diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 1e9aa73a..7f5f0600 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -1,7 +1,9 @@ -#include "transactionrecord.h" +#include -#include "wallet.h" #include "base58.h" +#include "wallet.h" + +#include "transactionrecord.h" /* Return positive answer if transaction should be shown in list. */ @@ -228,4 +230,3 @@ std::string TransactionRecord::getTxID() { return hash.ToString() + strprintf("-%03d", idx); } - diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 67ec4e77..f6059f5e 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -1,10 +1,10 @@ #ifndef TRANSACTIONRECORD_H #define TRANSACTIONRECORD_H -#include "uint256.h" - #include +#include "uint256.h" + class CWallet; class CWalletTx; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index fb06451b..5f2aa392 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -1,23 +1,22 @@ -#include "transactiontablemodel.h" +#include +#include +#include +#include + +#include "wallet.h" +#include "ui_interface.h" + +#include "coinunits.h" +#include "guiconstants.h" #include "guiutil.h" #include "transactionrecord.h" -#include "guiconstants.h" #include "transactiondesc.h" #include "walletmodel.h" #include "optionsmodel.h" #include "addresstablemodel.h" -#include "coinunits.h" - -#include "wallet.h" -#include "ui_interface.h" +#include "transactiontablemodel.h" -#include -#include -#include -#include -#include -#include -#include +#include "transactiontablemodel.h" // Amount column is right-aligned it contains numbers static int column_alignments[] = { diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 225d8d4e..3552ccf5 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -1,17 +1,3 @@ -#include "transactionview.h" - -#include "transactionfilterproxy.h" -#include "transactionrecord.h" -#include "walletmodel.h" -#include "addresstablemodel.h" -#include "transactiontablemodel.h" -#include "coinunits.h" -#include "csvmodelwriter.h" -#include "transactiondescdialog.h" -#include "editaddressdialog.h" -#include "optionsmodel.h" -#include "guiutil.h" - #include #include #include @@ -20,15 +6,25 @@ #include #include #include -#include #include #include #include -#include -#include #include #include +#include "coinunits.h" +#include "csvmodelwriter.h" +#include "guiutil.h" +#include "walletmodel.h" +#include "optionsmodel.h" +#include "addresstablemodel.h" +#include "transactiontablemodel.h" +#include "transactionfilterproxy.h" +#include "transactionrecord.h" +#include "transactiondescdialog.h" +#include "editaddressdialog.h" +#include "transactionview.h" + TransactionView::TransactionView(QWidget *parent) : QWidget(parent), model(0), transactionProxyModel(0), transactionView(0) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index a1bd9a72..3f5d081d 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1,16 +1,18 @@ -#include "walletmodel.h" +#include +#include + +#include +#include + +#include "base58.h" +#include "wallet.h" + #include "guiconstants.h" #include "optionsmodel.h" #include "addresstablemodel.h" #include "transactiontablemodel.h" - -#include "ui_interface.h" -#include "wallet.h" -#include "walletdb.h" /* for cloneWallet() */ -#include "base58.h" - -#include -#include +#include "walletmodel.h" +#include "walletmodeltransaction.h" WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) : QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0), diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index a10ab85c..2326a195 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -2,12 +2,11 @@ #define WALLETMODEL_H #include + #include #include #include "allocators.h" /* for SecureString */ -#include "wallet.h" -#include "walletmodeltransaction.h" class OptionsModel; class AddressTableModel; diff --git a/src/qt/walletmodeltransaction.cpp b/src/qt/walletmodeltransaction.cpp index 33274f50..942a0484 100644 --- a/src/qt/walletmodeltransaction.cpp +++ b/src/qt/walletmodeltransaction.cpp @@ -1,5 +1,8 @@ +#include "walletmodel.h" #include "walletmodeltransaction.h" +#include "wallet.h" + WalletModelTransaction::WalletModelTransaction(const QList &recipients) : recipients(recipients), walletTransaction(0), keyChange(0), fee(0) { walletTransaction = new CWalletTx(); diff --git a/src/qt/walletmodeltransaction.h b/src/qt/walletmodeltransaction.h index ea1730e5..1e553813 100644 --- a/src/qt/walletmodeltransaction.h +++ b/src/qt/walletmodeltransaction.h @@ -1,8 +1,11 @@ #ifndef WALLETMODELTRANSACTION_H #define WALLETMODELTRANSACTION_H -#include "walletmodel.h" +#include +class CWallet; +class CWalletTx; +class CReserveKey; class SendCoinsRecipient; /* Data model for a walletmodel transaction */ diff --git a/src/qt/walletstyles.cpp b/src/qt/walletstyles.cpp index 0c9bbeb4..dabd1de5 100644 --- a/src/qt/walletstyles.cpp +++ b/src/qt/walletstyles.cpp @@ -1,7 +1,5 @@ #include "walletstyles.h" -#include - WalletStyles::WalletStyles(QObject *parent): QAbstractListModel(parent), style_list(availableStyles()) { } diff --git a/src/qt/walletstyles.h b/src/qt/walletstyles.h index 73afbd06..87a757f4 100644 --- a/src/qt/walletstyles.h +++ b/src/qt/walletstyles.h @@ -2,6 +2,8 @@ #define WALLETSTYLES_H #include +#include +#include #include /* Wallet style definitions and descriptions */ diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fc390a29..1c96fc1d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -12,17 +12,15 @@ using namespace json_spirit; using namespace std; -double GetDifficulty(const CBlockIndex* blockindex) -{ - // Floating point number that is a multiple of the minimum difficulty, - // minimum difficulty = 1.0. - if (blockindex == NULL) - { - if (pindexBest == NULL) - return 1.0; - else - blockindex = pindexBest; - } +double GetDifficulty(const CBlockIndex *blockindex) { + + /* The reference difficulty is 1.0 which is the lowest Bitcoin difficulty + * and may not match the minimal difficulty of a particular altcoin */ + + if(!blockindex && pindexBest) + blockindex = pindexBest; + + if(!blockindex) return(1.0); int nShift = (blockindex->nBits >> 24) & 0xff; @@ -76,7 +74,7 @@ Value getblockcount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getblockcount\n" - "Returns the number of blocks in the longest block chain"; + "Displays the number of blocks in the best block chain."; throw(runtime_error(msg)); } @@ -88,8 +86,8 @@ Value getdifficulty(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getdifficulty\n" - "Returns the current proof-of-work difficulty\n" - "as a multiple of the lowest possible difficulty"; + "Displays the current proof-of-work difficulty\n" + "as a multiple of the lowest possible difficulty."; throw(runtime_error(msg)); } @@ -97,59 +95,27 @@ Value getdifficulty(const Array ¶ms, bool fHelp) { } -Value getnetworkhashps(const Array ¶ms, bool fHelp) { - - if(fHelp || (params.size() > 1)) { - string msg = "getnetworkhashps [blocks]\n" - "Calculates estimated network hashes per second based on the last 30 blocks.\n" - "Pass in [blocks] to override the default value;\n" - "zero specifies the number of blocks since the last retarget."; - throw(runtime_error(msg)); - } - - int lookup = params.size() > 0 ? params[0].get_int() : 30; - - if(pindexBest == NULL) return 0; - - // If look-up is zero or negative value, then use blocks since the last retarget - if(lookup <= 0) lookup = pindexBest->nHeight % 20 + 1; - - // If look-up is larger than block chain, then set it to the maximum allowed - if(lookup > pindexBest->nHeight) lookup = pindexBest->nHeight; - - CBlockIndex* pindexPrev = pindexBest; - for(int i = 0; i < lookup; i++) pindexPrev = pindexPrev->pprev; - - double timeDiff = pindexBest->GetBlockTime() - pindexPrev->GetBlockTime(); - double timePerBlock = timeDiff / lookup; - - return (boost::int64_t)(((double)GetDifficulty() * pow(2.0, 32)) / timePerBlock); -} - - Value settxfee(const Array ¶ms, bool fHelp) { - if(fHelp || (params.size() < 1) || (params.size() > 1)) { + if(fHelp || (params.size() != 1) || (AmountFromValue(params[0]) < MIN_TX_FEE)) { string msg = "settxfee \n" "Sets the transaction fee per 1000 bytes of data.\n" - " is a real and is rounded to the nearest 0.00000001"; + " is a floating point number rounded to the nearest 0.00000001"; throw(runtime_error(msg)); } - // Amount - int64 nAmount = 0; - if (params[0].get_real() != 0.0) - nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts + nTransactionFee = AmountFromValue(params[0]); + if(nTransactionFee < MIN_TX_FEE) nTransactionFee = MIN_TX_FEE; - nTransactionFee = nAmount; - return true; + return(true); } + Value getrawmempool(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getrawmempool\n" - "Returns IDs of all transactions stored in the memory pool"; + "Displays IDs of all transactions stored in the memory pool."; throw(runtime_error(msg)); } @@ -167,7 +133,7 @@ Value getblockhash(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "getblockhash \n" - "Returns hash of block in the best block chain at "; + "Displays hash of block in the best block chain at ."; throw(runtime_error(msg)); } @@ -179,23 +145,24 @@ Value getblockhash(const Array ¶ms, bool fHelp) { return pblockindex->phashBlock->GetHex(); } + Value getblock(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "getblock \n" - "Returns details of a block with a given block hash"; + "Displays details of a block with a given."; throw(runtime_error(msg)); } std::string strHash = params[0].get_str(); uint256 hash(strHash); - if (mapBlockIndex.count(hash) == 0) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + if(!mapBlockIndex.count(hash)) + throw(JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found")); CBlock block; - CBlockIndex* pblockindex = mapBlockIndex[hash]; + CBlockIndex *pblockindex = mapBlockIndex[hash]; block.ReadFromDisk(pblockindex, true); - return blockToJSON(block, pblockindex); + return(blockToJSON(block, pblockindex)); } diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 9ab953e9..f9f6a9de 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -4,30 +4,27 @@ #include -#include "init.h" // for pwalletMain -#include "base58.h" -#include "rpcmain.h" -#include "ui_interface.h" - #include #include #include -#define printf OutputDebugStringF +#include "base58.h" +#include "wallet.h" +#include "rpcmain.h" using namespace json_spirit; using namespace std; -class CTxDump -{ +extern CWallet *pwalletMain; + +class CTxDump { public: CBlockIndex *pindex; int64 nValue; bool fSpent; - CWalletTx* ptx; + CWalletTx *ptx; int nOut; - CTxDump(CWalletTx* ptx = NULL, int nOut = -1) - { + CTxDump(CWalletTx *ptx = NULL, int nOut = -1) { pindex = NULL; nValue = 0; fSpent = false; @@ -36,12 +33,14 @@ class CTxDump } }; + Value importprivkey(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 3)) { string msg = "importprivkey [label] [rescan]\n" - "Adds a private to your wallet in the format of RPC dumpprivkey.\n" - "Block chain re-scanning is on (true) by default.\n"; + "Adds a private to the wallet in the format of RPC dumpprivkey.\n" + "[label] specifies an in-wallet text label, empty by default.\n" + "[rescan] allows to rescan the block chain, true by default."; throw(runtime_error(msg)); } @@ -84,13 +83,15 @@ Value importprivkey(const Array ¶ms, bool fHelp) { return(Value::null); } + Value importaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 3)) { - string msg = "importaddress
[label] [rescan]\n" - "Adds a watch only (unspendable) P2PKH address to your wallet.\n" - "Pubkey hash or script in hex may be specified instead of the address.\n" - "Block chain re-scanning is off (false) by default.\n"; + string msg = "importaddress
[label] [rescan]\n" + "Adds a watch only (unspendable) P2PKH
to the wallet.\n" + "Pubkey hash or script in hex may be specified instead of the
.\n" + "[label] specifies an in-wallet text label, empty by default.\n" + "[rescan] allows to rescan the block chain, true by default."; throw(runtime_error(msg)); } @@ -171,12 +172,14 @@ Value importaddress(const Array ¶ms, bool fHelp) { return(Value::null); } + Value importpubkey(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 3)) { string msg = "importpubkey [label] [rescan]\n" - "Adds a watch only (unspendable) public key in hex to your wallet.\n" - "Block chain re-scanning is off (false) by default.\n"; + "Adds a watch only (unspendable) public in hex to the wallet.\n" + "[label] specifies an in-wallet text label, empty by default.\n" + "[rescan] allows to rescan the block chain, true by default."; throw(runtime_error(msg)); } @@ -229,11 +232,12 @@ Value importpubkey(const Array ¶ms, bool fHelp) { return(Value::null); } + Value importwallet(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "importwallet \n" - "Imports keys from a generated by RPC dumpwallet.\n" + "Imports key pairs from a generated by RPC dumpwallet.\n" "The file name may be specified with a directory path."; throw(runtime_error(msg)); } @@ -256,11 +260,12 @@ Value importwallet(const Array ¶ms, bool fHelp) { return(Value::null); } + Value dumpprivkey(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "dumpprivkey
\n" - "Reveals the private key corresponding to an
"; + "Reveals the private key corresponding to an
."; throw(runtime_error(msg)); } @@ -280,11 +285,12 @@ Value dumpprivkey(const Array ¶ms, bool fHelp) { return(CCoinSecret(vchSecret, fCompressed).ToString()); } + Value dumpwallet(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "dumpwallet \n" - "Dumps all wallet keys to a in a human readable format.\n" + "Dumps key pairs to a in a human readable format.\n" "The file name may be specified with a directory path."; throw(runtime_error(msg)); } diff --git a/src/rpcmain.cpp b/src/rpcmain.cpp index a38d4833..aecc925b 100644 --- a/src/rpcmain.cpp +++ b/src/rpcmain.cpp @@ -4,17 +4,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include -#include "util.h" -#include "init.h" -#include "sync.h" -#include "base58.h" -#include "db.h" -#include "ntp.h" -#include "rpcmain.h" -#include "ui_interface.h" - -#undef printf #include #include #if (BOOST_VERSION >= 107100) @@ -31,15 +22,23 @@ #include #include #include -#include -#define printf OutputDebugStringF +#include "base58.h" +#include "init.h" +#include "db.h" +#include "net.h" +#include "wallet.h" +#include "util.h" +#include "main.h" +#include "rpcmain.h" using namespace std; using namespace boost; using namespace boost::asio; using namespace json_spirit; +extern CWallet *pwalletMain; + void ThreadRPCServer2(void* parg); static std::string strRPCUserColonPass; @@ -127,6 +126,41 @@ std::string HexBits(unsigned int nBits) } +uint256 ParseHashV(const Value &v, string strName) { + uint256 result; + string strHex; + + if(v.type() == str_type) + strHex = v.get_str(); + + if(!IsHex(strHex)) + throw(JSONRPCError(RPC_INVALID_PARAMETER, strName + " must be hex string (not '"+strHex+"')")); + + result.SetHex(strHex); + + return(result); +} + +uint256 ParseHashO(const Object &o, string strKey) { + return(ParseHashV(find_value(o, strKey), strKey)); +} + +vector ParseHexV(const Value &v, string strName) { + string strHex; + + if(v.type() == str_type) + strHex = v.get_str(); + + if(!IsHex(strHex)) + throw(JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hex string (not '"+strHex+"')")); + + return ParseHex(strHex); +} + +vector ParseHexO(const Object& o, string strKey) { + return ParseHexV(find_value(o, strKey), strKey); +} + /// /// Note: This interface may still be subject to change. @@ -143,8 +177,10 @@ string CRPCTable::help(string strCommand) const // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; - if (!strCommand.empty() && strMethod != strCommand) - continue; + + if(!strCommand.empty() && (strMethod != strCommand)) + continue; + try { Array params; @@ -156,9 +192,11 @@ string CRPCTable::help(string strCommand) const { // Help text is returned in an exception string strHelp = string(e.what()); - if (strCommand.empty()) - if (strHelp.find('\n') != string::npos) + if(strCommand.empty()) { + if(strHelp.find('\n') != string::npos) { strHelp = strHelp.substr(0, strHelp.find('\n')); + } + } strRet += strHelp + "\n"; } } @@ -172,7 +210,7 @@ Value help(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { string msg = "help [command]\n" - "Lists all RPC commands or shows help for a particular command"; + "Lists all RPC commands or shows help for a particular command."; throw(runtime_error(msg)); } @@ -187,9 +225,9 @@ Value help(const Array ¶ms, bool fHelp) { Value stop(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { - string msg = "stop \n" + string msg = "stop [detach]\n" "Stops the Phoenixcoin server.\n" - " is true or false to detach the data base or not."; + "[detach] is true or false to detach the data base or not."; throw(runtime_error(msg)); } @@ -366,7 +404,7 @@ static string HTTPReply(int nStatus, const string& strMsg, bool keepalive) "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Connection: %s\r\n" - "Content-Length: %" PRIszu"\r\n" + "Content-Length: %" PRIszu "\r\n" "Content-Type: application/json\r\n" "Server: pxc-json-rpc/%s\r\n" "\r\n" @@ -420,8 +458,8 @@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHea return nLen; } -int ReadHTTP(std::basic_istream& stream, map& mapHeadersRet, string& strMessageRet) -{ +int ReadHTTP(std::basic_istream &stream, map &mapHeadersRet, + string &strMessageRet) { mapHeadersRet.clear(); strMessageRet.clear(); @@ -766,9 +804,8 @@ void ThreadRPCServer2(void* parg) printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; - if (mapArgs["-rpcpassword"].empty()) - { - unsigned char rand_pwd[32]; + if(mapArgs["-rpcpassword"].empty()) { + uchar rand_pwd[32]; RAND_bytes(rand_pwd, 32); string strWhatAmI = "To use phoenixcoind"; if (mapArgs.count("-server")) @@ -1076,9 +1113,8 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s // Observe safe mode string strWarning = GetWarnings("rpc"); - if (!strWarning.empty() && !GetBoolArg("-disablesafemode") && - !pcmd->okSafeMode) - throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); + if(!strWarning.empty() && !GetBoolArg("-disablesafemode") && !pcmd->okSafeMode) + throw(JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning)); try { @@ -1101,13 +1137,14 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s } -Object CallRPC(const string& strMethod, const Array& params) -{ - if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty()) - throw runtime_error(strprintf( - _("You must set rpcpassword= in the configuration file:\n%s\n" - "If the file does not exist, create it with owner-readable-only file permissions."), - GetConfigFile().string().c_str())); +Object CallRPC(const string &strMethod, const Array ¶ms) { + + if(mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty()) { + throw(runtime_error(strprintf( + _("You must set rpcpassword= in the configuration file:\n%s\n" + "If the file does not exist, create it with owner-readable-only file permissions."), + GetConfigFile().string().c_str()))); + } // Connect to localhost bool fUseSSL = GetBoolArg("-rpcssl"); @@ -1277,12 +1314,15 @@ int CommandLineRPC(int argc, char *argv[]) else { // Result - if (result.type() == null_type) + if(result.type() == null_type) { strPrint.clear(); - else if (result.type() == str_type) - strPrint = result.get_str(); - else - strPrint = write_string(result, true); + } else { + if(result.type() == str_type) { + strPrint = result.get_str(); + } else { + strPrint = write_string(result, true); + } + } } } catch (std::exception& e) @@ -1295,11 +1335,11 @@ int CommandLineRPC(int argc, char *argv[]) PrintException(NULL, "CommandLineRPC()"); } - if (!strPrint.empty()) - { - fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); + if(!strPrint.empty()) { + fprintf((!nRet ? stdout : stderr), "%s\n", strPrint.c_str()); } - return nRet; + + return(nRet); } diff --git a/src/rpcmain.h b/src/rpcmain.h index 8efa5e0d..af558bcc 100644 --- a/src/rpcmain.h +++ b/src/rpcmain.h @@ -11,12 +11,14 @@ #include #include -class CBlockIndex; - #include "json/json_spirit_reader_template.h" #include "json/json_spirit_writer_template.h" #include "json/json_spirit_utils.h" +#include "uint256.h" + +class CBlockIndex; + // HTTP status codes enum HTTPStatusCode { @@ -121,18 +123,23 @@ extern const CRPCTable tableRPC; extern int64 nWalletUnlockTime; extern int64 AmountFromValue(const json_spirit::Value& value); extern json_spirit::Value ValueFromAmount(int64 amount); -extern double GetDifficulty(const CBlockIndex* blockindex = NULL); +extern double GetDifficulty(const CBlockIndex *blockindex = NULL); extern std::string HexBits(unsigned int nBits); extern std::string HelpRequiringPassphrase(); extern void EnsureWalletIsUnlocked(); -/* in rpcnet.cpp */ -extern json_spirit::Value getconnectioncount(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getpeerinfo(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value addnode(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getaddednodeinfo(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getnettotals(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value ntptime(const json_spirit::Array ¶ms, bool fHelp); +extern uint256 ParseHashV(const json_spirit::Value &v, std::string strName); +extern uint256 ParseHashO(const json_spirit::Object &o, std::string strKey); +extern std::vector ParseHexV(const json_spirit::Value &v, std::string strName); +extern std::vector ParseHexO(const json_spirit::Object &o, std::string strKey); + +/* in rpcblockchain.cpp */ +extern json_spirit::Value getblockcount(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getdifficulty(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value settxfee(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getrawmempool(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getblockhash(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getblock(const json_spirit::Array ¶ms, bool fHelp); /* in rpcdump.cpp */ extern json_spirit::Value importprivkey(const json_spirit::Array ¶ms, bool fHelp); @@ -146,19 +153,39 @@ extern json_spirit::Value dumpwallet(const json_spirit::Array ¶ms, bool fHel extern json_spirit::Value getgenerate(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value setgenerate(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value gethashespersec(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getnetworkhashps(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getmininginfo(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getwork(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getblocktemplate(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value submitblock(const json_spirit::Array ¶ms, bool fHelp); +/* in rpcnet.cpp */ +extern json_spirit::Value getconnectioncount(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getpeerinfo(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value addnode(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getaddednodeinfo(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getnettotals(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value ntptime(const json_spirit::Array ¶ms, bool fHelp); + +/* in rpcrawtransaction.cpp */ +extern json_spirit::Value getrawtransaction(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value listunspent(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value decodescript(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value createrawtransaction(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value decoderawtransaction(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value signrawtransaction(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value sendrawtransaction(const json_spirit::Array ¶ms, bool fHelp); + /* in rpcwallet.cpp */ extern json_spirit::Value getinfo(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getnewaddress(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value getnewpubkey(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getaccountaddress(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value setaccount(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getaccount(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value sendtoaddress(const json_spirit::Array ¶ms, bool fHelp); +extern json_spirit::Value listaddressgroupings(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value signmessage(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value verifymessage(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array ¶ms, bool fHelp); @@ -171,7 +198,6 @@ extern json_spirit::Value addmultisigaddress(const json_spirit::Array ¶ms, b extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value listtransactions(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value listaddressgroupings(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value listaccounts(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value listsinceblock(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value gettransaction(const json_spirit::Array ¶ms, bool fHelp); @@ -185,21 +211,4 @@ extern json_spirit::Value validateaddress(const json_spirit::Array ¶ms, bool extern json_spirit::Value validatepubkey(const json_spirit::Array ¶ms, bool fHelp); extern json_spirit::Value resendtx(const json_spirit::Array ¶ms, bool fHelp); -/* in rcprawtransaction.cpp */ -extern json_spirit::Value getrawtransaction(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value listunspent(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value createrawtransaction(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value decoderawtransaction(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value signrawtransaction(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value sendrawtransaction(const json_spirit::Array ¶ms, bool fHelp); - -/* in rpcblockchain.cpp */ -extern json_spirit::Value getblockcount(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getdifficulty(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getnetworkhashps(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value settxfee(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getrawmempool(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getblockhash(const json_spirit::Array ¶ms, bool fHelp); -extern json_spirit::Value getblock(const json_spirit::Array ¶ms, bool fHelp); - #endif /* RPCMAIN_H */ diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 0a181dd3..f6f13830 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -8,19 +8,21 @@ #include #include -#include "init.h" -#include "db.h" -#include "main.h" +#include "wallet.h" #include "rpcmain.h" +#include "main.h" using namespace json_spirit; using namespace std; +extern CWallet *pwalletMain; + + Value getgenerate(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getgenerate\n" - "Returns execution state of the internal proof-of-work miner"; + "Displays execution state of the internal proof-of-work miner."; throw(runtime_error(msg)); } @@ -32,7 +34,7 @@ Value setgenerate(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { string msg = "setgenerate [genproclimit]\n" - "Sets execution state of the internal proof-of-work miner.\n" + "Sets execution of the internal proof-of-work miner.\n" " is true or false to set mining on or off respectively.\n" "[genproclimit] defines the maximum number of mining threads, -1 is unlimited."; throw(runtime_error(msg)); @@ -60,7 +62,7 @@ Value gethashespersec(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "gethashespersec\n" - "Returns hash rate of the internal proof-of-work miner"; + "Displays hash rate of the internal proof-of-work miner."; throw(runtime_error(msg)); } @@ -70,11 +72,42 @@ Value gethashespersec(const Array ¶ms, bool fHelp) { } +Value getnetworkhashps(const Array ¶ms, bool fHelp) { + + if(fHelp || (params.size() > 1)) { + string msg = "getnetworkhashps [blocks]\n" + "Estimates network hashes per second based on the last 30 proof-of-work blocks.\n" + "Pass in [blocks] to override the default value."; + throw(runtime_error(msg)); + } + + int nRange = params.size() > 0 ? params[0].get_int() : 30; + + /* The genesis block only */ + if(!pindexBest) return(0); + if(!pindexBest->pprev) return(0); + + /* Range limit */ + if(nRange <= 0) nRange = 30; + + // If look-up is larger than block chain, then set it to the maximum allowed + if(nRange > pindexBest->nHeight) nRange = pindexBest->nHeight; + + CBlockIndex *pindexPrev = pindexBest; + for(int i = 0; i < nRange; i++) pindexPrev = pindexPrev->pprev; + + double timeDiff = pindexBest->GetBlockTime() - pindexPrev->GetBlockTime(); + double timePerBlock = timeDiff / nRange; + + return((int64_t)(((double)GetDifficulty() * pow(2.0, 32)) / timePerBlock)); +} + + Value getmininginfo(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getmininginfo\n" - "Returns information related to mining"; + "Displays mining related information."; throw(runtime_error(msg)); } @@ -188,10 +221,10 @@ Value getwork(const Array ¶ms, bool fHelp) { #if 0 /* Dump block data sent */ - uint i; + uint t; printf("Block data 80 bytes Tx: "); - for(i = 0; i < 80; i++) - printf("%02X", ((uchar *) &pdata[0])[i]); + for(t = 0; t < 80; t++) + printf("%02X", ((uchar *) &pdata[0])[t]); printf("\n"); #endif @@ -210,11 +243,11 @@ Value getwork(const Array ¶ms, bool fHelp) { #if 0 /* Dump block data received */ - uint i, size; + uint r, size; size = (uint)vchData.size(); printf("Block data %u bytes Rx: ", size); - for(i = 0; i < size; i++) - printf("%02X", ((uchar *) &vchData[0])[i]); + for(r = 0; r < size; r++) + printf("%02X", ((uchar *) &vchData[0])[r]); printf("\n"); #endif @@ -229,14 +262,14 @@ Value getwork(const Array ¶ms, bool fHelp) { /* Pick up the block contents saved previously */ if(!mapNewBlock.count(pdata->hashMerkleRoot)) return(false); - CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first; + CBlock *pblock = mapNewBlock[pdata->hashMerkleRoot].first; /* Replace with the data received */ pblock->nTime = pdata->nTime; pblock->nNonce = pdata->nNonce; pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second; - /* Re-build the merkle root */ + /* Rebuild the merkle root */ pblock->hashMerkleRoot = pblock->BuildMerkleTree(); /* Verify the resulting hash against target */ @@ -249,7 +282,7 @@ Value getblocktemplate(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { string msg = "getblocktemplate [params]\n" - "Returns data required to construct a block to work on:\n" + "Retrieves data required to construct a block to work on:\n" " \"version\" : block version\n" " \"previousblockhash\" : hash of the current best block\n" " \"transactions\" : contents of transactions to be included in the next block\n" @@ -337,8 +370,7 @@ Value getblocktemplate(const Array ¶ms, bool fHelp) { uint256 txHash = tx.GetHash(); setTxIndex[txHash] = i++; - if (tx.IsCoinBase()) - continue; + if(tx.IsCoinBase()) continue; Object entry; @@ -391,7 +423,7 @@ Value getblocktemplate(const Array ¶ms, bool fHelp) { result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); result.push_back(Pair("target", hashTarget.GetHex())); - result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); + result.push_back(Pair("mintime", (int64_t)(pindexPrev->GetMedianTimePast() + BLOCK_LIMITER_TIME + 1))); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS)); @@ -408,8 +440,8 @@ Value submitblock(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { string msg = "submitblock [workid]\n" - "Attempts to submit a new block to the network.\n" - "[workid] parameter is optional and ignored.\n"; + "Attempts to submit hexadecimal of a new block to the network.\n" + "[workid] parameter is optional and ignored."; throw(runtime_error(msg)); } @@ -426,11 +458,11 @@ Value submitblock(const Array ¶ms, bool fHelp) { if(!ProcessBlock(NULL, &block)) { #if 0 /* Dump block data received */ - uint i, size; + uint r, size; size = (uint)blockData.size(); printf("Block data %u bytes Rx: ", size); - for(i = 0; i < size; i++) - printf("%02X", ((uchar *) &blockData[0])[i]); + for(r = 0; r < size; r++) + printf("%02X", ((uchar *) &blockData[0])[r]); printf("\n"); #endif return("rejected"); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 55c1bee0..33b474e1 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -4,10 +4,10 @@ #include -#include "util.h" +#include "ntp.h" #include "net.h" +#include "util.h" #include "rpcmain.h" -#include "ntp.h" using namespace json_spirit; using namespace std; @@ -17,7 +17,7 @@ Value getconnectioncount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getconnectioncount\n" - "Returns the number of connections to other nodes"; + "Displays the number of connections to other nodes."; throw(runtime_error(msg)); } @@ -39,11 +39,12 @@ static void CopyNodeStats(std::vector& vstats) } } + Value getpeerinfo(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getpeerinfo\n" - "Returns data about each connected network node"; + "Displays data about each connected network node."; throw(runtime_error(msg)); } @@ -56,7 +57,7 @@ Value getpeerinfo(const Array ¶ms, bool fHelp) { Object obj; obj.push_back(Pair("addr", stats.addrName)); - obj.push_back(Pair("services", strprintf("%08" PRI64x, stats.nServices))); + obj.push_back(Pair("services", strprintf("%016" PRI64x "", stats.nServices))); obj.push_back(Pair("lastsend", DateTimeStrFormat(stats.nLastSend))); obj.push_back(Pair("lastrecv", DateTimeStrFormat(stats.nLastRecv))); obj.push_back(Pair("conntime", DateTimeStrFormat(stats.nTimeConnected))); @@ -90,7 +91,7 @@ Value addnode(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 2) || ((strCommand != "onetry") && (strCommand != "add") && (strCommand != "remove"))) { string msg = "addnode \n" - "Attempts to add or remove a node from the list or try a connection to the node once"; + "Attempts to add or remove a node from the list or try a connection to the node once."; throw(runtime_error(msg)); } @@ -126,9 +127,9 @@ Value getaddednodeinfo(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { string msg = "getaddednodeinfo [node:port]\n" - "Returns information about the given added node or all added nodes\n" - " is true or false to provide extended information or not\n" - "Note that one try addnodes are not listed.\n"; + "Displays information on the particular added node or all added nodes.\n" + " is true or false to provide extended information or not to.\n" + "One try addnodes are not listed.\n"; throw(runtime_error(msg)); } @@ -209,8 +210,8 @@ Value getnettotals(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 0)) { string msg = "getnettotals\n" - "Returns information about network traffic including bytes received,\n" - "bytes transmitted and current time"; + "Displays network traffic related information\n" + "including bytes received, bytes transmitted and current time."; throw(runtime_error(msg)); } @@ -228,7 +229,7 @@ Value ntptime(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { string msg = "ntptime [server]\n" - "Returns current time from a specific or random NTP server"; + "Displays current time received from a specific or random NTP server."; throw(runtime_error(msg)); } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 633c586e..02d7cc5b 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -3,28 +3,27 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include - #include #include #include #include -#include "init.h" -#include "main.h" +#include + #include "base58.h" #include "db.h" #include "wallet.h" -#include "net.h" #include "rpcmain.h" +#include "main.h" + +extern CWallet *pwalletMain; using namespace std; using namespace boost; using namespace boost::assign; using namespace json_spirit; -void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out) -{ +void ScriptPubKeyToJSON(const CScript &scriptPubKey, Object &out) { txnouttype type; vector addresses; int nRequired; @@ -109,6 +108,7 @@ Value getrawtransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { string msg = "getrawtransaction [verbose]\n" + "Retrieves data of transaction from the block chain.\n" "If [verbose] is zero, returns a string containing serialised hex data for .\n" "If [verbose] is non-zero, returns an object with information about ."; throw(runtime_error(msg)); @@ -144,10 +144,10 @@ Value listunspent(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 3)) { string msg = "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n" - "Returns array of unspent transaction outputs\n" - "with between minconf and maxconf (inclusive) confirmations.\n" + "Reports unspent transaction outputs\n" + "with minconf to maxconf (inclusive) confirmations.\n" "Optionally filtered to only include txouts paid to specified addresses.\n" - "Results are an array of Objects, each of which has:\n" + "Results are an array of objects, each of which has:\n" "{txid, vout, scriptPubKey, amount, confirmations}"; throw(runtime_error(msg)); } @@ -211,16 +211,41 @@ Value listunspent(const Array ¶ms, bool fHelp) { } +Value decodescript(const Array ¶ms, bool fHelp) { + + if(fHelp || (params.size() != 1)) { + string msg = "decodescript \n" + "Decodes hex encoded script ."; + throw(runtime_error(msg)); + } + + RPCTypeCheck(params, list_of(str_type)); + + Object r; + CScript script; + if (params[0].get_str().size() > 0){ + vector scriptData(ParseHexV(params[0], "argument")); + script = CScript(scriptData.begin(), scriptData.end()); + } else { + /* Empty scripts are valid */ + } + ScriptPubKeyToJSON(script, r); + + r.push_back(Pair("p2sh", CCoinAddress(script.GetID()).ToString())); + return(r); +} + + Value createrawtransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 2)) { string msg = "createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\n" "Creates a transaction spending inputs formatted in an array of\n" "objects each comprising of a transaction ID and output index,\n" - "to given addresses in amounts specified.\n" + "to addresses provided in amounts specified.\n" "Returns a serialised hex encoded raw transaction.\n" - "Note that the transaction's inputs are not signed, and\n" - "it is not stored in the wallet or transmitted to the network."; + "The transaction inputs are not signed and not stored\n" + "in the wallet or transmitted to the network."; throw(runtime_error(msg)); } @@ -284,9 +309,9 @@ Value createrawtransaction(const Array ¶ms, bool fHelp) { Value decoderawtransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { - string msg = "decoderawtransaction \n" - "Decodes a hex string of raw transaction data and\n" - "returns a JSON object of formatted data of this transaction."; + string msg = "decoderawtransaction \n" + "Decodes raw hexadecimal transaction provided and\n" + "returns an object with formatted transaction data."; throw(runtime_error(msg)); } @@ -312,8 +337,8 @@ Value decoderawtransaction(const Array ¶ms, bool fHelp) { Value signrawtransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 4)) { - string msg = "signrawtransaction [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex},...] [,...] [sighashtype=\"ALL\"]\n" - "Signs inputs of a serialised hex encoded raw transaction in the .\n" + string msg = "signrawtransaction [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex},...] [,...] [sighashtype=\"ALL\"]\n" + "Signs inputs of a raw transaction provided as hexadecimal .\n" "The second argument is an optional array of previous transaction outputs that\n" "this transaction depends on, which may not yet be in the block chain.\n" "The third argument is an optional array of base58 encoded private\n" @@ -503,8 +528,9 @@ Value signrawtransaction(const Array ¶ms, bool fHelp) { Value sendrawtransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 1)) { - string msg = "sendrawtransaction \n" - "Submits a serialised hex encoded raw transaction to the local node and network"; + string msg = "sendrawtransaction \n" + "Submits a serialised raw transaction provided as hexadecimal \n" + "to the local node and network."; throw(runtime_error(msg)); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 6522b3b9..66fae961 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -12,12 +12,14 @@ #include #include -#include "init.h" #include "base58.h" -#include "walletdb.h" +#include "init.h" +#include "ntp.h" #include "wallet.h" #include "rpcmain.h" -#include "ntp.h" +#include "main.h" + +extern CWallet *pwalletMain; using namespace json_spirit; using namespace std; @@ -48,11 +50,11 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); - entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); + entry.push_back(Pair("blocktime", (int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); - entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); - entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); + entry.push_back(Pair("time", (int64_t)wtx.GetTxTime())); + entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } @@ -70,7 +72,7 @@ Value getinfo(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 0)) { string msg = "getinfo\n" - "Returns an object containing various state info"; + "Reports various state info."; throw(runtime_error(msg)); } @@ -85,12 +87,12 @@ Value getinfo(const Array ¶ms, bool fHelp) { obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); - obj.push_back(Pair("systemtime", (boost::int64_t)GetTime())); - obj.push_back(Pair("adjustedtime", (boost::int64_t)GetAdjustedTime())); - obj.push_back(Pair("ntpoffset", (boost::int64_t)nNtpOffset != INT64_MAX ? (boost::int64_t)nNtpOffset : Value::null)); - obj.push_back(Pair("p2poffset", (boost::int64_t)nPeersOffset != INT64_MAX ? (boost::int64_t)nPeersOffset : Value::null)); + obj.push_back(Pair("systemtime", (int64_t)GetTime())); + obj.push_back(Pair("adjustedtime", (int64_t)GetAdjustedTime())); + obj.push_back(Pair("ntpoffset", (int64_t)nNtpOffset != INT64_MAX ? (boost::int64_t)nNtpOffset : Value::null)); + obj.push_back(Pair("p2poffset", (int64_t)nPeersOffset != INT64_MAX ? (boost::int64_t)nPeersOffset : Value::null)); obj.push_back(Pair("testnet", fTestNet)); - obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoololdest", (int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); @@ -105,9 +107,9 @@ Value getnewaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { string msg = "getnewaddress [account]\n" - "Picks up a new address from the key pool.\n" - "If [account] is specified (recommended), it is added to the address book\n" - "so payments received with the address will be credited to [account]."; + "Picks up a new address from the key pool and displays it.\n" + "If [account] is specified (recommended), it is added to the address book,\n" + "so payments received with it will be credited to [account]."; throw(runtime_error(msg)); } @@ -131,6 +133,38 @@ Value getnewaddress(const Array ¶ms, bool fHelp) { } +Value getnewpubkey(const Array ¶ms, bool fHelp) { + + if(fHelp || (params.size() > 1)) { + string msg = "getnewpubkey [account]\n" + "Picks up a new address from the key pool and displays the public key.\n" + "If [account] is specified (recommended), it is added to the address book,\n" + "so payments received with it will be credited to [account]."; + throw(runtime_error(msg)); + } + + string strAccount; + if(params.size() > 0) + strAccount = AccountFromValue(params[0]); + + if(!pwalletMain->IsLocked()) + pwalletMain->TopUpKeyPool(); + + CPubKey newKey; + if(!pwalletMain->GetKeyFromPool(newKey, false)) { + throw(JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, + "Error: keypool empty, call keypoolrefill first")); + } + CKeyID keyID = newKey.GetID(); + + pwalletMain->SetAddressBookName(keyID, strAccount); + + vector vchPubKey = newKey.Raw(); + + return(HexStr(vchPubKey.begin(), vchPubKey.end())); +} + + CCoinAddress GetAccountAddress(string strAccount, bool bForceNew = false) { CWalletDB walletdb(pwalletMain->strWalletFile); @@ -172,11 +206,10 @@ Value getaccountaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "getaccountaddress \n" - "Returns the current address for receiving payments to this account"; + "Displays the current address for receiving payments to the "; throw(runtime_error(msg)); } - // Parse the account first so we don't generate a key if there's an error string strAccount = AccountFromValue(params[0]); Value ret; @@ -191,7 +224,7 @@ Value setaccount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { string msg = "setaccount
\n" - "Sets the account associated with the given address"; + "Assigns the
to the specified."; throw(runtime_error(msg)); } @@ -222,7 +255,7 @@ Value getaccount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "getaccount
\n" - "Returns the account associated with the given address"; + "Displays the account associated with the
specified."; throw(runtime_error(msg)); } @@ -242,18 +275,18 @@ Value getaddressesbyaccount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "getaddressesbyaccount \n" - "Returns the list of addresses for the given account"; + "Displays a list of addresses associated with the specified."; throw(runtime_error(msg)); } string strAccount = AccountFromValue(params[0]); - // Find all addresses that have the given account Array ret; - BOOST_FOREACH(const PAIRTYPE(CCoinAddress, string)& item, pwalletMain->mapAddressBook) { + BOOST_FOREACH(const PAIRTYPE(CCoinAddress, string) &item, pwalletMain->mapAddressBook) { const CCoinAddress &address = item.first; const string &strName = item.second; - if(strName == strAccount) ret.push_back(address.ToString()); + if(strName == strAccount) + ret.push_back(address.ToString()); } return(ret); } @@ -263,7 +296,8 @@ Value sendtoaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 2) || (params.size() > 4)) { string msg = "sendtoaddress
[comment] [comment-to]\n" - " is a real and is rounded to the nearest 0.00000001" + "Sends to an
\n" + " is a floating point number rounded to the nearest 0.00000001" + HelpRequiringPassphrase(); throw(runtime_error(msg)); } @@ -285,9 +319,11 @@ Value sendtoaddress(const Array ¶ms, bool fHelp) { if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); + /* Send */ string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); - if (!strError.empty()) - throw JSONRPCError(RPC_WALLET_ERROR, strError); + + if(!strError.empty()) + throw(JSONRPCError(RPC_WALLET_ERROR, strError)); return wtx.GetHash().GetHex(); } @@ -299,7 +335,7 @@ Value listaddressgroupings(const Array ¶ms, bool fHelp) { string msg = "listaddressgroupings\n" "Lists groups of addresses which have had their common ownership\n" "made public by common use as inputs or as the resulting change\n" - "in past transactions"; + "in the past transactions."; throw(runtime_error(msg)); } @@ -330,7 +366,7 @@ Value signmessage(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 2)) { string msg = "signmessage
\n" - "Signs a message with the private key of an address"; + "Signs a with the private key of
specified."; throw(runtime_error(msg)); } @@ -367,7 +403,7 @@ Value verifymessage(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 3)) { string msg = "verifymessage
\n" - "Verifies a signed message"; + "Verifies a of the
with the provided."; throw(runtime_error(msg)); } @@ -404,9 +440,9 @@ Value verifymessage(const Array ¶ms, bool fHelp) { Value getreceivedbyaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { - string msg = "getreceivedbyaddress
[minconf=1]\n" - "Returns the total amount received by
in transactions\n" - "with at least [minconf] confirmations"; + string msg = "getreceivedbyaddress
[minconf]\n" + "Returns the total amount of transactions made to the
.\n" + "[minconf] specifies the number of confirmations required, 1 by default."; throw(runtime_error(msg)); } @@ -418,10 +454,10 @@ Value getreceivedbyaddress(const Array ¶ms, bool fHelp) { scriptPubKey.SetDestination(address.Get()); if(!IsMine(*pwalletMain, scriptPubKey)) return((double)0.0); - // Minimum confirmations + /* Minimum confirmations */ int nMinDepth = 1; - if (params.size() > 1) - nMinDepth = params[1].get_int(); + if(params.size() > 1) nMinDepth = params[1].get_int(); + if(nMinDepth < -1) nMinDepth = -1; // Tally int64 nAmount = 0; @@ -455,16 +491,16 @@ void GetAccountAddresses(string strAccount, set& setAddress) Value getreceivedbyaccount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 1) || (params.size() > 2)) { - string msg = "getreceivedbyaccount [minconf=1]\n" - "Returns the total amount received by addresses\n" - "with in transactions with at least [minconf] confirmations"; + string msg = "getreceivedbyaccount [minconf]\n" + "Returns the total amount of transactions made to addresses of the .\n" + "[minconf] specifies the number of confirmations required, 1 by default."; throw(runtime_error(msg)); } - // Minimum confirmations + /* Minimum confirmations */ int nMinDepth = 1; - if (params.size() > 1) - nMinDepth = params[1].get_int(); + if(params.size() > 1) nMinDepth = params[1].get_int(); + if(nMinDepth < -1) nMinDepth = -1; // Get the set of pub keys assigned to account string strAccount = AccountFromValue(params[0]); @@ -526,9 +562,10 @@ int64 GetAccountBalance(const string& strAccount, int nMinDepth) Value getbalance(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 2)) { - string msg = "getbalance [account] [minconf=1]\n" - "If [account] is not specified, returns the server's total available balance.\n" - "If [account] is specified, returns the balance in the account."; + string msg = "getbalance [account] [minconf]\n" + "If [account] is not specified, returns the total available balance.\n" + "If [account] is specified, returns the balance in the [account].\n" + "[minconf] specifies the number of confirmations required, 1 by default."; throw(runtime_error(msg)); } @@ -536,8 +573,8 @@ Value getbalance(const Array ¶ms, bool fHelp) { return ValueFromAmount(pwalletMain->GetBalance()); int nMinDepth = 1; - if (params.size() > 1) - nMinDepth = params[1].get_int(); + if(params.size() > 1) nMinDepth = params[1].get_int(); + if(nMinDepth < -1) nMinDepth = -1; if (params[0].get_str() == "*") { // Calculate total balance a different way from GetBalance() @@ -578,20 +615,17 @@ Value getbalance(const Array ¶ms, bool fHelp) { Value movecmd(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 3) || (params.size() > 5)) { - string msg = "move [minconf=1] [comment]\n" - "Moves from one account in your wallet to another."; + string msg = "move [comment]\n" + "Sends from one account to another.\n" + " is a floating point number rounded to the nearest 0.00000001"; throw(runtime_error(msg)); } string strFrom = AccountFromValue(params[0]); string strTo = AccountFromValue(params[1]); int64 nAmount = AmountFromValue(params[2]); - if (params.size() > 3) - // unused parameter, used to be nMinDepth, keep type-checking it though - (void)params[3].get_int(); string strComment; - if (params.size() > 4) - strComment = params[4].get_str(); + if(params.size() > 3) strComment = params[3].get_str(); CWalletDB walletdb(pwalletMain->strWalletFile); if (!walletdb.TxnBegin()) @@ -629,8 +663,10 @@ Value movecmd(const Array ¶ms, bool fHelp) { Value sendfrom(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 3) || (params.size() > 6)) { - string msg = "sendfrom [minconf=1] [comment] [comment-to]\n" - " is a real and is rounded to the nearest 0.00000001" + string msg = "sendfrom
[minconf] [comment] [comment-to]\n" + "Sends from to a single
.\n" + " is a floating point number rounded to the nearest 0.00000001\n" + "[minconf] specifies the number of confirmations required, 1 by default." + HelpRequiringPassphrase(); throw(runtime_error(msg)); } @@ -640,9 +676,10 @@ Value sendfrom(const Array ¶ms, bool fHelp) { if(!address.IsValid()) throw(JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Phoenixcoin address")); int64 nAmount = AmountFromValue(params[2]); + int nMinDepth = 1; - if(params.size() > 3) - nMinDepth = params[3].get_int(); + if(params.size() > 3) nMinDepth = params[3].get_int(); + if(nMinDepth < 0) nMinDepth = 0; CWalletTx wtx; wtx.strFromAccount = strAccount; @@ -658,29 +695,33 @@ Value sendfrom(const Array ¶ms, bool fHelp) { if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); - // Send + /* Send */ string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); - if (!strError.empty()) - throw JSONRPCError(RPC_WALLET_ERROR, strError); - return wtx.GetHash().GetHex(); + if(!strError.empty()) + throw(JSONRPCError(RPC_WALLET_ERROR, strError)); + + return(wtx.GetHash().GetHex()); } Value sendmany(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 2) || (params.size() > 4)) { - string msg = "sendmany {address:amount,...} [minconf=1] [comment]\n" - "Amounts are double precision floating point numbers" + string msg = "sendmany {address:amount,...} [minconf] [comment]\n" + "Sends from to multiple recipients.\n" + "Amounts are floating point numbers rounded to the nearest 0.00000001\n" + "[minconf] specifies the number of confirmations required, 1 by default." + HelpRequiringPassphrase(); throw(runtime_error(msg)); } string strAccount = AccountFromValue(params[0]); Object sendTo = params[1].get_obj(); + int nMinDepth = 1; - if (params.size() > 2) - nMinDepth = params[2].get_int(); + if(params.size() > 2) nMinDepth = params[2].get_int(); + if(nMinDepth < 0) nMinDepth = 0; CWalletTx wtx; wtx.strFromAccount = strAccount; @@ -739,10 +780,10 @@ Value sendmany(const Array ¶ms, bool fHelp) { Value addmultisigaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() < 2) || (params.size() > 3)) { - string msg = "addmultisigaddress <'[\"key\",\"key\"]'> [account]\n" - "Add a nrequired-to-sign multisignature address to the wallet\"\n" - "each key is an address or hex encoded public key.\n" - "If [account] is specified, assign address to [account]."; + string msg = "addmultisigaddress <'[\"key\",\"key\"]'> [account]\n" + "Adds a N-required-to-sign multisignature address to the wallet.\n" + "Each key is an address or hex encoded public key.\n" + "If [account] is specified, assigns the address to it."; throw(runtime_error(msg)); } @@ -752,13 +793,16 @@ Value addmultisigaddress(const Array ¶ms, bool fHelp) { if (params.size() > 2) strAccount = AccountFromValue(params[2]); - // Gather public keys - if (nRequired < 1) - throw runtime_error("a multisignature address must require at least one key to redeem"); - if ((int)keys.size() < nRequired) - throw runtime_error( - strprintf("not enough keys supplied " - "(got %" PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired)); + /* Gather public keys */ + if(nRequired < 1) { + throw(runtime_error("a multisignature address must require at least one key to redeem")); + } + + if((int)keys.size() < nRequired) { + throw(runtime_error(strprintf("not enough keys supplied " \ + "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired))); + } + std::vector pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) @@ -903,13 +947,13 @@ Value ListReceived(const Array& params, bool fByAccounts) return ret; } - Value listreceivedbyaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 2)) { - string msg = "listreceivedbyaddress [minconf=1] [include-empty=false]\n" - "[minconf] is the minimum number of confirmations before payments are included.\n" - "[include-empty] whether to include addresses that haven't received any payments.\n" + string msg = "listreceivedbyaddress [minconf] [empty]\n" + "Displays amounts received by each in-wallet address.\n" + "[minconf] specifies the number of confirmations required, 1 by default." + "[empty] lists addresses without any payments received, false by default.\n" "Returns an array of objects containing:\n" " \"address\" : receiving address\n" " \"account\" : the account of the receiving address\n" @@ -925,9 +969,10 @@ Value listreceivedbyaddress(const Array ¶ms, bool fHelp) { Value listreceivedbyaccount(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 2)) { - string msg = "listreceivedbyaccount [minconf=1] [include-empty=false]\n" - "[minconf] is the minimum number of confirmations before payments are included.\n" - "[include-empty] whether to include accounts that haven't received any payments.\n" + string msg = "listreceivedbyaccount [minconf] [empty]\n" + "Displays amounts received by each account.\n" + "[minconf] specifies the number of confirmations required, 1 by default." + "[empty] lists accounts without any payments received, false by default.\n" "Returns an array of objects containing:\n" " \"account\" : the account of the receiving addresses\n" " \"amount\" : total amount received by addresses with this account\n" @@ -1020,9 +1065,10 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Ar Value listtransactions(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 3)) { - string msg = "listtransactions [account] [count=10] [from=0]\n" - "Returns up to [count] most recent transactions\n" - "skipping the first [from] transactions for account [account]"; + string msg = "listtransactions [account] [count] [skip]\n" + "Displays up to [count] most recent in-wallet transactions, 10 by default,\n" + "for [account], * by default meaning all accounts,\n" + "discarding first [skip] transactions, 0 by default."; throw(runtime_error(msg)); } @@ -1081,8 +1127,9 @@ Value listtransactions(const Array ¶ms, bool fHelp) { Value listaccounts(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 1)) { - string msg = "listaccounts [minconf=1]\n" - "Returns object that has account names as keys, account balances as values"; + string msg = "listaccounts [minconf]\n" + "Displays accounts and their respective balance.\n" + "[minconf] specifies the number of confirmations required, 1 by default."; throw(runtime_error(msg)); } @@ -1133,8 +1180,9 @@ Value listaccounts(const Array ¶ms, bool fHelp) { Value listsinceblock(const Array ¶ms, bool fHelp) { if(fHelp) { - string msg = "listsinceblock [hash] [target-confirmations]\n" - "Gets all transactions in blocks since a block [hash] or all transactions if omitted"; + string msg = "listsinceblock [hash] [minconf]\n" + "Displays in-wallet transactions since block with [hash], default is genesis,\n" + "having [minconf] confirmations at least, default is 1."; throw(runtime_error(msg)); } @@ -1199,7 +1247,7 @@ Value gettransaction(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "gettransaction \n" - "Displays detailed information about an in-wallet transaction "; + "Displays detailed information about an in-wallet transaction ."; throw(runtime_error(msg)); } @@ -1235,7 +1283,7 @@ Value backupwallet(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "backupwallet \n" "Safely copies wallet.dat to ,\n" - "which can be a directory or a path with file name"; + "which can be a directory or a path with file name."; throw(runtime_error(msg)); } @@ -1251,7 +1299,7 @@ Value keypoolrefill(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() > 0)) { string msg = "keypoolrefill\n" - "Tops up the pool of ready-for-use private and public key pairs" + "Tops up the pool of ready-for-use private and public key pairs." + HelpRequiringPassphrase(); throw(runtime_error(msg)); } @@ -1319,17 +1367,16 @@ void ThreadCleanWalletPassphrase(void* parg) delete (int64*)parg; } - Value walletpassphrase(const Array ¶ms, bool fHelp) { if(pwalletMain->IsCrypted() && (fHelp || (params.size() != 2))) { string msg = "walletpassphrase \n" - "Stores the wallet decryption key in memory for seconds"; + "Stores the wallet decryption key in memory for seconds."; throw(runtime_error(msg)); } - if (fHelp) - return true; + if(fHelp) return(true); + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); @@ -1364,12 +1411,12 @@ Value walletpassphrasechange(const Array ¶ms, bool fHelp) { if(pwalletMain->IsCrypted() && (fHelp || (params.size() != 2))) { string msg = "walletpassphrasechange \n" - "Changes the wallet decryption key from to "; + "Changes the wallet decryption key from to ."; throw(runtime_error(msg)); } - if (fHelp) - return true; + if(fHelp) return(true); + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); @@ -1400,14 +1447,12 @@ Value walletlock(const Array ¶ms, bool fHelp) { if(pwalletMain->IsCrypted() && (fHelp || (params.size() != 0))) { string msg = "walletlock\n" - "Removes the wallet decryption key from memory and locks the wallet.\n" - "You need to call walletpassphrase again after this\n" - "in order to call any methods which require the wallet to be unlocked."; + "Removes the wallet decryption key from memory and locks the wallet."; throw(runtime_error(msg)); } - if (fHelp) - return true; + if(fHelp) return(true); + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); @@ -1425,12 +1470,12 @@ Value encryptwallet(const Array ¶ms, bool fHelp) { if(!pwalletMain->IsCrypted() && (fHelp || (params.size() != 1))) { string msg = "encryptwallet \n" - "Encrypts the wallet with the key"; + "Encrypts the wallet with the key."; throw(runtime_error(msg)); } - if (fHelp) - return true; + if(fHelp) return(true); + if (pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); @@ -1509,7 +1554,7 @@ Value validateaddress(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "validateaddress
\n" - "Returns information about
"; + "Displays information about the
."; throw(runtime_error(msg)); } @@ -1541,7 +1586,7 @@ Value validatepubkey(const Array ¶ms, bool fHelp) { if(fHelp || (params.size() != 1)) { string msg = "validatepubkey \n" - "Returns information about "; + "Displays information about the public ."; throw(runtime_error(msg)); } @@ -1579,9 +1624,9 @@ Value validatepubkey(const Array ¶ms, bool fHelp) { Value resendtx(const Array ¶ms, bool fHelp) { - if(fHelp || (params.size() > 1)) { + if(fHelp || (params.size() > 0)) { string msg = "resendtx\n" - "Resends unconfirmed wallet transactions.\n"; + "Resends unconfirmed wallet transactions."; throw(runtime_error(msg)); } diff --git a/src/script.cpp b/src/script.cpp index a303b428..d3c23461 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -3,27 +3,28 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include - #include #include #include -using namespace std; -using namespace boost; +#include +#include -#include "script.h" -#include "keystore.h" +#include "sync.h" #include "bignum.h" +#include "keystore.h" #include "key.h" #include "util.h" #include "main.h" -#include "sync.h" +#include "script.h" + +using namespace std; +using namespace boost; -bool CheckSig(vector vchSig, vector vchPubKey, CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); +bool CheckSig(vector vchSig, vector vchPubKey, CScript scriptCode, + const CTransaction &txTo, uint nIn, int nHashType); -typedef vector valtype; +typedef vector valtype; static const valtype vchFalse(0); static const valtype vchZero(0); static const valtype vchTrue(1, 1); diff --git a/src/script.h b/src/script.h index 347d44d7..9208af13 100644 --- a/src/script.h +++ b/src/script.h @@ -11,8 +11,9 @@ #include -#include "keystore.h" #include "bignum.h" +#include "keystore.h" +#include "util.h" class CTransaction; diff --git a/src/serialize.h b/src/serialize.h index 4ef8d96c..aecf25f4 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -6,11 +6,6 @@ #ifndef SERIALIZE_H #define SERIALIZE_H -#include -#include -#include -#include - #include #include #include @@ -23,6 +18,11 @@ #include #include +#include +#include +#include +#include + #include "datatypes.h" #include "allocators.h" #include "version.h" diff --git a/src/sync.cpp b/src/sync.cpp index 53ef4465..aa9d474d 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -7,11 +7,11 @@ #include #include -#include "util.h" -#include "sync.h" - #include +#include "sync.h" +#include "util.h" + #ifdef DEBUG_LOCKCONTENTION void PrintLockContention(const char* pszName, const char* pszFile, int nLine) { diff --git a/src/sync.h b/src/sync.h index f1d07528..b876cd20 100644 --- a/src/sync.h +++ b/src/sync.h @@ -11,9 +11,6 @@ #include #include - - - /** Wrapped boost mutex: supports recursive locking, but no waiting */ typedef boost::recursive_mutex CCriticalSection; diff --git a/src/ui_interface.h b/src/ui_interface.h index 842cc667..5abaa5e1 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -7,13 +7,15 @@ #define UI_INTERFACE_H #include -#include "util.h" // for int64 + #include #include +#include "datatypes.h" + +class uint256; class CBasicKeyStore; class CWallet; -class uint256; /** General change type (added, updated, removed). */ enum ChangeType diff --git a/src/uint256.h b/src/uint256.h index 924fe32a..2549fbd5 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -6,11 +6,12 @@ #ifndef UINT256_H #define UINT256_H +#include +#include + #include #include #include -#include -#include #include "datatypes.h" diff --git a/src/util.cpp b/src/util.cpp index 56619826..904dfa95 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -6,15 +6,25 @@ #include #include -#include "util.h" -#include "sync.h" +#include + +#include +#include +#include +#include +#include +#include +#include + #include "strlcpy.h" #include "version.h" +#include "sync.h" +#include "netbase.h" #include "ui_interface.h" +#include "util.h" -#include "netbase.h" /* for AddTimeData() */ - -#include +#include +#include // Work around clang compilation problem in Boost 1.46: // /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 @@ -26,15 +36,6 @@ namespace boost { } } -#include -#include -#include -#include -#include -#include -#include -#include -#include #ifdef WINDOWS #ifndef NOMINMAX @@ -117,7 +118,7 @@ instance_of_cinit; void RandAddSeed() { int64 nCounter = GetTimeMicros(); RAND_add(&nCounter, sizeof(nCounter), 1.5); - memset(&nCounter, 0, sizeof(nCounter)); + OPENSSL_cleanse(&nCounter, sizeof(nCounter)); } void RandAddSeedPerfmon() @@ -134,8 +135,8 @@ void RandAddSeedPerfmon() // Don't need this on Linux, OpenSSL automatically uses /dev/urandom // Seed with the entire set of perfmon data unsigned char pdata[250000]; - memset(pdata, 0, sizeof(pdata)); unsigned long nSize = sizeof(pdata); + OPENSSL_cleanse(pdata, nSize); long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, pdata, &nSize); RegCloseKey(HKEY_PERFORMANCE_DATA); @@ -175,61 +176,50 @@ uint256 GetRandHash() } - - - - - - -inline int OutputDebugStringF(const char* pszFormat, ...) -{ +/* Prints either to stdout, debug.log or debugger */ +inline int OutputDebugStringF(const char *pszFormat, ...) { int ret = 0; - if (fPrintToConsole) - { - // print to console + + if(fPrintToConsole) { va_list arg_ptr; va_start(arg_ptr, pszFormat); ret = vprintf(pszFormat, arg_ptr); va_end(arg_ptr); - } - else if (!fPrintToDebugger) - { - // print to debug.log - static FILE* fileout = NULL; + } else if(!fPrintToDebugger) { + static FILE *fileout = NULL; - if (!fileout) - { + if(!fileout) { boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; fileout = fopen(pathDebug.string().c_str(), "a"); - if (fileout) setbuf(fileout, NULL); // unbuffered + if(fileout) setbuf(fileout, NULL); // unbuffered } - if (fileout) - { + + if(fileout) { static bool fStartedNewLine = true; // This routine may be called by global destructors during shutdown. // Since the order of destruction of static/global objects is undefined, // allocate mutexDebugLog on the heap the first time this routine // is called to avoid crashes during shutdown. - static boost::mutex* mutexDebugLog = NULL; - if (mutexDebugLog == NULL) mutexDebugLog = new boost::mutex(); + static boost::mutex *mutexDebugLog = NULL; + if(!mutexDebugLog) mutexDebugLog = new boost::mutex(); boost::mutex::scoped_lock scoped_lock(*mutexDebugLog); - // reopen the log file, if requested - if (fReopenDebugLog) { + /* Reopen the log file if requested */ + if(fReopenDebugLog) { fReopenDebugLog = false; boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; - if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL) - setbuf(fileout, NULL); // unbuffered + if(freopen(pathDebug.string().c_str(),"a",fileout)) + setbuf(fileout, NULL); // unbuffered } - // Debug print useful for profiling + /* Debug print useful for profiling */ if(fLogTimestamps && fStartedNewLine) fprintf(fileout, "%s ", DateTimeStrFormat(GetTime()).c_str()); - if (pszFormat[strlen(pszFormat) - 1] == '\n') - fStartedNewLine = true; + if(pszFormat[strlen(pszFormat) - 1] == '\n') + fStartedNewLine = true; else - fStartedNewLine = false; + fStartedNewLine = false; va_list arg_ptr; va_start(arg_ptr, pszFormat); @@ -239,11 +229,11 @@ inline int OutputDebugStringF(const char* pszFormat, ...) } #ifdef WINDOWS - if (fPrintToDebugger) - { + if(fPrintToDebugger) { static CCriticalSection cs_OutputDebugStringF; - // accumulate and output a line at a time + /* Accumulate and output a line at a time */ + { LOCK(cs_OutputDebugStringF); static std::string buffer; @@ -254,8 +244,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) va_end(arg_ptr); int line_start = 0, line_end; - while((line_end = buffer.find('\n', line_start)) != -1) - { + while((line_end = buffer.find('\n', line_start)) != -1) { OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str()); line_start = line_end + 1; } @@ -263,7 +252,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...) } } #endif - return ret; + + return(ret); } string vstrprintf(const char *format, va_list ap) @@ -349,9 +339,9 @@ string FormatMoney(int64 n, bool fPlus) // Note: not using straight sprintf here because we do NOT want // localized number formatting. int64 n_abs = (n > 0 ? n : -n); - int64 quotient = n_abs/COIN; - int64 remainder = n_abs%COIN; - string str = strprintf("%" PRI64d".%08" PRI64d, quotient, remainder); + int64 quotient = n_abs / COIN; + int64 remainder = n_abs % COIN; + string str = strprintf("%" PRI64d ".%08" PRI64d "", quotient, remainder); // Right-trim excess zeros before the decimal point: int nTrim = 0; @@ -926,16 +916,10 @@ bool WildcardMatch(const string& str, const string& mask) } - - - - - - -static std::string FormatException(std::exception* pex, const char* pszThread) -{ +static std::string FormatException(std::exception *pex, const char *pszThread) { #ifdef WINDOWS - char pszModule[MAX_PATH].clear(); + char pszModule[MAX_PATH]; + memset(pszModule, 0x00, MAX_PATH); GetModuleFileNameA(NULL, pszModule, sizeof(pszModule)); #else const char *pszModule = "phoenixcoin"; @@ -980,11 +964,17 @@ boost::filesystem::path GetDefaultDataDir() { path = boost::filesystem::current_path() / "data"; #else /* Linux, Mac OS X, *BSD and so on: ~/.phoenixcoin */ - char* pszHome = getenv("HOME"); - if((pszHome == NULL) || (strlen(pszHome) == 0)) - path = fs::path("/.phoenixcoin"); - else - path = fs::path(pszHome) / ".phoenixcoin"; + char *pszHome = getenv("HOME"); + if(!pszHome || !strlen(pszHome)) { + /* Must be root if no $HOME set */ +#ifdef __APPLE__ + path = fs::path("/private/var/root/.phoenixcoin"); +#else + path = fs::path("/root/.phoenixcoin"); +#endif + } else { + path = fs::path(pszHome) / ".phoenixcoin"; + } #endif return(path); @@ -1009,9 +999,9 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) if (mapArgs.count("-datadir")) { path = fs::system_complete(mapArgs["-datadir"]); - if (!fs::is_directory(path)) { + if(!fs::is_directory(path)) { path.clear(); - return path; + return(path); } } else { path = GetDefaultDataDir(); @@ -1133,30 +1123,23 @@ int GetFilesize(FILE* file) void ShrinkDebugFile() { boost::filesystem::path pathLog = GetDataDir() / "debug.log"; - FILE* file = fopen(pathLog.string().c_str(), "r"); - /* If the file size exceeds 10Mb, crop it to the last 200Kb */ + FILE *file = fopen(pathLog.string().c_str(), "r"); + /* If the file size exceeds 10Mb, crop it to the last 100Kb */ if(file && (GetFilesize(file) > 10 * 1024 * 1024)) { - char pch[200 * 1024]; + char pch[100 * 1024]; fseek(file, -((long)sizeof(pch)), SEEK_END); int nBytes = fread(pch, 1, sizeof(pch), file); fclose(file); file = fopen(pathLog.string().c_str(), "w"); - if (file) - { + if(file) { fwrite(pch, 1, nBytes, file); fclose(file); } - } else if(file != NULL) fclose(file); + } else if(file) fclose(file); } - - - - - - // // "Never go to sea with two chronometers; take one or three." // Our three time sources are: @@ -1213,7 +1196,8 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) // Add data vTimeOffsets.input(nOffsetSample); - printf("Added time data, samples %d, offset %+" PRI64d" (%+" PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + printf("Added time data, samples %d, offset %+" PRI64d " (%+" PRI64d " minutes)\n", + vTimeOffsets.size(), nOffsetSample, nOffsetSample / 60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { int64 nMedian = vTimeOffsets.median(); @@ -1250,12 +1234,12 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) if (fDebug) { BOOST_FOREACH(int64 n, vSorted) - printf("%+" PRI64d" ", n); + printf("%+" PRI64d " ", n); printf("| "); } if(nPeersOffset != INT64_MAX) - printf("nPeersOffset = %+" PRI64d" seconds\n", nPeersOffset); + printf("nPeersOffset = %+" PRI64d " seconds\n", nPeersOffset); } } diff --git a/src/util.h b/src/util.h index 3e6c7fa6..0a2ede80 100644 --- a/src/util.h +++ b/src/util.h @@ -11,21 +11,19 @@ #include #include -#include "datatypes.h" -#include "compat.h" - -#include "uint256.h" -#include "serialize.h" - -#include -#include -#include #include #include +#include +#include +#include #include #include +#include "compat.h" +#include "uint256.h" +#include "serialize.h" + static const int64 COIN = 100000000; static const int64 CENT = 1000000; @@ -70,22 +68,6 @@ inline void Sleep(int64 n) } #endif -/* This GNU C extension enables the compiler to check the format string against the parameters provided. - * X is the number of the "format string" parameter, and Y is the number of the first variadic parameter. - * Parameters count from 1. - */ -#ifdef __GNUC__ -#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y))) -#else -#define ATTR_WARN_PRINTF(X,Y) -#endif - - - - - - - extern std::map mapArgs; extern std::map > mapMultiArgs; @@ -111,33 +93,6 @@ extern int64 nPeersOffset; void RandAddSeed(); void RandAddSeedPerfmon(); -int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...); - -/* - Rationale for the real_strprintf / strprintf construction: - It is not allowed to use va_start with a pass-by-reference argument. - (C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a - macro to keep similar semantics. -*/ - -/** Overload strprintf for char*, so that GCC format type warnings can be given */ -std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...); -/** Overload strprintf for std::string, to be able to use it with _ (translation). - * This will not support GCC format type warnings (-Wformat) so be careful. - */ -std::string real_strprintf(const std::string &format, int dummy, ...); -#define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__) -std::string vstrprintf(const char *format, va_list ap); - -bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...); - -/* Redefine printf so that it directs output to debug.log - * - * Do this *after* defining the other printf-like functions, because otherwise the - * __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y))) - * which confuses gcc. - */ -#define printf OutputDebugStringF void LogException(std::exception* pex, const char* pszThread); void PrintException(std::exception* pex, const char* pszThread); @@ -169,9 +124,6 @@ boost::filesystem::path GetConfigFile(); boost::filesystem::path GetPidFile(); void CreatePidFile(const boost::filesystem::path &path, pid_t pid); void ReadConfigFile(std::map& mapSettingsRet, std::map >& mapMultiSettingsRet); -#ifdef WINDOWS -boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); -#endif void ShrinkDebugFile(); int GetRandInt(int nMax); uint64 GetRand(uint64 nMax); @@ -184,21 +136,51 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const void runCommand(std::string strCommand); +/* This GNU C extension enables the compiler to check the format string against the parameters provided. + * X is the number of the "format string" parameter, and Y is the number of the first variadic parameter. + * Parameters count from 1. + */ +#ifdef __GNUC__ +#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y))) +#else +#define ATTR_WARN_PRINTF(X,Y) +#endif +int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char *pszFormat, ...); +/* + Rationale for the real_strprintf / strprintf construction: + It is not allowed to use va_start with a pass-by-reference argument. + (C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a + macro to keep similar semantics. +*/ +/** Overload strprintf for char*, so that GCC format type warnings can be given */ +std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...); +/** Overload strprintf for std::string, to be able to use it with _ (translation). + * This will not support GCC format type warnings (-Wformat) so be careful. + */ +std::string real_strprintf(const std::string &format, int dummy, ...); +#define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__) +std::string vstrprintf(const char *format, va_list ap); +bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...); +/* Redefine printf so that it directs output to debug.log + * + * Do this *after* defining the other printf-like functions, because otherwise the + * __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y))) + * which confuses gcc. + */ +#define printf OutputDebugStringF -inline std::string i64tostr(int64 n) -{ - return strprintf("%" PRI64d, n); +inline std::string i64tostr(int64 n) { + return(strprintf("%" PRI64d "", n)); } -inline std::string itostr(int n) -{ - return strprintf("%d", n); +inline std::string itostr(int n) { + return(strprintf("%d", n)); } inline int64 atoi64(const char* psz) diff --git a/src/version.cpp b/src/version.cpp index d7813ff1..7059f9fb 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include #include "version.h" diff --git a/src/version.h b/src/version.h index ff44011d..0d0c182d 100644 --- a/src/version.h +++ b/src/version.h @@ -5,12 +5,9 @@ #ifndef VERSION_H #define VERSION_H -#include "clientversion.h" #include -// -// client versioning -// +#include "clientversion.h" static const int CLIENT_VERSION = 1000000 * CLIENT_VERSION_MAJOR @@ -22,10 +19,6 @@ extern const std::string CLIENT_NAME; extern const std::string CLIENT_BUILD; extern const std::string CLIENT_DATE; -// -// network protocol versioning -// - static const int PROTOCOL_VERSION = 70000; static const int MAX_PROTOCOL_VERSION = 79999; static const int MIN_PROTOCOL_VERSION = 60004; diff --git a/src/wallet.cpp b/src/wallet.cpp index efa48a09..fa94e33d 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -9,11 +9,9 @@ #include "crypter.h" #include "walletdb.h" #include "wallet.h" -#include "ui_interface.h" using namespace std; - ////////////////////////////////////////////////////////////////////////////// // // mapWallet @@ -401,17 +399,20 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx) BOOST_FOREACH(const CTxIn& txin, tx.vin) { map::iterator mi = mapWallet.find(txin.prevout.hash); - if (mi != mapWallet.end()) - { - CWalletTx& wtx = (*mi).second; - if (txin.prevout.n >= wtx.vout.size()) - printf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString().c_str()); - else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n])) - { - printf("WalletUpdateSpent found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str()); - wtx.MarkSpent(txin.prevout.n); - wtx.WriteToDisk(); - NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); + if(mi != mapWallet.end()) { + CWalletTx &wtx = (*mi).second; + if(txin.prevout.n >= wtx.vout.size()) { + printf("WalletUpdateSpent() : bad wallet tx %s\n", + wtx.GetHash().ToString().c_str()); + } else { + if(!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n])) { + printf("WalletUpdateSpent() : found spent %s PXC %s\n", + FormatMoney(wtx.GetCredit()).c_str(), + wtx.GetHash().ToString().c_str()); + wtx.MarkSpent(txin.prevout.n); + wtx.WriteToDisk(); + NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); + } } } } @@ -871,9 +872,10 @@ void CWallet::ReacceptWalletTransactions() if (txdb.ReadTxIndex(wtx.GetHash(), txindex)) { // Update fSpent if a tx got spent somewhere else by a copy of wallet.dat - if (txindex.vSpent.size() != wtx.vout.size()) - { - printf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %" PRIszu" != wtx.vout.size() %" PRIszu"\n", txindex.vSpent.size(), wtx.vout.size()); + if(txindex.vSpent.size() != wtx.vout.size()) { + printf("ERROR: ReacceptWalletTransactions() : " \ + "txindex.vSpent.size() %" PRIszu " != wtx.vout.size() %" PRIszu "\n", + txindex.vSpent.size(), wtx.vout.size()); continue; } for (unsigned int i = 0; i < txindex.vSpent.size(); i++) @@ -887,9 +889,10 @@ void CWallet::ReacceptWalletTransactions() vMissingTx.push_back(txindex.vSpent[i]); } } - if (fUpdated) - { - printf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str()); + if(fUpdated) { + printf("ReacceptWalletTransactions() : found spent %s PXC %s\n", + FormatMoney(wtx.GetCredit()).c_str(), + wtx.GetHash().ToString().c_str()); wtx.MarkDirty(); wtx.WriteToDisk(); } @@ -1523,7 +1526,8 @@ void CWallet::PrintWallet(const CBlock& block) if (mapWallet.count(block.vtx[0].GetHash())) { CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()]; - printf(" mine: %d %d %" PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit()); + printf(" mine: %d %d %" PRI64d "", wtx.GetDepthInMainChain(), + wtx.GetBlocksToMaturity(), wtx.GetCredit()); } } printf("\n"); @@ -1585,7 +1589,7 @@ bool CWallet::NewKeyPool() walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); setKeyPool.insert(nIndex); } - printf("CWallet::NewKeyPool wrote %" PRI64d" new keys\n", nKeys); + printf("CWallet::NewKeyPool wrote %" PRI64d " new keys\n", nKeys); } return true; } @@ -1610,7 +1614,8 @@ bool CWallet::TopUpKeyPool() if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - printf("keypool added key %" PRI64d", size=%" PRIszu"\n", nEnd, setKeyPool.size()); + printf("keypool added key %" PRI64d ", size=%" PRIszu "\n", + nEnd, setKeyPool.size()); } } return true; @@ -1639,7 +1644,7 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - printf("keypool reserve %" PRI64d"\n", nIndex); + printf("keypool reserve %" PRI64d "\n", nIndex); } } @@ -1666,7 +1671,7 @@ void CWallet::KeepKey(int64 nIndex) CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } - printf("keypool keep %" PRI64d"\n", nIndex); + printf("keypool keep %" PRI64d "\n", nIndex); } void CWallet::ReturnKey(int64 nIndex) @@ -1676,7 +1681,7 @@ void CWallet::ReturnKey(int64 nIndex) LOCK(cs_wallet); setKeyPool.insert(nIndex); } - printf("keypool return %" PRI64d"\n", nIndex); + printf("keypool return %" PRI64d "\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) diff --git a/src/wallet.h b/src/wallet.h index f5511b75..1ceae8c9 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -6,8 +6,6 @@ #ifndef WALLET_H #define WALLET_H -#include - #include #include #include @@ -16,13 +14,15 @@ #include #include -#include "main.h" +#include + +#include "sync.h" #include "key.h" #include "keystore.h" #include "script.h" #include "ui_interface.h" -#include "util.h" #include "walletdb.h" +#include "main.h" class CAccountingEntry; class CWalletTx; diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 6ab9894e..9d0a7aa3 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -3,24 +3,24 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include -#include -#include -#include -#include - #include #include #include +#include +#include +#include +#include +#include +#include + +#include "base58.h" #include "walletdb.h" #include "wallet.h" using namespace std; using namespace boost; - static uint64 nAccountingEntryNumber = 0; // @@ -568,7 +568,7 @@ void ThreadFlushWalletDB(void* parg) bitdb.CheckpointLSN(strFile); bitdb.mapFileUseCount.erase(mi++); - printf("Flushed wallet.dat %" PRI64d"ms\n", GetTimeMillis() - nStart); + printf("Flushed wallet.dat %" PRI64d "ms\n", GetTimeMillis() - nStart); } } } @@ -629,7 +629,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys) // Set -rescan so any missing transactions will be // found. int64 now = GetTime(); - std::string newFilename = strprintf("wallet.%" PRI64d".bak", now); + std::string newFilename = strprintf("wallet.%" PRI64d ".bak", now); int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL, newFilename.c_str(), DB_AUTO_COMMIT); @@ -648,7 +648,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys) printf("Salvage(aggressive) found no records in %s.\n", newFilename.c_str()); return false; } - printf("Salvage(aggressive) found %" PRIszu" records\n", salvagedData.size()); + printf("Salvage(aggressive) found %" PRIszu " records\n", salvagedData.size()); bool fSuccess = allOK; Db* pdbCopy = new Db(&dbenv.dbenv, 0); diff --git a/src/walletdb.h b/src/walletdb.h index a11d76f0..fd9cfe21 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -12,11 +12,11 @@ #include #include "db.h" -#include "base58.h" -class CKeyPool; class CAccount; class CAccountingEntry; +class CKeyPool; +class CWalletTx; /** Error statuses for the wallet database */ enum DBErrors From 78e813166edc32bb0781499fb849984d4859f753 Mon Sep 17 00:00:00 2001 From: John Doering Date: Sun, 14 Nov 2021 03:59:19 +0000 Subject: [PATCH 2/9] CBigNum operator- Fixed Eliminates a bug in commit d4000a2c3b3195f44cf24981305d05c7d1f39f70 --- src/bignum.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bignum.h b/src/bignum.h index 25c37b57..df00cdbe 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -665,9 +665,9 @@ inline const CBigNum operator+(const CBigNum &a, const CBigNum &b) { inline const CBigNum operator-(const CBigNum &a, const CBigNum &b) { CBigNum r; #if (OPENSSL_VERSION_NUMBER < 0x10100000L) - if(!BN_add(&r, &a, &b)) + if(!BN_sub(&r, &a, &b)) #else - if(!BN_add(r.get(), a.cget(), b.cget())) + if(!BN_sub(r.get(), a.cget(), b.cget())) #endif throw(bignum_error("CBigNum::operator- : BN_sub() failed")); return(r); From 59f70043bcef54a11ef7b6ee8cbbed01f00afc39 Mon Sep 17 00:00:00 2001 From: sats0k Date: Thu, 23 Sep 2021 15:40:37 +0300 Subject: [PATCH 3/9] Don't use Double or Float point --- src/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 66fae961..cf76bf35 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -452,7 +452,8 @@ Value getreceivedbyaddress(const Array ¶ms, bool fHelp) { if(!address.IsValid()) throw(JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Phoenixcoin address")); scriptPubKey.SetDestination(address.Get()); - if(!IsMine(*pwalletMain, scriptPubKey)) return((double)0.0); + if(!IsMine(*pwalletMain, scriptPubKey)) + return(ValueFromAmount(0)); /* Minimum confirmations */ int nMinDepth = 1; @@ -473,7 +474,7 @@ Value getreceivedbyaddress(const Array ¶ms, bool fHelp) { nAmount += txout.nValue; } - return ValueFromAmount(nAmount); + return(ValueFromAmount(nAmount)); } From 50b9aa5b305192fe7b59e4057b815ede71c35f95 Mon Sep 17 00:00:00 2001 From: sats0k Date: Thu, 23 Sep 2021 09:53:19 +0300 Subject: [PATCH 4/9] Hurricane Electric IPv6 fix IPv6 uses 2001:470 not 2011:470 --- src/netbase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index f42e7693..8cbb7743 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -898,7 +898,7 @@ std::vector CNetAddr::GetGroup() const nBits = 4; } // for he.net, use /36 groups - else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70) + else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70) nBits = 36; // for the rest of the IPv6 network, use /32 groups else From 779015111400df0c3a7a15118c923826d70a4c2d Mon Sep 17 00:00:00 2001 From: John Doering Date: Tue, 16 Nov 2021 17:07:23 +0000 Subject: [PATCH 5/9] External HTTP IPv4 Finder Rewritten --- src/main.cpp | 4 + src/net.cpp | 222 ++++++++++++++++++++++++++++++--------------------- src/net.h | 5 +- 3 files changed, 137 insertions(+), 94 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 982a4eae..3d8b2b50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2732,6 +2732,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return true; } + /* Record my external IP as reported */ + if(addrFrom.IsRoutable() && addrMe.IsRoutable()) + addrSeenByPeer = addrMe; + // Be shy and don't send version until we hear if (pfrom->fInbound) pfrom->PushVersion(); diff --git a/src/net.cpp b/src/net.cpp index 02919658..c23a2f01 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -62,6 +62,7 @@ static map mapLocalHost; static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; +CAddress addrSeenByPeer(CService("0.0.0.0", 0), nLocalServices); uint64 nLocalHostNonce = 0; boost::array vnThreadsRunning; static std::vector vhListenSocket; @@ -312,128 +313,164 @@ bool IsReachable(const CNetAddr& addr) return vfReachable[net] && !vfLimited[net]; } -bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet) -{ + +bool GetMyExternalIP2(const CService &addrConnect, const char *pszGet, + CService &addrRet) { SOCKET hSocket; - if (!ConnectSocket(addrConnect, hSocket)) - return error("GetMyExternalIP() : connection to %s failed", addrConnect.ToString().c_str()); + bool fChunked = false; + + if(!ConnectSocket(addrConnect, hSocket)) { + printf("GetMyExternalIP() : connection to %s failed", + addrConnect.ToString().c_str()); + return(false); + } send(hSocket, pszGet, strlen(pszGet), MSG_NOSIGNAL); + /* Every line of HTTP datagram is \r\n terminated. + * Starts with headers followed by an empty line separator, + * then by payload with the last line double terminated \r\n\r\n */ + string strLine; - while (RecvLine(hSocket, strLine)) - { - if (strLine.empty()) // HTTP response is separated from headers by blank line - { - while(true) { - if (!RecvLine(hSocket, strLine)) - { - closesocket(hSocket); - return false; - } - if (pszKeyword == NULL) - break; - if (strLine.find(pszKeyword) != string::npos) - { - strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword)); - break; - } - } + + /* Parse the header */ + while(RecvLine(hSocket, strLine)) { + + /* "Transfer-Encoding: chunked" header suggests the line after + * the separator is chunk size with payload in the following line */ + if(strLine.find("chunked") != string::npos) fChunked = true; + + /* The separator */ + if(strLine.empty()) break; + + } + + /* The line after the separator */ + if(!RecvLine(hSocket, strLine)) { + closesocket(hSocket); + return(false); + } + + if(fChunked) { + /* One more line */ + if(!RecvLine(hSocket, strLine)) { closesocket(hSocket); - if (strLine.find("<") != string::npos) - strLine = strLine.substr(0, strLine.find("<")); - strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r")); - while (strLine.size() > 0 && isspace(strLine[strLine.size()-1])) - strLine.resize(strLine.size()-1); - CService addr(strLine,0,true); - printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str()); - if (!addr.IsValid() || !addr.IsRoutable()) - return false; - ipRet.SetIP(addr); - return true; + return(false); } } + closesocket(hSocket); - return error("GetMyExternalIP() : connection closed"); + + /* The line may contain HTML tags, text and special characters + * in addition to the IP address, but hopefully no additional digits; + * although it doesn't make much sense to detect IPv6 this way, + * both IPv4 and public IPv6 addresses start with a numeric character + * and alphabetic characters of IPv6 addresses must be in lowercase + * according to RFC 5952 */ + + /* Remove everything before the IP address */ + strLine = strLine.substr(strcspn(strLine.c_str(), "0123456789")); + + /* Remove everything after the IP address */ + strLine = strLine.substr(0, strspn(strLine.c_str(), "0123456789abcdef.:")); + + printf("GetMyExternalIP() received [%s] from %s\n", + strLine.c_str(), addrConnect.ToString().c_str()); + + CService addr(strLine, 0, true); + + if(!addr.IsValid() || !addr.IsRoutable()) + return(false); + + addrRet = addr; + + return(true); } -// We now get our external IP from the IRC server first and only use this as a backup -bool GetMyExternalIP(CNetAddr& ipRet) -{ - CService addrConnect; - const char* pszGet; - const char* pszKeyword; +/* External HTTP IPv4 finder; + * called if detection through IRC failed or was disabled */ +bool GetMyExternalIP(CNetAddr &ipRet) { + CService addrConnect, addrRet; + const char *pszGet; + bool addrValid = false; + uint i; - for (int nLookup = 0; nLookup <= 1; nLookup++) - for (int nHost = 1; nHost <= 2; nHost++) - { - // We should be phasing out our use of sites like these. If we need - // replacements, we should ask for volunteers to put this simple - // php file on their web server that prints the client IP: - // - if (nHost == 1) - { - addrConnect = CService("91.198.22.70",80); // checkip.dyndns.org + for(i = 0; i < 4; i++) { - if (nLookup == 1) - { - CService addrIP("checkip.dyndns.org", 80, true); - if (addrIP.IsValid()) - addrConnect = addrIP; - } + /* Public IP detectors, plain HTTP; + * something like is enough */ - pszGet = "GET / HTTP/1.1\r\n" - "Host: checkip.dyndns.org\r\n" - "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" - "Connection: close\r\n" - "\r\n"; + switch(i) { - pszKeyword = "Address:"; - } - else if (nHost == 2) - { - addrConnect = CService("74.208.43.192", 80); // www.showmyip.com + case(0): + addrConnect = CService("phoenixcoin.org", 80, true); + pszGet = "GET /ip/index.php HTTP/1.1\r\n" + "Host: phoenixcoin.org\r\n" + "User-Agent: Phoenixcoin\r\n" + "Connection: close\r\n\r\n"; + if(addrConnect.IsValid()) { + addrValid = GetMyExternalIP2(addrConnect, pszGet, addrRet); + } + break; - if (nLookup == 1) - { - CService addrIP("www.showmyip.com", 80, true); - if (addrIP.IsValid()) - addrConnect = addrIP; - } + case(1): + addrConnect = CService("orbitcoin.org", 80, true); + pszGet = "GET /ip/index.php HTTP/1.1\r\n" + "Host: orbitcoin.org\r\n" + "User-Agent: Phoenixcoin\r\n" + "Connection: close\r\n\r\n"; + if(addrConnect.IsValid()) { + addrValid = GetMyExternalIP2(addrConnect, pszGet, addrRet); + } + break; - pszGet = "GET /simple/ HTTP/1.1\r\n" - "Host: www.showmyip.com\r\n" - "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" - "Connection: close\r\n" - "\r\n"; + case(2): + addrConnect = CService("ifconfig.me", 80, true); + pszGet = "GET /ip HTTP/1.1\r\n" + "Host: ifconfig.me\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" + "Connection: close\r\n\r\n"; + if(addrConnect.IsValid()) { + addrValid = GetMyExternalIP2(addrConnect, pszGet, addrRet); + } + break; + + case(3): + addrConnect = CService("checkip.dyndns.org", 80, true); + pszGet = "GET / HTTP/1.1\r\n" + "Host: checkip.dyndns.org\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" + "Connection: close\r\n\r\n"; + if(addrConnect.IsValid()) { + addrValid = GetMyExternalIP2(addrConnect, pszGet, addrRet); + } + break; + + } - pszKeyword = NULL; // Returns just IP address + if(addrValid) { + addrSeenByPeer = CAddress(addrRet, 0); + ipRet.SetIP(addrRet); + return(true); } - if (GetMyExternalIP2(addrConnect, pszGet, pszKeyword, ipRet)) - return true; } - return false; + return(false); } -void ThreadGetMyExternalIP(void* parg) -{ - // Make this thread recognisable as the external IP detection thread +void ThreadGetMyExternalIP(void *parg) { + RenameThread("pxc-ext-ip"); CNetAddr addrLocalHost; - if (GetMyExternalIP(addrLocalHost)) - { + if(GetMyExternalIP(addrLocalHost)) { printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str()); AddLocal(addrLocalHost, LOCAL_HTTP); } } - - - void AddressCurrentlyConnected(const CService& addr) { addrman.Connected(addr); @@ -1909,9 +1946,10 @@ static void Discover() } #endif - // Don't use external IPv4 discovery, when -onlynet="IPv6" - if (!IsLimited(NET_IPV4)) - NewThread(ThreadGetMyExternalIP, NULL); + /* External HTTP service to report our IPv4 address; + * no need to call if operating in IPv6 only mode */ + if(!IsLimited(NET_IPV4)) + NewThread(ThreadGetMyExternalIP, NULL); } void StartNode(void* parg) diff --git a/src/net.h b/src/net.h index 61e9df04..6750452d 100644 --- a/src/net.h +++ b/src/net.h @@ -39,7 +39,7 @@ inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*10 void AddOneShot(std::string strDest); bool RecvLine(SOCKET hSocket, std::string& strLine); -bool GetMyExternalIP(CNetAddr& ipRet); +bool GetMyExternalIP(CNetAddr &ipRet); void AddressCurrentlyConnected(const CService& addr); CNode* FindNode(const CNetAddr& ip); CNode* FindNode(const CService& ip); @@ -57,7 +57,7 @@ enum LOCAL_BIND, // address explicit bound to LOCAL_UPNP, // address reported by UPnP LOCAL_IRC, // address reported by IRC (deprecated) - LOCAL_HTTP, // address reported by whatismyip.com and similar + LOCAL_HTTP, /* address reported by external HTTP service */ LOCAL_MANUAL, // address explicitly specified (-externalip=) LOCAL_MAX @@ -124,6 +124,7 @@ extern bool fDiscover; extern bool fUseUPnP; extern uint64 nLocalServices; extern uint64 nLocalHostNonce; +extern CAddress addrSeenByPeer; extern boost::array vnThreadsRunning; extern CAddrMan addrman; From 8c5db5616768481051e9502cb4c617ece20a1756 Mon Sep 17 00:00:00 2001 From: John Doering Date: Tue, 7 Dec 2021 07:54:23 +0000 Subject: [PATCH 6/9] Qt GUI: Command Line Options Button Relocated --- src/qt/forms/rpcconsole.ui | 71 +++++++++++++++++++++++------- src/qt/guiutil.cpp | 2 +- src/qt/guiutil.h | 2 +- src/qt/locale/phoenixcoin_de.ts | 6 +-- src/qt/locale/phoenixcoin_en.ts | 12 ++--- src/qt/locale/phoenixcoin_es.ts | 6 +-- src/qt/locale/phoenixcoin_fr.ts | 6 +-- src/qt/locale/phoenixcoin_it.ts | 6 +-- src/qt/locale/phoenixcoin_pl.ts | 6 +-- src/qt/locale/phoenixcoin_ru.ts | 6 +-- src/qt/locale/phoenixcoin_uk.ts | 6 +-- src/qt/locale/phoenixcoin_zh_CN.ts | 6 +-- src/qt/optionsmodel.cpp | 4 +- src/qt/phoenixcoin.cpp | 4 +- 14 files changed, 90 insertions(+), 53 deletions(-) diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui index 4aa2de4f..a9b3ae06 100644 --- a/src/qt/forms/rpcconsole.ui +++ b/src/qt/forms/rpcconsole.ui @@ -23,7 +23,7 @@ &Information - + 12 @@ -319,8 +319,33 @@ + + + + + 75 + true + + + + Command line options + + + + + + 160 + 48 + + + + + 160 + 48 + + Open the Phoenixcoin debug log file from the current data directory. This can take a few seconds for large log files. @@ -332,23 +357,22 @@ - - - - - 75 - true - + + + + + 160 + 48 + - - Command-line options + + + 160 + 48 + - - - - - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. &Show @@ -358,7 +382,7 @@ - + Qt::Vertical @@ -366,7 +390,20 @@ 20 - 40 + 20 + + + + + + + + Qt::Horizontal + + + + 20 + 20 diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index dff763f7..0bde8e8e 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -425,7 +425,7 @@ HelpMessageBox::HelpMessageBox(QWidget *parent) : header = tr("Phoenixcoin-Qt") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()) + "\n\n" + tr("Usage:") + "\n" + - " phoenixcoin-qt [" + tr("command-line options") + "] " + "\n"; + " phoenixcoin-qt [" + tr("command line options") + "] " + "\n"; coreOptions = QString::fromStdString(HelpMessage()); diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index fca544ee..b64daf2b 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -96,7 +96,7 @@ namespace GUIUtil { bool GetStartOnSystemStartup(); bool SetStartOnSystemStartup(bool fAutoStart); - /* Help message for Phoenixcoin-Qt, shown with --help */ + /* Help message for the Qt GUI shown with --help */ class HelpMessageBox : public QMessageBox { Q_OBJECT diff --git a/src/qt/locale/phoenixcoin_de.ts b/src/qt/locale/phoenixcoin_de.ts index ed9a1a80..39eda5b6 100644 --- a/src/qt/locale/phoenixcoin_de.ts +++ b/src/qt/locale/phoenixcoin_de.ts @@ -749,7 +749,7 @@ Adresse: %4 - command-line options + Command line options Kommandozeilenoptionen @@ -1179,12 +1179,12 @@ Adresse: %4 - Command-line options + Command line options Kommandozeilenoptionen - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. Zeige die Phoenixcoin-Qt Hilfsnachricht, um eine Liste mit möglichen Kommandozeilenoptionen zu erhalten. diff --git a/src/qt/locale/phoenixcoin_en.ts b/src/qt/locale/phoenixcoin_en.ts index b65cd99c..a194f574 100644 --- a/src/qt/locale/phoenixcoin_en.ts +++ b/src/qt/locale/phoenixcoin_en.ts @@ -755,8 +755,8 @@ Address: %4 - command-line options - command-line options + command line options + command line options @@ -1185,13 +1185,13 @@ Address: %4 - Command-line options - Command-line options + Command line options + Command line options - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. diff --git a/src/qt/locale/phoenixcoin_es.ts b/src/qt/locale/phoenixcoin_es.ts index f376a861..94244089 100644 --- a/src/qt/locale/phoenixcoin_es.ts +++ b/src/qt/locale/phoenixcoin_es.ts @@ -753,7 +753,7 @@ Dirección: %4 - command-line options + command line options opciones de la línea de órdenes @@ -1183,12 +1183,12 @@ Dirección: %4 - Command-line options + Command line options Opciones de la línea de órdenes - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. Mostrar el mensaje de ayuda de Phoenixcoin-Qt que enumera las opciones disponibles de línea de órdenes para Phoenixcoin. diff --git a/src/qt/locale/phoenixcoin_fr.ts b/src/qt/locale/phoenixcoin_fr.ts index 0739a969..a65a37a8 100644 --- a/src/qt/locale/phoenixcoin_fr.ts +++ b/src/qt/locale/phoenixcoin_fr.ts @@ -750,7 +750,7 @@ Adresse : %4 - command-line options + command line options options de ligne de commande @@ -1180,12 +1180,12 @@ Adresse : %4 - Command-line options + Command line options Options de ligne de commande - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. Afficher le message d'aide de Phoenixcoin-Qt pour obtenir la liste des options de ligne de commande disponibles pour Phoenixcoin. diff --git a/src/qt/locale/phoenixcoin_it.ts b/src/qt/locale/phoenixcoin_it.ts index 38fbcb63..eef48a0c 100644 --- a/src/qt/locale/phoenixcoin_it.ts +++ b/src/qt/locale/phoenixcoin_it.ts @@ -751,7 +751,7 @@ Indirizzo: %4 - command-line options + command line options opzioni riga di comando @@ -1182,12 +1182,12 @@ Indirizzo: %4 - Command-line options + Command line options opzioni riga di comando - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. diff --git a/src/qt/locale/phoenixcoin_pl.ts b/src/qt/locale/phoenixcoin_pl.ts index 5bcd5121..eef4158d 100644 --- a/src/qt/locale/phoenixcoin_pl.ts +++ b/src/qt/locale/phoenixcoin_pl.ts @@ -756,7 +756,7 @@ Adres: %4 - command-line options + command line options opcje konsoli @@ -1186,12 +1186,12 @@ Adres: %4 - Command-line options + Command line options Opcje konsoli - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. Pokaż pomoc Phoenixcoin-Qt, aby zobaczyć listę wszystkich opcji linii poleceń diff --git a/src/qt/locale/phoenixcoin_ru.ts b/src/qt/locale/phoenixcoin_ru.ts index 5f2a9c07..a3e81cc8 100644 --- a/src/qt/locale/phoenixcoin_ru.ts +++ b/src/qt/locale/phoenixcoin_ru.ts @@ -756,7 +756,7 @@ Address: %4 - command-line options + command line options параметры командной строки @@ -1186,12 +1186,12 @@ Address: %4 - Command-line options + Command line options Параметры командной строки - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. Показать помощь по Phoenixcoin-Qt, чтобы получить список доступных параметров командной строки. diff --git a/src/qt/locale/phoenixcoin_uk.ts b/src/qt/locale/phoenixcoin_uk.ts index 25b190c8..3c67388f 100644 --- a/src/qt/locale/phoenixcoin_uk.ts +++ b/src/qt/locale/phoenixcoin_uk.ts @@ -756,7 +756,7 @@ Address: %4 - command-line options + command line options @@ -1187,12 +1187,12 @@ Address: %4 - Command-line options + Command line options - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. diff --git a/src/qt/locale/phoenixcoin_zh_CN.ts b/src/qt/locale/phoenixcoin_zh_CN.ts index bc81218b..87e4b356 100644 --- a/src/qt/locale/phoenixcoin_zh_CN.ts +++ b/src/qt/locale/phoenixcoin_zh_CN.ts @@ -744,7 +744,7 @@ Address: %4 - command-line options + command line options 命令行选项 @@ -1175,12 +1175,12 @@ Address: %4 - Command-line options + Command line options 命令行选项 - Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command-line options. + Show the Phoenixcoin-Qt help message to get a list with possible Phoenixcoin command line options. 显示Phoenixcoin命令行选项帮助信息 diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 4642bc9e..8722dedc 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -52,8 +52,8 @@ void OptionsModel::Init() language = settings.value("language", "").toString(); fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool(); - /* These are shared with the Phoenixcoin core; we want - * command-line options to override the GUI settings */ + /* These are shared with the wallet core; we want + * command line options to override the GUI settings */ if (settings.contains("fUseUPnP")) SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()); if (settings.contains("addrProxy") && settings.value("fUseProxy").toBool()) diff --git a/src/qt/phoenixcoin.cpp b/src/qt/phoenixcoin.cpp index 2237b9d4..04c78c23 100644 --- a/src/qt/phoenixcoin.cpp +++ b/src/qt/phoenixcoin.cpp @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) // Install global event filter that makes sure that long tooltips can be word-wrapped app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app)); - // Command-line options take precedence: + // Command line options take precedence: ParseParameters(argc, argv); // ... then phoenixcoin.conf: @@ -198,7 +198,7 @@ int main(int argc, char *argv[]) uiInterface.QueueShutdown.connect(QueueShutdown); uiInterface.Translate.connect(Translate); - // Show help message immediately after parsing command-line options (for "-lang") and setting locale, + // Show help message immediately after parsing command line options (for "-lang") and setting locale, // but before showing splash screen. if (mapArgs.count("-?") || mapArgs.count("--help")) { From 8cd3d7179cc05bba988616aaac3de7940228b9ff Mon Sep 17 00:00:00 2001 From: John Doering Date: Tue, 7 Dec 2021 09:41:58 +0000 Subject: [PATCH 7/9] Qt GUI: Display Versions of BerkeleyDB and Boost --- src/init.cpp | 4 +- src/qt/forms/rpcconsole.ui | 91 ++++++++++++++++++++---------- src/qt/locale/phoenixcoin_de.ts | 9 +-- src/qt/locale/phoenixcoin_en.ts | 9 +-- src/qt/locale/phoenixcoin_es.ts | 9 +-- src/qt/locale/phoenixcoin_fr.ts | 9 +-- src/qt/locale/phoenixcoin_it.ts | 9 +-- src/qt/locale/phoenixcoin_pl.ts | 9 +-- src/qt/locale/phoenixcoin_ru.ts | 9 +-- src/qt/locale/phoenixcoin_uk.ts | 9 +-- src/qt/locale/phoenixcoin_zh_CN.ts | 9 +-- src/qt/rpcconsole.cpp | 19 +++++-- 12 files changed, 95 insertions(+), 100 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 06c93f47..a68414fd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -505,11 +505,11 @@ bool AppInit2() if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); - printf("Phoenixcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str()); + printf("Phoenixcoin %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str()); printf("Using OpenSSL release: %s\n", SSLeay_version(SSLEAY_VERSION)); printf("Using BerkeleyDB release: %s\n", DbEnv::version(0, 0, 0)); printf("Using Boost v%d.%d.%d\n", - BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100); + BOOST_VERSION / 100000, (BOOST_VERSION / 100) % 1000, BOOST_VERSION % 100); #ifdef USE_UPNP printf("Using miniUPnP Client v%s API v%d\n", MINIUPNPC_VERSION, MINIUPNPC_API_VERSION); #endif diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui index a9b3ae06..f3a8347d 100644 --- a/src/qt/forms/rpcconsole.ui +++ b/src/qt/forms/rpcconsole.ui @@ -41,14 +41,14 @@ - + - Client name + Client version - + IBeamCursor @@ -64,14 +64,17 @@ - + - Client version + using + + + 10 - + IBeamCursor @@ -87,9 +90,9 @@ - + - Using OpenSSL version + using 10 @@ -97,7 +100,7 @@ - + IBeamCursor @@ -113,13 +116,39 @@ + + + using + + + 10 + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + Build date - + IBeamCursor @@ -135,14 +164,14 @@ - + Startup time - + IBeamCursor @@ -158,7 +187,7 @@ - + @@ -171,14 +200,14 @@ - + Number of connections - + IBeamCursor @@ -194,14 +223,14 @@ - + On testnet - + false @@ -211,7 +240,7 @@ - + @@ -224,14 +253,14 @@ - + Current number of blocks - + IBeamCursor @@ -247,14 +276,14 @@ - + Estimated total blocks - + IBeamCursor @@ -270,14 +299,14 @@ - + Last block time - + IBeamCursor @@ -293,7 +322,7 @@ - + Qt::Vertical @@ -306,7 +335,7 @@ - + @@ -319,7 +348,7 @@ - + @@ -332,7 +361,7 @@ - + @@ -357,7 +386,7 @@ - + @@ -382,7 +411,7 @@ - + Qt::Vertical @@ -395,7 +424,7 @@ - + Qt::Horizontal diff --git a/src/qt/locale/phoenixcoin_de.ts b/src/qt/locale/phoenixcoin_de.ts index 39eda5b6..6964d61d 100644 --- a/src/qt/locale/phoenixcoin_de.ts +++ b/src/qt/locale/phoenixcoin_de.ts @@ -1098,11 +1098,6 @@ Adresse: %4 RPCConsole - - - Client name - Client Name - @@ -1129,8 +1124,8 @@ Adresse: %4 - Using OpenSSL version - Verwendete OpenSSL Version + using + mit Hilfe von diff --git a/src/qt/locale/phoenixcoin_en.ts b/src/qt/locale/phoenixcoin_en.ts index a194f574..f62a3931 100644 --- a/src/qt/locale/phoenixcoin_en.ts +++ b/src/qt/locale/phoenixcoin_en.ts @@ -1104,11 +1104,6 @@ Address: %4 RPCConsole - - - Client name - Client name - @@ -1135,8 +1130,8 @@ Address: %4 - Using OpenSSL version - Using OpenSSL version + using + using diff --git a/src/qt/locale/phoenixcoin_es.ts b/src/qt/locale/phoenixcoin_es.ts index 94244089..3acd2a61 100644 --- a/src/qt/locale/phoenixcoin_es.ts +++ b/src/qt/locale/phoenixcoin_es.ts @@ -1102,11 +1102,6 @@ Dirección: %4 RPCConsole - - - Client name - Nombre del cliente - @@ -1133,8 +1128,8 @@ Dirección: %4 - Using OpenSSL version - Utilizando la versión OpenSSL + using + con la ayuda de diff --git a/src/qt/locale/phoenixcoin_fr.ts b/src/qt/locale/phoenixcoin_fr.ts index a65a37a8..df6da43b 100644 --- a/src/qt/locale/phoenixcoin_fr.ts +++ b/src/qt/locale/phoenixcoin_fr.ts @@ -1099,11 +1099,6 @@ Adresse : %4 RPCConsole - - - Client name - Nom du client - @@ -1130,8 +1125,8 @@ Adresse : %4 - Using OpenSSL version - Version d'OpenSSL utilisée + using + avec l'aide de diff --git a/src/qt/locale/phoenixcoin_it.ts b/src/qt/locale/phoenixcoin_it.ts index eef48a0c..62971f31 100644 --- a/src/qt/locale/phoenixcoin_it.ts +++ b/src/qt/locale/phoenixcoin_it.ts @@ -1101,11 +1101,6 @@ Indirizzo: %4 RPCConsole - - - Client name - - @@ -1132,8 +1127,8 @@ Indirizzo: %4 - Using OpenSSL version - + using + con l'aiuto di diff --git a/src/qt/locale/phoenixcoin_pl.ts b/src/qt/locale/phoenixcoin_pl.ts index eef4158d..96b476c8 100644 --- a/src/qt/locale/phoenixcoin_pl.ts +++ b/src/qt/locale/phoenixcoin_pl.ts @@ -1105,11 +1105,6 @@ Adres: %4 RPCConsole - - - Client name - Nazwa klienta - @@ -1136,8 +1131,8 @@ Adres: %4 - Using OpenSSL version - Używana wersja OpenSSL + using + za pomocą diff --git a/src/qt/locale/phoenixcoin_ru.ts b/src/qt/locale/phoenixcoin_ru.ts index a3e81cc8..001ab5a8 100644 --- a/src/qt/locale/phoenixcoin_ru.ts +++ b/src/qt/locale/phoenixcoin_ru.ts @@ -1105,11 +1105,6 @@ Address: %4 RPCConsole - - - Client name - Имя клиента - @@ -1136,8 +1131,8 @@ Address: %4 - Using OpenSSL version - Используется версия OpenSSL + using + с использованием diff --git a/src/qt/locale/phoenixcoin_uk.ts b/src/qt/locale/phoenixcoin_uk.ts index 3c67388f..17b34eb3 100644 --- a/src/qt/locale/phoenixcoin_uk.ts +++ b/src/qt/locale/phoenixcoin_uk.ts @@ -1106,11 +1106,6 @@ Address: %4 RPCConsole - - - Client name - - @@ -1137,8 +1132,8 @@ Address: %4 - Using OpenSSL version - + using + з використанням diff --git a/src/qt/locale/phoenixcoin_zh_CN.ts b/src/qt/locale/phoenixcoin_zh_CN.ts index 87e4b356..5a78a50b 100644 --- a/src/qt/locale/phoenixcoin_zh_CN.ts +++ b/src/qt/locale/phoenixcoin_zh_CN.ts @@ -1094,11 +1094,6 @@ Address: %4 RPCConsole - - - Client name - 客户端名称 - @@ -1125,8 +1120,8 @@ Address: %4 - Using OpenSSL version - 使用OpenSSL版本 + using + 借助 diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index be8a103f..4fedbaba 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -7,7 +7,10 @@ #include #endif -#include +#include /* for SSLEAY_VERSION */ +#include /* for BOOST_VERSION */ + +#include "db.h" /* for DbEnv::version() */ #ifndef Q_MOC_RUN #include "rpcmain.h" @@ -211,8 +214,17 @@ RPCConsole::RPCConsole(QWidget *parent) : connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); - // set OpenSSL version label - ui->openSSLVersion->setText(SSLeay_version(SSLEAY_VERSION)); + /* Display OpenSSL version and release date */ + ui->versionOpenSSL->setText(SSLeay_version(SSLEAY_VERSION)); + + /* Display BerkeleyDB version and release date */ + ui->versionBDB->setText(DbEnv::version(0, 0, 0)); + + /* Display Boost version */ + char chVersionBoost[64]; + sprintf(chVersionBoost, "Boost v%d.%d.%d", + BOOST_VERSION / 100000, (BOOST_VERSION / 100) % 1000, BOOST_VERSION % 100); + ui->versionBoost->setText(chVersionBoost); startExecutor(); @@ -278,7 +290,6 @@ void RPCConsole::setClientModel(ClientModel *model) // Provide initial values ui->clientVersion->setText(model->formatFullVersion()); - ui->clientName->setText(model->clientName()); ui->buildDate->setText(model->formatBuildDate()); ui->startupTime->setText(model->formatClientStartupTime()); From 67734dcb728d3f454a1f4eb45768c935a5c63836 Mon Sep 17 00:00:00 2001 From: John Doering Date: Fri, 17 Dec 2021 14:05:42 +0000 Subject: [PATCH 8/9] Hardcoded IP Seeds Removed --- src/net.cpp | 113 ---------------------------------------------------- 1 file changed, 113 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c23a2f01..11e5c622 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1208,7 +1208,6 @@ void MapPort() static const char *strDNSSeed[][2] = { {"pxcseed0", "seed0.phoenixcoin.org"}, {"pxcseed1", "seed1.phoenixcoin.org"}, - {"pxcseed2", "seed2.phoenixcoin.org"}, }; void ThreadDNSAddressSeed(void* parg) @@ -1267,97 +1266,6 @@ void ThreadDNSAddressSeed2(void* parg) } - - - - - - - - - - -unsigned int pnSeed[] = -{ - 0x959bd347, 0xf8de42b2, 0x73bc0518, 0xea6edc50, 0x21b00a4d, 0xc725b43d, 0xd665464d, 0x1a2a770e, - 0x27c93946, 0x65b2fa46, 0xb80ae255, 0x66b3b446, 0xb1877a3e, 0x6ee89e3e, 0xc3175b40, 0x2a01a83c, - 0x95b1363a, 0xa079ad3d, 0xe6ca801f, 0x027f4f4a, 0x34f7f03a, 0xf790f04a, 0x16ca801f, 0x2f4d5e40, - 0x3a4d5e40, 0xc43a322e, 0xc8159753, 0x14d4724c, 0x7919a118, 0xe0bdb34e, 0x68a16b2e, 0xff64b44d, - 0x6099115b, 0x9b57b05b, 0x7bd1b4ad, 0xdf95944f, 0x29d2b73d, 0xafa8db79, 0xe247ba41, 0x24078348, - 0xf722f03c, 0x33567ebc, 0xace64ed4, 0x984d3932, 0xb5f34e55, 0x27b7024d, 0x94579247, 0x8894042e, - 0x9357d34c, 0x1063c24b, 0xcaa228b1, 0xa3c5a8b2, 0x5dc64857, 0xa2c23643, 0xa8369a54, 0x31203077, - 0x00707c5c, 0x09fc0b3a, 0x272e9e2e, 0xf80f043e, 0x9449ca3e, 0x5512c33e, 0xd106b555, 0xe8024157, - 0xe288ec29, 0xc79c5461, 0xafb63932, 0xdb02ab4b, 0x0e512777, 0x8a145a4c, 0xb201ff4f, 0x5e09314b, - 0xcd9bfbcd, 0x1c023765, 0x4394e75c, 0xa728bd4d, 0x65331552, 0xa98420b1, 0x89ecf559, 0x6e80801f, - 0xf404f118, 0xefd62b51, 0x05918346, 0x9b186d5f, 0xacabab46, 0xf912e255, 0xc188ea62, 0xcc55734e, - 0xc668064d, 0xd77a4558, 0x46201c55, 0xf17dfc80, 0xf7142f2e, 0x87bfb718, 0x8aa54fb2, 0xc451d518, - 0xc4ae8831, 0x8dd44d55, 0x5bbd206c, 0x64536b5d, 0x5c667e60, 0x3b064242, 0xfe963a42, 0xa28e6dc8, - 0xe8a9604a, 0xc989464e, 0xd124a659, 0x50065140, 0xa44dfe5e, 0x1079e655, 0x3fb986d5, 0x47895b18, - 0x7d3ce4ad, 0x4561ba50, 0x296eec62, 0x255b41ad, 0xaed35ec9, 0x55556f12, 0xc7d3154d, 0x3297b65d, - 0x8930121f, 0xabf42e4e, 0x4a29e044, 0x1212685d, 0x676c1e40, 0xce009744, 0x383a8948, 0xa2dbd0ad, - 0xecc2564d, 0x07dbc252, 0x887ee24b, 0x5171644c, 0x6bb798c1, 0x847f495d, 0x4cbb7145, 0x3bb81c32, - 0x45eb262e, 0xc8015a4e, 0x250a361b, 0xf694f946, 0xd64a183e, 0xd4f1dd59, 0x8f20ffd4, 0x51d9e55c, - 0x09521763, 0x5e02002e, 0x32c8074d, 0xe685762e, 0x8290b0bc, 0x762a922e, 0xfc5ee754, 0x83a24829, - 0x775b224d, 0x6295bb4d, 0x38ec0555, 0xbffbba50, 0xe5560260, 0x86b16a7c, 0xd372234e, 0x49a3c24b, - 0x2f6a171f, 0x4d75ed60, 0xae94115b, 0xcb543744, 0x63080c59, 0x3f9c724c, 0xc977ce18, 0x532efb18, - 0x69dc3b2e, 0x5f94d929, 0x1732bb4d, 0x9c814b4d, 0xe6b3762e, 0xc024f662, 0x8face35b, 0x6b5b044d, - 0x798c7b57, 0x79a6b44c, 0x067d3057, 0xf9e94e5f, 0x91cbe15b, 0x71405eb2, 0x2662234e, 0xcbcc4a6d, - 0xbf69d54b, 0xa79b4e55, 0xec6d3e51, 0x7c0b3c02, 0x60f83653, 0x24c1e15c, 0x1110b62e, 0x10350f59, - 0xa56f1d55, 0x3509e7a9, 0xeb128354, 0x14268e2e, 0x934e28bc, 0x8e32692e, 0x8331a21f, 0x3e633932, - 0xc812b12e, 0xc684bf2e, 0x80112d2e, 0xe0ddc96c, 0xc630ca4a, 0x5c09b3b2, 0x0b580518, 0xc8e9d54b, - 0xd169aa43, 0x17d0d655, 0x1d029963, 0x7ff87559, 0xcb701f1f, 0x6fa3e85d, 0xe45e9a54, 0xf05d1802, - 0x44d03b2e, 0x837b692e, 0xccd4354e, 0x3d6da13c, 0x3423084d, 0xf707c34a, 0x55f6db3a, 0xad26e442, - 0x6233a21f, 0x09e80e59, 0x8caeb54d, 0xbe870941, 0xb407d20e, 0x20b51018, 0x56fb152e, 0x460d2a4e, - 0xbb9a2946, 0x560eb12e, 0xed83dd29, 0xd6724f53, 0xa50aafb8, 0x451346d9, 0x88348e2e, 0x7312fead, - 0x8ecaf96f, 0x1bda4e5f, 0xf1671e40, 0x3c8c3e3b, 0x4716324d, 0xdde24ede, 0xf98cd17d, 0xa91d4644, - 0x28124eb2, 0x147d5129, 0xd022042e, 0x61733d3b, 0xad0d5e02, 0x8ce2932e, 0xe5c18502, 0x549c1e32, - 0x9685801f, 0x86e217ad, 0xd948214b, 0x4110f462, 0x3a2e894e, 0xbd35492e, 0x87e0d558, 0x64b8ef7d, - 0x7c3eb962, 0x72a84b3e, 0x7cd667c9, 0x28370a2e, 0x4bc60e7b, 0x6fc1ec60, 0x14a6983f, 0x86739a4b, - 0x46954e5f, 0x32e2e15c, 0x2e9326cf, 0xe5801c5e, 0x379607b2, 0x32151145, 0xf0e39744, 0xacb54c55, - 0xa37dfb60, 0x83b55cc9, 0x388f7ca5, 0x15034f5f, 0x3e94965b, 0x68e0ffad, 0x35280f59, 0x8fe190cf, - 0x7c6ba5b2, 0xa5e9db43, 0x4ee1fc60, 0xd9d94e5f, 0x04040677, 0x0ea9b35e, 0x5961f14f, 0x67fda063, - 0xa48a5a31, 0xc6524e55, 0x283d325e, 0x3f37515f, 0x96b94b3e, 0xacce620e, 0x6481cc5b, 0xa4a06d4b, - 0x9e95d2d9, 0xe40c03d5, 0xc2f4514b, 0xb79aad44, 0xf64be843, 0xb2064070, 0xfca00455, 0x429dfa4e, - 0x2323f173, 0xeda4185e, 0xabd5227d, 0x9efd4d58, 0xb1104758, 0x4811e955, 0xbd9ab355, 0xe921f44b, - 0x9f166dce, 0x09e279b2, 0xe0c9ac7b, 0x7901a5ad, 0xa145d4b0, 0x79104671, 0xec31e35a, 0x4fe0b555, - 0xc7d9cbad, 0xad057f55, 0xe94cc759, 0x7fe0b043, 0xe4529f2e, 0x0d4dd4b2, 0x9f11a54d, 0x031e2e4e, - 0xe6014f5f, 0x11d1ca6c, 0x26bd7f61, 0xeb86854f, 0x4d347b57, 0x116bbe2e, 0xdba7234e, 0x7bcbfd2e, - 0x174dd4b2, 0x6686762e, 0xb089ba50, 0xc6258246, 0x087e767b, 0xc4a8cb4a, 0x595dba50, 0x7f0ae502, - 0x7b1dbd5a, 0xa0603492, 0x57d1af4b, 0x9e21ffd4, 0x6393064d, 0x7407376e, 0xe484762e, 0x122a4e53, - 0x4a37aa43, 0x3888a6be, 0xee77864e, 0x039c8dd5, 0x688d89af, 0x0e988f62, 0x08218246, 0xfc2f8246, - 0xd1d97040, 0xd64cd4b2, 0x5ae4a6b8, 0x7d0de9bc, 0x8d304d61, 0x06c5c672, 0xa4c8bd4d, 0xe0fd373b, - 0x575ebe4d, 0x72d26277, 0x55570f55, 0x77b154d9, 0xe214293a, 0xfc740f4b, 0xfe3f6a57, 0xa9c55f02, - 0xae4054db, 0x2394d918, 0xb511b24a, 0xb8741ab2, 0x0758e65e, 0xc7b5795b, 0xb0a30a4c, 0xaf7f170c, - 0xf3b4762e, 0x8179576d, 0x738a1581, 0x4b95b64c, 0x9829b618, 0x1bea932e, 0x7bdeaa4b, 0xcb5e0281, - 0x65618f54, 0x0658474b, 0x27066acf, 0x40556d65, 0x7d204d53, 0xf28bc244, 0xdce23455, 0xadc0ff54, - 0x3863c948, 0xcee34e5f, 0xdeb85e02, 0x2ed17a61, 0x6a7b094d, 0x7f0cfc40, 0x59603f54, 0x3220afbc, - 0xb5dfd962, 0x125d21c0, 0x13f8d243, 0xacfefb4e, 0x86c2c147, 0x3d8bbd59, 0xbd02a21f, 0x2593042e, - 0xc6a17a7c, 0x28925861, 0xb487ed44, 0xb5f4fd6d, 0x90c28a45, 0x5a14f74d, 0x43d71b4c, 0x728ebb5d, - 0x885bf950, 0x08134dd0, 0x38ec046e, 0xc575684b, 0x50082d2e, 0xa2f47757, 0x270f86ae, 0xf3ff6462, - 0x10ed3f4e, 0x4b58d462, 0xe01ce23e, 0x8c5b092e, 0x63e52f4e, 0x22c1e85d, 0xa908f54e, 0x8591624f, - 0x2c0fb94e, 0xa280ba3c, 0xb6f41b4c, 0x24f9aa47, 0x27201647, 0x3a3ea6dc, 0xa14fc3be, 0x3c34bdd5, - 0x5b8d4f5b, 0xaadeaf4b, 0xc71cab50, 0x15697a4c, 0x9a1a734c, 0x2a037d81, 0x2590bd59, 0x48ec2741, - 0x53489c5b, 0x7f00314b, 0x2170d362, 0xf2e92542, 0x42c10b44, 0x98f0f118, 0x883a3456, 0x099a932e, - 0xea38f7bc, 0x644e9247, 0xbb61b62e, 0x30e0863d, 0x5f51be54, 0x207215c7, 0x5f306c45, 0xaa7f3932, - 0x98da7d45, 0x4e339b59, 0x2e411581, 0xa808f618, 0xad2c0c59, 0x54476741, 0x09e99fd1, 0x5db8f752, - 0xc16df8bd, 0x1dd4b44f, 0x106edf2e, 0x9e15c180, 0x2ad6b56f, 0x633a5332, 0xff33787c, 0x077cb545, - 0x6610be6d, 0x75aad2c4, 0x72fb4d5b, 0xe81e0f59, 0x576f6332, 0x47333373, 0x351ed783, 0x2d90fb50, - 0x8d5e0f6c, 0x5b27a552, 0xdb293ebb, 0xe55ef950, 0x4b133ad8, 0x75df975a, 0x7b6a8740, 0xa899464b, - 0xfab15161, 0x10f8b64d, 0xd055ea4d, 0xee8e146b, 0x4b14afb8, 0x4bc1c44a, 0x9b961dcc, 0xd111ff43, - 0xfca0b745, 0xc800e412, 0x0afad9d1, 0xf751c350, 0xf9f0cccf, 0xa290a545, 0x8ef13763, 0x7ec70d59, - 0x2b066acf, 0x65496c45, 0xade02c1b, 0xae6eb077, 0x92c1e65b, 0xc064e6a9, 0xc649e56d, 0x5287a243, - 0x36de4f5b, 0x5b1df6ad, 0x65c39a59, 0xdba805b2, 0x20067aa8, 0x6457e56d, 0x3cee26cf, 0xfd3ff26d, - 0x04f86d4a, 0x06b8e048, 0xa93bcd5c, 0x91135852, 0xbe90a643, 0x8fa0094d, 0x06d8215f, 0x2677094d, - 0xd735685c, 0x164a00c9, 0x5209ac5f, 0xa9564c5c, 0x3b504f5f, 0xcc826bd0, 0x4615042e, 0x5fe13b4a, - 0x8c81b86d, 0x879ab68c, 0x1de564b8, 0x434487d8, 0x2dcb1b63, 0x82ab524a, 0xb0676abb, 0xa13d9c62, - 0xdbb5b86d, 0x5b7f4b59, 0xaddfb44d, 0xad773532, 0x3997054c, 0x72cebd89, 0xb194544c, 0xc5b8046e, - 0x6e1adeb2, 0xaa5abb51, 0xefb54b44, 0x15efc54f, 0xe9f1bc4d, 0x5f401b6c, 0x97f018ad, 0xc82f9252, - 0x2cdc762e, 0x8e52e56d, 0x1827175e, 0x9b7d7d80, 0xb2ad6845, 0x51065140, 0x71180a18, 0x5b27006c, - 0x0621e255, 0x721cbe58, 0x670c0cb8, 0xf8bd715d, 0xe0bdc5d9, 0xed843501, 0x4b84554d, 0x7f1a18bc, - 0x53bcaf47, 0x5729d35f, 0xf0dda246, 0x22382bd0, 0x4d641fb0, 0x316afcde, 0x50a22f1f, 0x73608046, - 0xc461d84a, 0xb2dbe247, -}; - void DumpAddresses() { int64 nStart = GetTimeMillis(); @@ -1462,7 +1370,6 @@ void ThreadOpenConnections2(void* parg) } // Initiate network connections - int64 nStart = GetTime(); while(true) { ProcessOneShot(); @@ -1479,26 +1386,6 @@ void ThreadOpenConnections2(void* parg) if (fShutdown) return; - // Add seed nodes if IRC isn't working - if (addrman.size()==0 && (GetTime() - nStart > 60) && !fTestNet) - { - std::vector vAdd; - for (unsigned int i = 0; i < ARRAYLEN(pnSeed); i++) - { - // It'll only connect to one or two seed nodes because once it connects, - // it'll get a pile of addresses with newer timestamps. - // Seed nodes are given a random 'last seen time' of between one and two - // weeks ago. - const int64 nOneWeek = 7*24*60*60; - struct in_addr ip; - memcpy(&ip, &pnSeed[i], sizeof(ip)); - CAddress addr(CService(ip, GetDefaultPort())); - addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek; - vAdd.push_back(addr); - } - addrman.Add(vAdd, CNetAddr("127.0.0.1")); - } - // // Choose an address to connect to based on most recently seen // From a2759e793bdac97ab866a30cd333739f8a1b7969 Mon Sep 17 00:00:00 2001 From: John Doering Date: Mon, 20 Dec 2021 02:17:11 +0000 Subject: [PATCH 9/9] FileCommit() Fixed fcntl() with F_FULLFSYNC returns 0 on success or -1 on failure --- src/util.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 904dfa95..9bd179fa 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1085,13 +1085,14 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) #endif /* WINDOWS */ } -/* Returns zero on success and -1 on failure */ +/* Syncronises a file with a medium; + * returns zero on success or -1 on failure */ int FileCommit(FILE *fileout) { int ret, fd; - /* fflush() is a caller's responsibility */ + /* fflush() is a caller's responsibility; + * get a file descriptor first and perform the synchronisation next */ - /* Get a file descriptor and perform the synchronisation */ #if (WINDOWS) fd = _fileno(fileout); ret = _commit(fd); @@ -1100,10 +1101,10 @@ int FileCommit(FILE *fileout) { #if (__linux__) ret = fdatasync(fd); #elif (__APPLE__) && (F_FULLFSYNC) - /* F_FULLFSYNC means fsync with device flush to medium; - * works with HFS only as of 10.4, so fail over to fsync */ + /* fcntl() with F_FULLFSYNC means fsync() with device flush to medium; + * works with HFS only as of 10.4, so fail over to fsync() */ ret = fcntl(fd, F_FULLFSYNC, 0); - if(!ret) ret = fsync(fd); + if(ret) ret = fsync(fd); #else ret = fsync(fd); #endif