diff --git a/README.md b/README.md index 8e7fec9..bc770b6 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,4 @@ Stones will generate if held and not moved for more than ~8.8 Days. Forum https://bitcointalk.org/index.php?topic=830427.0 -HomePage: http://philosopherstones.org/ - -Community Channel: http://philosopherstones.org/channel - -Explorer: http://philosopherstones.org/block/ +HomePage: http://phs.ovh/ diff --git a/philosopherstone-qt.pro b/philosopherstone-qt.pro index d043440..c843197 100644 --- a/philosopherstone-qt.pro +++ b/philosopherstone-qt.pro @@ -1,25 +1,26 @@ TEMPLATE = app TARGET = philosopherstone-qt -VERSION = 0.7.5 +VERSION = 1.6.7 QT += core gui network INCLUDEPATH += src src/json src/qt -DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN __NO_SYSTEM_INCLUDES +DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE __STDC_FORMAT_MACROS __STDC_LIMIT_MACROS CONFIG += no_include_pwd CONFIG += thread CONFIG += static greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -BOOST_LIB_SUFFIX=-mgw71-mt-s-1_64 -BOOST_INCLUDE_PATH=D:/deps/x64/boost_1_64_0 -BOOST_LIB_PATH=D:/deps/x64/boost_1_64_0/stage/lib -BDB_INCLUDE_PATH=D:/deps/x64/db-6.2.32/build_unix -BDB_LIB_PATH=D:/deps/x64/db-6.2.32/build_unix -OPENSSL_INCLUDE_PATH=D:/deps/x64/openssl-1.0.2l/include -OPENSSL_LIB_PATH=D:/deps/x64/openssl-1.0.2l -QRENCODE_INCLUDE_PATH=D:/deps/x64/qrencode-3.4.4 -QRENCODE_LIB_PATH=D:/deps/x64/qrencode-3.4.4/.libs - # UNCOMMENT THIS SECTION TO BUILD ON WINDOWS +# Change paths if needed + +#BOOST_LIB_SUFFIX=-mgw71-mt-s-1_64 +#BOOST_INCLUDE_PATH=D:/deps/x64/boost_1_64_0 +#BOOST_LIB_PATH=D:/deps/x64/boost_1_64_0/stage/lib +#BDB_INCLUDE_PATH=D:/deps/x64/db-6.2.32/build_unix +#BDB_LIB_PATH=D:/deps/x64/db-6.2.32/build_unix +#OPENSSL_INCLUDE_PATH=D:/deps/x64/openssl-1.0.2l/include +#OPENSSL_LIB_PATH=D:/deps/x64/openssl-1.0.2l +#QRENCODE_INCLUDE_PATH=D:/deps/x64/qrencode-3.4.4 +#QRENCODE_LIB_PATH=D:/deps/x64/qrencode-3.4.4/.libs OBJECTS_DIR = build MOC_DIR = build @@ -44,9 +45,8 @@ QMAKE_LFLAGS *= -fstack-protector-all --param ssp-buffer-size=1 # This can be enabled for Windows, when we switch to MinGW >= 4.4.x. } # for extra security on Windows: enable ASLR and DEP via GCC linker flags -win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat -# on Windows: enable GCC large address aware linker flag -win32:QMAKE_LFLAGS *= -Wl,-static +windows:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat +windows:QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -static -pthread # use: qmake "USE_QRCODE=1" # libqrencode (http://fukuchi.org/works/qrencode/index.en.html) must be installed for support @@ -100,7 +100,7 @@ SOURCES += src/txdb-leveldb.cpp QMAKE_RANLIB = $$replace(QMAKE_STRIP, strip, ranlib) } LIBS += -lshlwapi - #genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX TARGET_OS=OS_WINDOWS_CROSSCOMPILE $(MAKE) OPT=\"$$QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE\" libleveldb.a libmemenv.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libleveldb.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libmemenv.a + genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX TARGET_OS=OS_WINDOWS_CROSSCOMPILE $(MAKE) OPT=\"$$QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE\" libleveldb.a libmemenv.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libleveldb.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libmemenv.a } genleveldb.target = $$PWD/src/leveldb/libleveldb.a genleveldb.depends = FORCE @@ -344,7 +344,7 @@ OTHER_FILES += \ # platform specific defaults, if not overridden on command line isEmpty(BOOST_LIB_SUFFIX) { macx:BOOST_LIB_SUFFIX = -mt - windows:BOOST_LIB_SUFFIX = -mgw71-mt-s-1_57 + windows:BOOST_LIB_SUFFIX = -mt } isEmpty(BOOST_THREAD_LIB_SUFFIX) { @@ -403,8 +403,7 @@ LIBS += $$join(BOOST_LIB_PATH,,-L,) $$join(BDB_LIB_PATH,,-L,) $$join(OPENSSL_LIB LIBS += -lssl -lcrypto -ldb_cxx$$BDB_LIB_SUFFIX # -lgdi32 has to happen after -lcrypto (see #681) windows:LIBS += -lws2_32 -lshlwapi -lmswsock -lole32 -loleaut32 -luuid -lgdi32 -LIBS += -lboost_system$$BOOST_LIB_SUFFIX -lboost_filesystem$$BOOST_LIB_SUFFIX -lboost_program_options$$BOOST_LIB_SUFFIX -lboost_thread$$BOOST_THREAD_LIB_SUFFIX -windows:LIBS += -lboost_chrono$$BOOST_LIB_SUFFIX +LIBS += -lboost_system$$BOOST_LIB_SUFFIX -lboost_filesystem$$BOOST_LIB_SUFFIX -lboost_program_options$$BOOST_LIB_SUFFIX -lboost_chrono$$BOOST_LIB_SUFFIX -lboost_thread$$BOOST_THREAD_LIB_SUFFIX contains(RELEASE, 1) { !windows:!macx { diff --git a/src/alert.cpp b/src/alert.cpp index b8896fc..26a1d22 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -56,8 +56,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/base58.h b/src/base58.h index dc29ffe..8c96af2 100644 --- a/src/base58.h +++ b/src/base58.h @@ -49,7 +49,7 @@ inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char CBigNum rem; while (bn > bn0) { - if (!BN_div(&dv, &rem, &bn, &bn58, pctx)) + if (!BN_div(dv.get(), rem.get(), bn.cget(), bn58.cget(), pctx)) throw bignum_error("EncodeBase58 : BN_div failed"); bn = dv; unsigned int c = rem.getulong(); @@ -96,7 +96,7 @@ inline bool DecodeBase58(const char* psz, std::vector& vchRet) break; } bnChar.setulong(p1 - pszBase58); - if (!BN_mul(&bn, &bn, &bn58, pctx)) + if (!BN_mul(bn.get(), bn.cget(), bn58.cget(), pctx)) throw bignum_error("DecodeBase58 : BN_mul failed"); bn += bnChar; } diff --git a/src/bignum.h b/src/bignum.h index c214275..4bcb107 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -48,75 +48,89 @@ class CAutoBN_CTX /** C++ wrapper for BIGNUM (OpenSSL bignum) */ -class CBigNum : public BIGNUM +class CBigNum { +private: + BIGNUM *self; + + void init() + { + if (self) BN_clear_free(self); + self = BN_new(); + if (!self) + throw bignum_error("CBigNum::init() : BN_new() returned NULL"); + } + public: - CBigNum() + BIGNUM* get() { return self; } + const BIGNUM* cget() const { return self; } + + CBigNum() : self(NULL) { - BN_init(this); + init(); } - CBigNum(const CBigNum& b) + CBigNum(const CBigNum& b) : self(NULL) { - BN_init(this); - if (!BN_copy(this, &b)) + init(); + if (!BN_copy(self, b.cget())) { - BN_clear_free(this); + BN_clear_free(self); throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); } } CBigNum& operator=(const CBigNum& b) { - if (!BN_copy(this, &b)) + if (!BN_copy(self, b.cget())) throw bignum_error("CBigNum::operator= : BN_copy failed"); return (*this); } ~CBigNum() { - BN_clear_free(this); + if (self) BN_clear_free(self); } //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. - CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int64 n) { BN_init(this); setint64(n); } - CBigNum(unsigned char n) { BN_init(this); setulong(n); } - CBigNum(unsigned short n) { BN_init(this); setulong(n); } - CBigNum(unsigned int n) { BN_init(this); setulong(n); } - CBigNum(unsigned long n) { BN_init(this); setulong(n); } - CBigNum(uint64 n) { BN_init(this); setuint64(n); } - explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } - - explicit CBigNum(const std::vector& vch) - { - BN_init(this); + CBigNum(signed char n) : self(NULL) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(short n) : self(NULL) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int n) : self(NULL) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long n) : self(NULL) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int64 n) : self(NULL) { init(); setint64(n); } + CBigNum(unsigned char n) : self(NULL) { init(); setulong(n); } + CBigNum(unsigned short n) : self(NULL) { init(); setulong(n); } + CBigNum(unsigned int n) : self(NULL) { init(); setulong(n); } + CBigNum(unsigned long n) : self(NULL) { init(); setulong(n); } + CBigNum(uint64 n) : self(NULL) { init(); setuint64(n); } + explicit CBigNum(uint256 n) : self(NULL) { init(); setuint256(n); } + + explicit CBigNum(const std::vector& vch) : self(NULL) + { + init(); setvch(vch); } void setulong(unsigned long n) { - if (!BN_set_word(this, n)) + if (!BN_set_word(self, n)) throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed"); } unsigned long getulong() const { - return BN_get_word(this); + return BN_get_word(self); } unsigned int getuint() const { - return BN_get_word(this); + return BN_get_word(self); } int getint() const { - unsigned long n = BN_get_word(this); - if (!BN_is_negative(this)) + unsigned long n = BN_get_word(self); + if (!BN_is_negative(self)) return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::max() : n); else return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); @@ -162,22 +176,7 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); - } - - uint64 getuint64() - { - unsigned int nSize = BN_bn2mpi(this, NULL); - if (nSize < 4) - return 0; - std::vector vch(nSize); - BN_bn2mpi(this, &vch[0]); - if (vch.size() > 4) - vch[4] &= 0x7f; - uint64 n = 0; - for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) - ((unsigned char*)&n)[i] = vch[j]; - return n; + BN_mpi2bn(pch, p - pch, self); } void setuint64(uint64 n) @@ -204,7 +203,22 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, p - pch, self); + } + + uint64 getuint64() + { + unsigned int nSize = BN_bn2mpi(self, NULL); + if (nSize < 4) + return 0; + std::vector vch(nSize); + BN_bn2mpi(self, &vch[0]); + if (vch.size() > 4) + vch[4] &= 0x7f; + uint64 n = 0; + for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) + ((unsigned char*)&n)[i] = vch[j]; + return n; } void setuint256(uint256 n) @@ -232,16 +246,16 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize >> 0) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, p - pch, self); } uint256 getuint256() { - unsigned int nSize = BN_bn2mpi(this, NULL); + unsigned int nSize = BN_bn2mpi(self, NULL); if (nSize < 4) return 0; std::vector vch(nSize); - BN_bn2mpi(this, &vch[0]); + BN_bn2mpi(self, &vch[0]); if (vch.size() > 4) vch[4] &= 0x7f; uint256 n = 0; @@ -250,7 +264,6 @@ class CBigNum : public BIGNUM return n; } - void setvch(const std::vector& vch) { std::vector vch2(vch.size() + 4); @@ -263,16 +276,16 @@ class CBigNum : public BIGNUM vch2[3] = (nSize >> 0) & 0xff; // swap data to big endian reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4); - BN_mpi2bn(&vch2[0], vch2.size(), this); + BN_mpi2bn(&vch2[0], vch2.size(), self); } std::vector getvch() const { - unsigned int nSize = BN_bn2mpi(this, NULL); + unsigned int nSize = BN_bn2mpi(self, NULL); if (nSize <= 4) return std::vector(); std::vector vch(nSize); - BN_bn2mpi(this, &vch[0]); + BN_bn2mpi(self, &vch[0]); vch.erase(vch.begin(), vch.begin() + 4); reverse(vch.begin(), vch.end()); return vch; @@ -281,25 +294,43 @@ class CBigNum : public BIGNUM CBigNum& SetCompact(unsigned int nCompact) { unsigned int nSize = nCompact >> 24; - std::vector vch(4 + nSize); - vch[3] = nSize; - if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff; - if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff; - if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff; - BN_mpi2bn(&vch[0], vch.size(), this); + bool fNegative =(nCompact & 0x00800000) != 0; + unsigned int nWord = nCompact & 0x007fffff; + if (nSize <= 3) + { + nWord >>= 8*(3-nSize); + BN_set_word(self, nWord); + } + else + { + BN_set_word(self, nWord); + BN_lshift(self, self, 8*(nSize-3)); + } + BN_set_negative(self, fNegative); return *this; } unsigned int GetCompact() const { - unsigned int nSize = BN_bn2mpi(this, NULL); - std::vector vch(nSize); - nSize -= 4; - BN_bn2mpi(this, &vch[0]); - unsigned int nCompact = nSize << 24; - if (nSize >= 1) nCompact |= (vch[4] << 16); - if (nSize >= 2) nCompact |= (vch[5] << 8); - if (nSize >= 3) nCompact |= (vch[6] << 0); + unsigned int nSize = BN_num_bytes(self); + unsigned int nCompact = 0; + if (nSize <= 3) + nCompact = BN_get_word(self) << 8*(3-nSize); + else + { + CBigNum bn; + BN_rshift(bn.get(), self, 8*(nSize-3)); + nCompact = BN_get_word(bn.cget()); + } + // The 0x00800000 bit denotes the sign. + // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. + if (nCompact & 0x00800000) + { + nCompact >>= 8; + nSize++; + } + nCompact |= nSize << 24; + nCompact |= (BN_is_negative(self) ? 0x00800000 : 0); return nCompact; } @@ -340,20 +371,20 @@ class CBigNum : public BIGNUM CBigNum bn0 = 0; std::string str; CBigNum bn = *this; - BN_set_negative(&bn, false); + BN_set_negative(bn.get(), false); CBigNum dv; CBigNum rem; - if (BN_cmp(&bn, &bn0) == 0) + if (BN_cmp(bn.get(), bn0.cget()) == 0) return "0"; - while (BN_cmp(&bn, &bn0) > 0) + while (BN_cmp(bn.get(), bn0.cget()) > 0) { - if (!BN_div(&dv, &rem, &bn, &bnBase, pctx)) + if (!BN_div(dv.get(), rem.get(), bn.cget(), bnBase.cget(), pctx)) throw bignum_error("CBigNum::ToString() : BN_div failed"); bn = dv; unsigned int c = rem.getulong(); str += "0123456789abcdef"[c]; } - if (BN_is_negative(this)) + if (BN_is_negative(self)) str += "-"; reverse(str.begin(), str.end()); return str; @@ -386,12 +417,12 @@ class CBigNum : public BIGNUM bool operator!() const { - return BN_is_zero(this); + return BN_is_zero(self); } CBigNum& operator+=(const CBigNum& b) { - if (!BN_add(this, this, &b)) + if (!BN_add(self, self, b.cget())) throw bignum_error("CBigNum::operator+= : BN_add failed"); return *this; } @@ -405,7 +436,7 @@ class CBigNum : public BIGNUM CBigNum& operator*=(const CBigNum& b) { CAutoBN_CTX pctx; - if (!BN_mul(this, this, &b, pctx)) + if (!BN_mul(self, self, b.cget(), pctx)) throw bignum_error("CBigNum::operator*= : BN_mul failed"); return *this; } @@ -424,7 +455,7 @@ class CBigNum : public BIGNUM CBigNum& operator<<=(unsigned int shift) { - if (!BN_lshift(this, this, shift)) + if (!BN_lshift(self, self, shift)) throw bignum_error("CBigNum:operator<<= : BN_lshift failed"); return *this; } @@ -435,13 +466,13 @@ class CBigNum : public BIGNUM // if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL CBigNum a = 1; a <<= shift; - if (BN_cmp(&a, this) > 0) + if (BN_cmp(a.cget(), self) > 0) { *this = 0; return *this; } - if (!BN_rshift(this, this, shift)) + if (!BN_rshift(self, self, shift)) throw bignum_error("CBigNum:operator>>= : BN_rshift failed"); return *this; } @@ -450,7 +481,7 @@ class CBigNum : public BIGNUM CBigNum& operator++() { // prefix operator - if (!BN_add(this, this, BN_value_one())) + if (!BN_add(self, self, BN_value_one())) throw bignum_error("CBigNum::operator++ : BN_add failed"); return *this; } @@ -467,7 +498,7 @@ class CBigNum : public BIGNUM { // prefix operator CBigNum r; - if (!BN_sub(&r, this, BN_value_one())) + if (!BN_sub(r.get(), self, BN_value_one())) throw bignum_error("CBigNum::operator-- : BN_sub failed"); *this = r; return *this; @@ -492,7 +523,7 @@ class CBigNum : public BIGNUM inline const CBigNum operator+(const CBigNum& a, const CBigNum& b) { CBigNum r; - if (!BN_add(&r, &a, &b)) + if (!BN_add(r.get(), a.cget(), b.cget())) throw bignum_error("CBigNum::operator+ : BN_add failed"); return r; } @@ -500,7 +531,7 @@ inline const CBigNum operator+(const CBigNum& a, const CBigNum& b) inline const CBigNum operator-(const CBigNum& a, const CBigNum& b) { CBigNum r; - if (!BN_sub(&r, &a, &b)) + if (!BN_sub(r.get(), a.cget(), b.cget())) throw bignum_error("CBigNum::operator- : BN_sub failed"); return r; } @@ -508,7 +539,7 @@ inline const CBigNum operator-(const CBigNum& a, const CBigNum& b) inline const CBigNum operator-(const CBigNum& a) { CBigNum r(a); - BN_set_negative(&r, !BN_is_negative(&r)); + BN_set_negative(r.get(), !BN_is_negative(r.cget())); return r; } @@ -516,7 +547,7 @@ inline const CBigNum operator*(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; - if (!BN_mul(&r, &a, &b, pctx)) + if (!BN_mul(r.get(), a.cget(), b.cget(), pctx)) throw bignum_error("CBigNum::operator* : BN_mul failed"); return r; } @@ -525,7 +556,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; - if (!BN_div(&r, NULL, &a, &b, pctx)) + if (!BN_div(r.get(), NULL, a.cget(), b.cget(), pctx)) throw bignum_error("CBigNum::operator/ : BN_div failed"); return r; } @@ -534,7 +565,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; - if (!BN_mod(&r, &a, &b, pctx)) + if (!BN_mod(r.get(), a.cget(), b.cget(), pctx)) throw bignum_error("CBigNum::operator% : BN_div failed"); return r; } @@ -542,7 +573,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b) inline const CBigNum operator<<(const CBigNum& a, unsigned int shift) { CBigNum r; - if (!BN_lshift(&r, &a, shift)) + if (!BN_lshift(r.get(), a.cget(), shift)) throw bignum_error("CBigNum:operator<< : BN_lshift failed"); return r; } @@ -554,11 +585,11 @@ inline const CBigNum operator>>(const CBigNum& a, unsigned int shift) return r; } -inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); } -inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); } -inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); } -inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); } -inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); } -inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); } +inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) == 0); } +inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) != 0); } +inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) <= 0); } +inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) >= 0); } +inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) < 0); } +inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) > 0); } #endif diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 75d3dae..7b397b8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -348,7 +348,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: Philosopherstone-json-rpc/%s\r\n" "\r\n" @@ -548,9 +548,12 @@ class SSLIOStreamDevice : public iostreams::device { if (fUseSSL) return asio::write(stream, asio::buffer(s, n)); return asio::write(stream.next_layer(), asio::buffer(s, n)); } - bool connect(const std::string& server, const std::string& port) - { + bool connect(const std::string &server, const std::string &port) { +#if (BOOST_VERSION >= 107000) + ip::tcp::resolver resolver((boost::asio::io_context &)(stream.get_executor().context())); +#else ip::tcp::resolver resolver(stream.get_io_service()); +#endif ip::tcp::resolver::query query(server.c_str(), port.c_str()); ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); ip::tcp::resolver::iterator end; @@ -640,8 +643,13 @@ void ThreadRPCServer(void* parg) } // Forward declaration required for RPCListen +#if (BOOST_VERSION > 106501) +template +static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor > acceptor, +#else template static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor > acceptor, +#endif ssl::context& context, bool fUseSSL, AcceptedConnection* conn, @@ -650,18 +658,32 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor 106501) +template +static void RPCListen(boost::shared_ptr< basic_socket_acceptor > acceptor, +#else template static void RPCListen(boost::shared_ptr< basic_socket_acceptor > acceptor, +#endif ssl::context& context, const bool fUseSSL) { // Accept connection - AcceptedConnectionImpl* conn = new AcceptedConnectionImpl(acceptor->get_io_service(), context, fUseSSL); + AcceptedConnectionImpl* conn = new AcceptedConnectionImpl +#if (BOOST_VERSION >= 107000) + ((boost::asio::io_context &)(acceptor->get_executor().context()), context, fUseSSL); +#else + (acceptor->get_io_service(), context, fUseSSL); +#endif acceptor->async_accept( conn->sslStream.lowest_layer(), conn->peer, +#if (BOOST_VERSION > 106501) + boost::bind(&RPCAcceptHandler, +#else boost::bind(&RPCAcceptHandler, +#endif acceptor, boost::ref(context), fUseSSL, @@ -672,8 +694,13 @@ static void RPCListen(boost::shared_ptr< basic_socket_acceptor 106501) +template +static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor > acceptor, +#else template static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor > acceptor, +#endif ssl::context& context, const bool fUseSSL, AcceptedConnection* conn, @@ -733,7 +760,7 @@ void ThreadRPCServer2(void* parg) uiInterface.ThreadSafeMessageBox(strprintf( _("%s, you must set a rpcpassword in the configuration file:\n %s\n" "It is recommended you use the following random password:\n" - "rpcuser=bitcoinrpc\n" + "rpcuser=phsrpc\n" "rpcpassword=%s\n" "(you do not need to remember this password)\n" "The username and password MUST NOT be the same.\n" @@ -752,23 +779,32 @@ void ThreadRPCServer2(void* parg) asio::io_service io_service; +#if (BOOST_VERSION > 106501) + ssl::context context(ssl::context::sslv23); +#else ssl::context context(io_service, ssl::context::sslv23); +#endif if (fUseSSL) { context.set_options(ssl::context::no_sslv2); - filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert")); - if (!pathCertFile.is_complete()) pathCertFile = filesystem::path(GetDataDir()) / pathCertFile; - if (filesystem::exists(pathCertFile)) context.use_certificate_chain_file(pathCertFile.string()); + boost::filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert")); + if (!pathCertFile.is_complete()) pathCertFile = boost::filesystem::path(GetDataDir()) / pathCertFile; + if (boost::filesystem::exists(pathCertFile)) context.use_certificate_chain_file(pathCertFile.string()); else printf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string().c_str()); - filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem")); - if (!pathPKFile.is_complete()) pathPKFile = filesystem::path(GetDataDir()) / pathPKFile; - if (filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string(), ssl::context::pem); + boost::filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem")); + if (!pathPKFile.is_complete()) pathPKFile = boost::filesystem::path(GetDataDir()) / pathPKFile; + if (boost::filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string(), ssl::context::pem); else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str()); string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH"); + +#if (BOOST_VERSION > 106501) + SSL_CTX_set_cipher_list(context.native_handle(), strCiphers.c_str()); +#else SSL_CTX_set_cipher_list(context.impl(), strCiphers.c_str()); +#endif } // Try a dual IPv6/IPv4 socket, falling back to separate IPv4 and IPv6 sockets @@ -1063,7 +1099,13 @@ Object CallRPC(const string& strMethod, const Array& params) // Connect to localhost bool fUseSSL = GetBoolArg("-rpcssl"); asio::io_service io_service; + +#if (BOOST_VERSION > 106501) + ssl::context context(ssl::context::sslv23); +#else ssl::context context(io_service, ssl::context::sslv23); +#endif + context.set_options(ssl::context::no_sslv2); asio::ssl::stream sslStream(io_service, context); SSLIOStreamDevice d(sslStream, fUseSSL); diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 1f3ee44..a8f825e 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -33,7 +33,8 @@ namespace Checkpoints (292477, uint256("0xa4acb90c0539f5e50261d4180c1f4adaa40c85d3420f0c2feab2314661fa1d61")) (316344, uint256("0x4486e82497838ae9eff7ed0c138fec6aca47235f90e138fa7fef7ccd48cbd46a")) (746700, uint256("0x8fe08c5d6a27d9b86f3ca422ee705cc0bd1fe82dd45592975ae9b7af3b14258d")) - ; + (1553365, uint256("0xbd439928aff81cfc51e62db05cd60400fd266b921ec3addcbddd1daf87dc0284")) + ; static MapCheckpoints mapCheckpointsTestnet = boost::assign::map_list_of diff --git a/src/clientversion.h b/src/clientversion.h index 7956126..2ec858e 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,8 +12,8 @@ #define CLIENT_VERSION_MAJOR 1 #define CLIENT_VERSION_MINOR 6 -#define CLIENT_VERSION_REVISION 6 -#define CLIENT_VERSION_BUILD 9 +#define CLIENT_VERSION_REVISION 7 +#define CLIENT_VERSION_BUILD 2 // Converts the parameter X to a string after macro replacement on X has been performed. // Don't merge these into one macro! diff --git a/src/crypter.cpp b/src/crypter.cpp index a2b62a8..4aa032f 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -56,15 +56,17 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector (nCLen); - EVP_CIPHER_CTX ctx; + EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); + if (!ctx) return false; bool fOk = true; - EVP_CIPHER_CTX_init(&ctx); - if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); - if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); - if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen); - EVP_CIPHER_CTX_cleanup(&ctx); + EVP_CIPHER_CTX_init(ctx); + if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); + if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen); + EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_free(ctx); if (!fOk) return false; @@ -83,15 +85,17 @@ bool CCrypter::Decrypt(const std::vector& vchCiphertext, CKeyingM vchPlaintext = CKeyingMaterial(nPLen); - EVP_CIPHER_CTX ctx; + EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); + if (!ctx) return false; bool fOk = true; - EVP_CIPHER_CTX_init(&ctx); - if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); - if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); - if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen); - EVP_CIPHER_CTX_cleanup(&ctx); + EVP_CIPHER_CTX_init(ctx); + if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); + if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen); + EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_free(ctx); if (!fOk) return false; diff --git a/src/db.cpp b/src/db.cpp index 37209ba..29f6688 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -39,7 +39,7 @@ void CDBEnv::EnvShutdown() if (ret != 0) printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret); if (!fMockDb) - DbEnv(0).remove(strPath.c_str(), 0); + DbEnv(0u).remove(strPath.c_str(), 0); } CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS) @@ -67,11 +67,11 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_) return false; pathEnv = pathEnv_; - filesystem::path pathDataDir = pathEnv; + boost::filesystem::path pathDataDir = pathEnv; strPath = pathDataDir.string(); - filesystem::path pathLogDir = pathDataDir / "database"; - filesystem::create_directory(pathLogDir); - filesystem::path pathErrorFile = pathDataDir / "db.log"; + boost::filesystem::path pathLogDir = pathDataDir / "database"; + boost::filesystem::create_directory(pathLogDir); + boost::filesystem::path pathErrorFile = pathDataDir / "db.log"; printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str()); unsigned int nEnvFlags = 0; @@ -478,7 +478,7 @@ 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/init.cpp b/src/init.cpp index 1b53a6d..3794fab 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -27,6 +27,7 @@ using namespace boost; CWallet* pwalletMain; CClientUIInterface uiInterface; unsigned int nNodeLifespan; +std::string strWalletFileName; bool fConfChange; bool fEnforceCanonical; unsigned int nMinerSleep; @@ -63,7 +64,7 @@ void Shutdown(void* parg) static bool fTaken; // Make this thread recognisable as the shutdown thread - RenameThread("bitcoin-shutoff"); + RenameThread("phs-shutoff"); bool fFirstThread = false; { @@ -229,6 +230,7 @@ std::string HelpMessage() " -conf= " + _("Specify configuration file (default: Philosopherstone.conf)") + "\n" + " -pid= " + _("Specify pid file (default: Philosopherstoned.pid)") + "\n" + " -datadir= " + _("Specify data directory") + "\n" + + " -wallet= " + _("Specify wallet file (within data directory)") + "\n" + " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -dblogsize= " + _("Set database disk log size in megabytes (default: 100)") + "\n" + " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + @@ -496,8 +498,13 @@ bool AppInit2() return InitError(_("Initialization sanity check failed. Philosopherstone is shutting down.")); std::string strDataDir = GetDataDir().string(); + std::string strWalletFileName = GetArg("-wallet", "wallet.dat"); - // Make sure only a single Bitcoin process is using the data directory. + // strWalletFileName must be a plain filename without a directory + if (strWalletFileName != boost::filesystem::basename(strWalletFileName) + boost::filesystem::extension(strWalletFileName)) + return InitError(strprintf(_("Wallet %s resides outside data directory %s."), strWalletFileName.c_str(), strDataDir.c_str())); + + // Make sure only a single PHS process is using the data directory. boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. if (file) fclose(file); @@ -558,13 +565,13 @@ bool AppInit2() if (GetBoolArg("-salvagewallet")) { // Recover readable keypairs: - if (!CWalletDB::Recover(bitdb, "wallet.dat", true)) + if (!CWalletDB::Recover(bitdb, strWalletFileName, true)) return false; } - if (filesystem::exists(GetDataDir() / "wallet.dat")) + if (boost::filesystem::exists(GetDataDir() / strWalletFileName)) { - CDBEnv::VerifyResult r = bitdb.Verify("wallet.dat", CWalletDB::Recover); + CDBEnv::VerifyResult r = bitdb.Verify(strWalletFileName, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" @@ -585,7 +592,7 @@ bool AppInit2() if (nSplitThreshold > MAX_SPLIT_AMOUNT) nSplitThreshold = MAX_SPLIT_AMOUNT; } - printf("splitthreshold set to %"PRI64d"\n",nSplitThreshold); + printf("splitthreshold set to %" PRI64d "\n",nSplitThreshold); } if (mapArgs.count("-combinethreshold")) @@ -596,7 +603,7 @@ bool AppInit2() if (nCombineThreshold > MAX_COMBINE_AMOUNT) nCombineThreshold = MAX_COMBINE_AMOUNT; } - printf("combinethreshold set to %"PRI64d"\n",nCombineThreshold); + printf("combinethreshold set to %" PRI64d "\n",nCombineThreshold); } // ********************************************************* Step 6: network initialization @@ -747,7 +754,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")) { @@ -784,7 +791,7 @@ bool AppInit2() printf("Loading wallet...\n"); nStart = GetTimeMillis(); bool fFirstRun = true; - pwalletMain = new CWallet("wallet.dat"); + pwalletMain = new CWallet(strWalletFileName); DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); if (nLoadWalletRet != DB_LOAD_OK) { @@ -838,7 +845,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); @@ -847,7 +854,7 @@ bool AppInit2() pindexRescan = pindexGenesisBlock; else { - CWalletDB walletdb("wallet.dat"); + CWalletDB walletdb(strWalletFileName); CBlockLocator locator; if (walletdb.ReadBestBlock(locator)) pindexRescan = locator.GetBlockIndex(); @@ -858,7 +865,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 @@ -876,13 +883,13 @@ bool AppInit2() exit(0); } - filesystem::path pathBootstrap = filesystem::initial_path() / "bootstrap.dat"; - if (filesystem::exists(pathBootstrap)) { + boost::filesystem::path pathBootstrap = boost::filesystem::initial_path() / "bootstrap.dat"; + if (boost::filesystem::exists(pathBootstrap)) { uiInterface.InitMessage(_("Importing bootstrap blockchain data file.")); FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); if (file) { - filesystem::path pathBootstrapOld = filesystem::initial_path() / "bootstrap.dat.old"; + boost::filesystem::path pathBootstrapOld = boost::filesystem::initial_path() / "bootstrap.dat.old"; LoadExternalBlockFile(file); RenameOver(pathBootstrap, pathBootstrapOld); } @@ -900,7 +907,7 @@ bool AppInit2() printf("Invalid or missing peers.dat; recreating\n"); } - printf("Loaded %i addresses from peers.dat %"PRI64d"ms\n", + printf("Loaded %i addresses from peers.dat %" PRI64d "ms\n", addrman.size(), GetTimeMillis() - nStart); // ********************************************************* Step 11: start node @@ -911,11 +918,11 @@ bool AppInit2() RandAddSeedPerfmon(); //// debug print - printf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.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()); + 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 8308ee6..a722810 100644 --- a/src/init.h +++ b/src/init.h @@ -9,6 +9,7 @@ extern CWallet* pwalletMain; +extern std::string strWalletFileName; void StartShutdown(); void Shutdown(void* parg); bool AppInit2(); diff --git a/src/irc.cpp b/src/irc.cpp index 6116656..039668e 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -260,7 +260,7 @@ void ThreadIRCSeed2(void* parg) if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") - strMyName = strprintf("x%"PRI64u"", GetRand(1000000000)); + strMyName = strprintf("x%" PRI64u "", GetRand(1000000000)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str()); diff --git a/src/json/json_spirit_writer_template.h b/src/json/json_spirit_writer_template.h index 28c49dd..41b78a3 100644 --- a/src/json/json_spirit_writer_template.h +++ b/src/json/json_spirit_writer_template.h @@ -28,7 +28,8 @@ namespace json_spirit template< class String_type > String_type non_printable_to_string( unsigned int c ) { - typedef typename String_type::value_type Char_type; + // Silence the warning: typedef ‘Char_type’ locally defined but not used [-Wunused-local-typedefs] + // typedef typename String_type::value_type Char_type; String_type result( 6, '\\' ); diff --git a/src/kernel.cpp b/src/kernel.cpp index e06d2e6..d5c2de3 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -28,17 +28,17 @@ static std::map mapStakeModifierCheckpoints = ( 224125,0xbbd31d80u ) ( 230007,0x63c795b0u ) ( 252789,0x63e5b34cu ) + ( 1553365,0x050fb72cu ) ; - + // Get time weight int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd) { - // Kernel hash weight starts from 0 at the 30-day min age - // this change increases active coins participating the hash and helps - // to secure the network when proof-of-stake difficulty is low - return min(nIntervalEnd - nIntervalBeginning, (int64)nStakeMaxAge) - nStakeMinAge; + // Kernel hash weight starts from 0 at the 30-day min age + // this change increases active coins participating the hash and helps + // to secure the network when proof-of-stake difficulty is low + return min(nIntervalEnd - nIntervalBeginning, (int64)nStakeMaxAge) - nStakeMinAge; } - // Get the last stake modifier and its generation time from a given block static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime) @@ -59,7 +59,7 @@ static int64 GetStakeModifierSelectionIntervalSection(int nSection) { assert (nSection >= 0 && nSection < 64); int64 a = nModifierInterval * 63 / (63 + ((63 - nSection) * (MODIFIER_INTERVAL_RATIO - 1))); - return a; + return a; } // Get stake modifier selection interval (in seconds) @@ -67,9 +67,9 @@ static int64 GetStakeModifierSelectionInterval() { int64 nSelectionInterval = 0; for (int nSection=0; nSection<64; nSection++) - { + { nSelectionInterval += GetStakeModifierSelectionIntervalSection(nSection); - } + } return nSelectionInterval; } @@ -151,7 +151,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64& nStakeModif return error("ComputeNextStakeModifier: unable to get last modifier"); if (fDebug) { - printf("ComputeNextStakeModifier: prev modifier=0x%016"PRI64x" time=%s\n", nStakeModifier, DateTimeStrFormat(nModifierTime).c_str()); + printf("ComputeNextStakeModifier: prev modifier=0x%016" PRI64x " time=%s\n", nStakeModifier, DateTimeStrFormat(nModifierTime).c_str()); } if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval) return true; @@ -215,7 +215,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64& nStakeModif } if (fDebug) { - printf("ComputeNextStakeModifier: new modifier=0x%016"PRI64x" time=%s\n", nStakeModifierNew, DateTimeStrFormat(pindexPrev->GetBlockTime()).c_str()); + printf("ComputeNextStakeModifier: new modifier=0x%016" PRI64x " time=%s\n", nStakeModifierNew, DateTimeStrFormat(pindexPrev->GetBlockTime()).c_str()); } nStakeModifier = nStakeModifierNew; @@ -245,11 +245,11 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s", pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str()); else - { - // printf(">> nStakeModifierTime = %"PRI64d", pindexFrom->GetBlockTime() = %"PRI64d", nStakeModifierSelectionInterval = %"PRI64d"\n", - // nStakeModifierTime, pindexFrom->GetBlockTime(), nStakeModifierSelectionInterval); + { + // printf(">> nStakeModifierTime = %" PRI64d ", pindexFrom->GetBlockTime() = %" PRI64d ", nStakeModifierSelectionInterval = %" PRI64d "\n", + // nStakeModifierTime, pindexFrom->GetBlockTime(), nStakeModifierSelectionInterval); return false; - } + } } pindex = pindex->pnext; if (pindex->GeneratedStakeModifier()) @@ -306,7 +306,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60); targetProofOfStake = CBigNum(bnCoinDayWeight * bnTargetPerCoinDay).getuint256(); - // printf(">>> CheckStakeKernelHash: nTimeWeight = %"PRI64d"\n", nTimeWeight); + // printf(">>> CheckStakeKernelHash: nTimeWeight = %" PRI64d "\n", nTimeWeight); // Calculate hash CDataStream ss(SER_GETHASH, 0); uint64 nStakeModifier = 0; @@ -324,12 +324,12 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned hashProofOfStake = Hash(ss.begin(), ss.end()); if (fPrintProofOfStake) { - printf("CheckStakeKernelHash() : using modifier 0x%016"PRI64x" at height=%d timestamp=%s for block from height=%d timestamp=%s\n", + printf("CheckStakeKernelHash() : using modifier 0x%016" PRI64x " at height=%d timestamp=%s for block from height=%d timestamp=%s\n", nStakeModifier, nStakeModifierHeight, DateTimeStrFormat(nStakeModifierTime).c_str(), mapBlockIndex[hashBlockFrom]->nHeight, DateTimeStrFormat(blockFrom.GetBlockTime()).c_str()); - printf("CheckStakeKernelHash() : check protocol=%s modifier=0x%016"PRI64x" nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", + printf("CheckStakeKernelHash() : check protocol=%s modifier=0x%016" PRI64x " nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", "0.3", nStakeModifier, nTimeBlockFrom, nTxPrevOffset, txPrev.nTime, prevout.n, nTimeTx, @@ -348,12 +348,12 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned if (fDebug && !fPrintProofOfStake) { - printf("CheckStakeKernelHash() : using modifier 0x%016"PRI64x" at height=%d timestamp=%s for block from height=%d timestamp=%s\n", + printf("CheckStakeKernelHash() : using modifier 0x%016" PRI64x " at height=%d timestamp=%s for block from height=%d timestamp=%s\n", nStakeModifier, nStakeModifierHeight, DateTimeStrFormat(nStakeModifierTime).c_str(), mapBlockIndex[hashBlockFrom]->nHeight, DateTimeStrFormat(blockFrom.GetBlockTime()).c_str()); - printf("CheckStakeKernelHash() : pass protocol=%s modifier=0x%016"PRI64x" nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", + printf("CheckStakeKernelHash() : pass protocol=%s modifier=0x%016" PRI64x " nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n", "0.3", nStakeModifier, nTimeBlockFrom, nTxPrevOffset, txPrev.nTime, prevout.n, nTimeTx, diff --git a/src/key.cpp b/src/key.cpp index d081b1c..64fd1b7 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -4,7 +4,10 @@ #include +#if OPENSSL_VERSION_NUMBER < 0x10100000L #include +#endif + #include #include "key.h" @@ -52,6 +55,14 @@ int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key) int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check) { if (!eckey) return 0; + + const BIGNUM *sig_r, *sig_s; + #if OPENSSL_VERSION_NUMBER > 0x1000ffffL + ECDSA_SIG_get0(ecsig, &sig_r, &sig_s); + #else + sig_r = ecsig->r; + sig_s = ecsig->s; + #endif int ret = 0; BN_CTX *ctx = NULL; @@ -78,7 +89,7 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch x = BN_CTX_get(ctx); if (!BN_copy(x, order)) { ret=-1; goto err; } if (!BN_mul_word(x, i)) { ret=-1; goto err; } - if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; } + if (!BN_add(x, x, sig_r)) { ret=-1; goto err; } field = BN_CTX_get(ctx); if (!EC_GROUP_get_curve_GFp(group, field, NULL, NULL, ctx)) { ret=-2; goto err; } if (BN_cmp(x, field) >= 0) { ret=0; goto err; } @@ -96,12 +107,12 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch if (!BN_bin2bn(msg, msglen, e)) { ret=-1; goto err; } if (8*msglen > n) BN_rshift(e, e, 8-(n & 7)); zero = BN_CTX_get(ctx); - if (!BN_zero(zero)) { ret=-1; goto err; } + if (!BN_set_word(zero, 0)) { ret=-1; goto err; } if (!BN_mod_sub(e, zero, e, order, ctx)) { ret=-1; goto err; } rr = BN_CTX_get(ctx); - if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; } + if (!BN_mod_inverse(rr, sig_r, order, ctx)) { ret=-1; goto err; } sor = BN_CTX_get(ctx); - if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; } + if (!BN_mod_mul(sor, sig_s, rr, order, ctx)) { ret=-1; goto err; } eor = BN_CTX_get(ctx); if (!BN_mod_mul(eor, e, rr, order, ctx)) { ret=-1; goto err; } if (!EC_POINT_mul(group, Q, eor, R, sor, ctx)) { ret=-2; goto err; } @@ -308,8 +319,17 @@ bool CKey::SignCompact(uint256 hash, std::vector& vchSig) return false; vchSig.clear(); vchSig.resize(65,0); - int nBitsR = BN_num_bits(sig->r); - int nBitsS = BN_num_bits(sig->s); + + const BIGNUM *sig_r, *sig_s; + #if OPENSSL_VERSION_NUMBER > 0x1000ffffL + ECDSA_SIG_get0(sig, &sig_r, &sig_s); + #else + sig_r = sig->r; + sig_s = sig->s; + #endif + + int nBitsR = BN_num_bits(sig_r); + int nBitsS = BN_num_bits(sig_s); if (nBitsR <= 256 && nBitsS <= 256) { int nRecId = -1; @@ -334,8 +354,8 @@ bool CKey::SignCompact(uint256 hash, std::vector& vchSig) } vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0); - BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]); - BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]); + BN_bn2bin(sig_r,&vchSig[33-(nBitsR+7)/8]); + BN_bn2bin(sig_s,&vchSig[65-(nBitsS+7)/8]); fOk = true; } ECDSA_SIG_free(sig); @@ -354,8 +374,19 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector& v if (nV<27 || nV>=35) return false; ECDSA_SIG *sig = ECDSA_SIG_new(); + if (!sig) return false; + + #if OPENSSL_VERSION_NUMBER > 0x1000ffffL + // sig_r and sig_s are deallocated by ECDSA_SIG_free(sig); + BIGNUM *sig_r = BN_bin2bn(&vchSig[1],32,BN_new()); + BIGNUM *sig_s = BN_bin2bn(&vchSig[33],32,BN_new()); + if (!sig_r || !sig_s) return false; + // copy and transfer ownership to sig + ECDSA_SIG_set0(sig, sig_r, sig_s); + #else BN_bin2bn(&vchSig[1],32,sig->r); BN_bin2bn(&vchSig[33],32,sig->s); + #endif EC_KEY_free(pkey); pkey = EC_KEY_new_by_curve_name(NID_secp256k1); diff --git a/src/main.cpp b/src/main.cpp index cc831c0..acf2469 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,10 +42,10 @@ static CBigNum bnProofOfStakeLimit(~uint256(0) >> 20); static CBigNum bnProofOfWorkLimitTestNet(~uint256(0) >> 20); static CBigNum bnProofOfStakeLimitTestNet(~uint256(0) >> 20); -unsigned int nStakeMinAge = 60 * 60 * 24 * 5; // minimum age for coin age: 5d -unsigned int nStakeMinAge2 = 60 * 60 * 24 * 8.8; // PALM until fork -unsigned int nStakeMaxAge = 60 * 60 * 24 * 15; // stake age of full weight: 15d -unsigned int nStakeTargetSpacing = 120; // 2-minute block spacing +unsigned int nStakeMinAge = 60 * 60 * 24 * 5; // minimum age for coin age: 5d +unsigned int nStakeMinAge2 = 60 * 60 * 24 * 8.8; // PALM until fork +unsigned int nStakeMaxAge = 60 * 60 * 24 * 15; // stake age of full weight: 15d +unsigned int nStakeTargetSpacing = 120; // 2-minute block spacing unsigned int nStakeTargetSpacingNEW = 200; int64 nChainStartTime = 1374911180; @@ -212,7 +212,7 @@ bool AddOrphanTx(const CTransaction& tx) if (nSize > 5000) { - printf("ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", nSize, hash.ToString().substr(0,10).c_str()); + printf("ignoring large orphan tx (size: %" PRIszu ", hash: %s)\n", nSize, hash.ToString().substr(0,10).c_str()); return false; } @@ -220,7 +220,7 @@ bool AddOrphanTx(const CTransaction& tx) BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash); - printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().substr(0,10).c_str(), + printf("stored orphan tx %s (mapsz %" PRIszu ")\n", hash.ToString().substr(0,10).c_str(), mapOrphanTransactions.size()); return true; } @@ -293,9 +293,9 @@ bool CTransaction::IsStandard() const if (nVersion > CTransaction::CURRENT_VERSION) return false; - // Disallow large transaction comments - if (strTxComment.length() > MAX_TX_COMMENT_LEN) - return false; + // Disallow large transaction comments + if (strTxComment.length() > MAX_TX_COMMENT_LEN) + return false; BOOST_FOREACH(const CTxIn& txin, vin) @@ -635,7 +635,7 @@ 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(1000, false, GMF_RELAY, nSize); if (nFees < txMinFee) - return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d, + return error("CTxMemPool::accept() : not enough fees %s, %" PRI64d " < %" PRI64d, hash.ToString().c_str(), nFees, txMinFee); @@ -688,7 +688,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n", + printf("CTxMemPool::accept() : accepted %s (poolsz %" PRIszu ")\n", hash.ToString().substr(0,10).c_str(), mapTx.size()); return true; @@ -969,7 +969,7 @@ uint256 WantedByOrphan(const CBlock* pblockOrphan) int generateMTRandom(unsigned int s, int range) { - random::mt19937 gen(s); + random::mt19937 gen(s); random::uniform_int_distribution<> dist(1, range); return dist(gen); } @@ -978,31 +978,31 @@ int generateMTRandom(unsigned int s, int range) // miner's coin base reward based on nBits int64 GetProofOfWorkReward(int nHeight, int64 nFees, uint256 prevHash) { - int64 nSubsidy = 64 * COIN; + int64 nSubsidy = 64 * COIN; - std::string cseed_str = prevHash.ToString().substr(7,7); - const char* cseed = cseed_str.c_str(); - long seed = hex2long(cseed); - int rand = generateMTRandom(seed, 7200); + std::string cseed_str = prevHash.ToString().substr(7,7); + const char* cseed = cseed_str.c_str(); + long seed = hex2long(cseed); + int rand = generateMTRandom(seed, 7200); - // printf(">>> nHeight = %d, Rand = %d\n", nHeight, rand); + // printf(">>> nHeight = %d, Rand = %d\n", nHeight, rand); - if(rand > 5000 && rand < 5011) - { - nSubsidy = 512 * COIN; - } - else if(rand > 2000 && rand < 2241) - { - nSubsidy = 128 * COIN; - } - - if(nHeight < 3600) // 1st 5 days double payout - { - nSubsidy *= 2; - } + if(rand > 5000 && rand < 5011) + { + nSubsidy = 512 * COIN; + } + else if(rand > 2000 && rand < 2241) + { + nSubsidy = 128 * COIN; + } + + if(nHeight < 3600) // 1st 5 days double payout + { + nSubsidy *= 2; + } - // Subsidy is cut in half every 64,800 blocks, which will occur approximately every 3 months - nSubsidy >>= (nHeight / 64800); + // Subsidy is cut in half every 64,800 blocks, which will occur approximately every 3 months + nSubsidy >>= (nHeight / 64800); return nSubsidy + nFees; } @@ -1012,20 +1012,20 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi { int64 nRewardCoinYear; - nRewardCoinYear = MAX_MINT_PROOF_OF_STAKE; + nRewardCoinYear = MAX_MINT_PROOF_OF_STAKE; - if (nHeight > SECOND_HALVING_BLOCK) - nRewardCoinYear /= 4; - else if (nHeight > FIRST_HALVING_BLOCK) - nRewardCoinYear /= 2; + if (nHeight > SECOND_HALVING_BLOCK) + nRewardCoinYear /= 4; + else if (nHeight > FIRST_HALVING_BLOCK) + nRewardCoinYear /= 2; int64 nSubsidy = nCoinAge * nRewardCoinYear / 365; - if(nTime > RWD_SWITCH_TIME) - nSubsidy /= 64; + if(nTime > RWD_SWITCH_TIME) + nSubsidy /= 64; - if (fDebug && GetBoolArg("-printcreation")) - printf("GetProofOfStakeReward(): create=%s nCoinAge=%"PRI64d" nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits); + if (fDebug && GetBoolArg("-printcreation")) + printf("GetProofOfStakeReward(): create=%s nCoinAge=%" PRI64d " nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits); return nSubsidy; } @@ -1158,7 +1158,7 @@ unsigned int static GetNextTargetRequiredV3(const CBlockIndex* pindexLast, bool CBigNum bnNew; bnNew.SetCompact(pindexPrev->nBits); - int64 nTargetSpacing = fProofOfStake? nStakeTargetSpacingNEW : min(nTargetSpacingWorkMaxNEW, (int64) nStakeTargetSpacingNEW * (1 + pindexLast->nHeight - pindexPrev->nHeight)); + int64 nTargetSpacing = fProofOfStake? nStakeTargetSpacingNEW : min(nTargetSpacingWorkMaxNEW, (int64) nStakeTargetSpacingNEW * (1 + pindexLast->nHeight - pindexPrev->nHeight)); int64 nInterval = nTargetTimespan / nTargetSpacing; bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing); bnNew /= ((nInterval + 1) * nTargetSpacing); @@ -1175,7 +1175,7 @@ unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfS return GetNextTargetRequiredV1(pindexLast, fProofOfStake); else if (pindexLast->nHeight >= 213500 && pindexLast->nHeight < 224100) return GetNextTargetRequiredV2(pindexLast, fProofOfStake); - else + else return GetNextTargetRequiredV3(pindexLast, fProofOfStake); } @@ -1344,7 +1344,7 @@ 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())); } } @@ -1417,7 +1417,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, 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())); + 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 or coinstake, check that it's matured if (txPrev.IsCoinBase() || txPrev.IsCoinStake()) @@ -1482,9 +1482,9 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, int64 nCalculatedStakeReward = GetProofOfStakeReward(nCoinAge, pindexBlock->nBits, nTime, pindexBlock->nHeight) - GetMinFee() + MIN_TX_FEE; if (nStakeReward > nCalculatedStakeReward) - return DoS(100, error("ConnectInputs() : coinstake pays too much(actual=%"PRI64d" vs calculated=%"PRI64d")", nStakeReward, nCalculatedStakeReward)); + return DoS(100, error("ConnectInputs() : coinstake pays too much(actual=%" PRI64d " vs calculated=%" PRI64d ")", nStakeReward, nCalculatedStakeReward)); } - + else { if (nValueIn < GetValueOut()) @@ -1669,7 +1669,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) // ppcoin: fees are not collected by miners as in bitcoin // ppcoin: fees are destroyed to compensate the entire network if (fDebug && GetBoolArg("-printcreation")) - printf("ConnectBlock() : destroy=%s nFees=%"PRI64d"\n", FormatMoney(nFees).c_str(), nFees); + printf("ConnectBlock() : destroy=%s nFees=%" PRI64d "\n", FormatMoney(nFees).c_str(), nFees); if (fJustCheck) return true; @@ -1681,15 +1681,15 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) return error("ConnectBlock() : UpdateTxIndex failed"); } - uint256 prevHash = 0; - if(pindex->pprev) - { - prevHash = pindex->pprev->GetBlockHash(); - // printf("==> Got prevHash = %s\n", prevHash.ToString().c_str()); - } + uint256 prevHash = 0; + if(pindex->pprev) + { + prevHash = pindex->pprev->GetBlockHash(); + // printf("==> Got prevHash = %s\n", prevHash.ToString().c_str()); + } - if (vtx[0].GetValueOut() > GetProofOfWorkReward(pindex->nHeight, nFees, prevHash)) - return DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetValueOut(), GetProofOfWorkReward(pindex->nHeight, nFees, prevHash))); + if (vtx[0].GetValueOut() > GetProofOfWorkReward(pindex->nHeight, nFees, prevHash)) + return DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%" PRI64d " vs limit=%" PRI64d ")", vtx[0].GetValueOut(), GetProofOfWorkReward(pindex->nHeight, nFees, prevHash))); // Update block index on disk without changing it in memory. // The memory index structure will be changed after the db commits. @@ -1737,8 +1737,8 @@ 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; @@ -1869,7 +1869,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) } if (!vpindexSecondary.empty()) - printf("Postponing %"PRIszu" reconnects\n", vpindexSecondary.size()); + printf("Postponing %" PRIszu " reconnects\n", vpindexSecondary.size()); // Switch to new best branch if (!Reorganize(txdb, pindexIntermediate)) @@ -1983,7 +1983,7 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const bnCentSecond += CBigNum(nValueIn) * (nTime-txPrev.nTime) / CENT; if (fDebug && GetBoolArg("-printcoinage")) - printf("coin age nValueIn=%"PRI64d" nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString().c_str()); + printf("coin age nValueIn=%" PRI64d " nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString().c_str()); } CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); @@ -2011,7 +2011,7 @@ bool CBlock::GetCoinAge(uint64& nCoinAge) const if (nCoinAge == 0) // block coin age minimum 1 coin-day nCoinAge = 1; if (fDebug && GetBoolArg("-printcoinage")) - printf("block coin age total nCoinDays=%"PRI64d"\n", nCoinAge); + printf("block coin age total nCoinDays=%" PRI64d "\n", nCoinAge); return true; } @@ -2057,7 +2057,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) pindexNew->SetStakeModifier(nStakeModifier, fGeneratedStakeModifier); pindexNew->nStakeModifierChecksum = GetStakeModifierChecksum(pindexNew); if (!CheckStakeModifierCheckpoints(pindexNew->nHeight, pindexNew->nStakeModifierChecksum)) - return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindexNew->nHeight, nStakeModifier); + return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016" PRI64x, pindexNew->nHeight, nStakeModifier); // Add to mapBlockIndex map::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; @@ -2135,7 +2135,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const // Check coinstake timestamp if (!CheckCoinStakeTimestamp(GetBlockTime(), (int64)vtx[1].nTime)) - return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%"PRI64d" nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); + return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%" PRI64d " nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); } // Check transactions @@ -2181,29 +2181,29 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const bool CBlock::AcceptBlockFast() { - // Check for duplicate - uint256 hash = GetHash(); - if (mapBlockIndex.count(hash)) - return error("AcceptBlock() : block already in mapBlockIndex"); + // Check for duplicate + uint256 hash = GetHash(); + if (mapBlockIndex.count(hash)) + return error("AcceptBlock() : block already in mapBlockIndex"); - // Get prev block index - map::iterator mi = mapBlockIndex.find(hashPrevBlock); - if (mi == mapBlockIndex.end()) - return DoS(10, error("AcceptBlock() : prev block not found")); + // Get prev block index + map::iterator mi = mapBlockIndex.find(hashPrevBlock); + if (mi == mapBlockIndex.end()) + return DoS(10, error("AcceptBlock() : prev block not found")); - // Write block to history file - if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION))) - return error("AcceptBlock() : out of disk space"); - unsigned int nFile = -1; - unsigned int nBlockPos = 0; - if (!WriteToDisk(nFile, nBlockPos)) - return error("AcceptBlock() : WriteToDisk failed"); - if (!AddToBlockIndex(nFile, nBlockPos)) - return error("AcceptBlock() : AddToBlockIndex failed"); + // Write block to history file + if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION))) + return error("AcceptBlock() : out of disk space"); + unsigned int nFile = -1; + unsigned int nBlockPos = 0; + if (!WriteToDisk(nFile, nBlockPos)) + return error("AcceptBlock() : WriteToDisk failed"); + if (!AddToBlockIndex(nFile, nBlockPos)) + return error("AcceptBlock() : AddToBlockIndex failed"); - return true; + return true; } @@ -2220,10 +2220,10 @@ bool CBlock::AcceptBlock() return DoS(10, error("AcceptBlock() : prev block not found")); CBlockIndex* pindexPrev = (*mi).second; int nHeight = pindexPrev->nHeight+1; - + if (IsProofOfWork() && nHeight > LAST_POW_BLOCK) return DoS(100, error("AcceptBlock() : reject proof-of-work at height %d", nHeight)); - + // Check proof-of-work or proof-of-stake if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake())) return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); @@ -2298,51 +2298,51 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns bool ProcessBlockFast(CNode* pfrom, CBlock* pblock) { - // Check for duplicate - uint256 hash = pblock->GetHash(); - if (mapBlockIndex.count(hash)) - return error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString().substr(0, 20).c_str()); - if (mapOrphanBlocks.count(hash)) - return error("ProcessBlock() : already have block (orphan) %s", hash.ToString().substr(0, 20).c_str()); - - // ppcoin: verify hash target and signature of coinstake tx - if (pblock->IsProofOfStake()) - { - uint256 hashProofOfStake = 0, targetProofOfStake = 0; - if (!CheckProofOfStake(pblock->vtx[1], pblock->nBits, hashProofOfStake, targetProofOfStake)) - { - printf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str()); - return false; // do not error here as we expect this during initial block download - } - if (!mapProofOfStake.count(hash)) // add to mapProofOfStake - mapProofOfStake.insert(make_pair(hash, hashProofOfStake)); - } - - // Store to disk - if (!pblock->AcceptBlockFast()) - return error("ProcessBlock() : AcceptBlock FAILED"); - - // Recursively process any orphan blocks that depended on this one - vector vWorkQueue; - vWorkQueue.push_back(hash); - for (unsigned int i = 0; i < vWorkQueue.size(); i++) - { - uint256 hashPrev = vWorkQueue[i]; - for (multimap::iterator mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); - mi != mapOrphanBlocksByPrev.upper_bound(hashPrev); - ++mi) - { - CBlock* pblockOrphan = (*mi).second; - if (pblockOrphan->AcceptBlockFast()) - vWorkQueue.push_back(pblockOrphan->GetHash()); - mapOrphanBlocks.erase(pblockOrphan->GetHash()); - setStakeSeenOrphan.erase(pblockOrphan->GetProofOfStake()); - delete pblockOrphan; - } - mapOrphanBlocksByPrev.erase(hashPrev); - } - - return true; + // Check for duplicate + uint256 hash = pblock->GetHash(); + if (mapBlockIndex.count(hash)) + return error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString().substr(0, 20).c_str()); + if (mapOrphanBlocks.count(hash)) + return error("ProcessBlock() : already have block (orphan) %s", hash.ToString().substr(0, 20).c_str()); + + // ppcoin: verify hash target and signature of coinstake tx + if (pblock->IsProofOfStake()) + { + uint256 hashProofOfStake = 0, targetProofOfStake = 0; + if (!CheckProofOfStake(pblock->vtx[1], pblock->nBits, hashProofOfStake, targetProofOfStake)) + { + printf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str()); + return false; // do not error here as we expect this during initial block download + } + if (!mapProofOfStake.count(hash)) // add to mapProofOfStake + mapProofOfStake.insert(make_pair(hash, hashProofOfStake)); + } + + // Store to disk + if (!pblock->AcceptBlockFast()) + return error("ProcessBlock() : AcceptBlock FAILED"); + + // Recursively process any orphan blocks that depended on this one + vector vWorkQueue; + vWorkQueue.push_back(hash); + for (unsigned int i = 0; i < vWorkQueue.size(); i++) + { + uint256 hashPrev = vWorkQueue[i]; + for (multimap::iterator mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); + mi != mapOrphanBlocksByPrev.upper_bound(hashPrev); + ++mi) + { + CBlock* pblockOrphan = (*mi).second; + if (pblockOrphan->AcceptBlockFast()) + vWorkQueue.push_back(pblockOrphan->GetHash()); + mapOrphanBlocks.erase(pblockOrphan->GetHash()); + setStakeSeenOrphan.erase(pblockOrphan->GetProofOfStake()); + delete pblockOrphan; + } + mapOrphanBlocksByPrev.erase(hashPrev); + } + + return true; } bool ProcessBlock(CNode* pfrom, CBlock* pblock) @@ -2602,7 +2602,7 @@ bool CBlock::CheckBlockSignature() const bool CheckDiskSpace(uint64 nAdditionalBytes) { - uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; + uint64 nFreeBytesAvailable = boost::filesystem::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) @@ -2619,7 +2619,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) } -static filesystem::path BlockFilePath(unsigned int nFile) +static boost::filesystem::path BlockFilePath(unsigned int nFile) { string strBlockFn = strprintf("blk%04u.dat", nFile); return GetDataDir() / strBlockFn; @@ -2682,7 +2682,7 @@ bool LoadBlockIndex(bool fAllowNew) bnProofOfWorkLimit = bnProofOfWorkLimitTestNet; // 0x0000ffff PoW base target is fixed in testnet nStakeMinAge = 10 * 60; // testnet min age 10 min nStakeMaxAge = 60 * 60; // testnet min age 60 min - nModifierInterval = 60; // test modifier interval is 2 minutes + nModifierInterval = 60; // test modifier interval is 2 minutes nCoinbaseMaturity = 10; // test maturity is 10 blocks nStakeTargetSpacing = 60; // testnet spacing 1 minute } @@ -2710,7 +2710,7 @@ bool LoadBlockIndex(bool fAllowNew) txNew.vout.resize(1); txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(9999) << vector((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); txNew.vout[0].SetEmpty(); - txNew.strTxComment = "text:Philosopherstone genesis block"; + txNew.strTxComment = "text:Philosopherstone genesis block"; CBlock block; block.vtx.push_back(txNew); @@ -2729,7 +2729,7 @@ bool LoadBlockIndex(bool fAllowNew) printf("block.nNonce = %u \n", block.nNonce); assert(block.hashMerkleRoot == uint256("0xde1c576dae6f20985090b8553540147882c024d313dc46f7bd92003f9ad07cea")); - assert(block.GetHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet)); + assert(block.GetHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet)); // Start new block file unsigned int nFile; @@ -2809,7 +2809,7 @@ void PrintBlockTree() // print item CBlock block; block.ReadFromDisk(pindex); - printf("%d (%u,%u) %s %08x %s mint %7s tx %"PRIszu"", + printf("%d (%u,%u) %s %08x %s mint %7s tx %" PRIszu "", pindex->nHeight, pindex->nFile, pindex->nBlockPos, @@ -2894,7 +2894,7 @@ bool LoadExternalBlockFile(FILE* fileIn) __PRETTY_FUNCTION__); } } - printf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); + printf("Loaded %i blocks from external file in %" PRI64d "ms\n", nLoaded, GetTimeMillis() - nStart); return nLoaded > 0; } @@ -2942,12 +2942,12 @@ string GetWarnings(string strFor) // * Should not enter safe mode for longer invalid chain // * If sync-checkpoint is too old do not enter safe mode // * Display warning only in the STRICT mode - if (CheckpointsMode == Checkpoints::STRICT && Checkpoints::IsSyncCheckpointTooOld(60 * 60 * 24 * 10) && - !fTestNet && !IsInitialBlockDownload()) - { - nPriority = 100; - strStatusBar = _("WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers."); - } +// if (CheckpointsMode == Checkpoints::STRICT && Checkpoints::IsSyncCheckpointTooOld(60 * 60 * 24 * 10) && +// !fTestNet && !IsInitialBlockDownload()) +// { +// nPriority = 100; +// strStatusBar = _("WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers."); +// } // * If detected invalid checkpoint enter safe mode if (Checkpoints::hashInvalidCheckpoint != 0) @@ -3026,7 +3026,7 @@ 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()); + 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"); @@ -3185,7 +3185,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vAddr.size() > 1000) { pfrom->Misbehaving(20); - return error("message addr size() = %"PRIszu"", vAddr.size()); + return error("message addr size() = %" PRIszu "", vAddr.size()); } // Store the new addresses @@ -3248,7 +3248,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) 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 @@ -3298,11 +3298,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) 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()); + printf("received getdata (%" PRIszu " invsz)\n", vInv.size()); BOOST_FOREACH(const CInv& inv, vInv) { @@ -3927,7 +3927,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!vInv.empty()) pto->PushMessage("inv", vInv); - // // Message: getdata // @@ -3957,9 +3956,3 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } return true; } - - - - - - diff --git a/src/main.h b/src/main.h index 47d18ce..4476e08 100644 --- a/src/main.h +++ b/src/main.h @@ -40,8 +40,8 @@ static const int64 MIN_RELAY_TX_FEE = 0.1 * CENT; static const int64 MAX_MONEY = 2000000000 * COIN; static const int64 MAX_MINT_PROOF_OF_WORK = 64 * COIN; static const int64 MAX_MINT_PROOF_OF_WORK_LEGACY = 64 * COIN; -static const int64 MAX_MINT_PROOF_OF_STAKE = 0.50 * MAX_MINT_PROOF_OF_WORK; // 50% annual interest -static const unsigned int RWD_SWITCH_TIME = 1376006400; // August 9, 2013 00:00:00 GMT +static const int64 MAX_MINT_PROOF_OF_STAKE = 0.50 * MAX_MINT_PROOF_OF_WORK; // 50% annual interest +static const unsigned int RWD_SWITCH_TIME = 1376006400; // August 9, 2013 00:00:00 GMT /** Split/Combine Threshold Max */ static const int64 MAX_SPLIT_AMOUNT = 200 * COIN; static const int64 MAX_COMBINE_AMOUNT = MAX_SPLIT_AMOUNT; @@ -60,7 +60,6 @@ inline int64 FutureDrift(int64 nTime) { return nTime + 2 * 60 * 60; } // up to 2 extern CScript COINBASE_FLAGS; - extern CCriticalSection cs_main; extern std::map mapBlockIndex; extern std::set > setStakeSeen; @@ -100,7 +99,6 @@ extern bool fEnforceCanonical; // Minimum disk space required - used in CheckDiskSpace() static const uint64 nMinDiskSpace = 52428800; - class CReserveKey; class CTxDB; class CTxIndex; @@ -134,15 +132,6 @@ void BitcoinMiner(CWallet *pwallet); void StakeMiner(CWallet *pwallet); void ResendWalletTransactions(bool fForce = false); - - - - - - - - - bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); /** Position on disk for a particular transaction. */ @@ -659,15 +648,15 @@ class CTransaction { std::string str; str += IsCoinBase()? "Coinbase" : (IsCoinStake()? "Coinstake" : "CTransaction"); - str += strprintf("(hash=%s, nTime=%d, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%d)\n", + str += strprintf("(hash=%s, nTime=%d, ver=%d, vin.size=%" PRIszu ", vout.size=%" PRIszu ", nLockTime=%d, strTxComment=%s)\n", GetHash().ToString().substr(0,10).c_str(), nTime, nVersion, vin.size(), vout.size(), nLockTime, - strTxComment.substr(0,30).c_str() - ); + strTxComment.substr(0,30).c_str() + ); for (unsigned int i = 0; i < vin.size(); i++) str += " " + vin[i].ToString() + "\n"; @@ -1086,7 +1075,7 @@ class CBlock void print() const { - printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu", vchBlockSig=%s)\n", + printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%" PRIszu ", vchBlockSig=%s)\n", GetHash().ToString().c_str(), nVersion, hashPrevBlock.ToString().c_str(), @@ -1344,7 +1333,7 @@ class CBlockIndex std::string ToString() const { - return strprintf("CBlockIndex(nprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016"PRI64x", nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)", + return strprintf("CBlockIndex(nprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016" PRI64x ", nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)", pprev, pnext, nFile, nBlockPos, nHeight, FormatMoney(nMint).c_str(), FormatMoney(nMoneySupply).c_str(), GeneratedStakeModifier() ? "MOD" : "-", GetStakeEntropyBit(), IsProofOfStake()? "PoS" : "PoW", diff --git a/src/makefile.unix b/src/makefile.unix index 955aaf8..086b7c8 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -28,6 +28,7 @@ LIBS += \ -l boost_filesystem$(BOOST_LIB_SUFFIX) \ -l boost_program_options$(BOOST_LIB_SUFFIX) \ -l boost_thread$(BOOST_LIB_SUFFIX) \ + -l boost_chrono$(BOOST_LIB_SUFFIX) \ -l db_cxx$(BDB_LIB_SUFFIX) \ -l ssl \ -l crypto @@ -91,7 +92,7 @@ endif # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work. -xCXXFLAGS=-O2 $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \ +xCXXFLAGS=-O2 $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -std=c++11 \ $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only diff --git a/src/miner.cpp b/src/miner.cpp index b95032b..ea23daf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -355,7 +355,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) nLastBlockSize = nBlockSize; if (fDebug && GetBoolArg("-printpriority")) - printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize); + printf("CreateNewBlock(): total size %" PRI64u "\n", nBlockSize); if (!fProofOfStake) pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pindexPrev->nHeight+1, nFees, pindexPrev->GetBlockHash()); @@ -598,7 +598,7 @@ void StakeMiner(CWallet *pwallet) if (fTryToSync) { fTryToSync = false; - if (vNodes.size() < 3 || nBestHeight < GetNumBlocksOfPeers()) + if (vNodes.size() < 2 || nBestHeight < GetNumBlocksOfPeers()) { MilliSleep(60000); continue; diff --git a/src/net.cpp b/src/net.cpp index 70edaec..e407573 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1073,14 +1073,6 @@ void ThreadSocketHandler2(void* parg) } } - - - - - - - - #ifdef USE_UPNP void ThreadMapPort(void* parg) { @@ -1116,10 +1108,14 @@ void ThreadMapPort2(void* parg) #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0); -#else +#elif MINIUPNPC_API_VERSION < 14 /* miniupnpc 1.6 */ int error = 0; devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error); +#else + /* miniupnpc 1.9 */ + int error = 0; + devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error); #endif struct UPNPUrls urls; @@ -1164,7 +1160,7 @@ void ThreadMapPort2(void* parg) printf("UPnP Port Mapping successful.\n"); int i = 1; while (true) - { + { if (fShutdown || !fUseUPnP) { r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); @@ -1200,7 +1196,7 @@ void ThreadMapPort2(void* parg) if (r != 0) FreeUPNPUrls(&urls); while (true) - { + { if (fShutdown || !fUseUPnP) return; MilliSleep(2000); @@ -1223,24 +1219,14 @@ void MapPort() } #endif - - - - - - - - // DNS seeds // Each pair gives a source name and a seed name. // The first name is used as information source for addrman. // The second name should resolve to a list of seed addresses. static const char *strDNSSeed[][2] = { - { "main", "host1.philosopherstones.org" }, - { "node1", "node1.philosopherstones.org" }, - { "node2", "node2.philosopherstones.org" }, - { "node3", "node3.philosopherstones.org" }, - { "node4", "node4.philosopherstones.org" }, + { "node1", "node1.phs.ovh" }, + { "node2", "node2.phs.ovh" }, + { "node3", "node3.phs.ovh" }, }; void ThreadDNSAddressSeed(void* parg) @@ -1298,17 +1284,6 @@ void ThreadDNSAddressSeed2(void* parg) printf("%d addresses found from DNS seeds\n", found); } - - - - - - - - - - - unsigned int pnSeed[] = { }; @@ -1320,7 +1295,7 @@ void DumpAddresses() CAddrDB adb; adb.Write(addrman); - printf("Flushed %d addresses to peers.dat %"PRI64d"ms\n", + printf("Flushed %d addresses to peers.dat %" PRI64d "ms\n", addrman.size(), GetTimeMillis() - nStart); } diff --git a/src/net.h b/src/net.h index 8db0806..a698036 100644 --- a/src/net.h +++ b/src/net.h @@ -389,7 +389,7 @@ class CNode // 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()); + 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/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index c0e0791..b93d046 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -726,7 +726,8 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks) } // Set icon state: spinning if catching up, tick otherwise - if(secs < 90*60 && count >= nTotalBlocks) +// if(secs < 90*60 && count >= nTotalBlocks) + if(count >= nTotalBlocks) { tooltip = tr("Up to date") + QString(".
") + tooltip; labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); @@ -1332,7 +1333,7 @@ void BitcoinGUI::updateStakingIcon() if (!clientModel->getNumConnections()) labelStakingIcon->setToolTip(tr("Not staking because wallet is offline")); - else if (clientModel->getNumConnections() < 3 ) + else if (clientModel->getNumConnections() < 2 ) labelStakingIcon->setToolTip(tr("Not staking because wallet is still acquiring nodes")); else if (clientModel->inInitialBlockDownload() || clientModel->getNumBlocks() < clientModel->getNumBlocksOfPeers()) labelStakingIcon->setToolTip(tr("Not staking because wallet is syncing")); diff --git a/src/qt/bitcoinstrings.cpp b/src/qt/bitcoinstrings.cpp index ad256d5..2ef19d7 100644 --- a/src/qt/bitcoinstrings.cpp +++ b/src/qt/bitcoinstrings.cpp @@ -10,7 +10,7 @@ QT_TRANSLATE_NOOP("bitcoin-core", "" "%s, you must set a rpcpassword in the configuration file:\n" " %s\n" "It is recommended you use the following random password:\n" -"rpcuser=bitcoinrpc\n" +"rpcuser=phsrpc\n" "rpcpassword=%s\n" "(you do not need to remember this password)\n" "If the file does not exist, create it with owner-readable-only file " @@ -172,4 +172,4 @@ QT_TRANSLATE_NOOP("bitcoin-core", "Wallet needed to be rewritten: restart Philos QT_TRANSLATE_NOOP("bitcoin-core", "Warning: Disk space is low!"), QT_TRANSLATE_NOOP("bitcoin-core", "Warning: This version is obsolete, upgrade required!"), QT_TRANSLATE_NOOP("bitcoin-core", "wallet.dat corrupt, salvage failed"), -}; \ No newline at end of file +}; diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 38445c9..cee9ea1 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -246,14 +246,14 @@ void ClientModel::subscribeToCoreSignals() { // Connect signals to client uiInterface.NotifyBlocksChanged.connect(boost::bind(NotifyBlocksChanged, this)); - uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1)); - uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2)); + uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, boost::placeholders::_1)); + uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, boost::placeholders::_1, boost::placeholders::_2)); } void ClientModel::unsubscribeFromCoreSignals() { // Disconnect signals from client uiInterface.NotifyBlocksChanged.disconnect(boost::bind(NotifyBlocksChanged, this)); - uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1)); - uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2)); + uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, boost::placeholders::_1)); + uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, boost::placeholders::_1, boost::placeholders::_2)); } diff --git a/src/qt/qcustomplot.cpp b/src/qt/qcustomplot.cpp index 6f6ba14..ca3a62c 100644 --- a/src/qt/qcustomplot.cpp +++ b/src/qt/qcustomplot.cpp @@ -25,9 +25,6 @@ #include "qcustomplot.h" - - - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPainter //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/qt/qcustomplot.h b/src/qt/qcustomplot.h index e8b34ef..d01b824 100644 --- a/src/qt/qcustomplot.h +++ b/src/qt/qcustomplot.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/qt/res/text/style.qss b/src/qt/res/text/style.qss index 17f099e..f80e59a 100644 --- a/src/qt/res/text/style.qss +++ b/src/qt/res/text/style.qss @@ -35,7 +35,7 @@ QLineEdit,QLineEdit:disabled{border: 1px solid orange;color: white;} QTableView { color: #ffffff; border-style: none; selection-background-color: #ffffff; alternate-background-color: #121f1f; selection-color: #000000 ; border: 0px solid black;} QHeaderView { color: #ffffff; background-color: #000000; background-image: none;} -QHeaderView::section { color: #fffffff; background-color: #121f1f;} +QHeaderView::section { color: #ffffff; background-color: #121f1f;} QHeaderView::section:checked { background-color: #121f1f ;} QTabWidget:focus, QCheckBox:focus, QRadioButton:focus{ border: none; background-color: #1b2f2f; background: #1b2f2f;} @@ -58,4 +58,4 @@ QComboBox QAbstractItemView { color: #ffffff; selection-background-color: #fffff color: #ffffff; font: 75 bold 10pt; background: #1b2f2f; -background-image: url(:/Background/res/images/11.png); \ No newline at end of file +background-image: url(:/Background/res/images/11.png); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index b1fd4f3..b6afe06 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -377,17 +377,17 @@ static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, void WalletModel::subscribeToCoreSignals() { // Connect signals to wallet - wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1)); - wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5)); - wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3)); + wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, boost::placeholders::_1)); + wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4, boost::placeholders::_5)); + wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3)); } void WalletModel::unsubscribeFromCoreSignals() { // Disconnect signals from wallet - wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1)); - wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5)); - wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3)); + wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, boost::placeholders::_1)); + wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, boost::placeholders::_4, boost::placeholders::_5)); + wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3)); } // WalletModel::UnlockContext implementation diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e28f1ae..db06e3c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -94,7 +94,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPri result.push_back(Pair("flags", strprintf("%s%s", blockindex->IsProofOfStake()? "proof-of-stake" : "proof-of-work", blockindex->GeneratedStakeModifier()? " stake-modifier": ""))); result.push_back(Pair("proofhash", blockindex->IsProofOfStake()? blockindex->hashProofOfStake.GetHex() : blockindex->GetBlockHash().GetHex())); result.push_back(Pair("entropybit", (int)blockindex->GetStakeEntropyBit())); - result.push_back(Pair("modifier", strprintf("%016"PRI64x, blockindex->nStakeModifier))); + result.push_back(Pair("modifier", strprintf("%016" PRI64x, blockindex->nStakeModifier))); result.push_back(Pair("modifierchecksum", strprintf("%08x", blockindex->nStakeModifierChecksum))); Array txinfo; BOOST_FOREACH (const CTransaction& tx, block.vtx) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 571bd0c..521e0e7 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -52,7 +52,7 @@ Value getpeerinfo(const Array& params, 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("%08" PRI64x, stats.nServices))); obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected)); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index a817d8f..0f4eb07 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -46,7 +46,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); - entry.push_back(Pair("tx-comment", wtx.strTxComment)); + entry.push_back(Pair("tx-comment", wtx.strTxComment)); entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); @@ -89,7 +89,6 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput",ValueFromAmount(nMinimumInputValue))); - obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("encrypted", pwalletMain->IsCrypted())); if (pwalletMain->IsCrypted() && !pwalletMain->IsLocked() ) { @@ -100,7 +99,7 @@ Value getinfo(const Array& params, bool fHelp) { obj.push_back(Pair("unlocked_until", "Locked")); } - obj.push_back(Pair("errors", GetWarnings("statusbar"))); + obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; } @@ -316,7 +315,7 @@ Value sendtoaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "sendtoaddress [comment] [comment-to] [tx-comment]\n" + "sendtoaddress [comment] [comment-to] [tx-comment]\n" " is a real and is rounded to the nearest 0.000001" + HelpRequiringPassphrase()); @@ -337,14 +336,14 @@ Value sendtoaddress(const Array& params, bool fHelp) if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) wtx.mapValue["to"] = params[3].get_str(); - // Transaction comment - std::string txcomment; + // Transaction comment + std::string txcomment; if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty()) - { + { txcomment = params[4].get_str(); - if (txcomment.length() > MAX_TX_COMMENT_LEN) - txcomment.resize(MAX_TX_COMMENT_LEN); - } + if (txcomment.length() > MAX_TX_COMMENT_LEN) + txcomment.resize(MAX_TX_COMMENT_LEN); + } if (pwalletMain->IsLocked()) @@ -690,7 +689,7 @@ Value sendfrom(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 7) throw runtime_error( - "sendfrom [minconf=1] [comment] [comment-to] [tx-comment]\n" + "sendfrom [minconf=1] [comment] [comment-to] [tx-comment]\n" " is a real and is rounded to the nearest 0.000001" + HelpRequiringPassphrase()); @@ -714,13 +713,13 @@ Value sendfrom(const Array& params, bool fHelp) if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty()) wtx.mapValue["to"] = params[5].get_str(); - std::string txcomment; + std::string txcomment; if (params.size() > 6 && params[6].type() != null_type && !params[6].get_str().empty()) - { + { txcomment = params[6].get_str(); - if (txcomment.length() > MAX_TX_COMMENT_LEN) - txcomment.resize(MAX_TX_COMMENT_LEN); - } + if (txcomment.length() > MAX_TX_COMMENT_LEN) + txcomment.resize(MAX_TX_COMMENT_LEN); + } EnsureWalletIsUnlocked(); @@ -742,7 +741,7 @@ Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 5) throw runtime_error( - "sendmany {address:amount,...} [minconf=1] [comment] [tx-cmments]\n" + "sendmany {address:amount,...} [minconf=1] [comment] [tx-cmments]\n" "amounts are double-precision floating point numbers" + HelpRequiringPassphrase()); @@ -753,18 +752,18 @@ Value sendmany(const Array& params, bool fHelp) nMinDepth = params[2].get_int(); CWalletTx wtx; - std::string strTxComment; - + std::string strTxComment; + wtx.strFromAccount = strAccount; if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) wtx.mapValue["comment"] = params[3].get_str(); - if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty()) - { - strTxComment = params[4].get_str(); - if (strTxComment.length() > MAX_TX_COMMENT_LEN) - strTxComment.resize(MAX_TX_COMMENT_LEN); - } + if (params.size() > 4 && params[4].type() != null_type && !params[4].get_str().empty()) + { + strTxComment = params[4].get_str(); + if (strTxComment.length() > MAX_TX_COMMENT_LEN) + strTxComment.resize(MAX_TX_COMMENT_LEN); + } set setAddress; @@ -839,7 +838,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) 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)); + "(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++) diff --git a/src/script.cpp b/src/script.cpp index 4b68af1..e7ef2f6 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -778,11 +778,6 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_ADD: case OP_SUB: - case OP_MUL: - case OP_DIV: - case OP_MOD: - case OP_LSHIFT: - case OP_RSHIFT: case OP_BOOLAND: case OP_BOOLOR: case OP_NUMEQUAL: @@ -811,33 +806,6 @@ bool EvalScript(vector >& stack, const CScript& script, co bn = bn1 - bn2; break; - case OP_MUL: - if (!BN_mul(&bn, &bn1, &bn2, pctx)) - return false; - break; - - case OP_DIV: - if (!BN_div(&bn, NULL, &bn1, &bn2, pctx)) - return false; - break; - - case OP_MOD: - if (!BN_mod(&bn, &bn1, &bn2, pctx)) - return false; - break; - - case OP_LSHIFT: - if (bn2 < bnZero || bn2 > CBigNum(2048)) - return false; - bn = bn1 << bn2.getulong(); - break; - - case OP_RSHIFT: - if (bn2 < bnZero || bn2 > CBigNum(2048)) - return false; - bn = bn1 >> bn2.getulong(); - break; - case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break; case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break; case OP_NUMEQUAL: bn = (bn1 == bn2); break; diff --git a/src/script.h b/src/script.h index da0790e..c6bc9d4 100644 --- a/src/script.h +++ b/src/script.h @@ -273,6 +273,12 @@ class CScript : public std::vector CScript(const unsigned char* pbegin, const unsigned char* pend) : std::vector(pbegin, pend) { } #endif + CScript &operator=(const CScript &b) { + clear(); + insert(begin(), b.begin(), b.end()); + return(*this); + } + CScript& operator+=(const CScript& b) { insert(end(), b.begin(), b.end()); diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index 66b29ce..3a6cbdf 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -35,27 +35,27 @@ static leveldb::Options GetOptions() { void init_blockindex(leveldb::Options& options, bool fRemoveOld = false) { // First time init. - filesystem::path directory = GetDataDir() / "txleveldb"; + boost::filesystem::path directory = GetDataDir() / "txleveldb"; if (fRemoveOld) { - filesystem::remove_all(directory); // remove directory + boost::filesystem::remove_all(directory); // remove directory unsigned int nFile = 1; while (true) { - filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile); + boost::filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile); // Break if no such file - if( !filesystem::exists( strBlockFile ) ) + if( !boost::filesystem::exists( strBlockFile ) ) break; - filesystem::remove(strBlockFile); + boost::filesystem::remove(strBlockFile); nFile++; } } - filesystem::create_directory(directory); + boost::filesystem::create_directory(directory); printf("Opening LevelDB in %s\n", directory.string().c_str()); leveldb::Status status = leveldb::DB::Open(options, directory.string(), &txdb); if (!status.ok()) { @@ -413,7 +413,7 @@ bool CTxDB::LoadBlockIndex() // NovaCoin: calculate stake modifier checksum pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex); if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum)) - return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindex->nHeight, pindex->nStakeModifier); + return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016" PRI64x, pindex->nHeight, pindex->nStakeModifier); } // Load hashBestChain pointer to end of best chain diff --git a/src/util.cpp b/src/util.cpp index 09bc4f8..406aec4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -399,7 +399,7 @@ string FormatMoney(int64 n, bool fPlus) int64 n_abs = (n > 0 ? n : -n); int64 quotient = n_abs/COIN; int64 remainder = n_abs%COIN; - string str = strprintf("%"PRI64d".%06"PRI64d, quotient, remainder); + string str = strprintf("%" PRI64d ".%06" PRI64d, quotient, remainder); // Right-trim excess zeros before the decimal point: int nTrim = 0; @@ -1323,7 +1323,7 @@ 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(); @@ -1358,10 +1358,10 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) } if (fDebug) { BOOST_FOREACH(int64 n, vSorted) - printf("%+"PRI64d" ", n); + printf("%+" PRI64d " ", n); printf("| "); } - printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + printf("nTimeOffset = %+" PRI64d " (%+" PRI64d " minutes)\n", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index dbab78a..131f09a 100644 --- a/src/util.h +++ b/src/util.h @@ -246,7 +246,7 @@ void runCommand(std::string strCommand); inline std::string i64tostr(int64 n) { - return strprintf("%"PRI64d, n); + return strprintf("%" PRI64d, n); } inline std::string itostr(int n) diff --git a/src/version.cpp b/src/version.cpp index f163b3f..7296fda 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -8,10 +8,10 @@ // Name of client reported in the 'version' message. Report the same name // for both bitcoind and bitcoin-qt, to make it harder for attackers to // target servers or GUI users specifically. -const std::string CLIENT_NAME("Satoshi"); +const std::string CLIENT_NAME("Philosopherstone"); // Client version number -#define CLIENT_VERSION_SUFFIX "b" +#define CLIENT_VERSION_SUFFIX "-noise23" // The following part of the code determines the CLIENT_BUILD variable. diff --git a/src/wallet.cpp b/src/wallet.cpp index 5fa5ce3..18e65a8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -122,7 +122,7 @@ bool CWallet::LoadCScript(const CScript& redeemScript) if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { std::string strAddr = CBitcoinAddress(redeemScript.GetID()).ToString(); - printf("%s: Warning: This wallet contains a redeemScript of size %"PRIszu" which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", + printf("%s: Warning: This wallet contains a redeemScript of size %" PRIszu " which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr.c_str()); return true; } @@ -900,7 +900,7 @@ void CWallet::ReacceptWalletTransactions() // 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()); + 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++) @@ -1565,7 +1565,7 @@ uint64 CWallet::GetStakeWeight(const CKeyStore& keystore, enum StakeWeightMode m } if (fDebug && GetBoolArg("-printcoinage")) - printf("StakeWeight bnCoinDay=%"PRI64d"\n", nCoinAge); + printf("StakeWeight bnCoinDay=%" PRI64d "\n", nCoinAge); return nCoinAge; } @@ -1705,7 +1705,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int } static int nMaxStakeSearchInterval = 60; - // printf(">> block.GetBlockTime() = %"PRI64d", nStakeMinAge = %d, txNew.nTime = %d\n", block.GetBlockTime(), nStakeMinAge,txNew.nTime); + // printf(">> block.GetBlockTime() = %" PRI64d ", nStakeMinAge = %d, txNew.nTime = %d\n", block.GetBlockTime(), nStakeMinAge,txNew.nTime); if (block.GetBlockTime() + nStakeMinAge2 > txNew.nTime - nMaxStakeSearchInterval) //PALM continue; // only count coins meeting min age requirement @@ -1776,7 +1776,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second)); nCredit += pcoin.first->vout[pcoin.second].nValue; - // printf(">> Wallet: CreateCoinStake: nCredit = %"PRI64d"\n", nCredit); + // printf(">> Wallet: CreateCoinStake: nCredit = %" PRI64d "\n", nCredit); vwtxPrev.push_back(pcoin.first); txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); @@ -1793,7 +1793,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int } if (nCredit == 0 || nCredit > nBalance - nReserveBalance) { - // printf(">> Wallet: CreateCoinStake: nCredit = %"PRI64d", nBalance = %"PRI64d", nReserveBalance = %"PRI64d"\n", nCredit, nBalance, nReserveBalance); + // printf(">> Wallet: CreateCoinStake: nCredit = %" PRI64d ", nBalance = %" PRI64d ", nReserveBalance = %" PRI64d "\n", nCredit, nBalance, nReserveBalance); return false; } @@ -2040,12 +2040,12 @@ void CWallet::PrintWallet(const CBlock& block) if (block.IsProofOfWork() && 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()); } if (block.IsProofOfStake() && mapWallet.count(block.vtx[1].GetHash())) { CWalletTx& wtx = mapWallet[block.vtx[1].GetHash()]; - printf(" stake: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit()); + printf(" stake: %d %d %" PRI64d "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit()); } } @@ -2108,7 +2108,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; } @@ -2138,7 +2138,7 @@ bool CWallet::TopUpKeyPool(unsigned int nSize) 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; @@ -2168,7 +2168,7 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); if (fDebug && GetBoolArg("-printkeypool")) - printf("keypool reserve %"PRI64d"\n", nIndex); + printf("keypool reserve %" PRI64d "\n", nIndex); } } @@ -2196,7 +2196,7 @@ void CWallet::KeepKey(int64 nIndex) walletdb.ErasePool(nIndex); } if(fDebug) - printf("keypool keep %"PRI64d"\n", nIndex); + printf("keypool keep %" PRI64d "\n", nIndex); } void CWallet::ReturnKey(int64 nIndex) @@ -2207,7 +2207,7 @@ void CWallet::ReturnKey(int64 nIndex) setKeyPool.insert(nIndex); } if(fDebug) - printf("keypool return %"PRI64d"\n", nIndex); + printf("keypool return %" PRI64d "\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) diff --git a/src/walletdb.cpp b/src/walletdb.cpp index c39e0a8..beb48fc 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -258,7 +258,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, //// debug print //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str()); - //printf(" %12"PRI64d" %s %s %s\n", + //printf(" %12" PRI64d " %s %s %s\n", // wtx.vout[0].nValue, // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(), // wtx.hashBlock.ToString().substr(0,20).c_str(), @@ -587,7 +587,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); } } } @@ -611,20 +611,20 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) bitdb.mapFileUseCount.erase(wallet.strWalletFile); // Copy wallet.dat - filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; - filesystem::path pathDest(strDest); - if (filesystem::is_directory(pathDest)) + boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; + boost::filesystem::path pathDest(strDest); + if (boost::filesystem::is_directory(pathDest)) pathDest /= wallet.strWalletFile; try { #if BOOST_VERSION >= 104000 - filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists); + boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists); #else - filesystem::copy_file(pathSrc, pathDest); + boost::filesystem::copy_file(pathSrc, pathDest); #endif printf("copied wallet.dat to %s\n", pathDest.string().c_str()); return true; - } catch(const filesystem::filesystem_error &e) { + } catch(const boost::filesystem::filesystem_error &e) { printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); return false; } @@ -648,7 +648,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); @@ -667,7 +667,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);