mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#29015: kernel: Streamline util library
c7376babd1
doc: Clarify distinction between util and common libraries in libraries.md (Ryan Ofsky)4f74c59334
util: Move util/string.h functions to util namespace (Ryan Ofsky)4d05d3f3b4
util: add TransactionError includes and namespace declarations (Ryan Ofsky)680eafdc74
util: move fees.h and error.h to common/messages.h (Ryan Ofsky)02e62c6c9a
common: Add PSBTError enum (Ryan Ofsky)0d44c44ae3
util: move error.h TransactionError enum to node/types.h (Ryan Ofsky)9bcce2608d
util: move spanparsing.h to script/parsing.h (Ryan Ofsky)6dd2ad4792
util: move spanparsing.h Split functions to string.h (Ryan Ofsky)23cc8ddff4
util: move HexStr and HexDigit from util to crypto (TheCharlatan)6861f954f8
util: move util/message to common/signmessage (Ryan Ofsky)cc5f29fbea
build: move memory_cleanse from util to crypto (Ryan Ofsky)5b9309420c
build: move chainparamsbase from util to common (Ryan Ofsky)ffa27af24d
test: Add check-deps.sh script to check for unexpected library dependencies (Ryan Ofsky) Pull request description: Remove `fees.h`, `errors.h`, and `spanparsing.h` from the util library. Specifically: - Move `Split` functions from `util/spanparsing.h` to `util/string.h`, using `util` namespace for clarity. - Move remaining spanparsing functions to `script/parsing.h` since they are used for descriptor and miniscript parsing. - Combine `util/fees.h` and `util/errors.h` into `common/messages.h` so there is a place for simple functions that generate user messages to live, and these functions are not part of the util library. Motivation for this change is that the util library is a dependency of the kernel, and we should remove functionality from util that shouldn't be called by kernel code or kernel applications. These changes should also improve code organization and make functions easier to discover. Some of these same moves are (or were) part of #28690, but did not help with code organization, or made it worse, so it is better to move them and clean them up in the same PR so code only has to change one time. ACKs for top commit: achow101: ACKc7376babd1
TheCharlatan: Re-ACKc7376babd1
hebasto: re-ACKc7376babd1
. Tree-SHA512: 5bcef16c1255463b1b69270548711e7ff78ca0dd34e300b95e3ca1ce52ceb34f83d9ddb2839e83800ba36b200de30396e504bbb04fa02c6d0c24a16d06ae523d
This commit is contained in:
commit
011a895a82
121 changed files with 1023 additions and 526 deletions
203
contrib/devtools/check-deps.sh
Executable file
203
contrib/devtools/check-deps.sh
Executable file
|
@ -0,0 +1,203 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
export LC_ALL=C
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
# Declare paths to libraries
|
||||||
|
declare -A LIBS
|
||||||
|
LIBS[cli]="libbitcoin_cli.a"
|
||||||
|
LIBS[common]="libbitcoin_common.a"
|
||||||
|
LIBS[consensus]="libbitcoin_consensus.a"
|
||||||
|
LIBS[crypto]="crypto/.libs/libbitcoin_crypto_base.a crypto/.libs/libbitcoin_crypto_x86_shani.a crypto/.libs/libbitcoin_crypto_sse41.a crypto/.libs/libbitcoin_crypto_avx2.a"
|
||||||
|
LIBS[node]="libbitcoin_node.a"
|
||||||
|
LIBS[util]="libbitcoin_util.a"
|
||||||
|
LIBS[wallet]="libbitcoin_wallet.a"
|
||||||
|
LIBS[wallet_tool]="libbitcoin_wallet_tool.a"
|
||||||
|
|
||||||
|
# Declare allowed dependencies "X Y" where X is allowed to depend on Y. This
|
||||||
|
# list is taken from doc/design/libraries.md.
|
||||||
|
ALLOWED_DEPENDENCIES=(
|
||||||
|
"cli common"
|
||||||
|
"cli util"
|
||||||
|
"common consensus"
|
||||||
|
"common crypto"
|
||||||
|
"common util"
|
||||||
|
"consensus crypto"
|
||||||
|
"node common"
|
||||||
|
"node consensus"
|
||||||
|
"node crypto"
|
||||||
|
"node kernel"
|
||||||
|
"node util"
|
||||||
|
"util crypto"
|
||||||
|
"wallet common"
|
||||||
|
"wallet crypto"
|
||||||
|
"wallet util"
|
||||||
|
"wallet_tool util"
|
||||||
|
"wallet_tool wallet"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add minor dependencies omitted from doc/design/libraries.md to keep the
|
||||||
|
# dependency diagram simple.
|
||||||
|
ALLOWED_DEPENDENCIES+=(
|
||||||
|
"wallet consensus"
|
||||||
|
"wallet_tool common"
|
||||||
|
"wallet_tool crypto"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Declare list of known errors that should be suppressed.
|
||||||
|
declare -A SUPPRESS
|
||||||
|
# init.cpp file currently calls Berkeley DB sanity check function on startup, so
|
||||||
|
# there is an undocumented dependency of the node library on the wallet library.
|
||||||
|
SUPPRESS["libbitcoin_node_a-init.o libbitcoin_wallet_a-bdb.o _ZN6wallet27BerkeleyDatabaseSanityCheckEv"]=1
|
||||||
|
# init/common.cpp file calls InitError and InitWarning from interface_ui which
|
||||||
|
# is currently part of the node library. interface_ui should just be part of the
|
||||||
|
# common library instead, and is moved in
|
||||||
|
# https://github.com/bitcoin/bitcoin/issues/10102
|
||||||
|
SUPPRESS["libbitcoin_common_a-common.o libbitcoin_node_a-interface_ui.o _Z11InitWarningRK13bilingual_str"]=1
|
||||||
|
SUPPRESS["libbitcoin_common_a-common.o libbitcoin_node_a-interface_ui.o _Z9InitErrorRK13bilingual_str"]=1
|
||||||
|
# rpc/external_signer.cpp adds defines node RPC methods but is built as part of the
|
||||||
|
# common library. It should be moved to the node library instead.
|
||||||
|
SUPPRESS["libbitcoin_common_a-external_signer.o libbitcoin_node_a-server.o _ZN9CRPCTable13appendCommandERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPK11CRPCCommand"]=1
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $(basename "${BASH_SOURCE[0]}") [BUILD_DIR]"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Output makefile targets, converting library .a paths to libtool .la targets
|
||||||
|
lib_targets() {
|
||||||
|
for lib in "${!LIBS[@]}"; do
|
||||||
|
for lib_path in ${LIBS[$lib]}; do
|
||||||
|
# shellcheck disable=SC2001
|
||||||
|
sed 's:/.libs/\(.*\)\.a$:/\1.la:g' <<<"$lib_path"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extract symbol names and object names and write to text files
|
||||||
|
extract_symbols() {
|
||||||
|
local temp_dir="$1"
|
||||||
|
for lib in "${!LIBS[@]}"; do
|
||||||
|
for lib_path in ${LIBS[$lib]}; do
|
||||||
|
nm -o "$lib_path" | grep ' T ' | awk '{print $3, $1}' >> "${temp_dir}/${lib}_exports.txt"
|
||||||
|
nm -o "$lib_path" | grep ' U ' | awk '{print $3, $1}' >> "${temp_dir}/${lib}_imports.txt"
|
||||||
|
awk '{print $1}' "${temp_dir}/${lib}_exports.txt" | sort -u > "${temp_dir}/${lib}_exported_symbols.txt"
|
||||||
|
awk '{print $1}' "${temp_dir}/${lib}_imports.txt" | sort -u > "${temp_dir}/${lib}_imported_symbols.txt"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Lookup object name(s) corresponding to symbol name in text file
|
||||||
|
obj_names() {
|
||||||
|
local symbol="$1"
|
||||||
|
local txt_file="$2"
|
||||||
|
sed -n "s/^$symbol [^:]\\+:\\([^:]\\+\\):[^:]*\$/\\1/p" "$txt_file" | sort -u
|
||||||
|
}
|
||||||
|
|
||||||
|
# Iterate through libraries and find disallowed dependencies
|
||||||
|
check_libraries() {
|
||||||
|
local temp_dir="$1"
|
||||||
|
local result=0
|
||||||
|
for src in "${!LIBS[@]}"; do
|
||||||
|
for dst in "${!LIBS[@]}"; do
|
||||||
|
if [ "$src" != "$dst" ] && ! is_allowed "$src" "$dst"; then
|
||||||
|
if ! check_disallowed "$src" "$dst" "$temp_dir"; then
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
check_not_suppressed
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return whether src library is allowed to depend on dst.
|
||||||
|
is_allowed() {
|
||||||
|
local src="$1"
|
||||||
|
local dst="$2"
|
||||||
|
for allowed in "${ALLOWED_DEPENDENCIES[@]}"; do
|
||||||
|
if [ "$src $dst" = "$allowed" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return whether src library imports any symbols from dst, assuming src is not
|
||||||
|
# allowed to depend on dst.
|
||||||
|
check_disallowed() {
|
||||||
|
local src="$1"
|
||||||
|
local dst="$2"
|
||||||
|
local temp_dir="$3"
|
||||||
|
local result=0
|
||||||
|
|
||||||
|
# Loop over symbol names exported by dst and imported by src
|
||||||
|
while read symbol; do
|
||||||
|
local dst_obj
|
||||||
|
dst_obj=$(obj_names "$symbol" "${temp_dir}/${dst}_exports.txt")
|
||||||
|
while read src_obj; do
|
||||||
|
if ! check_suppress "$src_obj" "$dst_obj" "$symbol"; then
|
||||||
|
echo "Error: $src_obj depends on $dst_obj symbol '$(c++filt "$symbol")', can suppess with:"
|
||||||
|
echo " SUPPRESS[\"$src_obj $dst_obj $symbol\"]=1"
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
done < <(obj_names "$symbol" "${temp_dir}/${src}_imports.txt")
|
||||||
|
done < <(comm -12 "${temp_dir}/${dst}_exported_symbols.txt" "${temp_dir}/${src}_imported_symbols.txt")
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Declare array to track errors which were suppressed.
|
||||||
|
declare -A SUPPRESSED
|
||||||
|
|
||||||
|
# Return whether error should be suppressed and record suppresssion in
|
||||||
|
# SUPPRESSED array.
|
||||||
|
check_suppress() {
|
||||||
|
local src_obj="$1"
|
||||||
|
local dst_obj="$2"
|
||||||
|
local symbol="$3"
|
||||||
|
for suppress in "${!SUPPRESS[@]}"; do
|
||||||
|
read suppress_src suppress_dst suppress_pattern <<<"$suppress"
|
||||||
|
if [[ "$src_obj" == "$suppress_src" && "$dst_obj" == "$suppress_dst" && "$symbol" =~ $suppress_pattern ]]; then
|
||||||
|
SUPPRESSED["$suppress"]=1
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Warn about error which were supposed to be suppress, but were not encountered.
|
||||||
|
check_not_suppressed() {
|
||||||
|
for suppress in "${!SUPPRESS[@]}"; do
|
||||||
|
if [[ ! -v SUPPRESSED[$suppress] ]]; then
|
||||||
|
echo >&2 "Warning: suppression '$suppress' was ignored, consider deleting."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check arguments.
|
||||||
|
if [ "$#" = 0 ]; then
|
||||||
|
BUILD_DIR="$(dirname "${BASH_SOURCE[0]}")/../../src"
|
||||||
|
elif [ "$#" = 1 ]; then
|
||||||
|
BUILD_DIR="$1"
|
||||||
|
else
|
||||||
|
echo >&2 "Error: wrong number of arguments."
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -f "$BUILD_DIR/Makefile" ]; then
|
||||||
|
echo >&2 "Error: directory '$BUILD_DIR' does not contain a makefile, please specify path to build directory for library targets."
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build libraries and run checks.
|
||||||
|
cd "$BUILD_DIR"
|
||||||
|
# shellcheck disable=SC2046
|
||||||
|
make -j"$(nproc)" $(lib_targets)
|
||||||
|
TEMP_DIR="$(mktemp -d)"
|
||||||
|
extract_symbols "$TEMP_DIR"
|
||||||
|
if check_libraries "$TEMP_DIR"; then
|
||||||
|
echo "Success! No unexpected dependencies were detected."
|
||||||
|
else
|
||||||
|
echo >&2 "Error: Unexpected dependencies were detected. Check previous output."
|
||||||
|
fi
|
||||||
|
rm -r "$TEMP_DIR"
|
|
@ -5,6 +5,7 @@
|
||||||
| *libbitcoin_cli* | RPC client functionality used by *bitcoin-cli* executable |
|
| *libbitcoin_cli* | RPC client functionality used by *bitcoin-cli* executable |
|
||||||
| *libbitcoin_common* | Home for common functionality shared by different executables and libraries. Similar to *libbitcoin_util*, but higher-level (see [Dependencies](#dependencies)). |
|
| *libbitcoin_common* | Home for common functionality shared by different executables and libraries. Similar to *libbitcoin_util*, but higher-level (see [Dependencies](#dependencies)). |
|
||||||
| *libbitcoin_consensus* | Stable, backwards-compatible consensus functionality used by *libbitcoin_node* and *libbitcoin_wallet*. |
|
| *libbitcoin_consensus* | Stable, backwards-compatible consensus functionality used by *libbitcoin_node* and *libbitcoin_wallet*. |
|
||||||
|
| *libbitcoin_crypto* | Hardware-optimized functions for data encryption, hashing, message authentication, and key derivation. |
|
||||||
| *libbitcoin_kernel* | Consensus engine and support library used for validation by *libbitcoin_node*. |
|
| *libbitcoin_kernel* | Consensus engine and support library used for validation by *libbitcoin_node*. |
|
||||||
| *libbitcoinqt* | GUI functionality used by *bitcoin-qt* and *bitcoin-gui* executables. |
|
| *libbitcoinqt* | GUI functionality used by *bitcoin-qt* and *bitcoin-gui* executables. |
|
||||||
| *libbitcoin_ipc* | IPC functionality used by *bitcoin-node*, *bitcoin-wallet*, *bitcoin-gui* executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. |
|
| *libbitcoin_ipc* | IPC functionality used by *bitcoin-node*, *bitcoin-wallet*, *bitcoin-gui* executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. |
|
||||||
|
@ -53,13 +54,18 @@ bitcoin-wallet[bitcoin-wallet]-->libbitcoin_wallet_tool;
|
||||||
libbitcoin_cli-->libbitcoin_util;
|
libbitcoin_cli-->libbitcoin_util;
|
||||||
libbitcoin_cli-->libbitcoin_common;
|
libbitcoin_cli-->libbitcoin_common;
|
||||||
|
|
||||||
|
libbitcoin_consensus-->libbitcoin_crypto;
|
||||||
|
|
||||||
libbitcoin_common-->libbitcoin_consensus;
|
libbitcoin_common-->libbitcoin_consensus;
|
||||||
|
libbitcoin_common-->libbitcoin_crypto;
|
||||||
libbitcoin_common-->libbitcoin_util;
|
libbitcoin_common-->libbitcoin_util;
|
||||||
|
|
||||||
libbitcoin_kernel-->libbitcoin_consensus;
|
libbitcoin_kernel-->libbitcoin_consensus;
|
||||||
|
libbitcoin_kernel-->libbitcoin_crypto;
|
||||||
libbitcoin_kernel-->libbitcoin_util;
|
libbitcoin_kernel-->libbitcoin_util;
|
||||||
|
|
||||||
libbitcoin_node-->libbitcoin_consensus;
|
libbitcoin_node-->libbitcoin_consensus;
|
||||||
|
libbitcoin_node-->libbitcoin_crypto;
|
||||||
libbitcoin_node-->libbitcoin_kernel;
|
libbitcoin_node-->libbitcoin_kernel;
|
||||||
libbitcoin_node-->libbitcoin_common;
|
libbitcoin_node-->libbitcoin_common;
|
||||||
libbitcoin_node-->libbitcoin_util;
|
libbitcoin_node-->libbitcoin_util;
|
||||||
|
@ -67,7 +73,10 @@ libbitcoin_node-->libbitcoin_util;
|
||||||
libbitcoinqt-->libbitcoin_common;
|
libbitcoinqt-->libbitcoin_common;
|
||||||
libbitcoinqt-->libbitcoin_util;
|
libbitcoinqt-->libbitcoin_util;
|
||||||
|
|
||||||
|
libbitcoin_util-->libbitcoin_crypto;
|
||||||
|
|
||||||
libbitcoin_wallet-->libbitcoin_common;
|
libbitcoin_wallet-->libbitcoin_common;
|
||||||
|
libbitcoin_wallet-->libbitcoin_crypto;
|
||||||
libbitcoin_wallet-->libbitcoin_util;
|
libbitcoin_wallet-->libbitcoin_util;
|
||||||
|
|
||||||
libbitcoin_wallet_tool-->libbitcoin_wallet;
|
libbitcoin_wallet_tool-->libbitcoin_wallet;
|
||||||
|
@ -78,22 +87,23 @@ class bitcoin-qt,bitcoind,bitcoin-cli,bitcoin-wallet bold
|
||||||
```
|
```
|
||||||
</td></tr><tr><td>
|
</td></tr><tr><td>
|
||||||
|
|
||||||
**Dependency graph**. Arrows show linker symbol dependencies. *Consensus* lib depends on nothing. *Util* lib is depended on by everything. *Kernel* lib depends only on consensus and util.
|
**Dependency graph**. Arrows show linker symbol dependencies. *Crypto* lib depends on nothing. *Util* lib is depended on by everything. *Kernel* lib depends only on consensus, crypto, and util.
|
||||||
|
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
|
|
||||||
- The graph shows what _linker symbols_ (functions and variables) from each library other libraries can call and reference directly, but it is not a call graph. For example, there is no arrow connecting *libbitcoin_wallet* and *libbitcoin_node* libraries, because these libraries are intended to be modular and not depend on each other's internal implementation details. But wallet code is still able to call node code indirectly through the `interfaces::Chain` abstract class in [`interfaces/chain.h`](../../src/interfaces/chain.h) and node code calls wallet code through the `interfaces::ChainClient` and `interfaces::Chain::Notifications` abstract classes in the same file. In general, defining abstract classes in [`src/interfaces/`](../../src/interfaces/) can be a convenient way of avoiding unwanted direct dependencies or circular dependencies between libraries.
|
- The graph shows what _linker symbols_ (functions and variables) from each library other libraries can call and reference directly, but it is not a call graph. For example, there is no arrow connecting *libbitcoin_wallet* and *libbitcoin_node* libraries, because these libraries are intended to be modular and not depend on each other's internal implementation details. But wallet code is still able to call node code indirectly through the `interfaces::Chain` abstract class in [`interfaces/chain.h`](../../src/interfaces/chain.h) and node code calls wallet code through the `interfaces::ChainClient` and `interfaces::Chain::Notifications` abstract classes in the same file. In general, defining abstract classes in [`src/interfaces/`](../../src/interfaces/) can be a convenient way of avoiding unwanted direct dependencies or circular dependencies between libraries.
|
||||||
|
|
||||||
- *libbitcoin_consensus* should be a standalone dependency that any library can depend on, and it should not depend on any other libraries itself.
|
- *libbitcoin_crypto* should be a standalone dependency that any library can depend on, and it should not depend on any other libraries itself.
|
||||||
|
|
||||||
- *libbitcoin_util* should also be a standalone dependency that any library can depend on, and it should not depend on other internal libraries.
|
- *libbitcoin_consensus* should only depend on *libbitcoin_crypto*, and all other libraries besides *libbitcoin_crypto* should be allowed to depend on it.
|
||||||
|
|
||||||
- *libbitcoin_common* should serve a similar function as *libbitcoin_util* and be a place for miscellaneous code used by various daemon, GUI, and CLI applications and libraries to live. It should not depend on anything other than *libbitcoin_util* and *libbitcoin_consensus*. The boundary between _util_ and _common_ is a little fuzzy but historically _util_ has been used for more generic, lower-level things like parsing hex, and _common_ has been used for bitcoin-specific, higher-level things like parsing base58. The difference between util and common is mostly important because *libbitcoin_kernel* is not supposed to depend on *libbitcoin_common*, only *libbitcoin_util*. In general, if it is ever unclear whether it is better to add code to *util* or *common*, it is probably better to add it to *common* unless it is very generically useful or useful particularly to include in the kernel.
|
- *libbitcoin_util* should be a standalone dependency that any library can depend on, and it should not depend on other libraries except *libbitcoin_crypto*. It provides basic utilities that fill in gaps in the C++ standard library and provide lightweight abstractions over platform-specific features. Since the util library is distributed with the kernel and is usable by kernel applications, it shouldn't contain functions that external code shouldn't call, like higher level code targetted at the node or wallet. (*libbitcoin_common* is a better place for higher level code, or code that is meant to be used by internal applications only.)
|
||||||
|
|
||||||
|
- *libbitcoin_common* is a home for miscellaneous shared code used by different Bitcoin Core applications. It should not depend on anything other than *libbitcoin_util*, *libbitcoin_consensus*, and *libbitcoin_crypto*.
|
||||||
|
|
||||||
- *libbitcoin_kernel* should only depend on *libbitcoin_util* and *libbitcoin_consensus*.
|
- *libbitcoin_kernel* should only depend on *libbitcoin_util*, *libbitcoin_consensus*, and *libbitcoin_crypto*.
|
||||||
|
|
||||||
- The only thing that should depend on *libbitcoin_kernel* internally should be *libbitcoin_node*. GUI and wallet libraries *libbitcoinqt* and *libbitcoin_wallet* in particular should not depend on *libbitcoin_kernel* and the unneeded functionality it would pull in, like block validation. To the extent that GUI and wallet code need scripting and signing functionality, they should be get able it from *libbitcoin_consensus*, *libbitcoin_common*, and *libbitcoin_util*, instead of *libbitcoin_kernel*.
|
- The only thing that should depend on *libbitcoin_kernel* internally should be *libbitcoin_node*. GUI and wallet libraries *libbitcoinqt* and *libbitcoin_wallet* in particular should not depend on *libbitcoin_kernel* and the unneeded functionality it would pull in, like block validation. To the extent that GUI and wallet code need scripting and signing functionality, they should be get able it from *libbitcoin_consensus*, *libbitcoin_common*, *libbitcoin_crypto*, and *libbitcoin_util*, instead of *libbitcoin_kernel*.
|
||||||
|
|
||||||
- GUI, node, and wallet code internal implementations should all be independent of each other, and the *libbitcoinqt*, *libbitcoin_node*, *libbitcoin_wallet* libraries should never reference each other's symbols. They should only call each other through [`src/interfaces/`](../../src/interfaces/) abstract interfaces.
|
- GUI, node, and wallet code internal implementations should all be independent of each other, and the *libbitcoinqt*, *libbitcoin_node*, *libbitcoin_wallet* libraries should never reference each other's symbols. They should only call each other through [`src/interfaces/`](../../src/interfaces/) abstract interfaces.
|
||||||
|
|
||||||
|
|
|
@ -137,13 +137,16 @@ BITCOIN_CORE_H = \
|
||||||
common/bloom.h \
|
common/bloom.h \
|
||||||
common/init.h \
|
common/init.h \
|
||||||
common/run_command.h \
|
common/run_command.h \
|
||||||
|
common/types.h \
|
||||||
common/url.h \
|
common/url.h \
|
||||||
compat/assumptions.h \
|
compat/assumptions.h \
|
||||||
compat/byteswap.h \
|
compat/byteswap.h \
|
||||||
compat/compat.h \
|
compat/compat.h \
|
||||||
compat/cpuid.h \
|
compat/cpuid.h \
|
||||||
compat/endian.h \
|
compat/endian.h \
|
||||||
|
common/messages.h \
|
||||||
common/settings.h \
|
common/settings.h \
|
||||||
|
common/signmessage.h \
|
||||||
common/system.h \
|
common/system.h \
|
||||||
compressor.h \
|
compressor.h \
|
||||||
consensus/consensus.h \
|
consensus/consensus.h \
|
||||||
|
@ -233,6 +236,7 @@ BITCOIN_CORE_H = \
|
||||||
node/timeoffsets.h \
|
node/timeoffsets.h \
|
||||||
node/transaction.h \
|
node/transaction.h \
|
||||||
node/txreconciliation.h \
|
node/txreconciliation.h \
|
||||||
|
node/types.h \
|
||||||
node/utxo_snapshot.h \
|
node/utxo_snapshot.h \
|
||||||
node/validation_cache_args.h \
|
node/validation_cache_args.h \
|
||||||
noui.h \
|
noui.h \
|
||||||
|
@ -267,6 +271,7 @@ BITCOIN_CORE_H = \
|
||||||
script/descriptor.h \
|
script/descriptor.h \
|
||||||
script/keyorigin.h \
|
script/keyorigin.h \
|
||||||
script/miniscript.h \
|
script/miniscript.h \
|
||||||
|
script/parsing.h \
|
||||||
script/sigcache.h \
|
script/sigcache.h \
|
||||||
script/sign.h \
|
script/sign.h \
|
||||||
script/signingprovider.h \
|
script/signingprovider.h \
|
||||||
|
@ -297,11 +302,9 @@ BITCOIN_CORE_H = \
|
||||||
util/chaintype.h \
|
util/chaintype.h \
|
||||||
util/check.h \
|
util/check.h \
|
||||||
util/epochguard.h \
|
util/epochguard.h \
|
||||||
util/error.h \
|
|
||||||
util/exception.h \
|
util/exception.h \
|
||||||
util/fastrange.h \
|
util/fastrange.h \
|
||||||
util/feefrac.h \
|
util/feefrac.h \
|
||||||
util/fees.h \
|
|
||||||
util/fs.h \
|
util/fs.h \
|
||||||
util/fs_helpers.h \
|
util/fs_helpers.h \
|
||||||
util/golombrice.h \
|
util/golombrice.h \
|
||||||
|
@ -309,7 +312,6 @@ BITCOIN_CORE_H = \
|
||||||
util/hasher.h \
|
util/hasher.h \
|
||||||
util/insert.h \
|
util/insert.h \
|
||||||
util/macros.h \
|
util/macros.h \
|
||||||
util/message.h \
|
|
||||||
util/moneystr.h \
|
util/moneystr.h \
|
||||||
util/overflow.h \
|
util/overflow.h \
|
||||||
util/overloaded.h \
|
util/overloaded.h \
|
||||||
|
@ -319,7 +321,7 @@ BITCOIN_CORE_H = \
|
||||||
util/serfloat.h \
|
util/serfloat.h \
|
||||||
util/signalinterrupt.h \
|
util/signalinterrupt.h \
|
||||||
util/sock.h \
|
util/sock.h \
|
||||||
util/spanparsing.h \
|
util/strencodings.h \
|
||||||
util/string.h \
|
util/string.h \
|
||||||
util/subprocess.h \
|
util/subprocess.h \
|
||||||
util/syserror.h \
|
util/syserror.h \
|
||||||
|
@ -569,6 +571,8 @@ crypto_libbitcoin_crypto_base_la_SOURCES = \
|
||||||
crypto/chacha20poly1305.h \
|
crypto/chacha20poly1305.h \
|
||||||
crypto/chacha20poly1305.cpp \
|
crypto/chacha20poly1305.cpp \
|
||||||
crypto/common.h \
|
crypto/common.h \
|
||||||
|
crypto/hex_base.cpp \
|
||||||
|
crypto/hex_base.h \
|
||||||
crypto/hkdf_sha256_32.cpp \
|
crypto/hkdf_sha256_32.cpp \
|
||||||
crypto/hkdf_sha256_32.h \
|
crypto/hkdf_sha256_32.h \
|
||||||
crypto/hmac_sha256.cpp \
|
crypto/hmac_sha256.cpp \
|
||||||
|
@ -591,7 +595,8 @@ crypto_libbitcoin_crypto_base_la_SOURCES = \
|
||||||
crypto/sha512.cpp \
|
crypto/sha512.cpp \
|
||||||
crypto/sha512.h \
|
crypto/sha512.h \
|
||||||
crypto/siphash.cpp \
|
crypto/siphash.cpp \
|
||||||
crypto/siphash.h
|
crypto/siphash.h \
|
||||||
|
support/cleanse.cpp
|
||||||
|
|
||||||
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
|
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
|
||||||
# CXXFLAGS above
|
# CXXFLAGS above
|
||||||
|
@ -661,9 +666,7 @@ libbitcoin_consensus_a_SOURCES = \
|
||||||
span.h \
|
span.h \
|
||||||
tinyformat.h \
|
tinyformat.h \
|
||||||
uint256.cpp \
|
uint256.cpp \
|
||||||
uint256.h \
|
uint256.h
|
||||||
util/strencodings.cpp \
|
|
||||||
util/strencodings.h
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# common #
|
# common #
|
||||||
|
@ -673,6 +676,7 @@ libbitcoin_common_a_SOURCES = \
|
||||||
addresstype.cpp \
|
addresstype.cpp \
|
||||||
base58.cpp \
|
base58.cpp \
|
||||||
bech32.cpp \
|
bech32.cpp \
|
||||||
|
chainparamsbase.cpp \
|
||||||
chainparams.cpp \
|
chainparams.cpp \
|
||||||
coins.cpp \
|
coins.cpp \
|
||||||
common/args.cpp \
|
common/args.cpp \
|
||||||
|
@ -680,8 +684,10 @@ libbitcoin_common_a_SOURCES = \
|
||||||
common/config.cpp \
|
common/config.cpp \
|
||||||
common/init.cpp \
|
common/init.cpp \
|
||||||
common/interfaces.cpp \
|
common/interfaces.cpp \
|
||||||
|
common/messages.cpp \
|
||||||
common/run_command.cpp \
|
common/run_command.cpp \
|
||||||
common/settings.cpp \
|
common/settings.cpp \
|
||||||
|
common/signmessage.cpp \
|
||||||
common/system.cpp \
|
common/system.cpp \
|
||||||
common/url.cpp \
|
common/url.cpp \
|
||||||
compressor.cpp \
|
compressor.cpp \
|
||||||
|
@ -711,6 +717,7 @@ libbitcoin_common_a_SOURCES = \
|
||||||
scheduler.cpp \
|
scheduler.cpp \
|
||||||
script/descriptor.cpp \
|
script/descriptor.cpp \
|
||||||
script/miniscript.cpp \
|
script/miniscript.cpp \
|
||||||
|
script/parsing.cpp \
|
||||||
script/sign.cpp \
|
script/sign.cpp \
|
||||||
script/signingprovider.cpp \
|
script/signingprovider.cpp \
|
||||||
script/solver.cpp \
|
script/solver.cpp \
|
||||||
|
@ -723,13 +730,11 @@ libbitcoin_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||||
libbitcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
libbitcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
libbitcoin_util_a_SOURCES = \
|
libbitcoin_util_a_SOURCES = \
|
||||||
support/lockedpool.cpp \
|
support/lockedpool.cpp \
|
||||||
chainparamsbase.cpp \
|
|
||||||
clientversion.cpp \
|
clientversion.cpp \
|
||||||
logging.cpp \
|
logging.cpp \
|
||||||
random.cpp \
|
random.cpp \
|
||||||
randomenv.cpp \
|
randomenv.cpp \
|
||||||
streams.cpp \
|
streams.cpp \
|
||||||
support/cleanse.cpp \
|
|
||||||
sync.cpp \
|
sync.cpp \
|
||||||
util/asmap.cpp \
|
util/asmap.cpp \
|
||||||
util/batchpriority.cpp \
|
util/batchpriority.cpp \
|
||||||
|
@ -737,16 +742,13 @@ libbitcoin_util_a_SOURCES = \
|
||||||
util/bytevectorhash.cpp \
|
util/bytevectorhash.cpp \
|
||||||
util/chaintype.cpp \
|
util/chaintype.cpp \
|
||||||
util/check.cpp \
|
util/check.cpp \
|
||||||
util/error.cpp \
|
|
||||||
util/exception.cpp \
|
util/exception.cpp \
|
||||||
util/feefrac.cpp \
|
util/feefrac.cpp \
|
||||||
util/fees.cpp \
|
|
||||||
util/fs.cpp \
|
util/fs.cpp \
|
||||||
util/fs_helpers.cpp \
|
util/fs_helpers.cpp \
|
||||||
util/hasher.cpp \
|
util/hasher.cpp \
|
||||||
util/sock.cpp \
|
util/sock.cpp \
|
||||||
util/syserror.cpp \
|
util/syserror.cpp \
|
||||||
util/message.cpp \
|
|
||||||
util/moneystr.cpp \
|
util/moneystr.cpp \
|
||||||
util/rbf.cpp \
|
util/rbf.cpp \
|
||||||
util/readwritefile.cpp \
|
util/readwritefile.cpp \
|
||||||
|
@ -755,7 +757,6 @@ libbitcoin_util_a_SOURCES = \
|
||||||
util/threadinterrupt.cpp \
|
util/threadinterrupt.cpp \
|
||||||
util/threadnames.cpp \
|
util/threadnames.cpp \
|
||||||
util/serfloat.cpp \
|
util/serfloat.cpp \
|
||||||
util/spanparsing.cpp \
|
|
||||||
util/strencodings.cpp \
|
util/strencodings.cpp \
|
||||||
util/string.cpp \
|
util/string.cpp \
|
||||||
util/time.cpp \
|
util/time.cpp \
|
||||||
|
@ -972,7 +973,6 @@ libbitcoinkernel_la_SOURCES = \
|
||||||
script/solver.cpp \
|
script/solver.cpp \
|
||||||
signet.cpp \
|
signet.cpp \
|
||||||
streams.cpp \
|
streams.cpp \
|
||||||
support/cleanse.cpp \
|
|
||||||
support/lockedpool.cpp \
|
support/lockedpool.cpp \
|
||||||
sync.cpp \
|
sync.cpp \
|
||||||
txdb.cpp \
|
txdb.cpp \
|
||||||
|
|
|
@ -375,6 +375,7 @@ test_fuzz_fuzz_SOURCES = \
|
||||||
test/fuzz/script_format.cpp \
|
test/fuzz/script_format.cpp \
|
||||||
test/fuzz/script_interpreter.cpp \
|
test/fuzz/script_interpreter.cpp \
|
||||||
test/fuzz/script_ops.cpp \
|
test/fuzz/script_ops.cpp \
|
||||||
|
test/fuzz/script_parsing.cpp \
|
||||||
test/fuzz/script_sigcache.cpp \
|
test/fuzz/script_sigcache.cpp \
|
||||||
test/fuzz/script_sign.cpp \
|
test/fuzz/script_sign.cpp \
|
||||||
test/fuzz/scriptnum_ops.cpp \
|
test/fuzz/scriptnum_ops.cpp \
|
||||||
|
@ -384,7 +385,6 @@ test_fuzz_fuzz_SOURCES = \
|
||||||
test/fuzz/signet.cpp \
|
test/fuzz/signet.cpp \
|
||||||
test/fuzz/socks5.cpp \
|
test/fuzz/socks5.cpp \
|
||||||
test/fuzz/span.cpp \
|
test/fuzz/span.cpp \
|
||||||
test/fuzz/spanparsing.cpp \
|
|
||||||
test/fuzz/string.cpp \
|
test/fuzz/string.cpp \
|
||||||
test/fuzz/strprintf.cpp \
|
test/fuzz/strprintf.cpp \
|
||||||
test/fuzz/system.cpp \
|
test/fuzz/system.cpp \
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
using util::ContainsNoNUL;
|
||||||
|
|
||||||
/** All alphanumeric characters except for "0", "I", "O", and "l" */
|
/** All alphanumeric characters except for "0", "I", "O", and "l" */
|
||||||
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
static const int8_t mapBase58[256] = {
|
static const int8_t mapBase58[256] = {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
static const char* DEFAULT_BENCH_FILTER = ".*";
|
static const char* DEFAULT_BENCH_FILTER = ".*";
|
||||||
static constexpr int64_t DEFAULT_MIN_TIME_MS{10};
|
static constexpr int64_t DEFAULT_MIN_TIME_MS{10};
|
||||||
/** Priority level default value, run "all" priority levels */
|
/** Priority level default value, run "all" priority levels */
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
#include <event2/keyvalq_struct.h>
|
#include <event2/keyvalq_struct.h>
|
||||||
#include <support/events.h>
|
#include <support/events.h>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
// The server returns time values from a mockable system clock, but it is not
|
// The server returns time values from a mockable system clock, but it is not
|
||||||
// trivial to get the mocked time from the server, nor is it needed for now, so
|
// trivial to get the mocked time from the server, nor is it needed for now, so
|
||||||
// just use a plain system_clock.
|
// just use a plain system_clock.
|
||||||
|
|
|
@ -32,6 +32,11 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
using util::ToString;
|
||||||
|
using util::TrimString;
|
||||||
|
using util::TrimStringView;
|
||||||
|
|
||||||
static bool fCreateBlank;
|
static bool fCreateBlank;
|
||||||
static std::map<std::string,UniValue> registers;
|
static std::map<std::string,UniValue> registers;
|
||||||
static const int CONTINUE_EXECUTION=-1;
|
static const int CONTINUE_EXECUTION=-1;
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||||
|
|
||||||
static void SetupWalletToolArgs(ArgsManager& argsman)
|
static void SetupWalletToolArgs(ArgsManager& argsman)
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <util/golombrice.h>
|
#include <util/golombrice.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
static const std::map<BlockFilterType, std::string> g_filter_types = {
|
static const std::map<BlockFilterType, std::string> g_filter_types = {
|
||||||
{BlockFilterType::BASIC, "basic"},
|
{BlockFilterType::BASIC, "basic"},
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
||||||
{
|
{
|
||||||
if (args.IsArgSet("-signetseednode")) {
|
if (args.IsArgSet("-signetseednode")) {
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of client reported in the 'version' message. Report the same name
|
* Name of client reported in the 'version' message. Report the same name
|
||||||
* for both bitcoind and bitcoin-qt, to make it harder for attackers to
|
* for both bitcoind and bitcoin-qt, to make it harder for attackers to
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::TrimString;
|
||||||
|
using util::TrimStringView;
|
||||||
|
|
||||||
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
|
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
|
||||||
{
|
{
|
||||||
std::string str, prefix;
|
std::string str, prefix;
|
||||||
|
|
139
src/common/messages.cpp
Normal file
139
src/common/messages.cpp
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
|
// Copyright (c) 2009-2022 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 <common/messages.h>
|
||||||
|
|
||||||
|
#include <common/types.h>
|
||||||
|
#include <policy/fees.h>
|
||||||
|
#include <node/types.h>
|
||||||
|
#include <tinyformat.h>
|
||||||
|
#include <util/strencodings.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
#include <util/translation.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using node::TransactionError;
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
|
namespace common {
|
||||||
|
std::string StringForFeeReason(FeeReason reason)
|
||||||
|
{
|
||||||
|
static const std::map<FeeReason, std::string> fee_reason_strings = {
|
||||||
|
{FeeReason::NONE, "None"},
|
||||||
|
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
||||||
|
{FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
|
||||||
|
{FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
|
||||||
|
{FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
|
||||||
|
{FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
|
||||||
|
{FeeReason::PAYTXFEE, "PayTxFee set"},
|
||||||
|
{FeeReason::FALLBACK, "Fallback fee"},
|
||||||
|
{FeeReason::REQUIRED, "Minimum Required Fee"},
|
||||||
|
};
|
||||||
|
auto reason_string = fee_reason_strings.find(reason);
|
||||||
|
|
||||||
|
if (reason_string == fee_reason_strings.end()) return "Unknown";
|
||||||
|
|
||||||
|
return reason_string->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
|
||||||
|
{
|
||||||
|
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
|
||||||
|
{"unset", FeeEstimateMode::UNSET},
|
||||||
|
{"economical", FeeEstimateMode::ECONOMICAL},
|
||||||
|
{"conservative", FeeEstimateMode::CONSERVATIVE},
|
||||||
|
};
|
||||||
|
return FEE_MODES;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FeeModes(const std::string& delimiter)
|
||||||
|
{
|
||||||
|
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string InvalidEstimateModeErrorMessage()
|
||||||
|
{
|
||||||
|
return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
|
||||||
|
{
|
||||||
|
auto searchkey = ToUpper(mode_string);
|
||||||
|
for (const auto& pair : FeeModeMap()) {
|
||||||
|
if (ToUpper(pair.first) == searchkey) {
|
||||||
|
fee_estimate_mode = pair.second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str PSBTErrorString(PSBTError err)
|
||||||
|
{
|
||||||
|
switch (err) {
|
||||||
|
case PSBTError::MISSING_INPUTS:
|
||||||
|
return Untranslated("Inputs missing or spent");
|
||||||
|
case PSBTError::SIGHASH_MISMATCH:
|
||||||
|
return Untranslated("Specified sighash value does not match value stored in PSBT");
|
||||||
|
case PSBTError::EXTERNAL_SIGNER_NOT_FOUND:
|
||||||
|
return Untranslated("External signer not found");
|
||||||
|
case PSBTError::EXTERNAL_SIGNER_FAILED:
|
||||||
|
return Untranslated("External signer failed to sign");
|
||||||
|
case PSBTError::UNSUPPORTED:
|
||||||
|
return Untranslated("Signer does not support PSBT");
|
||||||
|
// no default case, so the compiler can warn about missing cases
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str TransactionErrorString(const TransactionError err)
|
||||||
|
{
|
||||||
|
switch (err) {
|
||||||
|
case TransactionError::OK:
|
||||||
|
return Untranslated("No error");
|
||||||
|
case TransactionError::MISSING_INPUTS:
|
||||||
|
return Untranslated("Inputs missing or spent");
|
||||||
|
case TransactionError::ALREADY_IN_CHAIN:
|
||||||
|
return Untranslated("Transaction already in block chain");
|
||||||
|
case TransactionError::MEMPOOL_REJECTED:
|
||||||
|
return Untranslated("Transaction rejected by mempool");
|
||||||
|
case TransactionError::MEMPOOL_ERROR:
|
||||||
|
return Untranslated("Mempool internal error");
|
||||||
|
case TransactionError::MAX_FEE_EXCEEDED:
|
||||||
|
return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
|
||||||
|
case TransactionError::MAX_BURN_EXCEEDED:
|
||||||
|
return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
|
||||||
|
case TransactionError::INVALID_PACKAGE:
|
||||||
|
return Untranslated("Transaction rejected due to invalid package");
|
||||||
|
// no default case, so the compiler can warn about missing cases
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
|
||||||
|
{
|
||||||
|
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)
|
||||||
|
{
|
||||||
|
return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str AmountHighWarn(const std::string& optname)
|
||||||
|
{
|
||||||
|
return strprintf(_("%s is set very high!"), optname);
|
||||||
|
}
|
||||||
|
|
||||||
|
bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
|
||||||
|
{
|
||||||
|
return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
|
||||||
|
}
|
||||||
|
} // namespace common
|
38
src/common/messages.h
Normal file
38
src/common/messages.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
//! @file common/messages.h is a home for simple string functions returning
|
||||||
|
//! descriptive messages that are used in RPC and GUI interfaces or log
|
||||||
|
//! messages, and are called in different parts of the codebase across
|
||||||
|
//! node/wallet/gui boundaries.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_COMMON_MESSAGES_H
|
||||||
|
#define BITCOIN_COMMON_MESSAGES_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct bilingual_str;
|
||||||
|
|
||||||
|
enum class FeeEstimateMode;
|
||||||
|
enum class FeeReason;
|
||||||
|
namespace node {
|
||||||
|
enum class TransactionError;
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
|
namespace common {
|
||||||
|
enum class PSBTError;
|
||||||
|
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||||
|
std::string StringForFeeReason(FeeReason reason);
|
||||||
|
std::string FeeModes(const std::string& delimiter);
|
||||||
|
std::string InvalidEstimateModeErrorMessage();
|
||||||
|
bilingual_str PSBTErrorString(PSBTError error);
|
||||||
|
bilingual_str TransactionErrorString(const node::TransactionError error);
|
||||||
|
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind);
|
||||||
|
bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& strPort);
|
||||||
|
bilingual_str AmountHighWarn(const std::string& optname);
|
||||||
|
bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue);
|
||||||
|
} // namespace common
|
||||||
|
|
||||||
|
#endif // BITCOIN_COMMON_MESSAGES_H
|
|
@ -3,12 +3,12 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/signmessage.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/message.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
|
@ -3,8 +3,8 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#ifndef BITCOIN_UTIL_MESSAGE_H
|
#ifndef BITCOIN_COMMON_SIGNMESSAGE_H
|
||||||
#define BITCOIN_UTIL_MESSAGE_H
|
#define BITCOIN_COMMON_SIGNMESSAGE_H
|
||||||
|
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
|
@ -74,4 +74,4 @@ uint256 MessageHash(const std::string& message);
|
||||||
|
|
||||||
std::string SigningResultString(const SigningResult res);
|
std::string SigningResultString(const SigningResult res);
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_MESSAGE_H
|
#endif // BITCOIN_COMMON_SIGNMESSAGE_H
|
|
@ -28,6 +28,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
using util::ReplaceAll;
|
||||||
|
|
||||||
// Application startup time (used for uptime calculation)
|
// Application startup time (used for uptime calculation)
|
||||||
const int64_t nStartupTime = GetTime();
|
const int64_t nStartupTime = GetTime();
|
||||||
|
|
||||||
|
|
26
src/common/types.h
Normal file
26
src/common/types.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (c) 2010-2021 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
//! @file common/types.h is a home for simple enum and struct type definitions
|
||||||
|
//! that can be used internally by functions in the libbitcoin_common library,
|
||||||
|
//! but also used externally by node, wallet, and GUI code.
|
||||||
|
//!
|
||||||
|
//! This file is intended to define only simple types that do not have external
|
||||||
|
//! dependencies. More complicated types should be defined in dedicated header
|
||||||
|
//! files.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_COMMON_TYPES_H
|
||||||
|
#define BITCOIN_COMMON_TYPES_H
|
||||||
|
|
||||||
|
namespace common {
|
||||||
|
enum class PSBTError {
|
||||||
|
MISSING_INPUTS,
|
||||||
|
SIGHASH_MISMATCH,
|
||||||
|
EXTERNAL_SIGNER_NOT_FOUND,
|
||||||
|
EXTERNAL_SIGNER_FAILED,
|
||||||
|
UNSUPPORTED,
|
||||||
|
};
|
||||||
|
} // namespace common
|
||||||
|
|
||||||
|
#endif // BITCOIN_COMMON_TYPES_H
|
|
@ -16,6 +16,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class OpCodeParser
|
class OpCodeParser
|
||||||
{
|
{
|
||||||
|
|
67
src/crypto/hex_base.cpp
Normal file
67
src/crypto/hex_base.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
// Copyright (c) 2009-present 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 <crypto/hex_base.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ByteAsHex = std::array<char, 2>;
|
||||||
|
|
||||||
|
constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
|
||||||
|
{
|
||||||
|
constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
|
||||||
|
std::array<ByteAsHex, 256> byte_to_hex{};
|
||||||
|
for (size_t i = 0; i < byte_to_hex.size(); ++i) {
|
||||||
|
byte_to_hex[i][0] = hexmap[i >> 4];
|
||||||
|
byte_to_hex[i][1] = hexmap[i & 15];
|
||||||
|
}
|
||||||
|
return byte_to_hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::string HexStr(const Span<const uint8_t> s)
|
||||||
|
{
|
||||||
|
std::string rv(s.size() * 2, '\0');
|
||||||
|
static constexpr auto byte_to_hex = CreateByteToHexMap();
|
||||||
|
static_assert(sizeof(byte_to_hex) == 512);
|
||||||
|
|
||||||
|
char* it = rv.data();
|
||||||
|
for (uint8_t v : s) {
|
||||||
|
std::memcpy(it, byte_to_hex[v].data(), 2);
|
||||||
|
it += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(it == rv.data() + rv.size());
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
const signed char p_util_hexdigit[256] =
|
||||||
|
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
|
||||||
|
|
||||||
|
signed char HexDigit(char c)
|
||||||
|
{
|
||||||
|
return p_util_hexdigit[(unsigned char)c];
|
||||||
|
}
|
||||||
|
|
23
src/crypto/hex_base.h
Normal file
23
src/crypto/hex_base.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright (c) 2009-present The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_CRYPTO_HEX_BASE_H
|
||||||
|
#define BITCOIN_CRYPTO_HEX_BASE_H
|
||||||
|
|
||||||
|
#include <span.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a span of bytes to a lower-case hexadecimal string.
|
||||||
|
*/
|
||||||
|
std::string HexStr(const Span<const uint8_t> s);
|
||||||
|
inline std::string HexStr(const Span<const char> s) { return HexStr(MakeUCharSpan(s)); }
|
||||||
|
inline std::string HexStr(const Span<const std::byte> s) { return HexStr(MakeUCharSpan(s)); }
|
||||||
|
|
||||||
|
signed char HexDigit(char c);
|
||||||
|
|
||||||
|
#endif // BITCOIN_CRYPTO_HEX_BASE_H
|
|
@ -23,6 +23,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
using util::TrimStringView;
|
||||||
|
|
||||||
/** WWW-Authenticate to present with 401 Unauthorized response */
|
/** WWW-Authenticate to present with 401 Unauthorized response */
|
||||||
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
|
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
|
#include <script/parsing.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/readwritefile.h>
|
#include <util/readwritefile.h>
|
||||||
#include <util/sock.h>
|
#include <util/sock.h>
|
||||||
#include <util/spanparsing.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/threadinterrupt.h>
|
#include <util/threadinterrupt.h>
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using util::Split;
|
||||||
|
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,7 +310,7 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
|
||||||
|
|
||||||
reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE);
|
reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE);
|
||||||
|
|
||||||
for (const auto& kv : spanparsing::Split(reply.full, ' ')) {
|
for (const auto& kv : Split(reply.full, ' ')) {
|
||||||
const auto& pos = std::find(kv.begin(), kv.end(), '=');
|
const auto& pos = std::find(kv.begin(), kv.end(), '=');
|
||||||
if (pos != kv.end()) {
|
if (pos != kv.end()) {
|
||||||
reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()});
|
reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()});
|
||||||
|
|
|
@ -115,6 +115,9 @@
|
||||||
#include <zmq/zmqrpc.h>
|
#include <zmq/zmqrpc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using common::AmountErrMsg;
|
||||||
|
using common::InvalidPortErrMsg;
|
||||||
|
using common::ResolveErrMsg;
|
||||||
using kernel::DumpMempool;
|
using kernel::DumpMempool;
|
||||||
using kernel::LoadMempool;
|
using kernel::LoadMempool;
|
||||||
using kernel::ValidationCacheSizes;
|
using kernel::ValidationCacheSizes;
|
||||||
|
@ -133,6 +136,9 @@ using node::NodeContext;
|
||||||
using node::ShouldPersistMempool;
|
using node::ShouldPersistMempool;
|
||||||
using node::ImportBlocks;
|
using node::ImportBlocks;
|
||||||
using node::VerifyLoadedChainstate;
|
using node::VerifyLoadedChainstate;
|
||||||
|
using util::Join;
|
||||||
|
using util::ReplaceAll;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
|
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
|
||||||
static constexpr bool DEFAULT_REST_ENABLE{false};
|
static constexpr bool DEFAULT_REST_ENABLE{false};
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
namespace init {
|
namespace init {
|
||||||
void AddLoggingArgs(ArgsManager& argsman)
|
void AddLoggingArgs(ArgsManager& argsman)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,10 +30,10 @@ class RPCTimerInterface;
|
||||||
class UniValue;
|
class UniValue;
|
||||||
class Proxy;
|
class Proxy;
|
||||||
enum class SynchronizationState;
|
enum class SynchronizationState;
|
||||||
enum class TransactionError;
|
|
||||||
struct CNodeStateStats;
|
struct CNodeStateStats;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
namespace node {
|
namespace node {
|
||||||
|
enum class TransactionError;
|
||||||
struct NodeContext;
|
struct NodeContext;
|
||||||
} // namespace node
|
} // namespace node
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
|
@ -208,7 +208,7 @@ public:
|
||||||
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
|
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
|
||||||
|
|
||||||
//! Broadcast transaction.
|
//! Broadcast transaction.
|
||||||
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
|
virtual node::TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
|
||||||
|
|
||||||
//! Get wallet loader.
|
//! Get wallet loader.
|
||||||
virtual WalletLoader& walletLoader() = 0;
|
virtual WalletLoader& walletLoader() = 0;
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
#define BITCOIN_INTERFACES_WALLET_H
|
#define BITCOIN_INTERFACES_WALLET_H
|
||||||
|
|
||||||
#include <addresstype.h>
|
#include <addresstype.h>
|
||||||
|
#include <common/signmessage.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <support/allocators/secure.h>
|
#include <support/allocators/secure.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/message.h>
|
|
||||||
#include <util/result.h>
|
#include <util/result.h>
|
||||||
#include <util/ui_change_type.h>
|
#include <util/ui_change_type.h>
|
||||||
|
|
||||||
|
@ -30,9 +30,14 @@ class CFeeRate;
|
||||||
class CKey;
|
class CKey;
|
||||||
enum class FeeReason;
|
enum class FeeReason;
|
||||||
enum class OutputType;
|
enum class OutputType;
|
||||||
enum class TransactionError;
|
|
||||||
struct PartiallySignedTransaction;
|
struct PartiallySignedTransaction;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
namespace common {
|
||||||
|
enum class PSBTError;
|
||||||
|
} // namespace common
|
||||||
|
namespace node {
|
||||||
|
enum class TransactionError;
|
||||||
|
} // namespace node
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
class CCoinControl;
|
class CCoinControl;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
|
@ -202,7 +207,7 @@ public:
|
||||||
int& num_blocks) = 0;
|
int& num_blocks) = 0;
|
||||||
|
|
||||||
//! Fill PSBT.
|
//! Fill PSBT.
|
||||||
virtual TransactionError fillPSBT(int sighash_type,
|
virtual std::optional<common::PSBTError> fillPSBT(int sighash_type,
|
||||||
bool sign,
|
bool sign,
|
||||||
bool bip32derivs,
|
bool bip32derivs,
|
||||||
size_t* n_signed,
|
size_t* n_signed,
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
using util::RemovePrefix;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
|
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
|
||||||
constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info};
|
constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info};
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ namespace BCLog {
|
||||||
/** Returns a string with the log categories in alphabetical order. */
|
/** Returns a string with the log categories in alphabetical order. */
|
||||||
std::string LogCategoriesString() const
|
std::string LogCategoriesString() const
|
||||||
{
|
{
|
||||||
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
return util::Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Returns a string with all user-selectable log levels.
|
//! Returns a string with all user-selectable log levels.
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <common/system.h>
|
#include <common/system.h>
|
||||||
#include <net_permissions.h>
|
#include <net_permissions.h>
|
||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
#include <util/error.h>
|
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
|
using common::ResolveErrMsg;
|
||||||
|
|
||||||
const std::vector<std::string> NET_PERMISSIONS_DOC{
|
const std::vector<std::string> NET_PERMISSIONS_DOC{
|
||||||
"bloomfilter (allow requesting BIP37 filtered blocks and transactions)",
|
"bloomfilter (allow requesting BIP37 filtered blocks and transactions)",
|
||||||
"noban (do not ban for misbehavior; implies download)",
|
"noban (do not ban for misbehavior; implies download)",
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
using util::ContainsNoNUL;
|
||||||
|
using util::HasPrefix;
|
||||||
|
|
||||||
CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const
|
CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const
|
||||||
{
|
{
|
||||||
switch (m_net) {
|
switch (m_net) {
|
||||||
|
|
|
@ -448,7 +448,7 @@ private:
|
||||||
// Recognize NET_INTERNAL embedded in IPv6, such addresses are not
|
// Recognize NET_INTERNAL embedded in IPv6, such addresses are not
|
||||||
// gossiped but could be coming from addrman, when unserializing from
|
// gossiped but could be coming from addrman, when unserializing from
|
||||||
// disk.
|
// disk.
|
||||||
if (HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) {
|
if (util::HasPrefix(m_addr, INTERNAL_IN_IPV6_PREFIX)) {
|
||||||
m_net = NET_INTERNAL;
|
m_net = NET_INTERNAL;
|
||||||
memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
|
memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
|
||||||
ADDR_INTERNAL_SIZE);
|
ADDR_INTERNAL_SIZE);
|
||||||
|
@ -456,8 +456,8 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) &&
|
if (!util::HasPrefix(m_addr, IPV4_IN_IPV6_PREFIX) &&
|
||||||
!HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) {
|
!util::HasPrefix(m_addr, TORV2_IN_IPV6_PREFIX)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using util::ContainsNoNUL;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
static GlobalMutex g_proxyinfo_mutex;
|
static GlobalMutex g_proxyinfo_mutex;
|
||||||
static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
|
static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <boost/signals2/optional_last_value.hpp>
|
#include <boost/signals2/optional_last_value.hpp>
|
||||||
#include <boost/signals2/signal.hpp>
|
#include <boost/signals2/signal.hpp>
|
||||||
|
|
||||||
|
using util::MakeUnorderedList;
|
||||||
|
|
||||||
CClientUIInterface uiInterface;
|
CClientUIInterface uiInterface;
|
||||||
|
|
||||||
struct UISignals {
|
struct UISignals {
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <node/mini_miner.h>
|
#include <node/mini_miner.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
|
@ -70,6 +71,7 @@ using interfaces::Handler;
|
||||||
using interfaces::MakeSignalHandler;
|
using interfaces::MakeSignalHandler;
|
||||||
using interfaces::Node;
|
using interfaces::Node;
|
||||||
using interfaces::WalletLoader;
|
using interfaces::WalletLoader;
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
// All members of the classes in this namespace are intentionally public, as the
|
// All members of the classes in this namespace are intentionally public, as the
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
using util::ReplaceAll;
|
||||||
|
|
||||||
static void AlertNotify(const std::string& strMessage)
|
static void AlertNotify(const std::string& strMessage)
|
||||||
{
|
{
|
||||||
uiInterface.NotifyAlertChanged();
|
uiInterface.NotifyAlertChanged();
|
||||||
|
|
|
@ -8,19 +8,20 @@
|
||||||
#include <kernel/mempool_options.h>
|
#include <kernel/mempool_options.h>
|
||||||
|
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
|
#include <common/messages.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <kernel/chainparams.h>
|
#include <kernel/chainparams.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/error.h>
|
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
using common::AmountErrMsg;
|
||||||
using kernel::MemPoolLimits;
|
using kernel::MemPoolLimits;
|
||||||
using kernel::MemPoolOptions;
|
using kernel::MemPoolOptions;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
#ifndef BITCOIN_NODE_TRANSACTION_H
|
#ifndef BITCOIN_NODE_TRANSACTION_H
|
||||||
#define BITCOIN_NODE_TRANSACTION_H
|
#define BITCOIN_NODE_TRANSACTION_H
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <util/error.h>
|
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
|
|
29
src/node/types.h
Normal file
29
src/node/types.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (c) 2010-2021 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
//! @file node/types.h is a home for public enum and struct type definitions
|
||||||
|
//! that are used by internally by node code, but also used externally by wallet
|
||||||
|
//! or GUI code.
|
||||||
|
//!
|
||||||
|
//! This file is intended to define only simple types that do not have external
|
||||||
|
//! dependencies. More complicated types should be defined in dedicated header
|
||||||
|
//! files.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_NODE_TYPES_H
|
||||||
|
#define BITCOIN_NODE_TYPES_H
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
enum class TransactionError {
|
||||||
|
OK, //!< No error
|
||||||
|
MISSING_INPUTS,
|
||||||
|
ALREADY_IN_CHAIN,
|
||||||
|
MEMPOOL_REJECTED,
|
||||||
|
MEMPOOL_ERROR,
|
||||||
|
MAX_FEE_EXCEEDED,
|
||||||
|
MAX_BURN_EXCEEDED,
|
||||||
|
INVALID_PACKAGE,
|
||||||
|
};
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
|
#endif // BITCOIN_NODE_TYPES_H
|
|
@ -6,12 +6,12 @@
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
|
#include <crypto/hex_base.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/strencodings.h>
|
|
||||||
#include <util/transaction_identifier.h>
|
#include <util/transaction_identifier.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
#include <psbt.h>
|
#include <psbt.h>
|
||||||
|
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
|
|
||||||
PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx)
|
PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx)
|
||||||
{
|
{
|
||||||
inputs.resize(tx.vin.size());
|
inputs.resize(tx.vin.size());
|
||||||
|
@ -508,17 +508,17 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs)
|
bool CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs)
|
||||||
{
|
{
|
||||||
out = psbtxs[0]; // Copy the first one
|
out = psbtxs[0]; // Copy the first one
|
||||||
|
|
||||||
// Merge
|
// Merge
|
||||||
for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
|
for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
|
||||||
if (!out.Merge(*it)) {
|
if (!out.Merge(*it)) {
|
||||||
return TransactionError::PSBT_MISMATCH;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TransactionError::OK;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PSBTRoleName(PSBTRole role) {
|
std::string PSBTRoleName(PSBTRole role) {
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
enum class TransactionError;
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
// Magic bytes
|
// Magic bytes
|
||||||
static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};
|
static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};
|
||||||
|
|
||||||
|
@ -1263,9 +1267,9 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
|
||||||
*
|
*
|
||||||
* @param[out] out the combined PSBT, if successful
|
* @param[out] out the combined PSBT, if successful
|
||||||
* @param[in] psbtxs the PSBTs to combine
|
* @param[in] psbtxs the PSBTs to combine
|
||||||
* @return error (OK if we successfully combined the transactions, other error if they were not compatible)
|
* @return True if we successfully combined the transactions, false if they were not compatible
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
|
[[nodiscard]] bool CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
|
||||||
|
|
||||||
//! Decode a base64ed PSBT into a PartiallySignedTransaction
|
//! Decode a base64ed PSBT into a PartiallySignedTransaction
|
||||||
[[nodiscard]] bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
|
[[nodiscard]] bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
|
||||||
|
|
|
@ -85,6 +85,8 @@ Q_DECLARE_METATYPE(uint256)
|
||||||
Q_DECLARE_METATYPE(wallet::AddressPurpose)
|
Q_DECLARE_METATYPE(wallet::AddressPurpose)
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
|
|
||||||
|
using util::MakeUnorderedList;
|
||||||
|
|
||||||
static void RegisterMetaTypes()
|
static void RegisterMetaTypes()
|
||||||
{
|
{
|
||||||
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection
|
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
|
|
||||||
#include <qt/psbtoperationsdialog.h>
|
#include <qt/psbtoperationsdialog.h>
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <node/psbt.h>
|
#include <node/psbt.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <qt/bitcoinunits.h>
|
#include <qt/bitcoinunits.h>
|
||||||
#include <qt/forms/ui_psbtoperationsdialog.h>
|
#include <qt/forms/ui_psbtoperationsdialog.h>
|
||||||
|
@ -20,9 +22,11 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using common::TransactionErrorString;
|
||||||
using node::AnalyzePSBT;
|
using node::AnalyzePSBT;
|
||||||
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
|
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
|
||||||
using node::PSBTAnalysis;
|
using node::PSBTAnalysis;
|
||||||
|
using node::TransactionError;
|
||||||
|
|
||||||
PSBTOperationsDialog::PSBTOperationsDialog(
|
PSBTOperationsDialog::PSBTOperationsDialog(
|
||||||
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),
|
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),
|
||||||
|
@ -55,10 +59,10 @@ void PSBTOperationsDialog::openWithPSBT(PartiallySignedTransaction psbtx)
|
||||||
bool complete = FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
|
bool complete = FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
|
||||||
if (m_wallet_model) {
|
if (m_wallet_model) {
|
||||||
size_t n_could_sign;
|
size_t n_could_sign;
|
||||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, &n_could_sign, m_transaction_data, complete);
|
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, &n_could_sign, m_transaction_data, complete)};
|
||||||
if (err != TransactionError::OK) {
|
if (err) {
|
||||||
showStatus(tr("Failed to load transaction: %1")
|
showStatus(tr("Failed to load transaction: %1")
|
||||||
.arg(QString::fromStdString(TransactionErrorString(err).translated)),
|
.arg(QString::fromStdString(PSBTErrorString(*err).translated)),
|
||||||
StatusLevel::ERR);
|
StatusLevel::ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -79,11 +83,11 @@ void PSBTOperationsDialog::signTransaction()
|
||||||
|
|
||||||
WalletModel::UnlockContext ctx(m_wallet_model->requestUnlock());
|
WalletModel::UnlockContext ctx(m_wallet_model->requestUnlock());
|
||||||
|
|
||||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, &n_signed, m_transaction_data, complete);
|
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, &n_signed, m_transaction_data, complete)};
|
||||||
|
|
||||||
if (err != TransactionError::OK) {
|
if (err) {
|
||||||
showStatus(tr("Failed to sign transaction: %1")
|
showStatus(tr("Failed to sign transaction: %1")
|
||||||
.arg(QString::fromStdString(TransactionErrorString(err).translated)), StatusLevel::ERR);
|
.arg(QString::fromStdString(PSBTErrorString(*err).translated)), StatusLevel::ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,9 +251,9 @@ size_t PSBTOperationsDialog::couldSignInputs(const PartiallySignedTransaction &p
|
||||||
|
|
||||||
size_t n_signed;
|
size_t n_signed;
|
||||||
bool complete;
|
bool complete;
|
||||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/false, &n_signed, m_transaction_data, complete);
|
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/false, &n_signed, m_transaction_data, complete)};
|
||||||
|
|
||||||
if (err != TransactionError::OK) {
|
if (err) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return n_signed;
|
return n_signed;
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <QLatin1Char>
|
#include <QLatin1Char>
|
||||||
#include <QLatin1String>
|
#include <QLatin1String>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
||||||
QAbstractTableModel(parent), walletModel(parent)
|
QAbstractTableModel(parent), walletModel(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
|
||||||
const int CONSOLE_HISTORY = 50;
|
const int CONSOLE_HISTORY = 50;
|
||||||
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
|
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
|
||||||
const QSize FONT_RANGE(4, 40);
|
const QSize FONT_RANGE(4, 40);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
@ -37,6 +38,7 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
using common::PSBTError;
|
||||||
using wallet::CCoinControl;
|
using wallet::CCoinControl;
|
||||||
using wallet::DEFAULT_PAY_TX_FEE;
|
using wallet::DEFAULT_PAY_TX_FEE;
|
||||||
|
|
||||||
|
@ -442,26 +444,26 @@ void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx, CMutableTransaction& mtx, bool& complete) {
|
bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx, CMutableTransaction& mtx, bool& complete) {
|
||||||
TransactionError err;
|
std::optional<PSBTError> err;
|
||||||
try {
|
try {
|
||||||
err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
QMessageBox::critical(nullptr, tr("Sign failed"), e.what());
|
QMessageBox::critical(nullptr, tr("Sign failed"), e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (err == TransactionError::EXTERNAL_SIGNER_NOT_FOUND) {
|
if (err == PSBTError::EXTERNAL_SIGNER_NOT_FOUND) {
|
||||||
//: "External signer" means using devices such as hardware wallets.
|
//: "External signer" means using devices such as hardware wallets.
|
||||||
const QString msg = tr("External signer not found");
|
const QString msg = tr("External signer not found");
|
||||||
QMessageBox::critical(nullptr, msg, msg);
|
QMessageBox::critical(nullptr, msg, msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (err == TransactionError::EXTERNAL_SIGNER_FAILED) {
|
if (err == PSBTError::EXTERNAL_SIGNER_FAILED) {
|
||||||
//: "External signer" means using devices such as hardware wallets.
|
//: "External signer" means using devices such as hardware wallets.
|
||||||
const QString msg = tr("External signer failure");
|
const QString msg = tr("External signer failure");
|
||||||
QMessageBox::critical(nullptr, msg, msg);
|
QMessageBox::critical(nullptr, msg, msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (err != TransactionError::OK) {
|
if (err) {
|
||||||
tfm::format(std::cerr, "Failed to sign PSBT");
|
tfm::format(std::cerr, "Failed to sign PSBT");
|
||||||
processSendCoinsReturn(WalletModel::TransactionCreationFailed);
|
processSendCoinsReturn(WalletModel::TransactionCreationFailed);
|
||||||
return false;
|
return false;
|
||||||
|
@ -501,9 +503,9 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||||
PartiallySignedTransaction psbtx(mtx);
|
PartiallySignedTransaction psbtx(mtx);
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
// Fill without signing
|
// Fill without signing
|
||||||
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
const auto err{model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
|
||||||
assert(!complete);
|
assert(!complete);
|
||||||
assert(err == TransactionError::OK);
|
assert(!err);
|
||||||
|
|
||||||
// Copy PSBT to clipboard and offer to save
|
// Copy PSBT to clipboard and offer to save
|
||||||
presentPSBT(psbtx);
|
presentPSBT(psbtx);
|
||||||
|
@ -517,9 +519,9 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
// Always fill without signing first. This prevents an external signer
|
// Always fill without signing first. This prevents an external signer
|
||||||
// from being called prematurely and is not expensive.
|
// from being called prematurely and is not expensive.
|
||||||
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
const auto err{model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
|
||||||
assert(!complete);
|
assert(!complete);
|
||||||
assert(err == TransactionError::OK);
|
assert(!err);
|
||||||
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
|
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
|
||||||
// Don't broadcast when user rejects it on the device or there's a failure:
|
// Don't broadcast when user rejects it on the device or there's a failure:
|
||||||
broadcast = complete && !send_failure;
|
broadcast = complete && !send_failure;
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
#include <qt/platformstyle.h>
|
#include <qt/platformstyle.h>
|
||||||
#include <qt/walletmodel.h>
|
#include <qt/walletmodel.h>
|
||||||
|
|
||||||
|
#include <common/signmessage.h> // For MessageSign(), MessageVerify()
|
||||||
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <util/message.h> // For MessageSign(), MessageVerify()
|
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
using wallet::WALLET_FLAG_BLANK_WALLET;
|
using wallet::WALLET_FLAG_BLANK_WALLET;
|
||||||
using wallet::WALLET_FLAG_DESCRIPTORS;
|
using wallet::WALLET_FLAG_DESCRIPTORS;
|
||||||
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <psbt.h>
|
#include <psbt.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/coincontrol.h>
|
#include <wallet/coincontrol.h>
|
||||||
|
@ -534,8 +535,8 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
|
||||||
// "Create Unsigned" clicked
|
// "Create Unsigned" clicked
|
||||||
PartiallySignedTransaction psbtx(mtx);
|
PartiallySignedTransaction psbtx(mtx);
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
const TransactionError err = wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete);
|
const auto err{wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete)};
|
||||||
if (err != TransactionError::OK || complete) {
|
if (err || complete) {
|
||||||
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction."));
|
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
using node::GetTransaction;
|
using node::GetTransaction;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
|
static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
|
||||||
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;
|
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;
|
||||||
|
|
|
@ -61,6 +61,9 @@ using kernel::CoinStatsHashType;
|
||||||
using node::BlockManager;
|
using node::BlockManager;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
using node::SnapshotMetadata;
|
using node::SnapshotMetadata;
|
||||||
|
using util::Join;
|
||||||
|
using util::MakeUnorderedList;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
struct CUpdatedBlock
|
struct CUpdatedBlock
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
|
@ -14,7 +15,6 @@
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
#include <util/fees.h>
|
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -22,6 +22,9 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using common::FeeModeFromString;
|
||||||
|
using common::FeeModes;
|
||||||
|
using common::InvalidEstimateModeErrorMessage;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
|
||||||
static RPCHelpMan estimatesmartfee()
|
static RPCHelpMan estimatesmartfee()
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <kernel/mempool_entry.h>
|
#include <kernel/mempool_entry.h>
|
||||||
#include <node/mempool_persist_args.h>
|
#include <node/mempool_persist_args.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
@ -32,6 +33,8 @@ using node::DEFAULT_MAX_BURN_AMOUNT;
|
||||||
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
|
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
|
||||||
using node::MempoolPath;
|
using node::MempoolPath;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
using node::TransactionError;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
static RPCHelpMan sendrawtransaction()
|
static RPCHelpMan sendrawtransaction()
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ using node::CBlockTemplate;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
using node::RegenerateCommitments;
|
using node::RegenerateCommitments;
|
||||||
using node::UpdateTime;
|
using node::UpdateTime;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return average network hashes per second based on the last 'lookup' blocks,
|
* Return average network hashes per second based on the last 'lookup' blocks,
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
using util::Join;
|
||||||
|
using util::TrimString;
|
||||||
|
|
||||||
const std::vector<std::string> CONNECTION_TYPE_DOC{
|
const std::vector<std::string> CONNECTION_TYPE_DOC{
|
||||||
"outbound-full-relay (default automatic connections)",
|
"outbound-full-relay (default automatic connections)",
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/psbt.h>
|
#include <node/psbt.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/packages.h>
|
#include <policy/packages.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
|
@ -1489,9 +1490,8 @@ static RPCHelpMan combinepsbt()
|
||||||
}
|
}
|
||||||
|
|
||||||
PartiallySignedTransaction merged_psbt;
|
PartiallySignedTransaction merged_psbt;
|
||||||
const TransactionError error = CombinePSBTs(merged_psbt, psbtxs);
|
if (!CombinePSBTs(merged_psbt, psbtxs)) {
|
||||||
if (error != TransactionError::OK) {
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "PSBTs not compatible (different transactions)");
|
||||||
throw JSONRPCTransactionError(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataStream ssTx{};
|
DataStream ssTx{};
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
static GlobalMutex g_rpc_warmup_mutex;
|
static GlobalMutex g_rpc_warmup_mutex;
|
||||||
static std::atomic<bool> g_rpc_running{false};
|
static std::atomic<bool> g_rpc_running{false};
|
||||||
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
|
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/signmessage.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <rpc/protocol.h>
|
#include <rpc/protocol.h>
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
#include <util/message.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,12 @@
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
|
#include <common/messages.h>
|
||||||
|
#include <common/types.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <script/interpreter.h>
|
#include <script/interpreter.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <outputtype.h>
|
#include <outputtype.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <script/descriptor.h>
|
#include <script/descriptor.h>
|
||||||
|
@ -30,6 +33,14 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
using common::PSBTError;
|
||||||
|
using common::PSBTErrorString;
|
||||||
|
using common::TransactionErrorString;
|
||||||
|
using node::TransactionError;
|
||||||
|
using util::Join;
|
||||||
|
using util::SplitString;
|
||||||
|
using util::TrimString;
|
||||||
|
|
||||||
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
|
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
|
||||||
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
|
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
|
||||||
|
|
||||||
|
@ -364,6 +375,18 @@ unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target)
|
||||||
return unsigned_target;
|
return unsigned_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RPCErrorCode RPCErrorFromPSBTError(PSBTError err)
|
||||||
|
{
|
||||||
|
switch (err) {
|
||||||
|
case PSBTError::UNSUPPORTED:
|
||||||
|
return RPC_INVALID_PARAMETER;
|
||||||
|
case PSBTError::SIGHASH_MISMATCH:
|
||||||
|
return RPC_DESERIALIZATION_ERROR;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return RPC_TRANSACTION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
|
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
|
||||||
{
|
{
|
||||||
switch (terr) {
|
switch (terr) {
|
||||||
|
@ -371,18 +394,16 @@ RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
|
||||||
return RPC_TRANSACTION_REJECTED;
|
return RPC_TRANSACTION_REJECTED;
|
||||||
case TransactionError::ALREADY_IN_CHAIN:
|
case TransactionError::ALREADY_IN_CHAIN:
|
||||||
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
|
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
|
||||||
case TransactionError::P2P_DISABLED:
|
|
||||||
return RPC_CLIENT_P2P_DISABLED;
|
|
||||||
case TransactionError::INVALID_PSBT:
|
|
||||||
case TransactionError::PSBT_MISMATCH:
|
|
||||||
return RPC_INVALID_PARAMETER;
|
|
||||||
case TransactionError::SIGHASH_MISMATCH:
|
|
||||||
return RPC_DESERIALIZATION_ERROR;
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return RPC_TRANSACTION_ERROR;
|
return RPC_TRANSACTION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue JSONRPCPSBTError(PSBTError err)
|
||||||
|
{
|
||||||
|
return JSONRPCError(RPCErrorFromPSBTError(err), PSBTErrorString(err).original);
|
||||||
|
}
|
||||||
|
|
||||||
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string)
|
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string)
|
||||||
{
|
{
|
||||||
if (err_string.length() > 0) {
|
if (err_string.length() > 0) {
|
||||||
|
@ -778,7 +799,7 @@ std::string RPCHelpMan::ToString() const
|
||||||
if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
|
if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
|
||||||
|
|
||||||
// Push named argument name and description
|
// Push named argument name and description
|
||||||
sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
|
sections.m_sections.emplace_back(util::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
|
||||||
sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
|
sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
|
||||||
|
|
||||||
// Recursively push nested args
|
// Recursively push nested args
|
||||||
|
|
|
@ -34,9 +34,14 @@
|
||||||
class JSONRPCRequest;
|
class JSONRPCRequest;
|
||||||
enum ServiceFlags : uint64_t;
|
enum ServiceFlags : uint64_t;
|
||||||
enum class OutputType;
|
enum class OutputType;
|
||||||
enum class TransactionError;
|
|
||||||
struct FlatSigningProvider;
|
struct FlatSigningProvider;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
namespace common {
|
||||||
|
enum class PSBTError;
|
||||||
|
} // namespace common
|
||||||
|
namespace node {
|
||||||
|
enum class TransactionError;
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
static constexpr bool DEFAULT_RPC_DOC_CHECK{
|
static constexpr bool DEFAULT_RPC_DOC_CHECK{
|
||||||
#ifdef RPC_DOC_CHECK
|
#ifdef RPC_DOC_CHECK
|
||||||
|
@ -127,8 +132,9 @@ int ParseSighashString(const UniValue& sighash);
|
||||||
//! Parse a confirm target option and raise an RPC error if it is invalid.
|
//! Parse a confirm target option and raise an RPC error if it is invalid.
|
||||||
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);
|
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);
|
||||||
|
|
||||||
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr);
|
RPCErrorCode RPCErrorFromTransactionError(node::TransactionError terr);
|
||||||
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string = "");
|
UniValue JSONRPCPSBTError(common::PSBTError err);
|
||||||
|
UniValue JSONRPCTransactionError(node::TransactionError terr, const std::string& err_string = "");
|
||||||
|
|
||||||
//! Parse a JSON range specified as int64, or [int64, int64]
|
//! Parse a JSON range specified as int64, or [int64, int64]
|
||||||
std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value);
|
std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
#include <script/miniscript.h>
|
#include <script/miniscript.h>
|
||||||
|
#include <script/parsing.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <script/solver.h>
|
#include <script/solver.h>
|
||||||
|
@ -17,7 +18,6 @@
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/spanparsing.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::Split;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1350,8 +1352,6 @@ enum class ParseScriptContext {
|
||||||
/** Parse a public key that excludes origin information. */
|
/** Parse a public key that excludes origin information. */
|
||||||
std::unique_ptr<PubkeyProvider> ParsePubkeyInner(uint32_t key_exp_index, const Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, bool& apostrophe, std::string& error)
|
std::unique_ptr<PubkeyProvider> ParsePubkeyInner(uint32_t key_exp_index, const Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, bool& apostrophe, std::string& error)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
|
||||||
|
|
||||||
bool permit_uncompressed = ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH;
|
bool permit_uncompressed = ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH;
|
||||||
auto split = Split(sp, '/');
|
auto split = Split(sp, '/');
|
||||||
std::string str(split[0].begin(), split[0].end());
|
std::string str(split[0].begin(), split[0].end());
|
||||||
|
@ -1424,8 +1424,6 @@ std::unique_ptr<PubkeyProvider> ParsePubkeyInner(uint32_t key_exp_index, const S
|
||||||
/** Parse a public key including origin information (if enabled). */
|
/** Parse a public key including origin information (if enabled). */
|
||||||
std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
|
||||||
|
|
||||||
auto origin_split = Split(sp, ']');
|
auto origin_split = Split(sp, ']');
|
||||||
if (origin_split.size() > 2) {
|
if (origin_split.size() > 2) {
|
||||||
error = "Multiple ']' characters found for a single pubkey";
|
error = "Multiple ']' characters found for a single pubkey";
|
||||||
|
@ -1589,7 +1587,7 @@ struct KeyParser {
|
||||||
// NOLINTNEXTLINE(misc-no-recursion)
|
// NOLINTNEXTLINE(misc-no-recursion)
|
||||||
std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
using namespace script;
|
||||||
|
|
||||||
auto expr = Expr(sp);
|
auto expr = Expr(sp);
|
||||||
if (Func("pk", expr)) {
|
if (Func("pk", expr)) {
|
||||||
|
@ -2038,8 +2036,6 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
|
||||||
/** Check a descriptor checksum, and update desc to be the checksum-less part. */
|
/** Check a descriptor checksum, and update desc to be the checksum-less part. */
|
||||||
bool CheckChecksum(Span<const char>& sp, bool require_checksum, std::string& error, std::string* out_checksum = nullptr)
|
bool CheckChecksum(Span<const char>& sp, bool require_checksum, std::string& error, std::string* out_checksum = nullptr)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
|
||||||
|
|
||||||
auto check_split = Split(sp, '#');
|
auto check_split = Split(sp, '#');
|
||||||
if (check_split.size() > 2) {
|
if (check_split.size() > 2) {
|
||||||
error = "Multiple '#' symbols";
|
error = "Multiple '#' symbols";
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
|
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
#include <script/parsing.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/spanparsing.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
@ -863,8 +863,8 @@ public:
|
||||||
if (!key_str) return {};
|
if (!key_str) return {};
|
||||||
return std::move(ret) + "pk_h(" + std::move(*key_str) + ")";
|
return std::move(ret) + "pk_h(" + std::move(*key_str) + ")";
|
||||||
}
|
}
|
||||||
case Fragment::AFTER: return std::move(ret) + "after(" + ::ToString(node.k) + ")";
|
case Fragment::AFTER: return std::move(ret) + "after(" + util::ToString(node.k) + ")";
|
||||||
case Fragment::OLDER: return std::move(ret) + "older(" + ::ToString(node.k) + ")";
|
case Fragment::OLDER: return std::move(ret) + "older(" + util::ToString(node.k) + ")";
|
||||||
case Fragment::HASH256: return std::move(ret) + "hash256(" + HexStr(node.data) + ")";
|
case Fragment::HASH256: return std::move(ret) + "hash256(" + HexStr(node.data) + ")";
|
||||||
case Fragment::HASH160: return std::move(ret) + "hash160(" + HexStr(node.data) + ")";
|
case Fragment::HASH160: return std::move(ret) + "hash160(" + HexStr(node.data) + ")";
|
||||||
case Fragment::SHA256: return std::move(ret) + "sha256(" + HexStr(node.data) + ")";
|
case Fragment::SHA256: return std::move(ret) + "sha256(" + HexStr(node.data) + ")";
|
||||||
|
@ -883,7 +883,7 @@ public:
|
||||||
return std::move(ret) + "andor(" + std::move(subs[0]) + "," + std::move(subs[1]) + "," + std::move(subs[2]) + ")";
|
return std::move(ret) + "andor(" + std::move(subs[0]) + "," + std::move(subs[1]) + "," + std::move(subs[2]) + ")";
|
||||||
case Fragment::MULTI: {
|
case Fragment::MULTI: {
|
||||||
CHECK_NONFATAL(!is_tapscript);
|
CHECK_NONFATAL(!is_tapscript);
|
||||||
auto str = std::move(ret) + "multi(" + ::ToString(node.k);
|
auto str = std::move(ret) + "multi(" + util::ToString(node.k);
|
||||||
for (const auto& key : node.keys) {
|
for (const auto& key : node.keys) {
|
||||||
auto key_str = ctx.ToString(key);
|
auto key_str = ctx.ToString(key);
|
||||||
if (!key_str) return {};
|
if (!key_str) return {};
|
||||||
|
@ -893,7 +893,7 @@ public:
|
||||||
}
|
}
|
||||||
case Fragment::MULTI_A: {
|
case Fragment::MULTI_A: {
|
||||||
CHECK_NONFATAL(is_tapscript);
|
CHECK_NONFATAL(is_tapscript);
|
||||||
auto str = std::move(ret) + "multi_a(" + ::ToString(node.k);
|
auto str = std::move(ret) + "multi_a(" + util::ToString(node.k);
|
||||||
for (const auto& key : node.keys) {
|
for (const auto& key : node.keys) {
|
||||||
auto key_str = ctx.ToString(key);
|
auto key_str = ctx.ToString(key);
|
||||||
if (!key_str) return {};
|
if (!key_str) return {};
|
||||||
|
@ -902,7 +902,7 @@ public:
|
||||||
return std::move(str) + ")";
|
return std::move(str) + ")";
|
||||||
}
|
}
|
||||||
case Fragment::THRESH: {
|
case Fragment::THRESH: {
|
||||||
auto str = std::move(ret) + "thresh(" + ::ToString(node.k);
|
auto str = std::move(ret) + "thresh(" + util::ToString(node.k);
|
||||||
for (auto& sub : subs) {
|
for (auto& sub : subs) {
|
||||||
str += "," + std::move(sub);
|
str += "," + std::move(sub);
|
||||||
}
|
}
|
||||||
|
@ -1764,7 +1764,7 @@ void BuildBack(const MiniscriptContext script_ctx, Fragment nt, std::vector<Node
|
||||||
template<typename Key, typename Ctx>
|
template<typename Key, typename Ctx>
|
||||||
inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
|
inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
using namespace script;
|
||||||
|
|
||||||
// Account for the minimum script size for all parsed fragments so far. It "borrows" 1
|
// Account for the minimum script size for all parsed fragments so far. It "borrows" 1
|
||||||
// script byte from all leaf nodes, counting it instead whenever a space for a recursive
|
// script byte from all leaf nodes, counting it instead whenever a space for a recursive
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <util/spanparsing.h>
|
#include <script/parsing.h>
|
||||||
|
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace spanparsing {
|
namespace script {
|
||||||
|
|
||||||
bool Const(const std::string& str, Span<const char>& sp)
|
bool Const(const std::string& str, Span<const char>& sp)
|
||||||
{
|
{
|
||||||
|
@ -49,4 +49,4 @@ Span<const char> Expr(Span<const char>& sp)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spanparsing
|
} // namespace script
|
40
src/script/parsing.h
Normal file
40
src/script/parsing.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright (c) 2018-2022 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_SCRIPT_PARSING_H
|
||||||
|
#define BITCOIN_SCRIPT_PARSING_H
|
||||||
|
|
||||||
|
#include <span.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
/** Parse a constant.
|
||||||
|
*
|
||||||
|
* If sp's initial part matches str, sp is updated to skip that part, and true is returned.
|
||||||
|
* Otherwise sp is unmodified and false is returned.
|
||||||
|
*/
|
||||||
|
bool Const(const std::string& str, Span<const char>& sp);
|
||||||
|
|
||||||
|
/** Parse a function call.
|
||||||
|
*
|
||||||
|
* If sp's initial part matches str + "(", and sp ends with ")", sp is updated to be the
|
||||||
|
* section between the braces, and true is returned. Otherwise sp is unmodified and false
|
||||||
|
* is returned.
|
||||||
|
*/
|
||||||
|
bool Func(const std::string& str, Span<const char>& sp);
|
||||||
|
|
||||||
|
/** Extract the expression that sp begins with.
|
||||||
|
*
|
||||||
|
* This function will return the initial part of sp, up to (but not including) the first
|
||||||
|
* comma or closing brace, skipping ones that are surrounded by braces. So for example,
|
||||||
|
* for "foo(bar(1),2),3" the initial part "foo(bar(1),2)" will be returned. sp will be
|
||||||
|
* updated to skip the initial part that is returned.
|
||||||
|
*/
|
||||||
|
Span<const char> Expr(Span<const char>& sp);
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
|
||||||
|
#endif // BITCOIN_SCRIPT_PARSING_H
|
|
@ -6,10 +6,10 @@
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
|
|
||||||
#include <crypto/common.h>
|
#include <crypto/common.h>
|
||||||
|
#include <crypto/hex_base.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/hash_type.h>
|
#include <util/hash_type.h>
|
||||||
#include <util/strencodings.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
static NetGroupManager EMPTY_NETGROUPMAN{std::vector<bool>()};
|
static NetGroupManager EMPTY_NETGROUPMAN{std::vector<bool>()};
|
||||||
static const bool DETERMINISTIC{true};
|
static const bool DETERMINISTIC{true};
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_datadir)
|
BOOST_AUTO_TEST_CASE(util_datadir)
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
/* Equality between doubles is imprecise. Comparison should be done
|
/* Equality between doubles is imprecise. Comparison should be done
|
||||||
* with a small threshold of tolerance, rather than exact equality.
|
* with a small threshold of tolerance, rather than exact equality.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
// Test if a string consists entirely of null characters
|
// Test if a string consists entirely of null characters
|
||||||
static bool is_null_key(const std::vector<unsigned char>& key) {
|
static bool is_null_key(const std::vector<unsigned char>& key) {
|
||||||
bool isnull = true;
|
bool isnull = true;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::Split;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void CheckUnparsable(const std::string& prv, const std::string& pub, const std::string& expected_error)
|
void CheckUnparsable(const std::string& prv, const std::string& pub, const std::string& expected_error)
|
||||||
|
@ -400,7 +403,6 @@ void CheckInferDescriptor(const std::string& script_hex, const std::string& expe
|
||||||
provider.pubkeys.emplace(origin_pubkey.GetID(), origin_pubkey);
|
provider.pubkeys.emplace(origin_pubkey.GetID(), origin_pubkey);
|
||||||
|
|
||||||
if (!origin_str.empty()) {
|
if (!origin_str.empty()) {
|
||||||
using namespace spanparsing;
|
|
||||||
KeyOriginInfo info;
|
KeyOriginInfo info;
|
||||||
Span<const char> origin_sp{origin_str};
|
Span<const char> origin_sp{origin_str};
|
||||||
std::vector<Span<const char>> origin_split = Split(origin_sp, "/");
|
std::vector<Span<const char>> origin_split = Split(origin_sp, "/");
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::TrimString;
|
||||||
|
using util::TrimStringView;
|
||||||
|
|
||||||
FUZZ_TARGET(base_encode_decode)
|
FUZZ_TARGET(base_encode_decode)
|
||||||
{
|
{
|
||||||
const std::string random_encoded_string(buffer.begin(), buffer.end());
|
const std::string random_encoded_string(buffer.begin(), buffer.end());
|
||||||
|
|
|
@ -2,17 +2,19 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <util/fees.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using common::StringForFeeReason;
|
||||||
|
|
||||||
FUZZ_TARGET(fees)
|
FUZZ_TARGET(fees)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
void initialize_integer()
|
void initialize_integer()
|
||||||
{
|
{
|
||||||
SelectParams(ChainType::REGTEST);
|
SelectParams(ChainType::REGTEST);
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <common/messages.h>
|
||||||
#include <merkleblock.h>
|
#include <merkleblock.h>
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <util/error.h>
|
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
@ -16,17 +17,15 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using common::TransactionErrorString;
|
||||||
|
using node::TransactionError;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
|
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
|
||||||
TransactionError::OK,
|
|
||||||
TransactionError::MISSING_INPUTS,
|
TransactionError::MISSING_INPUTS,
|
||||||
TransactionError::ALREADY_IN_CHAIN,
|
TransactionError::ALREADY_IN_CHAIN,
|
||||||
TransactionError::P2P_DISABLED,
|
|
||||||
TransactionError::MEMPOOL_REJECTED,
|
TransactionError::MEMPOOL_REJECTED,
|
||||||
TransactionError::MEMPOOL_ERROR,
|
TransactionError::MEMPOOL_ERROR,
|
||||||
TransactionError::INVALID_PSBT,
|
|
||||||
TransactionError::PSBT_MISMATCH,
|
|
||||||
TransactionError::SIGHASH_MISMATCH,
|
|
||||||
TransactionError::MAX_FEE_EXCEEDED,
|
TransactionError::MAX_FEE_EXCEEDED,
|
||||||
};
|
};
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
|
|
@ -51,7 +51,7 @@ FUZZ_TARGET(locale)
|
||||||
int64_t parseint64_out_without_locale;
|
int64_t parseint64_out_without_locale;
|
||||||
const bool parseint64_without_locale = ParseInt64(random_string, &parseint64_out_without_locale);
|
const bool parseint64_without_locale = ParseInt64(random_string, &parseint64_out_without_locale);
|
||||||
const int64_t random_int64 = fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
const int64_t random_int64 = fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
||||||
const std::string tostring_without_locale = ToString(random_int64);
|
const std::string tostring_without_locale = util::ToString(random_int64);
|
||||||
// The variable `random_int32` is no longer used, but the harness still needs to
|
// The variable `random_int32` is no longer used, but the harness still needs to
|
||||||
// consume the same data that it did previously to not invalidate existing seeds.
|
// consume the same data that it did previously to not invalidate existing seeds.
|
||||||
const int32_t random_int32 = fuzzed_data_provider.ConsumeIntegral<int32_t>();
|
const int32_t random_int32 = fuzzed_data_provider.ConsumeIntegral<int32_t>();
|
||||||
|
@ -75,7 +75,7 @@ FUZZ_TARGET(locale)
|
||||||
if (parseint64_without_locale) {
|
if (parseint64_without_locale) {
|
||||||
assert(parseint64_out_without_locale == parseint64_out_with_locale);
|
assert(parseint64_out_without_locale == parseint64_out_with_locale);
|
||||||
}
|
}
|
||||||
const std::string tostring_with_locale = ToString(random_int64);
|
const std::string tostring_with_locale = util::ToString(random_int64);
|
||||||
assert(tostring_without_locale == tostring_with_locale);
|
assert(tostring_without_locale == tostring_with_locale);
|
||||||
const std::string strprintf_int_with_locale = strprintf("%d", random_int64);
|
const std::string strprintf_int_with_locale = strprintf("%d", random_int64);
|
||||||
assert(strprintf_int_without_locale == strprintf_int_with_locale);
|
assert(strprintf_int_without_locale == strprintf_int_with_locale);
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
|
#include <common/signmessage.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
#include <util/message.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
enum class ChainType;
|
enum class ChainType;
|
||||||
|
|
||||||
|
using util::Join;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct RPCFuzzTestingSetup : public TestingSetup {
|
struct RPCFuzzTestingSetup : public TestingSetup {
|
||||||
RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args}
|
RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
// This fuzz "test" can be used to minimize test cases for script_assets_test in
|
// This fuzz "test" can be used to minimize test cases for script_assets_test in
|
||||||
// src/test/script_tests.cpp. While it written as a fuzz test, and can be used as such,
|
// src/test/script_tests.cpp. While it written as a fuzz test, and can be used as such,
|
||||||
// fuzzing the inputs is unlikely to construct useful test cases.
|
// fuzzing the inputs is unlikely to construct useful test cases.
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <script/parsing.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <util/spanparsing.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
FUZZ_TARGET(spanparsing)
|
using util::Split;
|
||||||
|
|
||||||
|
FUZZ_TARGET(script_parsing)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||||
|
@ -15,16 +18,16 @@ FUZZ_TARGET(spanparsing)
|
||||||
const Span<const char> const_span{span_str};
|
const Span<const char> const_span{span_str};
|
||||||
|
|
||||||
Span<const char> mut_span = const_span;
|
Span<const char> mut_span = const_span;
|
||||||
(void)spanparsing::Const(query, mut_span);
|
(void)script::Const(query, mut_span);
|
||||||
|
|
||||||
mut_span = const_span;
|
mut_span = const_span;
|
||||||
(void)spanparsing::Func(query, mut_span);
|
(void)script::Func(query, mut_span);
|
||||||
|
|
||||||
mut_span = const_span;
|
mut_span = const_span;
|
||||||
(void)spanparsing::Expr(mut_span);
|
(void)script::Expr(mut_span);
|
||||||
|
|
||||||
if (!query.empty()) {
|
if (!query.empty()) {
|
||||||
mut_span = const_span;
|
mut_span = const_span;
|
||||||
(void)spanparsing::Split(mut_span, query.front());
|
(void)Split(mut_span, query.front());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
#include <blockfilter.h>
|
#include <blockfilter.h>
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
|
#include <common/messages.h>
|
||||||
#include <common/settings.h>
|
#include <common/settings.h>
|
||||||
#include <common/system.h>
|
#include <common/system.h>
|
||||||
#include <common/url.h>
|
#include <common/url.h>
|
||||||
|
@ -21,8 +22,6 @@
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <util/error.h>
|
|
||||||
#include <util/fees.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
@ -37,6 +36,16 @@
|
||||||
|
|
||||||
enum class FeeEstimateMode;
|
enum class FeeEstimateMode;
|
||||||
|
|
||||||
|
using common::AmountErrMsg;
|
||||||
|
using common::AmountHighWarn;
|
||||||
|
using common::FeeModeFromString;
|
||||||
|
using common::ResolveErrMsg;
|
||||||
|
using util::ContainsNoNUL;
|
||||||
|
using util::Join;
|
||||||
|
using util::RemovePrefix;
|
||||||
|
using util::SplitString;
|
||||||
|
using util::TrimString;
|
||||||
|
|
||||||
FUZZ_TARGET(string)
|
FUZZ_TARGET(string)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
using node::BlockAssembler;
|
using node::BlockAssembler;
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
|
||||||
|
|
||||||
void ResetArgs(ArgsManager& local_args, const std::string& strArg)
|
void ResetArgs(ArgsManager& local_args, const std::string& strArg)
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
static const std::string strSecret1 = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj";
|
static const std::string strSecret1 = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj";
|
||||||
static const std::string strSecret2 = "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3";
|
static const std::string strSecret2 = "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3";
|
||||||
static const std::string strSecret1C = "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw";
|
static const std::string strSecret1C = "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw";
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
using util::TrimString;
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
|
||||||
|
|
||||||
static void ResetLogger()
|
static void ResetLogger()
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
|
||||||
static UniValue JSON(std::string_view json)
|
static UniValue JSON(std::string_view json)
|
||||||
{
|
{
|
||||||
UniValue value;
|
UniValue value;
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b)
|
inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b)
|
||||||
{
|
{
|
||||||
return a.write() == b.write();
|
return a.write() == b.write();
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
|
using util::SplitString;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
typedef std::vector<unsigned char> valtype;
|
typedef std::vector<unsigned char> valtype;
|
||||||
|
|
||||||
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
|
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <common/signmessage.h> // For MessageSign(), MessageVerify(), MESSAGE_MAGIC
|
||||||
#include <hash.h> // For Hash()
|
#include <hash.h> // For Hash()
|
||||||
#include <key.h> // For CKey
|
#include <key.h> // For CKey
|
||||||
|
#include <script/parsing.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <test/util/random.h>
|
#include <test/util/random.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
@ -12,11 +14,9 @@
|
||||||
#include <util/bitdeque.h>
|
#include <util/bitdeque.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/fs_helpers.h>
|
#include <util/fs_helpers.h>
|
||||||
#include <util/message.h> // For MessageSign(), MessageVerify(), MESSAGE_MAGIC
|
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/overflow.h>
|
#include <util/overflow.h>
|
||||||
#include <util/readwritefile.h>
|
#include <util/readwritefile.h>
|
||||||
#include <util/spanparsing.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
|
@ -45,6 +45,15 @@
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
using util::Join;
|
||||||
|
using util::RemovePrefix;
|
||||||
|
using util::RemovePrefixView;
|
||||||
|
using util::ReplaceAll;
|
||||||
|
using util::Split;
|
||||||
|
using util::SplitString;
|
||||||
|
using util::TrimString;
|
||||||
|
using util::TrimStringView;
|
||||||
|
|
||||||
static const std::string STRING_WITH_EMBEDDED_NULL_CHAR{"1"s "\0" "1"s};
|
static const std::string STRING_WITH_EMBEDDED_NULL_CHAR{"1"s "\0" "1"s};
|
||||||
|
|
||||||
/* defined in logging.cpp */
|
/* defined in logging.cpp */
|
||||||
|
@ -1292,9 +1301,9 @@ static std::string SpanToStr(const Span<const char>& span)
|
||||||
return std::string(span.begin(), span.end());
|
return std::string(span.begin(), span.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_spanparsing)
|
BOOST_AUTO_TEST_CASE(test_script_parsing)
|
||||||
{
|
{
|
||||||
using namespace spanparsing;
|
using namespace script;
|
||||||
std::string input;
|
std::string input;
|
||||||
Span<const char> sp;
|
Span<const char> sp;
|
||||||
bool success;
|
bool success;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(util_threadnames_tests)
|
BOOST_AUTO_TEST_SUITE(util_threadnames_tests)
|
||||||
|
|
||||||
const std::string TEST_THREAD_NAME_BASE = "test_thread.";
|
const std::string TEST_THREAD_NAME_BASE = "test_thread.";
|
||||||
|
|
|
@ -42,6 +42,10 @@
|
||||||
#include <event2/thread.h>
|
#include <event2/thread.h>
|
||||||
#include <event2/util.h>
|
#include <event2/util.h>
|
||||||
|
|
||||||
|
using util::ReplaceAll;
|
||||||
|
using util::SplitString;
|
||||||
|
using util::ToString;
|
||||||
|
|
||||||
/** Default control ip and port */
|
/** Default control ip and port */
|
||||||
const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT);
|
const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT);
|
||||||
/** Tor cookie size (from control-spec.txt) */
|
/** Tor cookie size (from control-spec.txt) */
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
// Copyright (c) 2010-2022 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 <util/error.h>
|
|
||||||
|
|
||||||
#include <tinyformat.h>
|
|
||||||
#include <util/translation.h>
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
bilingual_str TransactionErrorString(const TransactionError err)
|
|
||||||
{
|
|
||||||
switch (err) {
|
|
||||||
case TransactionError::OK:
|
|
||||||
return Untranslated("No error");
|
|
||||||
case TransactionError::MISSING_INPUTS:
|
|
||||||
return Untranslated("Inputs missing or spent");
|
|
||||||
case TransactionError::ALREADY_IN_CHAIN:
|
|
||||||
return Untranslated("Transaction already in block chain");
|
|
||||||
case TransactionError::P2P_DISABLED:
|
|
||||||
return Untranslated("Peer-to-peer functionality missing or disabled");
|
|
||||||
case TransactionError::MEMPOOL_REJECTED:
|
|
||||||
return Untranslated("Transaction rejected by mempool");
|
|
||||||
case TransactionError::MEMPOOL_ERROR:
|
|
||||||
return Untranslated("Mempool internal error");
|
|
||||||
case TransactionError::INVALID_PSBT:
|
|
||||||
return Untranslated("PSBT is not well-formed");
|
|
||||||
case TransactionError::PSBT_MISMATCH:
|
|
||||||
return Untranslated("PSBTs not compatible (different transactions)");
|
|
||||||
case TransactionError::SIGHASH_MISMATCH:
|
|
||||||
return Untranslated("Specified sighash value does not match value stored in PSBT");
|
|
||||||
case TransactionError::MAX_FEE_EXCEEDED:
|
|
||||||
return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
|
|
||||||
case TransactionError::MAX_BURN_EXCEEDED:
|
|
||||||
return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
|
|
||||||
case TransactionError::EXTERNAL_SIGNER_NOT_FOUND:
|
|
||||||
return Untranslated("External signer not found");
|
|
||||||
case TransactionError::EXTERNAL_SIGNER_FAILED:
|
|
||||||
return Untranslated("External signer failed to sign");
|
|
||||||
case TransactionError::INVALID_PACKAGE:
|
|
||||||
return Untranslated("Transaction rejected due to invalid package");
|
|
||||||
// no default case, so the compiler can warn about missing cases
|
|
||||||
}
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
|
|
||||||
{
|
|
||||||
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
|
|
||||||
}
|
|
||||||
|
|
||||||
bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)
|
|
||||||
{
|
|
||||||
return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bilingual_str AmountHighWarn(const std::string& optname)
|
|
||||||
{
|
|
||||||
return strprintf(_("%s is set very high!"), optname);
|
|
||||||
}
|
|
||||||
|
|
||||||
bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
|
|
||||||
{
|
|
||||||
return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
// Copyright (c) 2010-2021 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#ifndef BITCOIN_UTIL_ERROR_H
|
|
||||||
#define BITCOIN_UTIL_ERROR_H
|
|
||||||
|
|
||||||
/**
|
|
||||||
* util/error.h is a common place for definitions of simple error types and
|
|
||||||
* string functions. Types and functions defined here should not require any
|
|
||||||
* outside dependencies.
|
|
||||||
*
|
|
||||||
* Error types defined here can be used in different parts of the
|
|
||||||
* codebase, to avoid the need to write boilerplate code catching and
|
|
||||||
* translating errors passed across wallet/node/rpc/gui code boundaries.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
struct bilingual_str;
|
|
||||||
|
|
||||||
enum class TransactionError {
|
|
||||||
OK, //!< No error
|
|
||||||
MISSING_INPUTS,
|
|
||||||
ALREADY_IN_CHAIN,
|
|
||||||
P2P_DISABLED,
|
|
||||||
MEMPOOL_REJECTED,
|
|
||||||
MEMPOOL_ERROR,
|
|
||||||
INVALID_PSBT,
|
|
||||||
PSBT_MISMATCH,
|
|
||||||
SIGHASH_MISMATCH,
|
|
||||||
MAX_FEE_EXCEEDED,
|
|
||||||
MAX_BURN_EXCEEDED,
|
|
||||||
EXTERNAL_SIGNER_NOT_FOUND,
|
|
||||||
EXTERNAL_SIGNER_FAILED,
|
|
||||||
INVALID_PACKAGE,
|
|
||||||
};
|
|
||||||
|
|
||||||
bilingual_str TransactionErrorString(const TransactionError error);
|
|
||||||
|
|
||||||
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind);
|
|
||||||
|
|
||||||
bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& strPort);
|
|
||||||
|
|
||||||
bilingual_str AmountHighWarn(const std::string& optname);
|
|
||||||
|
|
||||||
bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue);
|
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_ERROR_H
|
|
|
@ -1,67 +0,0 @@
|
||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
||||||
// Copyright (c) 2009-2020 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 <util/fees.h>
|
|
||||||
|
|
||||||
#include <policy/fees.h>
|
|
||||||
#include <util/strencodings.h>
|
|
||||||
#include <util/string.h>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
std::string StringForFeeReason(FeeReason reason)
|
|
||||||
{
|
|
||||||
static const std::map<FeeReason, std::string> fee_reason_strings = {
|
|
||||||
{FeeReason::NONE, "None"},
|
|
||||||
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
|
||||||
{FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
|
|
||||||
{FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
|
|
||||||
{FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
|
|
||||||
{FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
|
|
||||||
{FeeReason::PAYTXFEE, "PayTxFee set"},
|
|
||||||
{FeeReason::FALLBACK, "Fallback fee"},
|
|
||||||
{FeeReason::REQUIRED, "Minimum Required Fee"},
|
|
||||||
};
|
|
||||||
auto reason_string = fee_reason_strings.find(reason);
|
|
||||||
|
|
||||||
if (reason_string == fee_reason_strings.end()) return "Unknown";
|
|
||||||
|
|
||||||
return reason_string->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
|
|
||||||
{
|
|
||||||
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
|
|
||||||
{"unset", FeeEstimateMode::UNSET},
|
|
||||||
{"economical", FeeEstimateMode::ECONOMICAL},
|
|
||||||
{"conservative", FeeEstimateMode::CONSERVATIVE},
|
|
||||||
};
|
|
||||||
return FEE_MODES;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string FeeModes(const std::string& delimiter)
|
|
||||||
{
|
|
||||||
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string InvalidEstimateModeErrorMessage()
|
|
||||||
{
|
|
||||||
return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
|
|
||||||
{
|
|
||||||
auto searchkey = ToUpper(mode_string);
|
|
||||||
for (const auto& pair : FeeModeMap()) {
|
|
||||||
if (ToUpper(pair.first) == searchkey) {
|
|
||||||
fee_estimate_mode = pair.second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
||||||
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
#ifndef BITCOIN_UTIL_FEES_H
|
|
||||||
#define BITCOIN_UTIL_FEES_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
enum class FeeEstimateMode;
|
|
||||||
enum class FeeReason;
|
|
||||||
|
|
||||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
|
||||||
std::string StringForFeeReason(FeeReason reason);
|
|
||||||
std::string FeeModes(const std::string& delimiter);
|
|
||||||
std::string InvalidEstimateModeErrorMessage();
|
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_FEES_H
|
|
|
@ -13,6 +13,9 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
using util::ContainsNoNUL;
|
||||||
|
using util::TrimString;
|
||||||
|
|
||||||
std::string FormatMoney(const CAmount n)
|
std::string FormatMoney(const CAmount n)
|
||||||
{
|
{
|
||||||
// Note: not using straight sprintf here because we do NOT want
|
// Note: not using straight sprintf here because we do NOT want
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue