Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2017-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_CONSENSUS_TX_VERIFY_H6#define BITCOIN_CONSENSUS_TX_VERIFY_H8#include <consensus/amount.h>9#include <script/verify_flags.h>11#include <cstdint>12#include <utility>13#include <vector>15class CBlockIndex;16class CCoinsViewCache;17class CTransaction;18class TxValidationState;20/** Transaction validation functions */22namespace Consensus {23/**24* Check whether all inputs of this transaction are valid (no double spends and amounts)25* This does not modify the UTXO set. This does not check scripts and sigs.26* @param[out] txfee Set to the transaction fee if successful.27* Preconditions: tx.IsCoinBase() is false.28*/29[[nodiscard]] bool CheckTxInputs(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee);30} // namespace Consensus32/** Auxiliary functions for transaction validation (ideally should not be exposed) */34/**35* Count ECDSA signature operations the old-fashioned (pre-0.6) way36* @return number of sigops this transaction's outputs will produce when spent37* @see CTransaction::FetchInputs38*/39unsigned int GetLegacySigOpCount(const CTransaction& tx);41/**42* Count ECDSA signature operations in pay-to-script-hash inputs.43*44* @param[in] mapInputs Map of previous transactions that have outputs we're spending45* @return maximum number of sigops required to validate this transaction's inputs46* @see CTransaction::FetchInputs47*/48unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);50/**51* Compute total signature operation cost of a transaction.52* @param[in] tx Transaction for which we are computing the cost53* @param[in] inputs Map of previous transactions that have outputs we're spending54* @param[in] flags Script verification flags55* @return Total signature operation cost of tx56*/57int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, script_verify_flags flags);59/**60* Check if transaction is final and can be included in a block with the61* specified height and time. Consensus critical.62*/63bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);65/**66* Calculates the block height and previous block's median time past at67* which the transaction will be considered final in the context of BIP 68.68* For each input that is not sequence locked, the corresponding entries in69* prevHeights are set to 0 as they do not affect the calculation.70*/71std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector<int>& prevHeights, const CBlockIndex& block);73bool EvaluateSequenceLocks(const CBlockIndex& block, std::pair<int, int64_t> lockPair);74/**75* Check if transaction is final per BIP 68 sequence numbers and can be included in a block.76* Consensus critical. Takes as input a list of heights at which tx's inputs (in order) confirmed.77*/78bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>& prevHeights, const CBlockIndex& block);80#endif // BITCOIN_CONSENSUS_TX_VERIFY_H