Files
bitcoin/src/qt/sendcoinsrecipient.h
rustaceanrob 05c35c402c refactor: Make all const static class members constexpr
If a `static class` member is not inlined or `constexpr`, the linker
will fail when attempting to ODR-use the constant (passing as `const
T&`). These can be fixed by finding all member variables that are
`const` qualified and inlining them with `constexpr`. There is a
clang-tidy pull request that would lint these callsites: https://github.com/llvm/llvm-project/pull/162741

A script was used to modify these sites, however it cannot run as a
scripted-diff because it uses clang-query and a build folder.

The script only queries for integer and enumeration types, as other data
members would have to be marked `constexpr` or `inline` from what I
understand: https://en.cppreference.com/cpp/language/static#Constant_static_members

Removing the ZMQ forward declaration was a clang-tidy lint.

The script used to find these sites, LLM assisted:
```
set -uxo pipefail

cd "$(git rev-parse --show-toplevel)"

BUILD=${BUILD:-build}
if [ ! -f "${BUILD}/compile_commands.json" ]; then
    echo "error: ${BUILD}/compile_commands.json not found. Run cmake -B ${BUILD} first." >&2
    exit 1
fi
if ! command -v clang-query >/dev/null; then
    echo "error: clang-query not on PATH. Install clang-tools." >&2
    exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
    echo "error: working tree has uncommitted changes. Commit or stash first." >&2
    exit 1
fi

MATCHER='match varDecl(hasParent(cxxRecordDecl()),
                      hasType(qualType(isConstQualified(),
                                       anyOf(hasCanonicalType(isInteger()),
                                             hasDeclaration(enumDecl())))),
                      hasInitializer(expr()),
                      unless(isConstexpr()),
                      isExpansionInFileMatching("/src/"))'

RAW=$(mktemp)
trap 'rm -f "$RAW"' EXIT

echo "Sweeping TUs (batched, may take a few minutes)..." >&2
find src -type d \( -name secp256k1 -o -name leveldb -o -name crc32c \
                    -o -name minisketch -o -name libmultiprocess -o -name ctaes \) -prune -o \
        -name '*.cpp' -print0 \
    | xargs -0 -n 50 clang-query -p "${BUILD}" \
          -c 'set output diag' \
          -c "${MATCHER}" \
          >>"$RAW" || true

ROOT=$(pwd)
LOCS=$(grep -oE "${ROOT}/src/[^:]+:[0-9]+:[0-9]+:" "$RAW" \
    | sed -E "s|^${ROOT}/||; s|:[0-9]+:$||" \
    | sort -u)

if [ -z "$LOCS" ]; then
    echo "no matches" >&2
    exit 0
fi

FILTERED=""
while IFS=: read -r file line; do
    case "$file" in
        src/secp256k1/*|src/leveldb/*|src/crc32c/*|src/minisketch/*|src/ipc/libmultiprocess/*|src/crypto/ctaes/*) continue ;;
        src/tinyformat.h) continue ;;
    esac
    src=$(sed -n "${line}p" "$file")
    case "$src" in *inline*) continue ;; esac
    FILTERED+="${file}:${line}"$'\n'
done <<<"$LOCS"
FILTERED=$(printf '%s' "$FILTERED" | sed '/^$/d')

if [ -z "$FILTERED" ]; then
    echo "no matches after filtering" >&2
    exit 0
fi

echo "Sites to rewrite ($(echo "$FILTERED" | wc -l)):" >&2
echo "$FILTERED" >&2

declare -A LINES
while IFS=: read -r file line; do
    LINES[$file]+="${line} "
done <<<"$FILTERED"

for file in "${!LINES[@]}"; do
    args=()
    for line in ${LINES[$file]}; do
        args+=(-e "${line}s/static const /static constexpr /")
    done
    sed -i "${args[@]}" "$file"
done

echo >&2
echo "===== proposed diff =====" >&2
git --no-pager diff
```
2026-07-24 14:01:06 +01:00

62 lines
2.5 KiB
C++

// Copyright (c) 2011-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_QT_SENDCOINSRECIPIENT_H
#define BITCOIN_QT_SENDCOINSRECIPIENT_H
#include <consensus/amount.h>
#include <serialize.h>
#include <string>
#include <QString>
class SendCoinsRecipient
{
public:
explicit SendCoinsRecipient() : amount(0), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
explicit SendCoinsRecipient(const QString &addr, const QString &_label, const CAmount& _amount, const QString &_message):
address(addr), label(_label), amount(_amount), message(_message), fSubtractFeeFromAmount(false), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
// If from an unauthenticated payment request, this is used for storing
// the addresses, e.g. address-A<br />address-B<br />address-C.
// Info: As we don't need to process addresses in here when using
// payment requests, we can abuse it for displaying an address list.
// Todo: This is a hack, should be replaced with a cleaner solution!
QString address;
QString label;
CAmount amount;
// If from a payment request, this is used for storing the memo
QString message;
// Keep the payment request around as a serialized string to ensure
// load/store is lossless.
std::string sPaymentRequest;
// Empty if no authentication or invalid signature/cert/etc.
QString authenticatedMerchant;
bool fSubtractFeeFromAmount; // memory only
static constexpr int CURRENT_VERSION{1};
int nVersion;
SERIALIZE_METHODS(SendCoinsRecipient, obj)
{
std::string address_str, label_str, message_str, auth_merchant_str;
SER_WRITE(obj, address_str = obj.address.toStdString());
SER_WRITE(obj, label_str = obj.label.toStdString());
SER_WRITE(obj, message_str = obj.message.toStdString());
SER_WRITE(obj, auth_merchant_str = obj.authenticatedMerchant.toStdString());
READWRITE(obj.nVersion, address_str, label_str, obj.amount, message_str, obj.sPaymentRequest, auth_merchant_str);
SER_READ(obj, obj.address = QString::fromStdString(address_str));
SER_READ(obj, obj.label = QString::fromStdString(label_str));
SER_READ(obj, obj.message = QString::fromStdString(message_str));
SER_READ(obj, obj.authenticatedMerchant = QString::fromStdString(auth_merchant_str));
}
};
#endif // BITCOIN_QT_SENDCOINSRECIPIENT_H