aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml113
-rw-r--r--.travis/README.md8
-rwxr-xr-x.travis/lint_04_install.sh9
-rwxr-xr-x.travis/lint_05_before_script.sh9
-rwxr-xr-x.travis/lint_06_script.sh24
-rwxr-xr-x.travis/test_03_before_install.sh25
-rwxr-xr-x.travis/test_04_install.sh26
-rwxr-xr-x.travis/test_05_before_script.sh25
-rwxr-xr-x.travis/test_06_script.sh67
-rwxr-xr-xcontrib/devtools/symbol-check.py48
-rw-r--r--contrib/gitian-descriptors/gitian-linux.yml14
-rw-r--r--contrib/testgen/README.md4
-rwxr-xr-xcontrib/testgen/gen_base58_test_vectors.py132
-rwxr-xr-xcontrib/testgen/gen_key_io_test_vectors.py249
-rw-r--r--depends/config.site.in9
-rw-r--r--doc/release-notes-14023.md8
-rw-r--r--src/Makefile.test.include1
-rw-r--r--src/bench/crypto_hash.cpp6
-rw-r--r--src/bench/mempool_eviction.cpp2
-rw-r--r--src/bench/rollingbloom.cpp3
-rw-r--r--src/compat.h6
-rw-r--r--src/fs.cpp84
-rw-r--r--src/fs.h21
-rw-r--r--src/init.cpp2
-rw-r--r--src/interfaces/handler.cpp2
-rw-r--r--src/interfaces/wallet.cpp7
-rw-r--r--src/interfaces/wallet.h1
-rw-r--r--src/key_io.cpp2
-rw-r--r--src/logging.cpp10
-rw-r--r--src/net.cpp1
-rw-r--r--src/net.h1
-rw-r--r--src/netbase.cpp4
-rw-r--r--src/policy/fees.h90
-rw-r--r--src/prevector.h10
-rw-r--r--src/qt/addresstablemodel.cpp2
-rw-r--r--src/qt/bitcoingui.h2
-rw-r--r--src/qt/rpcconsole.cpp4
-rw-r--r--src/qt/transactiontablemodel.cpp2
-rw-r--r--src/qt/walletmodel.cpp2
-rw-r--r--src/rpc/client.cpp10
-rw-r--r--src/rpc/net.cpp2
-rw-r--r--src/rpc/rawtransaction.cpp18
-rw-r--r--src/rpc/server.cpp5
-rw-r--r--src/script/sign.cpp55
-rw-r--r--src/script/sign.h49
-rw-r--r--src/test/blockencodings_tests.cpp6
-rw-r--r--src/test/descriptor_tests.cpp2
-rw-r--r--src/test/mempool_tests.cpp84
-rw-r--r--src/test/miner_tests.cpp50
-rw-r--r--src/test/netbase_tests.cpp18
-rw-r--r--src/test/policyestimator_tests.cpp6
-rw-r--r--src/test/scheduler_tests.cpp2
-rw-r--r--src/test/script_tests.cpp8
-rw-r--r--src/test/txindex_tests.cpp2
-rw-r--r--src/test/util_tests.cpp39
-rw-r--r--src/test/validation_block_tests.cpp2
-rw-r--r--src/txmempool.cpp22
-rw-r--r--src/txmempool.h20
-rw-r--r--src/util.cpp40
-rw-r--r--src/util.h15
-rw-r--r--src/utilstrencodings.cpp53
-rw-r--r--src/utilstrencodings.h47
-rw-r--r--src/validation.cpp4
-rw-r--r--src/wallet/feebumper.cpp2
-rw-r--r--src/wallet/init.cpp2
-rw-r--r--src/wallet/rpcdump.cpp2
-rw-r--r--src/wallet/rpcwallet.cpp896
-rw-r--r--src/wallet/test/accounting_tests.cpp136
-rw-r--r--src/wallet/test/coinselector_tests.cpp10
-rw-r--r--src/wallet/test/psbt_wallet_tests.cpp2
-rw-r--r--src/wallet/test/wallet_tests.cpp2
-rw-r--r--src/wallet/wallet.cpp204
-rw-r--r--src/wallet/wallet.h143
-rw-r--r--src/wallet/walletdb.cpp110
-rw-r--r--src/wallet/walletdb.h12
-rwxr-xr-xtest/functional/combine_logs.py18
-rwxr-xr-xtest/functional/feature_block.py76
-rwxr-xr-xtest/functional/mining_basic.py2
-rwxr-xr-xtest/functional/p2p_invalid_block.py6
-rwxr-xr-xtest/functional/p2p_segwit.py222
-rwxr-xr-xtest/functional/rpc_deprecated.py80
-rwxr-xr-xtest/functional/rpc_help.py31
-rwxr-xr-xtest/functional/rpc_net.py5
-rwxr-xr-xtest/functional/rpc_psbt.py10
-rwxr-xr-xtest/functional/rpc_rawtransaction.py2
-rwxr-xr-xtest/functional/test_framework/mininode.py10
-rwxr-xr-xtest/functional/test_runner.py1
-rwxr-xr-xtest/functional/wallet_address_types.py2
-rwxr-xr-xtest/functional/wallet_labels.py126
-rwxr-xr-xtest/lint/lint-includes.sh2
-rwxr-xr-xtest/lint/lint-locale-dependence.sh2
-rwxr-xr-xtest/lint/lint-shell-locale.sh5
92 files changed, 1493 insertions, 2222 deletions
diff --git a/.travis.yml b/.travis.yml
index aafdc2e89d..8819d38914 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,19 +5,19 @@ language: minimal
cache:
ccache: true
directories:
- - depends/built
- - depends/sdk-sources
- - $HOME/.ccache
+ - depends/built
+ - depends/sdk-sources
+ - $HOME/.ccache
stages:
- lint
- test
env:
global:
- MAKEJOBS=-j3
- - RUN_TESTS=false
+ - RUN_UNIT_TESTS=true
+ - RUN_FUNCTIONAL_TESTS=true
- RUN_BENCH=false # Set to true for any one job that has debug enabled, to quickly check bench is not crashing or hitting assertions
- DOCKER_NAME_TAG=ubuntu:18.04
- - LC_ALL=C.UTF-8
- BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID
- CCACHE_SIZE=100M
- CCACHE_TEMPDIR=/tmp/.ccache-temp
@@ -28,54 +28,43 @@ env:
- WINEDEBUG=fixme-all
- DOCKER_PACKAGES="build-essential libtool autotools-dev automake pkg-config bsdmainutils curl git ca-certificates ccache"
before_install:
- - export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")
- - BEGIN_FOLD () { echo ""; CURRENT_FOLD_NAME=$1; echo "travis_fold:start:${CURRENT_FOLD_NAME}"; }
- - END_FOLD () { RET=$?; echo "travis_fold:end:${CURRENT_FOLD_NAME}"; return $RET; }
+ - set -o errexit; source .travis/test_03_before_install.sh
install:
- - travis_retry docker pull $DOCKER_NAME_TAG
- - env | grep -E '^(CCACHE_|WINEDEBUG|LC_ALL|BOOST_TEST_RANDOM|CONFIG_SHELL)' | tee /tmp/env
- - if [[ $HOST = *-mingw32 ]]; then DOCKER_ADMIN="--cap-add SYS_ADMIN"; fi
- - DOCKER_ID=$(docker run $DOCKER_ADMIN -idt --mount type=bind,src=$TRAVIS_BUILD_DIR,dst=$TRAVIS_BUILD_DIR --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR -w $TRAVIS_BUILD_DIR --env-file /tmp/env $DOCKER_NAME_TAG)
- - DOCKER_EXEC () { docker exec $DOCKER_ID bash -c "cd $PWD && $*"; }
- - if [ -n "$DPKG_ADD_ARCH" ]; then DOCKER_EXEC dpkg --add-architecture "$DPKG_ADD_ARCH" ; fi
- - travis_retry DOCKER_EXEC apt-get update
- - travis_retry DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES $DOCKER_PACKAGES
+ - set -o errexit; source .travis/test_04_install.sh
before_script:
- - DOCKER_EXEC echo \> \$HOME/.bitcoin # Make sure default datadir does not exist and is never read by creating a dummy file
- - mkdir -p depends/SDKs depends/sdk-sources
- - if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi
- - if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi
- - if [[ $HOST = *-mingw32 ]]; then DOCKER_EXEC update-alternatives --set $HOST-g++ \$\(which $HOST-g++-posix\); fi
- - if [ -z "$NO_DEPENDS" ]; then DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS; fi
+ - set -o errexit; source .travis/test_05_before_script.sh
script:
- - export TRAVIS_COMMIT_LOG=`git log --format=fuller -1`
- - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST
- - BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib"
- - if [ -z "$NO_DEPENDS" ]; then DOCKER_EXEC ccache --max-size=$CCACHE_SIZE; fi
- - BEGIN_FOLD autogen; test -n "$CONFIG_SHELL" && DOCKER_EXEC "$CONFIG_SHELL" -c "./autogen.sh" || DOCKER_EXEC ./autogen.sh; END_FOLD
- - mkdir build && cd build
- - BEGIN_FOLD configure; DOCKER_EXEC ../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false); END_FOLD
- - BEGIN_FOLD distdir; DOCKER_EXEC make distdir VERSION=$HOST; END_FOLD
- - cd bitcoin-$HOST
- - BEGIN_FOLD configure; DOCKER_EXEC ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false); END_FOLD
- - BEGIN_FOLD build; DOCKER_EXEC make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && DOCKER_EXEC make $GOAL V=1 ; false ); END_FOLD
- - if [ "$RUN_TESTS" = "true" ]; then BEGIN_FOLD unit-tests; DOCKER_EXEC LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib make $MAKEJOBS check VERBOSE=1; END_FOLD; fi
- - if [ "$RUN_BENCH" = "true" ]; then BEGIN_FOLD bench; DOCKER_EXEC LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib $OUTDIR/bin/bench_bitcoin -scaling=0.001 ; END_FOLD; fi
- - if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then extended="--extended --exclude feature_pruning,feature_dbcrash"; fi
- - if [ "$RUN_TESTS" = "true" ]; then BEGIN_FOLD functional-tests; DOCKER_EXEC test/functional/test_runner.py --combinedlogslen=4000 --coverage --quiet --failfast ${extended}; END_FOLD; fi
+ - set -o errexit; source .travis/test_06_script.sh
after_script:
- - echo $TRAVIS_COMMIT_RANGE
- - echo $TRAVIS_COMMIT_LOG
+ - echo $TRAVIS_COMMIT_RANGE
+ - echo $TRAVIS_COMMIT_LOG
jobs:
include:
+# lint stage
+ - stage: lint
+ env:
+ sudo: false
+ cache: false
+ language: python
+ python: '3.6'
+ install:
+ - set -o errexit; source .travis/lint_04_install.sh
+ before_script:
+ - set -o errexit; source .travis/lint_05_before_script.sh
+ script:
+ - set -o errexit; source .travis/lint_06_script.sh
# ARM
- stage: test
env: >-
HOST=arm-linux-gnueabihf
PACKAGES="g++-arm-linux-gnueabihf"
DEP_OPTS="NO_QT=1"
+ RUN_UNIT_TESTS=false
+ RUN_FUNCTIONAL_TESTS=false
GOAL="install"
- BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
+ # -Wno-psabi is to disable ABI warnings: "note: parameter passing for argument of type ... changed in GCC 7.1"
+ # This could be removed once the ABI change warning does not show up by default
+ BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports CXXFLAGS=-Wno-psabi"
# Win32
- stage: test
env: >-
@@ -83,7 +72,6 @@ jobs:
DPKG_ADD_ARCH="i386"
DEP_OPTS="NO_QT=1"
PACKAGES="python3 nsis g++-mingw-w64-i686 wine-binfmt wine32"
- RUN_TESTS=true
GOAL="install"
BITCOIN_CONFIG="--enable-reduce-exports"
# Win64
@@ -92,7 +80,6 @@ jobs:
HOST=x86_64-w64-mingw32
DEP_OPTS="NO_QT=1"
PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64"
- RUN_TESTS=true
GOAL="install"
BITCOIN_CONFIG="--enable-reduce-exports"
# 32-bit + dash
@@ -101,7 +88,6 @@ jobs:
HOST=i686-pc-linux-gnu
PACKAGES="g++-multilib python3-zmq"
DEP_OPTS="NO_QT=1"
- RUN_TESTS=true
GOAL="install"
BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++"
CONFIG_SHELL="/bin/dash"
@@ -111,26 +97,32 @@ jobs:
HOST=x86_64-unknown-linux-gnu
PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev libprotobuf-dev"
DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1"
- RUN_TESTS=true
- RUN_BENCH=true
GOAL="install"
BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports --enable-debug CXXFLAGS=\"-g0 -O2\""
-# x86_64 Linux (Qt5 & system libs)
+# x86_64 Linux (no depends, only system libs)
- stage: test
env: >-
HOST=x86_64-unknown-linux-gnu
PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools libssl1.0-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev"
NO_DEPENDS=1
- RUN_TESTS=true
GOAL="install"
BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --enable-glibc-back-compat --enable-reduce-exports --with-gui=qt5 CPPFLAGS=-DDEBUG_LOCKORDER"
+# x86_64 Linux (sanitizers)
+ - stage: test
+ env: >-
+ HOST=x86_64-unknown-linux-gnu
+ PACKAGES="clang python3-zmq qtbase5-dev qttools5-dev-tools libssl1.0-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev"
+ NO_DEPENDS=1
+ RUN_BENCH=true
+ RUN_FUNCTIONAL_TESTS=false # Disabled for now, can be combined with the other x86_64 linux NO_DEPENDS job when functional tests pass the sanitizers
+ GOAL="install"
+ BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --enable-glibc-back-compat --enable-reduce-exports --with-gui=qt5 CPPFLAGS=-DDEBUG_LOCKORDER --with-sanitizers=undefined CC=clang CXX=clang++"
# x86_64 Linux, No wallet
- stage: test
env: >-
HOST=x86_64-unknown-linux-gnu
PACKAGES="python3"
DEP_OPTS="NO_WALLET=1"
- RUN_TESTS=true
GOAL="install"
BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
# Cross-Mac
@@ -139,28 +131,7 @@ jobs:
HOST=x86_64-apple-darwin14
PACKAGES="cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev python3-setuptools-git"
OSX_SDK=10.11
+ RUN_UNIT_TESTS=false
+ RUN_FUNCTIONAL_TESTS=false
GOAL="all deploy"
BITCOIN_CONFIG="--enable-gui --enable-reduce-exports --enable-werror"
- - stage: lint
- env:
- sudo: false
- cache: false
- language: python
- python: '3.6'
- install:
- - travis_retry pip install flake8
- before_script:
- - git fetch --unshallow
- script:
- - if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then test/lint/commit-script-check.sh $TRAVIS_COMMIT_RANGE; fi
- - test/lint/git-subtree-check.sh src/crypto/ctaes
- - test/lint/git-subtree-check.sh src/secp256k1
- - test/lint/git-subtree-check.sh src/univalue
- - test/lint/git-subtree-check.sh src/leveldb
- - test/lint/check-doc.py
- - test/lint/check-rpc-mappings.py .
- - test/lint/lint-all.sh
- - if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" -a "$TRAVIS_EVENT_TYPE" = "cron" ]; then
- while read LINE; do travis_retry gpg --keyserver hkp://subset.pool.sks-keyservers.net --recv-keys $LINE; done < contrib/verify-commits/trusted-keys &&
- travis_wait 50 contrib/verify-commits/verify-commits.py;
- fi
diff --git a/.travis/README.md b/.travis/README.md
new file mode 100644
index 0000000000..21d1b9cc03
--- /dev/null
+++ b/.travis/README.md
@@ -0,0 +1,8 @@
+## travis build scripts
+
+The `.travis` directory contains scripts for each build step in each build stage.
+Currently the travis build defines two stages `lint` and `test`. Each stage has
+it's own [lifecycle](https://docs.travis-ci.com/user/customizing-the-build/#the-build-lifecycle).
+Every script in here is named and numbered according to which stage and lifecycle
+step it belongs to.
+
diff --git a/.travis/lint_04_install.sh b/.travis/lint_04_install.sh
new file mode 100755
index 0000000000..34118a57c3
--- /dev/null
+++ b/.travis/lint_04_install.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+travis_retry pip install flake8
diff --git a/.travis/lint_05_before_script.sh b/.travis/lint_05_before_script.sh
new file mode 100755
index 0000000000..28bcbb47f7
--- /dev/null
+++ b/.travis/lint_05_before_script.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+git fetch --unshallow
diff --git a/.travis/lint_06_script.sh b/.travis/lint_06_script.sh
new file mode 100755
index 0000000000..6191d82571
--- /dev/null
+++ b/.travis/lint_06_script.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
+ test/lint/commit-script-check.sh $TRAVIS_COMMIT_RANGE
+fi
+
+test/lint/git-subtree-check.sh src/crypto/ctaes
+test/lint/git-subtree-check.sh src/secp256k1
+test/lint/git-subtree-check.sh src/univalue
+test/lint/git-subtree-check.sh src/leveldb
+test/lint/check-doc.py
+test/lint/check-rpc-mappings.py .
+test/lint/lint-all.sh
+
+if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" -a "$TRAVIS_EVENT_TYPE" = "cron" ]; then
+ while read -r LINE; do travis_retry gpg --keyserver hkp://subset.pool.sks-keyservers.net --recv-keys $LINE; done < contrib/verify-commits/trusted-keys &&
+ travis_wait 50 contrib/verify-commits/verify-commits.py;
+fi
diff --git a/.travis/test_03_before_install.sh b/.travis/test_03_before_install.sh
new file mode 100755
index 0000000000..d091a67ca9
--- /dev/null
+++ b/.travis/test_03_before_install.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")
+export PATH
+
+BEGIN_FOLD () {
+ echo ""
+ CURRENT_FOLD_NAME=$1
+ echo "travis_fold:start:${CURRENT_FOLD_NAME}"
+}
+
+END_FOLD () {
+ RET=$?
+ echo "travis_fold:end:${CURRENT_FOLD_NAME}"
+ if [ $RET != 0 ]; then
+ echo "${CURRENT_FOLD_NAME} failed with status code ${RET}"
+ fi
+}
+
diff --git a/.travis/test_04_install.sh b/.travis/test_04_install.sh
new file mode 100755
index 0000000000..ef595287b7
--- /dev/null
+++ b/.travis/test_04_install.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+travis_retry docker pull "$DOCKER_NAME_TAG"
+env | grep -E '^(CCACHE_|WINEDEBUG|LC_ALL|BOOST_TEST_RANDOM|CONFIG_SHELL)' | tee /tmp/env
+if [[ $HOST = *-mingw32 ]]; then
+ DOCKER_ADMIN="--cap-add SYS_ADMIN"
+fi
+DOCKER_ID=$(docker run $DOCKER_ADMIN -idt --mount type=bind,src=$TRAVIS_BUILD_DIR,dst=$TRAVIS_BUILD_DIR --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR -w $TRAVIS_BUILD_DIR --env-file /tmp/env $DOCKER_NAME_TAG)
+
+DOCKER_EXEC () {
+ docker exec $DOCKER_ID bash -c "cd $PWD && $*"
+}
+
+if [ -n "$DPKG_ADD_ARCH" ]; then
+ DOCKER_EXEC dpkg --add-architecture "$DPKG_ADD_ARCH"
+fi
+
+travis_retry DOCKER_EXEC apt-get update
+travis_retry DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES $DOCKER_PACKAGES
+
diff --git a/.travis/test_05_before_script.sh b/.travis/test_05_before_script.sh
new file mode 100755
index 0000000000..70caee979c
--- /dev/null
+++ b/.travis/test_05_before_script.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+DOCKER_EXEC echo \> \$HOME/.bitcoin # Make sure default datadir does not exist and is never read by creating a dummy file
+
+mkdir -p depends/SDKs depends/sdk-sources
+
+if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
+ curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
+fi
+if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
+ tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
+fi
+if [[ $HOST = *-mingw32 ]]; then
+ DOCKER_EXEC update-alternatives --set $HOST-g++ \$\(which $HOST-g++-posix\)
+fi
+if [ -z "$NO_DEPENDS" ]; then
+ DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
+fi
+
diff --git a/.travis/test_06_script.sh b/.travis/test_06_script.sh
new file mode 100755
index 0000000000..e5fea81187
--- /dev/null
+++ b/.travis/test_06_script.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+TRAVIS_COMMIT_LOG=$(git log --format=fuller -1)
+export TRAVIS_COMMIT_LOG
+
+OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST
+BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib"
+if [ -z "$NO_DEPENDS" ]; then
+ DOCKER_EXEC ccache --max-size=$CCACHE_SIZE
+fi
+
+BEGIN_FOLD autogen
+if [ -n "$CONFIG_SHELL" ]; then
+ DOCKER_EXEC "$CONFIG_SHELL" -c "./autogen.sh"
+else
+ DOCKER_EXEC ./autogen.sh
+fi
+END_FOLD
+
+mkdir build
+cd build || (echo "could not enter build directory"; exit 1)
+
+BEGIN_FOLD configure
+DOCKER_EXEC ../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
+END_FOLD
+
+BEGIN_FOLD distdir
+DOCKER_EXEC make distdir VERSION=$HOST
+END_FOLD
+
+cd "bitcoin-$HOST" || (echo "could not enter distdir bitcoin-$HOST"; exit 1)
+
+BEGIN_FOLD configure
+DOCKER_EXEC ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
+END_FOLD
+
+BEGIN_FOLD build
+DOCKER_EXEC make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && DOCKER_EXEC make $GOAL V=1 ; false )
+END_FOLD
+
+if [ "$RUN_UNIT_TESTS" = "true" ]; then
+ BEGIN_FOLD unit-tests
+ DOCKER_EXEC LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib make $MAKEJOBS check VERBOSE=1
+ END_FOLD
+fi
+
+if [ "$RUN_BENCH" = "true" ]; then
+ BEGIN_FOLD bench
+ DOCKER_EXEC LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib $OUTDIR/bin/bench_bitcoin -scaling=0.001
+ END_FOLD
+fi
+
+if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
+ extended="--extended --exclude feature_pruning,feature_dbcrash"
+fi
+
+if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
+ BEGIN_FOLD functional-tests
+ DOCKER_EXEC test/functional/test_runner.py --combinedlogslen=4000 --coverage --quiet --failfast ${extended}
+ END_FOLD
+fi
diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py
index 6808e77da7..c6158c9422 100755
--- a/contrib/devtools/symbol-check.py
+++ b/contrib/devtools/symbol-check.py
@@ -36,17 +36,18 @@ import os
# (glibc) GLIBC_2_11
#
MAX_VERSIONS = {
-'GCC': (4,4,0),
-'CXXABI': (1,3,3),
-'GLIBCXX': (3,4,13),
-'GLIBC': (2,11)
+'GCC': (4,4,0),
+'CXXABI': (1,3,3),
+'GLIBCXX': (3,4,13),
+'GLIBC': (2,11),
+'LIBATOMIC': (1,0)
}
# See here for a description of _IO_stdin_used:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634261#109
# Ignore symbols that are exported as part of every executable
IGNORE_EXPORTS = {
-'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used', 'stdin', 'stdout', 'stderr'
+'_edata', '_end', '__end__', '_init', '__bss_start', '__bss_start__', '_bss_end__', '__bss_end__', '_fini', '_IO_stdin_used', 'stdin', 'stdout', 'stderr'
}
READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
@@ -59,8 +60,12 @@ ALLOWED_LIBRARIES = {
'libanl.so.1', # DNS resolve
'libm.so.6', # math library
'librt.so.1', # real-time (clock)
+'libatomic.so.1',
'ld-linux-x86-64.so.2', # 64-bit dynamic linker
'ld-linux.so.2', # 32-bit dynamic linker
+'ld-linux-aarch64.so.1', # 64-bit ARM dynamic linker
+'ld-linux-armhf.so.3', # 32-bit ARM dynamic linker
+'ld-linux-riscv64-lp64d.so.1', # 64-bit RISC-V dynamic linker
# bitcoin-qt only
'libX11-xcb.so.1', # part of X11
'libX11.so.6', # part of X11
@@ -69,7 +74,13 @@ ALLOWED_LIBRARIES = {
'libfreetype.so.6', # font parsing
'libdl.so.2' # programming interface to dynamic linker
}
-
+ARCH_MIN_GLIBC_VER = {
+'80386': (2,1),
+'X86-64': (2,2,5),
+'ARM': (2,4),
+'AArch64':(2,17),
+'RISC-V': (2,27)
+}
class CPPFilt(object):
'''
Demangle C++ symbol names.
@@ -94,23 +105,25 @@ def read_symbols(executable, imports=True):
Parse an ELF executable and return a list of (symbol,version) tuples
for dynamic, imported symbols.
'''
- p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', '-h', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
(stdout, stderr) = p.communicate()
if p.returncode:
raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
syms = []
for line in stdout.splitlines():
line = line.split()
+ if 'Machine:' in line:
+ arch = line[-1]
if len(line)>7 and re.match('[0-9]+:$', line[0]):
(sym, _, version) = line[7].partition('@')
is_import = line[6] == 'UND'
if version.startswith('@'):
version = version[1:]
if is_import == imports:
- syms.append((sym, version))
+ syms.append((sym, version, arch))
return syms
-def check_version(max_versions, version):
+def check_version(max_versions, version, arch):
if '_' in version:
(lib, _, ver) = version.rpartition('_')
else:
@@ -119,7 +132,7 @@ def check_version(max_versions, version):
ver = tuple([int(x) for x in ver.split('.')])
if not lib in max_versions:
return False
- return ver <= max_versions[lib]
+ return ver <= max_versions[lib] or lib == 'GLIBC' and ver <= ARCH_MIN_GLIBC_VER[arch]
def read_libraries(filename):
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
@@ -142,16 +155,17 @@ if __name__ == '__main__':
retval = 0
for filename in sys.argv[1:]:
# Check imported symbols
- for sym,version in read_symbols(filename, True):
- if version and not check_version(MAX_VERSIONS, version):
+ for sym,version,arch in read_symbols(filename, True):
+ if version and not check_version(MAX_VERSIONS, version, arch):
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
retval = 1
# Check exported symbols
- for sym,version in read_symbols(filename, False):
- if sym in IGNORE_EXPORTS:
- continue
- print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
- retval = 1
+ if arch != 'RISC-V':
+ for sym,version,arch in read_symbols(filename, False):
+ if sym in IGNORE_EXPORTS:
+ continue
+ print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
+ retval = 1
# Check dependency libraries
for library_name in read_libraries(filename):
if library_name not in ALLOWED_LIBRARIES:
diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml
index c7933cff20..e97072c80a 100644
--- a/contrib/gitian-descriptors/gitian-linux.yml
+++ b/contrib/gitian-descriptors/gitian-linux.yml
@@ -173,18 +173,7 @@ script: |
CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-ccache --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS} CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}" LDFLAGS="${HOST_LDFLAGS}"
make ${MAKEOPTS}
make ${MAKEOPTS} -C src check-security
-
- #TODO: This is a quick hack that disables symbol checking for arm.
- # Instead, we should investigate why these are popping up.
- # For aarch64, we'll need to bump up the min GLIBC version, as the abi
- # support wasn't introduced until 2.17.
- case $i in
- aarch64-*) : ;;
- arm-*) : ;;
- riscv64-*) : ;;
- *) make ${MAKEOPTS} -C src check-symbols ;;
- esac
-
+ make ${MAKEOPTS} -C src check-symbols
make install DESTDIR=${INSTALLPATH}
cd installed
find . -name "lib*.la" -delete
@@ -192,6 +181,7 @@ script: |
rm -rf ${DISTNAME}/lib/pkgconfig
find ${DISTNAME}/bin -type f -executable -exec ../contrib/devtools/split-debug.sh {} {} {}.dbg \;
find ${DISTNAME}/lib -type f -exec ../contrib/devtools/split-debug.sh {} {} {}.dbg \;
+ cp ../doc/README.md ${DISTNAME}/
find ${DISTNAME} -not -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz
find ${DISTNAME} -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}-debug.tar.gz
cd ../../
diff --git a/contrib/testgen/README.md b/contrib/testgen/README.md
index 83624f443a..580ed541cf 100644
--- a/contrib/testgen/README.md
+++ b/contrib/testgen/README.md
@@ -4,5 +4,5 @@ Utilities to generate test vectors for the data-driven Bitcoin tests.
Usage:
- gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json
- gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json \ No newline at end of file
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py valid 50 > ../../src/test/data/key_io_keys_valid.json
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py invalid 50 > ../../src/test/data/key_io_keys_invalid.json
diff --git a/contrib/testgen/gen_base58_test_vectors.py b/contrib/testgen/gen_base58_test_vectors.py
deleted file mode 100755
index c76de5ce75..0000000000
--- a/contrib/testgen/gen_base58_test_vectors.py
+++ /dev/null
@@ -1,132 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (c) 2012-2018 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-'''
-Generate valid and invalid base58 address and private key test vectors.
-
-Usage:
- gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json
- gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json
-'''
-# 2012 Wladimir J. van der Laan
-# Released under MIT License
-import os
-from itertools import islice
-from base58 import b58encode_chk, b58decode_chk, b58chars
-import random
-from binascii import b2a_hex
-
-# key types
-PUBKEY_ADDRESS = 0
-SCRIPT_ADDRESS = 5
-PUBKEY_ADDRESS_TEST = 111
-SCRIPT_ADDRESS_TEST = 196
-PRIVKEY = 128
-PRIVKEY_TEST = 239
-
-metadata_keys = ['isPrivkey', 'isTestnet', 'addrType', 'isCompressed']
-# templates for valid sequences
-templates = [
- # prefix, payload_size, suffix, metadata
- # None = N/A
- ((PUBKEY_ADDRESS,), 20, (), (False, False, 'pubkey', None)),
- ((SCRIPT_ADDRESS,), 20, (), (False, False, 'script', None)),
- ((PUBKEY_ADDRESS_TEST,), 20, (), (False, True, 'pubkey', None)),
- ((SCRIPT_ADDRESS_TEST,), 20, (), (False, True, 'script', None)),
- ((PRIVKEY,), 32, (), (True, False, None, False)),
- ((PRIVKEY,), 32, (1,), (True, False, None, True)),
- ((PRIVKEY_TEST,), 32, (), (True, True, None, False)),
- ((PRIVKEY_TEST,), 32, (1,), (True, True, None, True))
-]
-
-def is_valid(v):
- '''Check vector v for validity'''
- result = b58decode_chk(v)
- if result is None:
- return False
- for template in templates:
- prefix = bytearray(template[0])
- suffix = bytearray(template[2])
- if result.startswith(prefix) and result.endswith(suffix):
- if (len(result) - len(prefix) - len(suffix)) == template[1]:
- return True
- return False
-
-def gen_valid_vectors():
- '''Generate valid test vectors'''
- while True:
- for template in templates:
- prefix = bytearray(template[0])
- payload = bytearray(os.urandom(template[1]))
- suffix = bytearray(template[2])
- rv = b58encode_chk(prefix + payload + suffix)
- assert is_valid(rv)
- metadata = {x: y for x, y in zip(metadata_keys,template[3]) if y is not None}
- hexrepr = b2a_hex(payload)
- if isinstance(hexrepr, bytes):
- hexrepr = hexrepr.decode('utf8')
- yield (rv, hexrepr, metadata)
-
-def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt_suffix):
- '''Generate possibly invalid vector'''
- if corrupt_prefix:
- prefix = os.urandom(1)
- else:
- prefix = bytearray(template[0])
-
- if randomize_payload_size:
- payload = os.urandom(max(int(random.expovariate(0.5)), 50))
- else:
- payload = os.urandom(template[1])
-
- if corrupt_suffix:
- suffix = os.urandom(len(template[2]))
- else:
- suffix = bytearray(template[2])
-
- return b58encode_chk(prefix + payload + suffix)
-
-def randbool(p = 0.5):
- '''Return True with P(p)'''
- return random.random() < p
-
-def gen_invalid_vectors():
- '''Generate invalid test vectors'''
- # start with some manual edge-cases
- yield "",
- yield "x",
- while True:
- # kinds of invalid vectors:
- # invalid prefix
- # invalid payload length
- # invalid (randomized) suffix (add random data)
- # corrupt checksum
- for template in templates:
- val = gen_invalid_vector(template, randbool(0.2), randbool(0.2), randbool(0.2))
- if random.randint(0,10)<1: # line corruption
- if randbool(): # add random character to end
- val += random.choice(b58chars)
- else: # replace random character in the middle
- n = random.randint(0, len(val))
- val = val[0:n] + random.choice(b58chars) + val[n+1:]
- if not is_valid(val):
- yield val,
-
-if __name__ == '__main__':
- import sys
- import json
- iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
- try:
- uiter = iters[sys.argv[1]]
- except IndexError:
- uiter = gen_valid_vectors
- try:
- count = int(sys.argv[2])
- except IndexError:
- count = 0
-
- data = list(islice(uiter(), count))
- json.dump(data, sys.stdout, sort_keys=True, indent=4)
- sys.stdout.write('\n')
-
diff --git a/contrib/testgen/gen_key_io_test_vectors.py b/contrib/testgen/gen_key_io_test_vectors.py
new file mode 100755
index 0000000000..a00acb1f41
--- /dev/null
+++ b/contrib/testgen/gen_key_io_test_vectors.py
@@ -0,0 +1,249 @@
+#!/usr/bin/env python3
+# Copyright (c) 2012-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Generate valid and invalid base58 address and private key test vectors.
+
+Usage:
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py valid 50 > ../../src/test/data/key_io_valid.json
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py invalid 50 > ../../src/test/data/key_io_invalid.json
+'''
+# 2012 Wladimir J. van der Laan
+# Released under MIT License
+import os
+from itertools import islice
+from base58 import b58encode_chk, b58decode_chk, b58chars
+import random
+from binascii import b2a_hex
+from segwit_addr import bech32_encode, decode, convertbits, CHARSET
+
+# key types
+PUBKEY_ADDRESS = 0
+SCRIPT_ADDRESS = 5
+PUBKEY_ADDRESS_TEST = 111
+SCRIPT_ADDRESS_TEST = 196
+PUBKEY_ADDRESS_REGTEST = 111
+SCRIPT_ADDRESS_REGTEST = 196
+PRIVKEY = 128
+PRIVKEY_TEST = 239
+PRIVKEY_REGTEST = 239
+
+# script
+OP_0 = 0x00
+OP_1 = 0x51
+OP_2 = 0x52
+OP_16 = 0x60
+OP_DUP = 0x76
+OP_EQUAL = 0x87
+OP_EQUALVERIFY = 0x88
+OP_HASH160 = 0xa9
+OP_CHECKSIG = 0xac
+pubkey_prefix = (OP_DUP, OP_HASH160, 20)
+pubkey_suffix = (OP_EQUALVERIFY, OP_CHECKSIG)
+script_prefix = (OP_HASH160, 20)
+script_suffix = (OP_EQUAL,)
+p2wpkh_prefix = (OP_0, 20)
+p2wsh_prefix = (OP_0, 32)
+
+metadata_keys = ['isPrivkey', 'chain', 'isCompressed', 'tryCaseFlip']
+# templates for valid sequences
+templates = [
+ # prefix, payload_size, suffix, metadata, output_prefix, output_suffix
+ # None = N/A
+ ((PUBKEY_ADDRESS,), 20, (), (False, 'main', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS,), 20, (), (False, 'main', None, None), script_prefix, script_suffix),
+ ((PUBKEY_ADDRESS_TEST,), 20, (), (False, 'test', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS_TEST,), 20, (), (False, 'test', None, None), script_prefix, script_suffix),
+ ((PUBKEY_ADDRESS_REGTEST,), 20, (), (False, 'regtest', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS_REGTEST,), 20, (), (False, 'regtest', None, None), script_prefix, script_suffix),
+ ((PRIVKEY,), 32, (), (True, 'main', False, None), (), ()),
+ ((PRIVKEY,), 32, (1,), (True, 'main', True, None), (), ()),
+ ((PRIVKEY_TEST,), 32, (), (True, 'test', False, None), (), ()),
+ ((PRIVKEY_TEST,), 32, (1,), (True, 'test', True, None), (), ()),
+ ((PRIVKEY_REGTEST,), 32, (), (True, 'regtest', False, None), (), ()),
+ ((PRIVKEY_REGTEST,), 32, (1,), (True, 'regtest', True, None), (), ())
+]
+# templates for valid bech32 sequences
+bech32_templates = [
+ # hrp, version, witprog_size, metadata, output_prefix
+ ('bc', 0, 20, (False, 'main', None, True), p2wpkh_prefix),
+ ('bc', 0, 32, (False, 'main', None, True), p2wsh_prefix),
+ ('bc', 1, 2, (False, 'main', None, True), (OP_1, 2)),
+ ('tb', 0, 20, (False, 'test', None, True), p2wpkh_prefix),
+ ('tb', 0, 32, (False, 'test', None, True), p2wsh_prefix),
+ ('tb', 2, 16, (False, 'test', None, True), (OP_2, 16)),
+ ('bcrt', 0, 20, (False, 'regtest', None, True), p2wpkh_prefix),
+ ('bcrt', 0, 32, (False, 'regtest', None, True), p2wsh_prefix),
+ ('bcrt', 16, 40, (False, 'regtest', None, True), (OP_16, 40))
+]
+# templates for invalid bech32 sequences
+bech32_ng_templates = [
+ # hrp, version, witprog_size, invalid_bech32, invalid_checksum, invalid_char
+ ('tc', 0, 20, False, False, False),
+ ('tb', 17, 32, False, False, False),
+ ('bcrt', 3, 1, False, False, False),
+ ('bc', 15, 41, False, False, False),
+ ('tb', 0, 16, False, False, False),
+ ('bcrt', 0, 32, True, False, False),
+ ('bc', 0, 16, True, False, False),
+ ('tb', 0, 32, False, True, False),
+ ('bcrt', 0, 20, False, False, True)
+]
+
+def is_valid(v):
+ '''Check vector v for validity'''
+ if len(set(v) - set(b58chars)) > 0:
+ return is_valid_bech32(v)
+ result = b58decode_chk(v)
+ if result is None:
+ return is_valid_bech32(v)
+ for template in templates:
+ prefix = bytearray(template[0])
+ suffix = bytearray(template[2])
+ if result.startswith(prefix) and result.endswith(suffix):
+ if (len(result) - len(prefix) - len(suffix)) == template[1]:
+ return True
+ return is_valid_bech32(v)
+
+def is_valid_bech32(v):
+ '''Check vector v for bech32 validity'''
+ for hrp in ['bc', 'tb', 'bcrt']:
+ if decode(hrp, v) != (None, None):
+ return True
+ return False
+
+def gen_valid_base58_vector(template):
+ '''Generate valid base58 vector'''
+ prefix = bytearray(template[0])
+ payload = bytearray(os.urandom(template[1]))
+ suffix = bytearray(template[2])
+ dst_prefix = bytearray(template[4])
+ dst_suffix = bytearray(template[5])
+ rv = b58encode_chk(prefix + payload + suffix)
+ return rv, dst_prefix + payload + dst_suffix
+
+def gen_valid_bech32_vector(template):
+ '''Generate valid bech32 vector'''
+ hrp = template[0]
+ witver = template[1]
+ witprog = bytearray(os.urandom(template[2]))
+ dst_prefix = bytearray(template[4])
+ rv = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5))
+ return rv, dst_prefix + witprog
+
+def gen_valid_vectors():
+ '''Generate valid test vectors'''
+ glist = [gen_valid_base58_vector, gen_valid_bech32_vector]
+ tlist = [templates, bech32_templates]
+ while True:
+ for template, valid_vector_generator in [(t, g) for g, l in zip(glist, tlist) for t in l]:
+ rv, payload = valid_vector_generator(template)
+ assert is_valid(rv)
+ metadata = {x: y for x, y in zip(metadata_keys,template[3]) if y is not None}
+ hexrepr = b2a_hex(payload)
+ if isinstance(hexrepr, bytes):
+ hexrepr = hexrepr.decode('utf8')
+ yield (rv, hexrepr, metadata)
+
+def gen_invalid_base58_vector(template):
+ '''Generate possibly invalid vector'''
+ # kinds of invalid vectors:
+ # invalid prefix
+ # invalid payload length
+ # invalid (randomized) suffix (add random data)
+ # corrupt checksum
+ corrupt_prefix = randbool(0.2)
+ randomize_payload_size = randbool(0.2)
+ corrupt_suffix = randbool(0.2)
+
+ if corrupt_prefix:
+ prefix = os.urandom(1)
+ else:
+ prefix = bytearray(template[0])
+
+ if randomize_payload_size:
+ payload = os.urandom(max(int(random.expovariate(0.5)), 50))
+ else:
+ payload = os.urandom(template[1])
+
+ if corrupt_suffix:
+ suffix = os.urandom(len(template[2]))
+ else:
+ suffix = bytearray(template[2])
+
+ val = b58encode_chk(prefix + payload + suffix)
+ if random.randint(0,10)<1: # line corruption
+ if randbool(): # add random character to end
+ val += random.choice(b58chars)
+ else: # replace random character in the middle
+ n = random.randint(0, len(val))
+ val = val[0:n] + random.choice(b58chars) + val[n+1:]
+
+ return val
+
+def gen_invalid_bech32_vector(template):
+ '''Generate possibly invalid bech32 vector'''
+ no_data = randbool(0.1)
+ to_upper = randbool(0.1)
+ hrp = template[0]
+ witver = template[1]
+ witprog = bytearray(os.urandom(template[2]))
+
+ if no_data:
+ rv = bech32_encode(hrp, [])
+ else:
+ data = [witver] + convertbits(witprog, 8, 5)
+ if template[3] and not no_data:
+ if template[2] % 5 in {2, 4}:
+ data[-1] |= 1
+ else:
+ data.append(0)
+ rv = bech32_encode(hrp, data)
+
+ if template[4]:
+ i = len(rv) - random.randrange(1, 7)
+ rv = rv[:i] + random.choice(CHARSET.replace(rv[i], '')) + rv[i + 1:]
+ if template[5]:
+ i = len(hrp) + 1 + random.randrange(0, len(rv) - len(hrp) - 4)
+ rv = rv[:i] + rv[i:i + 4].upper() + rv[i + 4:]
+
+ if to_upper:
+ rv = rv.swapcase()
+
+ return rv
+
+def randbool(p = 0.5):
+ '''Return True with P(p)'''
+ return random.random() < p
+
+def gen_invalid_vectors():
+ '''Generate invalid test vectors'''
+ # start with some manual edge-cases
+ yield "",
+ yield "x",
+ glist = [gen_invalid_base58_vector, gen_invalid_bech32_vector]
+ tlist = [templates, bech32_ng_templates]
+ while True:
+ for template, invalid_vector_generator in [(t, g) for g, l in zip(glist, tlist) for t in l]:
+ val = invalid_vector_generator(template)
+ if not is_valid(val):
+ yield val,
+
+if __name__ == '__main__':
+ import sys
+ import json
+ iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
+ try:
+ uiter = iters[sys.argv[1]]
+ except IndexError:
+ uiter = gen_valid_vectors
+ try:
+ count = int(sys.argv[2])
+ except IndexError:
+ count = 0
+
+ data = list(islice(uiter(), count))
+ json.dump(data, sys.stdout, sort_keys=True, indent=4)
+ sys.stdout.write('\n')
+
diff --git a/depends/config.site.in b/depends/config.site.in
index 8444dc26f2..b7a5e795c8 100644
--- a/depends/config.site.in
+++ b/depends/config.site.in
@@ -61,9 +61,12 @@ fi
CPPFLAGS="-I$depends_prefix/include/ $CPPFLAGS"
LDFLAGS="-L$depends_prefix/lib $LDFLAGS"
-CC="@CC@"
-CXX="@CXX@"
-OBJC="${CC}"
+if test -n "@CC@" -a -z "${CC}"; then
+ CC="@CC@"
+fi
+if test -n "@CXX@" -a -z "${CXX}"; then
+ CXX="@CXX@"
+fi
PYTHONPATH=$depends_prefix/native/lib/python/dist-packages:$PYTHONPATH
if test -n "@AR@"; then
diff --git a/doc/release-notes-14023.md b/doc/release-notes-14023.md
new file mode 100644
index 0000000000..18ea6f26d0
--- /dev/null
+++ b/doc/release-notes-14023.md
@@ -0,0 +1,8 @@
+Account API removed
+-------------------
+
+The 'account' API was deprecated in v0.17 and has been fully removed in v0.18.
+The 'label' API was introduced in v0.17 as a replacement for accounts.
+
+See the release notes from v0.17 for a full description of the changes from the
+'account' API to the 'label' API.
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 9e7d0dc745..abfd66efad 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -96,7 +96,6 @@ BITCOIN_TESTS =\
if ENABLE_WALLET
BITCOIN_TESTS += \
- wallet/test/accounting_tests.cpp \
wallet/test/psbt_wallet_tests.cpp \
wallet/test/wallet_tests.cpp \
wallet/test/wallet_crypto_tests.cpp \
diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp
index bab22f5984..5b0cf27e04 100644
--- a/src/bench/crypto_hash.cpp
+++ b/src/bench/crypto_hash.cpp
@@ -80,18 +80,16 @@ static void SipHash_32b(benchmark::State& state)
static void FastRandom_32bit(benchmark::State& state)
{
FastRandomContext rng(true);
- uint32_t x = 0;
while (state.KeepRunning()) {
- x += rng.rand32();
+ rng.rand32();
}
}
static void FastRandom_1bit(benchmark::State& state)
{
FastRandomContext rng(true);
- uint32_t x = 0;
while (state.KeepRunning()) {
- x += rng.randbool();
+ rng.randbool();
}
}
diff --git a/src/bench/mempool_eviction.cpp b/src/bench/mempool_eviction.cpp
index 0ec7c158cc..3908a7d231 100644
--- a/src/bench/mempool_eviction.cpp
+++ b/src/bench/mempool_eviction.cpp
@@ -16,7 +16,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
bool spendsCoinbase = false;
unsigned int sigOpCost = 4;
LockPoints lp;
- pool.addUnchecked(tx->GetHash(), CTxMemPoolEntry(
+ pool.addUnchecked(CTxMemPoolEntry(
tx, nFee, nTime, nHeight,
spendsCoinbase, sigOpCost, lp));
}
diff --git a/src/bench/rollingbloom.cpp b/src/bench/rollingbloom.cpp
index 43e7635047..0a99ea3184 100644
--- a/src/bench/rollingbloom.cpp
+++ b/src/bench/rollingbloom.cpp
@@ -12,7 +12,6 @@ static void RollingBloom(benchmark::State& state)
CRollingBloomFilter filter(120000, 0.000001);
std::vector<unsigned char> data(32);
uint32_t count = 0;
- uint64_t match = 0;
while (state.KeepRunning()) {
count++;
data[0] = count;
@@ -25,7 +24,7 @@ static void RollingBloom(benchmark::State& state)
data[1] = count >> 16;
data[2] = count >> 8;
data[3] = count;
- match += filter.contains(data);
+ filter.contains(data);
}
}
diff --git a/src/compat.h b/src/compat.h
index 19f9813fd4..d228611160 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -14,10 +14,10 @@
// GCC 4.8 is missing some C++11 type_traits,
// https://www.gnu.org/software/gcc/gcc-5/changes.html
-#if defined(__GNUC__) && __GNUC__ < 5
-#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivial
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
+#define IS_TRIVIALLY_CONSTRUCTIBLE std::has_trivial_default_constructor
#else
-#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_constructible
+#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_default_constructible
#endif
#ifdef WIN32
diff --git a/src/fs.cpp b/src/fs.cpp
index 570ed3e2ee..2dbc13643b 100644
--- a/src/fs.cpp
+++ b/src/fs.cpp
@@ -1,5 +1,12 @@
#include <fs.h>
+#ifndef WIN32
+#include <fcntl.h>
+#else
+#include <codecvt>
+#include <windows.h>
+#endif
+
namespace fsbridge {
FILE *fopen(const fs::path& p, const char *mode)
@@ -7,9 +14,82 @@ FILE *fopen(const fs::path& p, const char *mode)
return ::fopen(p.string().c_str(), mode);
}
-FILE *freopen(const fs::path& p, const char *mode, FILE *stream)
+#ifndef WIN32
+
+static std::string GetErrorReason() {
+ return std::strerror(errno);
+}
+
+FileLock::FileLock(const fs::path& file)
+{
+ fd = open(file.string().c_str(), O_RDWR);
+ if (fd == -1) {
+ reason = GetErrorReason();
+ }
+}
+
+FileLock::~FileLock()
+{
+ if (fd != -1) {
+ close(fd);
+ }
+}
+
+bool FileLock::TryLock()
+{
+ if (fd == -1) {
+ return false;
+ }
+ struct flock lock;
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 0;
+ if (fcntl(fd, F_SETLK, &lock) == -1) {
+ reason = GetErrorReason();
+ return false;
+ }
+ return true;
+}
+#else
+
+static std::string GetErrorReason() {
+ wchar_t* err;
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<WCHAR*>(&err), 0, nullptr);
+ std::wstring err_str(err);
+ LocalFree(err);
+ return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(err_str);
+}
+
+FileLock::FileLock(const fs::path& file)
+{
+ hFile = CreateFileW(file.wstring().c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ reason = GetErrorReason();
+ }
+}
+
+FileLock::~FileLock()
+{
+ if (hFile != INVALID_HANDLE_VALUE) {
+ CloseHandle(hFile);
+ }
+}
+
+bool FileLock::TryLock()
{
- return ::freopen(p.string().c_str(), mode, stream);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+ _OVERLAPPED overlapped = {0};
+ if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 0, &overlapped)) {
+ reason = GetErrorReason();
+ return false;
+ }
+ return true;
}
+#endif
} // fsbridge
diff --git a/src/fs.h b/src/fs.h
index abb4be254b..5a28d9a81c 100644
--- a/src/fs.h
+++ b/src/fs.h
@@ -18,7 +18,26 @@ namespace fs = boost::filesystem;
/** Bridge operations to C stdio */
namespace fsbridge {
FILE *fopen(const fs::path& p, const char *mode);
- FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
+
+ class FileLock
+ {
+ public:
+ FileLock() = delete;
+ FileLock(const FileLock&) = delete;
+ FileLock(FileLock&&) = delete;
+ explicit FileLock(const fs::path& file);
+ ~FileLock();
+ bool TryLock();
+ std::string GetReason() { return reason; }
+
+ private:
+ std::string reason;
+#ifndef WIN32
+ int fd = -1;
+#else
+ void* hFile = (void*)-1; // INVALID_HANDLE_VALUE
+#endif
+ };
};
#endif // BITCOIN_FS_H
diff --git a/src/init.cpp b/src/init.cpp
index 2131a6adc0..bd330459f6 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -51,13 +51,13 @@
#ifndef WIN32
#include <signal.h>
+#include <sys/stat.h>
#endif
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/bind.hpp>
-#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
diff --git a/src/interfaces/handler.cpp b/src/interfaces/handler.cpp
index 80f461f4d3..ddf9b342d8 100644
--- a/src/interfaces/handler.cpp
+++ b/src/interfaces/handler.cpp
@@ -15,7 +15,7 @@ namespace {
class HandlerImpl : public Handler
{
public:
- HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
+ explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
void disconnect() override { m_connection.disconnect(); }
diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp
index 703c0811ac..566ae37509 100644
--- a/src/interfaces/wallet.cpp
+++ b/src/interfaces/wallet.cpp
@@ -31,7 +31,7 @@ namespace {
class PendingWalletTxImpl : public PendingWalletTx
{
public:
- PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_key(&wallet) {}
+ explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_key(&wallet) {}
const CTransaction& get() override { return *m_tx; }
@@ -39,12 +39,11 @@ public:
bool commit(WalletValueMap value_map,
WalletOrderForm order_form,
- std::string from_account,
std::string& reject_reason) override
{
LOCK2(cs_main, m_wallet.cs_wallet);
CValidationState state;
- if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), std::move(from_account), m_key, g_connman.get(), state)) {
+ if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, g_connman.get(), state)) {
reject_reason = state.GetRejectReason();
return false;
}
@@ -117,7 +116,7 @@ static WalletTxOut MakeWalletTxOut(CWallet& wallet, const CWalletTx& wtx, int n,
class WalletImpl : public Wallet
{
public:
- WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_shared_wallet(wallet), m_wallet(*wallet.get()) {}
+ explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_shared_wallet(wallet), m_wallet(*wallet.get()) {}
bool encryptWallet(const SecureString& wallet_passphrase) override
{
diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h
index ae54d42442..44240a5726 100644
--- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -289,7 +289,6 @@ public:
//! Send pending transaction and commit to wallet.
virtual bool commit(WalletValueMap value_map,
WalletOrderForm order_form,
- std::string from_account,
std::string& reject_reason) = 0;
};
diff --git a/src/key_io.cpp b/src/key_io.cpp
index 5c5e2dc031..c6a541cdb1 100644
--- a/src/key_io.cpp
+++ b/src/key_io.cpp
@@ -24,7 +24,7 @@ private:
const CChainParams& m_params;
public:
- DestinationEncoder(const CChainParams& params) : m_params(params) {}
+ explicit DestinationEncoder(const CChainParams& params) : m_params(params) {}
std::string operator()(const CKeyID& id) const
{
diff --git a/src/logging.cpp b/src/logging.cpp
index 6557dddffb..0ae4f8121e 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -219,13 +219,13 @@ void BCLog::Logger::LogPrintStr(const std::string &str)
// reopen the log file, if requested
if (m_reopen_file) {
m_reopen_file = false;
- m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
- if (!m_fileout) {
- return;
+ FILE* new_fileout = fsbridge::fopen(m_file_path, "a");
+ if (new_fileout) {
+ setbuf(new_fileout, nullptr); // unbuffered
+ fclose(m_fileout);
+ m_fileout = new_fileout;
}
- setbuf(m_fileout, nullptr); // unbuffered
}
-
FileWriteStr(strTimestamped, m_fileout);
}
}
diff --git a/src/net.cpp b/src/net.cpp
index ec4fa6c267..df2cb54b7a 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -715,6 +715,7 @@ void CNode::copyStats(CNodeStats &stats)
X(nRecvBytes);
}
X(fWhitelisted);
+ X(minFeeFilter);
// It is common for nodes with good ping times to suddenly become lagged,
// due to a new block arriving or other large transfer.
diff --git a/src/net.h b/src/net.h
index f9cfea59b7..edd2f8cf0d 100644
--- a/src/net.h
+++ b/src/net.h
@@ -558,6 +558,7 @@ public:
double dPingTime;
double dPingWait;
double dMinPing;
+ CAmount minFeeFilter;
// Our address, as reported by the peer
std::string addrLocal;
// Address of this peer
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 9750173987..4b63757f3d 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -19,8 +19,6 @@
#include <fcntl.h>
#endif
-#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
-
#if !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
#endif
@@ -37,7 +35,7 @@ static const int SOCKS5_RECV_TIMEOUT = 20 * 1000;
static std::atomic<bool> interruptSocks5Recv(false);
enum Network ParseNetwork(std::string net) {
- boost::to_lower(net);
+ Downcase(net);
if (net == "ipv4") return NET_IPV4;
if (net == "ipv6") return NET_IPV6;
if (net == "onion") return NET_ONION;
diff --git a/src/policy/fees.h b/src/policy/fees.h
index 136fb481f7..2733c5a7de 100644
--- a/src/policy/fees.h
+++ b/src/policy/fees.h
@@ -22,51 +22,6 @@ class CTxMemPoolEntry;
class CTxMemPool;
class TxConfirmStats;
-/** \class CBlockPolicyEstimator
- * The BlockPolicyEstimator is used for estimating the feerate needed
- * for a transaction to be included in a block within a certain number of
- * blocks.
- *
- * At a high level the algorithm works by grouping transactions into buckets
- * based on having similar feerates and then tracking how long it
- * takes transactions in the various buckets to be mined. It operates under
- * the assumption that in general transactions of higher feerate will be
- * included in blocks before transactions of lower feerate. So for
- * example if you wanted to know what feerate you should put on a transaction to
- * be included in a block within the next 5 blocks, you would start by looking
- * at the bucket with the highest feerate transactions and verifying that a
- * sufficiently high percentage of them were confirmed within 5 blocks and
- * then you would look at the next highest feerate bucket, and so on, stopping at
- * the last bucket to pass the test. The average feerate of transactions in this
- * bucket will give you an indication of the lowest feerate you can put on a
- * transaction and still have a sufficiently high chance of being confirmed
- * within your desired 5 blocks.
- *
- * Here is a brief description of the implementation:
- * When a transaction enters the mempool, we track the height of the block chain
- * at entry. All further calculations are conducted only on this set of "seen"
- * transactions. Whenever a block comes in, we count the number of transactions
- * in each bucket and the total amount of feerate paid in each bucket. Then we
- * calculate how many blocks Y it took each transaction to be mined. We convert
- * from a number of blocks to a number of periods Y' each encompassing "scale"
- * blocks. This is tracked in 3 different data sets each up to a maximum
- * number of periods. Within each data set we have an array of counters in each
- * feerate bucket and we increment all the counters from Y' up to max periods
- * representing that a tx was successfully confirmed in less than or equal to
- * that many periods. We want to save a history of this information, so at any
- * time we have a counter of the total number of transactions that happened in a
- * given feerate bucket and the total number that were confirmed in each of the
- * periods or less for any bucket. We save this history by keeping an
- * exponentially decaying moving average of each one of these stats. This is
- * done for a different decay in each of the 3 data sets to keep relevant data
- * from different time horizons. Furthermore we also keep track of the number
- * unmined (in mempool or left mempool without being included in a block)
- * transactions in each bucket and for how many blocks they have been
- * outstanding and use both of these numbers to increase the number of transactions
- * we've seen in that feerate bucket when calculating an estimate for any number
- * of confirmations below the number of blocks they've been outstanding.
- */
-
/* Identifier for each of the 3 different TxConfirmStats which will track
* history over different time horizons. */
enum class FeeEstimateHorizon {
@@ -130,7 +85,50 @@ struct FeeCalculation
int returnedTarget = 0;
};
-/**
+/** \class CBlockPolicyEstimator
+ * The BlockPolicyEstimator is used for estimating the feerate needed
+ * for a transaction to be included in a block within a certain number of
+ * blocks.
+ *
+ * At a high level the algorithm works by grouping transactions into buckets
+ * based on having similar feerates and then tracking how long it
+ * takes transactions in the various buckets to be mined. It operates under
+ * the assumption that in general transactions of higher feerate will be
+ * included in blocks before transactions of lower feerate. So for
+ * example if you wanted to know what feerate you should put on a transaction to
+ * be included in a block within the next 5 blocks, you would start by looking
+ * at the bucket with the highest feerate transactions and verifying that a
+ * sufficiently high percentage of them were confirmed within 5 blocks and
+ * then you would look at the next highest feerate bucket, and so on, stopping at
+ * the last bucket to pass the test. The average feerate of transactions in this
+ * bucket will give you an indication of the lowest feerate you can put on a
+ * transaction and still have a sufficiently high chance of being confirmed
+ * within your desired 5 blocks.
+ *
+ * Here is a brief description of the implementation:
+ * When a transaction enters the mempool, we track the height of the block chain
+ * at entry. All further calculations are conducted only on this set of "seen"
+ * transactions. Whenever a block comes in, we count the number of transactions
+ * in each bucket and the total amount of feerate paid in each bucket. Then we
+ * calculate how many blocks Y it took each transaction to be mined. We convert
+ * from a number of blocks to a number of periods Y' each encompassing "scale"
+ * blocks. This is tracked in 3 different data sets each up to a maximum
+ * number of periods. Within each data set we have an array of counters in each
+ * feerate bucket and we increment all the counters from Y' up to max periods
+ * representing that a tx was successfully confirmed in less than or equal to
+ * that many periods. We want to save a history of this information, so at any
+ * time we have a counter of the total number of transactions that happened in a
+ * given feerate bucket and the total number that were confirmed in each of the
+ * periods or less for any bucket. We save this history by keeping an
+ * exponentially decaying moving average of each one of these stats. This is
+ * done for a different decay in each of the 3 data sets to keep relevant data
+ * from different time horizons. Furthermore we also keep track of the number
+ * unmined (in mempool or left mempool without being included in a block)
+ * transactions in each bucket and for how many blocks they have been
+ * outstanding and use both of these numbers to increase the number of transactions
+ * we've seen in that feerate bucket when calculating an estimate for any number
+ * of confirmations below the number of blocks they've been outstanding.
+ *
* We want to be able to estimate feerates that are needed on tx's to be included in
* a certain number of blocks. Every time a block is added to the best chain, this class records
* stats on the transactions included in that block
diff --git a/src/prevector.h b/src/prevector.h
index 033952c959..6ddb6f321f 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -248,32 +248,32 @@ public:
prevector() : _size(0), _union{{}} {}
- explicit prevector(size_type n) : _size(0) {
+ explicit prevector(size_type n) : prevector() {
resize(n);
}
- explicit prevector(size_type n, const T& val = T()) : _size(0) {
+ explicit prevector(size_type n, const T& val) : prevector() {
change_capacity(n);
_size += n;
fill(item_ptr(0), n, val);
}
template<typename InputIterator>
- prevector(InputIterator first, InputIterator last) : _size(0) {
+ prevector(InputIterator first, InputIterator last) : prevector() {
size_type n = last - first;
change_capacity(n);
_size += n;
fill(item_ptr(0), first, last);
}
- prevector(const prevector<N, T, Size, Diff>& other) : _size(0) {
+ prevector(const prevector<N, T, Size, Diff>& other) : prevector() {
size_type n = other.size();
change_capacity(n);
_size += n;
fill(item_ptr(0), other.begin(), other.end());
}
- prevector(prevector<N, T, Size, Diff>&& other) : _size(0) {
+ prevector(prevector<N, T, Size, Diff>&& other) : prevector() {
swap(other);
}
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index 380a3ddb84..2f88e15d21 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -71,7 +71,7 @@ public:
QList<AddressTableEntry> cachedAddressTable;
AddressTableModel *parent;
- AddressTablePriv(AddressTableModel *_parent):
+ explicit AddressTablePriv(AddressTableModel *_parent):
parent(_parent) {}
void refreshAddressTable(interfaces::Wallet& wallet)
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index 61cd6f76cc..dcaca10557 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -212,7 +212,7 @@ private:
void setEncryptionStatus(int status);
/** Set the hd-enabled status as shown in the UI.
- @param[in] status current hd enabled status
+ @param[in] hdEnabled current hd enabled status
@see WalletModel::EncryptionStatus
*/
void setHDStatus(int hdEnabled);
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index 66e36f0b67..ad13b20ebe 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -82,7 +82,7 @@ class RPCExecutor : public QObject
{
Q_OBJECT
public:
- RPCExecutor(interfaces::Node& node) : m_node(node) {}
+ explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
public Q_SLOTS:
void request(const QString &command, const QString &walletID);
@@ -142,7 +142,7 @@ public:
* - Within single quotes, no escaping is possible and no special interpretation takes place
*
* @param[in] node optional node to execute command on
- * @param[out] result stringified Result from the executed command(chain)
+ * @param[out] strResult stringified result from the executed command(chain)
* @param[in] strCommand Command line to split
* @param[in] fExecute set true if you want the command to be executed
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index 4fa941b630..b4be068904 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -60,7 +60,7 @@ struct TxLessThan
class TransactionTablePriv
{
public:
- TransactionTablePriv(TransactionTableModel *_parent) :
+ explicit TransactionTablePriv(TransactionTableModel *_parent) :
parent(_parent)
{
}
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 18a5bda9c3..f7cc94ae32 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -253,7 +253,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
auto& newTx = transaction.getWtx();
std::string rejectReason;
- if (!newTx->commit({} /* mapValue */, std::move(vOrderForm), {} /* fromAccount */, rejectReason))
+ if (!newTx->commit({} /* mapValue */, std::move(vOrderForm), rejectReason))
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(rejectReason));
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp
index c7f3e38ac0..784d6416cf 100644
--- a/src/rpc/client.cpp
+++ b/src/rpc/client.cpp
@@ -40,15 +40,11 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "settxfee", 0, "amount" },
{ "sethdseed", 0, "newkeypool" },
{ "getreceivedbyaddress", 1, "minconf" },
- { "getreceivedbyaccount", 1, "minconf" },
{ "getreceivedbylabel", 1, "minconf" },
{ "listreceivedbyaddress", 0, "minconf" },
{ "listreceivedbyaddress", 1, "include_empty" },
{ "listreceivedbyaddress", 2, "include_watchonly" },
{ "listreceivedbyaddress", 3, "address_filter" },
- { "listreceivedbyaccount", 0, "minconf" },
- { "listreceivedbyaccount", 1, "include_empty" },
- { "listreceivedbyaccount", 2, "include_watchonly" },
{ "listreceivedbylabel", 0, "minconf" },
{ "listreceivedbylabel", 1, "include_empty" },
{ "listreceivedbylabel", 2, "include_watchonly" },
@@ -59,15 +55,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "waitforblockheight", 1, "timeout" },
{ "waitforblock", 1, "timeout" },
{ "waitfornewblock", 0, "timeout" },
- { "move", 2, "amount" },
- { "move", 3, "minconf" },
- { "sendfrom", 2, "amount" },
- { "sendfrom", 3, "minconf" },
{ "listtransactions", 1, "count" },
{ "listtransactions", 2, "skip" },
{ "listtransactions", 3, "include_watchonly" },
- { "listaccounts", 0, "minconf" },
- { "listaccounts", 1, "include_watchonly" },
{ "walletpassphrase", 1, "timeout" },
{ "getblocktemplate", 0, "template_request" },
{ "listsinceblock", 1, "target_confirmations" },
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 610a1fee6f..343b7d3b05 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -102,6 +102,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
" ...\n"
" ],\n"
" \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n"
+ " \"minfeefilter\": n, (numeric) The minimum fee rate for transactions this peer accepts\n"
" \"bytessent_per_msg\": {\n"
" \"addr\": n, (numeric) The total bytes sent aggregated by message type\n"
" ...\n"
@@ -169,6 +170,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
obj.pushKV("inflight", heights);
}
obj.pushKV("whitelisted", stats.fWhitelisted);
+ obj.pushKV("minfeefilter", ValueFromAmount(stats.minFeeFilter));
UniValue sendPerMsgCmd(UniValue::VOBJ);
for (const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) {
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 7ca097f8cf..248b963c0b 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -1458,11 +1458,8 @@ UniValue decodepsbt(const JSONRPCRequest& request)
UniValue keypath(UniValue::VOBJ);
keypath.pushKV("pubkey", HexStr(entry.first));
- uint32_t fingerprint = entry.second.at(0);
- keypath.pushKV("master_fingerprint", strprintf("%08x", bswap_32(fingerprint)));
-
- entry.second.erase(entry.second.begin());
- keypath.pushKV("path", WriteHDKeypath(entry.second));
+ keypath.pushKV("master_fingerprint", strprintf("%08x", ReadBE32(entry.second.fingerprint)));
+ keypath.pushKV("path", WriteHDKeypath(entry.second.path));
keypaths.push_back(keypath);
}
in.pushKV("bip32_derivs", keypaths);
@@ -1520,12 +1517,8 @@ UniValue decodepsbt(const JSONRPCRequest& request)
for (auto entry : output.hd_keypaths) {
UniValue keypath(UniValue::VOBJ);
keypath.pushKV("pubkey", HexStr(entry.first));
-
- uint32_t fingerprint = entry.second.at(0);
- keypath.pushKV("master_fingerprint", strprintf("%08x", bswap_32(fingerprint)));
-
- entry.second.erase(entry.second.begin());
- keypath.pushKV("path", WriteHDKeypath(entry.second));
+ keypath.pushKV("master_fingerprint", strprintf("%08x", ReadBE32(entry.second.fingerprint)));
+ keypath.pushKV("path", WriteHDKeypath(entry.second.path));
keypaths.push_back(keypath);
}
out.pushKV("bip32_derivs", keypaths);
@@ -1646,8 +1639,7 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
PSBTInput& input = psbtx.inputs.at(i);
- SignatureData sigdata;
- complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, sigdata, i, 1);
+ complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, 1);
}
UniValue result(UniValue::VOBJ);
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index e46bf2f765..7d7e83fea8 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -16,7 +16,6 @@
#include <boost/bind.hpp>
#include <boost/signals2/signal.hpp>
-#include <boost/algorithm/string/case_conv.hpp> // for to_upper()
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
@@ -192,9 +191,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
if (!category.empty())
strRet += "\n";
category = pcmd->category;
- std::string firstLetter = category.substr(0,1);
- boost::to_upper(firstLetter);
- strRet += "== " + firstLetter + category.substr(1) + " ==\n";
+ strRet += "== " + Capitalize(category) + " ==\n";
}
}
strRet += strHelp + "\n";
diff --git a/src/script/sign.cpp b/src/script/sign.cpp
index 23af1bd97f..d779910425 100644
--- a/src/script/sign.cpp
+++ b/src/script/sign.cpp
@@ -50,10 +50,6 @@ static bool GetCScript(const SigningProvider& provider, const SignatureData& sig
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
{
- if (provider.GetPubKey(address, pubkey)) {
- sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey);
- return true;
- }
// Look for pubkey in all partial sigs
const auto it = sigdata.signatures.find(address);
if (it != sigdata.signatures.end()) {
@@ -63,7 +59,15 @@ static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, c
// Look for pubkey in pubkey list
const auto& pk_it = sigdata.misc_pubkeys.find(address);
if (pk_it != sigdata.misc_pubkeys.end()) {
- pubkey = pk_it->second;
+ pubkey = pk_it->second.first;
+ return true;
+ }
+ // Query the underlying provider
+ if (provider.GetPubKey(address, pubkey)) {
+ KeyOriginInfo info;
+ if (provider.GetKeyOrigin(address, info)) {
+ sigdata.misc_pubkeys.emplace(address, std::make_pair(pubkey, std::move(info)));
+ }
return true;
}
return false;
@@ -232,7 +236,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
return sigdata.complete;
}
-bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash)
+bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
{
// if this input has a final scriptsig or scriptwitness, don't do anything with it
if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) {
@@ -240,6 +244,7 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
}
// Fill SignatureData with input info
+ SignatureData sigdata;
input.FillSignatureData(sigdata);
// Get UTXO
@@ -271,6 +276,16 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
// Verify that a witness signature was produced in case one was required.
if (require_witness_sig && !sigdata.witness) return false;
input.FromSignatureData(sigdata);
+
+ // If both UTXO types are present, drop the unnecessary one.
+ if (input.non_witness_utxo && !input.witness_utxo.IsNull()) {
+ if (sigdata.witness) {
+ input.non_witness_utxo = nullptr;
+ } else {
+ input.witness_utxo.SetNull();
+ }
+ }
+
return sig_complete;
}
@@ -541,7 +556,7 @@ void PSBTInput::FillSignatureData(SignatureData& sigdata) const
sigdata.witness_script = witness_script;
}
for (const auto& key_pair : hd_keypaths) {
- sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
+ sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
}
}
@@ -569,6 +584,9 @@ void PSBTInput::FromSignatureData(const SignatureData& sigdata)
if (witness_script.empty() && !sigdata.witness_script.empty()) {
witness_script = sigdata.witness_script;
}
+ for (const auto& entry : sigdata.misc_pubkeys) {
+ hd_keypaths.emplace(entry.second);
+ }
}
void PSBTInput::Merge(const PSBTInput& input)
@@ -610,7 +628,7 @@ void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
sigdata.witness_script = witness_script;
}
for (const auto& key_pair : hd_keypaths) {
- sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair.first);
+ sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
}
}
@@ -622,6 +640,9 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
if (witness_script.empty() && !sigdata.witness_script.empty()) {
witness_script = sigdata.witness_script;
}
+ for (const auto& entry : sigdata.misc_pubkeys) {
+ hd_keypaths.emplace(entry.second);
+ }
}
bool PSBTOutput::IsNull() const
@@ -638,14 +659,26 @@ void PSBTOutput::Merge(const PSBTOutput& output)
if (witness_script.empty() && !output.witness_script.empty()) witness_script = output.witness_script;
}
-bool PublicOnlySigningProvider::GetCScript(const CScriptID &scriptid, CScript& script) const
+bool HidingSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const
{
return m_provider->GetCScript(scriptid, script);
}
-bool PublicOnlySigningProvider::GetPubKey(const CKeyID &address, CPubKey& pubkey) const
+bool HidingSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const
+{
+ return m_provider->GetPubKey(keyid, pubkey);
+}
+
+bool HidingSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const
+{
+ if (m_hide_secret) return false;
+ return m_provider->GetKey(keyid, key);
+}
+
+bool HidingSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const
{
- return m_provider->GetPubKey(address, pubkey);
+ if (m_hide_origin) return false;
+ return m_provider->GetKeyOrigin(keyid, info);
}
bool FlatSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const { return LookupHelper(scripts, scriptid, script); }
diff --git a/src/script/sign.h b/src/script/sign.h
index 7ade715ee2..18b7320998 100644
--- a/src/script/sign.h
+++ b/src/script/sign.h
@@ -20,6 +20,12 @@ class CTransaction;
struct CMutableTransaction;
+struct KeyOriginInfo
+{
+ unsigned char fingerprint[4];
+ std::vector<uint32_t> path;
+};
+
/** An interface to be implemented by keystores that support signing. */
class SigningProvider
{
@@ -28,19 +34,24 @@ public:
virtual bool GetCScript(const CScriptID &scriptid, CScript& script) const { return false; }
virtual bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const { return false; }
virtual bool GetKey(const CKeyID &address, CKey& key) const { return false; }
+ virtual bool GetKeyOrigin(const CKeyID& id, KeyOriginInfo& info) const { return false; }
};
extern const SigningProvider& DUMMY_SIGNING_PROVIDER;
-class PublicOnlySigningProvider : public SigningProvider
+class HidingSigningProvider : public SigningProvider
{
private:
+ const bool m_hide_secret;
+ const bool m_hide_origin;
const SigningProvider* m_provider;
public:
- PublicOnlySigningProvider(const SigningProvider* provider) : m_provider(provider) {}
- bool GetCScript(const CScriptID &scriptid, CScript& script) const;
- bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const;
+ HidingSigningProvider(const SigningProvider* provider, bool hide_secret, bool hide_origin) : m_hide_secret(hide_secret), m_hide_origin(hide_origin), m_provider(provider) {}
+ bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
+ bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
+ bool GetKey(const CKeyID& keyid, CKey& key) const override;
+ bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
};
struct FlatSigningProvider final : public SigningProvider
@@ -98,7 +109,7 @@ struct SignatureData {
CScript witness_script; ///< The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
CScriptWitness scriptWitness; ///< The scriptWitness of an input. Contains complete signatures or the traditional partial signatures format. scriptWitness is part of a transaction input per BIP 144.
std::map<CKeyID, SigPair> signatures; ///< BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a final scriptSig or scriptWitness.
- std::map<CKeyID, CPubKey> misc_pubkeys;
+ std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> misc_pubkeys;
SignatureData() {}
explicit SignatureData(const CScript& script) : scriptSig(script) {}
@@ -155,7 +166,7 @@ void UnserializeFromVector(Stream& s, X&... args)
// Deserialize HD keypaths into a map
template<typename Stream>
-void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, std::vector<uint32_t>>& hd_keypaths)
+void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths)
{
// Make sure that the key is the size of pubkey + 1
if (key.size() != CPubKey::PUBLIC_KEY_SIZE + 1 && key.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1) {
@@ -172,25 +183,31 @@ void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std
// Read in key path
uint64_t value_len = ReadCompactSize(s);
- std::vector<uint32_t> keypath;
- for (unsigned int i = 0; i < value_len; i += sizeof(uint32_t)) {
+ if (value_len % 4 || value_len == 0) {
+ throw std::ios_base::failure("Invalid length for HD key path");
+ }
+
+ KeyOriginInfo keypath;
+ s >> keypath.fingerprint;
+ for (unsigned int i = 4; i < value_len; i += sizeof(uint32_t)) {
uint32_t index;
s >> index;
- keypath.push_back(index);
+ keypath.path.push_back(index);
}
// Add to map
- hd_keypaths.emplace(pubkey, keypath);
+ hd_keypaths.emplace(pubkey, std::move(keypath));
}
// Serialize HD keypaths to a stream from a map
template<typename Stream>
-void SerializeHDKeypaths(Stream& s, const std::map<CPubKey, std::vector<uint32_t>>& hd_keypaths, uint8_t type)
+void SerializeHDKeypaths(Stream& s, const std::map<CPubKey, KeyOriginInfo>& hd_keypaths, uint8_t type)
{
for (auto keypath_pair : hd_keypaths) {
SerializeToVector(s, type, MakeSpan(keypath_pair.first));
- WriteCompactSize(s, keypath_pair.second.size() * sizeof(uint32_t));
- for (auto& path : keypath_pair.second) {
+ WriteCompactSize(s, (keypath_pair.second.path.size() + 1) * sizeof(uint32_t));
+ s << keypath_pair.second.fingerprint;
+ for (const auto& path : keypath_pair.second.path) {
s << path;
}
}
@@ -205,7 +222,7 @@ struct PSBTInput
CScript witness_script;
CScript final_script_sig;
CScriptWitness final_script_witness;
- std::map<CPubKey, std::vector<uint32_t>> hd_keypaths;
+ std::map<CPubKey, KeyOriginInfo> hd_keypaths;
std::map<CKeyID, SigPair> partial_sigs;
std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
int sighash_type = 0;
@@ -418,7 +435,7 @@ struct PSBTOutput
{
CScript redeem_script;
CScript witness_script;
- std::map<CPubKey, std::vector<uint32_t>> hd_keypaths;
+ std::map<CPubKey, KeyOriginInfo> hd_keypaths;
std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
bool IsNull() const;
@@ -687,7 +704,7 @@ bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, C
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
-bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash = 1);
+bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash = SIGHASH_ALL);
/** Extract signature data from a transaction input, and insert it. */
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp
index d2c7c8cb1d..5131fe8235 100644
--- a/src/test/blockencodings_tests.cpp
+++ b/src/test/blockencodings_tests.cpp
@@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
CBlock block(BuildBlockTestCase());
LOCK(pool.cs);
- pool.addUnchecked(block.vtx[2]->GetHash(), entry.FromTx(block.vtx[2]));
+ pool.addUnchecked(entry.FromTx(block.vtx[2]));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
// Do a simple ShortTxIDs RT
@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
CBlock block(BuildBlockTestCase());
LOCK(pool.cs);
- pool.addUnchecked(block.vtx[2]->GetHash(), entry.FromTx(block.vtx[2]));
+ pool.addUnchecked(entry.FromTx(block.vtx[2]));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
uint256 txhash;
@@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
CBlock block(BuildBlockTestCase());
LOCK(pool.cs);
- pool.addUnchecked(block.vtx[1]->GetHash(), entry.FromTx(block.vtx[1]));
+ pool.addUnchecked(entry.FromTx(block.vtx[1]));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
uint256 txhash;
diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp
index f189222be8..e739b84a48 100644
--- a/src/test/descriptor_tests.cpp
+++ b/src/test/descriptor_tests.cpp
@@ -64,7 +64,7 @@ void Check(const std::string& prv, const std::string& pub, int flags, const std:
BOOST_CHECK_EQUAL(pub, pub2);
// Check that both can be serialized with private key back to the private version, but not without private key.
- std::string prv1, prv2;
+ std::string prv1;
BOOST_CHECK(parse_priv->ToPrivateString(keys_priv, prv1));
BOOST_CHECK_EQUAL(prv, prv1);
BOOST_CHECK(!parse_priv->ToPrivateString(keys_pub, prv1));
diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp
index e416de098e..0e15464fd9 100644
--- a/src/test/mempool_tests.cpp
+++ b/src/test/mempool_tests.cpp
@@ -63,17 +63,17 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
BOOST_CHECK_EQUAL(testPool.size(), poolSize);
// Just the parent:
- testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
+ testPool.addUnchecked(entry.FromTx(txParent));
poolSize = testPool.size();
testPool.removeRecursive(txParent);
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1);
// Parent, children, grandchildren:
- testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
+ testPool.addUnchecked(entry.FromTx(txParent));
for (int i = 0; i < 3; i++)
{
- testPool.addUnchecked(txChild[i].GetHash(), entry.FromTx(txChild[i]));
- testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
+ testPool.addUnchecked(entry.FromTx(txChild[i]));
+ testPool.addUnchecked(entry.FromTx(txGrandChild[i]));
}
// Remove Child[0], GrandChild[0] should be removed:
poolSize = testPool.size();
@@ -95,8 +95,8 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
// Add children and grandchildren, but NOT the parent (simulate the parent being in a block)
for (int i = 0; i < 3; i++)
{
- testPool.addUnchecked(txChild[i].GetHash(), entry.FromTx(txChild[i]));
- testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
+ testPool.addUnchecked(entry.FromTx(txChild[i]));
+ testPool.addUnchecked(entry.FromTx(txGrandChild[i]));
}
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
// put into the mempool (maybe because it is non-standard):
@@ -128,28 +128,28 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
tx1.vout.resize(1);
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx1.vout[0].nValue = 10 * COIN;
- pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx1));
/* highest fee */
CMutableTransaction tx2 = CMutableTransaction();
tx2.vout.resize(1);
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx2.vout[0].nValue = 2 * COIN;
- pool.addUnchecked(tx2.GetHash(), entry.Fee(20000LL).FromTx(tx2));
+ pool.addUnchecked(entry.Fee(20000LL).FromTx(tx2));
/* lowest fee */
CMutableTransaction tx3 = CMutableTransaction();
tx3.vout.resize(1);
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx3.vout[0].nValue = 5 * COIN;
- pool.addUnchecked(tx3.GetHash(), entry.Fee(0LL).FromTx(tx3));
+ pool.addUnchecked(entry.Fee(0LL).FromTx(tx3));
/* 2nd highest fee */
CMutableTransaction tx4 = CMutableTransaction();
tx4.vout.resize(1);
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx4.vout[0].nValue = 6 * COIN;
- pool.addUnchecked(tx4.GetHash(), entry.Fee(15000LL).FromTx(tx4));
+ pool.addUnchecked(entry.Fee(15000LL).FromTx(tx4));
/* equal fee rate to tx1, but newer */
CMutableTransaction tx5 = CMutableTransaction();
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx5.vout[0].nValue = 11 * COIN;
entry.nTime = 1;
- pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx5));
BOOST_CHECK_EQUAL(pool.size(), 5U);
std::vector<std::string> sortedOrder;
@@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
tx6.vout.resize(1);
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx6.vout[0].nValue = 20 * COIN;
- pool.addUnchecked(tx6.GetHash(), entry.Fee(0LL).FromTx(tx6));
+ pool.addUnchecked(entry.Fee(0LL).FromTx(tx6));
BOOST_CHECK_EQUAL(pool.size(), 6U);
// Check that at this point, tx6 is sorted low
sortedOrder.insert(sortedOrder.begin(), tx6.GetHash().ToString());
@@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry.Fee(2000000LL).FromTx(tx7), setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
BOOST_CHECK(setAncestorsCalculated == setAncestors);
- pool.addUnchecked(tx7.GetHash(), entry.FromTx(tx7), setAncestors);
+ pool.addUnchecked(entry.FromTx(tx7), setAncestors);
BOOST_CHECK_EQUAL(pool.size(), 7U);
// Now tx6 should be sorted higher (high fee child): tx7, tx6, tx2, ...
@@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
tx8.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx8.vout[0].nValue = 10 * COIN;
setAncestors.insert(pool.mapTx.find(tx7.GetHash()));
- pool.addUnchecked(tx8.GetHash(), entry.Fee(0LL).Time(2).FromTx(tx8), setAncestors);
+ pool.addUnchecked(entry.Fee(0LL).Time(2).FromTx(tx8), setAncestors);
// Now tx8 should be sorted low, but tx6/tx both high
sortedOrder.insert(sortedOrder.begin(), tx8.GetHash().ToString());
@@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
tx9.vout.resize(1);
tx9.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx9.vout[0].nValue = 1 * COIN;
- pool.addUnchecked(tx9.GetHash(), entry.Fee(0LL).Time(3).FromTx(tx9), setAncestors);
+ pool.addUnchecked(entry.Fee(0LL).Time(3).FromTx(tx9), setAncestors);
// tx9 should be sorted low
BOOST_CHECK_EQUAL(pool.size(), 9U);
@@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors(entry.Fee(200000LL).Time(4).FromTx(tx10), setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true);
BOOST_CHECK(setAncestorsCalculated == setAncestors);
- pool.addUnchecked(tx10.GetHash(), entry.FromTx(tx10), setAncestors);
+ pool.addUnchecked(entry.FromTx(tx10), setAncestors);
/**
* tx8 and tx9 should both now be sorted higher
@@ -301,14 +301,14 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
tx1.vout.resize(1);
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx1.vout[0].nValue = 10 * COIN;
- pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx1));
/* highest fee */
CMutableTransaction tx2 = CMutableTransaction();
tx2.vout.resize(1);
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx2.vout[0].nValue = 2 * COIN;
- pool.addUnchecked(tx2.GetHash(), entry.Fee(20000LL).FromTx(tx2));
+ pool.addUnchecked(entry.Fee(20000LL).FromTx(tx2));
uint64_t tx2Size = GetVirtualTransactionSize(tx2);
/* lowest fee */
@@ -316,21 +316,21 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
tx3.vout.resize(1);
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx3.vout[0].nValue = 5 * COIN;
- pool.addUnchecked(tx3.GetHash(), entry.Fee(0LL).FromTx(tx3));
+ pool.addUnchecked(entry.Fee(0LL).FromTx(tx3));
/* 2nd highest fee */
CMutableTransaction tx4 = CMutableTransaction();
tx4.vout.resize(1);
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx4.vout[0].nValue = 6 * COIN;
- pool.addUnchecked(tx4.GetHash(), entry.Fee(15000LL).FromTx(tx4));
+ pool.addUnchecked(entry.Fee(15000LL).FromTx(tx4));
/* equal fee rate to tx1, but newer */
CMutableTransaction tx5 = CMutableTransaction();
tx5.vout.resize(1);
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx5.vout[0].nValue = 11 * COIN;
- pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx5));
BOOST_CHECK_EQUAL(pool.size(), 5U);
std::vector<std::string> sortedOrder;
@@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
tx6.vout[0].nValue = 20 * COIN;
uint64_t tx6Size = GetVirtualTransactionSize(tx6);
- pool.addUnchecked(tx6.GetHash(), entry.Fee(0LL).FromTx(tx6));
+ pool.addUnchecked(entry.Fee(0LL).FromTx(tx6));
BOOST_CHECK_EQUAL(pool.size(), 6U);
// Ties are broken by hash
if (tx3.GetHash() < tx6.GetHash())
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
/* set the fee to just below tx2's feerate when including ancestor */
CAmount fee = (20000/tx2Size)*(tx7Size + tx6Size) - 1;
- pool.addUnchecked(tx7.GetHash(), entry.Fee(fee).FromTx(tx7));
+ pool.addUnchecked(entry.Fee(fee).FromTx(tx7));
BOOST_CHECK_EQUAL(pool.size(), 7U);
sortedOrder.insert(sortedOrder.begin()+1, tx7.GetHash().ToString());
CheckSort<ancestor_score>(pool, sortedOrder);
@@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
// Check that we sort by min(feerate, ancestor_feerate):
// set the fee so that the ancestor feerate is above tx1/5,
// but the transaction's own feerate is lower
- pool.addUnchecked(tx8.GetHash(), entry.Fee(5000LL).FromTx(tx8));
+ pool.addUnchecked(entry.Fee(5000LL).FromTx(tx8));
sortedOrder.insert(sortedOrder.end()-1, tx8.GetHash().ToString());
CheckSort<ancestor_score>(pool, sortedOrder);
}
@@ -431,7 +431,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
tx1.vout.resize(1);
tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
tx1.vout[0].nValue = 10 * COIN;
- pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx1));
CMutableTransaction tx2 = CMutableTransaction();
tx2.vin.resize(1);
@@ -439,7 +439,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
tx2.vout.resize(1);
tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL;
tx2.vout[0].nValue = 10 * COIN;
- pool.addUnchecked(tx2.GetHash(), entry.Fee(5000LL).FromTx(tx2));
+ pool.addUnchecked(entry.Fee(5000LL).FromTx(tx2));
pool.TrimToSize(pool.DynamicMemoryUsage()); // should do nothing
BOOST_CHECK(pool.exists(tx1.GetHash()));
@@ -449,7 +449,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
BOOST_CHECK(pool.exists(tx1.GetHash()));
BOOST_CHECK(!pool.exists(tx2.GetHash()));
- pool.addUnchecked(tx2.GetHash(), entry.FromTx(tx2));
+ pool.addUnchecked(entry.FromTx(tx2));
CMutableTransaction tx3 = CMutableTransaction();
tx3.vin.resize(1);
tx3.vin[0].prevout = COutPoint(tx2.GetHash(), 0);
@@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
tx3.vout.resize(1);
tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL;
tx3.vout[0].nValue = 10 * COIN;
- pool.addUnchecked(tx3.GetHash(), entry.Fee(20000LL).FromTx(tx3));
+ pool.addUnchecked(entry.Fee(20000LL).FromTx(tx3));
pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); // tx3 should pay for tx2 (CPFP)
BOOST_CHECK(!pool.exists(tx1.GetHash()));
@@ -520,10 +520,10 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
tx7.vout[1].nValue = 10 * COIN;
- pool.addUnchecked(tx4.GetHash(), entry.Fee(7000LL).FromTx(tx4));
- pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5));
- pool.addUnchecked(tx6.GetHash(), entry.Fee(1100LL).FromTx(tx6));
- pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7));
+ pool.addUnchecked(entry.Fee(7000LL).FromTx(tx4));
+ pool.addUnchecked(entry.Fee(1000LL).FromTx(tx5));
+ pool.addUnchecked(entry.Fee(1100LL).FromTx(tx6));
+ pool.addUnchecked(entry.Fee(9000LL).FromTx(tx7));
// we only require this to remove, at max, 2 txn, because it's not clear what we're really optimizing for aside from that
pool.TrimToSize(pool.DynamicMemoryUsage() - 1);
@@ -532,8 +532,8 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
BOOST_CHECK(!pool.exists(tx7.GetHash()));
if (!pool.exists(tx5.GetHash()))
- pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5));
- pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7));
+ pool.addUnchecked(entry.Fee(1000LL).FromTx(tx5));
+ pool.addUnchecked(entry.Fee(9000LL).FromTx(tx7));
pool.TrimToSize(pool.DynamicMemoryUsage() / 2); // should maximize mempool size by only removing 5/7
BOOST_CHECK(pool.exists(tx4.GetHash()));
@@ -541,8 +541,8 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
BOOST_CHECK(pool.exists(tx6.GetHash()));
BOOST_CHECK(!pool.exists(tx7.GetHash()));
- pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5));
- pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7));
+ pool.addUnchecked(entry.Fee(1000LL).FromTx(tx5));
+ pool.addUnchecked(entry.Fee(9000LL).FromTx(tx7));
std::vector<CTransactionRef> vtx;
SetMockTime(42);
@@ -603,7 +603,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// [tx1]
//
CTransactionRef tx1 = make_tx(/* output_values */ {10 * COIN});
- pool.addUnchecked(tx1->GetHash(), entry.Fee(10000LL).FromTx(tx1));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx1));
// Ancestors / descendants should be 1 / 1 (itself / itself)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants);
@@ -615,7 +615,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// [tx1].0 <- [tx2]
//
CTransactionRef tx2 = make_tx(/* output_values */ {495 * CENT, 5 * COIN}, /* inputs */ {tx1});
- pool.addUnchecked(tx2->GetHash(), entry.Fee(10000LL).FromTx(tx2));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx2));
// Ancestors / descendants should be:
// transaction ancestors descendants
@@ -634,7 +634,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// [tx1].0 <- [tx2].0 <- [tx3]
//
CTransactionRef tx3 = make_tx(/* output_values */ {290 * CENT, 200 * CENT}, /* inputs */ {tx2});
- pool.addUnchecked(tx3->GetHash(), entry.Fee(10000LL).FromTx(tx3));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx3));
// Ancestors / descendants should be:
// transaction ancestors descendants
@@ -659,7 +659,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// \---1 <- [tx4]
//
CTransactionRef tx4 = make_tx(/* output_values */ {290 * CENT, 250 * CENT}, /* inputs */ {tx2}, /* input_indices */ {1});
- pool.addUnchecked(tx4->GetHash(), entry.Fee(10000LL).FromTx(tx4));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tx4));
// Ancestors / descendants should be:
// transaction ancestors descendants
@@ -696,13 +696,13 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
CTransactionRef& tyi = *ty[i];
tyi = make_tx(/* output_values */ {v}, /* inputs */ i > 0 ? std::vector<CTransactionRef>{*ty[i - 1]} : std::vector<CTransactionRef>{});
v -= 50 * CENT;
- pool.addUnchecked(tyi->GetHash(), entry.Fee(10000LL).FromTx(tyi));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(tyi));
pool.GetTransactionAncestry(tyi->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, i+1);
BOOST_CHECK_EQUAL(descendants, i+1);
}
CTransactionRef ty6 = make_tx(/* output_values */ {5 * COIN}, /* inputs */ {tx3, ty5});
- pool.addUnchecked(ty6->GetHash(), entry.Fee(10000LL).FromTx(ty6));
+ pool.addUnchecked(entry.Fee(10000LL).FromTx(ty6));
// Ancestors / descendants should be:
// transaction ancestors descendants
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 2b9641b6d4..eb0e4219d3 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -29,7 +29,7 @@ BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
// BOOST_CHECK_EXCEPTION predicates to check the specific validation error
class HasReason {
public:
- HasReason(const std::string& reason) : m_reason(reason) {}
+ explicit HasReason(const std::string& reason) : m_reason(reason) {}
bool operator() (const std::runtime_error& e) const {
return std::string(e.what()).find(m_reason) != std::string::npos;
};
@@ -115,19 +115,19 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
tx.vout[0].nValue = 5000000000LL - 1000;
// This tx has a low fee: 1000 satoshis
uint256 hashParentTx = tx.GetHash(); // save this txid for later use
- mempool.addUnchecked(hashParentTx, entry.Fee(1000).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(1000).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
// This tx has a medium fee: 10000 satoshis
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
tx.vout[0].nValue = 5000000000LL - 10000;
uint256 hashMediumFeeTx = tx.GetHash();
- mempool.addUnchecked(hashMediumFeeTx, entry.Fee(10000).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(10000).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
// This tx has a high fee, but depends on the first transaction
tx.vin[0].prevout.hash = hashParentTx;
tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 50k satoshi fee
uint256 hashHighFeeTx = tx.GetHash();
- mempool.addUnchecked(hashHighFeeTx, entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
@@ -138,7 +138,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
tx.vin[0].prevout.hash = hashHighFeeTx;
tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 0 fee
uint256 hashFreeTx = tx.GetHash();
- mempool.addUnchecked(hashFreeTx, entry.Fee(0).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(0).FromTx(tx));
size_t freeTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
// Calculate a fee on child transaction that will put the package just
@@ -148,7 +148,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
tx.vin[0].prevout.hash = hashFreeTx;
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
uint256 hashLowFeeTx = tx.GetHash();
- mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(feeToUse).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
// Verify that the free tx and the low fee tx didn't get selected
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
@@ -162,7 +162,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
mempool.removeRecursive(tx);
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
hashLowFeeTx = tx.GetHash();
- mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse+2).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(feeToUse+2).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
@@ -175,7 +175,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
tx.vout[0].nValue = 5000000000LL - 100000000;
tx.vout[1].nValue = 100000000; // 1BTC output
uint256 hashFreeTx2 = tx.GetHash();
- mempool.addUnchecked(hashFreeTx2, entry.Fee(0).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(0).SpendsCoinbase(true).FromTx(tx));
// This tx can't be mined by itself
tx.vin[0].prevout.hash = hashFreeTx2;
@@ -183,7 +183,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
feeToUse = blockMinFeeRate.GetFee(freeTxSize);
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
uint256 hashLowFeeTx2 = tx.GetHash();
- mempool.addUnchecked(hashLowFeeTx2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
// Verify that this tx isn't selected.
@@ -196,7 +196,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
// as well.
tx.vin[0].prevout.n = 1;
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
- mempool.addUnchecked(tx.GetHash(), entry.Fee(10000).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(10000).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
}
@@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
hash = tx.GetHash();
bool spendsCoinbase = i == 0; // only first tx spends coinbase
// If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
@@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
hash = tx.GetHash();
bool spendsCoinbase = i == 0; // only first tx spends coinbase
// If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
@@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue -= LOWFEE;
hash = tx.GetHash();
bool spendsCoinbase = i == 0; // only first tx spends coinbase
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
@@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// orphan in mempool, template creation fails
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
mempool.clear();
@@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
tx.vin[0].prevout.hash = hash;
tx.vin.resize(2);
tx.vin[1].scriptSig = CScript() << OP_1;
@@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[1].prevout.n = 0;
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
mempool.clear();
@@ -348,7 +348,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 0;
hash = tx.GetHash();
// give it a fee so it'll get mined
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
// Should throw bad-cb-multiple
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-cb-multiple"));
mempool.clear();
@@ -359,10 +359,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
tx.vout[0].scriptPubKey = CScript() << OP_1;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
mempool.clear();
@@ -401,12 +401,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
script = CScript() << OP_0;
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
tx.vin[0].prevout.hash = hash;
tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
tx.vout[0].nValue -= LOWFEE;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
// Should throw block-validation-failed
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
mempool.clear();
@@ -440,7 +440,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].scriptPubKey = CScript() << OP_1;
tx.nLockTime = 0;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
+ mempool.addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
BOOST_CHECK(SequenceLocks(tx, flags, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 2))); // Sequence locks pass on 2nd block
@@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | (((chainActive.Tip()->GetMedianTimePast()+1-chainActive[1]->GetMedianTimePast()) >> CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + 1); // txFirst[1] is the 3rd block
prevheights[0] = baseheight + 2;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
+ mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx));
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
@@ -466,7 +466,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
prevheights[0] = baseheight + 3;
tx.nLockTime = chainActive.Tip()->nHeight + 1;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
+ mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx));
BOOST_CHECK(!CheckFinalTx(tx, flags)); // Locktime fails
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetMedianTimePast())); // Locktime passes on 2nd block
@@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
prevheights.resize(1);
prevheights[0] = baseheight + 4;
hash = tx.GetHash();
- mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
+ mempool.addUnchecked(entry.Time(GetTime()).FromTx(tx));
BOOST_CHECK(!CheckFinalTx(tx, flags)); // Locktime fails
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetMedianTimePast() + 1)); // Locktime passes 1 second later
diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp
index 9c1af6bdf6..8072eb922d 100644
--- a/src/test/netbase_tests.cpp
+++ b/src/test/netbase_tests.cpp
@@ -302,4 +302,22 @@ BOOST_AUTO_TEST_CASE(netbase_getgroup)
BOOST_CHECK(CreateInternal("baz.net").GetGroup() == internal_group);
}
+BOOST_AUTO_TEST_CASE(netbase_parsenetwork)
+{
+ BOOST_CHECK_EQUAL(ParseNetwork("ipv4"), NET_IPV4);
+ BOOST_CHECK_EQUAL(ParseNetwork("ipv6"), NET_IPV6);
+ BOOST_CHECK_EQUAL(ParseNetwork("onion"), NET_ONION);
+ BOOST_CHECK_EQUAL(ParseNetwork("tor"), NET_ONION);
+
+ BOOST_CHECK_EQUAL(ParseNetwork("IPv4"), NET_IPV4);
+ BOOST_CHECK_EQUAL(ParseNetwork("IPv6"), NET_IPV6);
+ BOOST_CHECK_EQUAL(ParseNetwork("ONION"), NET_ONION);
+ BOOST_CHECK_EQUAL(ParseNetwork("TOR"), NET_ONION);
+
+ BOOST_CHECK_EQUAL(ParseNetwork(":)"), NET_UNROUTABLE);
+ BOOST_CHECK_EQUAL(ParseNetwork("tÖr"), NET_UNROUTABLE);
+ BOOST_CHECK_EQUAL(ParseNetwork("\xfe\xff"), NET_UNROUTABLE);
+ BOOST_CHECK_EQUAL(ParseNetwork(""), NET_UNROUTABLE);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp
index 26a0b495d9..2022ed6659 100644
--- a/src/test/policyestimator_tests.cpp
+++ b/src/test/policyestimator_tests.cpp
@@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
for (int k = 0; k < 4; k++) { // add 4 fee txs
tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique
uint256 hash = tx.GetHash();
- mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
+ mpool.addUnchecked(entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
txHashes[j].push_back(hash);
}
}
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
for (int k = 0; k < 4; k++) { // add 4 fee txs
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
uint256 hash = tx.GetHash();
- mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
+ mpool.addUnchecked(entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
txHashes[j].push_back(hash);
}
}
@@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
for (int k = 0; k < 4; k++) { // add 4 fee txs
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
uint256 hash = tx.GetHash();
- mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
+ mpool.addUnchecked(entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx));
CTransactionRef ptx = mpool.get(hash);
if (ptx)
block.push_back(ptx);
diff --git a/src/test/scheduler_tests.cpp b/src/test/scheduler_tests.cpp
index 2af0ab22da..814459c2bc 100644
--- a/src/test/scheduler_tests.cpp
+++ b/src/test/scheduler_tests.cpp
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(manythreads)
boost::mutex counterMutex[10];
int counter[10] = { 0 };
- FastRandomContext rng(42);
+ FastRandomContext rng{/* fDeterministic */ true};
auto zeroToNine = [](FastRandomContext& rc) -> int { return rc.randrange(10); }; // [0, 9]
auto randomMsec = [](FastRandomContext& rc) -> int { return -11 + (int)rc.randrange(1012); }; // [-11, 1000]
auto randomDelta = [](FastRandomContext& rc) -> int { return -1000 + (int)rc.randrange(2001); }; // [-1000, 1000]
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index bc671394c0..67c377778f 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -937,17 +937,19 @@ BOOST_AUTO_TEST_CASE(script_build)
}
}
+#ifdef UPDATE_JSON_TESTS
std::string strGen;
-
+#endif
for (TestBuilder& test : tests) {
test.Test();
std::string str = JSONPrettyPrint(test.GetJSON());
-#ifndef UPDATE_JSON_TESTS
+#ifdef UPDATE_JSON_TESTS
+ strGen += str + ",\n";
+#else
if (tests_set.count(str) == 0) {
BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment());
}
#endif
- strGen += str + ",\n";
}
#ifdef UPDATE_JSON_TESTS
diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp
index be7ee2428b..2a160b9988 100644
--- a/src/test/txindex_tests.cpp
+++ b/src/test/txindex_tests.cpp
@@ -61,6 +61,8 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
BOOST_ERROR("Read incorrect tx");
}
}
+
+ txindex.Stop(); // Stop thread before calling destructor
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index b2960446eb..8e2f5abe66 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -1217,4 +1217,43 @@ BOOST_AUTO_TEST_CASE(test_DirIsWritable)
fs::remove(tmpdirname);
}
+BOOST_AUTO_TEST_CASE(test_ToLower)
+{
+ BOOST_CHECK_EQUAL(ToLower('@'), '@');
+ BOOST_CHECK_EQUAL(ToLower('A'), 'a');
+ BOOST_CHECK_EQUAL(ToLower('Z'), 'z');
+ BOOST_CHECK_EQUAL(ToLower('['), '[');
+ BOOST_CHECK_EQUAL(ToLower(0), 0);
+ BOOST_CHECK_EQUAL(ToLower(255), 255);
+
+ std::string testVector;
+ Downcase(testVector);
+ BOOST_CHECK_EQUAL(testVector, "");
+
+ testVector = "#HODL";
+ Downcase(testVector);
+ BOOST_CHECK_EQUAL(testVector, "#hodl");
+
+ testVector = "\x00\xfe\xff";
+ Downcase(testVector);
+ BOOST_CHECK_EQUAL(testVector, "\x00\xfe\xff");
+}
+
+BOOST_AUTO_TEST_CASE(test_ToUpper)
+{
+ BOOST_CHECK_EQUAL(ToUpper('`'), '`');
+ BOOST_CHECK_EQUAL(ToUpper('a'), 'A');
+ BOOST_CHECK_EQUAL(ToUpper('z'), 'Z');
+ BOOST_CHECK_EQUAL(ToUpper('{'), '{');
+ BOOST_CHECK_EQUAL(ToUpper(0), 0);
+ BOOST_CHECK_EQUAL(ToUpper(255), 255);
+}
+
+BOOST_AUTO_TEST_CASE(test_Capitalize)
+{
+ BOOST_CHECK_EQUAL(Capitalize(""), "");
+ BOOST_CHECK_EQUAL(Capitalize("bitcoin"), "Bitcoin");
+ BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"), "\x00\xfe\xff");
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp
index 37c4f79133..4316f37999 100644
--- a/src/test/validation_block_tests.cpp
+++ b/src/test/validation_block_tests.cpp
@@ -23,7 +23,7 @@ BOOST_FIXTURE_TEST_SUITE(validation_block_tests, RegtestingSetup)
struct TestSubscriber : public CValidationInterface {
uint256 m_expected_tip;
- TestSubscriber(uint256 tip) : m_expected_tip(tip) {}
+ explicit TestSubscriber(uint256 tip) : m_expected_tip(tip) {}
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override
{
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 8bada4dce8..05217149e3 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -20,13 +20,10 @@
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
int64_t _nTime, unsigned int _entryHeight,
- bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
- tx(_tx), nFee(_nFee), nTime(_nTime), entryHeight(_entryHeight),
+ bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp)
+ : tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
{
- nTxWeight = GetTransactionWeight(*tx);
- nUsageSize = RecursiveDynamicUsage(tx);
-
nCountWithDescendants = 1;
nSizeWithDescendants = GetTxSize();
nModFeesWithDescendants = nFee;
@@ -355,7 +352,7 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n)
nTransactionsUpdated += n;
}
-void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
+void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
{
NotifyEntryAdded(entry.GetSharedTx());
// Add to memory pool without checking anything.
@@ -367,7 +364,7 @@ void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
// Update transaction for any feeDelta created by PrioritiseTransaction
// TODO: refactor so that the fee delta is calculated before inserting
// into mapTx.
- std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
+ std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(entry.GetTx().GetHash());
if (pos != mapDeltas.end()) {
const CAmount &delta = pos->second;
if (delta) {
@@ -640,8 +637,6 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
innerUsage += memusage::DynamicUsage(links.parents) + memusage::DynamicUsage(links.children);
bool fDependsWait = false;
setEntries setParentCheck;
- int64_t parentSizes = 0;
- int64_t parentSigOpCost = 0;
for (const CTxIn &txin : tx.vin) {
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
@@ -649,10 +644,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
const CTransaction& tx2 = it2->GetTx();
assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull());
fDependsWait = true;
- if (setParentCheck.insert(it2).second) {
- parentSizes += it2->GetTxSize();
- parentSigOpCost += it2->GetSigOpCost();
- }
+ setParentCheck.insert(it2);
} else {
assert(pcoins->HaveCoin(txin.prevout));
}
@@ -928,13 +920,13 @@ int CTxMemPool::Expire(int64_t time) {
return stage.size();
}
-void CTxMemPool::addUnchecked(const uint256&hash, const CTxMemPoolEntry &entry, bool validFeeEstimate)
+void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate)
{
setEntries setAncestors;
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
std::string dummy;
CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
- return addUnchecked(hash, entry, setAncestors, validFeeEstimate);
+ return addUnchecked(entry, setAncestors, validFeeEstimate);
}
void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add)
diff --git a/src/txmempool.h b/src/txmempool.h
index f8915cec31..2163b5eb21 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -65,14 +65,14 @@ class CTxMemPool;
class CTxMemPoolEntry
{
private:
- CTransactionRef tx;
- CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
- size_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
- size_t nUsageSize; //!< ... and total memory usage
- int64_t nTime; //!< Local time when entering the mempool
- unsigned int entryHeight; //!< Chain height when entering the mempool
- bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
- int64_t sigOpCost; //!< Total sigop cost
+ const CTransactionRef tx;
+ const CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
+ const size_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
+ const size_t nUsageSize; //!< ... and total memory usage
+ const int64_t nTime; //!< Local time when entering the mempool
+ const unsigned int entryHeight; //!< Chain height when entering the mempool
+ const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
+ const int64_t sigOpCost; //!< Total sigop cost
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
LockPoints lockPoints; //!< Track the height and time at which tx was final
@@ -540,8 +540,8 @@ public:
// Note that addUnchecked is ONLY called from ATMP outside of tests
// and any other callers may break wallet's in-mempool tracking (due to
// lack of CValidationInterface::TransactionAddedToMempool callbacks).
- void addUnchecked(const uint256& hash, const CTxMemPoolEntry& entry, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs);
- void addUnchecked(const uint256& hash, const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void addUnchecked(const CTxMemPoolEntry& entry, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void addUnchecked(const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs);
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
diff --git a/src/util.cpp b/src/util.cpp
index 1aab85264f..3bb52e9b3d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -71,7 +71,6 @@
#include <malloc.h>
#endif
-#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
@@ -139,7 +138,7 @@ instance_of_cinit;
* cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks
* is called.
*/
-static std::map<std::string, std::unique_ptr<boost::interprocess::file_lock>> dir_locks;
+static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks;
/** Mutex to protect dir_locks. */
static std::mutex cs_dir_locks;
@@ -156,18 +155,13 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
// Create empty lock file if it doesn't exist.
FILE* file = fsbridge::fopen(pathLockFile, "a");
if (file) fclose(file);
-
- try {
- auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str());
- if (!lock->try_lock()) {
- return false;
- }
- if (!probe_only) {
- // Lock successful and we're not just probing, put it into the map
- dir_locks.emplace(pathLockFile.string(), std::move(lock));
- }
- } catch (const boost::interprocess::interprocess_exception& e) {
- return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
+ auto lock = MakeUnique<fsbridge::FileLock>(pathLockFile);
+ if (!lock->TryLock()) {
+ return error("Error while attempting to lock directory %s: %s", directory.string(), lock->GetReason());
+ }
+ if (!probe_only) {
+ // Lock successful and we're not just probing, put it into the map
+ dir_locks.emplace(pathLockFile.string(), std::move(lock));
}
return true;
}
@@ -222,7 +216,7 @@ public:
/** Determine whether to use config settings in the default section,
* See also comments around ArgsManager::ArgsManager() below. */
- static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg)
+ static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
{
return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0);
}
@@ -301,7 +295,7 @@ public:
/* Special test for -testnet and -regtest args, because we
* don't want to be confused by craziness like "[regtest] testnet=1"
*/
- static inline bool GetNetBoolArg(const ArgsManager &am, const std::string& net_arg)
+ static inline bool GetNetBoolArg(const ArgsManager &am, const std::string& net_arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args)
{
std::pair<bool,std::string> found_result(false,std::string());
found_result = GetArgHelper(am.m_override_args, net_arg, true);
@@ -378,6 +372,8 @@ ArgsManager::ArgsManager() :
void ArgsManager::WarnForSectionOnlyArgs()
{
+ LOCK(cs_args);
+
// if there's no section selected, don't worry
if (m_network.empty()) return;
@@ -406,6 +402,7 @@ void ArgsManager::WarnForSectionOnlyArgs()
void ArgsManager::SelectConfigNetwork(const std::string& network)
{
+ LOCK(cs_args);
m_network = network;
}
@@ -474,6 +471,7 @@ bool ArgsManager::IsArgKnown(const std::string& key) const
arg_no_net = std::string("-") + key.substr(option_index + 1, std::string::npos);
}
+ LOCK(cs_args);
for (const auto& arg_map : m_available_args) {
if (arg_map.second.count(arg_no_net)) return true;
}
@@ -577,6 +575,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
eq_index = name.size();
}
+ LOCK(cs_args);
std::map<std::string, Arg>& arg_map = m_available_args[cat];
auto ret = arg_map.emplace(name.substr(0, eq_index), Arg(name.substr(eq_index, name.size() - eq_index), help, debug_only));
assert(ret.second); // Make sure an insertion actually happened
@@ -594,6 +593,7 @@ std::string ArgsManager::GetHelpMessage() const
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
std::string usage = "";
+ LOCK(cs_args);
for (const auto& arg_map : m_available_args) {
switch(arg_map.first) {
case OptionsCategory::OPTIONS:
@@ -886,7 +886,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
}
// if there is an -includeconf in the override args, but it is empty, that means the user
// passed '-noincludeconf' on the command line, in which case we should not include anything
- if (m_override_args.count("-includeconf") == 0) {
+ bool emptyIncludeConf;
+ {
+ LOCK(cs_args);
+ emptyIncludeConf = m_override_args.count("-includeconf") == 0;
+ }
+ if (emptyIncludeConf) {
std::string chain_id = GetChainName();
std::vector<std::string> includeconf(GetArgs("-includeconf"));
{
@@ -946,6 +951,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
std::string ArgsManager::GetChainName() const
{
+ LOCK(cs_args);
bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
diff --git a/src/util.h b/src/util.h
index e93489c1ed..7bf9fdbe12 100644
--- a/src/util.h
+++ b/src/util.h
@@ -142,11 +142,11 @@ protected:
};
mutable CCriticalSection cs_args;
- std::map<std::string, std::vector<std::string>> m_override_args;
- std::map<std::string, std::vector<std::string>> m_config_args;
- std::string m_network;
- std::set<std::string> m_network_only_args;
- std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args;
+ std::map<std::string, std::vector<std::string>> m_override_args GUARDED_BY(cs_args);
+ std::map<std::string, std::vector<std::string>> m_config_args GUARDED_BY(cs_args);
+ std::string m_network GUARDED_BY(cs_args);
+ std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
+ std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
bool ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys = false);
@@ -262,7 +262,10 @@ public:
/**
* Clear available arguments
*/
- void ClearArgs() { m_available_args.clear(); }
+ void ClearArgs() {
+ LOCK(cs_args);
+ m_available_args.clear();
+ }
/**
* Get the help string
diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp
index a06d88cb19..2326383586 100644
--- a/src/utilstrencodings.cpp
+++ b/src/utilstrencodings.cpp
@@ -7,6 +7,7 @@
#include <tinyformat.h>
+#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <errno.h>
@@ -544,3 +545,55 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
return true;
}
+bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
+{
+ std::stringstream ss(keypath_str);
+ std::string item;
+ bool first = true;
+ while (std::getline(ss, item, '/')) {
+ if (item.compare("m") == 0) {
+ if (first) {
+ first = false;
+ continue;
+ }
+ return false;
+ }
+ // Finds whether it is hardened
+ uint32_t path = 0;
+ size_t pos = item.find("'");
+ if (pos != std::string::npos) {
+ // The hardened tick can only be in the last index of the string
+ if (pos != item.size() - 1) {
+ return false;
+ }
+ path |= 0x80000000;
+ item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick
+ }
+
+ // Ensure this is only numbers
+ if (item.find_first_not_of( "0123456789" ) != std::string::npos) {
+ return false;
+ }
+ uint32_t number;
+ if (!ParseUInt32(item, &number)) {
+ return false;
+ }
+ path |= number;
+
+ keypath.push_back(path);
+ first = false;
+ }
+ return true;
+}
+
+void Downcase(std::string& str)
+{
+ std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){return ToLower(c);});
+}
+
+std::string Capitalize(std::string str)
+{
+ if (str.empty()) return str;
+ str[0] = ToUpper(str.front());
+ return str;
+}
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h
index 5f2211b5dc..846a3917a2 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -183,4 +183,51 @@ bool ConvertBits(const O& outfn, I it, I end) {
return true;
}
+/** Parse an HD keypaths like "m/7/0'/2000". */
+bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
+
+/**
+ * Converts the given character to its lowercase equivalent.
+ * This function is locale independent. It only converts uppercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in] c the character to convert to lowercase.
+ * @return the lowercase equivalent of c; or the argument
+ * if no conversion is possible.
+ */
+constexpr unsigned char ToLower(unsigned char c)
+{
+ return (c >= 'A' && c <= 'Z' ? (c - 'A') + 'a' : c);
+}
+
+/**
+ * Converts the given string to its lowercase equivalent.
+ * This function is locale independent. It only converts uppercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in,out] str the string to convert to lowercase.
+ */
+void Downcase(std::string& str);
+
+/**
+ * Converts the given character to its uppercase equivalent.
+ * This function is locale independent. It only converts lowercase
+ * characters in the standard 7-bit ASCII range.
+ * @param[in] c the character to convert to uppercase.
+ * @return the uppercase equivalent of c; or the argument
+ * if no conversion is possible.
+ */
+constexpr unsigned char ToUpper(unsigned char c)
+{
+ return (c >= 'a' && c <= 'z' ? (c - 'a') + 'A' : c);
+}
+
+/**
+ * Capitalizes the first character of the given string.
+ * This function is locale independent. It only capitalizes the
+ * first character of the argument if it has an uppercase equivalent
+ * in the standard 7-bit ASCII range.
+ * @param[in] str the string to capitalize.
+ * @return string with the first letter capitalized.
+ */
+std::string Capitalize(std::string str);
+
#endif // BITCOIN_UTILSTRENCODINGS_H
diff --git a/src/validation.cpp b/src/validation.cpp
index 3e51221a5e..f6257ffaed 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -959,7 +959,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
bool validForFeeEstimation = !fReplacementTransaction && !bypass_limits && IsCurrentForFeeEstimation() && pool.HasNoInputsOf(tx);
// Store transaction in memory
- pool.addUnchecked(hash, entry, setAncestors, validForFeeEstimation);
+ pool.addUnchecked(entry, setAncestors, validForFeeEstimation);
// trim mempool and check if tx was trimmed
if (!bypass_limits) {
@@ -2448,7 +2448,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
if (!rv) {
if (state.IsInvalid())
InvalidBlockFound(pindexNew, state);
- return error("ConnectTip(): ConnectBlock %s failed", pindexNew->GetBlockHash().ToString());
+ return error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), FormatStateMessage(state));
}
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * MILLI, nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal);
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index 2b8a0f6467..677bf74b5d 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -242,7 +242,7 @@ Result CommitTransaction(CWallet* wallet, const uint256& txid, CMutableTransacti
CReserveKey reservekey(wallet);
CValidationState state;
- if (!wallet->CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm, oldWtx.strFromAccount, reservekey, g_connman.get(), state)) {
+ if (!wallet->CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm, reservekey, g_connman.get(), state)) {
// NOTE: CommitTransaction never returns false, so this should never happen.
errors.push_back(strprintf("The transaction was rejected: %s", FormatStateMessage(state)));
return Result::WALLET_ERROR;
diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp
index b9f267210e..b36287ff50 100644
--- a/src/wallet/init.cpp
+++ b/src/wallet/init.cpp
@@ -78,7 +78,7 @@ void WalletInit::AddWalletOptions() const
gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)", false, OptionsCategory::WALLET);
gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), false, OptionsCategory::WALLET);
gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
- " (1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)", false, OptionsCategory::WALLET);
+ " (1 = keep tx meta data e.g. payment request information, 2 = drop tx meta data)", false, OptionsCategory::WALLET);
gArgs.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE), true, OptionsCategory::WALLET_DEBUG_TEST);
gArgs.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), true, OptionsCategory::WALLET_DEBUG_TEST);
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 7cb41da39e..60f14e5886 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -1150,7 +1150,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
" \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
" \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments\n"
" \"watchonly\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n"
- " \"label\": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false\n"
+ " \"label\": <label> , (string, optional, default: '') Label to assign to the address, only allowed with internal=false\n"
" }\n"
" ,...\n"
" ]\n"
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 79a99ade84..66ec070982 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -196,59 +196,6 @@ static UniValue getnewaddress(const JSONRPCRequest& request)
return EncodeDestination(dest);
}
-CTxDestination GetLabelDestination(CWallet* const pwallet, const std::string& label, bool bForceNew=false)
-{
- CTxDestination dest;
- if (!pwallet->GetLabelDestination(dest, label, bForceNew)) {
- throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
- }
-
- return dest;
-}
-
-static UniValue getaccountaddress(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("getaccountaddress (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
- if (request.fHelp || request.params.size() != 1)
- throw std::runtime_error(
- "getaccountaddress \"account\"\n"
- "\n\nDEPRECATED. Returns the current Bitcoin address for receiving payments to this account.\n"
- "\nArguments:\n"
- "1. \"account\" (string, required) The account for the address. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created and a new address created if there is no account by the given name.\n"
- "\nResult:\n"
- "\"address\" (string) The account bitcoin address\n"
- "\nExamples:\n"
- + HelpExampleCli("getaccountaddress", "")
- + HelpExampleCli("getaccountaddress", "\"\"")
- + HelpExampleCli("getaccountaddress", "\"myaccount\"")
- + HelpExampleRpc("getaccountaddress", "\"myaccount\"")
- );
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- // Parse the account first so we don't generate a key if there's an error
- std::string account = LabelFromValue(request.params[0]);
-
- UniValue ret(UniValue::VSTR);
-
- ret = EncodeDestination(GetLabelDestination(pwallet, account));
- return ret;
-}
-
-
static UniValue getrawchangeaddress(const JSONRPCRequest& request)
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -312,13 +259,6 @@ static UniValue setlabel(const JSONRPCRequest& request)
return NullUniValue;
}
- if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "setaccount") {
- if (request.fHelp) {
- throw std::runtime_error("setaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "setaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"setlabel \"address\" \"label\"\n"
@@ -343,126 +283,15 @@ static UniValue setlabel(const JSONRPCRequest& request)
if (IsMine(*pwallet, dest)) {
pwallet->SetAddressBook(dest, label, "receive");
- if (request.strMethod == "setaccount" && old_label != label && dest == GetLabelDestination(pwallet, old_label)) {
- // for setaccount, call GetLabelDestination so a new receive address is created for the old account
- GetLabelDestination(pwallet, old_label, true);
- }
} else {
pwallet->SetAddressBook(dest, label, "send");
}
- // Detect when there are no addresses using this label.
- // If so, delete the account record for it. Labels, unlike addresses, can be deleted,
- // and if we wouldn't do this, the record would stick around forever.
- bool found_address = false;
- for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->mapAddressBook) {
- if (item.second.name == label) {
- found_address = true;
- break;
- }
- }
- if (!found_address) {
- pwallet->DeleteLabel(old_label);
- }
-
return NullUniValue;
}
-static UniValue getaccount(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("getaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
- if (request.fHelp || request.params.size() != 1)
- throw std::runtime_error(
- "getaccount \"address\"\n"
- "\nDEPRECATED. Returns the account associated with the given address.\n"
- "\nArguments:\n"
- "1. \"address\" (string, required) The bitcoin address for account lookup.\n"
- "\nResult:\n"
- "\"accountname\" (string) the account address\n"
- "\nExamples:\n"
- + HelpExampleCli("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
- + HelpExampleRpc("getaccount", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")
- );
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- CTxDestination dest = DecodeDestination(request.params[0].get_str());
- if (!IsValidDestination(dest)) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
- }
-
- std::string strAccount;
- std::map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(dest);
- if (mi != pwallet->mapAddressBook.end() && !(*mi).second.name.empty()) {
- strAccount = (*mi).second.name;
- }
- return strAccount;
-}
-
-
-static UniValue getaddressesbyaccount(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("getaddressbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaddressesbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
- if (request.fHelp || request.params.size() != 1)
- throw std::runtime_error(
- "getaddressesbyaccount \"account\"\n"
- "\nDEPRECATED. Returns the list of addresses for the given account.\n"
- "\nArguments:\n"
- "1. \"account\" (string, required) The account name.\n"
- "\nResult:\n"
- "[ (json array of string)\n"
- " \"address\" (string) a bitcoin address associated with the given account\n"
- " ,...\n"
- "]\n"
- "\nExamples:\n"
- + HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
- + HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
- );
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- std::string strAccount = LabelFromValue(request.params[0]);
-
- // Find all addresses that have the given account
- UniValue ret(UniValue::VARR);
- for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->mapAddressBook) {
- const CTxDestination& dest = item.first;
- const std::string& strName = item.second.name;
- if (strName == strAccount) {
- ret.push_back(EncodeDestination(dest));
- }
- }
- return ret;
-}
-
-static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, const CCoinControl& coin_control, mapValue_t mapValue, std::string fromAccount)
+static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, const CCoinControl& coin_control, mapValue_t mapValue)
{
CAmount curBalance = pwallet->GetBalance();
@@ -495,7 +324,7 @@ static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
CValidationState state;
- if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, std::move(fromAccount), reservekey, g_connman.get(), state)) {
+ if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, reservekey, g_connman.get(), state)) {
strError = strprintf("Error: The transaction was rejected! Reason given: %s", FormatStateMessage(state));
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
@@ -587,7 +416,7 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
EnsureWalletIsUnlocked(pwallet);
- CTransactionRef tx = SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, coin_control, std::move(mapValue), {} /* fromAccount */);
+ CTransactionRef tx = SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, coin_control, std::move(mapValue));
return tx->GetHash().GetHex();
}
@@ -789,13 +618,6 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
return NullUniValue;
}
- if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getreceivedbyaccount") {
- if (request.fHelp) {
- throw std::runtime_error("getreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "getreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"getreceivedbylabel \"label\" ( minconf )\n"
@@ -863,41 +685,16 @@ static UniValue getbalance(const JSONRPCRequest& request)
if (request.fHelp || (request.params.size() > 3 ))
throw std::runtime_error(
- (IsDeprecatedRPCEnabled("accounts") ? std::string(
- "getbalance ( \"account\" minconf include_watchonly )\n"
- "\nIf account is not specified, returns the server's total available balance.\n"
- "The available balance is what the wallet considers currently spendable, and is\n"
- "thus affected by options which limit spendability such as -spendzeroconfchange.\n"
- "If account is specified (DEPRECATED), returns the balance in the account.\n"
- "Note that the account \"\" is not the same as leaving the parameter out.\n"
- "The server total may be different to the balance in the default \"\" account.\n"
- "\nArguments:\n"
- "1. \"account\" (string, optional) DEPRECATED. This argument will be removed in V0.18. \n"
- " To use this deprecated argument, start bitcoind with -deprecatedrpc=accounts. The account string may be given as a\n"
- " specific account name to find the balance associated with wallet keys in\n"
- " a named account, or as the empty string (\"\") to find the balance\n"
- " associated with wallet keys not in any named account, or as \"*\" to find\n"
- " the balance associated with all wallet keys regardless of account.\n"
- " When this option is specified, it calculates the balance in a different\n"
- " way than when it is not specified, and which can count spends twice when\n"
- " there are conflicting pending transactions (such as those created by\n"
- " the bumpfee command), temporarily resulting in low or even negative\n"
- " balances. In general, account balance calculation is not considered\n"
- " reliable and has resulted in confusing outcomes, so it is recommended to\n"
- " avoid passing this argument.\n"
- "2. minconf (numeric, optional) Only include transactions confirmed at least this many times. \n"
- " The default is 1 if an account is provided or 0 if no account is provided\n")
- : std::string(
"getbalance ( \"(dummy)\" minconf include_watchonly )\n"
"\nReturns the total available balance.\n"
"The available balance is what the wallet considers currently spendable, and is\n"
"thus affected by options which limit spendability such as -spendzeroconfchange.\n"
"\nArguments:\n"
"1. (dummy) (string, optional) Remains for backward compatibility. Must be excluded or set to \"*\".\n"
- "2. minconf (numeric, optional, default=0) Only include transactions confirmed at least this many times.\n")) +
+ "2. minconf (numeric, optional, default=0) Only include transactions confirmed at least this many times.\n"
"3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')\n"
"\nResult:\n"
- "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
+ "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this wallet.\n"
"\nExamples:\n"
"\nThe total amount in the wallet with 1 or more confirmations\n"
+ HelpExampleCli("getbalance", "") +
@@ -913,13 +710,12 @@ static UniValue getbalance(const JSONRPCRequest& request)
LOCK2(cs_main, pwallet->cs_wallet);
- const UniValue& account_value = request.params[0];
+ const UniValue& dummy_value = request.params[0];
+ if (!dummy_value.isNull() && dummy_value.get_str() != "*") {
+ throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
+ }
int min_depth = 0;
- if (IsDeprecatedRPCEnabled("accounts") && !account_value.isNull()) {
- // Default min_depth to 1 when an account is provided.
- min_depth = 1;
- }
if (!request.params[1].isNull()) {
min_depth = request.params[1].get_int();
}
@@ -929,18 +725,6 @@ static UniValue getbalance(const JSONRPCRequest& request)
filter = filter | ISMINE_WATCH_ONLY;
}
- if (!account_value.isNull()) {
-
- const std::string& account_param = account_value.get_str();
- const std::string* account = account_param != "*" ? &account_param : nullptr;
-
- if (!IsDeprecatedRPCEnabled("accounts") && account_param != "*") {
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "dummy first argument must be excluded or set to \"*\".");
- } else if (IsDeprecatedRPCEnabled("accounts")) {
- return ValueFromAmount(pwallet->GetLegacyBalance(filter, min_depth, account));
- }
- }
-
return ValueFromAmount(pwallet->GetBalance(filter, min_depth));
}
@@ -968,148 +752,6 @@ static UniValue getunconfirmedbalance(const JSONRPCRequest &request)
}
-static UniValue movecmd(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("move (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "move is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
- if (request.fHelp || request.params.size() < 3 || request.params.size() > 5)
- throw std::runtime_error(
- "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
- "\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
- "\nArguments:\n"
- "1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
- "2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
- "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n"
- "4. (dummy) (numeric, optional) Ignored. Remains for backward compatibility.\n"
- "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
- "\nResult:\n"
- "true|false (boolean) true if successful.\n"
- "\nExamples:\n"
- "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n"
- + HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
- "\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n"
- + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
- "\nAs a json rpc call\n"
- + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
- );
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- std::string strFrom = LabelFromValue(request.params[0]);
- std::string strTo = LabelFromValue(request.params[1]);
- CAmount nAmount = AmountFromValue(request.params[2]);
- if (nAmount <= 0)
- throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
- if (!request.params[3].isNull())
- // unused parameter, used to be nMinDepth, keep type-checking it though
- (void)request.params[3].get_int();
- std::string strComment;
- if (!request.params[4].isNull())
- strComment = request.params[4].get_str();
-
- if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) {
- throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
- }
-
- return true;
-}
-
-
-static UniValue sendfrom(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("sendfrom (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "sendfrom is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
-
- if (request.fHelp || request.params.size() < 3 || request.params.size() > 6)
- throw std::runtime_error(
- "sendfrom \"fromaccount\" \"toaddress\" amount ( minconf \"comment\" \"comment_to\" )\n"
- "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a bitcoin address."
- + HelpRequiringPassphrase(pwallet) + "\n"
- "\nArguments:\n"
- "1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
- " Specifying an account does not influence coin selection, but it does associate the newly created\n"
- " transaction with the account, so the account's balance computation and transaction history can reflect\n"
- " the spend.\n"
- "2. \"toaddress\" (string, required) The bitcoin address to send funds to.\n"
- "3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n"
- "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
- "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
- " This is not part of the transaction, just kept in your wallet.\n"
- "6. \"comment_to\" (string, optional) An optional comment to store the name of the person or organization \n"
- " to which you're sending the transaction. This is not part of the transaction, \n"
- " it is just kept in your wallet.\n"
- "\nResult:\n"
- "\"txid\" (string) The transaction id.\n"
- "\nExamples:\n"
- "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n"
- + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") +
- "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
- + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") +
- "\nAs a json rpc call\n"
- + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"")
- );
-
- // Make sure the results are valid at least up to the most recent block
- // the user could have gotten from another RPC command prior to now
- pwallet->BlockUntilSyncedToCurrentChain();
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- std::string strAccount = LabelFromValue(request.params[0]);
- CTxDestination dest = DecodeDestination(request.params[1].get_str());
- if (!IsValidDestination(dest)) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
- }
- CAmount nAmount = AmountFromValue(request.params[2]);
- if (nAmount <= 0)
- throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
- int nMinDepth = 1;
- if (!request.params[3].isNull())
- nMinDepth = request.params[3].get_int();
-
- mapValue_t mapValue;
- if (!request.params[4].isNull() && !request.params[4].get_str().empty())
- mapValue["comment"] = request.params[4].get_str();
- if (!request.params[5].isNull() && !request.params[5].get_str().empty())
- mapValue["to"] = request.params[5].get_str();
-
- EnsureWalletIsUnlocked(pwallet);
-
- // Check funds
- CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
- if (nAmount > nBalance)
- throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
-
- CCoinControl no_coin_control; // This is a deprecated API
- CTransactionRef tx = SendMoney(pwallet, dest, nAmount, false, no_coin_control, std::move(mapValue), std::move(strAccount));
- return tx->GetHash().GetHex();
-}
-
-
static UniValue sendmany(const JSONRPCRequest& request)
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -1119,12 +761,10 @@ static UniValue sendmany(const JSONRPCRequest& request)
return NullUniValue;
}
- std::string help_text;
- if (!IsDeprecatedRPCEnabled("accounts")) {
- help_text = "sendmany \"\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] replaceable conf_target \"estimate_mode\")\n"
+ if (request.fHelp || request.params.size() < 2 || request.params.size() > 8)
+ throw std::runtime_error(
+ "sendmany \"\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] replaceable conf_target \"estimate_mode\")\n"
"\nSend multiple times. Amounts are double-precision floating point numbers.\n"
- "Note that the \"fromaccount\" argument has been removed in V0.17. To use this RPC with a \"fromaccount\" argument, restart\n"
- "bitcoind with -deprecatedrpc=accounts\n"
+ HelpRequiringPassphrase(pwallet) + "\n"
"\nArguments:\n"
"1. \"dummy\" (string, required) Must be set to \"\" for backwards compatibility.\n"
@@ -1160,49 +800,8 @@ static UniValue sendmany(const JSONRPCRequest& request)
"\nSend two amounts to two different addresses, subtract fee from amount:\n"
+ HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\",\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") +
"\nAs a json rpc call\n"
- + HelpExampleRpc("sendmany", "\"\", {\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}, 6, \"testing\"");
- } else {
- help_text = "sendmany \"\" \"fromaccount\" {\"address\":amount,...} ( minconf \"comment\" [\"address\",...] replaceable conf_target \"estimate_mode\")\n"
- "\nSend multiple times. Amounts are double-precision floating point numbers."
- + HelpRequiringPassphrase(pwallet) + "\n"
- "\nArguments:\n"
- "1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
- "2. \"amounts\" (string, required) A json object with addresses and amounts\n"
- " {\n"
- " \"address\":amount (numeric or string) The bitcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n"
- " ,...\n"
- " }\n"
- "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
- "4. \"comment\" (string, optional) A comment\n"
- "5. subtractfeefrom (array, optional) A json array with addresses.\n"
- " The fee will be equally deducted from the amount of each selected address.\n"
- " Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
- " If no addresses are specified here, the sender pays the fee.\n"
- " [\n"
- " \"address\" (string) Subtract fee from this address\n"
- " ,...\n"
- " ]\n"
- "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
- "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
- "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
- " \"UNSET\"\n"
- " \"ECONOMICAL\"\n"
- " \"CONSERVATIVE\"\n"
- "\nResult:\n"
- "\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
- " the number of addresses.\n"
- "\nExamples:\n"
- "\nSend two amounts to two different addresses:\n"
- + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") +
- "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
- + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") +
- "\nSend two amounts to two different addresses, subtract fee from amount:\n"
- + HelpExampleCli("sendmany", "\"\" \"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01,\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\",\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") +
- "\nAs a json rpc call\n"
- + HelpExampleRpc("sendmany", "\"\", {\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}, 6, \"testing\"");
- }
-
- if (request.fHelp || request.params.size() < 2 || request.params.size() > 8) throw std::runtime_error(help_text);
+ + HelpExampleRpc("sendmany", "\"\", {\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}, 6, \"testing\"")
+ );
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
@@ -1214,10 +813,9 @@ static UniValue sendmany(const JSONRPCRequest& request)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
}
- if (!IsDeprecatedRPCEnabled("accounts") && !request.params[0].get_str().empty()) {
+ if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
}
- std::string strAccount = LabelFromValue(request.params[0]);
UniValue sendTo = request.params[1].get_obj();
int nMinDepth = 1;
if (!request.params[2].isNull())
@@ -1282,9 +880,7 @@ static UniValue sendmany(const JSONRPCRequest& request)
EnsureWalletIsUnlocked(pwallet);
// Check funds
- if (IsDeprecatedRPCEnabled("accounts") && totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount)) {
- throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
- } else if (!IsDeprecatedRPCEnabled("accounts") && totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, nullptr)) {
+ if (totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth)) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Wallet has insufficient funds");
}
@@ -1301,7 +897,7 @@ static UniValue sendmany(const JSONRPCRequest& request)
if (!fCreated)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
CValidationState state;
- if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, std::move(strAccount), keyChange, g_connman.get(), state)) {
+ if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, keyChange, g_connman.get(), state)) {
strFailReason = strprintf("Transaction commit failed:: %s", FormatStateMessage(state));
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
}
@@ -1635,7 +1231,6 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
if(fIsWatchonly)
obj.pushKV("involvesWatchonly", true);
obj.pushKV("address", EncodeDestination(address));
- obj.pushKV("account", label);
obj.pushKV("amount", ValueFromAmount(nAmount));
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
obj.pushKV("label", label);
@@ -1661,7 +1256,6 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
UniValue obj(UniValue::VOBJ);
if (entry.second.fIsWatchonly)
obj.pushKV("involvesWatchonly", true);
- obj.pushKV("account", entry.first);
obj.pushKV("amount", ValueFromAmount(nAmount));
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
obj.pushKV("label", entry.first);
@@ -1695,7 +1289,6 @@ static UniValue listreceivedbyaddress(const JSONRPCRequest& request)
" {\n"
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
- " \"account\" : \"accountname\", (string) DEPRECATED. Backwards compatible alias for label.\n"
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n"
" \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
" \"label\" : \"label\", (string) The label of the receiving address. The default label is \"\".\n"
@@ -1732,13 +1325,6 @@ static UniValue listreceivedbylabel(const JSONRPCRequest& request)
return NullUniValue;
}
- if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "listreceivedbyaccount") {
- if (request.fHelp) {
- throw std::runtime_error("listreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "listreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
if (request.fHelp || request.params.size() > 3)
throw std::runtime_error(
"listreceivedbylabel ( minconf include_empty include_watchonly)\n"
@@ -1752,7 +1338,6 @@ static UniValue listreceivedbylabel(const JSONRPCRequest& request)
"[\n"
" {\n"
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
- " \"account\" : \"accountname\", (string) DEPRECATED. Backwards compatible alias for label.\n"
" \"amount\" : x.xxx, (numeric) The total amount received by addresses with this label\n"
" \"confirmations\" : n, (numeric) The number of confirmations of the most recent transaction included\n"
" \"label\" : \"label\" (string) The label of the receiving address. The default label is \"\".\n"
@@ -1787,26 +1372,23 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
*
* @param pwallet The wallet.
* @param wtx The wallet transaction.
- * @param strAccount The account, if any, or "*" for all.
* @param nMinDepth The minimum confirmation depth.
* @param fLong Whether to include the JSON version of the transaction.
* @param ret The UniValue into which the result is stored.
* @param filter The "is mine" filter bool.
*/
-static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
+static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
CAmount nFee;
- std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
- wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
+ wtx.GetAmounts(listReceived, listSent, nFee, filter);
- bool fAllAccounts = (strAccount == std::string("*"));
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
// Sent
- if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
+ if ((!listSent.empty() || nFee != 0))
{
for (const COutputEntry& s : listSent)
{
@@ -1814,7 +1396,6 @@ static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const
if (involvesWatchonly || (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) {
entry.pushKV("involvesWatchonly", true);
}
- if (IsDeprecatedRPCEnabled("accounts")) entry.pushKV("account", strSentAccount);
MaybePushAddress(entry, s.destination);
entry.pushKV("category", "send");
entry.pushKV("amount", ValueFromAmount(-s.amount));
@@ -1835,61 +1416,40 @@ static void ListTransactions(CWallet* const pwallet, const CWalletTx& wtx, const
{
for (const COutputEntry& r : listReceived)
{
- std::string account;
+ std::string label;
if (pwallet->mapAddressBook.count(r.destination)) {
- account = pwallet->mapAddressBook[r.destination].name;
+ label = pwallet->mapAddressBook[r.destination].name;
}
- if (fAllAccounts || (account == strAccount))
+ UniValue entry(UniValue::VOBJ);
+ if (involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) {
+ entry.pushKV("involvesWatchonly", true);
+ }
+ MaybePushAddress(entry, r.destination);
+ if (wtx.IsCoinBase())
{
- UniValue entry(UniValue::VOBJ);
- if (involvesWatchonly || (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) {
- entry.pushKV("involvesWatchonly", true);
- }
- if (IsDeprecatedRPCEnabled("accounts")) entry.pushKV("account", account);
- MaybePushAddress(entry, r.destination);
- if (wtx.IsCoinBase())
- {
- if (wtx.GetDepthInMainChain() < 1)
- entry.pushKV("category", "orphan");
- else if (wtx.IsImmatureCoinBase())
- entry.pushKV("category", "immature");
- else
- entry.pushKV("category", "generate");
- }
+ if (wtx.GetDepthInMainChain() < 1)
+ entry.pushKV("category", "orphan");
+ else if (wtx.IsImmatureCoinBase())
+ entry.pushKV("category", "immature");
else
- {
- entry.pushKV("category", "receive");
- }
- entry.pushKV("amount", ValueFromAmount(r.amount));
- if (pwallet->mapAddressBook.count(r.destination)) {
- entry.pushKV("label", account);
- }
- entry.pushKV("vout", r.vout);
- if (fLong)
- WalletTxToJSON(wtx, entry);
- ret.push_back(entry);
+ entry.pushKV("category", "generate");
+ }
+ else
+ {
+ entry.pushKV("category", "receive");
+ }
+ entry.pushKV("amount", ValueFromAmount(r.amount));
+ if (pwallet->mapAddressBook.count(r.destination)) {
+ entry.pushKV("label", label);
}
+ entry.pushKV("vout", r.vout);
+ if (fLong)
+ WalletTxToJSON(wtx, entry);
+ ret.push_back(entry);
}
}
}
-static void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccount, UniValue& ret)
-{
- bool fAllAccounts = (strAccount == std::string("*"));
-
- if (fAllAccounts || acentry.strAccount == strAccount)
- {
- UniValue entry(UniValue::VOBJ);
- entry.pushKV("account", acentry.strAccount);
- entry.pushKV("category", "move");
- entry.pushKV("time", acentry.nTime);
- entry.pushKV("amount", ValueFromAmount(acentry.nCreditDebit));
- if (IsDeprecatedRPCEnabled("accounts")) entry.pushKV("otheraccount", acentry.strOtherAccount);
- entry.pushKV("comment", acentry.strComment);
- ret.push_back(entry);
- }
-}
-
UniValue listtransactions(const JSONRPCRequest& request)
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -1899,12 +1459,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
return NullUniValue;
}
- std::string help_text {};
- if (!IsDeprecatedRPCEnabled("accounts")) {
- help_text = "listtransactions (dummy count skip include_watchonly)\n"
- "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
- "Note that the \"account\" argument and \"otheraccount\" return value have been removed in V0.17. To use this RPC with an \"account\" argument, restart\n"
- "bitcoind with -deprecatedrpc=accounts\n"
+ if (request.fHelp || request.params.size() > 4)
+ throw std::runtime_error(
+ "listtransactions (dummy count skip include_watchonly)\n"
+ "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions.\n"
"\nArguments:\n"
"1. \"dummy\" (string, optional) If set, should be \"*\" for backwards compatibility.\n"
"2. count (numeric, optional, default=10) The number of transactions to return\n"
@@ -1944,77 +1502,15 @@ UniValue listtransactions(const JSONRPCRequest& request)
"\nList transactions 100 to 120\n"
+ HelpExampleCli("listtransactions", "\"*\" 20 100") +
"\nAs a json rpc call\n"
- + HelpExampleRpc("listtransactions", "\"*\", 20, 100");
- } else {
- help_text = "listtransactions ( \"account\" count skip include_watchonly)\n"
- "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
- "\nArguments:\n"
- "1. \"account\" (string, optional) DEPRECATED. This argument will be removed in V0.18. The account name. Should be \"*\".\n"
- "2. count (numeric, optional, default=10) The number of transactions to return\n"
- "3. skip (numeric, optional, default=0) The number of transactions to skip\n"
- "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
- "\nResult:\n"
- "[\n"
- " {\n"
- " \"account\":\"accountname\", (string) DEPRECATED. This field will be removed in V0.18. The account name associated with the transaction. \n"
- " It will be \"\" for the default account.\n"
- " \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for \n"
- " move transactions (category = move).\n"
- " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
- " transaction between accounts, and not associated with an address,\n"
- " transaction id or block. 'send' and 'receive' transactions are \n"
- " associated with an address, transaction id and block details\n"
- " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n"
- " 'move' category for moves outbound. It is positive for the 'receive' category,\n"
- " and for the 'move' category for inbound funds.\n"
- " \"label\": \"label\", (string) A comment for the address/transaction, if any\n"
- " \"vout\": n, (numeric) the vout value\n"
- " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
- " 'send' category of transactions.\n"
- " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n"
- " 'receive' category of transactions. Negative confirmations indicate the\n"
- " transaction conflicts with the block chain\n"
- " \"trusted\": xxx, (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
- " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
- " category of transactions.\n"
- " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n"
- " category of transactions.\n"
- " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
- " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
- " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
- " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
- " for 'send' and 'receive' category of transactions.\n"
- " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
- " \"otheraccount\": \"accountname\", (string) DEPRECATED. This field will be removed in V0.18. For the 'move' category of transactions, the account the funds came \n"
- " from (for receiving funds, positive amounts), or went to (for sending funds,\n"
- " negative amounts).\n"
- " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
- " may be unknown for unconfirmed transactions not in the mempool\n"
- " \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
- " 'send' category of transactions.\n"
- " }\n"
- "]\n"
-
- "\nExamples:\n"
- "\nList the most recent 10 transactions in the systems\n"
- + HelpExampleCli("listtransactions", "") +
- "\nList transactions 100 to 120\n"
- + HelpExampleCli("listtransactions", "\"*\" 20 100") +
- "\nAs a json rpc call\n"
- + HelpExampleRpc("listtransactions", "\"*\", 20, 100");
- }
- if (request.fHelp || request.params.size() > 4) throw std::runtime_error(help_text);
+ + HelpExampleRpc("listtransactions", "\"*\", 20, 100")
+ );
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- std::string strAccount = "*";
- if (!request.params[0].isNull()) {
- strAccount = request.params[0].get_str();
- if (!IsDeprecatedRPCEnabled("accounts") && strAccount != "*") {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"*\"");
- }
+ if (!request.params[0].isNull() && request.params[0].get_str() != "*") {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"*\"");
}
int nCount = 10;
if (!request.params[1].isNull())
@@ -2042,14 +1538,8 @@ UniValue listtransactions(const JSONRPCRequest& request)
// iterate backwards until we have nCount items to return:
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{
- CWalletTx *const pwtx = (*it).second.first;
- if (pwtx != nullptr)
- ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
- if (IsDeprecatedRPCEnabled("accounts")) {
- CAccountingEntry *const pacentry = (*it).second.second;
- if (pacentry != nullptr) AcentryToJSON(*pacentry, strAccount, ret);
- }
-
+ CWalletTx *const pwtx = (*it).second;
+ ListTransactions(pwallet, *pwtx, 0, true, ret, filter);
if ((int)ret.size() >= (nCount+nFrom)) break;
}
}
@@ -2080,101 +1570,6 @@ UniValue listtransactions(const JSONRPCRequest& request)
return ret;
}
-static UniValue listaccounts(const JSONRPCRequest& request)
-{
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
- CWallet* const pwallet = wallet.get();
-
- if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
- return NullUniValue;
- }
-
- if (!IsDeprecatedRPCEnabled("accounts")) {
- if (request.fHelp) {
- throw std::runtime_error("listaccounts (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
- }
- throw JSONRPCError(RPC_METHOD_DEPRECATED, "listaccounts is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
- }
-
- if (request.fHelp || request.params.size() > 2)
- throw std::runtime_error(
- "listaccounts ( minconf include_watchonly)\n"
- "\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
- "\nArguments:\n"
- "1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
- "2. include_watchonly (bool, optional, default=false) Include balances in watch-only addresses (see 'importaddress')\n"
- "\nResult:\n"
- "{ (json object where keys are account names, and values are numeric balances\n"
- " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
- " ...\n"
- "}\n"
- "\nExamples:\n"
- "\nList account balances where there at least 1 confirmation\n"
- + HelpExampleCli("listaccounts", "") +
- "\nList account balances including zero confirmation transactions\n"
- + HelpExampleCli("listaccounts", "0") +
- "\nList account balances for 6 or more confirmations\n"
- + HelpExampleCli("listaccounts", "6") +
- "\nAs json rpc call\n"
- + HelpExampleRpc("listaccounts", "6")
- );
-
- // Make sure the results are valid at least up to the most recent block
- // the user could have gotten from another RPC command prior to now
- pwallet->BlockUntilSyncedToCurrentChain();
-
- LOCK2(cs_main, pwallet->cs_wallet);
-
- int nMinDepth = 1;
- if (!request.params[0].isNull())
- nMinDepth = request.params[0].get_int();
- isminefilter includeWatchonly = ISMINE_SPENDABLE;
- if(!request.params[1].isNull())
- if(request.params[1].get_bool())
- includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
-
- std::map<std::string, CAmount> mapAccountBalances;
- for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->mapAddressBook) {
- if (IsMine(*pwallet, entry.first) & includeWatchonly) { // This address belongs to me
- mapAccountBalances[entry.second.name] = 0;
- }
- }
-
- for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
- const CWalletTx& wtx = pairWtx.second;
- CAmount nFee;
- std::string strSentAccount;
- std::list<COutputEntry> listReceived;
- std::list<COutputEntry> listSent;
- int nDepth = wtx.GetDepthInMainChain();
- if (wtx.IsImmatureCoinBase() || nDepth < 0)
- continue;
- wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
- mapAccountBalances[strSentAccount] -= nFee;
- for (const COutputEntry& s : listSent)
- mapAccountBalances[strSentAccount] -= s.amount;
- if (nDepth >= nMinDepth)
- {
- for (const COutputEntry& r : listReceived)
- if (pwallet->mapAddressBook.count(r.destination)) {
- mapAccountBalances[pwallet->mapAddressBook[r.destination].name] += r.amount;
- }
- else
- mapAccountBalances[""] += r.amount;
- }
- }
-
- const std::list<CAccountingEntry>& acentries = pwallet->laccentries;
- for (const CAccountingEntry& entry : acentries)
- mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
-
- UniValue ret(UniValue::VOBJ);
- for (const std::pair<const std::string, CAmount>& accountBalance : mapAccountBalances) {
- ret.pushKV(accountBalance.first, ValueFromAmount(accountBalance.second));
- }
- return ret;
-}
-
static UniValue listsinceblock(const JSONRPCRequest& request)
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -2199,7 +1594,6 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
"\nResult:\n"
"{\n"
" \"transactions\": [\n"
- " \"account\":\"accountname\", (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account name associated with the transaction. Will be \"\" for the default account.\n"
" \"address\":\"address\", (string) The bitcoin address of the transaction. Not present for move transactions (category = move).\n"
" \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
" \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n"
@@ -2282,7 +1676,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
CWalletTx tx = pairWtx.second;
if (depth == -1 || tx.GetDepthInMainChain() < depth) {
- ListTransactions(pwallet, tx, "*", 0, true, transactions, filter);
+ ListTransactions(pwallet, tx, 0, true, transactions, filter);
}
}
@@ -2299,7 +1693,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
if (it != pwallet->mapWallet.end()) {
// We want all transactions regardless of confirmation count to appear here,
// even negative confirmation ones, hence the big negative.
- ListTransactions(pwallet, it->second, "*", -100000000, true, removed, filter);
+ ListTransactions(pwallet, it->second, -100000000, true, removed, filter);
}
}
paltindex = paltindex->pprev;
@@ -2348,7 +1742,6 @@ static UniValue gettransaction(const JSONRPCRequest& request)
" may be unknown for unconfirmed transactions not in the mempool\n"
" \"details\" : [\n"
" {\n"
- " \"account\" : \"accountname\", (string) DEPRECATED. This field will be removed in a V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account name involved in the transaction, can be \"\" for the default account.\n"
" \"address\" : \"address\", (string) The bitcoin address involved in the transaction\n"
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
" \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n"
@@ -2403,7 +1796,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
WalletTxToJSON(wtx, entry);
UniValue details(UniValue::VARR);
- ListTransactions(pwallet, wtx, "*", 0, false, details, filter);
+ ListTransactions(pwallet, wtx, 0, false, details, filter);
entry.pushKV("details", details);
std::string strHex = EncodeHexTx(*wtx.tx, RPCSerializationFlags());
@@ -3326,7 +2719,6 @@ static UniValue listunspent(const JSONRPCRequest& request)
" \"vout\" : n, (numeric) the vout value\n"
" \"address\" : \"address\", (string) the bitcoin address\n"
" \"label\" : \"label\", (string) The associated label, or \"\" for the default label\n"
- " \"account\" : \"account\", (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The associated account, or \"\" for the default account\n"
" \"scriptPubKey\" : \"key\", (string) the script key\n"
" \"amount\" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
@@ -3434,9 +2826,6 @@ static UniValue listunspent(const JSONRPCRequest& request)
auto i = pwallet->mapAddressBook.find(address);
if (i != pwallet->mapAddressBook.end()) {
entry.pushKV("label", i->second.name);
- if (IsDeprecatedRPCEnabled("accounts")) {
- entry.pushKV("account", i->second.name);
- }
}
if (scriptPubKey.IsPayToScriptHash()) {
@@ -4175,10 +3564,9 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
" ]\n"
" \"sigsrequired\" : xxxxx (numeric, optional) Number of signatures required to spend multisig output (only if \"script\" is \"multisig\")\n"
" \"pubkey\" : \"publickeyhex\", (string, optional) The hex value of the raw public key, for single-key addresses (possibly embedded in P2SH or P2WSH)\n"
- " \"embedded\" : {...}, (object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known. It includes all getaddressinfo output fields for the embedded address, excluding metadata (\"timestamp\", \"hdkeypath\", \"hdseedid\") and relation to the wallet (\"ismine\", \"iswatchonly\", \"account\").\n"
+ " \"embedded\" : {...}, (object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known. It includes all getaddressinfo output fields for the embedded address, excluding metadata (\"timestamp\", \"hdkeypath\", \"hdseedid\") and relation to the wallet (\"ismine\", \"iswatchonly\").\n"
" \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
- " \"label\" : \"label\" (string) The label associated with the address, \"\" is the default account\n"
- " \"account\" : \"account\" (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account associated with the address, \"\" is the default account\n"
+ " \"label\" : \"label\" (string) The label associated with the address, \"\" is the default label\n"
" \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD seed\n"
@@ -4220,9 +3608,6 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
ret.pushKVs(detail);
if (pwallet->mapAddressBook.count(dest)) {
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
- if (IsDeprecatedRPCEnabled("accounts")) {
- ret.pushKV("account", pwallet->mapAddressBook[dest].name);
- }
}
const CKeyMetadata* meta = nullptr;
CKeyID key_id = GetKeyForDestination(*pwallet, dest);
@@ -4430,74 +3815,17 @@ UniValue sethdseed(const JSONRPCRequest& request)
return NullUniValue;
}
-bool ParseHDKeypath(std::string keypath_str, std::vector<uint32_t>& keypath)
-{
- std::stringstream ss(keypath_str);
- std::string item;
- bool first = true;
- while (std::getline(ss, item, '/')) {
- if (item.compare("m") == 0) {
- if (first) {
- first = false;
- continue;
- }
- return false;
- }
- // Finds whether it is hardened
- uint32_t path = 0;
- size_t pos = item.find("'");
- if (pos != std::string::npos) {
- // The hardened tick can only be in the last index of the string
- if (pos != item.size() - 1) {
- return false;
- }
- path |= 0x80000000;
- item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick
- }
-
- // Ensure this is only numbers
- if (item.find_first_not_of( "0123456789" ) != std::string::npos) {
- return false;
- }
- uint32_t number;
- if (!ParseUInt32(item, &number)) {
- return false;
- }
- path |= number;
-
- keypath.push_back(path);
- first = false;
- }
- return true;
-}
-
-void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubKey, std::vector<uint32_t>>& hd_keypaths)
+void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubKey, KeyOriginInfo>& hd_keypaths)
{
CPubKey vchPubKey;
if (!pwallet->GetPubKey(keyID, vchPubKey)) {
return;
}
- CKeyMetadata meta;
- auto it = pwallet->mapKeyMetadata.find(keyID);
- if (it != pwallet->mapKeyMetadata.end()) {
- meta = it->second;
+ KeyOriginInfo info;
+ if (!pwallet->GetKeyOrigin(keyID, info)) {
+ throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal keypath is broken");
}
- std::vector<uint32_t> keypath;
- if (!meta.hdKeypath.empty()) {
- if (!ParseHDKeypath(meta.hdKeypath, keypath)) {
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal keypath is broken");
- }
- // Get the proper master key id
- CKey key;
- pwallet->GetKey(meta.hd_seed_id, key);
- CExtKey masterKey;
- masterKey.SetSeed(key.begin(), key.size());
- // Add to map
- keypath.insert(keypath.begin(), ReadLE32(masterKey.key.GetPubKey().GetID().begin()));
- } else { // Single pubkeys get the master fingerprint of themselves
- keypath.insert(keypath.begin(), ReadLE32(vchPubKey.GetID().begin()));
- }
- hd_keypaths.emplace(vchPubKey, keypath);
+ hd_keypaths.emplace(vchPubKey, std::move(info));
}
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const CTransaction* txConst, int sighash_type, bool sign, bool bip32derivs)
@@ -4525,28 +3853,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Specified Sighash and sighash in PSBT do not match.");
}
- SignatureData sigdata;
- if (sign) {
- complete &= SignPSBTInput(*pwallet, *psbtx.tx, input, sigdata, i, sighash_type);
- } else {
- complete &= SignPSBTInput(PublicOnlySigningProvider(pwallet), *psbtx.tx, input, sigdata, i, sighash_type);
- }
-
- if (it != pwallet->mapWallet.end()) {
- // Drop the unnecessary UTXO if we added both from the wallet.
- if (sigdata.witness) {
- input.non_witness_utxo = nullptr;
- } else {
- input.witness_utxo.SetNull();
- }
- }
-
- // Get public key paths
- if (bip32derivs) {
- for (const auto& pubkey_it : sigdata.misc_pubkeys) {
- AddKeypathToMap(pwallet, pubkey_it.first, input.hd_keypaths);
- }
- }
+ complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, i, sighash_type);
}
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
@@ -4559,15 +3866,8 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
psbt_out.FillSignatureData(sigdata);
MutableTransactionSignatureCreator creator(psbtx.tx.get_ptr(), 0, out.nValue, 1);
- ProduceSignature(*pwallet, creator, out.scriptPubKey, sigdata);
+ ProduceSignature(HidingSigningProvider(pwallet, true, !bip32derivs), creator, out.scriptPubKey, sigdata);
psbt_out.FromSignatureData(sigdata);
-
- // Get public key paths
- if (bip32derivs) {
- for (const auto& pubkey_it : sigdata.misc_pubkeys) {
- AddKeypathToMap(pwallet, pubkey_it.first, psbt_out.hd_keypaths);
- }
- }
}
return complete;
}
@@ -4598,7 +3898,7 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request)
" \"ALL|ANYONECANPAY\"\n"
" \"NONE|ANYONECANPAY\"\n"
" \"SINGLE|ANYONECANPAY\"\n"
- "4. bip32derivs (boolean, optiona, default=false) If true, includes the BIP 32 derivation paths for public keys if we know them\n"
+ "4. bip32derivs (boolean, optional, default=false) If true, includes the BIP 32 derivation paths for public keys if we know them\n"
"\nResult:\n"
"{\n"
@@ -4700,7 +4000,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
" \"ECONOMICAL\"\n"
" \"CONSERVATIVE\"\n"
" }\n"
- "5. bip32derivs (boolean, optiona, default=false) If true, includes the BIP 32 derivation paths for public keys if we know them\n"
+ "5. bip32derivs (boolean, optional, default=false) If true, includes the BIP 32 derivation paths for public keys if we know them\n"
"\nResult:\n"
"{\n"
" \"psbt\": \"value\", (string) The resulting raw transaction (base64-encoded string)\n"
@@ -4741,7 +4041,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
const CTransaction txConst(*psbtx.tx);
// Fill transaction with out data but don't sign
- bool bip32derivs = request.params[4].isNull() ? false : request.params[5].get_bool();
+ bool bip32derivs = request.params[4].isNull() ? false : request.params[4].get_bool();
FillPSBT(pwallet, psbtx, &txConst, 1, false, bip32derivs);
// Serialize the PSBT
@@ -4769,76 +4069,62 @@ UniValue importmulti(const JSONRPCRequest& request);
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
- { "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
- { "wallet", "walletprocesspsbt", &walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} },
- { "wallet", "walletcreatefundedpsbt", &walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} },
+ { "generating", "generate", &generate, {"nblocks","maxtries"} },
+ { "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
+ { "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
{ "wallet", "abortrescan", &abortrescan, {} },
- { "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","label|account","address_type"} },
- { "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
+ { "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","label","address_type"} },
{ "wallet", "backupwallet", &backupwallet, {"destination"} },
{ "wallet", "bumpfee", &bumpfee, {"txid", "options"} },
{ "wallet", "createwallet", &createwallet, {"wallet_name", "disable_private_keys"} },
{ "wallet", "dumpprivkey", &dumpprivkey, {"address"} },
{ "wallet", "dumpwallet", &dumpwallet, {"filename"} },
{ "wallet", "encryptwallet", &encryptwallet, {"passphrase"} },
+ { "wallet", "getaddressesbylabel", &getaddressesbylabel, {"label"} },
{ "wallet", "getaddressinfo", &getaddressinfo, {"address"} },
- { "wallet", "getbalance", &getbalance, {"account|dummy","minconf","include_watchonly"} },
- { "wallet", "getnewaddress", &getnewaddress, {"label|account","address_type"} },
+ { "wallet", "getbalance", &getbalance, {"dummy","minconf","include_watchonly"} },
+ { "wallet", "getnewaddress", &getnewaddress, {"label","address_type"} },
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {"address_type"} },
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf"} },
+ { "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf"} },
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly"} },
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
{ "wallet", "getwalletinfo", &getwalletinfo, {} },
+ { "wallet", "importaddress", &importaddress, {"address","label","rescan","p2sh"} },
{ "wallet", "importmulti", &importmulti, {"requests","options"} },
{ "wallet", "importprivkey", &importprivkey, {"privkey","label","rescan"} },
- { "wallet", "importwallet", &importwallet, {"filename"} },
- { "wallet", "importaddress", &importaddress, {"address","label","rescan","p2sh"} },
{ "wallet", "importprunedfunds", &importprunedfunds, {"rawtransaction","txoutproof"} },
{ "wallet", "importpubkey", &importpubkey, {"pubkey","label","rescan"} },
+ { "wallet", "importwallet", &importwallet, {"filename"} },
{ "wallet", "keypoolrefill", &keypoolrefill, {"newsize"} },
{ "wallet", "listaddressgroupings", &listaddressgroupings, {} },
+ { "wallet", "listlabels", &listlabels, {"purpose"} },
{ "wallet", "listlockunspent", &listlockunspent, {} },
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} },
+ { "wallet", "listreceivedbylabel", &listreceivedbylabel, {"minconf","include_empty","include_watchonly"} },
{ "wallet", "listsinceblock", &listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} },
- { "wallet", "listtransactions", &listtransactions, {"account|dummy","count","skip","include_watchonly"} },
+ { "wallet", "listtransactions", &listtransactions, {"dummy","count","skip","include_watchonly"} },
{ "wallet", "listunspent", &listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} },
{ "wallet", "listwallets", &listwallets, {} },
{ "wallet", "loadwallet", &loadwallet, {"filename"} },
{ "wallet", "lockunspent", &lockunspent, {"unlock","transactions"} },
- { "wallet", "sendmany", &sendmany, {"fromaccount|dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} },
+ { "wallet", "removeprunedfunds", &removeprunedfunds, {"txid"} },
+ { "wallet", "rescanblockchain", &rescanblockchain, {"start_height", "stop_height"} },
+ { "wallet", "sendmany", &sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} },
{ "wallet", "sendtoaddress", &sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode"} },
+ { "wallet", "sethdseed", &sethdseed, {"newkeypool","seed"} },
+ { "wallet", "setlabel", &setlabel, {"address","label"} },
{ "wallet", "settxfee", &settxfee, {"amount"} },
{ "wallet", "signmessage", &signmessage, {"address","message"} },
{ "wallet", "signrawtransactionwithwallet", &signrawtransactionwithwallet, {"hexstring","prevtxs","sighashtype"} },
{ "wallet", "unloadwallet", &unloadwallet, {"wallet_name"} },
+ { "wallet", "walletcreatefundedpsbt", &walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} },
{ "wallet", "walletlock", &walletlock, {} },
- { "wallet", "walletpassphrasechange", &walletpassphrasechange, {"oldpassphrase","newpassphrase"} },
{ "wallet", "walletpassphrase", &walletpassphrase, {"passphrase","timeout"} },
- { "wallet", "removeprunedfunds", &removeprunedfunds, {"txid"} },
- { "wallet", "rescanblockchain", &rescanblockchain, {"start_height", "stop_height"} },
- { "wallet", "sethdseed", &sethdseed, {"newkeypool","seed"} },
-
- /** Account functions (deprecated) */
- { "wallet", "getaccountaddress", &getaccountaddress, {"account"} },
- { "wallet", "getaccount", &getaccount, {"address"} },
- { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, {"account"} },
- { "wallet", "getreceivedbyaccount", &getreceivedbylabel, {"account","minconf"} },
- { "wallet", "listaccounts", &listaccounts, {"minconf","include_watchonly"} },
- { "wallet", "listreceivedbyaccount", &listreceivedbylabel, {"minconf","include_empty","include_watchonly"} },
- { "wallet", "setaccount", &setlabel, {"address","account"} },
- { "wallet", "sendfrom", &sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
- { "wallet", "move", &movecmd, {"fromaccount","toaccount","amount","minconf","comment"} },
-
- /** Label functions (to replace non-balance account functions) */
- { "wallet", "getaddressesbylabel", &getaddressesbylabel, {"label"} },
- { "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf"} },
- { "wallet", "listlabels", &listlabels, {"purpose"} },
- { "wallet", "listreceivedbylabel", &listreceivedbylabel, {"minconf","include_empty","include_watchonly"} },
- { "wallet", "setlabel", &setlabel, {"address","label"} },
-
- { "generating", "generate", &generate, {"nblocks","maxtries"} },
+ { "wallet", "walletpassphrasechange", &walletpassphrasechange, {"oldpassphrase","newpassphrase"} },
+ { "wallet", "walletprocesspsbt", &walletprocesspsbt, {"psbt","sign","sighashtype","bip32derivs"} },
};
void RegisterWalletRPCCommands(CRPCTable &t)
diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp
deleted file mode 100644
index 79060887be..0000000000
--- a/src/wallet/test/accounting_tests.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2012-2018 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include <wallet/wallet.h>
-
-#include <wallet/test/wallet_test_fixture.h>
-
-#include <stdint.h>
-
-#include <boost/test/unit_test.hpp>
-
-BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
-
-static void
-GetResults(CWallet& wallet, std::map<CAmount, CAccountingEntry>& results)
-{
- std::list<CAccountingEntry> aes;
-
- results.clear();
- BOOST_CHECK(wallet.ReorderTransactions() == DBErrors::LOAD_OK);
- wallet.ListAccountCreditDebit("", aes);
- for (CAccountingEntry& ae : aes)
- {
- results[ae.nOrderPos] = ae;
- }
-}
-
-BOOST_AUTO_TEST_CASE(acc_orderupgrade)
-{
- std::vector<CWalletTx*> vpwtx;
- CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef());
- CAccountingEntry ae;
- std::map<CAmount, CAccountingEntry> results;
-
- LOCK(m_wallet.cs_wallet);
-
- ae.strAccount = "";
- ae.nCreditDebit = 1;
- ae.nTime = 1333333333;
- ae.strOtherAccount = "b";
- ae.strComment = "";
- m_wallet.AddAccountingEntry(ae);
-
- wtx.mapValue["comment"] = "z";
- m_wallet.AddToWallet(wtx);
- vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
- vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
- vpwtx[0]->nOrderPos = -1;
-
- ae.nTime = 1333333336;
- ae.strOtherAccount = "c";
- m_wallet.AddAccountingEntry(ae);
-
- GetResults(m_wallet, results);
-
- BOOST_CHECK(m_wallet.nOrderPosNext == 3);
- BOOST_CHECK(2 == results.size());
- BOOST_CHECK(results[0].nTime == 1333333333);
- BOOST_CHECK(results[0].strComment.empty());
- BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
- BOOST_CHECK(results[2].nTime == 1333333336);
- BOOST_CHECK(results[2].strOtherAccount == "c");
-
-
- ae.nTime = 1333333330;
- ae.strOtherAccount = "d";
- ae.nOrderPos = m_wallet.IncOrderPosNext();
- m_wallet.AddAccountingEntry(ae);
-
- GetResults(m_wallet, results);
-
- BOOST_CHECK(results.size() == 3);
- BOOST_CHECK(m_wallet.nOrderPosNext == 4);
- BOOST_CHECK(results[0].nTime == 1333333333);
- BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
- BOOST_CHECK(results[2].nTime == 1333333336);
- BOOST_CHECK(results[3].nTime == 1333333330);
- BOOST_CHECK(results[3].strComment.empty());
-
-
- wtx.mapValue["comment"] = "y";
- {
- CMutableTransaction tx(*wtx.tx);
- ++tx.nLockTime; // Just to change the hash :)
- wtx.SetTx(MakeTransactionRef(std::move(tx)));
- }
- m_wallet.AddToWallet(wtx);
- vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
- vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
-
- wtx.mapValue["comment"] = "x";
- {
- CMutableTransaction tx(*wtx.tx);
- ++tx.nLockTime; // Just to change the hash :)
- wtx.SetTx(MakeTransactionRef(std::move(tx)));
- }
- m_wallet.AddToWallet(wtx);
- vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
- vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
- vpwtx[2]->nOrderPos = -1;
-
- GetResults(m_wallet, results);
-
- BOOST_CHECK(results.size() == 3);
- BOOST_CHECK(m_wallet.nOrderPosNext == 6);
- BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
- BOOST_CHECK(results[1].nTime == 1333333333);
- BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
- BOOST_CHECK(results[3].nTime == 1333333336);
- BOOST_CHECK(results[4].nTime == 1333333330);
- BOOST_CHECK(results[4].strComment.empty());
- BOOST_CHECK(5 == vpwtx[1]->nOrderPos);
-
-
- ae.nTime = 1333333334;
- ae.strOtherAccount = "e";
- ae.nOrderPos = -1;
- m_wallet.AddAccountingEntry(ae);
-
- GetResults(m_wallet, results);
-
- BOOST_CHECK(results.size() == 4);
- BOOST_CHECK(m_wallet.nOrderPosNext == 7);
- BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
- BOOST_CHECK(results[1].nTime == 1333333333);
- BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
- BOOST_CHECK(results[3].nTime == 1333333336);
- BOOST_CHECK(results[3].strComment.empty());
- BOOST_CHECK(results[4].nTime == 1333333330);
- BOOST_CHECK(results[4].strComment.empty());
- BOOST_CHECK(results[5].nTime == 1333333334);
- BOOST_CHECK(6 == vpwtx[1]->nOrderPos);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index 0776ffda9c..a24dc1b5f9 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -150,6 +150,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(1 * CENT, 1, actual_selection);
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
BOOST_CHECK(equal_sets(selection, actual_selection));
+ BOOST_CHECK_EQUAL(value_ret, 1 * CENT);
actual_selection.clear();
selection.clear();
@@ -157,6 +158,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(2 * CENT, 2, actual_selection);
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 2 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
BOOST_CHECK(equal_sets(selection, actual_selection));
+ BOOST_CHECK_EQUAL(value_ret, 2 * CENT);
actual_selection.clear();
selection.clear();
@@ -165,6 +167,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(2 * CENT, 2, actual_selection);
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 5 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
BOOST_CHECK(equal_sets(selection, actual_selection));
+ BOOST_CHECK_EQUAL(value_ret, 5 * CENT);
actual_selection.clear();
selection.clear();
@@ -181,6 +184,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(1 * CENT, 1, actual_selection);
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
BOOST_CHECK(equal_sets(selection, actual_selection));
+ BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
actual_selection.clear();
selection.clear();
@@ -190,6 +194,9 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(3 * CENT, 3, actual_selection);
add_coin(2 * CENT, 2, actual_selection);
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 5000, selection, value_ret, not_input_fees));
+ BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
+ // FIXME: this test is redundant with the above, because 1 Cent is selected, not "too small"
+ // BOOST_CHECK(equal_sets(selection, actual_selection));
// Select 0.25 Cent, not possible
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.25 * CENT, 0.5 * CENT, selection, value_ret, not_input_fees));
@@ -203,6 +210,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), target, 0, selection, value_ret, not_input_fees)); // Should not exhaust
// Test same value early bailout optimization
+ utxo_pool.clear();
add_coin(7 * CENT, 7, actual_selection);
add_coin(7 * CENT, 7, actual_selection);
add_coin(7 * CENT, 7, actual_selection);
@@ -217,6 +225,8 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
add_coin(5 * CENT, 7, utxo_pool);
}
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 30 * CENT, 5000, selection, value_ret, not_input_fees));
+ BOOST_CHECK_EQUAL(value_ret, 30 * CENT);
+ BOOST_CHECK(equal_sets(selection, actual_selection));
////////////////////
// Behavior tests //
diff --git a/src/wallet/test/psbt_wallet_tests.cpp b/src/wallet/test/psbt_wallet_tests.cpp
index 61c3fa94a6..526f2d983f 100644
--- a/src/wallet/test/psbt_wallet_tests.cpp
+++ b/src/wallet/test/psbt_wallet_tests.cpp
@@ -13,8 +13,6 @@
#include <test/test_bitcoin.h>
#include <wallet/test/wallet_test_fixture.h>
-extern bool ParseHDKeypath(std::string keypath_str, std::vector<uint32_t>& keypath);
-
BOOST_FIXTURE_TEST_SUITE(psbt_wallet_tests, WalletTestingSetup)
BOOST_AUTO_TEST_CASE(psbt_updater_test)
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index f44311b0be..b436efc276 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -297,7 +297,7 @@ public:
CCoinControl dummy;
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, reservekey, fee, changePos, error, dummy));
CValidationState state;
- BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, {}, reservekey, nullptr, state));
+ BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, reservekey, nullptr, state));
CMutableTransaction blocktx;
{
LOCK(wallet->cs_wallet);
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index d0857bcb72..d3ccd2dfaa 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -585,7 +585,6 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
// nTimeReceived not copied on purpose
copyTo->nTimeSmart = copyFrom->nTimeSmart;
copyTo->fFromMe = copyFrom->fFromMe;
- copyTo->strFromAccount = copyFrom->strFromAccount;
// nOrderPos not copied on purpose
// cached members not copied on purpose
}
@@ -735,44 +734,30 @@ DBErrors CWallet::ReorderTransactions()
// Old wallets didn't have any defined order for transactions
// Probably a bad idea to change the output of this
- // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
- typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
- typedef std::multimap<int64_t, TxPair > TxItems;
+ // First: get all CWalletTx into a sorted-by-time multimap.
+ typedef std::multimap<int64_t, CWalletTx*> TxItems;
TxItems txByTime;
for (auto& entry : mapWallet)
{
CWalletTx* wtx = &entry.second;
- txByTime.insert(std::make_pair(wtx->nTimeReceived, TxPair(wtx, nullptr)));
- }
- std::list<CAccountingEntry> acentries;
- batch.ListAccountCreditDebit("", acentries);
- for (CAccountingEntry& entry : acentries)
- {
- txByTime.insert(std::make_pair(entry.nTime, TxPair(nullptr, &entry)));
+ txByTime.insert(std::make_pair(wtx->nTimeReceived, wtx));
}
nOrderPosNext = 0;
std::vector<int64_t> nOrderPosOffsets;
for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
{
- CWalletTx *const pwtx = (*it).second.first;
- CAccountingEntry *const pacentry = (*it).second.second;
- int64_t& nOrderPos = (pwtx != nullptr) ? pwtx->nOrderPos : pacentry->nOrderPos;
+ CWalletTx *const pwtx = (*it).second;
+ int64_t& nOrderPos = pwtx->nOrderPos;
if (nOrderPos == -1)
{
nOrderPos = nOrderPosNext++;
nOrderPosOffsets.push_back(nOrderPos);
- if (pwtx)
- {
- if (!batch.WriteTx(*pwtx))
- return DBErrors::LOAD_FAIL;
- }
- else
- if (!batch.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
- return DBErrors::LOAD_FAIL;
+ if (!batch.WriteTx(*pwtx))
+ return DBErrors::LOAD_FAIL;
}
else
{
@@ -789,14 +774,8 @@ DBErrors CWallet::ReorderTransactions()
continue;
// Since we're changing the order, write it back
- if (pwtx)
- {
- if (!batch.WriteTx(*pwtx))
- return DBErrors::LOAD_FAIL;
- }
- else
- if (!batch.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
- return DBErrors::LOAD_FAIL;
+ if (!batch.WriteTx(*pwtx))
+ return DBErrors::LOAD_FAIL;
}
}
batch.WriteOrderPosNext(nOrderPosNext);
@@ -816,80 +795,6 @@ int64_t CWallet::IncOrderPosNext(WalletBatch *batch)
return nRet;
}
-bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment)
-{
- WalletBatch batch(*database);
- if (!batch.TxnBegin())
- return false;
-
- int64_t nNow = GetAdjustedTime();
-
- // Debit
- CAccountingEntry debit;
- debit.nOrderPos = IncOrderPosNext(&batch);
- debit.strAccount = strFrom;
- debit.nCreditDebit = -nAmount;
- debit.nTime = nNow;
- debit.strOtherAccount = strTo;
- debit.strComment = strComment;
- AddAccountingEntry(debit, &batch);
-
- // Credit
- CAccountingEntry credit;
- credit.nOrderPos = IncOrderPosNext(&batch);
- credit.strAccount = strTo;
- credit.nCreditDebit = nAmount;
- credit.nTime = nNow;
- credit.strOtherAccount = strFrom;
- credit.strComment = strComment;
- AddAccountingEntry(credit, &batch);
-
- if (!batch.TxnCommit())
- return false;
-
- return true;
-}
-
-bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew)
-{
- WalletBatch batch(*database);
-
- CAccount account;
- batch.ReadAccount(label, account);
-
- if (!bForceNew) {
- if (!account.vchPubKey.IsValid())
- bForceNew = true;
- else {
- // Check if the current key has been used (TODO: check other addresses with the same key)
- CScript scriptPubKey = GetScriptForDestination(GetDestinationForKey(account.vchPubKey, m_default_address_type));
- for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin();
- it != mapWallet.end() && account.vchPubKey.IsValid();
- ++it)
- for (const CTxOut& txout : (*it).second.tx->vout)
- if (txout.scriptPubKey == scriptPubKey) {
- bForceNew = true;
- break;
- }
- }
- }
-
- // Generate a new key
- if (bForceNew) {
- if (!GetKeyFromPool(account.vchPubKey, false))
- return false;
-
- LearnRelatedScripts(account.vchPubKey, m_default_address_type);
- dest = GetDestinationForKey(account.vchPubKey, m_default_address_type);
- SetAddressBook(dest, label, "receive");
- batch.WriteAccount(label, account);
- } else {
- dest = GetDestinationForKey(account.vchPubKey, m_default_address_type);
- }
-
- return true;
-}
-
void CWallet::MarkDirty()
{
{
@@ -944,7 +849,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
if (fInsertedNew) {
wtx.nTimeReceived = GetAdjustedTime();
wtx.nOrderPos = IncOrderPosNext(&batch);
- wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
+ wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
wtx.nTimeSmart = ComputeTimeSmart(wtx);
AddToSpends(hash);
}
@@ -1019,7 +924,7 @@ void CWallet::LoadToWallet(const CWalletTx& wtxIn)
CWalletTx& wtx = ins.first->second;
wtx.BindWallet(this);
if (/* insertion took place */ ins.second) {
- wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
+ wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
}
AddToSpends(hash);
for (const CTxIn& txin : wtx.tx->vin) {
@@ -1615,12 +1520,11 @@ int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet,
}
void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
- std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const
+ std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter) const
{
nFee = 0;
listReceived.clear();
listSent.clear();
- strSentAccount = strFromAccount;
// Compute fee:
CAmount nDebit = GetDebit(filter);
@@ -2189,7 +2093,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const
// wallet, and then subtracts the values of TxIns spending from the wallet. This
// also has fewer restrictions on which unconfirmed transactions are considered
// trusted.
-CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const
+CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth) const
{
LOCK2(cs_main, cs_wallet);
@@ -2208,21 +2112,17 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
for (const CTxOut& out : wtx.tx->vout) {
if (outgoing && IsChange(out)) {
debit -= out.nValue;
- } else if (IsMine(out) & filter && depth >= minDepth && (!account || *account == GetLabelName(out.scriptPubKey))) {
+ } else if (IsMine(out) & filter && depth >= minDepth) {
balance += out.nValue;
}
}
// For outgoing txs, subtract amount debited.
- if (outgoing && (!account || *account == wtx.strFromAccount)) {
+ if (outgoing) {
balance -= debit;
}
}
- if (account) {
- balance += WalletBatch(*database).GetAccountCreditDebit(*account);
- }
-
return balance;
}
@@ -3054,7 +2954,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
/**
* Call after CreateTransaction unless you want to abort
*/
-bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, std::string fromAccount, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
+bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
{
{
LOCK2(cs_main, cs_wallet);
@@ -3062,7 +2962,6 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
CWalletTx wtxNew(this, std::move(tx));
wtxNew.mapValue = std::move(mapValue);
wtxNew.vOrderForm = std::move(orderForm);
- wtxNew.strFromAccount = std::move(fromAccount);
wtxNew.fTimeReceivedIsTxTime = true;
wtxNew.fFromMe = true;
@@ -3102,31 +3001,6 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
return true;
}
-void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) {
- WalletBatch batch(*database);
- return batch.ListAccountCreditDebit(strAccount, entries);
-}
-
-bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry)
-{
- WalletBatch batch(*database);
-
- return AddAccountingEntry(acentry, &batch);
-}
-
-bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, WalletBatch *batch)
-{
- if (!batch->WriteAccountingEntry(++nAccountingEntryNumber, acentry)) {
- return false;
- }
-
- laccentries.push_back(acentry);
- CAccountingEntry & entry = laccentries.back();
- wtxOrdered.insert(std::make_pair(entry.nOrderPos, TxPair(nullptr, &entry)));
-
- return true;
-}
-
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
{
LOCK2(cs_main, cs_wallet);
@@ -3660,12 +3534,6 @@ std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) co
return result;
}
-void CWallet::DeleteLabel(const std::string& label)
-{
- WalletBatch batch(*database);
- batch.EraseAccount(label);
-}
-
bool CReserveKey::GetReservedKey(CPubKey& pubkey, bool internal)
{
if (nIndex == -1)
@@ -3856,19 +3724,14 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
int64_t latestTolerated = latestNow + 300;
const TxItems& txOrdered = wtxOrdered;
for (auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) {
- CWalletTx* const pwtx = it->second.first;
+ CWalletTx* const pwtx = it->second;
if (pwtx == &wtx) {
continue;
}
- CAccountingEntry* const pacentry = it->second.second;
int64_t nSmartTime;
- if (pwtx) {
- nSmartTime = pwtx->nTimeSmart;
- if (!nSmartTime) {
- nSmartTime = pwtx->nTimeReceived;
- }
- } else {
- nSmartTime = pacentry->nTime;
+ nSmartTime = pwtx->nTimeSmart;
+ if (!nSmartTime) {
+ nSmartTime = pwtx->nTimeReceived;
}
if (nSmartTime <= latestTolerated) {
latestEntry = nSmartTime;
@@ -4313,7 +4176,6 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name,
copyTo->nTimeReceived = copyFrom->nTimeReceived;
copyTo->nTimeSmart = copyFrom->nTimeSmart;
copyTo->fFromMe = copyFrom->fFromMe;
- copyTo->strFromAccount = copyFrom->strFromAccount;
copyTo->nOrderPos = copyFrom->nOrderPos;
batch.WriteTx(*copyTo);
}
@@ -4469,3 +4331,29 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
}
return groups;
}
+
+bool CWallet::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
+{
+ CKeyMetadata meta;
+ {
+ LOCK(cs_wallet);
+ auto it = mapKeyMetadata.find(keyID);
+ if (it != mapKeyMetadata.end()) {
+ meta = it->second;
+ }
+ }
+ if (!meta.hdKeypath.empty()) {
+ if (!ParseHDKeypath(meta.hdKeypath, info.path)) return false;
+ // Get the proper master key id
+ CKey key;
+ GetKey(meta.hd_seed_id, key);
+ CExtKey masterKey;
+ masterKey.SetSeed(key.begin(), key.size());
+ // Compute identifier
+ CKeyID masterid = masterKey.key.GetPubKey().GetID();
+ std::copy(masterid.begin(), masterid.begin() + 4, info.fingerprint);
+ } else { // Single pubkeys get the master fingerprint of themselves
+ std::copy(keyID.begin(), keyID.begin() + 4, info.fingerprint);
+ }
+ return true;
+}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 51ac3df71e..05ae9a1bbf 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -302,7 +302,7 @@ public:
* serialized in the wallet database:
*
* "comment", "to" - comment strings provided to sendtoaddress,
- * sendfrom, sendmany wallet RPCs
+ * and sendmany wallet RPCs
* "replaces_txid" - txid (as HexStr) of transaction replaced by
* bumpfee on transaction created by bumpfee
* "replaced_by_txid" - txid (as HexStr) of transaction created by
@@ -340,9 +340,8 @@ public:
* externally and came in through the network or sendrawtransaction RPC.
*/
char fFromMe;
- std::string strFromAccount;
int64_t nOrderPos; //!< position in ordered transaction list
- std::multimap<int64_t, std::pair<CWalletTx*, CAccountingEntry*>>::const_iterator m_it_wtxOrdered;
+ std::multimap<int64_t, CWalletTx*>::const_iterator m_it_wtxOrdered;
// memory only
mutable bool fDebitCached;
@@ -379,7 +378,6 @@ public:
nTimeReceived = 0;
nTimeSmart = 0;
fFromMe = false;
- strFromAccount.clear();
fDebitCached = false;
fCreditCached = false;
fImmatureCreditCached = false;
@@ -408,7 +406,7 @@ public:
char fSpent = false;
mapValue_t mapValueCopy = mapValue;
- mapValueCopy["fromaccount"] = strFromAccount;
+ mapValueCopy["fromaccount"] = "";
WriteOrderPos(nOrderPos, mapValueCopy);
if (nTimeSmart) {
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
@@ -429,7 +427,6 @@ public:
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
- strFromAccount = std::move(mapValue["fromaccount"]);
ReadOrderPos(nOrderPos, mapValue);
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
@@ -474,7 +471,7 @@ public:
}
void GetAmounts(std::list<COutputEntry>& listReceived,
- std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
+ std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter) const;
bool IsFromMe(const isminefilter& filter) const
{
@@ -569,89 +566,6 @@ public:
}
};
-/**
- * DEPRECATED Internal transfers.
- * Database key is acentry<account><counter>.
- */
-class CAccountingEntry
-{
-public:
- std::string strAccount;
- CAmount nCreditDebit;
- int64_t nTime;
- std::string strOtherAccount;
- std::string strComment;
- mapValue_t mapValue;
- int64_t nOrderPos; //!< position in ordered transaction list
- uint64_t nEntryNo;
-
- CAccountingEntry()
- {
- SetNull();
- }
-
- void SetNull()
- {
- nCreditDebit = 0;
- nTime = 0;
- strAccount.clear();
- strOtherAccount.clear();
- strComment.clear();
- nOrderPos = -1;
- nEntryNo = 0;
- }
-
- template <typename Stream>
- void Serialize(Stream& s) const {
- int nVersion = s.GetVersion();
- if (!(s.GetType() & SER_GETHASH)) {
- s << nVersion;
- }
- //! Note: strAccount is serialized as part of the key, not here.
- s << nCreditDebit << nTime << strOtherAccount;
-
- mapValue_t mapValueCopy = mapValue;
- WriteOrderPos(nOrderPos, mapValueCopy);
-
- std::string strCommentCopy = strComment;
- if (!mapValueCopy.empty() || !_ssExtra.empty()) {
- CDataStream ss(s.GetType(), s.GetVersion());
- ss.insert(ss.begin(), '\0');
- ss << mapValueCopy;
- ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
- strCommentCopy.append(ss.str());
- }
- s << strCommentCopy;
- }
-
- template <typename Stream>
- void Unserialize(Stream& s) {
- int nVersion = s.GetVersion();
- if (!(s.GetType() & SER_GETHASH)) {
- s >> nVersion;
- }
- //! Note: strAccount is serialized as part of the key, not here.
- s >> nCreditDebit >> nTime >> LIMITED_STRING(strOtherAccount, 65536) >> LIMITED_STRING(strComment, 65536);
-
- size_t nSepPos = strComment.find("\0", 0, 1);
- mapValue.clear();
- if (std::string::npos != nSepPos) {
- CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
- ss >> mapValue;
- _ssExtra = std::vector<char>(ss.begin(), ss.end());
- }
- ReadOrderPos(nOrderPos, mapValue);
- if (std::string::npos != nSepPos) {
- strComment.erase(nSepPos);
- }
-
- mapValue.erase("n");
- }
-
-private:
- std::vector<char> _ssExtra;
-};
-
struct CoinSelectionParams
{
bool use_bnb = true;
@@ -826,10 +740,8 @@ public:
}
std::map<uint256, CWalletTx> mapWallet;
- std::list<CAccountingEntry> laccentries;
- typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
- typedef std::multimap<int64_t, TxPair > TxItems;
+ typedef std::multimap<int64_t, CWalletTx*> TxItems;
TxItems wtxOrdered;
int64_t nOrderPosNext = 0;
@@ -941,8 +853,6 @@ public:
*/
int64_t IncOrderPosNext(WalletBatch *batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
DBErrors ReorderTransactions();
- bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "") EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
- bool GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew = false);
void MarkDirty();
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
@@ -962,7 +872,7 @@ public:
CAmount GetImmatureBalance() const;
CAmount GetUnconfirmedWatchOnlyBalance() const;
CAmount GetImmatureWatchOnlyBalance() const;
- CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
+ CAmount GetLegacyBalance(const isminefilter& filter, int minDepth) const;
CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
OutputType TransactionChangeType(OutputType change_type, const std::vector<CRecipient>& vecSend);
@@ -981,11 +891,8 @@ public:
*/
bool CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
- bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, std::string fromAccount, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
+ bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
- void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
- bool AddAccountingEntry(const CAccountingEntry&);
- bool AddAccountingEntry(const CAccountingEntry&, WalletBatch *batch);
bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts, bool use_max_sig = false) const
{
std::vector<CTxOut> v_txouts(txouts.size());
@@ -999,7 +906,7 @@ public:
unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};
bool m_spend_zero_conf_change{DEFAULT_SPEND_ZEROCONF_CHANGE};
bool m_signal_rbf{DEFAULT_WALLET_RBF};
- bool m_allow_fallback_fee{true}; //<! will be defined via chainparams
+ bool m_allow_fallback_fee{true}; //!< will be defined via chainparams
CFeeRate m_min_fee{DEFAULT_TRANSACTION_MINFEE}; //!< Override with -mintxfee
/**
* If fee estimation does not have enough data to provide estimates, use this fee instead.
@@ -1044,7 +951,6 @@ public:
std::map<CTxDestination, CAmount> GetAddressBalances() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
- void DeleteLabel(const std::string& label);
isminetype IsMine(const CTxIn& txin) const;
/**
@@ -1218,6 +1124,8 @@ public:
LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
};
+ /** Implement lookup of key origin information through wallet key metadata. */
+ bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
};
/** A key allocated from the key pool. */
@@ -1251,37 +1159,6 @@ public:
void KeepScript() override { KeepKey(); }
};
-
-/**
- * DEPRECATED Account information.
- * Stored in wallet with key "acc"+string account name.
- */
-class CAccount
-{
-public:
- CPubKey vchPubKey;
-
- CAccount()
- {
- SetNull();
- }
-
- void SetNull()
- {
- vchPubKey = CPubKey();
- }
-
- ADD_SERIALIZE_METHODS;
-
- template <typename Stream, typename Operation>
- inline void SerializationOp(Stream& s, Operation ser_action) {
- int nVersion = s.GetVersion();
- if (!(s.GetType() & SER_GETHASH))
- READWRITE(nVersion);
- READWRITE(vchPubKey);
- }
-};
-
/** RAII object to check and reserve a wallet rescan */
class WalletRescanReserver
{
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 1b787be198..5ce4d080e5 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -17,6 +17,7 @@
#include <wallet/wallet.h>
#include <atomic>
+#include <string>
#include <boost/thread.hpp>
@@ -150,82 +151,6 @@ bool WalletBatch::WriteMinVersion(int nVersion)
return WriteIC(std::string("minversion"), nVersion);
}
-bool WalletBatch::ReadAccount(const std::string& strAccount, CAccount& account)
-{
- account.SetNull();
- return m_batch.Read(std::make_pair(std::string("acc"), strAccount), account);
-}
-
-bool WalletBatch::WriteAccount(const std::string& strAccount, const CAccount& account)
-{
- return WriteIC(std::make_pair(std::string("acc"), strAccount), account);
-}
-
-bool WalletBatch::EraseAccount(const std::string& strAccount)
-{
- return EraseIC(std::make_pair(std::string("acc"), strAccount));
-}
-
-bool WalletBatch::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
-{
- return WriteIC(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
-}
-
-CAmount WalletBatch::GetAccountCreditDebit(const std::string& strAccount)
-{
- std::list<CAccountingEntry> entries;
- ListAccountCreditDebit(strAccount, entries);
-
- CAmount nCreditDebit = 0;
- for (const CAccountingEntry& entry : entries)
- nCreditDebit += entry.nCreditDebit;
-
- return nCreditDebit;
-}
-
-void WalletBatch::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries)
-{
- bool fAllAccounts = (strAccount == "*");
-
- Dbc* pcursor = m_batch.GetCursor();
- if (!pcursor)
- throw std::runtime_error(std::string(__func__) + ": cannot create DB cursor");
- bool setRange = true;
- while (true)
- {
- // Read next record
- CDataStream ssKey(SER_DISK, CLIENT_VERSION);
- if (setRange)
- ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? std::string("") : strAccount), uint64_t(0)));
- CDataStream ssValue(SER_DISK, CLIENT_VERSION);
- int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue, setRange);
- setRange = false;
- if (ret == DB_NOTFOUND)
- break;
- else if (ret != 0)
- {
- pcursor->close();
- throw std::runtime_error(std::string(__func__) + ": error scanning DB");
- }
-
- // Unserialize
- std::string strType;
- ssKey >> strType;
- if (strType != "acentry")
- break;
- CAccountingEntry acentry;
- ssKey >> acentry.strAccount;
- if (!fAllAccounts && acentry.strAccount != strAccount)
- break;
-
- ssValue >> acentry;
- ssKey >> acentry.nEntryNo;
- entries.push_back(acentry);
- }
-
- pcursor->close();
-}
-
class CWalletScanState {
public:
unsigned int nKeys;
@@ -284,9 +209,10 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
{
char fTmp;
char fUnused;
- ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
- strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
- wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
+ std::string unused_string;
+ ssValue >> fTmp >> fUnused >> unused_string;
+ strErr = strprintf("LoadWallet() upgrading tx ver=%d %d %s",
+ wtx.fTimeReceivedIsTxTime, fTmp, hash.ToString());
wtx.fTimeReceivedIsTxTime = fTmp;
}
else
@@ -302,24 +228,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
pwallet->LoadToWallet(wtx);
}
- else if (strType == "acentry")
- {
- std::string strAccount;
- ssKey >> strAccount;
- uint64_t nNumber;
- ssKey >> nNumber;
- if (nNumber > pwallet->nAccountingEntryNumber) {
- pwallet->nAccountingEntryNumber = nNumber;
- }
-
- if (!wss.fAnyUnordered)
- {
- CAccountingEntry acentry;
- ssValue >> acentry;
- if (acentry.nOrderPos == -1)
- wss.fAnyUnordered = true;
- }
- }
else if (strType == "watchs")
{
wss.nWatchKeys++;
@@ -510,7 +418,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
return false;
}
} else if (strType != "bestblock" && strType != "bestblock_nomerkle" &&
- strType != "minversion") {
+ strType != "minversion" && strType != "acentry") {
wss.m_unknown_records++;
}
} catch (...)
@@ -625,12 +533,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
if (wss.fAnyUnordered)
result = pwallet->ReorderTransactions();
- pwallet->laccentries.clear();
- ListAccountCreditDebit("*", pwallet->laccentries);
- for (CAccountingEntry& entry : pwallet->laccentries) {
- pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair(nullptr, &entry)));
- }
-
return result;
}
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index 0e6cb1bba4..5584407a56 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -31,8 +31,6 @@
static const bool DEFAULT_FLUSHWALLET = true;
-class CAccount;
-class CAccountingEntry;
struct CBlockLocator;
class CKeyPool;
class CMasterKey;
@@ -199,21 +197,11 @@ public:
bool WriteMinVersion(int nVersion);
- /// This writes directly to the database, and will not update the CWallet's cached accounting entries!
- /// Use wallet.AddAccountingEntry instead, to write *and* update its caches.
- bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
- bool ReadAccount(const std::string& strAccount, CAccount& account);
- bool WriteAccount(const std::string& strAccount, const CAccount& account);
- bool EraseAccount(const std::string& strAccount);
-
/// Write destination data key,value tuple to database
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
/// Erase destination data tuple from wallet database
bool EraseDestData(const std::string &address, const std::string &key);
- CAmount GetAccountCreditDebit(const std::string& strAccount);
- void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
-
DBErrors LoadWallet(CWallet* pwallet);
DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
diff --git a/test/functional/combine_logs.py b/test/functional/combine_logs.py
index 91b6415a7c..3759913e44 100755
--- a/test/functional/combine_logs.py
+++ b/test/functional/combine_logs.py
@@ -13,7 +13,7 @@ import re
import sys
# Matches on the date format at the start of the log event
-TIMESTAMP_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z")
+TIMESTAMP_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{6})?Z")
LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event'])
@@ -75,11 +75,17 @@ def get_log_events(source, logfile):
if time_match:
if event:
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
- event = line
timestamp = time_match.group()
+ if time_match.group(1) is None:
+ # timestamp does not have microseconds. Add zeroes.
+ timestamp_micro = timestamp.replace("Z", ".000000Z")
+ line = line.replace(timestamp, timestamp_micro)
+ timestamp = timestamp_micro
+ event = line
# if it doesn't have a timestamp, it's a continuation line of the previous log.
else:
- event += "\n" + line
+ # Add the line. Prefix with space equivalent to the source + timestamp so log lines are aligned
+ event += " " + line
# Flush the final event
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
except FileNotFoundError:
@@ -98,7 +104,11 @@ def print_logs(log_events, color=False, html=False):
colors["reset"] = "\033[0m" # Reset font color
for event in log_events:
- print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, event.event, colors["reset"]))
+ lines = event.event.splitlines()
+ print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
+ if len(lines) > 1:
+ for line in lines[1:]:
+ print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
else:
try:
diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py
index 79ed902871..e81ea12d0f 100755
--- a/test/functional/feature_block.py
+++ b/test/functional/feature_block.py
@@ -169,7 +169,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block where the miner creates too much coinbase reward")
self.move_tip(6)
b9 = self.next_block(9, spend=out[4], additional_coinbase_value=1)
- self.sync_blocks([b9], False, 16, b'bad-cb-amount', reconnect=True)
+ self.sync_blocks([b9], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
# Create a fork that ends in a block with too much fee (the one that causes the reorg)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -181,7 +181,7 @@ class FullBlockTest(BitcoinTestFramework):
self.sync_blocks([b10], False)
b11 = self.next_block(11, spend=out[4], additional_coinbase_value=1)
- self.sync_blocks([b11], False, 16, b'bad-cb-amount', reconnect=True)
+ self.sync_blocks([b11], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
# Try again, but with a valid fork first
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -194,7 +194,7 @@ class FullBlockTest(BitcoinTestFramework):
b13 = self.next_block(13, spend=out[4])
self.save_spendable_output()
b14 = self.next_block(14, spend=out[5], additional_coinbase_value=1)
- self.sync_blocks([b12, b13, b14], False, 16, b'bad-cb-amount', reconnect=True)
+ self.sync_blocks([b12, b13, b14], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
# New tip should be b13.
assert_equal(node.getbestblockhash(), b13.hash)
@@ -213,7 +213,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with too many checksigs")
too_many_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS))
b16 = self.next_block(16, spend=out[6], script=too_many_checksigs)
- self.sync_blocks([b16], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b16], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# Attempt to spend a transaction created on a different fork
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -222,7 +222,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with a spend from a re-org'ed out tx")
self.move_tip(15)
b17 = self.next_block(17, spend=txout_b3)
- self.sync_blocks([b17], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b17], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to spend a transaction created on a different fork (on a fork this time)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -235,7 +235,7 @@ class FullBlockTest(BitcoinTestFramework):
self.sync_blocks([b18], False)
b19 = self.next_block(19, spend=out[6])
- self.sync_blocks([b19], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b19], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to spend a coinbase at depth too low
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -244,7 +244,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block spending an immature coinbase.")
self.move_tip(15)
b20 = self.next_block(20, spend=out[7])
- self.sync_blocks([b20], False, 16, b'bad-txns-premature-spend-of-coinbase')
+ self.sync_blocks([b20], success=False, reject_code=16, reject_reason=b'bad-txns-premature-spend-of-coinbase')
# Attempt to spend a coinbase at depth too low (on a fork this time)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -257,7 +257,7 @@ class FullBlockTest(BitcoinTestFramework):
self.sync_blocks([b21], False)
b22 = self.next_block(22, spend=out[5])
- self.sync_blocks([b22], False, 16, b'bad-txns-premature-spend-of-coinbase')
+ self.sync_blocks([b22], success=False, reject_code=16, reject_reason=b'bad-txns-premature-spend-of-coinbase')
# Create a block on either side of MAX_BLOCK_BASE_SIZE and make sure its accepted/rejected
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -286,7 +286,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vout = [CTxOut(0, script_output)]
b24 = self.update_block(24, [tx])
assert_equal(len(b24.serialize()), MAX_BLOCK_BASE_SIZE + 1)
- self.sync_blocks([b24], False, 16, b'bad-blk-length', reconnect=True)
+ self.sync_blocks([b24], success=False, reject_code=16, reject_reason=b'bad-blk-length', reconnect=True)
b25 = self.next_block(25, spend=out[7])
self.sync_blocks([b25], False)
@@ -304,7 +304,7 @@ class FullBlockTest(BitcoinTestFramework):
# update_block causes the merkle root to get updated, even with no new
# transactions, and updates the required state.
b26 = self.update_block(26, [])
- self.sync_blocks([b26], False, 16, b'bad-cb-length', reconnect=True)
+ self.sync_blocks([b26], success=False, reject_code=16, reject_reason=b'bad-cb-length', reconnect=True)
# Extend the b26 chain to make sure bitcoind isn't accepting b26
b27 = self.next_block(27, spend=out[7])
@@ -316,7 +316,7 @@ class FullBlockTest(BitcoinTestFramework):
b28.vtx[0].vin[0].scriptSig = b'\x00' * 101
b28.vtx[0].rehash()
b28 = self.update_block(28, [])
- self.sync_blocks([b28], False, 16, b'bad-cb-length', reconnect=True)
+ self.sync_blocks([b28], success=False, reject_code=16, reject_reason=b'bad-cb-length', reconnect=True)
# Extend the b28 chain to make sure bitcoind isn't accepting b28
b29 = self.next_block(29, spend=out[7])
@@ -352,7 +352,7 @@ class FullBlockTest(BitcoinTestFramework):
too_many_multisigs = CScript([OP_CHECKMULTISIG] * (MAX_BLOCK_SIGOPS // 20))
b32 = self.next_block(32, spend=out[9], script=too_many_multisigs)
assert_equal(get_legacy_sigopcount_block(b32), MAX_BLOCK_SIGOPS + 1)
- self.sync_blocks([b32], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b32], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# CHECKMULTISIGVERIFY
self.log.info("Accept a block with the max number of OP_CHECKMULTISIGVERIFY sigops")
@@ -365,7 +365,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with too many OP_CHECKMULTISIGVERIFY sigops")
too_many_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * (MAX_BLOCK_SIGOPS // 20))
b34 = self.next_block(34, spend=out[10], script=too_many_multisigs)
- self.sync_blocks([b34], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b34], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# CHECKSIGVERIFY
self.log.info("Accept a block with the max number of OP_CHECKSIGVERIFY sigops")
@@ -378,7 +378,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with too many OP_CHECKSIGVERIFY sigops")
too_many_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS))
b36 = self.next_block(36, spend=out[11], script=too_many_checksigs)
- self.sync_blocks([b36], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b36], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# Check spending of a transaction in a block which failed to connect
#
@@ -395,12 +395,12 @@ class FullBlockTest(BitcoinTestFramework):
txout_b37 = b37.vtx[1]
tx = self.create_and_sign_transaction(out[11], 0)
b37 = self.update_block(37, [tx])
- self.sync_blocks([b37], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b37], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# attempt to spend b37's first non-coinbase tx, at which point b37 was still considered valid
self.move_tip(35)
b38 = self.next_block(38, spend=txout_b37)
- self.sync_blocks([b38], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b38], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# Check P2SH SigOp counting
#
@@ -492,7 +492,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.rehash()
new_txs.append(tx)
self.update_block(40, new_txs)
- self.sync_blocks([b40], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b40], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# same as b40, but one less sigop
self.log.info("Accept a block with the max number of P2SH sigops")
@@ -555,7 +555,7 @@ class FullBlockTest(BitcoinTestFramework):
self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1
self.tip = b45
self.blocks[45] = b45
- self.sync_blocks([b45], False, 16, b'bad-cb-missing', reconnect=True)
+ self.sync_blocks([b45], success=False, reject_code=16, reject_reason=b'bad-cb-missing', reconnect=True)
self.log.info("Reject a block with no transactions")
self.move_tip(44)
@@ -570,7 +570,7 @@ class FullBlockTest(BitcoinTestFramework):
self.tip = b46
assert 46 not in self.blocks
self.blocks[46] = b46
- self.sync_blocks([b46], False, 16, b'bad-blk-length', reconnect=True)
+ self.sync_blocks([b46], success=False, reject_code=16, reject_reason=b'bad-blk-length', reconnect=True)
self.log.info("Reject a block with invalid work")
self.move_tip(44)
@@ -593,7 +593,7 @@ class FullBlockTest(BitcoinTestFramework):
b49 = self.next_block(49)
b49.hashMerkleRoot += 1
b49.solve()
- self.sync_blocks([b49], False, 16, b'bad-txnmrklroot', reconnect=True)
+ self.sync_blocks([b49], success=False, reject_code=16, reject_reason=b'bad-txnmrklroot', reconnect=True)
self.log.info("Reject a block with incorrect POW limit")
self.move_tip(44)
@@ -607,7 +607,7 @@ class FullBlockTest(BitcoinTestFramework):
b51 = self.next_block(51)
cb2 = create_coinbase(51, self.coinbase_pubkey)
b51 = self.update_block(51, [cb2])
- self.sync_blocks([b51], False, 16, b'bad-cb-multiple', reconnect=True)
+ self.sync_blocks([b51], success=False, reject_code=16, reject_reason=b'bad-cb-multiple', reconnect=True)
self.log.info("Reject a block with duplicate transactions")
# Note: txns have to be in the right position in the merkle tree to trigger this error
@@ -615,7 +615,7 @@ class FullBlockTest(BitcoinTestFramework):
b52 = self.next_block(52, spend=out[15])
tx = self.create_tx(b52.vtx[1], 0, 1)
b52 = self.update_block(52, [tx, tx])
- self.sync_blocks([b52], False, 16, b'bad-txns-duplicate', reconnect=True)
+ self.sync_blocks([b52], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
# Test block timestamps
# -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15)
@@ -682,7 +682,7 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(len(b56.vtx), 3)
b56 = self.update_block(56, [tx1])
assert_equal(b56.hash, b57.hash)
- self.sync_blocks([b56], False, 16, b'bad-txns-duplicate', reconnect=True)
+ self.sync_blocks([b56], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
# b57p2 - a good block with 6 tx'es, don't submit until end
self.move_tip(55)
@@ -702,7 +702,7 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(b56p2.hash, b57p2.hash)
assert_equal(len(b56p2.vtx), 6)
b56p2 = self.update_block("b56p2", [tx3, tx4])
- self.sync_blocks([b56p2], False, 16, b'bad-txns-duplicate', reconnect=True)
+ self.sync_blocks([b56p2], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
self.move_tip("57p2")
self.sync_blocks([b57p2], True)
@@ -727,7 +727,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vout.append(CTxOut(0, b""))
tx.calc_sha256()
b58 = self.update_block(58, [tx])
- self.sync_blocks([b58], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b58], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# tx with output value > input value
self.log.info("Reject a block with a transaction with outputs > inputs")
@@ -735,7 +735,7 @@ class FullBlockTest(BitcoinTestFramework):
b59 = self.next_block(59)
tx = self.create_and_sign_transaction(out[17], 51 * COIN)
b59 = self.update_block(59, [tx])
- self.sync_blocks([b59], False, 16, b'bad-txns-in-belowout', reconnect=True)
+ self.sync_blocks([b59], success=False, reject_code=16, reject_reason=b'bad-txns-in-belowout', reconnect=True)
# reset to good chain
self.move_tip(57)
@@ -759,7 +759,7 @@ class FullBlockTest(BitcoinTestFramework):
b61.vtx[0].rehash()
b61 = self.update_block(61, [])
assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize())
- self.sync_blocks([b61], False, 16, b'bad-txns-BIP30', reconnect=True)
+ self.sync_blocks([b61], success=False, reject_code=16, reject_reason=b'bad-txns-BIP30', reconnect=True)
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)
#
@@ -776,7 +776,7 @@ class FullBlockTest(BitcoinTestFramework):
assert(tx.vin[0].nSequence < 0xffffffff)
tx.calc_sha256()
b62 = self.update_block(62, [tx])
- self.sync_blocks([b62], False, 16, b'bad-txns-nonfinal')
+ self.sync_blocks([b62], success=False, reject_code=16, reject_reason=b'bad-txns-nonfinal')
# Test a non-final coinbase is also rejected
#
@@ -790,7 +790,7 @@ class FullBlockTest(BitcoinTestFramework):
b63.vtx[0].vin[0].nSequence = 0xDEADBEEF
b63.vtx[0].rehash()
b63 = self.update_block(63, [])
- self.sync_blocks([b63], False, 16, b'bad-txns-nonfinal')
+ self.sync_blocks([b63], success=False, reject_code=16, reject_reason=b'bad-txns-nonfinal')
# This checks that a block with a bloated VARINT between the block_header and the array of tx such that
# the block is > MAX_BLOCK_BASE_SIZE with the bloated varint, but <= MAX_BLOCK_BASE_SIZE without the bloated varint,
@@ -824,7 +824,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
b64a = self.update_block("64a", [tx])
assert_equal(len(b64a.serialize()), MAX_BLOCK_BASE_SIZE + 8)
- self.sync_blocks([b64a], False, 1, b'error parsing message')
+ self.sync_blocks([b64a], success=False, reject_code=1, reject_reason=b'error parsing message')
# bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently
# resend the header message, it won't send us the getdata message again. Just
@@ -866,7 +866,7 @@ class FullBlockTest(BitcoinTestFramework):
tx1 = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue)
tx2 = self.create_and_sign_transaction(tx1, 1)
b66 = self.update_block(66, [tx2, tx1])
- self.sync_blocks([b66], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b66], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to double-spend a transaction created in a block
#
@@ -881,7 +881,7 @@ class FullBlockTest(BitcoinTestFramework):
tx2 = self.create_and_sign_transaction(tx1, 1)
tx3 = self.create_and_sign_transaction(tx1, 2)
b67 = self.update_block(67, [tx1, tx2, tx3])
- self.sync_blocks([b67], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b67], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# More tests of block subsidy
#
@@ -900,7 +900,7 @@ class FullBlockTest(BitcoinTestFramework):
b68 = self.next_block(68, additional_coinbase_value=10)
tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 9)
b68 = self.update_block(68, [tx])
- self.sync_blocks([b68], False, 16, b'bad-cb-amount', reconnect=True)
+ self.sync_blocks([b68], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
self.log.info("Accept a block claiming the correct subsidy in the coinbase transaction")
self.move_tip(65)
@@ -924,7 +924,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff))
tx.vout.append(CTxOut(1, b""))
b70 = self.update_block(70, [tx])
- self.sync_blocks([b70], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b70], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
# Test accepting an invalid block which has the same hash as a valid one (via merkle tree tricks)
#
@@ -949,7 +949,7 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(b72.sha256, b71.sha256)
self.move_tip(71)
- self.sync_blocks([b71], False, 16, b'bad-txns-duplicate', reconnect=True)
+ self.sync_blocks([b71], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
self.move_tip(72)
self.sync_blocks([b72], True)
@@ -987,7 +987,7 @@ class FullBlockTest(BitcoinTestFramework):
tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
b73 = self.update_block(73, [tx])
assert_equal(get_legacy_sigopcount_block(b73), MAX_BLOCK_SIGOPS + 1)
- self.sync_blocks([b73], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b73], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
# b74/75 - if we push an invalid script element, all prevous sigops are counted,
# but sigops after the element are not counted.
@@ -1011,7 +1011,7 @@ class FullBlockTest(BitcoinTestFramework):
a[MAX_BLOCK_SIGOPS + 4] = 0xff
tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
b74 = self.update_block(74, [tx])
- self.sync_blocks([b74], False, 16, b'bad-blk-sigops', reconnect=True)
+ self.sync_blocks([b74], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
self.move_tip(72)
b75 = self.next_block(75)
@@ -1160,7 +1160,7 @@ class FullBlockTest(BitcoinTestFramework):
b89a = self.next_block("89a", spend=out[32])
tx = self.create_tx(tx1, 0, 0, CScript([OP_TRUE]))
b89a = self.update_block("89a", [tx])
- self.sync_blocks([b89a], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
+ self.sync_blocks([b89a], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
self.log.info("Test a re-org of one week's worth of blocks (1088 blocks)")
diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py
index 15b2d7f757..b675cd882f 100755
--- a/test/functional/mining_basic.py
+++ b/test/functional/mining_basic.py
@@ -188,7 +188,7 @@ class MiningTest(BitcoinTestFramework):
# Should ask for the block from a p2p node, if they announce the header as well:
node.add_p2p_connection(P2PDataStore())
node.p2p.wait_for_getheaders(timeout=5) # Drop the first getheaders
- node.p2p.send_blocks_and_test(blocks=[block], rpc=node)
+ node.p2p.send_blocks_and_test(blocks=[block], node=node)
# Must be active now:
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()
diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py
index e910bedd09..8036f65d81 100755
--- a/test/functional/p2p_invalid_block.py
+++ b/test/functional/p2p_invalid_block.py
@@ -42,7 +42,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
# Save the coinbase for later
block1 = block
tip = block.sha256
- node.p2p.send_blocks_and_test([block1], node, True)
+ node.p2p.send_blocks_and_test([block1], node, success=True)
self.log.info("Mature the block.")
node.generate(100)
@@ -79,7 +79,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
assert_equal(orig_hash, block2.rehash())
assert(block2_orig.vtx != block2.vtx)
- node.p2p.send_blocks_and_test([block2], node, False, False, 16, b'bad-txns-duplicate')
+ node.p2p.send_blocks_and_test([block2], node, success=False, request_block=False, reject_code=16, reject_reason=b'bad-txns-duplicate')
self.log.info("Test very broken block.")
@@ -92,7 +92,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
block3.rehash()
block3.solve()
- node.p2p.send_blocks_and_test([block3], node, False, False, 16, b'bad-cb-amount')
+ node.p2p.send_blocks_and_test([block3], node, success=False, request_block=False, reject_code=16, reject_reason=b'bad-cb-amount')
if __name__ == '__main__':
InvalidBlockRequestTest().main()
diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
index be79a13237..45dc2928d3 100755
--- a/test/functional/p2p_segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -119,7 +119,7 @@ def get_virtual_size(witness_block):
vsize = int((3 * base_size + total_size + 3) / 4)
return vsize
-def test_transaction_acceptance(rpc, p2p, tx, with_witness, accepted, reason=None):
+def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None):
"""Send a transaction to the node and check that it's accepted to the mempool
- Submit the transaction over the p2p interface
@@ -129,13 +129,13 @@ def test_transaction_acceptance(rpc, p2p, tx, with_witness, accepted, reason=Non
tx_message = msg_witness_tx(tx)
p2p.send_message(tx_message)
p2p.sync_with_ping()
- assert_equal(tx.hash in rpc.getrawmempool(), accepted)
+ assert_equal(tx.hash in node.getrawmempool(), accepted)
if (reason is not None and not accepted):
# Check the rejection reason as well.
with mininode_lock:
assert_equal(p2p.last_message["reject"].reason, reason)
-def test_witness_block(rpc, p2p, block, accepted, with_witness=True, reason=None):
+def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=None):
"""Send a block to the node and check that it's accepted
- Submit the block over the p2p interface
@@ -145,7 +145,7 @@ def test_witness_block(rpc, p2p, block, accepted, with_witness=True, reason=None
else:
p2p.send_message(msg_block(block))
p2p.sync_with_ping()
- assert_equal(rpc.getbestblockhash() == block.hash, accepted)
+ assert_equal(node.getbestblockhash() == block.hash, accepted)
if (reason is not None and not accepted):
# Check the rejection reason as well.
with mininode_lock:
@@ -349,7 +349,7 @@ class SegWitTest(BitcoinTestFramework):
self.update_witness_block_with_transactions(block, [tx])
# Sending witness data before activation is not allowed (anti-spam
# rule).
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
wait_until(lambda: 'reject' in self.test_node.last_message and self.test_node.last_message["reject"].reason == b"unexpected-witness")
# But it should not be permanently marked bad...
@@ -380,20 +380,20 @@ class SegWitTest(BitcoinTestFramework):
self.test_node.announce_block_and_wait_for_getdata(block1, use_header=False)
assert(self.test_node.last_message["getdata"].inv[0].type == blocktype)
- test_witness_block(self.nodes[0].rpc, self.test_node, block1, True)
+ test_witness_block(self.nodes[0], self.test_node, block1, True)
block2 = self.build_next_block(version=4)
block2.solve()
self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True)
assert(self.test_node.last_message["getdata"].inv[0].type == blocktype)
- test_witness_block(self.nodes[0].rpc, self.test_node, block2, True)
+ test_witness_block(self.nodes[0], self.test_node, block2, True)
block3 = self.build_next_block(version=(VB_TOP_BITS | (1 << 15)))
block3.solve()
self.test_node.announce_block_and_wait_for_getdata(block3, use_header=True)
assert(self.test_node.last_message["getdata"].inv[0].type == blocktype)
- test_witness_block(self.nodes[0].rpc, self.test_node, block3, True)
+ test_witness_block(self.nodes[0], self.test_node, block3, True)
# Check that we can getdata for witness blocks or regular blocks,
# and the right thing happens.
@@ -423,7 +423,7 @@ class SegWitTest(BitcoinTestFramework):
# This gives us a witness commitment.
assert(len(block.vtx[0].wit.vtxinwit) == 1)
assert(len(block.vtx[0].wit.vtxinwit[0].scriptWitness.stack) == 1)
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Now try to retrieve it...
rpc_block = self.nodes[0].getblock(block.hash, False)
non_wit_block = self.test_node.request_block(block.sha256, 2)
@@ -640,11 +640,11 @@ class SegWitTest(BitcoinTestFramework):
# its from)
assert_equal(len(self.nodes[0].getrawmempool()), 0)
assert_equal(len(self.nodes[1].getrawmempool()), 0)
- test_transaction_acceptance(self.nodes[0].rpc, self.old_node, tx, with_witness=True, accepted=False)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.old_node, tx, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=False)
# But eliminating the witness should fix it
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=False, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
# Cleanup: mine the first transaction and update utxo
self.nodes[0].generate(1)
@@ -674,7 +674,7 @@ class SegWitTest(BitcoinTestFramework):
p2sh_tx.rehash()
# Mine it on test_node to create the confirmed output.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2sh_tx, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -689,7 +689,7 @@ class SegWitTest(BitcoinTestFramework):
# This is always accepted, since the mempool policy is to consider segwit as always active
# and thus allow segwit outputs
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx, with_witness=True, accepted=True)
# Now create something that looks like a P2PKH output. This won't be spendable.
script_pubkey = CScript([OP_0, hash160(witness_hash)])
@@ -701,7 +701,7 @@ class SegWitTest(BitcoinTestFramework):
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_program]
tx2.rehash()
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx2, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx2, with_witness=True, accepted=True)
# Now update self.utxo for later tests.
tx3 = CTransaction()
@@ -723,7 +723,7 @@ class SegWitTest(BitcoinTestFramework):
tx3.vout = [tx3_out]
tx3.rehash()
assert_equal(self.nodes[0].testmempoolaccept([bytes_to_hex_str(tx3.serialize_with_witness())]), [{'txid': tx3.hash, 'allowed': True}])
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -760,10 +760,10 @@ class SegWitTest(BitcoinTestFramework):
tx.rehash()
# Verify mempool acceptance and block validity
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=False, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True, with_witness=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True, with_witness=True)
sync_blocks(self.nodes)
# Now test attempts to spend the output.
@@ -777,12 +777,12 @@ class SegWitTest(BitcoinTestFramework):
# will require a witness to spend a witness program regardless of
# segwit activation. Note that older bitcoind's that are not
# segwit-aware would also reject this for failing CLEANSTACK.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, spend_tx, with_witness=False, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False)
# Try to put the witness script in the script_sig, should also fail.
spend_tx.vin[0].script_sig = CScript([p2wsh_pubkey, b'a'])
spend_tx.rehash()
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, spend_tx, with_witness=False, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False)
# Now put the witness script in the witness, should succeed after
# segwit activates.
@@ -792,7 +792,7 @@ class SegWitTest(BitcoinTestFramework):
spend_tx.wit.vtxinwit[0].scriptWitness.stack = [b'a', witness_program]
# Verify mempool acceptance
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, spend_tx, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=True, accepted=True)
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [spend_tx])
@@ -800,7 +800,7 @@ class SegWitTest(BitcoinTestFramework):
# This no longer works before activation, because SCRIPT_VERIFY_WITNESS
# is always set.
# TODO: rewrite this test to make clear that it only works after activation.
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Update self.utxo
self.utxo.pop(0)
@@ -821,7 +821,7 @@ class SegWitTest(BitcoinTestFramework):
assert(msg_witness_block(block).serialize() != msg_block(block).serialize())
# This empty block should be valid.
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Try to tweak the nonce
block_2 = self.build_next_block()
@@ -832,7 +832,7 @@ class SegWitTest(BitcoinTestFramework):
assert(block_2.vtx[0].vout[-1] != block.vtx[0].vout[-1])
# This should also be valid.
- test_witness_block(self.nodes[0].rpc, self.test_node, block_2, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_2, accepted=True)
# Now test commitments with actual transactions
tx = CTransaction()
@@ -864,7 +864,7 @@ class SegWitTest(BitcoinTestFramework):
block_3.rehash()
block_3.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block_3, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block_3, accepted=False)
# Add a different commitment with different nonce, but in the
# right location, and with some funds burned(!).
@@ -878,7 +878,7 @@ class SegWitTest(BitcoinTestFramework):
block_3.rehash()
assert(len(block_3.vtx[0].vout) == 4) # 3 OP_returns
block_3.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block_3, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_3, accepted=True)
# Finally test that a block with no witness transactions can
# omit the commitment.
@@ -890,7 +890,7 @@ class SegWitTest(BitcoinTestFramework):
block_4.vtx.append(tx3)
block_4.hashMerkleRoot = block_4.calc_merkle_root()
block_4.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block_4, with_witness=False, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_4, with_witness=False, accepted=True)
# Update available utxo's for use in later test.
self.utxo.pop(0)
@@ -930,11 +930,11 @@ class SegWitTest(BitcoinTestFramework):
# Change the nonce -- should not cause the block to be permanently
# failed
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack = [ser_uint256(1)]
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Changing the witness reserved value doesn't change the block hash
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack = [ser_uint256(0)]
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
@subtest
def test_witness_block_size(self):
@@ -998,7 +998,7 @@ class SegWitTest(BitcoinTestFramework):
# limit
assert(len(block.serialize(True)) > 2 * 1024 * 1024)
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now resize the second transaction to make the block fit.
cur_length = len(block.vtx[-1].wit.vtxinwit[0].scriptWitness.stack[0])
@@ -1008,7 +1008,7 @@ class SegWitTest(BitcoinTestFramework):
block.solve()
assert(get_virtual_size(block) == MAX_BLOCK_BASE_SIZE)
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Update available utxo's
self.utxo.pop(0)
@@ -1071,7 +1071,7 @@ class SegWitTest(BitcoinTestFramework):
self.update_witness_block_with_transactions(block, [tx])
# Extra witness data should not be allowed.
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Try extra signature data. Ok if we're not spending a witness output.
block.vtx[1].wit.vtxinwit = []
@@ -1080,7 +1080,7 @@ class SegWitTest(BitcoinTestFramework):
add_witness_commitment(block)
block.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Now try extra witness/signature data on an input that DOES require a
# witness
@@ -1096,7 +1096,7 @@ class SegWitTest(BitcoinTestFramework):
self.update_witness_block_with_transactions(block, [tx2])
# This has extra witness data, so it should fail.
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now get rid of the extra witness, but add extra scriptSig data
tx2.vin[0].scriptSig = CScript([OP_TRUE])
@@ -1108,7 +1108,7 @@ class SegWitTest(BitcoinTestFramework):
block.solve()
# This has extra signature data for a witness input, so it should fail.
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now get rid of the extra scriptsig on the witness input, and verify
# success (even with extra scriptsig data in the non-witness input)
@@ -1117,7 +1117,7 @@ class SegWitTest(BitcoinTestFramework):
add_witness_commitment(block)
block.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Update utxo for later tests
self.utxo.pop(0)
@@ -1147,14 +1147,14 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
self.update_witness_block_with_transactions(block, [tx, tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now reduce the length of the stack element
tx2.wit.vtxinwit[0].scriptWitness.stack[0] = b'a' * (MAX_SCRIPT_ELEMENT_SIZE)
add_witness_commitment(block)
block.solve()
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Update the utxo for later tests
self.utxo.pop()
@@ -1188,7 +1188,7 @@ class SegWitTest(BitcoinTestFramework):
self.update_witness_block_with_transactions(block, [tx, tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Try again with one less byte in the witness program
witness_program = CScript([b'a' * 520] * 19 + [OP_DROP] * 62 + [OP_TRUE])
@@ -1203,7 +1203,7 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
block.vtx = [block.vtx[0]]
self.update_witness_block_with_transactions(block, [tx, tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
self.utxo.pop()
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
@@ -1227,7 +1227,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Try various ways to spend tx that should all break.
# This "broken" transaction serializer will not normalize
@@ -1262,7 +1262,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now try using a too short vtxinwit
tx2.wit.vtxinwit.pop()
@@ -1270,7 +1270,7 @@ class SegWitTest(BitcoinTestFramework):
block.vtx = [block.vtx[0]]
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now make one of the intermediate witnesses be incorrect
tx2.wit.vtxinwit.append(CTxInWitness())
@@ -1279,13 +1279,13 @@ class SegWitTest(BitcoinTestFramework):
block.vtx = [block.vtx[0]]
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Fix the broken witness and the block should be accepted.
tx2.wit.vtxinwit[5].scriptWitness.stack = [b'a', witness_program]
block.vtx = [block.vtx[0]]
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
self.utxo.pop()
self.utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
@@ -1314,11 +1314,11 @@ class SegWitTest(BitcoinTestFramework):
# Verify that unnecessary witnesses are rejected.
self.test_node.announce_tx_and_wait_for_getdata(tx)
assert_equal(len(self.nodes[0].getrawmempool()), 0)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=False)
# Verify that removing the witness succeeds.
self.test_node.announce_tx_and_wait_for_getdata(tx)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=False, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
# Now try to add extra witness data to a valid witness tx.
witness_program = CScript([OP_TRUE])
@@ -1343,24 +1343,24 @@ class SegWitTest(BitcoinTestFramework):
# Node will not be blinded to the transaction
self.std_node.announce_tx_and_wait_for_getdata(tx3)
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx3, True, False, b'tx-size')
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx3, True, False, b'tx-size')
self.std_node.announce_tx_and_wait_for_getdata(tx3)
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx3, True, False, b'tx-size')
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx3, True, False, b'tx-size')
# Remove witness stuffing, instead add extra witness push on stack
tx3.vout[0] = CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_program]
tx3.rehash()
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx2, with_witness=True, accepted=True)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx2, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=False)
# Get rid of the extra witness, and verify acceptance.
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program]
# Also check that old_node gets a tx announcement, even though this is
# a witness transaction.
self.old_node.wait_for_inv([CInv(1, tx2.sha256)]) # wait until tx2 was inv'ed
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)
self.old_node.wait_for_inv([CInv(1, tx3.sha256)])
# Test that getrawtransaction returns correct witness information
@@ -1400,7 +1400,7 @@ class SegWitTest(BitcoinTestFramework):
tx.rehash()
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
self.utxo.pop(0)
for i in range(NUM_SEGWIT_VERSIONS):
self.utxo.append(UTXO(tx.sha256, i, split_value))
@@ -1417,8 +1417,8 @@ class SegWitTest(BitcoinTestFramework):
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")]
tx.vout = [CTxOut(self.utxo[0].nValue - 1000, script_pubkey)]
tx.rehash()
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx, with_witness=True, accepted=False)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=True)
self.utxo.pop(0)
temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))
@@ -1437,8 +1437,8 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
# Gets accepted to test_node, because standardness of outputs isn't
# checked with fRequireStandard
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx2, with_witness=True, accepted=True)
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx2, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx2, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx2, with_witness=True, accepted=False)
temp_utxo.pop() # last entry in temp_utxo was the output we just spent
temp_utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
@@ -1454,7 +1454,7 @@ class SegWitTest(BitcoinTestFramework):
tx3.rehash()
# Spending a higher version witness output is not allowed by policy,
# even with fRequireStandard=false.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=False)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=False)
self.test_node.sync_with_ping()
with mininode_lock:
assert(b"reserved for soft-fork upgrades" in self.test_node.last_message["reject"].reason)
@@ -1462,7 +1462,7 @@ class SegWitTest(BitcoinTestFramework):
# Building a block with the transaction must be valid, however.
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx2, tx3])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes)
# Add utxo to our list
@@ -1480,7 +1480,7 @@ class SegWitTest(BitcoinTestFramework):
# This next line will rehash the coinbase and update the merkle
# root, and solve.
self.update_witness_block_with_transactions(block, [])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
spend_tx = CTransaction()
spend_tx.vin = [CTxIn(COutPoint(block.vtx[0].sha256, 0), b"")]
@@ -1494,13 +1494,13 @@ class SegWitTest(BitcoinTestFramework):
sync_blocks(self.nodes)
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block2, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block2, accepted=False)
# Advancing one more block should allow the spend.
self.nodes[0].generate(1)
block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block2, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block2, accepted=True)
sync_blocks(self.nodes)
@subtest
@@ -1532,7 +1532,7 @@ class SegWitTest(BitcoinTestFramework):
# Confirm it in a block.
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Now try to spend it. Send it to a P2WSH output, which we'll
# use in the next test.
@@ -1551,11 +1551,11 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
# Should fail policy test.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx2, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx2, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
# But passes consensus.
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Test 2: P2WSH
# Try to spend the P2WSH output created in last test.
@@ -1571,11 +1571,11 @@ class SegWitTest(BitcoinTestFramework):
sign_p2pk_witness_input(witness_program, tx3, 0, SIGHASH_ALL, tx2.vout[0].nValue, key)
# Should fail policy test.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
# But passes consensus.
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx3])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Test 3: P2SH(P2WSH)
# Try to spend the P2SH output created in the last test.
@@ -1588,10 +1588,10 @@ class SegWitTest(BitcoinTestFramework):
sign_p2pk_witness_input(witness_program, tx4, 0, SIGHASH_ALL, tx3.vout[0].nValue, key)
# Should fail policy test.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx4, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx4, True, False, b'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)')
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx4])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Test 4: Uncompressed pubkeys should still be valid in non-segwit
# transactions.
@@ -1603,10 +1603,10 @@ class SegWitTest(BitcoinTestFramework):
tx5.vin[0].scriptSig = CScript([signature, pubkey])
tx5.rehash()
# Should pass policy and consensus.
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx5, True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx5, True, True)
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx5])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
self.utxo.append(UTXO(tx5.sha256, 0, tx5.vout[0].nValue))
@subtest
@@ -1626,11 +1626,11 @@ class SegWitTest(BitcoinTestFramework):
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
tx.rehash()
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=True, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=True, accepted=True)
# Mine this transaction in preparation for following tests.
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes)
self.utxo.pop(0)
@@ -1647,19 +1647,19 @@ class SegWitTest(BitcoinTestFramework):
# Too-large input value
sign_p2pk_witness_input(witness_program, tx, 0, hashtype, prev_utxo.nValue + 1, key)
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Too-small input value
sign_p2pk_witness_input(witness_program, tx, 0, hashtype, prev_utxo.nValue - 1, key)
block.vtx.pop() # remove last tx
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Now try correct value
sign_p2pk_witness_input(witness_program, tx, 0, hashtype, prev_utxo.nValue, key)
block.vtx.pop()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
prev_utxo = UTXO(tx.sha256, 0, tx.vout[0].nValue)
@@ -1683,7 +1683,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
block = self.build_next_block()
used_sighash_single_out_of_bounds = False
@@ -1725,7 +1725,7 @@ class SegWitTest(BitcoinTestFramework):
# Test the block periodically, if we're close to maxblocksize
if (get_virtual_size(block) > MAX_BLOCK_BASE_SIZE - 1000):
self.update_witness_block_with_transactions(block, [])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
block = self.build_next_block()
if (not used_sighash_single_out_of_bounds):
@@ -1733,7 +1733,7 @@ class SegWitTest(BitcoinTestFramework):
# Test the transactions we've added to the block
if (len(block.vtx) > 1):
self.update_witness_block_with_transactions(block, [])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
# Now test witness version 0 P2PKH transactions
pubkeyhash = hash160(pubkey)
@@ -1755,7 +1755,7 @@ class SegWitTest(BitcoinTestFramework):
tx2.vin[0].scriptSig = CScript([signature, pubkey])
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx, tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
# Move the signature to the witness.
block.vtx.pop()
@@ -1765,7 +1765,7 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
self.update_witness_block_with_transactions(block, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
temp_utxos.pop(0)
@@ -1786,7 +1786,7 @@ class SegWitTest(BitcoinTestFramework):
index += 1
block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
for i in range(len(tx.vout)):
self.utxo.append(UTXO(tx.sha256, i, tx.vout[i].nValue))
@@ -1808,7 +1808,7 @@ class SegWitTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))
tx.rehash()
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, False, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -1825,18 +1825,18 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
# This will be rejected due to a policy check:
# No witness is allowed, since it is not a witness program but a p2sh program
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx2, True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx2, True, False, b'bad-witness-nonstandard')
# If we send without witness, it should be accepted.
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx2, False, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx2, False, True)
# Now create a new anyone-can-spend utxo for the next test.
tx3 = CTransaction()
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), CScript([p2sh_program])))
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx3.rehash()
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx2, False, True)
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, False, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx2, False, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -1872,7 +1872,7 @@ class SegWitTest(BitcoinTestFramework):
tx.vout.append(CTxOut(outputvalue, CScript([OP_HASH160, p2sh, OP_EQUAL])))
tx.rehash()
txid = tx.sha256
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=False, accepted=True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
self.nodes[0].generate(1)
sync_blocks(self.nodes)
@@ -1897,45 +1897,45 @@ class SegWitTest(BitcoinTestFramework):
# Testing native P2WSH
# Witness stack size, excluding witnessScript, over 100 is non-standard
p2wsh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * 101 + [scripts[0]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2wsh_txs[0], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[0], True, False, b'bad-witness-nonstandard')
# Non-standard nodes should accept
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2wsh_txs[0], True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[0], True, True)
# Stack element size over 80 bytes is non-standard
p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 81] * 100 + [scripts[1]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2wsh_txs[1], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[1], True, False, b'bad-witness-nonstandard')
# Non-standard nodes should accept
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2wsh_txs[1], True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[1], True, True)
# Standard nodes should accept if element size is not over 80 bytes
p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 80] * 100 + [scripts[1]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2wsh_txs[1], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[1], True, True)
# witnessScript size at 3600 bytes is standard
p2wsh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[2]]
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2wsh_txs[2], True, True)
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2wsh_txs[2], True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[2], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[2], True, True)
# witnessScript size at 3601 bytes is non-standard
p2wsh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, pad, scripts[3]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2wsh_txs[3], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[3], True, False, b'bad-witness-nonstandard')
# Non-standard nodes should accept
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2wsh_txs[3], True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[3], True, True)
# Repeating the same tests with P2SH-P2WSH
p2sh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * 101 + [scripts[0]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2sh_txs[0], True, False, b'bad-witness-nonstandard')
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2sh_txs[0], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[0], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[0], True, True)
p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 81] * 100 + [scripts[1]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2sh_txs[1], True, False, b'bad-witness-nonstandard')
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2sh_txs[1], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[1], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[1], True, True)
p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 80] * 100 + [scripts[1]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2sh_txs[1], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[1], True, True)
p2sh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[2]]
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2sh_txs[2], True, True)
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2sh_txs[2], True, True)
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[2], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[2], True, True)
p2sh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, pad, scripts[3]]
- test_transaction_acceptance(self.nodes[1].rpc, self.std_node, p2sh_txs[3], True, False, b'bad-witness-nonstandard')
- test_transaction_acceptance(self.nodes[0].rpc, self.test_node, p2sh_txs[3], True, True)
+ test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[3], True, False, b'bad-witness-nonstandard')
+ test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[3], True, True)
self.nodes[0].generate(1) # Mine and clean up the mempool of non-standard node
# Valid but non-standard transactions in a block should be accepted by standard node
@@ -2011,7 +2011,7 @@ class SegWitTest(BitcoinTestFramework):
block_1 = self.build_next_block()
self.update_witness_block_with_transactions(block_1, [tx])
- test_witness_block(self.nodes[0].rpc, self.test_node, block_1, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_1, accepted=True)
tx2 = CTransaction()
# If we try to spend the first n-1 outputs from tx, that should be
@@ -2028,7 +2028,7 @@ class SegWitTest(BitcoinTestFramework):
block_2 = self.build_next_block()
self.update_witness_block_with_transactions(block_2, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block_2, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block_2, accepted=False)
# Try dropping the last input in tx2, and add an output that has
# too many sigops (contributing to legacy sigop count).
@@ -2041,14 +2041,14 @@ class SegWitTest(BitcoinTestFramework):
tx2.rehash()
block_3 = self.build_next_block()
self.update_witness_block_with_transactions(block_3, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block_3, accepted=False)
+ test_witness_block(self.nodes[0], self.test_node, block_3, accepted=False)
# If we drop the last checksig in this output, the tx should succeed.
block_4 = self.build_next_block()
tx2.vout[-1].scriptPubKey = CScript([OP_CHECKSIG] * (checksig_count - 1))
tx2.rehash()
self.update_witness_block_with_transactions(block_4, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block_4, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_4, accepted=True)
# Reset the tip back down for the next test
sync_blocks(self.nodes)
@@ -2064,7 +2064,7 @@ class SegWitTest(BitcoinTestFramework):
tx2.wit.vtxinwit[-1].scriptWitness.stack = [witness_program_justright]
tx2.rehash()
self.update_witness_block_with_transactions(block_5, [tx2])
- test_witness_block(self.nodes[0].rpc, self.test_node, block_5, accepted=True)
+ test_witness_block(self.nodes[0], self.test_node, block_5, accepted=True)
# TODO: test p2sh sigop counting
diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py
index deffe4e6bd..32088fe3e1 100755
--- a/test/functional/rpc_deprecated.py
+++ b/test/functional/rpc_deprecated.py
@@ -4,13 +4,12 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test deprecation of RPC calls."""
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_raises_rpc_error
class DeprecatedRpcTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
- self.extra_args = [[], ["-deprecatedrpc=validateaddress", "-deprecatedrpc=accounts"]]
+ self.extra_args = [[], ["-deprecatedrpc=validateaddress"]]
def run_test(self):
# This test should be used to verify correct behaviour of deprecated
@@ -27,82 +26,5 @@ class DeprecatedRpcTest(BitcoinTestFramework):
not_dep_val = self.nodes[1].validateaddress(SOME_ADDRESS)
assert "ismine" in not_dep_val
- self.log.info("Test accounts deprecation")
- # The following account RPC methods are deprecated:
- # - getaccount
- # - getaccountaddress
- # - getaddressesbyaccount
- # - getreceivedbyaccount
- # - listaccouts
- # - listreceivedbyaccount
- # - move
- # - setaccount
- #
- # The following 'label' RPC methods are usable both with and without the
- # -deprecatedrpc=accounts switch enabled.
- # - getaddressesbylabel
- # - getreceivedbylabel
- # - listlabels
- # - listreceivedbylabel
- # - setlabel
- #
- address0 = self.nodes[0].getnewaddress()
- self.nodes[0].generatetoaddress(101, address0)
- self.sync_all()
- address1 = self.nodes[1].getnewaddress()
- self.nodes[1].generatetoaddress(101, address1)
-
- self.log.info("- getaccount")
- assert_raises_rpc_error(-32, "getaccount is deprecated", self.nodes[0].getaccount, address0)
- self.nodes[1].getaccount(address1)
-
- self.log.info("- setaccount")
- assert_raises_rpc_error(-32, "setaccount is deprecated", self.nodes[0].setaccount, address0, "label0")
- self.nodes[1].setaccount(address1, "label1")
-
- self.log.info("- setlabel")
- self.nodes[0].setlabel(address0, "label0")
- self.nodes[1].setlabel(address1, "label1")
-
- self.log.info("- getaccountaddress")
- assert_raises_rpc_error(-32, "getaccountaddress is deprecated", self.nodes[0].getaccountaddress, "label0")
- self.nodes[1].getaccountaddress("label1")
-
- self.log.info("- getaddressesbyaccount")
- assert_raises_rpc_error(-32, "getaddressesbyaccount is deprecated", self.nodes[0].getaddressesbyaccount, "label0")
- self.nodes[1].getaddressesbyaccount("label1")
-
- self.log.info("- getaddressesbylabel")
- self.nodes[0].getaddressesbylabel("label0")
- self.nodes[1].getaddressesbylabel("label1")
-
- self.log.info("- getreceivedbyaccount")
- assert_raises_rpc_error(-32, "getreceivedbyaccount is deprecated", self.nodes[0].getreceivedbyaccount, "label0")
- self.nodes[1].getreceivedbyaccount("label1")
-
- self.log.info("- getreceivedbylabel")
- self.nodes[0].getreceivedbylabel("label0")
- self.nodes[1].getreceivedbylabel("label1")
-
- self.log.info("- listaccounts")
- assert_raises_rpc_error(-32, "listaccounts is deprecated", self.nodes[0].listaccounts)
- self.nodes[1].listaccounts()
-
- self.log.info("- listlabels")
- self.nodes[0].listlabels()
- self.nodes[1].listlabels()
-
- self.log.info("- listreceivedbyaccount")
- assert_raises_rpc_error(-32, "listreceivedbyaccount is deprecated", self.nodes[0].listreceivedbyaccount)
- self.nodes[1].listreceivedbyaccount()
-
- self.log.info("- listreceivedbylabel")
- self.nodes[0].listreceivedbylabel()
- self.nodes[1].listreceivedbylabel()
-
- self.log.info("- move")
- assert_raises_rpc_error(-32, "move is deprecated", self.nodes[0].move, "label0", "label0b", 10)
- self.nodes[1].move("label1", "label1b", 10)
-
if __name__ == '__main__':
DeprecatedRpcTest().main()
diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py
new file mode 100755
index 0000000000..e878ded258
--- /dev/null
+++ b/test/functional/rpc_help.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Test RPC help output."""
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import assert_equal, assert_raises_rpc_error
+
+class HelpRpcTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 1
+
+ def run_test(self):
+ node = self.nodes[0]
+
+ # wrong argument count
+ assert_raises_rpc_error(-1, 'help', node.help, 'foo', 'bar')
+
+ # invalid argument
+ assert_raises_rpc_error(-1, 'JSON value is not a string as expected', node.help, 0)
+
+ # help of unknown command
+ assert_equal(node.help('foo'), 'help: unknown command: foo')
+
+ # command titles
+ titles = [line[3:-3] for line in node.help().splitlines() if line.startswith('==')]
+ assert_equal(titles, ['Blockchain', 'Control', 'Generating', 'Mining', 'Network', 'Rawtransactions', 'Util', 'Wallet', 'Zmq'])
+
+if __name__ == '__main__':
+ HelpRpcTest().main()
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
index 02114eca76..a46518200c 100755
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -7,6 +7,8 @@
Tests correspond to code in rpc/net.cpp.
"""
+from decimal import Decimal
+
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
@@ -21,6 +23,7 @@ class NetTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
+ self.extra_args = [["-minrelaytxfee=0.00001000"],["-minrelaytxfee=0.00000500"]]
def run_test(self):
self._test_connection_count()
@@ -95,6 +98,8 @@ class NetTest(BitcoinTestFramework):
# the address bound to on one side will be the source address for the other node
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr'])
assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr'])
+ assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
+ assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
if __name__ == '__main__':
NetTest().main()
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index f847a01e59..d558de5fe1 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -143,17 +143,19 @@ class PSBTTest(BitcoinTestFramework):
# replaceable arg
block_height = self.nodes[0].getblockcount()
unspent = self.nodes[0].listunspent()[0]
- psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"replaceable":True})
+ psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"replaceable":True}, False)
decoded_psbt = self.nodes[0].decodepsbt(psbtx_info["psbt"])
- for tx_in in decoded_psbt["tx"]["vin"]:
+ for tx_in, psbt_in in zip(decoded_psbt["tx"]["vin"], decoded_psbt["inputs"]):
assert_equal(tx_in["sequence"], MAX_BIP125_RBF_SEQUENCE)
+ assert "bip32_derivs" not in psbt_in
assert_equal(decoded_psbt["tx"]["locktime"], block_height+2)
# Same construction with only locktime set
- psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height)
+ psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height, {}, True)
decoded_psbt = self.nodes[0].decodepsbt(psbtx_info["psbt"])
- for tx_in in decoded_psbt["tx"]["vin"]:
+ for tx_in, psbt_in in zip(decoded_psbt["tx"]["vin"], decoded_psbt["inputs"]):
assert tx_in["sequence"] > MAX_BIP125_RBF_SEQUENCE
+ assert "bip32_derivs" in psbt_in
assert_equal(decoded_psbt["tx"]["locktime"], block_height)
# Same construction without optional arguments
diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
index 1e3ada26f8..8169f2b981 100755
--- a/test/functional/rpc_rawtransaction.py
+++ b/test/functional/rpc_rawtransaction.py
@@ -358,7 +358,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# decoderawtransaction tests
# witness transaction
- encrawtx = "010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000000000000"
+ encrawtx = "010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000"
decrawtx = self.nodes[0].decoderawtransaction(encrawtx, True) # decode as witness transaction
assert_equal(decrawtx['vout'][0]['value'], Decimal('1.00000000'))
assert_raises_rpc_error(-22, 'TX decode failed', self.nodes[0].decoderawtransaction, encrawtx, False) # force decode as non-witness transaction
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index d1ddbbe8ee..034e83aaae 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -482,7 +482,7 @@ class P2PDataStore(P2PInterface):
self.reject_code_received = message.code
self.reject_reason_received = message.reason
- def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
+ def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
"""Send blocks to test node and test whether the tip advances.
- add all blocks to our block_store
@@ -508,16 +508,16 @@ class P2PDataStore(P2PInterface):
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
if success:
- wait_until(lambda: rpc.getbestblockhash() == blocks[-1].hash, timeout=timeout)
+ wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
else:
- assert rpc.getbestblockhash() != blocks[-1].hash
+ assert node.getbestblockhash() != blocks[-1].hash
if reject_code is not None:
wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock)
if reject_reason is not None:
wait_until(lambda: self.reject_reason_received == reject_reason, lock=mininode_lock)
- def send_txs_and_test(self, txs, rpc, success=True, expect_disconnect=False, reject_code=None, reject_reason=None):
+ def send_txs_and_test(self, txs, node, *, success=True, expect_disconnect=False, reject_code=None, reject_reason=None):
"""Send txs to test node and test whether they're accepted to the mempool.
- add all txs to our tx_store
@@ -541,7 +541,7 @@ class P2PDataStore(P2PInterface):
else:
self.sync_with_ping()
- raw_mempool = rpc.getrawmempool()
+ raw_mempool = node.getrawmempool()
if success:
# Check that all txs are now in the mempool
for tx in txs:
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index feea2a327a..13c687fd92 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -152,6 +152,7 @@ BASE_SCRIPTS = [
'p2p_node_network_limited.py',
'feature_blocksdir.py',
'feature_config_args.py',
+ 'rpc_help.py',
'feature_help.py',
# Don't append tests at the end to avoid merge conflicts
# Put them in a random line within the section that fits their approximate run-time
diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py
index 01c7b6366a..30851893b8 100755
--- a/test/functional/wallet_address_types.py
+++ b/test/functional/wallet_address_types.py
@@ -143,7 +143,7 @@ class AddressTypeTest(BitcoinTestFramework):
assert(False)
def test_change_output_type(self, node_sender, destinations, expected_type):
- txid = self.nodes[node_sender].sendmany(fromaccount="", amounts=dict.fromkeys(destinations, 0.001))
+ txid = self.nodes[node_sender].sendmany(dummy="", amounts=dict.fromkeys(destinations, 0.001))
raw_tx = self.nodes[node_sender].getrawtransaction(txid)
tx = self.nodes[node_sender].decoderawtransaction(raw_tx)
diff --git a/test/functional/wallet_labels.py b/test/functional/wallet_labels.py
index 0817054149..01a73d9cef 100755
--- a/test/functional/wallet_labels.py
+++ b/test/functional/wallet_labels.py
@@ -5,15 +5,9 @@
"""Test label RPCs.
RPCs tested are:
- - getaccountaddress
- - getaddressesbyaccount/getaddressesbylabel
+ - getaddressesbylabel
- listaddressgroupings
- setlabel
- - sendfrom (with account arguments)
- - move (with account arguments)
-
-Run the test twice - once using the accounts API and once using the labels API.
-The accounts API test can be removed in V0.18.
"""
from collections import defaultdict
@@ -23,22 +17,11 @@ from test_framework.util import assert_equal, assert_raises_rpc_error
class WalletLabelsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
- self.num_nodes = 2
- self.extra_args = [['-deprecatedrpc=accounts'], []]
-
- def setup_network(self):
- """Don't connect nodes."""
- self.setup_nodes()
+ self.num_nodes = 1
def run_test(self):
- """Run the test twice - once using the accounts API and once using the labels API."""
- self.log.info("Test accounts API")
- self._run_subtest(True, self.nodes[0])
- self.log.info("Test labels API")
- self._run_subtest(False, self.nodes[1])
-
- def _run_subtest(self, accounts_api, node):
- # Check that there's no UTXO on any of the nodes
+ # Check that there's no UTXO on the node
+ node = self.nodes[0]
assert_equal(len(node.listunspent()), 0)
# Note each time we call generate, all generated coins go into
@@ -61,17 +44,12 @@ class WalletLabelsTest(BitcoinTestFramework):
linked_addresses.add(address_group[0][0])
# send 50 from each address to a third address not in this wallet
- # There's some fee that will come back to us when the miner reward
- # matures.
common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
- txid = node.sendmany(
- fromaccount="",
+ node.sendmany(
amounts={common_address: 100},
subtractfeefrom=[common_address],
minconf=1,
)
- tx_details = node.gettransaction(txid)
- fee = -tx_details['details'][0]['fee']
# there should be 1 address group, with the previously
# unlinked addresses now linked (they both have 0 balance)
address_groups = node.listaddressgroupings()
@@ -85,32 +63,22 @@ class WalletLabelsTest(BitcoinTestFramework):
# we want to reset so that the "" label has what's expected.
# otherwise we're off by exactly the fee amount as that's mined
# and matures in the next 100 blocks
- if accounts_api:
- node.sendfrom("", common_address, fee)
amount_to_send = 1.0
# Create labels and make sure subsequent label API calls
# recognize the label/address associations.
- labels = [Label(name, accounts_api) for name in ("a", "b", "c", "d", "e")]
+ labels = [Label(name) for name in ("a", "b", "c", "d", "e")]
for label in labels:
- if accounts_api:
- address = node.getaccountaddress(label.name)
- else:
- address = node.getnewaddress(label.name)
+ address = node.getnewaddress(label.name)
label.add_receive_address(address)
label.verify(node)
# Check all labels are returned by listlabels.
assert_equal(node.listlabels(), [label.name for label in labels])
- # Send a transaction to each label, and make sure this forces
- # getaccountaddress to generate a new receiving address.
+ # Send a transaction to each label.
for label in labels:
- if accounts_api:
- node.sendtoaddress(label.receive_address, amount_to_send)
- label.add_receive_address(node.getaccountaddress(label.name))
- else:
- node.sendtoaddress(label.addresses[0], amount_to_send)
+ node.sendtoaddress(label.addresses[0], amount_to_send)
label.verify(node)
# Check the amounts received.
@@ -120,32 +88,17 @@ class WalletLabelsTest(BitcoinTestFramework):
node.getreceivedbyaddress(label.addresses[0]), amount_to_send)
assert_equal(node.getreceivedbylabel(label.name), amount_to_send)
- # Check that sendfrom label reduces listaccounts balances.
for i, label in enumerate(labels):
to_label = labels[(i + 1) % len(labels)]
- if accounts_api:
- node.sendfrom(label.name, to_label.receive_address, amount_to_send)
- else:
- node.sendtoaddress(to_label.addresses[0], amount_to_send)
+ node.sendtoaddress(to_label.addresses[0], amount_to_send)
node.generate(1)
for label in labels:
- if accounts_api:
- address = node.getaccountaddress(label.name)
- else:
- address = node.getnewaddress(label.name)
+ address = node.getnewaddress(label.name)
label.add_receive_address(address)
label.verify(node)
assert_equal(node.getreceivedbylabel(label.name), 2)
- if accounts_api:
- node.move(label.name, "", node.getbalance(label.name))
label.verify(node)
node.generate(101)
- expected_account_balances = {"": 5200}
- for label in labels:
- expected_account_balances[label.name] = 0
- if accounts_api:
- assert_equal(node.listaccounts(), expected_account_balances)
- assert_equal(node.getbalance(""), 5200)
# Check that setlabel can assign a label to a new unused address.
for label in labels:
@@ -153,10 +106,7 @@ class WalletLabelsTest(BitcoinTestFramework):
node.setlabel(address, label.name)
label.add_address(address)
label.verify(node)
- if accounts_api:
- assert address not in node.getaddressesbyaccount("")
- else:
- assert_raises_rpc_error(-11, "No addresses with label", node.getaddressesbylabel, "")
+ assert_raises_rpc_error(-11, "No addresses with label", node.getaddressesbylabel, "")
# Check that addmultisigaddress can assign labels.
for label in labels:
@@ -167,35 +117,20 @@ class WalletLabelsTest(BitcoinTestFramework):
label.add_address(multisig_address)
label.purpose[multisig_address] = "send"
label.verify(node)
- if accounts_api:
- node.sendfrom("", multisig_address, 50)
node.generate(101)
- if accounts_api:
- for label in labels:
- assert_equal(node.getbalance(label.name), 50)
# Check that setlabel can change the label of an address from a
# different label.
- change_label(node, labels[0].addresses[0], labels[0], labels[1], accounts_api)
+ change_label(node, labels[0].addresses[0], labels[0], labels[1])
# Check that setlabel can set the label of an address already
# in the label. This is a no-op.
- change_label(node, labels[2].addresses[0], labels[2], labels[2], accounts_api)
-
- if accounts_api:
- # Check that setaccount can change the label of an address which
- # is the receiving address of a different label.
- change_label(node, labels[0].receive_address, labels[0], labels[1], accounts_api)
-
- # Check that setaccount can set the label of an address which is
- # already the receiving address of the label. This is a no-op.
- change_label(node, labels[2].receive_address, labels[2], labels[2], accounts_api)
+ change_label(node, labels[2].addresses[0], labels[2], labels[2])
class Label:
- def __init__(self, name, accounts_api):
+ def __init__(self, name):
# Label name
self.name = name
- self.accounts_api = accounts_api
# Current receiving address associated with this label.
self.receive_address = None
# List of all addresses assigned with this label
@@ -209,56 +144,31 @@ class Label:
def add_receive_address(self, address):
self.add_address(address)
- if self.accounts_api:
- self.receive_address = address
def verify(self, node):
if self.receive_address is not None:
assert self.receive_address in self.addresses
- if self.accounts_api:
- assert_equal(node.getaccountaddress(self.name), self.receive_address)
for address in self.addresses:
assert_equal(
node.getaddressinfo(address)['labels'][0],
{"name": self.name,
"purpose": self.purpose[address]})
- if self.accounts_api:
- assert_equal(node.getaccount(address), self.name)
- else:
- assert_equal(node.getaddressinfo(address)['label'], self.name)
+ assert_equal(node.getaddressinfo(address)['label'], self.name)
assert_equal(
node.getaddressesbylabel(self.name),
{address: {"purpose": self.purpose[address]} for address in self.addresses})
- if self.accounts_api:
- assert_equal(set(node.getaddressesbyaccount(self.name)), set(self.addresses))
-
-def change_label(node, address, old_label, new_label, accounts_api):
+def change_label(node, address, old_label, new_label):
assert_equal(address in old_label.addresses, True)
- if accounts_api:
- node.setaccount(address, new_label.name)
- else:
- node.setlabel(address, new_label.name)
+ node.setlabel(address, new_label.name)
old_label.addresses.remove(address)
new_label.add_address(address)
- # Calling setaccount on an address which was previously the receiving
- # address of a different account should reset the receiving address of
- # the old account, causing getaccountaddress to return a brand new
- # address.
- if accounts_api:
- if old_label.name != new_label.name and address == old_label.receive_address:
- new_address = node.getaccountaddress(old_label.name)
- assert_equal(new_address not in old_label.addresses, True)
- assert_equal(new_address not in new_label.addresses, True)
- old_label.add_receive_address(new_address)
-
old_label.verify(node)
new_label.verify(node)
-
if __name__ == '__main__':
WalletLabelsTest().main()
diff --git a/test/lint/lint-includes.sh b/test/lint/lint-includes.sh
index 8f7a1fd76b..346829e24b 100755
--- a/test/lint/lint-includes.sh
+++ b/test/lint/lint-includes.sh
@@ -47,7 +47,6 @@ fi
EXPECTED_BOOST_INCLUDES=(
boost/algorithm/string.hpp
- boost/algorithm/string/case_conv.hpp
boost/algorithm/string/classification.hpp
boost/algorithm/string/replace.hpp
boost/algorithm/string/split.hpp
@@ -57,7 +56,6 @@ EXPECTED_BOOST_INCLUDES=(
boost/filesystem.hpp
boost/filesystem/detail/utf8_codecvt_facet.hpp
boost/filesystem/fstream.hpp
- boost/interprocess/sync/file_lock.hpp
boost/multi_index/hashed_index.hpp
boost/multi_index/ordered_index.hpp
boost/multi_index/sequenced_index.hpp
diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh
index cbe1143bd0..a5b97ca1e9 100755
--- a/test/lint/lint-locale-dependence.sh
+++ b/test/lint/lint-locale-dependence.sh
@@ -11,11 +11,9 @@ KNOWN_VIOLATIONS=(
"src/dbwrapper.cpp:.*vsnprintf"
"src/httprpc.cpp.*trim"
"src/init.cpp:.*atoi"
- "src/netbase.cpp.*to_lower"
"src/qt/rpcconsole.cpp:.*atoi"
"src/qt/rpcconsole.cpp:.*isdigit"
"src/rest.cpp:.*strtol"
- "src/rpc/server.cpp.*to_upper"
"src/test/dbwrapper_tests.cpp:.*snprintf"
"src/test/getarg_tests.cpp.*split"
"src/torcontrol.cpp:.*atoi"
diff --git a/test/lint/lint-shell-locale.sh b/test/lint/lint-shell-locale.sh
index 242b27c763..efd8081b8c 100755
--- a/test/lint/lint-shell-locale.sh
+++ b/test/lint/lint-shell-locale.sh
@@ -5,7 +5,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Make sure all shell scripts:
-# a.) explicitly opt out of locale dependence using "export LC_ALL=C", or
+# a.) explicitly opt out of locale dependence using
+# "export LC_ALL=C" or "export LC_ALL=C.UTF-8", or
# b.) explicitly opt in to locale dependence using the annotation below.
export LC_ALL=C
@@ -16,7 +17,7 @@ for SHELL_SCRIPT in $(git ls-files -- "*.sh" | grep -vE "src/(secp256k1|univalue
continue
fi
FIRST_NON_COMMENT_LINE=$(grep -vE '^(#.*|)$' "${SHELL_SCRIPT}" | head -1)
- if [[ ${FIRST_NON_COMMENT_LINE} != "export LC_ALL=C" ]]; then
+ if [[ ${FIRST_NON_COMMENT_LINE} != "export LC_ALL=C" && ${FIRST_NON_COMMENT_LINE} != "export LC_ALL=C.UTF-8" ]]; then
echo "Missing \"export LC_ALL=C\" (to avoid locale dependence) as first non-comment non-empty line in ${SHELL_SCRIPT}"
EXIT_CODE=1
fi