From: CryptoManiac Date: Sun, 4 Oct 2015 21:27:58 +0000 (+0300) Subject: Merge pull request #247 from svost/CWallet.SetNull X-Git-Tag: nvc-v0.5.5~54 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=33d45ddc282cea089237530f08bb8368aa686ead;hp=44de02325859a145a260545159767e4cbd4ec938 Merge pull request #247 from svost/CWallet.SetNull CWallet: added SetNull() --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 89592f3..b10cee7 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1217,9 +1217,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "scaninput" && n > 1) ConvertTo(params[1]); - if (strMethod == "scaninput" && n > 2) ConvertTo(params[2]); - if (strMethod == "scaninput" && n > 3) ConvertTo(params[3]); + if (strMethod == "scaninput" && n > 0) ConvertTo(params[0]); if (strMethod == "sendalert" && n > 2) ConvertTo(params[2]); if (strMethod == "sendalert" && n > 3) ConvertTo(params[3]); diff --git a/src/makefile.bsd b/src/makefile.bsd index 29c497e..8be6835 100644 --- a/src/makefile.bsd +++ b/src/makefile.bsd @@ -88,9 +88,14 @@ LIBS+= \ DEBUGFLAGS=-g +xOPT_LEVEL=-O2 +ifeq (${USE_O3}, 1) + xOPT_LEVEL=-O3 +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=-O0 -msse2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \ +xCXXFLAGS=$(xOPT_LEVEL) -msse2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \ $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index c34e197..3c65af9 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -50,9 +50,14 @@ LIBS= \ -l crypto \ -Wl,-Bstatic -lpthread -Wl,-Bdynamic +xOPT_LEVEL=-O2 +ifeq (${USE_O3}, 1) + xOPT_LEVEL=-O3 +endif + DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS DEBUGFLAGS=-g -CFLAGS=-O2 -msse2 -w -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) +CFLAGS=$(xOPT_LEVEL) -msse2 -w -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -static-libgcc -static-libstdc++ ifndef USE_UPNP diff --git a/src/makefile.mingw b/src/makefile.mingw index 2f1dd90..c09ed6b 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -38,9 +38,14 @@ LIBS= \ -l ssl \ -l crypto +xOPT_LEVEL=-O2 +ifeq (${USE_O3}, 1) + xOPT_LEVEL=-O3 +endif + DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS DEBUGFLAGS=-g -CFLAGS=-mthreads -O2 -msse2 -w -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) +CFLAGS=-mthreads $(xOPT_LEVEL) -msse2 -w -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware -static ifndef USE_UPNP diff --git a/src/makefile.osx b/src/makefile.osx index 5aa9e9c..cd13d12 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -134,16 +134,16 @@ ifeq (${USE_ASM}, 1) OBJS += crypto/scrypt/asm/obj/scrypt-arm.o crypto/scrypt/asm/obj/scrypt-x86.o crypto/scrypt/asm/obj/scrypt-x86_64.o crypto/scrypt/asm/obj/asm-wrapper.o crypto/scrypt/asm/obj/scrypt-x86.o: crypto/scrypt/asm/scrypt-x86.S - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< crypto/scrypt/asm/obj/scrypt-x86_64.o: crypto/scrypt/asm/scrypt-x86_64.S - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< crypto/scrypt/asm/obj/scrypt-arm.o: crypto/scrypt/asm/scrypt-arm.S - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< crypto/scrypt/asm/obj/asm-wrapper.o: crypto/scrypt/asm/asm-wrapper.cpp - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< else ifeq (${USE_SSE2}, 1) # Intrinsic implementation @@ -151,13 +151,13 @@ DEFS += -DUSE_SSE2 OBJS += crypto/scrypt/intrin/obj/scrypt-sse2.o crypto/scrypt/intrin/obj/scrypt-sse2.o: crypto/scrypt/intrin/scrypt-sse2.cpp - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< else # Generic implementation OBJS += crypto/scrypt/generic/obj/scrypt-generic.o crypto/scrypt/generic/obj/scrypt-generic.o: crypto/scrypt/generic/scrypt-generic.cpp - $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< + $(CXX) -c $(CFLAGS) -MMD -o $@ $< endif endif diff --git a/src/makefile.unix b/src/makefile.unix index 708695d..bc06fc4 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -94,10 +94,14 @@ ifeq (${ARCH}, i686) EXT_OPTIONS=-msse2 endif +xOPT_LEVEL=-O2 +ifeq (${USE_O3}, 1) + xOPT_LEVEL=-O3 +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=$(xOPT_LEVEL) $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \ $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only diff --git a/src/ntp.cpp b/src/ntp.cpp index 5263c5a..527a02c 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -52,7 +52,7 @@ typedef struct { } l_fp; -inline void Ntp2Unix(uint32_t &n, time_t &u) { +inline void Ntp2Unix(const uint32_t &n, time_t &u) { // Ntp's time scale starts in 1900, Unix in 1970. u = n - 0x83aa7e80; // 2208988800 1970 - 1900 in seconds @@ -280,8 +280,9 @@ std::string NtpServers[162] = { // ... To be continued }; -bool InitWithHost(std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) { - sockfd = -1; +bool InitWithHost(const std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) { + + sockfd = INVALID_SOCKET; std::vector vIP; bool fRet = LookupHost(strHostName.c_str(), vIP, 10, true); @@ -295,7 +296,7 @@ bool InitWithHost(std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, bool found = false; for(unsigned int i = 0; i < vIP.size(); i++) { - if ((found = vIP[i].GetInAddr(&servaddr.sin_addr))) { + if ((found = vIP[i].GetInAddr(&servaddr.sin_addr)) != false) { break; } } @@ -415,7 +416,7 @@ int64_t NtpGetTime(CNetAddr& ip) { return nTime; } -int64_t NtpGetTime(std::string &strHostName) +int64_t NtpGetTime(const std::string &strHostName) { struct sockaddr cliaddr; diff --git a/src/ntp.h b/src/ntp.h index 6ec9191..8cf3be6 100644 --- a/src/ntp.h +++ b/src/ntp.h @@ -2,7 +2,7 @@ int64_t NtpGetTime(CNetAddr& ip); // Get time from provided server. -int64_t NtpGetTime(std::string &strHostName); +int64_t NtpGetTime(const std::string &strHostName); extern std::string strTrustedUpstream; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index a4f9680..63b4e37 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -11,6 +11,10 @@ #include "kernel.h" #include "bitcoinrpc.h" +#include +#include +#include + using namespace json_spirit; using namespace std; @@ -69,45 +73,85 @@ Value getmininginfo(const Array& params, bool fHelp) return obj; } +// scaninput '{"txid":"95d640426fe66de866a8cf2d0601d2c8cf3ec598109b4d4ffa7fd03dad6d35ce","difficulty":0.01, "days":10}' Value scaninput(const Array& params, bool fHelp) { - if (fHelp || params.size() > 4 || params.size() < 2) + if (fHelp || params.size() != 1) throw runtime_error( - "scaninput [difficulty] [days]\n" - "Scan specified input for suitable kernel solutions.\n" - " [difficulty] - upper limit for difficulty, current difficulty by default;\n" - " [days] - time window, 365 days by default.\n" + "scaninput {\"txid\":txid, \"vout\":[vout1, vout2, ..., voutN], \"difficulty\":difficulty, \"days\":days}\n" + "Scan specified transaction or input for suitable kernel solutions.\n" + " difficulty - upper limit for difficulty, current difficulty by default;\n" + " days - time window, 90 days by default.\n" ); + RPCTypeCheck(params, boost::assign::list_of(obj_type)); + + Object scanParams = params[0].get_obj(); + + const Value& txid_v = find_value(scanParams, "txid"); + if (txid_v.type() != str_type) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing txid key"); - uint256 hash; - hash.SetHex(params[0].get_str()); + string txid = txid_v.get_str(); + if (!IsHex(txid)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid"); - uint32_t nOut = params[1].get_int(), nBits = GetNextTargetRequired(pindexBest, true), nDays = 365; + uint256 hash(txid); + int32_t nDays = 90; + uint32_t nBits = GetNextTargetRequired(pindexBest, true); - if (params.size() > 2) + const Value& diff_v = find_value(scanParams, "difficulty"); + if (diff_v.type() == real_type) { + double dDiff = diff_v.get_real(); + if (dDiff <= 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, diff must be greater than zero"); + CBigNum bnTarget(nPoWBase); bnTarget *= 1000; - bnTarget /= (int) (params[2].get_real() * 1000); + bnTarget /= (int) (dDiff * 1000); nBits = bnTarget.GetCompact(); } - if (params.size() > 3) + const Value& days_v = find_value(scanParams, "days"); + if (days_v.type() == int_type) { - nDays = params[3].get_int(); + nDays = days_v.get_int(); + if (nDays <= 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, interval length must be greater than zero"); } + CTransaction tx; uint256 hashBlock = 0; if (GetTransaction(hash, tx, hashBlock)) { - if (nOut > tx.vout.size()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect output number"); - if (hashBlock == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to find transaction in the blockchain"); + vector vInputs(0); + const Value& inputs_v = find_value(scanParams, "vout"); + if (inputs_v.type() == array_type) + { + Array inputs = inputs_v.get_array(); + BOOST_FOREACH(const Value &v_out, inputs) + { + int nOut = v_out.get_int(); + if (nOut < 0 || nOut > (int)tx.vout.size() - 1) + { + stringstream strErrorMsg; + strErrorMsg << boost::format("Invalid parameter, input number %d is out of range") % nOut; + throw JSONRPCError(RPC_INVALID_PARAMETER, strErrorMsg.str()); + } + + vInputs.push_back(nOut); + } + } + else + { + vInputs = vector(boost::counting_iterator( 0 ), boost::counting_iterator( tx.vout.size() )); + } + CTxDB txdb("r"); CBlock block; @@ -130,36 +174,48 @@ Value scaninput(const Array& params, bool fHelp) // Only count coins meeting min age requirement if (nStakeMinAge + block.nTime > interval.first) interval.first += (nStakeMinAge + block.nTime - interval.first); - interval.second = interval.first + nDays * 86400; - - // Build static part of kernel - CDataStream ssKernel(SER_GETHASH, 0); - ssKernel << nStakeModifier; - ssKernel << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << tx.nTime << nOut; - CDataStream::const_iterator itK = ssKernel.begin(); + interval.second = interval.first + nDays * nOneDay; - std::vector > solutions; - if (ScanKernelForward((unsigned char *)&itK[0], nBits, tx.nTime, tx.vout[nOut].nValue, interval, solutions)) + Array results; + BOOST_FOREACH(const int &nOut, vInputs) { - Array results; - - BOOST_FOREACH(const PAIRTYPE(uint256, uint32_t) solution, solutions) + // Check for spent flag + // It doesn't make sense to scan spent inputs. + if (!txindex.vSpent[nOut].IsNull()) + continue; + + // Skip zero value outputs + if (tx.vout[nOut].nValue == 0) + continue; + + // Build static part of kernel + CDataStream ssKernel(SER_GETHASH, 0); + ssKernel << nStakeModifier; + ssKernel << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << tx.nTime << nOut; + CDataStream::const_iterator itK = ssKernel.begin(); + + std::vector > result; + if (ScanKernelForward((unsigned char *)&itK[0], nBits, tx.nTime, tx.vout[nOut].nValue, interval, result)) { - - Object item; - item.push_back(Pair("hash", solution.first.GetHex())); - item.push_back(Pair("time", DateTimeStrFormat(solution.second))); - - results.push_back(item); + BOOST_FOREACH(const PAIRTYPE(uint256, uint32_t) solution, result) + { + Object item; + item.push_back(Pair("nout", nOut)); + item.push_back(Pair("hash", solution.first.GetHex())); + item.push_back(Pair("time", DateTimeStrFormat(solution.second))); + + results.push_back(item); + } } - - return results; } + + if (results.size() == 0) + return false; + + return results; } else throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); - - return Value::null; } Value getworkex(const Array& params, bool fHelp)