32 for (
const auto& txin : tx.
vin) {
41 assert(prevHeights.size() == tx.
vin.size());
49 int64_t nMinTime = -1;
56 return std::make_pair(nMinHeight, nMinTime);
59 for (
size_t txinIndex = 0; txinIndex < tx.
vin.size(); txinIndex++) {
60 const CTxIn& txin = tx.
vin[txinIndex];
67 prevHeights[txinIndex] = 0;
71 int nCoinHeight = prevHeights[txinIndex];
74 const int64_t nCoinTime{
Assert(block.
GetAncestor(std::max(nCoinHeight - 1, 0)))->GetMedianTimePast()};
94 return std::make_pair(nMinHeight, nMinTime);
101 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime)
114 unsigned int nSigOps = 0;
115 for (
const auto& txin : tx.
vin)
117 nSigOps += txin.scriptSig.GetSigOpCount(
false);
119 for (
const auto& txout : tx.
vout)
121 nSigOps += txout.scriptPubKey.GetSigOpCount(
false);
131 unsigned int nSigOps = 0;
132 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
154 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
169 strprintf(
"%s: inputs missing/spent", __func__));
173 for (
unsigned int i = 0; i < tx.
vin.size(); ++i) {
181 strprintf(
"tried to spend coinbase at depth %d", nSpendHeight - coin.
nHeight));
192 if (nValueIn < value_out) {
198 const CAmount txfee_aux = nValueIn - value_out;
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
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
If this flag is set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
static const uint32_t SEQUENCE_LOCKTIME_MASK
If CTxIn::nSequence encodes a relative lock-time, this mask is applied to extract that lock-time from...
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
If CTxIn::nSequence encodes a relative lock-time and this flag is set, the relative lock-time has uni...
static const int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration,...
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.