33 for (
const auto& txin : tx.
vin) {
42 assert(prevHeights.size() == tx.
vin.size());
50 int64_t nMinTime = -1;
55 bool fEnforceBIP68 =
static_cast<uint32_t
>(tx.
nVersion) >= 2
61 return std::make_pair(nMinHeight, nMinTime);
64 for (
size_t txinIndex = 0; txinIndex < tx.
vin.size(); txinIndex++) {
65 const CTxIn& txin = tx.
vin[txinIndex];
72 prevHeights[txinIndex] = 0;
76 int nCoinHeight = prevHeights[txinIndex];
99 return std::make_pair(nMinHeight, nMinTime);
106 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime)
119 unsigned int nSigOps = 0;
120 for (
const auto& txin : tx.
vin)
122 nSigOps += txin.scriptSig.GetSigOpCount(
false);
124 for (
const auto& txout : tx.
vout)
126 nSigOps += txout.scriptPubKey.GetSigOpCount(
false);
136 unsigned int nSigOps = 0;
137 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
159 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
174 strprintf(
"%s: inputs missing/spent", __func__));
178 for (
unsigned int i = 0; i < tx.
vin.size(); ++i) {
186 strprintf(
"tried to spend coinbase at depth %d", nSpendHeight - coin.
nHeight));
197 if (nValueIn < value_out) {
203 const CAmount txfee_aux = nValueIn - value_out;
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t GetMedianTimePast() const
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
An outpoint - a combination of a transaction hash and an index n into its vout.
bool IsPayToScriptHash() const
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
CAmount GetValueOut() const
const std::vector< CTxIn > vin
An input of a transaction.
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
static const uint32_t SEQUENCE_LOCKTIME_MASK
static const uint32_t SEQUENCE_FINAL
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
static const int SEQUENCE_LOCKTIME_GRANULARITY
An output of a transaction.
CTxOut out
unspent transaction output
bool IsSpent() const
Either this coin never existed (see e.g.
uint32_t nHeight
at which height this containing transaction was included in the active block chain
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
@ TX_PREMATURE_SPEND
transaction spends a coinbase too early, or violates locktime/sequence locks
@ TX_CONSENSUS
invalid by consensus rules
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
static const int WITNESS_SCALE_FACTOR
size_t CountWitnessSigOps(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags)
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, CAmount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
static const unsigned int LOCKTIME_THRESHOLD
bool EvaluateSequenceLocks(const CBlockIndex &block, std::pair< int, int64_t > lockPair)
std::pair< int, int64_t > CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Calculates the block height and previous block's median time past at which the transaction will be co...
int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &inputs, uint32_t flags)
Compute total signature operation cost of a transaction.
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Auxiliary functions for transaction validation (ideally should not be exposed)
bool SequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Check if transaction is final per BIP 68 sequence numbers and can be included in a block.
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.