23 if ((int64_t)tx.
nLockTime < ((int64_t)tx.
nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))
25 for (
const auto& txin : tx.
vin) {
34 assert(prevHeights->size() == tx.
vin.size());
42 int64_t nMinTime = -1;
47 bool fEnforceBIP68 =
static_cast<uint32_t
>(tx.
nVersion) >= 2
53 return std::make_pair(nMinHeight, nMinTime);
56 for (
size_t txinIndex = 0; txinIndex < tx.
vin.size(); txinIndex++) {
57 const CTxIn& txin = tx.
vin[txinIndex];
64 (*prevHeights)[txinIndex] = 0;
68 int nCoinHeight = (*prevHeights)[txinIndex];
91 return std::make_pair(nMinHeight, nMinTime);
98 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime)
111 unsigned int nSigOps = 0;
112 for (
const auto& txin : tx.
vin)
114 nSigOps += txin.scriptSig.GetSigOpCount(
false);
116 for (
const auto& txout : tx.
vout)
118 nSigOps += txout.scriptPubKey.GetSigOpCount(
false);
128 unsigned int nSigOps = 0;
129 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
134 if (prevout.scriptPubKey.IsPayToScriptHash())
151 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
165 return state.
DoS(10,
false, REJECT_INVALID,
"bad-txns-vin-empty");
167 return state.
DoS(10,
false, REJECT_INVALID,
"bad-txns-vout-empty");
172 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-oversize");
176 for (
const auto& txout : tx.
vout)
179 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-vout-empty");
180 if (txout.nValue < 0)
181 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-vout-negative");
182 if (txout.nValue > MAX_MONEY)
183 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-vout-toolarge");
184 nValueOut += txout.nValue;
186 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-txouttotal-toolarge");
189 if (txout.scriptPubKey.HasOpCall() || txout.scriptPubKey.HasOpCreate()) {
190 std::vector<valtype> vSolutions;
192 if (!
Solver(txout.scriptPubKey, whichType, vSolutions,
true)) {
193 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-contract-nonstandard");
200 if (fCheckDuplicateInputs) {
201 std::set<COutPoint> vInOutPoints;
202 for (
const auto& txin : tx.
vin)
204 if (!vInOutPoints.insert(txin.prevout).second)
205 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-inputs-duplicate");
211 if (tx.
vin[0].scriptSig.size() < 2 || tx.
vin[0].scriptSig.size() > 100)
212 return state.
DoS(100,
false, REJECT_INVALID,
"bad-cb-length");
216 for (
const auto& txin : tx.
vin)
217 if (txin.prevout.IsNull())
218 return state.
DoS(10,
false, REJECT_INVALID,
"bad-txns-prevout-null");
229 return state.
Invalid(
false, 0,
"",
"Inputs unavailable");
233 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
242 if (nSpendHeight - coin.
nHeight < COINBASE_MATURITY)
244 REJECT_INVALID,
"bad-txns-premature-spend-of-coinbase",
245 strprintf(
"tried to spend coinbase at depth %d", nSpendHeight - coin.
nHeight));
251 REJECT_INVALID,
"bad-txns-premature-spend-of-coinbase",
259 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-inputvalues-outofrange");
264 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-in-belowout",
false,
270 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-fee-negative");
273 return state.
DoS(100,
false, REJECT_INVALID,
"bad-txns-fee-outofrange");
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet, bool contractConsensus)
Return public keys or hashes from scriptPubKey, for 'standard' transaction types. ...
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 CheckTxInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
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...
size_t CountWitnessSigOps(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags)
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
static const uint32_t SEQUENCE_FINAL
Only serialized through CTransaction.
bool MoneyRange(const CAmount &nValue)
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
const Consensus::Params & GetConsensus() const
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
CTxOut out
unspent transaction output
static const int SEQUENCE_LOCKTIME_GRANULARITY
assert(len-trim+(2 *lenIndices)<=WIDTH)
bool DoS(int level, bool ret=false, unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="", bool corruptionIn=false, const std::string &strDebugMessageIn="")
const std::vector< CTxIn > vin
int64_t CAmount
Amount in lius (Can be negative)
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
const CChainParams & GetParams()
An input of a transaction.
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Fabcoin always counted CHECKMULTISIGs as 20 sigops.
int CoinbaseLock
Block height before which the coinbase subsidy will be locked for the same period.
CAmount GetValueOut() const
const std::vector< CTxOut > vout
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or a pruned one if not found.
bool EvaluateSequenceLocks(const CBlockIndex &block, std::pair< int, int64_t > lockPair)
An output of a transaction.
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
Parameters that influence chain consensus.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
Capture information about block/transaction validation.
static const uint32_t SEQUENCE_LOCKTIME_MASK
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Auxiliary functions for transaction validation (ideally should not be exposed)
The block chain is a tree shaped structure starting with the genesis block at the root...
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fCheckDuplicateInputs)
Transaction validation functions.
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...
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
The basic transaction that is broadcasted on the network and contained in blocks. ...
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.
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
bool Invalid(bool ret=false, unsigned int _chRejectCode=0, const std::string &_strRejectReason="", const std::string &_strDebugMessage="")
int64_t GetMedianTimePast() const
int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &inputs, int flags)
Compute total signature operation cost of a transaction.
unsigned int dgpMaxBlockWeight
The maximum allowed weight for a block, see BIP 141 (network rule)