diff options
137 files changed, 940 insertions, 1041 deletions
diff --git a/.gitignore b/.gitignore index bafc5919c1..c97432df92 100644 --- a/.gitignore +++ b/.gitignore @@ -99,7 +99,9 @@ linux-coverage-build linux-build win32-build qa/pull-tester/run-bitcoind-for-test.sh -qa/pull-tester/build-tests.sh +qa/pull-tester/tests-config.sh +qa/pull-tester/cache/* +qa/pull-tester/test.*/* !src/leveldb*/Makefile diff --git a/.travis.yml b/.travis.yml index 94d1c15f80..b685fbb5cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,17 +27,17 @@ matrix: - compiler: ": ARM" env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="NO_QT=1" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat CPPFLAGS=-DDEBUG_LOCKORDER" + env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat CPPFLAGS=-DDEBUG_LOCKORDER" - compiler: ": No wallet" env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" USE_SHELL="/bin/dash" + env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" USE_SHELL="/bin/dash" - compiler: ": Cross-Mac" env: HOST=x86_64-apple-darwin11 PACKAGES="gcc-multilib g++-multilib cmake libcap-dev libz-dev libbz2-dev" OSX_SDK=10.7 GOAL="deploy" - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine" RUN_TESTS=true GOAL="deploy" + env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine" RUN_TESTS=true GOAL="deploy" + env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" install: - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-upgrade -qq $PACKAGES; fi @@ -60,5 +60,6 @@ script: - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - if [ "$RUN_TESTS" = "true" ]; then make check; fi + - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.sh; fi after_script: - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi diff --git a/Makefile.am b/Makefile.am index 7fe3811476..6bc0044313 100644 --- a/Makefile.am +++ b/Makefile.am @@ -172,7 +172,7 @@ check-local: @qa/pull-tester/run-bitcoind-for-test.sh $(JAVA) -jar $(JAVA_COMPARISON_TOOL) qa/tmp/compTool $(COMPARISON_TOOL_REORG_TESTS) 2>&1 endif -EXTRA_DIST = $(top_srcdir)/share/genbuild.sh qa/pull-tester/pull-tester.sh qa/rpc-tests $(DIST_DOCS) $(WINDOWS_PACKAGING) $(OSX_PACKAGING) +EXTRA_DIST = $(top_srcdir)/share/genbuild.sh qa/pull-tester/rpc-tests.sh qa/pull-tester/run-bitcoin-cli qa/rpc-tests $(DIST_DOCS) $(WINDOWS_PACKAGING) $(OSX_PACKAGING) CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER) diff --git a/configure.ac b/configure.ac index b603d1766d..17efd987ac 100644 --- a/configure.ac +++ b/configure.ac @@ -824,7 +824,7 @@ AC_SUBST(MINIUPNPC_CPPFLAGS) AC_SUBST(MINIUPNPC_LIBS) AC_CONFIG_FILES([Makefile src/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py]) AC_CONFIG_FILES([qa/pull-tester/run-bitcoind-for-test.sh],[chmod +x qa/pull-tester/run-bitcoind-for-test.sh]) -AC_CONFIG_FILES([qa/pull-tester/build-tests.sh],[chmod +x qa/pull-tester/build-tests.sh]) +AC_CONFIG_FILES([qa/pull-tester/tests-config.sh],[chmod +x qa/pull-tester/tests-config.sh]) AC_OUTPUT dnl Taken from https://wiki.debian.org/RpathIssue diff --git a/doc/coding.md b/doc/coding.md index ceed8c18b4..b9d2006e3c 100644 --- a/doc/coding.md +++ b/doc/coding.md @@ -12,20 +12,6 @@ gradually. - No indentation for public/protected/private or for namespaces. - No extra spaces inside parenthesis; don't do ( this ) - No space after function names; one space after if, for and while. -- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp): -```c++ -#include "key.h" - -#include "crypto/sha2.h" -#include "util.h" - -#include <openssl/foo.h> -``` -- Class or struct keywords in header files need to be ordered alphabetically: -```c++ -class CAlpha; -class CBeta; -``` Block style example: ```c++ diff --git a/qa/pull-tester/build-tests.sh.in b/qa/pull-tester/build-tests.sh.in deleted file mode 100755 index f5c5f0bf70..0000000000 --- a/qa/pull-tester/build-tests.sh.in +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# Copyright (c) 2013-2014 The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -# -# Param1: The prefix to mingw staging -# Param2: Path to java comparison tool -# Param3: Number of make jobs. Defaults to 1. - -# Exit immediately if anything fails: -set -e -set -o xtrace - -MINGWPREFIX=$1 -JAVA_COMPARISON_TOOL=$2 -RUN_EXPENSIVE_TESTS=$3 -JOBS=${4-1} -OUT_DIR=${5-} - -if [ $# -lt 2 ]; then - echo "Usage: $0 [mingw-prefix] [java-comparison-tool] <make jobs> <save output dir>" - exit 1 -fi - -DISTDIR=@PACKAGE@-@VERSION@ - -# Cross-compile for windows first (breaking the mingw/windows build is most common) -cd @abs_top_srcdir@ -make distdir -mkdir -p win32-build -rsync -av $DISTDIR/ win32-build/ -rm -r $DISTDIR -cd win32-build - -if [ $RUN_EXPENSIVE_TESTS = 1 ]; then - ./configure --disable-silent-rules --disable-ccache --prefix=$MINGWPREFIX --host=i586-mingw32msvc --with-qt-bindir=$MINGWPREFIX/host/bin --with-qt-plugindir=$MINGWPREFIX/plugins --with-qt-incdir=$MINGWPREFIX/include --with-boost=$MINGWPREFIX --with-protoc-bindir=$MINGWPREFIX/host/bin CPPFLAGS=-I$MINGWPREFIX/include LDFLAGS=-L$MINGWPREFIX/lib --with-comparison-tool="$JAVA_COMPARISON_TOOL" -else - ./configure --disable-silent-rules --disable-ccache --prefix=$MINGWPREFIX --host=i586-mingw32msvc --with-qt-bindir=$MINGWPREFIX/host/bin --with-qt-plugindir=$MINGWPREFIX/plugins --with-qt-incdir=$MINGWPREFIX/include --with-boost=$MINGWPREFIX --with-protoc-bindir=$MINGWPREFIX/host/bin CPPFLAGS=-I$MINGWPREFIX/include LDFLAGS=-L$MINGWPREFIX/lib -fi -make -j$JOBS - -# And compile for Linux: -cd @abs_top_srcdir@ -make distdir -mkdir -p linux-build -rsync -av $DISTDIR/ linux-build/ -rm -r $DISTDIR -cd linux-build -if [ $RUN_EXPENSIVE_TESTS = 1 ]; then - ./configure --disable-silent-rules --disable-ccache --with-comparison-tool="$JAVA_COMPARISON_TOOL" --enable-comparison-tool-reorg-tests -else - ./configure --disable-silent-rules --disable-ccache --with-comparison-tool="$JAVA_COMPARISON_TOOL" -fi -make -j$JOBS - -# link interesting binaries to parent out/ directory, if it exists. Do this before -# running unit tests (we want bad binaries to be easy to find) -if [ -d "$OUT_DIR" -a -w "$OUT_DIR" ]; then - set +e - # Windows: - cp @abs_top_srcdir@/win32-build/src/bitcoind.exe $OUT_DIR/bitcoind.exe - cp @abs_top_srcdir@/win32-build/src/test/test_bitcoin.exe $OUT_DIR/test_bitcoin.exe - cp @abs_top_srcdir@/win32-build/src/qt/bitcoind-qt.exe $OUT_DIR/bitcoin-qt.exe - # Linux: - cp @abs_top_srcdir@/linux-build/src/bitcoind $OUT_DIR/bitcoind - cp @abs_top_srcdir@/linux-build/src/test/test_bitcoin $OUT_DIR/test_bitcoin - cp @abs_top_srcdir@/linux-build/src/qt/bitcoind-qt $OUT_DIR/bitcoin-qt - set -e -fi - -# Run unit tests and blockchain-tester on Linux: -cd @abs_top_srcdir@/linux-build -make check - -# Run RPC integration test on Linux: -@abs_top_srcdir@/qa/rpc-tests/wallet.sh @abs_top_srcdir@/linux-build/src -@abs_top_srcdir@/qa/rpc-tests/listtransactions.py --srcdir @abs_top_srcdir@/linux-build/src -@abs_top_srcdir@/qa/rpc-tests/forknotify.py --srcdir @abs_top_srcdir@/linux-build/src -# Clean up cache/ directory that the python regression tests create -rm -rf cache - -if [ $RUN_EXPENSIVE_TESTS = 1 ]; then - # Run unit tests and blockchain-tester on Windows: - cd @abs_top_srcdir@/win32-build - make check -fi - -# Clean up builds (pull-tester machine doesn't have infinite disk space) -cd @abs_top_srcdir@/linux-build -make clean -cd @abs_top_srcdir@/win32-build -make clean - -# TODO: Fix code coverage builds on pull-tester machine -# # Test code coverage -# cd @abs_top_srcdir@ -# make distdir -# mv $DISTDIR linux-coverage-build -# cd linux-coverage-build -# ./configure --enable-lcov --disable-silent-rules --disable-ccache --with-comparison-tool="$JAVA_COMPARISON_TOOL" -# make -j$JOBS -# make cov diff --git a/qa/pull-tester/pull-tester.py b/qa/pull-tester/pull-tester.py deleted file mode 100755 index 66688dd4b5..0000000000 --- a/qa/pull-tester/pull-tester.py +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2013-2014 The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -# -import json -from urllib import urlopen -import requests -import getpass -from string import Template -import sys -import os -import subprocess - -class RunError(Exception): - def __init__(self, value): - self.value = value - def __str__(self): - return repr(self.value) - -def run(command, **kwargs): - fail_hard = kwargs.pop("fail_hard", True) - # output to /dev/null by default: - kwargs.setdefault("stdout", open('/dev/null', 'w')) - kwargs.setdefault("stderr", open('/dev/null', 'w')) - command = Template(command).substitute(os.environ) - if "TRACE" in os.environ: - if 'cwd' in kwargs: - print("[cwd=%s] %s"%(kwargs['cwd'], command)) - else: print(command) - try: - process = subprocess.Popen(command.split(' '), **kwargs) - process.wait() - except KeyboardInterrupt: - process.terminate() - raise - if process.returncode != 0 and fail_hard: - raise RunError("Failed: "+command) - return process.returncode - -def checkout_pull(clone_url, commit, out): - # Init - build_dir=os.environ["BUILD_DIR"] - run("umount ${CHROOT_COPY}/proc", fail_hard=False) - run("rsync --delete -apv ${CHROOT_MASTER}/ ${CHROOT_COPY}") - run("rm -rf ${CHROOT_COPY}${SCRIPTS_DIR}") - run("cp -a ${SCRIPTS_DIR} ${CHROOT_COPY}${SCRIPTS_DIR}") - # Merge onto upstream/master - run("rm -rf ${BUILD_DIR}") - run("mkdir -p ${BUILD_DIR}") - run("git clone ${CLONE_URL} ${BUILD_DIR}") - run("git remote add pull "+clone_url, cwd=build_dir, stdout=out, stderr=out) - run("git fetch pull", cwd=build_dir, stdout=out, stderr=out) - if run("git merge "+ commit, fail_hard=False, cwd=build_dir, stdout=out, stderr=out) != 0: - return False - run("chown -R ${BUILD_USER}:${BUILD_GROUP} ${BUILD_DIR}", stdout=out, stderr=out) - run("mount --bind /proc ${CHROOT_COPY}/proc") - return True - -def commentOn(commentUrl, success, inMerge, needTests, linkUrl): - common_message = """ -This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ -Contact BlueMatt on freenode if something looks broken.""" - - # Remove old BitcoinPullTester comments (I'm being lazy and not paginating here) - recentcomments = requests.get(commentUrl+"?sort=created&direction=desc", - auth=(os.environ['GITHUB_USER'], os.environ["GITHUB_AUTH_TOKEN"])).json - for comment in recentcomments: - if comment["user"]["login"] == os.environ["GITHUB_USER"] and common_message in comment["body"]: - requests.delete(comment["url"], - auth=(os.environ['GITHUB_USER'], os.environ["GITHUB_AUTH_TOKEN"])) - - if success == True: - if needTests: - message = "Automatic sanity-testing: PLEASE ADD TEST-CASES, though technically passed. See " + linkUrl + " for binaries and test log." - else: - message = "Automatic sanity-testing: PASSED, see " + linkUrl + " for binaries and test log." - - post_data = { "body" : message + common_message} - elif inMerge: - post_data = { "body" : "Automatic sanity-testing: FAILED MERGE, see " + linkUrl + " for test log." + """ - -This pull does not merge cleanly onto current master""" + common_message} - else: - post_data = { "body" : "Automatic sanity-testing: FAILED BUILD/TEST, see " + linkUrl + " for binaries and test log." + """ - -This could happen for one of several reasons: -1. It chanages changes build scripts in a way that made them incompatible with the automated testing scripts (please tweak those patches in qa/pull-tester) -2. It adds/modifies tests which test network rules (thanks for doing that), which conflicts with a patch applied at test time -3. It does not build on either Linux i386 or Win32 (via MinGW cross compile) -4. The test suite fails on either Linux i386 or Win32 -5. The block test-cases failed (lookup the first bNN identifier which failed in https://github.com/TheBlueMatt/test-scripts/blob/master/FullBlockTestGenerator.java) - -If you believe this to be in error, please ping BlueMatt on freenode or TheBlueMatt here. -""" + common_message} - - resp = requests.post(commentUrl, json.dumps(post_data), auth=(os.environ['GITHUB_USER'], os.environ["GITHUB_AUTH_TOKEN"])) - -def testpull(number, comment_url, clone_url, commit): - print("Testing pull %d: %s : %s"%(number, clone_url,commit)) - - dir = os.environ["RESULTS_DIR"] + "/" + commit + "/" - print(" ouput to %s"%dir) - if os.path.exists(dir): - os.system("rm -r " + dir) - os.makedirs(dir) - currentdir = os.environ["RESULTS_DIR"] + "/current" - os.system("rm -r "+currentdir) - os.system("ln -s " + dir + " " + currentdir) - out = open(dir + "test.log", 'w+') - - resultsurl = os.environ["RESULTS_URL"] + commit - checkedout = checkout_pull(clone_url, commit, out) - if checkedout != True: - print("Failed to test pull - sending comment to: " + comment_url) - commentOn(comment_url, False, True, False, resultsurl) - open(os.environ["TESTED_DB"], "a").write(commit + "\n") - return - - run("rm -rf ${CHROOT_COPY}/${OUT_DIR}", fail_hard=False); - run("mkdir -p ${CHROOT_COPY}/${OUT_DIR}", fail_hard=False); - run("chown -R ${BUILD_USER}:${BUILD_GROUP} ${CHROOT_COPY}/${OUT_DIR}", fail_hard=False) - - script = os.environ["BUILD_PATH"]+"/qa/pull-tester/pull-tester.sh" - script += " ${BUILD_PATH} ${MINGW_DEPS_DIR} ${SCRIPTS_DIR}/BitcoindComparisonTool_jar/BitcoindComparisonTool.jar 0 6 ${OUT_DIR}" - returncode = run("chroot ${CHROOT_COPY} sudo -u ${BUILD_USER} -H timeout ${TEST_TIMEOUT} "+script, - fail_hard=False, stdout=out, stderr=out) - - run("mv ${CHROOT_COPY}/${OUT_DIR} " + dir) - run("mv ${BUILD_DIR} " + dir) - - if returncode == 42: - print("Successfully tested pull (needs tests) - sending comment to: " + comment_url) - commentOn(comment_url, True, False, True, resultsurl) - elif returncode != 0: - print("Failed to test pull - sending comment to: " + comment_url) - commentOn(comment_url, False, False, False, resultsurl) - else: - print("Successfully tested pull - sending comment to: " + comment_url) - commentOn(comment_url, True, False, False, resultsurl) - open(os.environ["TESTED_DB"], "a").write(commit + "\n") - -def environ_default(setting, value): - if not setting in os.environ: - os.environ[setting] = value - -if getpass.getuser() != "root": - print("Run me as root!") - sys.exit(1) - -if "GITHUB_USER" not in os.environ or "GITHUB_AUTH_TOKEN" not in os.environ: - print("GITHUB_USER and/or GITHUB_AUTH_TOKEN environment variables not set") - sys.exit(1) - -environ_default("CLONE_URL", "https://github.com/bitcoin/bitcoin.git") -environ_default("MINGW_DEPS_DIR", "/mnt/w32deps") -environ_default("SCRIPTS_DIR", "/mnt/test-scripts") -environ_default("CHROOT_COPY", "/mnt/chroot-tmp") -environ_default("CHROOT_MASTER", "/mnt/chroot") -environ_default("OUT_DIR", "/mnt/out") -environ_default("BUILD_PATH", "/mnt/bitcoin") -os.environ["BUILD_DIR"] = os.environ["CHROOT_COPY"] + os.environ["BUILD_PATH"] -environ_default("RESULTS_DIR", "/mnt/www/pull-tester") -environ_default("RESULTS_URL", "http://jenkins.bluematt.me/pull-tester/") -environ_default("GITHUB_REPO", "bitcoin/bitcoin") -environ_default("TESTED_DB", "/mnt/commits-tested.txt") -environ_default("BUILD_USER", "matt") -environ_default("BUILD_GROUP", "matt") -environ_default("TEST_TIMEOUT", str(60*60*2)) - -print("Optional usage: pull-tester.py 2112") - -f = open(os.environ["TESTED_DB"]) -tested = set( line.rstrip() for line in f.readlines() ) -f.close() - -if len(sys.argv) > 1: - pull = requests.get("https://api.github.com/repos/"+os.environ["GITHUB_REPO"]+"/pulls/"+sys.argv[1], - auth=(os.environ['GITHUB_USER'], os.environ["GITHUB_AUTH_TOKEN"])).json - testpull(pull["number"], pull["_links"]["comments"]["href"], - pull["head"]["repo"]["clone_url"], pull["head"]["sha"]) - -else: - for page in range(1,100): - result = requests.get("https://api.github.com/repos/"+os.environ["GITHUB_REPO"]+"/pulls?state=open&page=%d"%(page,), - auth=(os.environ['GITHUB_USER'], os.environ["GITHUB_AUTH_TOKEN"])).json - if len(result) == 0: break; - for pull in result: - if pull["head"]["sha"] in tested: - print("Pull %d already tested"%(pull["number"],)) - continue - testpull(pull["number"], pull["_links"]["comments"]["href"], - pull["head"]["repo"]["clone_url"], pull["head"]["sha"]) diff --git a/qa/pull-tester/pull-tester.sh b/qa/pull-tester/pull-tester.sh deleted file mode 100755 index 3fe4a05c76..0000000000 --- a/qa/pull-tester/pull-tester.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# Copyright (c) 2013-2014 The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -# -# Helper script for pull-tester. -#Param 1: path to bitcoin srcroot -#Param ...: arguments for build-test.sh - -if [ $# -lt 1 ]; then - echo "usage: $0 [bitcoin srcroot] build-test arguments..." -fi - -killall -q bitcoin-cli -killall -q bitcoind - -cd $1 -shift - -./autogen.sh -./configure -./qa/pull-tester/build-tests.sh "$@" diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh new file mode 100755 index 0000000000..f07e3c6d9d --- /dev/null +++ b/qa/pull-tester/rpc-tests.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +CURDIR=$(cd $(dirname "$0"); pwd) +# Get BUILDDIR and REAL_BITCOIND +. "${CURDIR}/tests-config.sh" + +export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli +export BITCOIND=${REAL_BITCOIND} + +#Run the tests + +if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then + ${BUILDDIR}/qa/rpc-tests/wallet.sh "${BUILDDIR}/src" + ${BUILDDIR}/qa/rpc-tests/listtransactions.py --srcdir "${BUILDDIR}/src" + ${BUILDDIR}/qa/rpc-tests/forknotify.py --srcdir "${BUILDDIR}/src" +else + echo "No rpc tests to run. Wallet, utils, and bitcoind must all be enabled" +fi diff --git a/qa/pull-tester/run-bitcoin-cli b/qa/pull-tester/run-bitcoin-cli new file mode 100755 index 0000000000..93c25bb9fc --- /dev/null +++ b/qa/pull-tester/run-bitcoin-cli @@ -0,0 +1,13 @@ +#!/bin/bash + +# This is a thin wrapper around bitcoin-cli that strips the Windows-style EOLs +# from the output if present. It is necessary when using bitcoin-cli.exe on +# Linux since shells will interpret the line-endings as part of the result. + +CURDIR=$(cd $(dirname "$0"); pwd) +# Get BUILDDIR and REAL_BITCOIND + +# Grab the value of $REAL_BITCOINCLI which may be bitcoin-cli.exe. +. "${CURDIR}/tests-config.sh" + +"${REAL_BITCOINCLI}" "$@" | sed 's/\r//' diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in new file mode 100755 index 0000000000..10f4d33e47 --- /dev/null +++ b/qa/pull-tester/tests-config.sh.in @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright (c) 2013-2014 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +BUILDDIR="@abs_top_builddir@" +EXEEXT="@EXEEXT@" + +# These will turn into comments if they were disabled when configuring. +@ENABLE_WALLET_TRUE@ENABLE_WALLET=1 +@BUILD_BITCOIN_UTILS_TRUE@ENABLE_UTILS=1 +@BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=1 + +REAL_BITCOIND="$BUILDDIR/src/bitcoind${EXEEXT}" +REAL_BITCOINCLI="$BUILDDIR/src/bitcoin-cli${EXEEXT}" + diff --git a/qa/rpc-tests/conflictedbalance.sh b/qa/rpc-tests/conflictedbalance.sh index 71761321ed..a112244c74 100755 --- a/qa/rpc-tests/conflictedbalance.sh +++ b/qa/rpc-tests/conflictedbalance.sh @@ -18,13 +18,14 @@ if [ $# -lt 1 ]; then echo "Usage: $0 path_to_binaries" echo "e.g. $0 ../../src" + echo "Env vars BITCOIND and BITCOINCLI may be used to specify the exact binaries used" exit 1 fi set -f -BITCOIND=${1}/bitcoind -CLI=${1}/bitcoin-cli +BITCOIND=${BITCOIND:-${1}/bitcoind} +CLI=${BITCOINCLI:-${1}/bitcoin-cli} DIR="${BASH_SOURCE%/*}" SENDANDWAIT="${DIR}/send.sh" diff --git a/qa/rpc-tests/forknotify.py b/qa/rpc-tests/forknotify.py index a4c2dc944e..1d2c4a9966 100755 --- a/qa/rpc-tests/forknotify.py +++ b/qa/rpc-tests/forknotify.py @@ -23,7 +23,7 @@ class ForkNotifyTest(BitcoinTestFramework): with open(self.alert_filename, 'w') as f: pass # Just open then close to create zero-length file self.nodes.append(start_node(0, self.options.tmpdir, - ["-blockversion=2", "-alertnotify=echo %s >> '" + self.alert_filename + "'"])) + ["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""])) # Node1 mines block.version=211 blocks self.nodes.append(start_node(1, self.options.tmpdir, ["-blockversion=211"])) diff --git a/qa/rpc-tests/txnmall.sh b/qa/rpc-tests/txnmall.sh index 035e7ee15f..1296d54d92 100755 --- a/qa/rpc-tests/txnmall.sh +++ b/qa/rpc-tests/txnmall.sh @@ -8,13 +8,14 @@ if [ $# -lt 1 ]; then echo "Usage: $0 path_to_binaries" echo "e.g. $0 ../../src" + echo "Env vars BITCOIND and BITCOINCLI may be used to specify the exact binaries used" exit 1 fi set -f -BITCOIND=${1}/bitcoind -CLI=${1}/bitcoin-cli +BITCOIND=${BITCOIND:-${1}/bitcoind} +CLI=${BITCOINCLI:-${1}/bitcoin-cli} DIR="${BASH_SOURCE%/*}" SENDANDWAIT="${DIR}/send.sh" diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py index 6d0b21c927..c895eb1619 100644 --- a/qa/rpc-tests/util.py +++ b/qa/rpc-tests/util.py @@ -85,11 +85,11 @@ def initialize_chain(test_dir): # Create cache directories, run bitcoinds: for i in range(4): datadir=initialize_datadir("cache", i) - args = [ "bitcoind", "-keypool=1", "-datadir="+datadir, "-discover=0" ] + args = [ os.getenv("BITCOIND", "bitcoind"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) - subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir, + subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir, "-rpcwait", "getblockcount"], stdout=devnull) devnull.close() rpcs = [] @@ -150,11 +150,11 @@ def start_node(i, dir, extra_args=None, rpchost=None): Start a bitcoind and return RPC connection to it """ datadir = os.path.join(dir, "node"+str(i)) - args = [ "bitcoind", "-datadir="+datadir, "-keypool=1", "-discover=0" ] + args = [ os.getenv("BITCOIND", "bitcoind"), "-datadir="+datadir, "-keypool=1", "-discover=0" ] if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") - subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir] + + subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) devnull.close() diff --git a/qa/rpc-tests/wallet.sh b/qa/rpc-tests/wallet.sh index bb5f34f590..c9ad0f2a78 100755 --- a/qa/rpc-tests/wallet.sh +++ b/qa/rpc-tests/wallet.sh @@ -8,13 +8,14 @@ if [ $# -lt 1 ]; then echo "Usage: $0 path_to_binaries" echo "e.g. $0 ../../src" + echo "Env vars BITCOIND and BITCOINCLI may be used to specify the exact binaries used" exit 1 fi set -f -BITCOIND=${1}/bitcoind -CLI=${1}/bitcoin-cli +BITCOIND=${BITCOIND:-${1}/bitcoind} +CLI=${BITCOINCLI:-${1}/bitcoin-cli} DIR="${BASH_SOURCE%/*}" SENDANDWAIT="${DIR}/send.sh" diff --git a/qa/rpc-tests/walletbackup.sh b/qa/rpc-tests/walletbackup.sh index ee11418bef..4af3d97f35 100755 --- a/qa/rpc-tests/walletbackup.sh +++ b/qa/rpc-tests/walletbackup.sh @@ -36,11 +36,12 @@ if [ $# -lt 1 ]; then echo "Usage: $0 path_to_binaries" echo "e.g. $0 ../../src" + echo "Env vars BITCOIND and BITCOINCLI may be used to specify the exact binaries used" exit 1 fi -BITCOIND=${1}/bitcoind -CLI=${1}/bitcoin-cli +BITCOIND=${BITCOIND:-${1}/bitcoind} +CLI=${BITCOINCLI:-${1}/bitcoin-cli} DIR="${BASH_SOURCE%/*}" SENDANDWAIT="${DIR}/send.sh" diff --git a/qa/rpc-tests/zapwallettxes.sh b/qa/rpc-tests/zapwallettxes.sh index e6d490cccc..4312d84e94 100755 --- a/qa/rpc-tests/zapwallettxes.sh +++ b/qa/rpc-tests/zapwallettxes.sh @@ -8,13 +8,14 @@ if [ $# -lt 1 ]; then echo "Usage: $0 path_to_binaries" echo "e.g. $0 ../../src" + echo "Env vars BITCOIND and BITCOINCLI may be used to specify the exact binaries used" exit 1 fi set -f -BITCOIND=${1}/bitcoind -CLI=${1}/bitcoin-cli +BITCOIND=${BITCOIND:-${1}/bitcoind} +CLI=${BITCOINCLI:-${1}/bitcoin-cli} DIR="${BASH_SOURCE%/*}" SENDANDWAIT="${DIR}/send.sh" diff --git a/share/seeds/generate-seeds.py b/share/seeds/generate-seeds.py index 5f06740560..cdd6831218 100755 --- a/share/seeds/generate-seeds.py +++ b/share/seeds/generate-seeds.py @@ -114,8 +114,8 @@ def main(): exit(1) g = sys.stdout indir = sys.argv[1] - g.write('#ifndef H_CHAINPARAMSSEEDS\n') - g.write('#define H_CHAINPARAMSSEEDS\n') + g.write('#ifndef BITCOIN_CHAINPARAMSSEEDS_H\n') + g.write('#define BITCOIN_CHAINPARAMSSEEDS_H\n') g.write('/**\n') g.write(' * List of fixed seed nodes for the bitcoin network\n') g.write(' * AUTOGENERATED by share/seeds/generate-seeds.py\n') @@ -128,7 +128,7 @@ def main(): g.write('\n') with open(os.path.join(indir,'nodes_test.txt'),'r') as f: process_nodes(g, f, 'pnSeed6_test', 18333) - g.write('#endif\n') + g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n') if __name__ == '__main__': main() diff --git a/src/Makefile.am b/src/Makefile.am index 8253c4ab14..3089b2ff40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -86,6 +86,7 @@ BITCOIN_CORE_H = \ core_io.h \ crypter.h \ db.h \ + eccryptoverify.h \ ecwrapper.h \ hash.h \ init.h \ @@ -101,6 +102,7 @@ BITCOIN_CORE_H = \ noui.h \ pow.h \ protocol.h \ + pubkey.h \ random.h \ rpcclient.h \ rpcprotocol.h \ @@ -220,12 +222,14 @@ libbitcoin_common_a_SOURCES = \ core/transaction.cpp \ core_read.cpp \ core_write.cpp \ + eccryptoverify.cpp \ ecwrapper.cpp \ hash.cpp \ key.cpp \ keystore.cpp \ netbase.cpp \ protocol.cpp \ + pubkey.cpp \ script/interpreter.cpp \ script/script.cpp \ script/sigcache.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 340eb9f1a7..6a8d9e58a4 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -42,8 +42,8 @@ BITCOIN_TESTS =\ test/bloom_tests.cpp \ test/checkblock_tests.cpp \ test/Checkpoints_tests.cpp \ - test/compress_tests.cpp \ test/coins_tests.cpp \ + test/compress_tests.cpp \ test/crypto_tests.cpp \ test/DoS_tests.cpp \ test/getarg_tests.cpp \ @@ -58,7 +58,9 @@ BITCOIN_TESTS =\ test/rpc_tests.cpp \ test/script_P2SH_tests.cpp \ test/script_tests.cpp \ + test/scriptnum_tests.cpp \ test/serialize_tests.cpp \ + test/sighash_tests.cpp \ test/sigopcount_tests.cpp \ test/skiplist_tests.cpp \ test/test_bitcoin.cpp \ @@ -66,9 +68,7 @@ BITCOIN_TESTS =\ test/transaction_tests.cpp \ test/uint256_tests.cpp \ test/univalue_tests.cpp \ - test/util_tests.cpp \ - test/scriptnum_tests.cpp \ - test/sighash_tests.cpp + test/util_tests.cpp if ENABLE_WALLET BITCOIN_TESTS += \ diff --git a/src/addrman.h b/src/addrman.h index 914086fc76..d47217683c 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOIN_ADDRMAN -#define _BITCOIN_ADDRMAN +#ifndef BITCOIN_ADDRMAN_H +#define BITCOIN_ADDRMAN_H #include "netbase.h" #include "protocol.h" @@ -514,4 +514,4 @@ public: } }; -#endif // _BITCOIN_ADDRMAN +#endif // BITCOIN_ADDRMAN_H diff --git a/src/alert.cpp b/src/alert.cpp index f16898dc38..ce8dfbf507 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -7,7 +7,7 @@ #include "chainparams.h" #include "clientversion.h" -#include "key.h" +#include "pubkey.h" #include "net.h" #include "timedata.h" #include "ui_interface.h" @@ -128,6 +128,9 @@ bool CAlert::RelayTo(CNode* pnode) const { if (!IsInEffect()) return false; + // don't relay to nodes which haven't sent their version message + if (pnode->nVersion == 0) + return false; // returns true if wasn't already contained in the set if (pnode->setKnown.insert(GetHash()).second) { diff --git a/src/alert.h b/src/alert.h index ba3235858d..96c203b557 100644 --- a/src/alert.h +++ b/src/alert.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOINALERT_H_ -#define _BITCOINALERT_H_ +#ifndef BITCOIN_ALERT_H +#define BITCOIN_ALERT_H #include "serialize.h" #include "sync.h" @@ -110,4 +110,4 @@ public: static CAlert getAlertByHash(const uint256 &hash); }; -#endif // _BITCOINALERT_H_ +#endif // BITCOIN_ALERT_H diff --git a/src/base58.h b/src/base58.h index c5e230c72e..7cd2d651a1 100644 --- a/src/base58.h +++ b/src/base58.h @@ -16,6 +16,7 @@ #include "chainparams.h" #include "key.h" +#include "pubkey.h" #include "script/script.h" #include "script/standard.h" diff --git a/src/bloom.cpp b/src/bloom.cpp index c1e7aeb3bf..df8cedaf6a 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -5,6 +5,7 @@ #include "bloom.h" #include "core/transaction.h" +#include "hash.h" #include "script/script.h" #include "script/standard.h" #include "streams.h" diff --git a/src/chain.h b/src/chain.h index 7c5603dafc..f99fd113b7 100644 --- a/src/chain.h +++ b/src/chain.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_CHAIN -#define H_BITCOIN_CHAIN +#ifndef BITCOIN_CHAIN_H +#define BITCOIN_CHAIN_H #include "core/block.h" #include "pow.h" @@ -409,4 +409,4 @@ public: const CBlockIndex *FindFork(const CBlockIndex *pindex) const; }; -#endif // H_BITCOIN_CHAIN +#endif // BITCOIN_CHAIN_H diff --git a/src/chainparams.h b/src/chainparams.h index 9279edd6c0..9f24b70a26 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_CHAIN_PARAMS_H -#define BITCOIN_CHAIN_PARAMS_H +#ifndef BITCOIN_CHAINPARAMS_H +#define BITCOIN_CHAINPARAMS_H #include "chainparamsbase.h" #include "checkpoints.h" @@ -151,4 +151,4 @@ void SelectParams(CBaseChainParams::Network network); */ bool SelectParamsFromCommandLine(); -#endif // BITCOIN_CHAIN_PARAMS_H +#endif // BITCOIN_CHAINPARAMS_H diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 4042b8c879..eaf3fea1b6 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_CHAIN_PARAMS_BASE_H -#define BITCOIN_CHAIN_PARAMS_BASE_H +#ifndef BITCOIN_CHAINPARAMSBASE_H +#define BITCOIN_CHAINPARAMSBASE_H #include <string> #include <vector> @@ -62,4 +62,4 @@ bool SelectBaseParamsFromCommandLine(); */ bool AreBaseParamsConfigured(); -#endif // BITCOIN_CHAIN_PARAMS_BASE_H +#endif // BITCOIN_CHAINPARAMSBASE_H diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index c3323c48bd..575e129334 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -1,10 +1,9 @@ -#ifndef H_CHAINPARAMSSEEDS -#define H_CHAINPARAMSSEEDS - +#ifndef BITCOIN_CHAINPARAMSSEEDS_H +#define BITCOIN_CHAINPARAMSSEEDS_H /** * List of fixed seed nodes for the bitcoin network - * AUTOGENERATED by contrib/devtools/generate-seeds.py - * + * AUTOGENERATED by share/seeds/generate-seeds.py + * * Each line contains a 16-byte IPv6 address and a port. * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly. */ @@ -638,4 +637,4 @@ static SeedSpec6 pnSeed6_test[] = { {{0xfd,0x87,0xd8,0x7e,0xeb,0x43,0x99,0xcb,0x26,0x31,0xba,0x48,0x51,0x31,0x39,0x0d}, 18333}, {{0xfd,0x87,0xd8,0x7e,0xeb,0x43,0x44,0xf4,0xf4,0xf0,0xbf,0xf7,0x7e,0x6d,0xc4,0xe8}, 18333} }; -#endif +#endif // BITCOIN_CHAINPARAMSSEEDS_H diff --git a/src/checkpoints.h b/src/checkpoints.h index b5b620fa6b..847524a9f2 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_CHECKPOINT_H -#define BITCOIN_CHECKPOINT_H +#ifndef BITCOIN_CHECKPOINTS_H +#define BITCOIN_CHECKPOINTS_H #include "uint256.h" @@ -40,4 +40,4 @@ extern bool fEnabled; } //namespace Checkpoints -#endif // BITCOIN_CHECKPOINT_H +#endif // BITCOIN_CHECKPOINTS_H diff --git a/src/checkqueue.h b/src/checkqueue.h index b2a713e646..afecfeede5 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef CHECKQUEUE_H -#define CHECKQUEUE_H +#ifndef BITCOIN_CHECKQUEUE_H +#define BITCOIN_CHECKQUEUE_H #include <algorithm> #include <vector> @@ -204,4 +204,4 @@ public: } }; -#endif // CHECKQUEUE_H +#endif // BITCOIN_CHECKQUEUE_H diff --git a/src/clientversion.h b/src/clientversion.h index a187e185c1..0a36eb8012 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef CLIENTVERSION_H -#define CLIENTVERSION_H +#ifndef BITCOIN_CLIENTVERSION_H +#define BITCOIN_CLIENTVERSION_H #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" @@ -67,4 +67,4 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const #endif // WINDRES_PREPROC -#endif // CLIENTVERSION_H +#endif // BITCOIN_CLIENTVERSION_H diff --git a/src/coincontrol.h b/src/coincontrol.h index c8f12d92de..c9057017d8 100644 --- a/src/coincontrol.h +++ b/src/coincontrol.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef COINCONTROL_H -#define COINCONTROL_H +#ifndef BITCOIN_COINCONTROL_H +#define BITCOIN_COINCONTROL_H #include "core/transaction.h" @@ -59,4 +59,4 @@ private: std::set<COutPoint> setSelected; }; -#endif // COINCONTROL_H +#endif // BITCOIN_COINCONTROL_H diff --git a/src/compat.h b/src/compat.h index 4fc28a36e0..dade79aae0 100644 --- a/src/compat.h +++ b/src/compat.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOIN_COMPAT_H -#define _BITCOIN_COMPAT_H +#ifndef BITCOIN_COMPAT_H +#define BITCOIN_COMPAT_H #ifdef WIN32 #ifdef _WIN32_WINNT @@ -84,4 +84,4 @@ typedef u_int SOCKET; #define THREAD_PRIORITY_ABOVE_NORMAL (-2) #endif -#endif // _BITCOIN_COMPAT_H +#endif // BITCOIN_COMPAT_H diff --git a/src/compat/sanity.h b/src/compat/sanity.h index 7016ac0ab7..7f5bc1a4fb 100644 --- a/src/compat/sanity.h +++ b/src/compat/sanity.h @@ -2,10 +2,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCON_COMPAT_SANITY_H -#define BITCON_COMPAT_SANITY_H +#ifndef BITCOIN_COMPAT_SANITY_H +#define BITCOIN_COMPAT_SANITY_H bool glibc_sanity_test(); bool glibcxx_sanity_test(); -#endif // BITCON_COMPAT_SANITY_H +#endif // BITCOIN_COMPAT_SANITY_H diff --git a/src/compressor.cpp b/src/compressor.cpp index 806175dd3e..c47a0f6f8c 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -6,7 +6,7 @@ #include "compressor.h" #include "hash.h" -#include "key.h" +#include "pubkey.h" #include "script/standard.h" bool CScriptCompressor::IsToKeyID(CKeyID &hash) const diff --git a/src/compressor.h b/src/compressor.h index a612c3a883..226be620e8 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_COMPRESSOR -#define H_BITCOIN_COMPRESSOR +#ifndef BITCOIN_COMPRESSOR_H +#define BITCOIN_COMPRESSOR_H #include "core/transaction.h" #include "script/script.h" @@ -116,4 +116,4 @@ public: } }; -#endif // H_BITCOIN_COMPRESSOR +#endif // BITCOIN_COMPRESSOR_H diff --git a/src/core/block.h b/src/core/block.h index f1eb7a844f..6e119c3699 100644 --- a/src/core/block.h +++ b/src/core/block.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_CORE_BLOCK -#define H_BITCOIN_CORE_BLOCK +#ifndef BITCOIN_CORE_BLOCK_H +#define BITCOIN_CORE_BLOCK_H #include "core/transaction.h" #include "serialize.h" @@ -165,4 +165,4 @@ struct CBlockLocator } }; -#endif // H_BITCOIN_CORE_BLOCK +#endif // BITCOIN_CORE_BLOCK_H diff --git a/src/core/transaction.h b/src/core/transaction.h index c21558cfeb..724348020a 100644 --- a/src/core/transaction.h +++ b/src/core/transaction.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_CORE_TRANSACTION -#define H_BITCOIN_CORE_TRANSACTION +#ifndef BITCOIN_CORE_TRANSACTION_H +#define BITCOIN_CORE_TRANSACTION_H #include "amount.h" #include "script/script.h" @@ -273,4 +273,4 @@ struct CMutableTransaction uint256 GetHash() const; }; -#endif // H_BITCOIN_CORE_TRANSACTION +#endif // BITCOIN_CORE_TRANSACTION_H diff --git a/src/core_io.h b/src/core_io.h index 94848f1c3d..b5ed03b8c8 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __BITCOIN_CORE_IO_H__ -#define __BITCOIN_CORE_IO_H__ +#ifndef BITCOIN_CORE_IO_H +#define BITCOIN_CORE_IO_H #include <string> #include <vector> @@ -26,4 +26,4 @@ extern void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); extern void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry); -#endif // __BITCOIN_CORE_IO_H__ +#endif // BITCOIN_CORE_IO_H diff --git a/src/crypter.h b/src/crypter.h index c7424c9b20..4d486c4313 100644 --- a/src/crypter.h +++ b/src/crypter.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __CRYPTER_H__ -#define __CRYPTER_H__ +#ifndef BITCOIN_CRYPTER_H +#define BITCOIN_CRYPTER_H #include "allocators.h" #include "serialize.h" @@ -195,4 +195,4 @@ public: boost::signals2::signal<void (CCryptoKeyStore* wallet)> NotifyStatusChanged; }; -#endif // __CRYPTER_H__ +#endif // BITCOIN_CRYPTER_H diff --git a/src/crypto/ripemd160.h b/src/crypto/ripemd160.h index 902e7ca83f..f468ec6722 100644 --- a/src/crypto/ripemd160.h +++ b/src/crypto/ripemd160.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_RIPEMD160_H -#define BITCOIN_RIPEMD160_H +#ifndef BITCOIN_CRYPTO_RIPEMD160_H +#define BITCOIN_CRYPTO_RIPEMD160_H #include <stdint.h> #include <stdlib.h> @@ -25,4 +25,4 @@ public: CRIPEMD160& Reset(); }; -#endif // BITCOIN_RIPEMD160_H +#endif // BITCOIN_CRYPTO_RIPEMD160_H diff --git a/src/crypto/sha1.h b/src/crypto/sha1.h index 68bd7ced9f..e28f98decd 100644 --- a/src/crypto/sha1.h +++ b/src/crypto/sha1.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_SHA1_H -#define BITCOIN_SHA1_H +#ifndef BITCOIN_CRYPTO_SHA1_H +#define BITCOIN_CRYPTO_SHA1_H #include <stdint.h> #include <stdlib.h> @@ -25,4 +25,4 @@ public: CSHA1& Reset(); }; -#endif // BITCOIN_SHA1_H +#endif // BITCOIN_CRYPTO_SHA1_H diff --git a/src/crypto/sha2.h b/src/crypto/sha2.h index a6cbe58554..329c6675ab 100644 --- a/src/crypto/sha2.h +++ b/src/crypto/sha2.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_SHA2_H -#define BITCOIN_SHA2_H +#ifndef BITCOIN_CRYPTO_SHA2_H +#define BITCOIN_CRYPTO_SHA2_H #include <stdint.h> #include <stdlib.h> @@ -61,4 +61,4 @@ public: void Finalize(unsigned char hash[OUTPUT_SIZE]); }; -#endif // BITCOIN_SHA2_H +#endif // BITCOIN_CRYPTO_SHA2_H diff --git a/src/eccryptoverify.cpp b/src/eccryptoverify.cpp new file mode 100644 index 0000000000..0a904f44ba --- /dev/null +++ b/src/eccryptoverify.cpp @@ -0,0 +1,63 @@ +#include "eccryptoverify.h" + +namespace { + +int CompareBigEndian(const unsigned char *c1, size_t c1len, const unsigned char *c2, size_t c2len) { + while (c1len > c2len) { + if (*c1) + return 1; + c1++; + c1len--; + } + while (c2len > c1len) { + if (*c2) + return -1; + c2++; + c2len--; + } + while (c1len > 0) { + if (*c1 > *c2) + return 1; + if (*c2 > *c1) + return -1; + c1++; + c2++; + c1len--; + } + return 0; +} + +/** Order of secp256k1's generator minus 1. */ +const unsigned char vchMaxModOrder[32] = { + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE, + 0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B, + 0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x40 +}; + +/** Half of the order of secp256k1's generator minus 1. */ +const unsigned char vchMaxModHalfOrder[32] = { + 0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0x5D,0x57,0x6E,0x73,0x57,0xA4,0x50,0x1D, + 0xDF,0xE9,0x2F,0x46,0x68,0x1B,0x20,0xA0 +}; + +const unsigned char vchZero[1] = {0}; +} // anon namespace + +namespace eccrypto { + +bool Check(const unsigned char *vch) { + return vch && + CompareBigEndian(vch, 32, vchZero, 0) > 0 && + CompareBigEndian(vch, 32, vchMaxModOrder, 32) <= 0; +} + +bool CheckSignatureElement(const unsigned char *vch, int len, bool half) { + return vch && + CompareBigEndian(vch, len, vchZero, 0) > 0 && + CompareBigEndian(vch, len, half ? vchMaxModHalfOrder : vchMaxModOrder, 32) <= 0; +} + +} // namespace eccrypto diff --git a/src/eccryptoverify.h b/src/eccryptoverify.h new file mode 100644 index 0000000000..7740e31db1 --- /dev/null +++ b/src/eccryptoverify.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_EC_CRYPTO_VERIFY_H +#define BITCOIN_EC_CRYPTO_VERIFY_H + +#include <vector> +#include <cstdlib> +class uint256; + +namespace eccrypto { + +bool Check(const unsigned char *vch); +bool CheckSignatureElement(const unsigned char *vch, int len, bool half); + +} // eccrypto namespace +#endif diff --git a/src/ecwrapper.cpp b/src/ecwrapper.cpp index e5db670927..ebaa350264 100644 --- a/src/ecwrapper.cpp +++ b/src/ecwrapper.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying +// Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "ecwrapper.h" diff --git a/src/ecwrapper.h b/src/ecwrapper.h index 072da4a942..52e9e5dab0 100644 --- a/src/ecwrapper.h +++ b/src/ecwrapper.h @@ -1,9 +1,9 @@ // Copyright (c) 2009-2014 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying +// Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_EC_WRAPPER_H -#define BITCOIN_EC_WRAPPER_H +#ifndef BITCOIN_ECWRAPPER_H +#define BITCOIN_ECWRAPPER_H #include <cstddef> #include <vector> @@ -43,4 +43,4 @@ public: static bool SanityCheck(); }; -#endif +#endif // BITCOIN_EC_WRAPPER_H diff --git a/src/hash.cpp b/src/hash.cpp index 218607a6fd..29376b45aa 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -63,3 +63,16 @@ unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char return h1; } + +void BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]) +{ + unsigned char num[4]; + num[0] = (nChild >> 24) & 0xFF; + num[1] = (nChild >> 16) & 0xFF; + num[2] = (nChild >> 8) & 0xFF; + num[3] = (nChild >> 0) & 0xFF; + CHMAC_SHA512(chainCode, 32).Write(&header, 1) + .Write(data, 32) + .Write(num, 4) + .Finalize(output); +} diff --git a/src/hash.h b/src/hash.h index bdcd4afb47..53a7672a8f 100644 --- a/src/hash.h +++ b/src/hash.h @@ -159,4 +159,5 @@ uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash); +void BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); #endif // BITCOIN_HASH_H diff --git a/src/key.cpp b/src/key.cpp index c466e84f26..1b539d073a 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -5,6 +5,8 @@ #include "key.h" #include "crypto/sha2.h" +#include "eccryptoverify.h" +#include "pubkey.h" #include "random.h" #ifdef USE_SECP256K1 @@ -30,60 +32,10 @@ public: static CSecp256k1Init instance_of_csecp256k1; #endif - -int CompareBigEndian(const unsigned char *c1, size_t c1len, const unsigned char *c2, size_t c2len) { - while (c1len > c2len) { - if (*c1) - return 1; - c1++; - c1len--; - } - while (c2len > c1len) { - if (*c2) - return -1; - c2++; - c2len--; - } - while (c1len > 0) { - if (*c1 > *c2) - return 1; - if (*c2 > *c1) - return -1; - c1++; - c2++; - c1len--; - } - return 0; -} - -/** Order of secp256k1's generator minus 1. */ -const unsigned char vchMaxModOrder[32] = { - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE, - 0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B, - 0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x40 -}; - -/** Half of the order of secp256k1's generator minus 1. */ -const unsigned char vchMaxModHalfOrder[32] = { - 0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0x5D,0x57,0x6E,0x73,0x57,0xA4,0x50,0x1D, - 0xDF,0xE9,0x2F,0x46,0x68,0x1B,0x20,0xA0 -}; - -const unsigned char vchZero[1] = {0}; - } // anon namespace bool CKey::Check(const unsigned char *vch) { - return CompareBigEndian(vch, 32, vchZero, 0) > 0 && - CompareBigEndian(vch, 32, vchMaxModOrder, 32) <= 0; -} - -bool CKey::CheckSignatureElement(const unsigned char *vch, int len, bool half) { - return CompareBigEndian(vch, len, vchZero, 0) > 0 && - CompareBigEndian(vch, len, half ? vchMaxModHalfOrder : vchMaxModOrder, 32) <= 0; + return eccrypto::Check(vch); } void CKey::MakeNewKey(bool fCompressedIn) { @@ -216,88 +168,6 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) { return true; } -bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const { - if (!IsValid()) - return false; -#ifdef USE_SECP256K1 - if (secp256k1_ecdsa_verify((const unsigned char*)&hash, 32, &vchSig[0], vchSig.size(), begin(), size()) != 1) - return false; -#else - CECKey key; - if (!key.SetPubKey(begin(), size())) - return false; - if (!key.Verify(hash, vchSig)) - return false; -#endif - return true; -} - -bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) { - if (vchSig.size() != 65) - return false; - int recid = (vchSig[0] - 27) & 3; - bool fComp = ((vchSig[0] - 27) & 4) != 0; -#ifdef USE_SECP256K1 - int pubkeylen = 65; - if (!secp256k1_ecdsa_recover_compact((const unsigned char*)&hash, 32, &vchSig[1], (unsigned char*)begin(), &pubkeylen, fComp, recid)) - return false; - assert((int)size() == pubkeylen); -#else - CECKey key; - if (!key.Recover(hash, &vchSig[1], recid)) - return false; - std::vector<unsigned char> pubkey; - key.GetPubKey(pubkey, fComp); - Set(pubkey.begin(), pubkey.end()); -#endif - return true; -} - -bool CPubKey::IsFullyValid() const { - if (!IsValid()) - return false; -#ifdef USE_SECP256K1 - if (!secp256k1_ecdsa_pubkey_verify(begin(), size())) - return false; -#else - CECKey key; - if (!key.SetPubKey(begin(), size())) - return false; -#endif - return true; -} - -bool CPubKey::Decompress() { - if (!IsValid()) - return false; -#ifdef USE_SECP256K1 - int clen = size(); - int ret = secp256k1_ecdsa_pubkey_decompress((unsigned char*)begin(), &clen); - assert(ret); - assert(clen == (int)size()); -#else - CECKey key; - if (!key.SetPubKey(begin(), size())) - return false; - std::vector<unsigned char> pubkey; - key.GetPubKey(pubkey, false); - Set(pubkey.begin(), pubkey.end()); -#endif - return true; -} - -void static BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]) { - unsigned char num[4]; - num[0] = (nChild >> 24) & 0xFF; - num[1] = (nChild >> 16) & 0xFF; - num[2] = (nChild >> 8) & 0xFF; - num[3] = (nChild >> 0) & 0xFF; - CHMAC_SHA512(chainCode, 32).Write(&header, 1) - .Write(data, 32) - .Write(num, 4) - .Finalize(output); -} - bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const { assert(IsValid()); assert(IsCompressed()); @@ -324,27 +194,6 @@ bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild return ret; } -bool CPubKey::Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const { - assert(IsValid()); - assert((nChild >> 31) == 0); - assert(begin() + 33 == end()); - unsigned char out[64]; - BIP32Hash(cc, nChild, *begin(), begin()+1, out); - memcpy(ccChild, out+32, 32); -#ifdef USE_SECP256K1 - pubkeyChild = *this; - bool ret = secp256k1_ecdsa_pubkey_tweak_add((unsigned char*)pubkeyChild.begin(), pubkeyChild.size(), out); -#else - CECKey key; - bool ret = key.SetPubKey(begin(), size()); - ret &= key.TweakPublic(out); - std::vector<unsigned char> pubkey; - key.GetPubKey(pubkey, true); - pubkeyChild.Set(pubkey.begin(), pubkey.end()); -#endif - return ret; -} - bool CExtKey::Derive(CExtKey &out, unsigned int nChild) const { out.nDepth = nDepth + 1; CKeyID id = key.GetPubKey().GetID(); @@ -395,32 +244,6 @@ void CExtKey::Decode(const unsigned char code[74]) { key.Set(code+42, code+74, true); } -void CExtPubKey::Encode(unsigned char code[74]) const { - code[0] = nDepth; - memcpy(code+1, vchFingerprint, 4); - code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; - code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; - memcpy(code+9, vchChainCode, 32); - assert(pubkey.size() == 33); - memcpy(code+41, pubkey.begin(), 33); -} - -void CExtPubKey::Decode(const unsigned char code[74]) { - nDepth = code[0]; - memcpy(vchFingerprint, code+1, 4); - nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; - memcpy(vchChainCode, code+9, 32); - pubkey.Set(code+41, code+74); -} - -bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const { - out.nDepth = nDepth + 1; - CKeyID id = pubkey.GetID(); - memcpy(&out.vchFingerprint[0], &id, 4); - out.nChild = nChild; - return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode); -} - bool ECC_InitSanityCheck() { #ifdef USE_SECP256K1 return true; @@ -7,13 +7,15 @@ #define BITCOIN_KEY_H #include "allocators.h" -#include "hash.h" #include "serialize.h" #include "uint256.h" #include <stdexcept> #include <vector> +class CPubKey; +class CExtPubKey; + /** * secp256k1: * const unsigned int PRIVATE_KEY_SIZE = 279; @@ -24,169 +26,6 @@ * script supports up to 75 for single byte push */ -/** A reference to a CKey: the Hash160 of its serialized public key */ -class CKeyID : public uint160 -{ -public: - CKeyID() : uint160(0) {} - CKeyID(const uint160& in) : uint160(in) {} -}; - -/** An encapsulated public key. */ -class CPubKey -{ -private: - - /** - * Just store the serialized data. - * Its length can very cheaply be computed from the first byte. - */ - unsigned char vch[65]; - - //! Compute the length of a pubkey with a given first byte. - unsigned int static GetLen(unsigned char chHeader) - { - if (chHeader == 2 || chHeader == 3) - return 33; - if (chHeader == 4 || chHeader == 6 || chHeader == 7) - return 65; - return 0; - } - - //! Set this key data to be invalid - void Invalidate() - { - vch[0] = 0xFF; - } - -public: - //! Construct an invalid public key. - CPubKey() - { - Invalidate(); - } - - //! Initialize a public key using begin/end iterators to byte data. - template <typename T> - void Set(const T pbegin, const T pend) - { - int len = pend == pbegin ? 0 : GetLen(pbegin[0]); - if (len && len == (pend - pbegin)) - memcpy(vch, (unsigned char*)&pbegin[0], len); - else - Invalidate(); - } - - //! Construct a public key using begin/end iterators to byte data. - template <typename T> - CPubKey(const T pbegin, const T pend) - { - Set(pbegin, pend); - } - - //! Construct a public key from a byte vector. - CPubKey(const std::vector<unsigned char>& vch) - { - Set(vch.begin(), vch.end()); - } - - //! Simple read-only vector-like interface to the pubkey data. - unsigned int size() const { return GetLen(vch[0]); } - const unsigned char* begin() const { return vch; } - const unsigned char* end() const { return vch + size(); } - const unsigned char& operator[](unsigned int pos) const { return vch[pos]; } - - //! Comparator implementation. - friend bool operator==(const CPubKey& a, const CPubKey& b) - { - return a.vch[0] == b.vch[0] && - memcmp(a.vch, b.vch, a.size()) == 0; - } - friend bool operator!=(const CPubKey& a, const CPubKey& b) - { - return !(a == b); - } - friend bool operator<(const CPubKey& a, const CPubKey& b) - { - return a.vch[0] < b.vch[0] || - (a.vch[0] == b.vch[0] && memcmp(a.vch, b.vch, a.size()) < 0); - } - - //! Implement serialization, as if this was a byte vector. - unsigned int GetSerializeSize(int nType, int nVersion) const - { - return size() + 1; - } - template <typename Stream> - void Serialize(Stream& s, int nType, int nVersion) const - { - unsigned int len = size(); - ::WriteCompactSize(s, len); - s.write((char*)vch, len); - } - template <typename Stream> - void Unserialize(Stream& s, int nType, int nVersion) - { - unsigned int len = ::ReadCompactSize(s); - if (len <= 65) { - s.read((char*)vch, len); - } else { - // invalid pubkey, skip available data - char dummy; - while (len--) - s.read(&dummy, 1); - Invalidate(); - } - } - - //! Get the KeyID of this public key (hash of its serialization) - CKeyID GetID() const - { - return CKeyID(Hash160(vch, vch + size())); - } - - //! Get the 256-bit hash of this public key. - uint256 GetHash() const - { - return Hash(vch, vch + size()); - } - - /* - * Check syntactic correctness. - * - * Note that this is consensus critical as CheckSig() calls it! - */ - bool IsValid() const - { - return size() > 0; - } - - //! fully validate whether this is a valid public key (more expensive than IsValid()) - bool IsFullyValid() const; - - //! Check whether this is a compressed public key. - bool IsCompressed() const - { - return size() == 33; - } - - /** - * Verify a DER signature (~72 bytes). - * If this public key is not fully valid, the return value will be false. - */ - bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const; - - //! Recover a public key from a compact signature. - bool RecoverCompact(const uint256& hash, const std::vector<unsigned char>& vchSig); - - //! Turn this public key into an uncompressed public key. - bool Decompress(); - - //! Derive BIP32 child pubkey. - bool Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const; -}; - - /** * secure_allocator is defined in allocators.h * CPrivKey is a serialized private key, with all parameters included (279 bytes) @@ -304,24 +143,6 @@ public: static bool CheckSignatureElement(const unsigned char* vch, int len, bool half); }; -struct CExtPubKey { - unsigned char nDepth; - unsigned char vchFingerprint[4]; - unsigned int nChild; - unsigned char vchChainCode[32]; - CPubKey pubkey; - - friend bool operator==(const CExtPubKey& a, const CExtPubKey& b) - { - return a.nDepth == b.nDepth && memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], 4) == 0 && a.nChild == b.nChild && - memcmp(&a.vchChainCode[0], &b.vchChainCode[0], 32) == 0 && a.pubkey == b.pubkey; - } - - void Encode(unsigned char code[74]) const; - void Decode(const unsigned char code[74]); - bool Derive(CExtPubKey& out, unsigned int nChild) const; -}; - struct CExtKey { unsigned char nDepth; unsigned char vchFingerprint[4]; diff --git a/src/keystore.h b/src/keystore.h index 66f8771d4a..60502e9a29 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -7,6 +7,7 @@ #define BITCOIN_KEYSTORE_H #include "key.h" +#include "pubkey.h" #include "sync.h" #include <boost/signals2/signal.hpp> diff --git a/src/main.cpp b/src/main.cpp index 008a059103..82d52913a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -128,6 +128,8 @@ namespace { }; map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight; + // Number of preferrable block download peers. + int nPreferredDownload = 0; } // anon namespace ////////////////////////////////////////////////////////////////////////////// @@ -152,6 +154,8 @@ struct CMainSignals { boost::signals2::signal<void (const uint256 &)> Inventory; // Tells listeners to broadcast their data. boost::signals2::signal<void ()> Broadcast; + // Notifies listeners of a block validation result + boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked; } g_signals; } // anon namespace @@ -163,9 +167,11 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn)); + g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); } void UnregisterValidationInterface(CValidationInterface* pwalletIn) { + g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn)); g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); @@ -175,6 +181,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) { } void UnregisterAllValidationInterfaces() { + g_signals.BlockChecked.disconnect_all_slots(); g_signals.Broadcast.disconnect_all_slots(); g_signals.Inventory.disconnect_all_slots(); g_signals.SetBestChain.disconnect_all_slots(); @@ -225,6 +232,8 @@ struct CNodeState { int64_t nStallingSince; list<QueuedBlock> vBlocksInFlight; int nBlocksInFlight; + // Whether we consider this a preferred download peer. + bool fPreferredDownload; CNodeState() { nMisbehavior = 0; @@ -235,6 +244,7 @@ struct CNodeState { fSyncStarted = false; nStallingSince = 0; nBlocksInFlight = 0; + fPreferredDownload = false; } }; @@ -255,6 +265,16 @@ int GetHeight() return chainActive.Height(); } +void UpdatePreferredDownload(CNode* node, CNodeState* state) +{ + nPreferredDownload -= state->fPreferredDownload; + + // Whether this node should be marked as a preferred download node. + state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && !node->fOneShot && !node->fClient; + + nPreferredDownload += state->fPreferredDownload; +} + void InitializeNode(NodeId nodeid, const CNode *pnode) { LOCK(cs_main); CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; @@ -271,6 +291,7 @@ void FinalizeNode(NodeId nodeid) { BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight) mapBlocksInFlight.erase(entry.hash); EraseOrphansFor(nodeid); + nPreferredDownload -= state->fPreferredDownload; mapNodeState.erase(nodeid); } @@ -1864,7 +1885,9 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { CCoinsViewCache view(pcoinsTip); CInv inv(MSG_BLOCK, pindexNew->GetBlockHash()); - if (!ConnectBlock(*pblock, state, pindexNew, view)) { + bool rv = ConnectBlock(*pblock, state, pindexNew, view); + g_signals.BlockChecked(*pblock, state); + if (!rv) { if (state.IsInvalid()) InvalidBlockFound(pindexNew, state); return error("ConnectTip() : ConnectBlock %s failed", pindexNew->GetBlockHash().ToString()); @@ -2504,7 +2527,7 @@ void CBlockIndex::BuildSkip() pskip = pprev->GetAncestor(GetSkipHeight(nHeight)); } -bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) +bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) { // Preliminary checks bool checked = CheckBlock(*pblock, state); @@ -2513,7 +2536,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl LOCK(cs_main); MarkBlockAsReceived(pblock->GetHash()); if (!checked) { - return error("ProcessBlock() : CheckBlock FAILED"); + return error("%s : CheckBlock FAILED", __func__); } // Store to disk @@ -2523,11 +2546,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId(); } if (!ret) - return error("ProcessBlock() : AcceptBlock FAILED"); + return error("%s : AcceptBlock FAILED", __func__); } if (!ActivateBestChain(state, pblock)) - return error("ProcessBlock() : ActivateBestChain failed"); + return error("%s : ActivateBestChain failed", __func__); return true; } @@ -3136,7 +3159,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) // process in case the block isn't known yet if (mapBlockIndex.count(hash) == 0) { CValidationState state; - if (ProcessBlock(state, NULL, &block, dbp)) + if (ProcessNewBlock(state, NULL, &block, dbp)) nLoaded++; if (state.IsError()) break; @@ -3156,7 +3179,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(), head.ToString()); CValidationState dummy; - if (ProcessBlock(dummy, NULL, &block, &it->second)) + if (ProcessNewBlock(dummy, NULL, &block, &it->second)) { nLoaded++; queue.push_back(block.GetHash()); @@ -3471,6 +3494,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fClient = !(pfrom->nServices & NODE_NETWORK); + // Potentially mark this peer as a preferred download peer. + UpdatePreferredDownload(pfrom, State(pfrom->GetId())); // Change version pfrom->PushMessage("verack"); @@ -3934,7 +3959,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->AddInventoryKnown(inv); CValidationState state; - ProcessBlock(state, pfrom, &block); + ProcessNewBlock(state, pfrom, &block); int nDoS; if (state.IsInvalid(nDoS)) { pfrom->PushMessage("reject", strCommand, state.GetRejectCode(), @@ -4415,7 +4440,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Start block sync if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); - bool fFetch = !pto->fInbound || (pindexBestHeader && (state.pindexLastCommonBlock ? state.pindexLastCommonBlock->nHeight : 0) + 144 > pindexBestHeader->nHeight); + bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. if (!state.fSyncStarted && !pto->fClient && fFetch && !fImporting && !fReindex) { // Only actively request headers from a single peer, unless we're close to today. if (nSyncStarted == 0 || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { diff --git a/src/main.h b/src/main.h index 1941ca7059..1bb0919817 100644 --- a/src/main.h +++ b/src/main.h @@ -39,8 +39,15 @@ #include <boost/unordered_map.hpp> class CBlockIndex; +class CBlockTreeDB; class CBloomFilter; class CInv; +class CScriptCheck; +class CValidationInterface; +class CValidationState; + +struct CBlockTemplate; +struct CNodeStateStats; /** The maximum allowed size for a serialized block, in bytes (network rule) */ static const unsigned int MAX_BLOCK_SIZE = 1000000; @@ -128,15 +135,6 @@ extern CBlockIndex *pindexBestHeader; // Minimum disk space required - used in CheckDiskSpace() static const uint64_t nMinDiskSpace = 52428800; - -class CBlockTreeDB; -class CScriptCheck; -class CValidationState; -class CValidationInterface; -struct CNodeStateStats; - -struct CBlockTemplate; - /** Register a wallet to receive updates from core */ void RegisterValidationInterface(CValidationInterface* pwalletIn); /** Unregister a wallet from core */ @@ -151,8 +149,16 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); /** Unregister a network node */ void UnregisterNodeSignals(CNodeSignals& nodeSignals); -/** Process an incoming block */ -bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL); +/** Process an incoming block. This only returns after the best known valid + block is made active. Note that it does not, however, guarantee that the + specific block passed to it has been checked for validity! + @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state iff pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface - this will have its BlockChecked method called whenever *any* block completes validation. + @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid. + @param[in] pblock The block we want to process. + @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location. + @return True if state.IsValid() +*/ +bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL); /** Check whether enough disk space is available for an incoming block */ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ @@ -651,6 +657,7 @@ protected: virtual void UpdatedTransaction(const uint256 &hash) {}; virtual void Inventory(const uint256 &hash) {}; virtual void ResendWalletTransactions() {}; + virtual void BlockChecked(const CBlock&, const CValidationState&) {}; friend void ::RegisterValidationInterface(CValidationInterface*); friend void ::UnregisterValidationInterface(CValidationInterface*); friend void ::UnregisterAllValidationInterfaces(); diff --git a/src/miner.cpp b/src/miner.cpp index 0235de3ab3..b5bfa9c7be 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -428,8 +428,8 @@ bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessBlock(state, NULL, pblock)) - return error("BitcoinMiner : ProcessBlock, block not accepted"); + if (!ProcessNewBlock(state, NULL, pblock)) + return error("BitcoinMiner : ProcessNewBlock, block not accepted"); return true; } diff --git a/src/protocol.h b/src/protocol.h index b73041a9fd..2ac8f3d8f7 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -7,8 +7,8 @@ #error This header can only be compiled as C++. #endif -#ifndef __INCLUDED_PROTOCOL_H__ -#define __INCLUDED_PROTOCOL_H__ +#ifndef BITCOIN_PROTOCOL_H +#define BITCOIN_PROTOCOL_H #include "netbase.h" #include "serialize.h" @@ -149,4 +149,4 @@ enum { MSG_FILTERED_BLOCK, }; -#endif // __INCLUDED_PROTOCOL_H__ +#endif // BITCOIN_PROTOCOL_H diff --git a/src/pubkey.cpp b/src/pubkey.cpp new file mode 100644 index 0000000000..3f16a4b4be --- /dev/null +++ b/src/pubkey.cpp @@ -0,0 +1,131 @@ +// Copyright (c) 2009-2014 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "pubkey.h" + +#include "crypto/sha2.h" +#include "eccryptoverify.h" + +#ifdef USE_SECP256K1 +#include <secp256k1.h> +#else +#include "ecwrapper.h" +#endif + +bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const { + if (!IsValid()) + return false; +#ifdef USE_SECP256K1 + if (secp256k1_ecdsa_verify((const unsigned char*)&hash, 32, &vchSig[0], vchSig.size(), begin(), size()) != 1) + return false; +#else + CECKey key; + if (!key.SetPubKey(begin(), size())) + return false; + if (!key.Verify(hash, vchSig)) + return false; +#endif + return true; +} + +bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) { + if (vchSig.size() != 65) + return false; + int recid = (vchSig[0] - 27) & 3; + bool fComp = ((vchSig[0] - 27) & 4) != 0; +#ifdef USE_SECP256K1 + int pubkeylen = 65; + if (!secp256k1_ecdsa_recover_compact((const unsigned char*)&hash, 32, &vchSig[1], (unsigned char*)begin(), &pubkeylen, fComp, recid)) + return false; + assert((int)size() == pubkeylen); +#else + CECKey key; + if (!key.Recover(hash, &vchSig[1], recid)) + return false; + std::vector<unsigned char> pubkey; + key.GetPubKey(pubkey, fComp); + Set(pubkey.begin(), pubkey.end()); +#endif + return true; +} + +bool CPubKey::IsFullyValid() const { + if (!IsValid()) + return false; +#ifdef USE_SECP256K1 + if (!secp256k1_ecdsa_pubkey_verify(begin(), size())) + return false; +#else + CECKey key; + if (!key.SetPubKey(begin(), size())) + return false; +#endif + return true; +} + +bool CPubKey::Decompress() { + if (!IsValid()) + return false; +#ifdef USE_SECP256K1 + int clen = size(); + int ret = secp256k1_ecdsa_pubkey_decompress((unsigned char*)begin(), &clen); + assert(ret); + assert(clen == (int)size()); +#else + CECKey key; + if (!key.SetPubKey(begin(), size())) + return false; + std::vector<unsigned char> pubkey; + key.GetPubKey(pubkey, false); + Set(pubkey.begin(), pubkey.end()); +#endif + return true; +} + +bool CPubKey::Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const { + assert(IsValid()); + assert((nChild >> 31) == 0); + assert(begin() + 33 == end()); + unsigned char out[64]; + BIP32Hash(cc, nChild, *begin(), begin()+1, out); + memcpy(ccChild, out+32, 32); +#ifdef USE_SECP256K1 + pubkeyChild = *this; + bool ret = secp256k1_ecdsa_pubkey_tweak_add((unsigned char*)pubkeyChild.begin(), pubkeyChild.size(), out); +#else + CECKey key; + bool ret = key.SetPubKey(begin(), size()); + ret &= key.TweakPublic(out); + std::vector<unsigned char> pubkey; + key.GetPubKey(pubkey, true); + pubkeyChild.Set(pubkey.begin(), pubkey.end()); +#endif + return ret; +} + +void CExtPubKey::Encode(unsigned char code[74]) const { + code[0] = nDepth; + memcpy(code+1, vchFingerprint, 4); + code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; + code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; + memcpy(code+9, vchChainCode, 32); + assert(pubkey.size() == 33); + memcpy(code+41, pubkey.begin(), 33); +} + +void CExtPubKey::Decode(const unsigned char code[74]) { + nDepth = code[0]; + memcpy(vchFingerprint, code+1, 4); + nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; + memcpy(vchChainCode, code+9, 32); + pubkey.Set(code+41, code+74); +} + +bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const { + out.nDepth = nDepth + 1; + CKeyID id = pubkey.GetID(); + memcpy(&out.vchFingerprint[0], &id, 4); + out.nChild = nChild; + return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode); +} diff --git a/src/pubkey.h b/src/pubkey.h new file mode 100644 index 0000000000..ccf9673453 --- /dev/null +++ b/src/pubkey.h @@ -0,0 +1,206 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_PUBKEY_H +#define BITCOIN_PUBKEY_H + +#include "hash.h" +#include "serialize.h" +#include "uint256.h" + +#include <stdexcept> +#include <vector> + +/** + * secp256k1: + * const unsigned int PRIVATE_KEY_SIZE = 279; + * const unsigned int PUBLIC_KEY_SIZE = 65; + * const unsigned int SIGNATURE_SIZE = 72; + * + * see www.keylength.com + * script supports up to 75 for single byte push + */ + +/** A reference to a CKey: the Hash160 of its serialized public key */ +class CKeyID : public uint160 +{ +public: + CKeyID() : uint160(0) {} + CKeyID(const uint160& in) : uint160(in) {} +}; + +/** An encapsulated public key. */ +class CPubKey +{ +private: + + /** + * Just store the serialized data. + * Its length can very cheaply be computed from the first byte. + */ + unsigned char vch[65]; + + //! Compute the length of a pubkey with a given first byte. + unsigned int static GetLen(unsigned char chHeader) + { + if (chHeader == 2 || chHeader == 3) + return 33; + if (chHeader == 4 || chHeader == 6 || chHeader == 7) + return 65; + return 0; + } + + //! Set this key data to be invalid + void Invalidate() + { + vch[0] = 0xFF; + } + +public: + //! Construct an invalid public key. + CPubKey() + { + Invalidate(); + } + + //! Initialize a public key using begin/end iterators to byte data. + template <typename T> + void Set(const T pbegin, const T pend) + { + int len = pend == pbegin ? 0 : GetLen(pbegin[0]); + if (len && len == (pend - pbegin)) + memcpy(vch, (unsigned char*)&pbegin[0], len); + else + Invalidate(); + } + + //! Construct a public key using begin/end iterators to byte data. + template <typename T> + CPubKey(const T pbegin, const T pend) + { + Set(pbegin, pend); + } + + //! Construct a public key from a byte vector. + CPubKey(const std::vector<unsigned char>& vch) + { + Set(vch.begin(), vch.end()); + } + + //! Simple read-only vector-like interface to the pubkey data. + unsigned int size() const { return GetLen(vch[0]); } + const unsigned char* begin() const { return vch; } + const unsigned char* end() const { return vch + size(); } + const unsigned char& operator[](unsigned int pos) const { return vch[pos]; } + + //! Comparator implementation. + friend bool operator==(const CPubKey& a, const CPubKey& b) + { + return a.vch[0] == b.vch[0] && + memcmp(a.vch, b.vch, a.size()) == 0; + } + friend bool operator!=(const CPubKey& a, const CPubKey& b) + { + return !(a == b); + } + friend bool operator<(const CPubKey& a, const CPubKey& b) + { + return a.vch[0] < b.vch[0] || + (a.vch[0] == b.vch[0] && memcmp(a.vch, b.vch, a.size()) < 0); + } + + //! Implement serialization, as if this was a byte vector. + unsigned int GetSerializeSize(int nType, int nVersion) const + { + return size() + 1; + } + template <typename Stream> + void Serialize(Stream& s, int nType, int nVersion) const + { + unsigned int len = size(); + ::WriteCompactSize(s, len); + s.write((char*)vch, len); + } + template <typename Stream> + void Unserialize(Stream& s, int nType, int nVersion) + { + unsigned int len = ::ReadCompactSize(s); + if (len <= 65) { + s.read((char*)vch, len); + } else { + // invalid pubkey, skip available data + char dummy; + while (len--) + s.read(&dummy, 1); + Invalidate(); + } + } + + //! Get the KeyID of this public key (hash of its serialization) + CKeyID GetID() const + { + return CKeyID(Hash160(vch, vch + size())); + } + + //! Get the 256-bit hash of this public key. + uint256 GetHash() const + { + return Hash(vch, vch + size()); + } + + /* + * Check syntactic correctness. + * + * Note that this is consensus critical as CheckSig() calls it! + */ + bool IsValid() const + { + return size() > 0; + } + + //! fully validate whether this is a valid public key (more expensive than IsValid()) + bool IsFullyValid() const; + + //! Check whether this is a compressed public key. + bool IsCompressed() const + { + return size() == 33; + } + + /** + * Verify a DER signature (~72 bytes). + * If this public key is not fully valid, the return value will be false. + */ + bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const; + + //! Recover a public key from a compact signature. + bool RecoverCompact(const uint256& hash, const std::vector<unsigned char>& vchSig); + + //! Turn this public key into an uncompressed public key. + bool Decompress(); + + //! Derive BIP32 child pubkey. + bool Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const; +}; + +struct CExtPubKey { + unsigned char nDepth; + unsigned char vchFingerprint[4]; + unsigned int nChild; + unsigned char vchChainCode[32]; + CPubKey pubkey; + + friend bool operator==(const CExtPubKey& a, const CExtPubKey& b) + { + return a.nDepth == b.nDepth && memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], 4) == 0 && a.nChild == b.nChild && + memcmp(&a.vchChainCode[0], &b.vchChainCode[0], 32) == 0 && a.pubkey == b.pubkey; + } + + void Encode(unsigned char code[74]) const; + void Decode(const unsigned char code[74]); + bool Derive(CExtPubKey& out, unsigned int nChild) const; +}; + +#endif // BITCOIN_PUBKEY_H diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index 20beb51ec4..031c424785 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef ADDRESSBOOKPAGE_H -#define ADDRESSBOOKPAGE_H +#ifndef BITCOIN_QT_ADDRESSBOOKPAGE_H +#define BITCOIN_QT_ADDRESSBOOKPAGE_H #include <QDialog> @@ -84,4 +84,4 @@ signals: void sendCoins(QString addr); }; -#endif // ADDRESSBOOKPAGE_H +#endif // BITCOIN_QT_ADDRESSBOOKPAGE_H diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index 71691f5a26..310647d7c3 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef ADDRESSTABLEMODEL_H -#define ADDRESSTABLEMODEL_H +#ifndef BITCOIN_QT_ADDRESSTABLEMODEL_H +#define BITCOIN_QT_ADDRESSTABLEMODEL_H #include <QAbstractTableModel> #include <QStringList> @@ -92,4 +92,4 @@ public slots: friend class AddressTablePriv; }; -#endif // ADDRESSTABLEMODEL_H +#endif // BITCOIN_QT_ADDRESSTABLEMODEL_H diff --git a/src/qt/askpassphrasedialog.h b/src/qt/askpassphrasedialog.h index 1119e0861f..6605086060 100644 --- a/src/qt/askpassphrasedialog.h +++ b/src/qt/askpassphrasedialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef ASKPASSPHRASEDIALOG_H -#define ASKPASSPHRASEDIALOG_H +#ifndef BITCOIN_QT_ASKPASSPHRASEDIALOG_H +#define BITCOIN_QT_ASKPASSPHRASEDIALOG_H #include <QDialog> @@ -48,4 +48,4 @@ protected: bool eventFilter(QObject *object, QEvent *event); }; -#endif // ASKPASSPHRASEDIALOG_H +#endif // BITCOIN_QT_ASKPASSPHRASEDIALOG_H diff --git a/src/qt/bitcoinaddressvalidator.h b/src/qt/bitcoinaddressvalidator.h index 0fb779f7d8..15a6245da4 100644 --- a/src/qt/bitcoinaddressvalidator.h +++ b/src/qt/bitcoinaddressvalidator.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOINADDRESSVALIDATOR_H -#define BITCOINADDRESSVALIDATOR_H +#ifndef BITCOIN_QT_BITCOINADDRESSVALIDATOR_H +#define BITCOIN_QT_BITCOINADDRESSVALIDATOR_H #include <QValidator> @@ -32,4 +32,4 @@ public: State validate(QString &input, int &pos) const; }; -#endif // BITCOINADDRESSVALIDATOR_H +#endif // BITCOIN_QT_BITCOINADDRESSVALIDATOR_H diff --git a/src/qt/bitcoinamountfield.h b/src/qt/bitcoinamountfield.h index 040a234177..4ab66001f0 100644 --- a/src/qt/bitcoinamountfield.h +++ b/src/qt/bitcoinamountfield.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOINAMOUNTFIELD_H -#define BITCOINAMOUNTFIELD_H +#ifndef BITCOIN_QT_BITCOINAMOUNTFIELD_H +#define BITCOIN_QT_BITCOINAMOUNTFIELD_H #include "amount.h" @@ -69,4 +69,4 @@ private slots: }; -#endif // BITCOINAMOUNTFIELD_H +#endif // BITCOIN_QT_BITCOINAMOUNTFIELD_H diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 0ef4101127..35b36811c4 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOINGUI_H -#define BITCOINGUI_H +#ifndef BITCOIN_QT_BITCOINGUI_H +#define BITCOIN_QT_BITCOINGUI_H #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" @@ -236,4 +236,4 @@ private slots: void onMenuSelection(QAction* action); }; -#endif // BITCOINGUI_H +#endif // BITCOIN_QT_BITCOINGUI_H diff --git a/src/qt/bitcoinunits.h b/src/qt/bitcoinunits.h index a392c42b9b..7a4f38274d 100644 --- a/src/qt/bitcoinunits.h +++ b/src/qt/bitcoinunits.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOINUNITS_H -#define BITCOINUNITS_H +#ifndef BITCOIN_QT_BITCOINUNITS_H +#define BITCOIN_QT_BITCOINUNITS_H #include "amount.h" @@ -126,4 +126,4 @@ private: }; typedef BitcoinUnits::Unit BitcoinUnit; -#endif // BITCOINUNITS_H +#endif // BITCOIN_QT_BITCOINUNITS_H diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index c7bd60bd41..c7a05e287d 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef CLIENTMODEL_H -#define CLIENTMODEL_H +#ifndef BITCOIN_QT_CLIENTMODEL_H +#define BITCOIN_QT_CLIENTMODEL_H #include <QObject> @@ -102,4 +102,4 @@ public slots: void updateAlert(const QString &hash, int status); }; -#endif // CLIENTMODEL_H +#endif // BITCOIN_QT_CLIENTMODEL_H diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h index 9eaa8eb41d..cc388d626e 100644 --- a/src/qt/coincontroldialog.h +++ b/src/qt/coincontroldialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef COINCONTROLDIALOG_H -#define COINCONTROLDIALOG_H +#ifndef BITCOIN_QT_COINCONTROLDIALOG_H +#define BITCOIN_QT_COINCONTROLDIALOG_H #include "amount.h" @@ -124,4 +124,4 @@ private slots: void updateLabelLocked(); }; -#endif // COINCONTROLDIALOG_H +#endif // BITCOIN_QT_COINCONTROLDIALOG_H diff --git a/src/qt/coincontroltreewidget.h b/src/qt/coincontroltreewidget.h index a2cd34eb88..643eaf0c70 100644 --- a/src/qt/coincontroltreewidget.h +++ b/src/qt/coincontroltreewidget.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef COINCONTROLTREEWIDGET_H -#define COINCONTROLTREEWIDGET_H +#ifndef BITCOIN_QT_COINCONTROLTREEWIDGET_H +#define BITCOIN_QT_COINCONTROLTREEWIDGET_H #include <QKeyEvent> #include <QTreeWidget> @@ -19,4 +19,4 @@ protected: virtual void keyPressEvent(QKeyEvent *event); }; -#endif // COINCONTROLTREEWIDGET_H
\ No newline at end of file +#endif // BITCOIN_QT_COINCONTROLTREEWIDGET_H diff --git a/src/qt/csvmodelwriter.h b/src/qt/csvmodelwriter.h index 29de251efe..c613ce73eb 100644 --- a/src/qt/csvmodelwriter.h +++ b/src/qt/csvmodelwriter.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef CSVMODELWRITER_H -#define CSVMODELWRITER_H +#ifndef BITCOIN_QT_CSVMODELWRITER_H +#define BITCOIN_QT_CSVMODELWRITER_H #include <QList> #include <QObject> @@ -43,4 +43,4 @@ private: QList<Column> columns; }; -#endif // CSVMODELWRITER_H +#endif // BITCOIN_QT_CSVMODELWRITER_H diff --git a/src/qt/editaddressdialog.h b/src/qt/editaddressdialog.h index 6910c667cd..aa1103a2f5 100644 --- a/src/qt/editaddressdialog.h +++ b/src/qt/editaddressdialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef EDITADDRESSDIALOG_H -#define EDITADDRESSDIALOG_H +#ifndef BITCOIN_QT_EDITADDRESSDIALOG_H +#define BITCOIN_QT_EDITADDRESSDIALOG_H #include <QDialog> @@ -54,4 +54,4 @@ private: QString address; }; -#endif // EDITADDRESSDIALOG_H +#endif // BITCOIN_QT_EDITADDRESSDIALOG_H diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index 4c8a67b663..f23175049a 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GUICONSTANTS_H -#define GUICONSTANTS_H +#ifndef BITCOIN_QT_GUICONSTANTS_H +#define BITCOIN_QT_GUICONSTANTS_H /* Milliseconds between model updates */ static const int MODEL_UPDATE_DELAY = 250; @@ -52,4 +52,4 @@ static const int MAX_PAYMENT_REQUEST_SIZE = 50000; // bytes #define QAPP_APP_NAME_DEFAULT "Bitcoin-Qt" #define QAPP_APP_NAME_TESTNET "Bitcoin-Qt-testnet" -#endif // GUICONSTANTS_H +#endif // BITCOIN_QT_GUICONSTANTS_H diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 0939c78f64..5666744bd3 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GUIUTIL_H -#define GUIUTIL_H +#ifndef BITCOIN_QT_GUIUTIL_H +#define BITCOIN_QT_GUIUTIL_H #include "amount.h" @@ -188,4 +188,4 @@ namespace GUIUtil QString formatPingTime(double dPingTime); } // namespace GUIUtil -#endif // GUIUTIL_H +#endif // BITCOIN_QT_GUIUTIL_H diff --git a/src/qt/intro.h b/src/qt/intro.h index e3e396d369..c9c0d448fa 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef INTRO_H -#define INTRO_H +#ifndef BITCOIN_QT_INTRO_H +#define BITCOIN_QT_INTRO_H #include <QDialog> #include <QMutex> @@ -70,4 +70,4 @@ private: friend class FreespaceChecker; }; -#endif // INTRO_H +#endif // BITCOIN_QT_INTRO_H diff --git a/src/qt/macdockiconhandler.h b/src/qt/macdockiconhandler.h index b21a61cb07..1ffab75c9a 100644 --- a/src/qt/macdockiconhandler.h +++ b/src/qt/macdockiconhandler.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef MACDOCKICONHANDLER_H -#define MACDOCKICONHANDLER_H +#ifndef BITCOIN_QT_MACDOCKICONHANDLER_H +#define BITCOIN_QT_MACDOCKICONHANDLER_H #include <QMainWindow> #include <QObject> @@ -48,4 +48,4 @@ private: QMainWindow *mainWindow; }; -#endif // MACDOCKICONCLICKHANDLER_H +#endif // BITCOIN_QT_MACDOCKICONHANDLER_H diff --git a/src/qt/macnotificationhandler.h b/src/qt/macnotificationhandler.h index bc335edede..f7a4cb7f5b 100644 --- a/src/qt/macnotificationhandler.h +++ b/src/qt/macnotificationhandler.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef MACNOTIFICATIONHANDLER_H -#define MACNOTIFICATIONHANDLER_H +#ifndef BITCOIN_QT_MACNOTIFICATIONHANDLER_H +#define BITCOIN_QT_MACNOTIFICATIONHANDLER_H #include <QObject> @@ -27,4 +27,4 @@ public: }; -#endif // MACNOTIFICATIONHANDLER_H +#endif // BITCOIN_QT_MACNOTIFICATIONHANDLER_H diff --git a/src/qt/networkstyle.h b/src/qt/networkstyle.h index 99304d61a3..e49b86c950 100644 --- a/src/qt/networkstyle.h +++ b/src/qt/networkstyle.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_NETWORKSTYLE -#define H_NETWORKSTYLE +#ifndef BITCOIN_QT_NETWORKSTYLE_H +#define BITCOIN_QT_NETWORKSTYLE_H #include <QIcon> #include <QPixmap> @@ -30,4 +30,4 @@ private: QPixmap splashImage; }; -#endif // H_NETWORKSTYLE +#endif // BITCOIN_QT_NETWORKSTYLE_H diff --git a/src/qt/notificator.h b/src/qt/notificator.h index 3395e64350..61c27e7ff8 100644 --- a/src/qt/notificator.h +++ b/src/qt/notificator.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef NOTIFICATOR_H -#define NOTIFICATOR_H +#ifndef BITCOIN_QT_NOTIFICATOR_H +#define BITCOIN_QT_NOTIFICATOR_H #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" @@ -77,4 +77,4 @@ private: #endif }; -#endif // NOTIFICATOR_H +#endif // BITCOIN_QT_NOTIFICATOR_H diff --git a/src/qt/openuridialog.h b/src/qt/openuridialog.h index 67a5f167d1..f04ec71b32 100644 --- a/src/qt/openuridialog.h +++ b/src/qt/openuridialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef OPENURIDIALOG_H -#define OPENURIDIALOG_H +#ifndef BITCOIN_QT_OPENURIDIALOG_H +#define BITCOIN_QT_OPENURIDIALOG_H #include <QDialog> @@ -31,4 +31,4 @@ private: Ui::OpenURIDialog *ui; }; -#endif // OPENURIDIALOG_H +#endif // BITCOIN_QT_OPENURIDIALOG_H diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 39c53f4391..108609610d 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -2,15 +2,18 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef OPTIONSDIALOG_H -#define OPTIONSDIALOG_H +#ifndef BITCOIN_QT_OPTIONSDIALOG_H +#define BITCOIN_QT_OPTIONSDIALOG_H #include <QDialog> -class QDataWidgetMapper; class OptionsModel; class QValidatedLineEdit; +QT_BEGIN_NAMESPACE +class QDataWidgetMapper; +QT_END_NAMESPACE + namespace Ui { class OptionsDialog; } @@ -56,4 +59,4 @@ private: bool fProxyIpValid; }; -#endif // OPTIONSDIALOG_H +#endif // BITCOIN_QT_OPTIONSDIALOG_H diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 42ea3bf8e5..e2dc067edb 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef OPTIONSMODEL_H -#define OPTIONSMODEL_H +#ifndef BITCOIN_QT_OPTIONSMODEL_H +#define BITCOIN_QT_OPTIONSMODEL_H #include "amount.h" @@ -88,4 +88,4 @@ signals: void coinControlFeaturesChanged(bool); }; -#endif // OPTIONSMODEL_H +#endif // BITCOIN_QT_OPTIONSMODEL_H diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 03f239008f..e889eae8be 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef OVERVIEWPAGE_H -#define OVERVIEWPAGE_H +#ifndef BITCOIN_QT_OVERVIEWPAGE_H +#define BITCOIN_QT_OVERVIEWPAGE_H #include "amount.h" @@ -63,4 +63,4 @@ private slots: void updateWatchOnlyLabels(bool showWatchOnly); }; -#endif // OVERVIEWPAGE_H +#endif // BITCOIN_QT_OVERVIEWPAGE_H diff --git a/src/qt/paymentrequestplus.h b/src/qt/paymentrequestplus.h index 3d94d93269..91c704c520 100644 --- a/src/qt/paymentrequestplus.h +++ b/src/qt/paymentrequestplus.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef PAYMENTREQUESTPLUS_H -#define PAYMENTREQUESTPLUS_H +#ifndef BITCOIN_QT_PAYMENTREQUESTPLUS_H +#define BITCOIN_QT_PAYMENTREQUESTPLUS_H #include "paymentrequest.pb.h" @@ -42,5 +42,4 @@ private: payments::PaymentDetails details; }; -#endif // PAYMENTREQUESTPLUS_H - +#endif // BITCOIN_QT_PAYMENTREQUESTPLUS_H diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index d84d09c57d..25b08cde49 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -2,8 +2,9 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef PAYMENTSERVER_H -#define PAYMENTSERVER_H +#ifndef BITCOIN_QT_PAYMENTSERVER_H +#define BITCOIN_QT_PAYMENTSERVER_H + // This class handles payment requests from clicking on // bitcoin: URIs // @@ -135,4 +136,4 @@ private: OptionsModel *optionsModel; }; -#endif // PAYMENTSERVER_H +#endif // BITCOIN_QT_PAYMENTSERVER_H diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h index 38f2662f89..23e71fc685 100644 --- a/src/qt/peertablemodel.h +++ b/src/qt/peertablemodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef PEERTABLEMODEL_H -#define PEERTABLEMODEL_H +#ifndef BITCOIN_QT_PEERTABLEMODEL_H +#define BITCOIN_QT_PEERTABLEMODEL_H #include "main.h" #include "net.h" @@ -78,4 +78,4 @@ private: QTimer *timer; }; -#endif // PEERTABLEMODEL_H +#endif // BITCOIN_QT_PEERTABLEMODEL_H diff --git a/src/qt/qvalidatedlineedit.h b/src/qt/qvalidatedlineedit.h index c2a4817e65..0996164b0f 100644 --- a/src/qt/qvalidatedlineedit.h +++ b/src/qt/qvalidatedlineedit.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef QVALIDATEDLINEEDIT_H -#define QVALIDATEDLINEEDIT_H +#ifndef BITCOIN_QT_QVALIDATEDLINEEDIT_H +#define BITCOIN_QT_QVALIDATEDLINEEDIT_H #include <QLineEdit> @@ -36,4 +36,4 @@ private slots: void checkValidity(); }; -#endif // QVALIDATEDLINEEDIT_H +#endif // BITCOIN_QT_QVALIDATEDLINEEDIT_H diff --git a/src/qt/qvaluecombobox.h b/src/qt/qvaluecombobox.h index 5f2182913c..821f41716b 100644 --- a/src/qt/qvaluecombobox.h +++ b/src/qt/qvaluecombobox.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef QVALUECOMBOBOX_H -#define QVALUECOMBOBOX_H +#ifndef BITCOIN_QT_QVALUECOMBOBOX_H +#define BITCOIN_QT_QVALUECOMBOBOX_H #include <QComboBox> #include <QVariant> @@ -34,4 +34,4 @@ private slots: void handleSelectionChanged(int idx); }; -#endif // QVALUECOMBOBOX_H +#endif // BITCOIN_QT_QVALUECOMBOBOX_H diff --git a/src/qt/receivecoinsdialog.h b/src/qt/receivecoinsdialog.h index 7a7e38e25e..220fb5c7a8 100644 --- a/src/qt/receivecoinsdialog.h +++ b/src/qt/receivecoinsdialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef RECEIVECOINSDIALOG_H -#define RECEIVECOINSDIALOG_H +#ifndef BITCOIN_QT_RECEIVECOINSDIALOG_H +#define BITCOIN_QT_RECEIVECOINSDIALOG_H #include "guiutil.h" @@ -73,4 +73,4 @@ private slots: void copyAmount(); }; -#endif // RECEIVECOINSDIALOG_H +#endif // BITCOIN_QT_RECEIVECOINSDIALOG_H diff --git a/src/qt/receiverequestdialog.h b/src/qt/receiverequestdialog.h index 9b78e495c3..6f3b9838e2 100644 --- a/src/qt/receiverequestdialog.h +++ b/src/qt/receiverequestdialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef QRCODEDIALOG_H -#define QRCODEDIALOG_H +#ifndef BITCOIN_QT_RECEIVEREQUESTDIALOG_H +#define BITCOIN_QT_RECEIVEREQUESTDIALOG_H #include "walletmodel.h" @@ -67,4 +67,4 @@ private: SendCoinsRecipient info; }; -#endif // QRCODEDIALOG_H +#endif // BITCOIN_QT_RECEIVEREQUESTDIALOG_H diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h index 3df5971823..ec6a49070d 100644 --- a/src/qt/recentrequeststablemodel.h +++ b/src/qt/recentrequeststablemodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef RECENTREQUESTSTABLEMODEL_H -#define RECENTREQUESTSTABLEMODEL_H +#ifndef BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H +#define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H #include "walletmodel.h" @@ -105,4 +105,4 @@ private: QString getAmountTitle(); }; -#endif +#endif // BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 1ffff92758..4bb9b62e93 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef RPCCONSOLE_H -#define RPCCONSOLE_H +#ifndef BITCOIN_QT_RPCCONSOLE_H +#define BITCOIN_QT_RPCCONSOLE_H #include "guiutil.h" #include "peertablemodel.h" @@ -100,4 +100,4 @@ private: NodeId cachedNodeid; }; -#endif // RPCCONSOLE_H +#endif // BITCOIN_QT_RPCCONSOLE_H diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 74cc4bde56..eec661cbd0 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef SENDCOINSDIALOG_H -#define SENDCOINSDIALOG_H +#ifndef BITCOIN_QT_SENDCOINSDIALOG_H +#define BITCOIN_QT_SENDCOINSDIALOG_H #include "walletmodel.h" @@ -83,4 +83,4 @@ signals: void message(const QString &title, const QString &message, unsigned int style); }; -#endif // SENDCOINSDIALOG_H +#endif // BITCOIN_QT_SENDCOINSDIALOG_H diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index 2b696c77fb..69ad1032df 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef SENDCOINSENTRY_H -#define SENDCOINSENTRY_H +#ifndef BITCOIN_QT_SENDCOINSENTRY_H +#define BITCOIN_QT_SENDCOINSENTRY_H #include "walletmodel.h" @@ -67,4 +67,4 @@ private: bool updateLabel(const QString &address); }; -#endif // SENDCOINSENTRY_H +#endif // BITCOIN_QT_SENDCOINSENTRY_H diff --git a/src/qt/signverifymessagedialog.h b/src/qt/signverifymessagedialog.h index bba861649a..36550edc8d 100644 --- a/src/qt/signverifymessagedialog.h +++ b/src/qt/signverifymessagedialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef SIGNVERIFYMESSAGEDIALOG_H -#define SIGNVERIFYMESSAGEDIALOG_H +#ifndef BITCOIN_QT_SIGNVERIFYMESSAGEDIALOG_H +#define BITCOIN_QT_SIGNVERIFYMESSAGEDIALOG_H #include <QDialog> @@ -48,4 +48,4 @@ private slots: void on_clearButton_VM_clicked(); }; -#endif // SIGNVERIFYMESSAGEDIALOG_H +#endif // BITCOIN_QT_SIGNVERIFYMESSAGEDIALOG_H diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h index 128edadbee..4d9651f022 100644 --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef SPLASHSCREEN_H -#define SPLASHSCREEN_H +#ifndef BITCOIN_QT_SPLASHSCREEN_H +#define BITCOIN_QT_SPLASHSCREEN_H #include <QSplashScreen> @@ -46,4 +46,4 @@ private: int curAlignment; }; -#endif // SPLASHSCREEN_H +#endif // BITCOIN_QT_SPLASHSCREEN_H diff --git a/src/qt/test/paymentservertests.h b/src/qt/test/paymentservertests.h index 9b6400b0d5..0717111f66 100644 --- a/src/qt/test/paymentservertests.h +++ b/src/qt/test/paymentservertests.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef PAYMENTSERVERTESTS_H -#define PAYMENTSERVERTESTS_H +#ifndef BITCOIN_QT_TEST_PAYMENTSERVERTESTS_H +#define BITCOIN_QT_TEST_PAYMENTSERVERTESTS_H #include "../paymentserver.h" @@ -32,4 +32,4 @@ public: SendCoinsRecipient recipient; }; -#endif // PAYMENTSERVERTESTS_H +#endif // BITCOIN_QT_TEST_PAYMENTSERVERTESTS_H diff --git a/src/qt/test/uritests.h b/src/qt/test/uritests.h index 1ea6d9f075..ed30a9f4a7 100644 --- a/src/qt/test/uritests.h +++ b/src/qt/test/uritests.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef URITESTS_H -#define URITESTS_H +#ifndef BITCOIN_QT_TEST_URITESTS_H +#define BITCOIN_QT_TEST_URITESTS_H #include <QObject> #include <QTest> @@ -16,4 +16,4 @@ private slots: void uriTests(); }; -#endif // URITESTS_H +#endif // BITCOIN_QT_TEST_URITESTS_H diff --git a/src/qt/trafficgraphwidget.h b/src/qt/trafficgraphwidget.h index efab6e7fc5..50571e0b2d 100644 --- a/src/qt/trafficgraphwidget.h +++ b/src/qt/trafficgraphwidget.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRAFFICGRAPHWIDGET_H -#define TRAFFICGRAPHWIDGET_H +#ifndef BITCOIN_QT_TRAFFICGRAPHWIDGET_H +#define BITCOIN_QT_TRAFFICGRAPHWIDGET_H #include <QWidget> #include <QQueue> @@ -45,4 +45,4 @@ private: ClientModel *clientModel; }; -#endif // TRAFFICGRAPHWIDGET_H +#endif // BITCOIN_QT_TRAFFICGRAPHWIDGET_H diff --git a/src/qt/transactiondesc.h b/src/qt/transactiondesc.h index 4bd4293210..fc958a097c 100644 --- a/src/qt/transactiondesc.h +++ b/src/qt/transactiondesc.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONDESC_H -#define TRANSACTIONDESC_H +#ifndef BITCOIN_QT_TRANSACTIONDESC_H +#define BITCOIN_QT_TRANSACTIONDESC_H #include <QObject> #include <QString> @@ -28,4 +28,4 @@ private: static QString FormatTxStatus(const CWalletTx& wtx); }; -#endif // TRANSACTIONDESC_H +#endif // BITCOIN_QT_TRANSACTIONDESC_H diff --git a/src/qt/transactiondescdialog.h b/src/qt/transactiondescdialog.h index d4719975b2..c12c18e824 100644 --- a/src/qt/transactiondescdialog.h +++ b/src/qt/transactiondescdialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONDESCDIALOG_H -#define TRANSACTIONDESCDIALOG_H +#ifndef BITCOIN_QT_TRANSACTIONDESCDIALOG_H +#define BITCOIN_QT_TRANSACTIONDESCDIALOG_H #include <QDialog> @@ -28,4 +28,4 @@ private: Ui::TransactionDescDialog *ui; }; -#endif // TRANSACTIONDESCDIALOG_H +#endif // BITCOIN_QT_TRANSACTIONDESCDIALOG_H diff --git a/src/qt/transactionfilterproxy.h b/src/qt/transactionfilterproxy.h index ca31ee8f87..5836b114ab 100644 --- a/src/qt/transactionfilterproxy.h +++ b/src/qt/transactionfilterproxy.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONFILTERPROXY_H -#define TRANSACTIONFILTERPROXY_H +#ifndef BITCOIN_QT_TRANSACTIONFILTERPROXY_H +#define BITCOIN_QT_TRANSACTIONFILTERPROXY_H #include "amount.h" @@ -65,4 +65,4 @@ private: bool showInactive; }; -#endif // TRANSACTIONFILTERPROXY_H +#endif // BITCOIN_QT_TRANSACTIONFILTERPROXY_H diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 9276c9f0af..e26453cda4 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONRECORD_H -#define TRANSACTIONRECORD_H +#ifndef BITCOIN_QT_TRANSACTIONRECORD_H +#define BITCOIN_QT_TRANSACTIONRECORD_H #include "amount.h" #include "uint256.h" @@ -140,4 +140,4 @@ public: bool statusUpdateNeeded(); }; -#endif // TRANSACTIONRECORD_H +#endif // BITCOIN_QT_TRANSACTIONRECORD_H diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index bb517a969c..cfefe4cf19 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONTABLEMODEL_H -#define TRANSACTIONTABLEMODEL_H +#ifndef BITCOIN_QT_TRANSACTIONTABLEMODEL_H +#define BITCOIN_QT_TRANSACTIONTABLEMODEL_H #include "bitcoinunits.h" @@ -109,4 +109,4 @@ public slots: friend class TransactionTablePriv; }; -#endif // TRANSACTIONTABLEMODEL_H +#endif // BITCOIN_QT_TRANSACTIONTABLEMODEL_H diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index b249e00411..be6989adee 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef TRANSACTIONVIEW_H -#define TRANSACTIONVIEW_H +#ifndef BITCOIN_QT_TRANSACTIONVIEW_H +#define BITCOIN_QT_TRANSACTIONVIEW_H #include "guiutil.h" @@ -112,4 +112,4 @@ public slots: }; -#endif // TRANSACTIONVIEW_H +#endif // BITCOIN_QT_TRANSACTIONVIEW_H diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h index ae5045cca9..e10b4dc8af 100644 --- a/src/qt/utilitydialog.h +++ b/src/qt/utilitydialog.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef UTILITYDIALOG_H -#define UTILITYDIALOG_H +#ifndef BITCOIN_QT_UTILITYDIALOG_H +#define BITCOIN_QT_UTILITYDIALOG_H #include <QDialog> #include <QObject> @@ -49,4 +49,4 @@ protected: void closeEvent(QCloseEvent *event); }; -#endif // UTILITYDIALOG_H +#endif // BITCOIN_QT_UTILITYDIALOG_H diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index f1830a0d6b..ae8592840d 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef WALLETFRAME_H -#define WALLETFRAME_H +#ifndef BITCOIN_QT_WALLETFRAME_H +#define BITCOIN_QT_WALLETFRAME_H #include <QFrame> #include <QMap> @@ -77,4 +77,4 @@ public slots: void usedReceivingAddresses(); }; -#endif // WALLETFRAME_H +#endif // BITCOIN_QT_WALLETFRAME_H diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index fe91e9d9fa..0c6077963d 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef WALLETMODEL_H -#define WALLETMODEL_H +#ifndef BITCOIN_QT_WALLETMODEL_H +#define BITCOIN_QT_WALLETMODEL_H #include "paymentrequestplus.h" #include "walletmodeltransaction.h" @@ -261,4 +261,4 @@ public slots: void pollBalanceChanged(); }; -#endif // WALLETMODEL_H +#endif // BITCOIN_QT_WALLETMODEL_H diff --git a/src/qt/walletmodeltransaction.h b/src/qt/walletmodeltransaction.h index 4eadfbe4d1..a880384ed6 100644 --- a/src/qt/walletmodeltransaction.h +++ b/src/qt/walletmodeltransaction.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef WALLETMODELTRANSACTION_H -#define WALLETMODELTRANSACTION_H +#ifndef BITCOIN_QT_WALLETMODELTRANSACTION_H +#define BITCOIN_QT_WALLETMODELTRANSACTION_H #include "walletmodel.h" @@ -41,4 +41,4 @@ private: CAmount fee; }; -#endif // WALLETMODELTRANSACTION_H +#endif // BITCOIN_QT_WALLETMODELTRANSACTION_H diff --git a/src/qt/walletview.h b/src/qt/walletview.h index cafba517fd..95890ccd67 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef WALLETVIEW_H -#define WALLETVIEW_H +#ifndef BITCOIN_QT_WALLETVIEW_H +#define BITCOIN_QT_WALLETVIEW_H #include "amount.h" @@ -116,4 +116,4 @@ signals: void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address); }; -#endif // WALLETVIEW_H +#endif // BITCOIN_QT_WALLETVIEW_H diff --git a/src/qt/winshutdownmonitor.h b/src/qt/winshutdownmonitor.h index 4c76d2c816..26f5d80361 100644 --- a/src/qt/winshutdownmonitor.h +++ b/src/qt/winshutdownmonitor.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef WINSHUTDOWNMONITOR_H -#define WINSHUTDOWNMONITOR_H +#ifndef BITCOIN_QT_WINSHUTDOWNMONITOR_H +#define BITCOIN_QT_WINSHUTDOWNMONITOR_H #ifdef WIN32 #include <QByteArray> @@ -26,4 +26,4 @@ public: #endif #endif -#endif // WINSHUTDOWNMONITOR_H +#endif // BITCOIN_QT_WINSHUTDOWNMONITOR_H diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 78f5569895..a7cd63bd95 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -474,7 +474,7 @@ struct CompareBlocksByHeight bool operator()(const CBlockIndex* a, const CBlockIndex* b) const { /* Make sure that unequal blocks with the same height do not compare - equal. Use the pointers themselves to make a distinction. */ + equal. Use the pointers themselves to make a distinction. */ if (a->nHeight != b->nHeight) return (a->nHeight > b->nHeight); diff --git a/src/rpcclient.h b/src/rpcclient.h index 307aa2aab8..cd11f177e8 100644 --- a/src/rpcclient.h +++ b/src/rpcclient.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOINRPC_CLIENT_H_ -#define _BITCOINRPC_CLIENT_H_ +#ifndef BITCOIN_RPCCLIENT_H +#define BITCOIN_RPCCLIENT_H #include "json/json_spirit_reader_template.h" #include "json/json_spirit_utils.h" @@ -12,4 +12,4 @@ json_spirit::Array RPCConvertValues(const std::string& strMethod, const std::vector<std::string>& strParams); -#endif // _BITCOINRPC_CLIENT_H_ +#endif // BITCOIN_RPCCLIENT_H diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8af3c46348..879a504115 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -527,6 +527,24 @@ Value getblocktemplate(const Array& params, bool fHelp) return result; } +class submitblock_StateCatcher : public CValidationInterface +{ +public: + uint256 hash; + bool found; + CValidationState state; + + submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {}; + +protected: + virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) { + if (block.GetHash() != hash) + return; + found = true; + state = stateIn; + }; +}; + Value submitblock(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -559,9 +577,28 @@ Value submitblock(const Array& params, bool fHelp) } CValidationState state; - bool fAccepted = ProcessBlock(state, NULL, &pblock); - if (!fAccepted) - return "rejected"; // TODO: report validation state + submitblock_StateCatcher sc(pblock.GetHash()); + RegisterValidationInterface(&sc); + bool fAccepted = ProcessNewBlock(state, NULL, &pblock); + UnregisterValidationInterface(&sc); + if (fAccepted) + { + if (!sc.found) + return "inconclusive"; + state = sc.state; + } + if (state.IsError()) + { + std::string strRejectReason = state.GetRejectReason(); + throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason); + } + if (state.IsInvalid()) + { + std::string strRejectReason = state.GetRejectReason(); + if (strRejectReason.empty()) + return "rejected"; + return strRejectReason; + } return Value::null; } diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index a9adb58803..9926daaf3d 100644 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOINRPC_PROTOCOL_H_ -#define _BITCOINRPC_PROTOCOL_H_ +#ifndef BITCOIN_RPCPROTOCOL_H +#define BITCOIN_RPCPROTOCOL_H #include <list> #include <map> @@ -49,9 +49,14 @@ enum RPCErrorCode RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter RPC_DATABASE_ERROR = -20, // Database error RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format - RPC_TRANSACTION_ERROR = -25, // General error during transaction submission - RPC_TRANSACTION_REJECTED = -26, // Transaction was rejected by network rules - RPC_TRANSACTION_ALREADY_IN_CHAIN= -27, // Transaction already in chain + RPC_VERIFY_ERROR = -25, // General error during transaction or block submission + RPC_VERIFY_REJECTED = -26, // Transaction or block was rejected by network rules + RPC_VERIFY_ALREADY_IN_CHAIN = -27, // Transaction already in chain + + // Aliases for backward compatibility + RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR, + RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED, + RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN, // P2P client errors RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected @@ -159,4 +164,4 @@ json_spirit::Object JSONRPCReplyObj(const json_spirit::Value& result, const json std::string JSONRPCReply(const json_spirit::Value& result, const json_spirit::Value& error, const json_spirit::Value& id); json_spirit::Object JSONRPCError(int code, const std::string& message); -#endif // _BITCOINRPC_PROTOCOL_H_ +#endif // BITCOIN_RPCPROTOCOL_H diff --git a/src/rpcserver.h b/src/rpcserver.h index cc444cef1f..2f34b11d22 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -3,12 +3,12 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef _BITCOINRPC_SERVER_H_ -#define _BITCOINRPC_SERVER_H_ +#ifndef BITCOIN_RPCSERVER_H +#define BITCOIN_RPCSERVER_H #include "amount.h" -#include "uint256.h" #include "rpcprotocol.h" +#include "uint256.h" #include <list> #include <map> @@ -211,4 +211,4 @@ extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp); -#endif // _BITCOINRPC_SERVER_H_ +#endif // BITCOIN_RPCSERVER_H diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 3625972ebf..54c2847f79 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -9,7 +9,8 @@ #include "crypto/ripemd160.h" #include "crypto/sha1.h" #include "crypto/sha2.h" -#include "key.h" +#include "eccryptoverify.h" +#include "pubkey.h" #include "script/script.h" #include "uint256.h" #include "util.h" @@ -122,7 +123,7 @@ bool static IsLowDERSignature(const valtype &vchSig) { // If the S value is above the order of the curve divided by two, its // complement modulo the order could have been used instead, which is // one byte shorter when encoded correctly. - if (!CKey::CheckSignatureElement(S, nLenS, true)) + if (!eccrypto::CheckSignatureElement(S, nLenS, true)) return error("Non-canonical signature: S value is unnecessarily high"); return true; diff --git a/src/script/interpreter.h b/src/script/interpreter.h index 5133c80aab..ed899fc411 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPT_INTERPRETER -#define H_BITCOIN_SCRIPT_INTERPRETER +#ifndef BITCOIN_SCRIPT_INTERPRETER_H +#define BITCOIN_SCRIPT_INTERPRETER_H #include <vector> #include <stdint.h> @@ -88,4 +88,4 @@ public: bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker); bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker); -#endif // H_BITCOIN_SCRIPT_INTERPRETER +#endif // BITCOIN_SCRIPT_INTERPRETER_H diff --git a/src/script/script.h b/src/script/script.h index 05f2e7e3a9..e525ad13ee 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPT -#define H_BITCOIN_SCRIPT +#ifndef BITCOIN_SCRIPT_SCRIPT_H +#define BITCOIN_SCRIPT_SCRIPT_H #include <assert.h> #include <climits> @@ -592,4 +592,4 @@ public: } }; -#endif // H_BITCOIN_SCRIPT +#endif // BITCOIN_SCRIPT_SCRIPT_H diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index ab366898d8..d76a5acd63 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -5,7 +5,7 @@ #include "sigcache.h" -#include "key.h" +#include "pubkey.h" #include "random.h" #include "uint256.h" #include "util.h" diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 46b8f4d335..df2a2ea13c 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPT_SIGCACHE -#define H_BITCOIN_SCRIPT_SIGCACHE +#ifndef BITCOIN_SCRIPT_SIGCACHE_H +#define BITCOIN_SCRIPT_SIGCACHE_H #include "script/interpreter.h" @@ -23,4 +23,4 @@ public: bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const; }; -#endif // H_BITCOIN_SCRIPT_SIGCACHE +#endif // BITCOIN_SCRIPT_SIGCACHE_H diff --git a/src/script/sign.h b/src/script/sign.h index f218a64562..c84d3f9a94 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPT_SIGN -#define H_BITCOIN_SCRIPT_SIGN +#ifndef BITCOIN_SCRIPT_SIGN_H +#define BITCOIN_SCRIPT_SIGN_H #include "script/interpreter.h" @@ -21,4 +21,4 @@ bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CMutab // combine them intelligently and return the result. CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsigned int nIn, const CScript& scriptSig1, const CScript& scriptSig2); -#endif // H_BITCOIN_SCRIPT_SIGN +#endif // BITCOIN_SCRIPT_SIGN_H diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 7356e541a6..e238ecedb0 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -5,6 +5,7 @@ #include "script/standard.h" +#include "pubkey.h" #include "script/script.h" #include "util.h" #include "utilstrencodings.h" diff --git a/src/script/standard.h b/src/script/standard.h index 504d98c686..faa7747604 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -3,11 +3,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPT_STANDARD -#define H_BITCOIN_SCRIPT_STANDARD +#ifndef BITCOIN_SCRIPT_STANDARD_H +#define BITCOIN_SCRIPT_STANDARD_H -#include "key.h" -#include "script/script.h" +#include "uint256.h" #include "script/interpreter.h" #include <boost/variant.hpp> @@ -15,6 +14,7 @@ #include <stdint.h> class CScript; +class CKeyID; /** A reference to a CScript: the Hash160 of its serialization (see script.h) */ class CScriptID : public uint160 @@ -84,4 +84,4 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std:: CScript GetScriptForDestination(const CTxDestination& dest); CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys); -#endif // H_BITCOIN_SCRIPT_STANDARD +#endif // BITCOIN_SCRIPT_STANDARD_H diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp index 9cf7a98f46..4869ba52ac 100644 --- a/src/test/alert_tests.cpp +++ b/src/test/alert_tests.cpp @@ -154,9 +154,6 @@ BOOST_AUTO_TEST_CASE(AlertApplies) } -// This uses sh 'echo' to test the -alertnotify function, writing to a -// /tmp file. So skip it on Windows: -#ifndef WIN32 BOOST_AUTO_TEST_CASE(AlertNotify) { SetMockTime(11); @@ -171,15 +168,24 @@ BOOST_AUTO_TEST_CASE(AlertNotify) std::vector<std::string> r = read_lines(temp); BOOST_CHECK_EQUAL(r.size(), 4u); + +// Windows built-in echo semantics are different than posixy shells. Quotes and +// whitespace are printed literally. + +#ifndef WIN32 BOOST_CHECK_EQUAL(r[0], "Alert 1"); BOOST_CHECK_EQUAL(r[1], "Alert 2, cancels 1"); BOOST_CHECK_EQUAL(r[2], "Alert 2, cancels 1"); BOOST_CHECK_EQUAL(r[3], "Evil Alert; /bin/ls; echo "); // single-quotes should be removed - +#else + BOOST_CHECK_EQUAL(r[0], "'Alert 1' "); + BOOST_CHECK_EQUAL(r[1], "'Alert 2, cancels 1' "); + BOOST_CHECK_EQUAL(r[2], "'Alert 2, cancels 1' "); + BOOST_CHECK_EQUAL(r[3], "'Evil Alert; /bin/ls; echo ' "); +#endif boost::filesystem::remove(temp); SetMockTime(0); } -#endif BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/bignum.h b/src/test/bignum.h index 86980b2af6..f64c987202 100644 --- a/src/test/bignum.h +++ b/src/test/bignum.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_BIGNUM_H -#define BITCOIN_BIGNUM_H +#ifndef BITCOIN_TEST_BIGNUM_H +#define BITCOIN_TEST_BIGNUM_H #include <algorithm> #include <limits> @@ -177,4 +177,4 @@ inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, 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); } -#endif +#endif // BITCOIN_TEST_BIGNUM_H diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 93b7fe189a..9a31bdf5fd 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -4,6 +4,7 @@ #include "main.h" #include "miner.h" +#include "pubkey.h" #include "uint256.h" #include "util.h" @@ -79,7 +80,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) pblock->hashMerkleRoot = pblock->BuildMerkleTree(); pblock->nNonce = blockinfo[i].nonce; CValidationState state; - BOOST_CHECK(ProcessBlock(state, NULL, pblock)); + BOOST_CHECK(ProcessNewBlock(state, NULL, pblock)); BOOST_CHECK(state.IsValid()); pblock->hashPrevBlock = pblock->GetHash(); } diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index 7b27703b62..5bf0862c71 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "pubkey.h" #include "key.h" #include "script/script.h" #include "script/standard.h" diff --git a/src/txdb.h b/src/txdb.h index 8f2bd9af4d..147c186990 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_TXDB_LEVELDB_H -#define BITCOIN_TXDB_LEVELDB_H +#ifndef BITCOIN_TXDB_H +#define BITCOIN_TXDB_H #include "leveldbwrapper.h" #include "main.h" @@ -62,4 +62,4 @@ public: bool LoadBlockIndexGuts(); }; -#endif // BITCOIN_TXDB_LEVELDB_H +#endif // BITCOIN_TXDB_H diff --git a/src/txmempool.cpp b/src/txmempool.cpp index d3d9cb8a01..b5070d5104 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -332,7 +332,7 @@ public: size_t numEntries; filein >> numEntries; if (numEntries <= 0 || numEntries > 10000) - throw runtime_error("Corrupt estimates file. Must have between 1 and 10k entires."); + throw runtime_error("Corrupt estimates file. Must have between 1 and 10k entires."); std::vector<CBlockAverage> fileHistory; @@ -343,8 +343,8 @@ public: fileHistory.push_back(entry); } - //Now that we've processed the entire fee estimate data file and not - //thrown any errors, we can copy it to our history + // Now that we've processed the entire fee estimate data file and not + // thrown any errors, we can copy it to our history nBestSeenHeight = nFileBestSeenHeight; history = fileHistory; assert(history.size() > 0); diff --git a/src/undo.h b/src/undo.h index 232c193429..4f5f4047dd 100644 --- a/src/undo.h +++ b/src/undo.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_TXUNDO -#define H_BITCOIN_TXUNDO +#ifndef BITCOIN_UNDO_H +#define BITCOIN_UNDO_H #include "compressor.h" #include "core/transaction.h" @@ -68,4 +68,4 @@ public: } }; -#endif // H_BITCOIN_TXUNDO +#endif // BITCOIN_UNDO_H diff --git a/src/univalue/gen.cpp b/src/univalue/gen.cpp index 881948f46e..f0b352eef0 100644 --- a/src/univalue/gen.cpp +++ b/src/univalue/gen.cpp @@ -35,8 +35,8 @@ static void initJsonEscape() static void outputEscape() { printf( "// Automatically generated file. Do not modify.\n" - "#ifndef __UNIVALUE_ESCAPES_H__\n" - "#define __UNIVALUE_ESCAPES_H__\n" + "#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" + "#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" "static const char *escapes[256] = {\n"); for (unsigned int i = 0; i < 256; i++) { @@ -66,7 +66,7 @@ static void outputEscape() } printf( "};\n" - "#endif // __UNIVALUE_ESCAPES_H__\n"); + "#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"); } int main (int argc, char *argv[]) diff --git a/src/univalue/univalue.h b/src/univalue/univalue.h index 0a7bf3cceb..5ac301d9e5 100644 --- a/src/univalue/univalue.h +++ b/src/univalue/univalue.h @@ -2,8 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __UNIVALUE_H__ -#define __UNIVALUE_H__ +#ifndef BITCOIN_UNIVALUE_UNIVALUE_H +#define BITCOIN_UNIVALUE_UNIVALUE_H #include <stdint.h> #include <string> @@ -152,4 +152,4 @@ extern enum jtokentype getJsonToken(std::string& tokenVal, unsigned int& consumed, const char *raw); extern const char *uvTypeName(UniValue::VType t); -#endif // __UNIVALUE_H__ +#endif // BITCOIN_UNIVALUE_UNIVALUE_H diff --git a/src/univalue/univalue_escapes.h b/src/univalue/univalue_escapes.h index 1d3a70a968..0514118285 100644 --- a/src/univalue/univalue_escapes.h +++ b/src/univalue/univalue_escapes.h @@ -1,6 +1,6 @@ // Automatically generated file. Do not modify. -#ifndef __UNIVALUE_ESCAPES_H__ -#define __UNIVALUE_ESCAPES_H__ +#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H +#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H static const char *escapes[256] = { NULL, NULL, @@ -259,4 +259,4 @@ static const char *escapes[256] = { NULL, NULL, }; -#endif // __UNIVALUE_ESCAPES_H__ +#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 81e156f43f..15094e5999 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -7,10 +7,10 @@ #include "tinyformat.h" -#include <errno.h> -#include <limits> #include <cstdlib> #include <cstring> +#include <errno.h> +#include <limits> using namespace std; diff --git a/src/wallet_ismine.cpp b/src/wallet_ismine.cpp index 07149ebd0b..05dc40aaee 100644 --- a/src/wallet_ismine.cpp +++ b/src/wallet_ismine.cpp @@ -7,6 +7,7 @@ #include "key.h" #include "keystore.h" +#include "script/script.h" #include "script/standard.h" #include <boost/foreach.hpp> diff --git a/src/wallet_ismine.h b/src/wallet_ismine.h index f326b86815..5f0c0c1a01 100644 --- a/src/wallet_ismine.h +++ b/src/wallet_ismine.h @@ -3,8 +3,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_WALLET_ISMINE -#define H_BITCOIN_WALLET_ISMINE +#ifndef BITCOIN_WALLET_ISMINE_H +#define BITCOIN_WALLET_ISMINE_H #include "key.h" #include "script/standard.h" @@ -26,4 +26,4 @@ typedef uint8_t isminefilter; isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest); -#endif // H_BITCOIN_WALLET_ISMINE +#endif // BITCOIN_WALLET_ISMINE_H |