27 int64_t lockTimeLimit =
29 if (lockTime < lockTimeLimit) {
33 for (
const auto &txin : tx.
vin) {
44 int64_t nMedianTimePast) {
49 "bad-txns-nonfinal",
"non-final transaction");
56 "bad-txns-undersize");
80 std::vector<int> &prevHeights,
82 assert(prevHeights.size() == tx.
vin.size());
90 int64_t nMinTime = -1;
95 bool fEnforceBIP68 =
static_cast<uint32_t
>(tx.
nVersion) >= 2 &&
100 if (!fEnforceBIP68) {
101 return std::make_pair(nMinHeight, nMinTime);
104 for (
size_t txinIndex = 0; txinIndex < tx.
vin.size(); txinIndex++) {
105 const CTxIn &txin = tx.
vin[txinIndex];
112 prevHeights[txinIndex] = 0;
116 int nCoinHeight = prevHeights[txinIndex];
119 const int64_t nCoinTime{
121 ->GetMedianTimePast()};
140 nMinHeight = std::max(
147 return std::make_pair(nMinHeight, nMinTime);
151 std::pair<int, int64_t> lockPair) {
154 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime) {
162 std::vector<int> &prevHeights,
const CBlockIndex &block) {
174 "bad-txns-inputs-missingorspent",
175 strprintf(
"%s: inputs missing/spent", __func__));
179 for (
const auto &in : tx.
vin) {
189 "bad-txns-premature-spend-of-coinbase",
190 strprintf(
"tried to spend coinbase at depth %d",
198 "bad-txns-inputvalues-outofrange");
203 if (nValueIn < value_out) {
211 const Amount txfee_aux = nValueIn - value_out;
214 "bad-txns-fee-outofrange");
bool IsWellingtonEnabled(const Consensus::Params ¶ms, int32_t nHeight)
Check if May 15th, 2023 protocol upgrade has activated.
bool IsMagneticAnomalyEnabled(const Consensus::Params ¶ms, int32_t nHeight)
Check if Nov 15, 2018 HF has activated using block height.
bool MoneyRange(const Amount nValue)
#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.
The basic transaction that is broadcasted on the network and contained in blocks.
static constexpr int32_t MAX_VERSION
Amount GetValueOut() const
const std::vector< CTxIn > vin
static constexpr int32_t MIN_VERSION
An input of a transaction.
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
If this flag 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.
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,...
uint32_t GetHeight() const
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 uint64_t MIN_TX_SIZE
The minimum allowed size for a transaction, in bytes.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, Amount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts).
static const unsigned int LOCKTIME_THRESHOLD
size_t GetSerializeSize(const T &t, int nVersion=0)
static constexpr Amount zero() noexcept
Parameters that influence chain consensus.
static bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
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...
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.
bool ContextualCheckTransaction(const Consensus::Params ¶ms, const CTransaction &tx, TxValidationState &state, int nHeight, int64_t nMedianTimePast)
Context dependent validity checks for non coinbase transactions.
static const int PROTOCOL_VERSION
network protocol versioning