aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--contrib/debian/copyright14
-rwxr-xr-xcontrib/install_db4.sh25
-rw-r--r--depends/packages/zeromq.mk1
-rw-r--r--doc/build-osx.md2
-rw-r--r--doc/build-unix.md12
-rw-r--r--doc/developer-notes.md2
-rw-r--r--doc/files.md9
-rw-r--r--doc/release-notes.md14
-rw-r--r--src/Makefile.test.include1
-rw-r--r--src/chainparams.cpp1
-rw-r--r--src/core_io.h2
-rw-r--r--src/core_read.cpp34
-rw-r--r--src/key.cpp75
-rw-r--r--src/key.h28
-rw-r--r--src/keystore.cpp10
-rw-r--r--src/keystore.h2
-rw-r--r--src/net.cpp31
-rw-r--r--src/policy/fees.cpp68
-rw-r--r--src/pubkey.cpp33
-rw-r--r--src/pubkey.h37
-rw-r--r--src/qt/forms/sendcoinsdialog.ui4
-rw-r--r--src/qt/sendcoinsdialog.cpp14
-rw-r--r--src/qt/walletmodel.cpp5
-rw-r--r--src/qt/walletmodel.h2
-rw-r--r--src/rpc/client.cpp2
-rw-r--r--src/rpc/rawtransaction.cpp16
-rw-r--r--src/script/interpreter.cpp6
-rw-r--r--src/test/miner_tests.cpp24
-rw-r--r--src/test/rpc_tests.cpp4
-rw-r--r--src/test/univalue_tests.cpp333
-rw-r--r--src/univalue/.travis.yml1
-rw-r--r--src/univalue/test/object.cpp3
-rw-r--r--src/wallet/init.cpp7
-rw-r--r--src/wallet/rpcdump.cpp103
-rw-r--r--src/wallet/rpcwallet.cpp18
-rw-r--r--src/wallet/walletdb.cpp4
-rw-r--r--src/wallet/walletutil.cpp2
-rw-r--r--src/wallet/walletutil.h3
-rwxr-xr-xtest/functional/conf_args.py49
-rwxr-xr-xtest/functional/multiwallet.py6
-rwxr-xr-xtest/functional/node_network_limited.py88
-rwxr-xr-xtest/functional/rawtransactions.py11
-rw-r--r--test/functional/test_framework/messages.py3
-rwxr-xr-xtest/functional/test_runner.py1
-rwxr-xr-xtest/functional/wallet-dump.py44
46 files changed, 515 insertions, 642 deletions
diff --git a/configure.ac b/configure.ac
index a05896edea..f7de4c9f9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -761,6 +761,9 @@ define(MINIMUM_REQUIRED_BOOST, 1.47.0)
dnl Check for boost libs
AX_BOOST_BASE([MINIMUM_REQUIRED_BOOST])
+if test x$want_boost = xno; then
+ AC_MSG_ERROR([[only libbitcoinconsensus can be built without boost]])
+fi
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
AX_BOOST_PROGRAM_OPTIONS
diff --git a/contrib/debian/copyright b/contrib/debian/copyright
index 72d64ce62d..8e715bd9d8 100644
--- a/contrib/debian/copyright
+++ b/contrib/debian/copyright
@@ -15,6 +15,14 @@ Copyright: 2010-2011, Jonas Smedegaard <dr@jones.dk>
2011, Matt Corallo <matt@bluematt.me>
License: GPL-2+
+Files: src/secp256k1/build-aux/m4/ax_jni_include_dir.m4
+Copyright: 2008 Don Anderson <dda@sleepycat.com>
+License: GNU-All-permissive-License
+
+Files: src/secp256k1/build-aux/m4/ax_prog_cc_for_build.m4
+Copyright: 2008 Paolo Bonzini <bonzini@gnu.org>
+License: GNU-All-permissive-License
+
Files: src/qt/res/icons/add.png
src/qt/res/icons/address-book.png
src/qt/res/icons/chevron.png
@@ -106,6 +114,12 @@ License: Expat
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+License: GNU-All-permissive-License
+ Copying and distribution of this file, with or without modification, are
+ permitted in any medium without royalty provided the copyright notice
+ and this notice are preserved. This file is offered as-is, without any
+ warranty.
+
License: GPL-2+
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
diff --git a/contrib/install_db4.sh b/contrib/install_db4.sh
index 1d33e8d3ba..b57ade139d 100755
--- a/contrib/install_db4.sh
+++ b/contrib/install_db4.sh
@@ -7,7 +7,7 @@ set -e
if [ -z "${1}" ]; then
echo "Usage: ./install_db4.sh <base-dir> [<extra-bdb-configure-flag> ...]"
echo
- echo "Must specify a single argument: the directory in which db5 will be built."
+ echo "Must specify a single argument: the directory in which db4 will be built."
echo "This is probably \`pwd\` if you're at the root of the bitcoin repository."
exit 1
fi
@@ -17,7 +17,6 @@ expand_path() {
}
BDB_PREFIX="$(expand_path ${1})/db4"; shift;
-BDB_EXTRA_CONFIGURE_FLAGS="${@}"
BDB_VERSION='db-4.8.30.NC'
BDB_HASH='12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef'
BDB_URL="https://download.oracle.com/berkeley-db/${BDB_VERSION}.tar.gz"
@@ -32,7 +31,11 @@ sha256_check() {
if check_exists sha256sum; then
echo "${1} ${2}" | sha256sum -c
elif check_exists sha256; then
- echo "${1} ${2}" | sha256 -c
+ if [ "$(uname)" = "FreeBSD" ]; then
+ sha256 -c "${1}" "${2}"
+ else
+ echo "${1} ${2}" | sha256 -c
+ fi
else
echo "${1} ${2}" | shasum -a 256 -c
fi
@@ -60,21 +63,17 @@ http_get "${BDB_URL}" "${BDB_VERSION}.tar.gz" "${BDB_HASH}"
tar -xzvf ${BDB_VERSION}.tar.gz -C "$BDB_PREFIX"
cd "${BDB_PREFIX}/${BDB_VERSION}/"
-# Apply a patch when building on OS X to make the build work with Xcode.
-#
-if [ "$(uname)" = "Darwin" ]; then
- BDB_OSX_ATOMIC_PATCH_URL='https://raw.githubusercontent.com/narkoleptik/os-x-berkeleydb-patch/0007e2846ae3fc9757849f5277018f4179ad17ef/atomic.patch'
- BDB_OSX_ATOMIC_PATCH_HASH='ba0e2b4f53e9cb0ec58f60a979b53b8567b4565f0384886196f1fc1ef111d151'
-
- http_get "${BDB_OSX_ATOMIC_PATCH_URL}" atomic.patch "${BDB_OSX_ATOMIC_PATCH_HASH}"
- patch -p1 < atomic.patch
-fi
+# Apply a patch necessary when building with clang and c++11 (see https://community.oracle.com/thread/3952592)
+CLANG_CXX11_PATCH_URL='https://gist.githubusercontent.com/LnL7/5153b251fd525fe15de69b67e63a6075/raw/7778e9364679093a32dec2908656738e16b6bdcb/clang.patch'
+CLANG_CXX11_PATCH_HASH='7a9a47b03fd5fb93a16ef42235fa9512db9b0829cfc3bdf90edd3ec1f44d637c'
+http_get "${CLANG_CXX11_PATCH_URL}" clang.patch "${CLANG_CXX11_PATCH_HASH}"
+patch -p2 < clang.patch
cd build_unix/
"${BDB_PREFIX}/${BDB_VERSION}/dist/configure" \
--enable-cxx --disable-shared --with-pic --prefix="${BDB_PREFIX}" \
- "${BDB_EXTRA_CONFIGURE_FLAGS}"
+ "${@}"
make install
diff --git a/depends/packages/zeromq.mk b/depends/packages/zeromq.mk
index 74bf4e9e11..3f97221e10 100644
--- a/depends/packages/zeromq.mk
+++ b/depends/packages/zeromq.mk
@@ -29,5 +29,6 @@ define $(package)_stage_cmds
endef
define $(package)_postprocess_cmds
+ sed -i.old "s/ -lstdc++//" lib/pkgconfig/libzmq.pc && \
rm -rf bin share
endef
diff --git a/doc/build-osx.md b/doc/build-osx.md
index 6663016ed8..cbc5288c16 100644
--- a/doc/build-osx.md
+++ b/doc/build-osx.md
@@ -29,7 +29,7 @@ NOTE: Building with Qt4 is still supported, however, could result in a broken UI
Berkeley DB
-----------
It is recommended to use Berkeley DB 4.8. If you have to build it yourself,
-you can use [the installation script included in contrib/](contrib/install_db4.sh)
+you can use [the installation script included in contrib/](/contrib/install_db4.sh)
like so
```shell
diff --git a/doc/build-unix.md b/doc/build-unix.md
index 5d3329e2cf..af567cadeb 100644
--- a/doc/build-unix.md
+++ b/doc/build-unix.md
@@ -166,7 +166,7 @@ turned off by default. See the configure options for upnp behavior desired:
Berkeley DB
-----------
It is recommended to use Berkeley DB 4.8. If you have to build it yourself,
-you can use [the installation script included in contrib/](contrib/install_db4.sh)
+you can use [the installation script included in contrib/](/contrib/install_db4.sh)
like so
```shell
@@ -312,17 +312,13 @@ You need to use GNU make (`gmake`) instead of `make`.
For the wallet (optional):
- pkg install db5
-
-This will give a warning "configure: WARNING: Found Berkeley DB other
-than 4.8; wallets opened by this build will not be portable!", but as FreeBSD never
-had a binary release, this may not matter. If backwards compatibility
-with 4.8-built Bitcoin Core is needed follow the steps under "Berkeley DB" above.
+ ./contrib/install_db4.sh `pwd`
+ setenv BDB_PREFIX $PWD/db4
Then build using:
./autogen.sh
- ./configure --with-incompatible-bdb BDB_CFLAGS="-I/usr/local/include/db5" BDB_LIBS="-L/usr/local/lib -ldb_cxx-5"
+ ./configure BDB_CFLAGS="-I${BDB_PREFIX}/include" BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx"
gmake
*Note on debugging*: The version of `gdb` installed by default is [ancient and considered harmful](https://wiki.freebsd.org/GdbRetirement).
diff --git a/doc/developer-notes.md b/doc/developer-notes.md
index 7f34b07d15..9dc63a1e4b 100644
--- a/doc/developer-notes.md
+++ b/doc/developer-notes.md
@@ -493,7 +493,7 @@ namespace {
- *Rationale*: Avoids confusion about the namespace context
- Prefer `#include <primitives/transaction.h>` bracket syntax instead of
- `#include "primitives/transactions.h"`` quote syntax when possible.
+ `#include "primitives/transactions.h"` quote syntax when possible.
- *Rationale*: Bracket syntax is less ambiguous because the preprocessor
searches a fixed list of include directories without taking location of the
diff --git a/doc/files.md b/doc/files.md
index 3d603445fb..2eac7ed664 100644
--- a/doc/files.md
+++ b/doc/files.md
@@ -6,13 +6,16 @@
* blocks/rev000??.dat; block undo data (custom); since 0.8.0 (format changed since pre-0.8)
* blocks/index/*; block index (LevelDB); since 0.8.0
* chainstate/*; block chain state database (LevelDB); since 0.8.0
-* database/*: BDB database environment; only used for wallet since 0.8.0
-* db.log: wallet database log file
+* database/*: BDB database environment; only used for wallet since 0.8.0; moved to wallets/ directory on new installs since 0.16.0
+* db.log: wallet database log file; moved to wallets/ directory on new installs since 0.16.0
* debug.log: contains debug information and general logging generated by bitcoind or bitcoin-qt
* fee_estimates.dat: stores statistics used to estimate minimum transaction fees and priorities required for confirmation; since 0.10.0
* mempool.dat: dump of the mempool's transactions; since 0.14.0.
* peers.dat: peer IP address database (custom format); since 0.7.0
-* wallet.dat: personal wallet (BDB) with keys and transactions
+* wallet.dat: personal wallet (BDB) with keys and transactions; moved to wallets/ directory on new installs since 0.16.0
+* wallets/database/*: BDB database environment; used for wallets since 0.16.0
+* wallets/db.log: wallet database log file; since 0.16.0
+* wallets/wallet.dat: personal wallet (BDB) with keys and transactions; since 0.16.0
* .cookie: session RPC authentication cookie (written at start when cookie authentication is used, deleted on shutdown): since 0.12.0
* onion_private_key: cached Tor hidden service private key for `-listenonion`: since 0.12.0
* guisettings.ini.bak: backup of former GUI settings after `-resetguisettings` is used
diff --git a/doc/release-notes.md b/doc/release-notes.md
index 78caddc8f0..d92666da72 100644
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -67,12 +67,20 @@ Due to a backward-incompatible change in the wallet database, wallets created
with version 0.16.0 will be rejected by previous versions. Also, version 0.16.0
will only create hierarchical deterministic (HD) wallets.
+Replace-By-Fee by default in GUI
+--------------------------------
+The send screen now uses BIP-125 RBF by default, regardless of `-walletrbf`.
+There is a checkbox to mark the transaction as final.
+
+The RPC default remains unchanged: to use RBF, launch with `-walletrbf=1` or
+use the `replaceable` argument for individual transactions.
+
Custom wallet directories
---------------------
The ability to specify a directory other than the default data directory in which to store
wallets has been added. An existing directory can be specified using the `-walletdir=<dir>`
argument. Wallets loaded via `-wallet` arguments must be in this wallet directory. Care should be taken
-when choosing a wallet directory location, as if it becomes unavailable during operation,
+when choosing a wallet directory location, as if it becomes unavailable during operation,
funds may be lost.
Default wallet directory change
@@ -100,6 +108,10 @@ The `share/rpcuser/rpcuser.py` script was renamed to `share/rpcauth/rpcauth.py`.
used to create `rpcauth` credentials for a JSON-RPC user.
+- `dumpwallet` now includes hex-encoded scripts from the wallet in the dumpfile, and
+ `importwallet` now imports these scripts, but corresponding addresses may not be added
+ correctly or a manual rescan may be required to find relevant transactions.
+
Credits
=======
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 06175be3fc..49a814c3f6 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -84,7 +84,6 @@ BITCOIN_TESTS =\
test/txvalidationcache_tests.cpp \
test/versionbits_tests.cpp \
test/uint256_tests.cpp \
- test/univalue_tests.cpp \
test/util_tests.cpp
if ENABLE_WALLET
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index e75d3be4c1..a78f530036 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -231,6 +231,7 @@ public:
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch", true);
vSeeds.emplace_back("seed.tbtc.petertodd.org", true);
+ vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl", true);
vSeeds.emplace_back("testnet-seed.bluematt.me", false);
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
diff --git a/src/core_io.h b/src/core_io.h
index 7ed84d6665..3cdae06dfb 100644
--- a/src/core_io.h
+++ b/src/core_io.h
@@ -20,7 +20,7 @@ class UniValue;
// core_read.cpp
CScript ParseScript(const std::string& s);
std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
-bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness = false);
+bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness = false, bool try_witness = true);
bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
uint256 ParseHashUV(const UniValue& v, const std::string& strName);
uint256 ParseHashStr(const std::string&, const std::string& strName);
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 2f5b67b5c7..4f2dabe10f 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -108,39 +108,39 @@ bool CheckTxScriptsSanity(const CMutableTransaction& tx)
return true;
}
-bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness)
+bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
{
- if (!IsHex(strHexTx)) {
+ if (!IsHex(hex_tx)) {
return false;
}
- std::vector<unsigned char> txData(ParseHex(strHexTx));
+ std::vector<unsigned char> txData(ParseHex(hex_tx));
- if (fTryNoWitness) {
+ if (try_no_witness) {
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
try {
ssData >> tx;
- if (ssData.eof() && CheckTxScriptsSanity(tx)) {
+ if (ssData.eof() && (!try_witness || CheckTxScriptsSanity(tx))) {
return true;
}
- }
- catch (const std::exception&) {
+ } catch (const std::exception&) {
// Fall through.
}
}
- CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
- try {
- ssData >> tx;
- if (!ssData.empty()) {
- return false;
+ if (try_witness) {
+ CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
+ try {
+ ssData >> tx;
+ if (ssData.empty()) {
+ return true;
+ }
+ } catch (const std::exception&) {
+ // Fall through.
}
}
- catch (const std::exception&) {
- return false;
- }
-
- return true;
+
+ return false;
}
bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
diff --git a/src/key.cpp b/src/key.cpp
index 9d4c4498d8..9893b88220 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -1,4 +1,5 @@
// Copyright (c) 2009-2016 The Bitcoin Core developers
+// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -15,43 +16,62 @@
static secp256k1_context* secp256k1_context_sign = nullptr;
/** These functions are taken from the libsecp256k1 distribution and are very ugly. */
+
+/**
+ * This parses a format loosely based on a DER encoding of the ECPrivateKey type from
+ * section C.4 of SEC 1 <http://www.secg.org/sec1-v2.pdf>, with the following caveats:
+ *
+ * * The octet-length of the SEQUENCE must be encoded as 1 or 2 octets. It is not
+ * required to be encoded as one octet if it is less than 256, as DER would require.
+ * * The octet-length of the SEQUENCE must not be greater than the remaining
+ * length of the key encoding, but need not match it (i.e. the encoding may contain
+ * junk after the encoded SEQUENCE).
+ * * The privateKey OCTET STRING is zero-filled on the left to 32 octets.
+ * * Anything after the encoding of the privateKey OCTET STRING is ignored, whether
+ * or not it is validly encoded DER.
+ *
+ * out32 must point to an output buffer of length at least 32 bytes.
+ */
static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
const unsigned char *end = privkey + privkeylen;
- int lenb = 0;
- int len = 0;
memset(out32, 0, 32);
/* sequence header */
- if (end < privkey+1 || *privkey != 0x30) {
+ if (end - privkey < 1 || *privkey != 0x30u) {
return 0;
}
privkey++;
/* sequence length constructor */
- if (end < privkey+1 || !(*privkey & 0x80)) {
+ if (end - privkey < 1 || !(*privkey & 0x80u)) {
return 0;
}
- lenb = *privkey & ~0x80; privkey++;
+ size_t lenb = *privkey & ~0x80u; privkey++;
if (lenb < 1 || lenb > 2) {
return 0;
}
- if (end < privkey+lenb) {
+ if (end - privkey < lenb) {
return 0;
}
/* sequence length */
- len = privkey[lenb-1] | (lenb > 1 ? privkey[lenb-2] << 8 : 0);
+ size_t len = privkey[lenb-1] | (lenb > 1 ? privkey[lenb-2] << 8 : 0u);
privkey += lenb;
- if (end < privkey+len) {
+ if (end - privkey < len) {
return 0;
}
/* sequence element 0: version number (=1) */
- if (end < privkey+3 || privkey[0] != 0x02 || privkey[1] != 0x01 || privkey[2] != 0x01) {
+ if (end - privkey < 3 || privkey[0] != 0x02u || privkey[1] != 0x01u || privkey[2] != 0x01u) {
return 0;
}
privkey += 3;
/* sequence element 1: octet string, up to 32 bytes */
- if (end < privkey+2 || privkey[0] != 0x04 || privkey[1] > 0x20 || end < privkey+2+privkey[1]) {
+ if (end - privkey < 2 || privkey[0] != 0x04u) {
+ return 0;
+ }
+ size_t oslen = privkey[1];
+ privkey += 2;
+ if (oslen > 32 || end - privkey < oslen) {
return 0;
}
- memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
+ memcpy(out32 + (32 - oslen), privkey, oslen);
if (!secp256k1_ec_seckey_verify(ctx, out32)) {
memset(out32, 0, 32);
return 0;
@@ -59,7 +79,18 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou
return 1;
}
+/**
+ * This serializes to a DER encoding of the ECPrivateKey type from section C.4 of SEC 1
+ * <http://www.secg.org/sec1-v2.pdf>. The optional parameters and publicKey fields are
+ * included.
+ *
+ * privkey must point to an output buffer of length at least CKey::PRIVATE_KEY_SIZE bytes.
+ * privkeylen must initially be set to the size of the privkey buffer. Upon return it
+ * will be set to the number of bytes used in the buffer.
+ * key32 must point to a 32-byte raw private key.
+ */
static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
+ assert(*privkeylen >= CKey::PRIVATE_KEY_SIZE);
secp256k1_pubkey pubkey;
size_t pubkeylen = 0;
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
@@ -85,10 +116,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
- pubkeylen = 33;
+ pubkeylen = CPubKey::COMPRESSED_PUBLIC_KEY_SIZE;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
+ assert(*privkeylen == CKey::COMPRESSED_PRIVATE_KEY_SIZE);
} else {
static const unsigned char begin[] = {
0x30,0x82,0x01,0x13,0x02,0x01,0x01,0x04,0x20
@@ -110,10 +142,11 @@ static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *pr
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
- pubkeylen = 65;
+ pubkeylen = CPubKey::PUBLIC_KEY_SIZE;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
+ assert(*privkeylen == CKey::PRIVATE_KEY_SIZE);
}
return 1;
}
@@ -135,8 +168,8 @@ CPrivKey CKey::GetPrivKey() const {
CPrivKey privkey;
int ret;
size_t privkeylen;
- privkey.resize(279);
- privkeylen = 279;
+ privkey.resize(PRIVATE_KEY_SIZE);
+ privkeylen = PRIVATE_KEY_SIZE;
ret = ec_privkey_export_der(secp256k1_context_sign, (unsigned char*) privkey.data(), &privkeylen, begin(), fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
assert(ret);
privkey.resize(privkeylen);
@@ -146,7 +179,7 @@ CPrivKey CKey::GetPrivKey() const {
CPubKey CKey::GetPubKey() const {
assert(fValid);
secp256k1_pubkey pubkey;
- size_t clen = 65;
+ size_t clen = CPubKey::PUBLIC_KEY_SIZE;
CPubKey result;
int ret = secp256k1_ec_pubkey_create(secp256k1_context_sign, &pubkey, begin());
assert(ret);
@@ -159,8 +192,8 @@ CPubKey CKey::GetPubKey() const {
bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_t test_case) const {
if (!fValid)
return false;
- vchSig.resize(72);
- size_t nSigLen = 72;
+ vchSig.resize(CPubKey::SIGNATURE_SIZE);
+ size_t nSigLen = CPubKey::SIGNATURE_SIZE;
unsigned char extra_entropy[32] = {0};
WriteLE32(extra_entropy, test_case);
secp256k1_ecdsa_signature sig;
@@ -188,7 +221,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const {
if (!fValid)
return false;
- vchSig.resize(65);
+ vchSig.resize(CPubKey::COMPACT_SIGNATURE_SIZE);
int rec = -1;
secp256k1_ecdsa_recoverable_signature sig;
int ret = secp256k1_ecdsa_sign_recoverable(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, nullptr);
@@ -218,10 +251,10 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
if ((nChild >> 31) == 0) {
CPubKey pubkey = GetPubKey();
- assert(pubkey.begin() + 33 == pubkey.end());
+ assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data());
} else {
- assert(begin() + 32 == end());
+ assert(size() == 32);
BIP32Hash(cc, nChild, 0, begin(), vout.data());
}
memcpy(ccChild.begin(), vout.data()+32, 32);
diff --git a/src/key.h b/src/key.h
index c610e5e6cd..8ef6c51b14 100644
--- a/src/key.h
+++ b/src/key.h
@@ -1,5 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
+// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -16,24 +17,29 @@
/**
- * secp256k1:
- * const unsigned int PRIVATE_KEY_SIZE = 279;
- * const unsigned int PUBLIC_KEY_SIZE = 65;
- * const unsigned int SIGNATURE_SIZE = 72;
- *
- * see www.keylength.com
- * script supports up to 75 for single byte push
- */
-
-/**
* secure_allocator is defined in allocators.h
- * CPrivKey is a serialized private key, with all parameters included (279 bytes)
+ * CPrivKey is a serialized private key, with all parameters included
+ * (PRIVATE_KEY_SIZE bytes)
*/
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
/** An encapsulated private key. */
class CKey
{
+public:
+ /**
+ * secp256k1:
+ */
+ static const unsigned int PRIVATE_KEY_SIZE = 279;
+ static const unsigned int COMPRESSED_PRIVATE_KEY_SIZE = 214;
+ /**
+ * see www.keylength.com
+ * script supports up to 75 for single byte push
+ */
+ static_assert(
+ PRIVATE_KEY_SIZE >= COMPRESSED_PRIVATE_KEY_SIZE,
+ "COMPRESSED_PRIVATE_KEY_SIZE is larger than PRIVATE_KEY_SIZE");
+
private:
//! Whether this private key is valid. We check for correctness when modifying the key
//! data, so fValid should always correspond to the actual state.
diff --git a/src/keystore.cpp b/src/keystore.cpp
index 4ab089e032..a010a1244a 100644
--- a/src/keystore.cpp
+++ b/src/keystore.cpp
@@ -77,6 +77,16 @@ bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
return mapScripts.count(hash) > 0;
}
+std::set<CScriptID> CBasicKeyStore::GetCScripts() const
+{
+ LOCK(cs_KeyStore);
+ std::set<CScriptID> set_script;
+ for (const auto& mi : mapScripts) {
+ set_script.insert(mi.first);
+ }
+ return set_script;
+}
+
bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
{
LOCK(cs_KeyStore);
diff --git a/src/keystore.h b/src/keystore.h
index 4e6d8e8a27..516a238241 100644
--- a/src/keystore.h
+++ b/src/keystore.h
@@ -36,6 +36,7 @@ public:
//! Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
virtual bool AddCScript(const CScript& redeemScript) =0;
virtual bool HaveCScript(const CScriptID &hash) const =0;
+ virtual std::set<CScriptID> GetCScripts() const =0;
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const =0;
//! Support for Watch-only addresses
@@ -67,6 +68,7 @@ public:
bool GetKey(const CKeyID &address, CKey &keyOut) const override;
bool AddCScript(const CScript& redeemScript) override;
bool HaveCScript(const CScriptID &hash) const override;
+ std::set<CScriptID> GetCScripts() const override;
bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
bool AddWatchOnly(const CScript &dest) override;
diff --git a/src/net.cpp b/src/net.cpp
index 23bf640472..e00faaeecd 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -603,21 +603,28 @@ void CConnman::SetBanned(const banmap_t &banMap)
void CConnman::SweepBanned()
{
int64_t now = GetTime();
-
- LOCK(cs_setBanned);
- banmap_t::iterator it = setBanned.begin();
- while(it != setBanned.end())
+ bool notifyUI = false;
{
- CSubNet subNet = (*it).first;
- CBanEntry banEntry = (*it).second;
- if(now > banEntry.nBanUntil)
+ LOCK(cs_setBanned);
+ banmap_t::iterator it = setBanned.begin();
+ while(it != setBanned.end())
{
- setBanned.erase(it++);
- setBannedIsDirty = true;
- LogPrint(BCLog::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString());
+ CSubNet subNet = (*it).first;
+ CBanEntry banEntry = (*it).second;
+ if(now > banEntry.nBanUntil)
+ {
+ setBanned.erase(it++);
+ setBannedIsDirty = true;
+ notifyUI = true;
+ LogPrint(BCLog::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString());
+ }
+ else
+ ++it;
}
- else
- ++it;
+ }
+ // update UI
+ if(notifyUI && clientInterface) {
+ clientInterface->BannedListChanged();
}
}
diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp
index dc88c4f91a..490986fc11 100644
--- a/src/policy/fees.cpp
+++ b/src/policy/fees.cpp
@@ -411,15 +411,13 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
size_t maxConfirms, maxPeriods;
// The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
- if (nFileVersion >= 149900) {
- filein >> decay;
- if (decay <= 0 || decay >= 1) {
- throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
- }
- filein >> scale;
- if (scale == 0) {
- throw std::runtime_error("Corrupt estimates file. Scale must be non-zero");
- }
+ filein >> decay;
+ if (decay <= 0 || decay >= 1) {
+ throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
+ }
+ filein >> scale;
+ if (scale == 0) {
+ throw std::runtime_error("Corrupt estimates file. Scale must be non-zero");
}
filein >> avg;
@@ -443,20 +441,13 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
}
}
- if (nFileVersion >= 149900) {
- filein >> failAvg;
- if (maxPeriods != failAvg.size()) {
- throw std::runtime_error("Corrupt estimates file. Mismatch in confirms tracked for failures");
- }
- for (unsigned int i = 0; i < maxPeriods; i++) {
- if (failAvg[i].size() != numBuckets) {
- throw std::runtime_error("Corrupt estimates file. Mismatch in one of failure average bucket counts");
- }
- }
- } else {
- failAvg.resize(confAvg.size());
- for (unsigned int i = 0; i < failAvg.size(); i++) {
- failAvg[i].resize(numBuckets);
+ filein >> failAvg;
+ if (maxPeriods != failAvg.size()) {
+ throw std::runtime_error("Corrupt estimates file. Mismatch in confirms tracked for failures");
+ }
+ for (unsigned int i = 0; i < maxPeriods; i++) {
+ if (failAvg[i].size() != numBuckets) {
+ throw std::runtime_error("Corrupt estimates file. Mismatch in one of failure average bucket counts");
}
}
@@ -563,7 +554,7 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
if (mapMemPoolTxs.count(hash)) {
LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error mempool tx %s already being tracked\n",
hash.ToString().c_str());
- return;
+ return;
}
if (txHeight != nBestSeenHeight) {
@@ -944,32 +935,9 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
unsigned int nFileBestSeenHeight;
filein >> nFileBestSeenHeight;
- if (nVersionThatWrote < 149900) {
- // Read the old fee estimates file for temporary use, but then discard. Will start collecting data from scratch.
- // decay is stored before buckets in old versions, so pre-read decay and pass into TxConfirmStats constructor
- double tempDecay;
- filein >> tempDecay;
- if (tempDecay <= 0 || tempDecay >= 1)
- throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
-
- std::vector<double> tempBuckets;
- filein >> tempBuckets;
- size_t tempNum = tempBuckets.size();
- if (tempNum <= 1 || tempNum > 1000)
- throw std::runtime_error("Corrupt estimates file. Must have between 2 and 1000 feerate buckets");
-
- std::map<double, unsigned int> tempMap;
-
- std::unique_ptr<TxConfirmStats> tempFeeStats(new TxConfirmStats(tempBuckets, tempMap, MED_BLOCK_PERIODS, tempDecay, 1));
- tempFeeStats->Read(filein, nVersionThatWrote, tempNum);
- // if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored.
-
- tempMap.clear();
- for (unsigned int i = 0; i < tempBuckets.size(); i++) {
- tempMap[tempBuckets[i]] = i;
- }
- }
- else { // nVersionThatWrote >= 149900
+ if (nVersionRequired < 149900) {
+ LogPrintf("%s: incompatible old fee estimation data (non-fatal). Version: %d\n", __func__, nVersionRequired);
+ } else { // New format introduced in 149900
unsigned int nFileHistoricalFirst, nFileHistoricalBest;
filein >> nFileHistoricalFirst >> nFileHistoricalBest;
if (nFileHistoricalFirst > nFileHistoricalBest || nFileHistoricalBest > nFileBestSeenHeight) {
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index 7f5ec1e8de..e52acf077c 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -1,4 +1,5 @@
// Copyright (c) 2009-2016 The Bitcoin Core developers
+// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -46,7 +47,7 @@ static int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1
lenbyte = input[pos++];
if (lenbyte & 0x80) {
lenbyte -= 0x80;
- if (pos + lenbyte > inputlen) {
+ if (lenbyte > inputlen - pos) {
return 0;
}
pos += lenbyte;
@@ -65,14 +66,15 @@ static int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1
lenbyte = input[pos++];
if (lenbyte & 0x80) {
lenbyte -= 0x80;
- if (pos + lenbyte > inputlen) {
+ if (lenbyte > inputlen - pos) {
return 0;
}
while (lenbyte > 0 && input[pos] == 0) {
pos++;
lenbyte--;
}
- if (lenbyte >= sizeof(size_t)) {
+ static_assert(sizeof(size_t) >= 4, "size_t too small");
+ if (lenbyte >= 4) {
return 0;
}
rlen = 0;
@@ -103,14 +105,15 @@ static int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1
lenbyte = input[pos++];
if (lenbyte & 0x80) {
lenbyte -= 0x80;
- if (pos + lenbyte > inputlen) {
+ if (lenbyte > inputlen - pos) {
return 0;
}
while (lenbyte > 0 && input[pos] == 0) {
pos++;
lenbyte--;
}
- if (lenbyte >= sizeof(size_t)) {
+ static_assert(sizeof(size_t) >= 4, "size_t too small");
+ if (lenbyte >= 4) {
return 0;
}
slen = 0;
@@ -181,7 +184,7 @@ bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchS
}
bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
- if (vchSig.size() != 65)
+ if (vchSig.size() != COMPACT_SIGNATURE_SIZE)
return false;
int recid = (vchSig[0] - 27) & 3;
bool fComp = ((vchSig[0] - 27) & 4) != 0;
@@ -193,8 +196,8 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned cha
if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, hash.begin())) {
return false;
}
- unsigned char pub[65];
- size_t publen = 65;
+ unsigned char pub[PUBLIC_KEY_SIZE];
+ size_t publen = PUBLIC_KEY_SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
Set(pub, pub + publen);
return true;
@@ -214,8 +217,8 @@ bool CPubKey::Decompress() {
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size())) {
return false;
}
- unsigned char pub[65];
- size_t publen = 65;
+ unsigned char pub[PUBLIC_KEY_SIZE];
+ size_t publen = PUBLIC_KEY_SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
Set(pub, pub + publen);
return true;
@@ -224,7 +227,7 @@ bool CPubKey::Decompress() {
bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const {
assert(IsValid());
assert((nChild >> 31) == 0);
- assert(begin() + 33 == end());
+ assert(size() == COMPRESSED_PUBLIC_KEY_SIZE);
unsigned char out[64];
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
memcpy(ccChild.begin(), out+32, 32);
@@ -235,8 +238,8 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, out)) {
return false;
}
- unsigned char pub[33];
- size_t publen = 33;
+ unsigned char pub[COMPRESSED_PUBLIC_KEY_SIZE];
+ size_t publen = COMPRESSED_PUBLIC_KEY_SIZE;
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
pubkeyChild.Set(pub, pub + publen);
return true;
@@ -248,8 +251,8 @@ void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
memcpy(code+9, chaincode.begin(), 32);
- assert(pubkey.size() == 33);
- memcpy(code+41, pubkey.begin(), 33);
+ assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
+ memcpy(code+41, pubkey.begin(), CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
}
void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
diff --git a/src/pubkey.h b/src/pubkey.h
index c9f3c18eb3..e6c32913de 100644
--- a/src/pubkey.h
+++ b/src/pubkey.h
@@ -1,5 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
+// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -13,16 +14,6 @@
#include <stdexcept>
#include <vector>
-/**
- * secp256k1:
- * const unsigned int PRIVATE_KEY_SIZE = 279;
- * const unsigned int PUBLIC_KEY_SIZE = 65;
- * const unsigned int SIGNATURE_SIZE = 72;
- *
- * see www.keylength.com
- * script supports up to 75 for single byte push
- */
-
const unsigned int BIP32_EXTKEY_SIZE = 74;
/** A reference to a CKey: the Hash160 of its serialized public key */
@@ -38,21 +29,37 @@ typedef uint256 ChainCode;
/** An encapsulated public key. */
class CPubKey
{
+public:
+ /**
+ * secp256k1:
+ */
+ static const unsigned int PUBLIC_KEY_SIZE = 65;
+ static const unsigned int COMPRESSED_PUBLIC_KEY_SIZE = 33;
+ static const unsigned int SIGNATURE_SIZE = 72;
+ static const unsigned int COMPACT_SIGNATURE_SIZE = 65;
+ /**
+ * see www.keylength.com
+ * script supports up to 75 for single byte push
+ */
+ static_assert(
+ PUBLIC_KEY_SIZE >= COMPRESSED_PUBLIC_KEY_SIZE,
+ "COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE");
+
private:
/**
* Just store the serialized data.
* Its length can very cheaply be computed from the first byte.
*/
- unsigned char vch[65];
+ unsigned char vch[PUBLIC_KEY_SIZE];
//! Compute the length of a pubkey with a given first byte.
unsigned int static GetLen(unsigned char chHeader)
{
if (chHeader == 2 || chHeader == 3)
- return 33;
+ return COMPRESSED_PUBLIC_KEY_SIZE;
if (chHeader == 4 || chHeader == 6 || chHeader == 7)
- return 65;
+ return PUBLIC_KEY_SIZE;
return 0;
}
@@ -127,7 +134,7 @@ public:
void Unserialize(Stream& s)
{
unsigned int len = ::ReadCompactSize(s);
- if (len <= 65) {
+ if (len <= PUBLIC_KEY_SIZE) {
s.read((char*)vch, len);
} else {
// invalid pubkey, skip available data
@@ -166,7 +173,7 @@ public:
//! Check whether this is a compressed public key.
bool IsCompressed() const
{
- return size() == 33;
+ return size() == COMPRESSED_PUBLIC_KEY_SIZE;
}
/**
diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui
index c6fd708cdf..195a5560f7 100644
--- a/src/qt/forms/sendcoinsdialog.ui
+++ b/src/qt/forms/sendcoinsdialog.ui
@@ -1108,10 +1108,10 @@
<item>
<widget class="QCheckBox" name="optInRBF">
<property name="text">
- <string>Allow increasing fee</string>
+ <string>Enable Replace-By-Fee</string>
</property>
<property name="toolTip">
- <string>This allows you to increase the fee later if the transaction takes a long time to confirm. This will also cause the recommended fee to be lower. ("Replace-By-Fee", BIP 125)</string>
+ <string>With Replace-By-Fee (BIP-125) you can increase a transaction's fee after it is sent. Without this, a higher fee may be recommended to compensate for increased transaction delay risk.</string>
</property>
</widget>
</item>
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index faddfcd4d0..9473198dfc 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -181,7 +181,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
updateSmartFeeLabel();
// set default rbf checkbox state
- ui->optInRBF->setCheckState(model->getDefaultWalletRbf() ? Qt::Checked : Qt::Unchecked);
+ ui->optInRBF->setCheckState(Qt::Checked);
// set the smartfee-sliders default value (wallets default conf.target or last stored value)
QSettings settings;
@@ -339,12 +339,14 @@ void SendCoinsDialog::on_sendButton_clicked()
questionString.append(QString("<span style='font-size:10pt;font-weight:normal;'><br />(=%2)</span>")
.arg(alternativeUnits.join(" " + tr("or") + "<br />")));
- if (ui->optInRBF->isChecked())
- {
- questionString.append("<hr /><span>");
- questionString.append(tr("You can increase the fee later (signals Replace-By-Fee)."));
- questionString.append("</span>");
+ questionString.append("<hr /><span>");
+ if (ui->optInRBF->isChecked()) {
+ questionString.append(tr("You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
+ } else {
+ questionString.append(tr("Not signalling Replace-By-Fee, BIP-125."));
}
+ questionString.append("</span>");
+
SendConfirmationDialog confirmationDialog(tr("Confirm send coins"),
questionString.arg(formatted.join("<br />")), SEND_CONFIRM_DELAY, this);
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index a38e233608..e0193ed475 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -737,8 +737,3 @@ int WalletModel::getDefaultConfirmTarget() const
{
return nTxConfirmTarget;
}
-
-bool WalletModel::getDefaultWalletRbf() const
-{
- return fWalletRbf;
-}
diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h
index 028146c187..8009e54b19 100644
--- a/src/qt/walletmodel.h
+++ b/src/qt/walletmodel.h
@@ -216,8 +216,6 @@ public:
int getDefaultConfirmTarget() const;
- bool getDefaultWalletRbf() const;
-
private:
CWallet *wallet;
bool fHaveWatchOnly;
diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp
index f2fa114313..e641493e1e 100644
--- a/src/rpc/client.cpp
+++ b/src/rpc/client.cpp
@@ -91,11 +91,13 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "createrawtransaction", 1, "outputs" },
{ "createrawtransaction", 2, "locktime" },
{ "createrawtransaction", 3, "replaceable" },
+ { "decoderawtransaction", 1, "iswitness" },
{ "signrawtransaction", 1, "prevtxs" },
{ "signrawtransaction", 2, "privkeys" },
{ "sendrawtransaction", 1, "allowhighfees" },
{ "combinerawtransaction", 0, "txs" },
{ "fundrawtransaction", 1, "options" },
+ { "fundrawtransaction", 2, "iswitness" },
{ "gettxout", 1, "n" },
{ "gettxout", 2, "include_mempool" },
{ "gettxoutproof", 0, "txids" },
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index fbebdf44d4..1049131d5e 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -441,13 +441,15 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
UniValue decoderawtransaction(const JSONRPCRequest& request)
{
- if (request.fHelp || request.params.size() != 1)
+ if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
- "decoderawtransaction \"hexstring\"\n"
+ "decoderawtransaction \"hexstring\" ( iswitness )\n"
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
"\nArguments:\n"
"1. \"hexstring\" (string, required) The transaction hex string\n"
+ "2. iswitness (boolean, optional) Whether the transaction hex is a serialized witness transaction\n"
+ " If iswitness is not present, heuristic tests will be used in decoding\n"
"\nResult:\n"
"{\n"
@@ -495,12 +497,16 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
);
LOCK(cs_main);
- RPCTypeCheck(request.params, {UniValue::VSTR});
+ RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});
CMutableTransaction mtx;
- if (!DecodeHexTx(mtx, request.params[0].get_str(), true))
+ bool try_witness = request.params[1].isNull() ? true : request.params[1].get_bool();
+ bool try_no_witness = request.params[1].isNull() ? true : !request.params[1].get_bool();
+
+ if (!DecodeHexTx(mtx, request.params[0].get_str(), try_no_witness, try_witness)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
+ }
UniValue result(UniValue::VOBJ);
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);
@@ -1016,7 +1022,7 @@ static const CRPCCommand commands[] =
// --------------------- ------------------------ ----------------------- ----------
{ "rawtransactions", "getrawtransaction", &getrawtransaction, {"txid","verbose","blockhash"} },
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime","replaceable"} },
- { "rawtransactions", "decoderawtransaction", &decoderawtransaction, {"hexstring"} },
+ { "rawtransactions", "decoderawtransaction", &decoderawtransaction, {"hexstring","iswitness"} },
{ "rawtransactions", "decodescript", &decodescript, {"hexstring"} },
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, {"hexstring","allowhighfees"} },
{ "rawtransactions", "combinerawtransaction", &combinerawtransaction, {"txs"} },
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
index 3c3f92fe46..62042e8e70 100644
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -173,7 +173,13 @@ bool static IsLowDERSignature(const valtype &vchSig, ScriptError* serror) {
if (!IsValidSignatureEncoding(vchSig)) {
return set_error(serror, SCRIPT_ERR_SIG_DER);
}
+ // https://bitcoin.stackexchange.com/a/12556:
+ // Also note that inside transaction signatures, an extra hashtype byte
+ // follows the actual signature data.
std::vector<unsigned char> vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size() - 1);
+ // If the S value is above the order of the curve divided by two, its
+ // complement modulo the order could have been used instead, which is
+ // one byte shorter when encoded correctly.
if (!CPubKey::CheckLowS(vchSigCopy)) {
return set_error(serror, SCRIPT_ERR_SIG_HIGH_S);
}
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index b1a2032ea8..97c548dbb0 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -26,6 +26,17 @@
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) {}
+ bool operator() (const std::runtime_error& e) const {
+ return std::string(e.what()).find(m_reason) != std::string::npos;
+ };
+private:
+ const std::string m_reason;
+};
+
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
static BlockAssembler AssemblerForTest(const CChainParams& params) {
@@ -264,7 +275,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
- BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
+
+ BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-blk-sigops"));
mempool.clear();
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
@@ -304,7 +316,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));
- BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
+ BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
mempool.clear();
// child with higher feerate than parent
@@ -332,7 +344,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
hash = tx.GetHash();
// give it a fee so it'll get mined
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
- BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
+ // Should throw bad-cb-multiple
+ BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-cb-multiple"));
mempool.clear();
// double spend txn pair in mempool, template creation fails
@@ -345,7 +358,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
- BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
+ BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
mempool.clear();
// subsidy changing
@@ -389,7 +402,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue -= LOWFEE;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
- BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
+ // Should throw block-validation-failed
+ BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
mempool.clear();
// Delete the dummy blocks again.
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 710d09ead6..c69b5f1ca3 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -65,7 +65,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193);
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1);
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0);
- BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" extra"), std::runtime_error);
+ BOOST_CHECK_THROW(CallRPC(std::string("decoderawtransaction ")+rawtx+" extra"), std::runtime_error);
+ BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false"));
+ BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false extra"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("signrawtransaction"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("signrawtransaction null"), std::runtime_error);
diff --git a/src/test/univalue_tests.cpp b/src/test/univalue_tests.cpp
deleted file mode 100644
index 7386204437..0000000000
--- a/src/test/univalue_tests.cpp
+++ /dev/null
@@ -1,333 +0,0 @@
-// Copyright (c) 2014 BitPay Inc.
-// Copyright (c) 2014-2016 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 <stdint.h>
-#include <vector>
-#include <string>
-#include <map>
-#include <univalue.h>
-#include <test/test_bitcoin.h>
-
-#include <boost/test/unit_test.hpp>
-
-BOOST_FIXTURE_TEST_SUITE(univalue_tests, BasicTestingSetup)
-
-BOOST_AUTO_TEST_CASE(univalue_constructor)
-{
- UniValue v1;
- BOOST_CHECK(v1.isNull());
-
- UniValue v2(UniValue::VSTR);
- BOOST_CHECK(v2.isStr());
-
- UniValue v3(UniValue::VSTR, "foo");
- BOOST_CHECK(v3.isStr());
- BOOST_CHECK_EQUAL(v3.getValStr(), "foo");
-
- UniValue numTest;
- BOOST_CHECK(numTest.setNumStr("82"));
- BOOST_CHECK(numTest.isNum());
- BOOST_CHECK_EQUAL(numTest.getValStr(), "82");
-
- uint64_t vu64 = 82;
- UniValue v4(vu64);
- BOOST_CHECK(v4.isNum());
- BOOST_CHECK_EQUAL(v4.getValStr(), "82");
-
- int64_t vi64 = -82;
- UniValue v5(vi64);
- BOOST_CHECK(v5.isNum());
- BOOST_CHECK_EQUAL(v5.getValStr(), "-82");
-
- int vi = -688;
- UniValue v6(vi);
- BOOST_CHECK(v6.isNum());
- BOOST_CHECK_EQUAL(v6.getValStr(), "-688");
-
- double vd = -7.21;
- UniValue v7(vd);
- BOOST_CHECK(v7.isNum());
- BOOST_CHECK_EQUAL(v7.getValStr(), "-7.21");
-
- std::string vs("yawn");
- UniValue v8(vs);
- BOOST_CHECK(v8.isStr());
- BOOST_CHECK_EQUAL(v8.getValStr(), "yawn");
-
- const char *vcs = "zappa";
- UniValue v9(vcs);
- BOOST_CHECK(v9.isStr());
- BOOST_CHECK_EQUAL(v9.getValStr(), "zappa");
-}
-
-BOOST_AUTO_TEST_CASE(univalue_typecheck)
-{
- UniValue v1;
- BOOST_CHECK(v1.setNumStr("1"));
- BOOST_CHECK(v1.isNum());
- BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
-
- UniValue v2;
- BOOST_CHECK(v2.setBool(true));
- BOOST_CHECK_EQUAL(v2.get_bool(), true);
- BOOST_CHECK_THROW(v2.get_int(), std::runtime_error);
-
- UniValue v3;
- BOOST_CHECK(v3.setNumStr("32482348723847471234"));
- BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error);
- BOOST_CHECK(v3.setNumStr("1000"));
- BOOST_CHECK_EQUAL(v3.get_int64(), 1000);
-
- UniValue v4;
- BOOST_CHECK(v4.setNumStr("2147483648"));
- BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648);
- BOOST_CHECK_THROW(v4.get_int(), std::runtime_error);
- BOOST_CHECK(v4.setNumStr("1000"));
- BOOST_CHECK_EQUAL(v4.get_int(), 1000);
- BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
- BOOST_CHECK_EQUAL(v4.get_real(), 1000);
- BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
- BOOST_CHECK_THROW(v4.getKeys(), std::runtime_error);
- BOOST_CHECK_THROW(v4.getValues(), std::runtime_error);
- BOOST_CHECK_THROW(v4.get_obj(), std::runtime_error);
-
- UniValue v5;
- BOOST_CHECK(v5.read("[true, 10]"));
- BOOST_CHECK_NO_THROW(v5.get_array());
- std::vector<UniValue> vals = v5.getValues();
- BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error);
- BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
-
- BOOST_CHECK_EQUAL(vals[1].get_int(), 10);
- BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
-}
-
-BOOST_AUTO_TEST_CASE(univalue_set)
-{
- UniValue v(UniValue::VSTR, "foo");
- v.clear();
- BOOST_CHECK(v.isNull());
- BOOST_CHECK_EQUAL(v.getValStr(), "");
-
- BOOST_CHECK(v.setObject());
- BOOST_CHECK(v.isObject());
- BOOST_CHECK_EQUAL(v.size(), 0);
- BOOST_CHECK_EQUAL(v.getType(), UniValue::VOBJ);
- BOOST_CHECK(v.empty());
-
- BOOST_CHECK(v.setArray());
- BOOST_CHECK(v.isArray());
- BOOST_CHECK_EQUAL(v.size(), 0);
-
- BOOST_CHECK(v.setStr("zum"));
- BOOST_CHECK(v.isStr());
- BOOST_CHECK_EQUAL(v.getValStr(), "zum");
-
- BOOST_CHECK(v.setFloat(-1.01));
- BOOST_CHECK(v.isNum());
- BOOST_CHECK_EQUAL(v.getValStr(), "-1.01");
-
- BOOST_CHECK(v.setInt((int)1023));
- BOOST_CHECK(v.isNum());
- BOOST_CHECK_EQUAL(v.getValStr(), "1023");
-
- BOOST_CHECK(v.setInt((int64_t)-1023LL));
- BOOST_CHECK(v.isNum());
- BOOST_CHECK_EQUAL(v.getValStr(), "-1023");
-
- BOOST_CHECK(v.setInt((uint64_t)1023ULL));
- BOOST_CHECK(v.isNum());
- BOOST_CHECK_EQUAL(v.getValStr(), "1023");
-
- BOOST_CHECK(v.setNumStr("-688"));
- BOOST_CHECK(v.isNum());
- BOOST_CHECK_EQUAL(v.getValStr(), "-688");
-
- BOOST_CHECK(v.setBool(false));
- BOOST_CHECK_EQUAL(v.isBool(), true);
- BOOST_CHECK_EQUAL(v.isTrue(), false);
- BOOST_CHECK_EQUAL(v.isFalse(), true);
- BOOST_CHECK_EQUAL(v.getBool(), false);
-
- BOOST_CHECK(v.setBool(true));
- BOOST_CHECK_EQUAL(v.isBool(), true);
- BOOST_CHECK_EQUAL(v.isTrue(), true);
- BOOST_CHECK_EQUAL(v.isFalse(), false);
- BOOST_CHECK_EQUAL(v.getBool(), true);
-
- BOOST_CHECK(!v.setNumStr("zombocom"));
-
- BOOST_CHECK(v.setNull());
- BOOST_CHECK(v.isNull());
-}
-
-BOOST_AUTO_TEST_CASE(univalue_array)
-{
- UniValue arr(UniValue::VARR);
-
- UniValue v((int64_t)1023LL);
- BOOST_CHECK(arr.push_back(v));
-
- std::string vStr("zippy");
- BOOST_CHECK(arr.push_back(vStr));
-
- const char *s = "pippy";
- BOOST_CHECK(arr.push_back(s));
-
- std::vector<UniValue> vec;
- v.setStr("boing");
- vec.push_back(v);
-
- v.setStr("going");
- vec.push_back(v);
-
- BOOST_CHECK(arr.push_backV(vec));
-
- BOOST_CHECK_EQUAL(arr.empty(), false);
- BOOST_CHECK_EQUAL(arr.size(), 5);
-
- BOOST_CHECK_EQUAL(arr[0].getValStr(), "1023");
- BOOST_CHECK_EQUAL(arr[1].getValStr(), "zippy");
- BOOST_CHECK_EQUAL(arr[2].getValStr(), "pippy");
- BOOST_CHECK_EQUAL(arr[3].getValStr(), "boing");
- BOOST_CHECK_EQUAL(arr[4].getValStr(), "going");
-
- BOOST_CHECK_EQUAL(arr[999].getValStr(), "");
-
- arr.clear();
- BOOST_CHECK(arr.empty());
- BOOST_CHECK_EQUAL(arr.size(), 0);
-}
-
-BOOST_AUTO_TEST_CASE(univalue_object)
-{
- UniValue obj(UniValue::VOBJ);
- std::string strKey, strVal;
- UniValue v;
-
- strKey = "age";
- v.setInt(100);
- BOOST_CHECK(obj.pushKV(strKey, v));
-
- strKey = "first";
- strVal = "John";
- BOOST_CHECK(obj.pushKV(strKey, strVal));
-
- strKey = "last";
- const char *cVal = "Smith";
- BOOST_CHECK(obj.pushKV(strKey, cVal));
-
- strKey = "distance";
- BOOST_CHECK(obj.pushKV(strKey, (int64_t) 25));
-
- strKey = "time";
- BOOST_CHECK(obj.pushKV(strKey, (uint64_t) 3600));
-
- strKey = "calories";
- BOOST_CHECK(obj.pushKV(strKey, (int) 12));
-
- strKey = "temperature";
- BOOST_CHECK(obj.pushKV(strKey, (double) 90.012));
-
- UniValue obj2(UniValue::VOBJ);
- BOOST_CHECK(obj2.pushKV("cat1", 9000));
- BOOST_CHECK(obj2.pushKV("cat2", 12345));
-
- BOOST_CHECK(obj.pushKVs(obj2));
-
- BOOST_CHECK_EQUAL(obj.empty(), false);
- BOOST_CHECK_EQUAL(obj.size(), 9);
-
- BOOST_CHECK_EQUAL(obj["age"].getValStr(), "100");
- BOOST_CHECK_EQUAL(obj["first"].getValStr(), "John");
- BOOST_CHECK_EQUAL(obj["last"].getValStr(), "Smith");
- BOOST_CHECK_EQUAL(obj["distance"].getValStr(), "25");
- BOOST_CHECK_EQUAL(obj["time"].getValStr(), "3600");
- BOOST_CHECK_EQUAL(obj["calories"].getValStr(), "12");
- BOOST_CHECK_EQUAL(obj["temperature"].getValStr(), "90.012");
- BOOST_CHECK_EQUAL(obj["cat1"].getValStr(), "9000");
- BOOST_CHECK_EQUAL(obj["cat2"].getValStr(), "12345");
-
- BOOST_CHECK_EQUAL(obj["nyuknyuknyuk"].getValStr(), "");
-
- BOOST_CHECK(obj.exists("age"));
- BOOST_CHECK(obj.exists("first"));
- BOOST_CHECK(obj.exists("last"));
- BOOST_CHECK(obj.exists("distance"));
- BOOST_CHECK(obj.exists("time"));
- BOOST_CHECK(obj.exists("calories"));
- BOOST_CHECK(obj.exists("temperature"));
- BOOST_CHECK(obj.exists("cat1"));
- BOOST_CHECK(obj.exists("cat2"));
-
- BOOST_CHECK(!obj.exists("nyuknyuknyuk"));
-
- std::map<std::string, UniValue::VType> objTypes;
- objTypes["age"] = UniValue::VNUM;
- objTypes["first"] = UniValue::VSTR;
- objTypes["last"] = UniValue::VSTR;
- objTypes["distance"] = UniValue::VNUM;
- objTypes["time"] = UniValue::VNUM;
- objTypes["calories"] = UniValue::VNUM;
- objTypes["temperature"] = UniValue::VNUM;
- objTypes["cat1"] = UniValue::VNUM;
- objTypes["cat2"] = UniValue::VNUM;
- BOOST_CHECK(obj.checkObject(objTypes));
-
- objTypes["cat2"] = UniValue::VSTR;
- BOOST_CHECK(!obj.checkObject(objTypes));
-
- obj.clear();
- BOOST_CHECK(obj.empty());
- BOOST_CHECK_EQUAL(obj.size(), 0);
-}
-
-static const char *json1 =
-"[1.10000000,{\"key1\":\"str\\u0000\",\"key2\":800,\"key3\":{\"name\":\"martian http://test.com\"}}]";
-
-BOOST_AUTO_TEST_CASE(univalue_readwrite)
-{
- UniValue v;
- BOOST_CHECK(v.read(json1));
-
- std::string strJson1(json1);
- BOOST_CHECK(v.read(strJson1));
-
- BOOST_CHECK(v.isArray());
- BOOST_CHECK_EQUAL(v.size(), 2);
-
- BOOST_CHECK_EQUAL(v[0].getValStr(), "1.10000000");
-
- UniValue obj = v[1];
- BOOST_CHECK(obj.isObject());
- BOOST_CHECK_EQUAL(obj.size(), 3);
-
- BOOST_CHECK(obj["key1"].isStr());
- std::string correctValue("str");
- correctValue.push_back('\0');
- BOOST_CHECK_EQUAL(obj["key1"].getValStr(), correctValue);
- BOOST_CHECK(obj["key2"].isNum());
- BOOST_CHECK_EQUAL(obj["key2"].getValStr(), "800");
- BOOST_CHECK(obj["key3"].isObject());
-
- BOOST_CHECK_EQUAL(strJson1, v.write());
-
- /* Check for (correctly reporting) a parsing error if the initial
- JSON construct is followed by more stuff. Note that whitespace
- is, of course, exempt. */
-
- BOOST_CHECK(v.read(" {}\n "));
- BOOST_CHECK(v.isObject());
- BOOST_CHECK(v.read(" []\n "));
- BOOST_CHECK(v.isArray());
-
- BOOST_CHECK(!v.read("@{}"));
- BOOST_CHECK(!v.read("{} garbage"));
- BOOST_CHECK(!v.read("[]{}"));
- BOOST_CHECK(!v.read("{}[]"));
- BOOST_CHECK(!v.read("{} 42"));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/univalue/.travis.yml b/src/univalue/.travis.yml
index 132743d349..43a1ed362e 100644
--- a/src/univalue/.travis.yml
+++ b/src/univalue/.travis.yml
@@ -25,7 +25,6 @@ addons:
- pkg-config
before_script:
- - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew uninstall libtool; brew install libtool; fi
- if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi
- test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh
diff --git a/src/univalue/test/object.cpp b/src/univalue/test/object.cpp
index 02446292a1..679cc9f143 100644
--- a/src/univalue/test/object.cpp
+++ b/src/univalue/test/object.cpp
@@ -19,9 +19,10 @@
#define BOOST_CHECK_THROW(stmt, excMatch) { \
try { \
(stmt); \
+ assert(0 && "No exception caught"); \
} catch (excMatch & e) { \
} catch (...) { \
- assert(0); \
+ assert(0 && "Wrong exception caught"); \
} \
}
#define BOOST_CHECK_NO_THROW(stmt) { \
diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp
index 67c46df87d..71e7111b1a 100644
--- a/src/wallet/init.cpp
+++ b/src/wallet/init.cpp
@@ -31,7 +31,7 @@ std::string GetWalletHelpString(bool showDebug)
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet on startup"));
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE));
strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
- strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF));
+ strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)"), DEFAULT_WALLET_RBF));
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup"));
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT));
strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), DEFAULT_WALLETBROADCAST));
@@ -194,7 +194,10 @@ bool VerifyWallets()
}
if (gArgs.IsArgSet("-walletdir") && !fs::is_directory(GetWalletDir())) {
- return InitError(strprintf(_("Error: Specified wallet directory \"%s\" does not exist."), gArgs.GetArg("-walletdir", "").c_str()));
+ if (fs::exists(fs::system_complete(gArgs.GetArg("-walletdir", "")))) {
+ return InitError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), gArgs.GetArg("-walletdir", "").c_str()));
+ }
+ return InitError(strprintf(_("Specified -walletdir \"%s\" does not exist"), gArgs.GetArg("-walletdir", "").c_str()));
}
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 6ca947bf1b..41179ebd4a 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -500,40 +500,57 @@ UniValue importwallet(const JSONRPCRequest& request)
if (vstr.size() < 2)
continue;
CBitcoinSecret vchSecret;
- if (!vchSecret.SetString(vstr[0]))
- continue;
- CKey key = vchSecret.GetKey();
- CPubKey pubkey = key.GetPubKey();
- assert(key.VerifyPubKey(pubkey));
- CKeyID keyid = pubkey.GetID();
- if (pwallet->HaveKey(keyid)) {
- LogPrintf("Skipping import of %s (key already present)\n", EncodeDestination(keyid));
- continue;
- }
- int64_t nTime = DecodeDumpTime(vstr[1]);
- std::string strLabel;
- bool fLabel = true;
- for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
- if (boost::algorithm::starts_with(vstr[nStr], "#"))
- break;
- if (vstr[nStr] == "change=1")
- fLabel = false;
- if (vstr[nStr] == "reserve=1")
- fLabel = false;
- if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
- strLabel = DecodeDumpString(vstr[nStr].substr(6));
- fLabel = true;
+ if (vchSecret.SetString(vstr[0])) {
+ CKey key = vchSecret.GetKey();
+ CPubKey pubkey = key.GetPubKey();
+ assert(key.VerifyPubKey(pubkey));
+ CKeyID keyid = pubkey.GetID();
+ if (pwallet->HaveKey(keyid)) {
+ LogPrintf("Skipping import of %s (key already present)\n", EncodeDestination(keyid));
+ continue;
}
+ int64_t nTime = DecodeDumpTime(vstr[1]);
+ std::string strLabel;
+ bool fLabel = true;
+ for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
+ if (boost::algorithm::starts_with(vstr[nStr], "#"))
+ break;
+ if (vstr[nStr] == "change=1")
+ fLabel = false;
+ if (vstr[nStr] == "reserve=1")
+ fLabel = false;
+ if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
+ strLabel = DecodeDumpString(vstr[nStr].substr(6));
+ fLabel = true;
+ }
+ }
+ LogPrintf("Importing %s...\n", EncodeDestination(keyid));
+ if (!pwallet->AddKeyPubKey(key, pubkey)) {
+ fGood = false;
+ continue;
+ }
+ pwallet->mapKeyMetadata[keyid].nCreateTime = nTime;
+ if (fLabel)
+ pwallet->SetAddressBook(keyid, strLabel, "receive");
+ nTimeBegin = std::min(nTimeBegin, nTime);
+ } else if(IsHex(vstr[0])) {
+ std::vector<unsigned char> vData(ParseHex(vstr[0]));
+ CScript script = CScript(vData.begin(), vData.end());
+ if (pwallet->HaveCScript(script)) {
+ LogPrintf("Skipping import of %s (script already present)\n", vstr[0]);
+ continue;
+ }
+ if(!pwallet->AddCScript(script)) {
+ LogPrintf("Error importing script %s\n", vstr[0]);
+ fGood = false;
+ continue;
+ }
+ int64_t birth_time = DecodeDumpTime(vstr[1]);
+ if (birth_time > 0) {
+ pwallet->m_script_metadata[CScriptID(script)].nCreateTime = birth_time;
+ nTimeBegin = std::min(nTimeBegin, birth_time);
+ }
}
- LogPrintf("Importing %s...\n", EncodeDestination(keyid));
- if (!pwallet->AddKeyPubKey(key, pubkey)) {
- fGood = false;
- continue;
- }
- pwallet->mapKeyMetadata[keyid].nCreateTime = nTime;
- if (fLabel)
- pwallet->SetAddressBook(keyid, strLabel, "receive");
- nTimeBegin = std::min(nTimeBegin, nTime);
}
file.close();
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
@@ -542,7 +559,7 @@ UniValue importwallet(const JSONRPCRequest& request)
pwallet->MarkDirty();
if (!fGood)
- throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
+ throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys/scripts to wallet");
return NullUniValue;
}
@@ -601,7 +618,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
throw std::runtime_error(
"dumpwallet \"filename\"\n"
"\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n"
- "Imported scripts are not currently included in wallet dumps, these must be backed up separately.\n"
+ "Imported scripts are included in the dumpfile, but corresponding BIP173 addresses, etc. may not be added automatically by importwallet.\n"
"Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by\n"
"only backing up the seed itself, and must be backed up too (e.g. ensure you back up the whole dumpfile).\n"
"\nArguments:\n"
@@ -640,6 +657,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
const std::map<CKeyID, int64_t>& mapKeyPool = pwallet->GetAllReserveKeys();
pwallet->GetKeyBirthTimes(mapKeyBirth);
+ std::set<CScriptID> scripts = pwallet->GetCScripts();
+ // TODO: include scripts in GetKeyBirthTimes() output instead of separate
+
// sort time/key pairs
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
for (const auto& entry : mapKeyBirth) {
@@ -694,6 +714,21 @@ UniValue dumpwallet(const JSONRPCRequest& request)
}
}
file << "\n";
+ for (const CScriptID &scriptid : scripts) {
+ CScript script;
+ std::string create_time = "0";
+ std::string address = EncodeDestination(scriptid);
+ // get birth times for scripts with metadata
+ auto it = pwallet->m_script_metadata.find(scriptid);
+ if (it != pwallet->m_script_metadata.end()) {
+ create_time = EncodeDumpTime(it->second.nCreateTime);
+ }
+ if(pwallet->GetCScript(scriptid, script)) {
+ file << strprintf("%s %s script=1", HexStr(script.begin(), script.end()), create_time);
+ file << strprintf(" # addr=%s\n", address);
+ }
+ }
+ file << "\n";
file << "# End of dump\n";
file.close();
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 473acd8367..f839a18612 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -771,6 +771,8 @@ UniValue getbalance(const JSONRPCRequest& request)
throw std::runtime_error(
"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"
@@ -2980,9 +2982,9 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
return NullUniValue;
}
- if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
+ if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
- "fundrawtransaction \"hexstring\" ( options )\n"
+ "fundrawtransaction \"hexstring\" ( options iswitness )\n"
"\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
"This will not modify existing inputs, and will add at most one change output to the outputs.\n"
"No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
@@ -3017,6 +3019,9 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
" \"CONSERVATIVE\"\n"
" }\n"
" for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
+ "3. iswitness (boolean, optional) Whether the transaction hex is a serialized witness transaction \n"
+ " If iswitness is not present, heuristic tests will be used in decoding\n"
+
"\nResult:\n"
"{\n"
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
@@ -3053,7 +3058,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
coinControl.fAllowWatchOnly = request.params[1].get_bool();
}
else {
- RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ});
+ RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ, UniValue::VBOOL});
UniValue options = request.params[1];
@@ -3122,8 +3127,11 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
// parse hex string from parameter
CMutableTransaction tx;
- if (!DecodeHexTx(tx, request.params[0].get_str(), true))
+ bool try_witness = request.params[2].isNull() ? true : request.params[2].get_bool();
+ bool try_no_witness = request.params[2].isNull() ? true : !request.params[2].get_bool();
+ if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
+ }
if (tx.vout.size() == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
@@ -3441,7 +3449,7 @@ extern UniValue rescanblockchain(const JSONRPCRequest& request);
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
- { "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options"} },
+ { "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
{ "wallet", "abortrescan", &abortrescan, {} },
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index efc50f72eb..0b0d84708d 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -626,7 +626,6 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx)
{
- bool fNoncriticalErrors = false;
DBErrors result = DB_LOAD_OK;
try {
@@ -681,9 +680,6 @@ DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWal
result = DB_CORRUPT;
}
- if (fNoncriticalErrors && result == DB_LOAD_OK)
- result = DB_NONCRITICAL_ERROR;
-
return result;
}
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index fbb5215a51..f15e5de1e2 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include "wallet/walletutil.h"
+#include <wallet/walletutil.h>
fs::path GetWalletDir()
{
diff --git a/src/wallet/walletutil.h b/src/wallet/walletutil.h
index a94f286a44..50ff736402 100644
--- a/src/wallet/walletutil.h
+++ b/src/wallet/walletutil.h
@@ -5,7 +5,8 @@
#ifndef BITCOIN_WALLET_UTIL_H
#define BITCOIN_WALLET_UTIL_H
-#include "util.h"
+#include <chainparamsbase.h>
+#include <util.h>
//! Get the path of the wallet directory.
fs::path GetWalletDir();
diff --git a/test/functional/conf_args.py b/test/functional/conf_args.py
new file mode 100755
index 0000000000..61abba8082
--- /dev/null
+++ b/test/functional/conf_args.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 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 various command line arguments and configuration file parameters."""
+
+import os
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import get_datadir_path
+
+class ConfArgsTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 1
+
+ def run_test(self):
+ self.stop_node(0)
+ # Remove the -datadir argument so it doesn't override the config file
+ self.nodes[0].args = [arg for arg in self.nodes[0].args if not arg.startswith("-datadir")]
+
+ default_data_dir = get_datadir_path(self.options.tmpdir, 0)
+ new_data_dir = os.path.join(default_data_dir, 'newdatadir')
+ new_data_dir_2 = os.path.join(default_data_dir, 'newdatadir2')
+
+ # Check that using -datadir argument on non-existent directory fails
+ self.nodes[0].datadir = new_data_dir
+ self.assert_start_raises_init_error(0, ['-datadir='+new_data_dir], 'Error: Specified data directory "' + new_data_dir + '" does not exist.')
+
+ # Check that using non-existent datadir in conf file fails
+ conf_file = os.path.join(default_data_dir, "bitcoin.conf")
+ with open(conf_file, 'a', encoding='utf8') as f:
+ f.write("datadir=" + new_data_dir + "\n")
+ self.assert_start_raises_init_error(0, ['-conf='+conf_file], 'Error reading configuration file: specified data directory "' + new_data_dir + '" does not exist.')
+
+ # Create the directory and ensure the config file now works
+ os.mkdir(new_data_dir)
+ self.start_node(0, ['-conf='+conf_file, '-wallet=w1'])
+ self.stop_node(0)
+ assert os.path.isfile(os.path.join(new_data_dir, 'regtest', 'wallets', 'w1'))
+
+ # Ensure command line argument overrides datadir in conf
+ os.mkdir(new_data_dir_2)
+ self.nodes[0].datadir = new_data_dir_2
+ self.start_node(0, ['-datadir='+new_data_dir_2, '-conf='+conf_file, '-wallet=w2'])
+ assert os.path.isfile(os.path.join(new_data_dir_2, 'regtest', 'wallets', 'w2'))
+
+if __name__ == '__main__':
+ ConfArgsTest().main()
diff --git a/test/functional/multiwallet.py b/test/functional/multiwallet.py
index 06409b6f31..d0c40e5446 100755
--- a/test/functional/multiwallet.py
+++ b/test/functional/multiwallet.py
@@ -40,7 +40,11 @@ class MultiWalletTest(BitcoinTestFramework):
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
# should not initialize if the specified walletdir does not exist
- self.assert_start_raises_init_error(0, ['-walletdir=bad'], 'Error: Specified wallet directory "bad" does not exist.')
+ self.assert_start_raises_init_error(0, ['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
+ # should not initialize if the specified walletdir is not a directory
+ not_a_dir = os.path.join(wallet_dir, 'notadir')
+ open(not_a_dir, 'a').close()
+ self.assert_start_raises_init_error(0, ['-walletdir='+not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
# if wallets/ doesn't exist, datadir should be the default wallet dir
wallet_dir2 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')
diff --git a/test/functional/node_network_limited.py b/test/functional/node_network_limited.py
index 6d1bf7ced2..70415e0168 100755
--- a/test/functional/node_network_limited.py
+++ b/test/functional/node_network_limited.py
@@ -2,15 +2,26 @@
# Copyright (c) 2017 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Tests NODE_NETWORK_LIMITED.
+
+Tests that a node configured with -prune=550 signals NODE_NETWORK_LIMITED correctly
+and that it responds to getdata requests for blocks correctly:
+ - send a block within 288 + 2 of the tip
+ - disconnect peers who request blocks older than that."""
+from test_framework.messages import CInv, msg_getdata
+from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import *
-from test_framework.mininode import *
+from test_framework.util import assert_equal
-class BaseNode(P2PInterface):
- nServices = 0
- firstAddrnServices = 0
- def on_version(self, message):
- self.nServices = message.nServices
+class P2PIgnoreInv(P2PInterface):
+ def on_inv(self, message):
+ # The node will send us invs for other blocks. Ignore them.
+ pass
+
+ def send_getdata_for_block(self, blockhash):
+ getdata_request = msg_getdata()
+ getdata_request.inv.append(CInv(2, int(blockhash, 16)))
+ self.send_message(getdata_request)
class NodeNetworkLimitedTest(BitcoinTestFramework):
def set_test_params(self):
@@ -18,64 +29,29 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.num_nodes = 1
self.extra_args = [['-prune=550']]
- def getSignaledServiceFlags(self):
- node = self.nodes[0].add_p2p_connection(BaseNode())
+ def run_test(self):
+ node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
NetworkThread().start()
node.wait_for_verack()
- services = node.nServices
- self.nodes[0].disconnect_p2ps()
- node.wait_for_disconnect()
- return services
- def tryGetBlockViaGetData(self, blockhash, must_disconnect):
- node = self.nodes[0].add_p2p_connection(BaseNode())
- NetworkThread().start()
- node.wait_for_verack()
- node.send_message(msg_verack())
- getdata_request = msg_getdata()
- getdata_request.inv.append(CInv(2, int(blockhash, 16)))
- node.send_message(getdata_request)
+ expected_services = NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED
- if (must_disconnect):
- #ensure we get disconnected
- node.wait_for_disconnect(5)
- else:
- # check if the peer sends us the requested block
- node.wait_for_block(int(blockhash, 16), 3)
- self.nodes[0].disconnect_p2ps()
- node.wait_for_disconnect()
+ self.log.info("Check that node has signalled expected services.")
+ assert_equal(node.nServices, expected_services)
- def run_test(self):
- #NODE_BLOOM & NODE_WITNESS & NODE_NETWORK_LIMITED must now be signaled
- assert_equal(self.getSignaledServiceFlags(), 1036) #1036 == 0x40C == 0100 0000 1100
-# | ||
-# | |^--- NODE_BLOOM
-# | ^---- NODE_WITNESS
-# ^-- NODE_NETWORK_LIMITED
+ self.log.info("Check that the localservices is as expected.")
+ assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
- #now mine some blocks over the NODE_NETWORK_LIMITED + 2(racy buffer ext.) target
- firstblock = self.nodes[0].generate(1)[0]
+ self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
blocks = self.nodes[0].generate(292)
- blockWithinLimitedRange = blocks[-1]
-
- #make sure we can max retrive block at tip-288
- #requesting block at height 2 (tip-289) must fail (ignored)
- self.tryGetBlockViaGetData(firstblock, True) #first block must lead to disconnect
- self.tryGetBlockViaGetData(blocks[1], False) #last block in valid range
- self.tryGetBlockViaGetData(blocks[0], True) #first block outside of the 288+2 limit
-
- #NODE_NETWORK_LIMITED must still be signaled after restart
- self.restart_node(0)
- assert_equal(self.getSignaledServiceFlags(), 1036)
-
- #test the RPC service flags
- assert_equal(self.nodes[0].getnetworkinfo()['localservices'], "000000000000040c")
- # getdata a block above the NODE_NETWORK_LIMITED threshold must be possible
- self.tryGetBlockViaGetData(blockWithinLimitedRange, False)
+ self.log.info("Make sure we can max retrive block at tip-288.")
+ node.send_getdata_for_block(blocks[1]) # last block in valid range
+ node.wait_for_block(int(blocks[1], 16), timeout=3)
- # getdata a block below the NODE_NETWORK_LIMITED threshold must be ignored
- self.tryGetBlockViaGetData(firstblock, True)
+ self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
+ node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
+ node.wait_for_disconnect(5)
if __name__ == '__main__':
NodeNetworkLimitedTest().main()
diff --git a/test/functional/rawtransactions.py b/test/functional/rawtransactions.py
index 20da577af1..aa519eb8e8 100755
--- a/test/functional/rawtransactions.py
+++ b/test/functional/rawtransactions.py
@@ -253,6 +253,17 @@ class RawTransactionsTest(BitcoinTestFramework):
self.sync_all()
assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
+ # decoderawtransaction tests
+ # witness transaction
+ encrawtx = "010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000000000000"
+ 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
+ # non-witness transaction
+ encrawtx = "01000000010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f505000000000000000000"
+ decrawtx = self.nodes[0].decoderawtransaction(encrawtx, False) # decode as non-witness transaction
+ assert_equal(decrawtx['vout'][0]['value'], Decimal('1.00000000'))
+
# getrawtransaction tests
# 1. valid parameters - only supply txid
txHash = rawTx["hash"]
diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py
index 2ab1bdac0f..d8032e4430 100644
--- a/test/functional/test_framework/messages.py
+++ b/test/functional/test_framework/messages.py
@@ -38,10 +38,11 @@ COIN = 100000000 # 1 btc in satoshis
NODE_NETWORK = (1 << 0)
# NODE_GETUTXO = (1 << 1)
-# NODE_BLOOM = (1 << 2)
+NODE_BLOOM = (1 << 2)
NODE_WITNESS = (1 << 3)
NODE_UNSUPPORTED_SERVICE_BIT_5 = (1 << 5)
NODE_UNSUPPORTED_SERVICE_BIT_7 = (1 << 7)
+NODE_NETWORK_LIMITED = (1 << 10)
# Serialization/deserialization tools
def sha256(s):
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 58faec521d..bfd1192d3a 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -129,6 +129,7 @@ BASE_SCRIPTS= [
'p2p-acceptblock.py',
'feature_logging.py',
'node_network_limited.py',
+ 'conf_args.py',
]
EXTENDED_SCRIPTS = [
diff --git a/test/functional/wallet-dump.py b/test/functional/wallet-dump.py
index 47de8777a6..85812f9acc 100755
--- a/test/functional/wallet-dump.py
+++ b/test/functional/wallet-dump.py
@@ -10,13 +10,14 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, assert_raises_rpc_error)
-def read_dump(file_name, addrs, hd_master_addr_old):
+def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
"""
Read the given dump, count the addrs that match, count change and reserve.
Also check that the old hd_master is inactive
"""
with open(file_name, encoding='utf8') as inputfile:
found_addr = 0
+ found_script_addr = 0
found_addr_chg = 0
found_addr_rsv = 0
hd_master_addr_ret = None
@@ -38,6 +39,9 @@ def read_dump(file_name, addrs, hd_master_addr_old):
# ensure we have generated a new hd master key
assert(hd_master_addr_old != addr)
hd_master_addr_ret = addr
+ elif keytype == "script=1":
+ # scripts don't have keypaths
+ keypath = None
else:
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
@@ -52,7 +56,14 @@ def read_dump(file_name, addrs, hd_master_addr_old):
elif keytype == "reserve=1":
found_addr_rsv += 1
break
- return found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
+
+ # count scripts
+ for script_addr in script_addrs:
+ if script_addr == addr.rstrip() and keytype == "script=1":
+ found_script_addr += 1
+ break
+
+ return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
class WalletDumpTest(BitcoinTestFramework):
@@ -81,13 +92,19 @@ class WalletDumpTest(BitcoinTestFramework):
# Should be a no-op:
self.nodes[0].keypoolrefill()
+ # Test scripts dump by adding a P2SH witness and a 1-of-1 multisig address
+ witness_addr = self.nodes[0].addwitnessaddress(addrs[0]["address"], True)
+ multisig_addr = self.nodes[0].addmultisigaddress(1, [addrs[1]["address"]])
+ script_addrs = [witness_addr, multisig_addr]
+
# dump unencrypted wallet
result = self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.unencrypted.dump")
assert_equal(result['filename'], os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
- found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
- read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
+ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
+ read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, script_addrs, None)
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
+ assert_equal(found_script_addr, 2) # all scripts must be in the dump
assert_equal(found_addr_chg, 50) # 50 blocks where mined
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
@@ -99,14 +116,29 @@ class WalletDumpTest(BitcoinTestFramework):
self.nodes[0].keypoolrefill()
self.nodes[0].dumpwallet(tmpdir + "/node0/wallet.encrypted.dump")
- found_addr, found_addr_chg, found_addr_rsv, _ = \
- read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
+ found_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
+ read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, script_addrs, hd_master_addr_unenc)
assert_equal(found_addr, test_addr_count)
+ assert_equal(found_script_addr, 2)
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 90*2)
# Overwriting should fail
assert_raises_rpc_error(-8, "already exists", self.nodes[0].dumpwallet, tmpdir + "/node0/wallet.unencrypted.dump")
+ # Restart node with new wallet, and test importwallet
+ self.stop_node(0)
+ self.start_node(0, ['-wallet=w2'])
+
+ # Make sure the address is not IsMine before import
+ result = self.nodes[0].validateaddress(multisig_addr)
+ assert(result['ismine'] == False)
+
+ self.nodes[0].importwallet(os.path.abspath(tmpdir + "/node0/wallet.unencrypted.dump"))
+
+ # Now check IsMine is true
+ result = self.nodes[0].validateaddress(multisig_addr)
+ assert(result['ismine'] == True)
+
if __name__ == '__main__':
WalletDumpTest().main ()