mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 22:41:25 +02:00
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 ```
134 lines
3.8 KiB
C++
134 lines
3.8 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_TRANSACTIONRECORD_H
|
|
#define BITCOIN_QT_TRANSACTIONRECORD_H
|
|
|
|
#include <consensus/amount.h>
|
|
#include <primitives/transaction_identifier.h>
|
|
#include <uint256.h>
|
|
|
|
#include <QList>
|
|
#include <QString>
|
|
|
|
namespace interfaces {
|
|
class Node;
|
|
class Wallet;
|
|
struct WalletTx;
|
|
struct WalletTxStatus;
|
|
}
|
|
|
|
/** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
|
|
*/
|
|
struct TransactionStatus {
|
|
enum Status {
|
|
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
|
|
/// Normal (sent/received) transactions
|
|
Unconfirmed, /**< Not yet mined into a block **/
|
|
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
|
|
Conflicted, /**< Conflicts with other transaction or mempool **/
|
|
Abandoned, /**< Abandoned from the wallet **/
|
|
/// Generated (mined) transactions
|
|
Immature, /**< Mined but waiting for maturity */
|
|
NotAccepted /**< Mined but not accepted */
|
|
};
|
|
|
|
/// Transaction counts towards available balance
|
|
bool countsForBalance{false};
|
|
/// Sorting key based on status
|
|
std::string sortKey;
|
|
|
|
/** @name Generated (mined) transactions
|
|
@{*/
|
|
int matures_in{0};
|
|
/**@}*/
|
|
|
|
/** @name Reported status
|
|
@{*/
|
|
Status status{Unconfirmed};
|
|
qint64 depth{0};
|
|
/**@}*/
|
|
|
|
/** Current block hash (to know whether cached status is still valid) */
|
|
uint256 m_cur_block_hash{};
|
|
|
|
bool needsUpdate{false};
|
|
};
|
|
|
|
/** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
|
|
multiple outputs.
|
|
*/
|
|
class TransactionRecord
|
|
{
|
|
public:
|
|
enum Type
|
|
{
|
|
Other,
|
|
Generated,
|
|
SendToAddress,
|
|
SendToOther,
|
|
RecvWithAddress,
|
|
RecvFromOther,
|
|
};
|
|
|
|
/** Number of confirmation recommended for accepting a transaction */
|
|
static constexpr int RecommendedNumConfirmations{6};
|
|
|
|
TransactionRecord():
|
|
hash(), time(0), type(Other), debit(0), credit(0), idx(0)
|
|
{
|
|
}
|
|
|
|
TransactionRecord(Txid _hash, qint64 _time):
|
|
hash(_hash), time(_time), type(Other), debit(0),
|
|
credit(0), idx(0)
|
|
{
|
|
}
|
|
|
|
TransactionRecord(Txid _hash, qint64 _time,
|
|
Type _type, const std::string &_address,
|
|
const CAmount& _debit, const CAmount& _credit):
|
|
hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit),
|
|
idx(0)
|
|
{
|
|
}
|
|
|
|
/** Decompose CWallet transaction to model transaction records.
|
|
*/
|
|
static bool showTransaction();
|
|
static QList<TransactionRecord> decomposeTransaction(const interfaces::WalletTx& wtx);
|
|
|
|
/** @name Immutable transaction attributes
|
|
@{*/
|
|
Txid hash;
|
|
qint64 time;
|
|
Type type;
|
|
std::string address;
|
|
CAmount debit;
|
|
CAmount credit;
|
|
/**@}*/
|
|
|
|
/** Subtransaction index, for sort key */
|
|
int idx;
|
|
|
|
/** Status: can change with block chain update */
|
|
TransactionStatus status;
|
|
|
|
/** Return the unique identifier for this transaction (part) */
|
|
QString getTxHash() const;
|
|
|
|
/** Return the output index of the subtransaction */
|
|
int getOutputIndex() const;
|
|
|
|
/** Update status from core wallet tx.
|
|
*/
|
|
void updateStatus(const interfaces::WalletTxStatus& wtx, const uint256& block_hash, int numBlocks, int64_t block_time);
|
|
|
|
/** Return whether a status update is needed.
|
|
*/
|
|
bool statusUpdateNeeded(const uint256& block_hash) const;
|
|
};
|
|
|
|
#endif // BITCOIN_QT_TRANSACTIONRECORD_H
|