Use unique_ptr for pdbCopy (Db) and fix potential memory leak
[bitcoinplatinum.git] / src / consensus / tx_verify.h
blob288892462d006aa9a4c42db387f0a4ec4a8c191c
1 // Copyright (c) 2017-2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_CONSENSUS_TX_VERIFY_H
6 #define BITCOIN_CONSENSUS_TX_VERIFY_H
8 #include "amount.h"
10 #include <stdint.h>
11 #include <vector>
13 class CBlockIndex;
14 class CCoinsViewCache;
15 class CTransaction;
16 class CValidationState;
18 /** Transaction validation functions */
20 /** Context-independent validity checks */
21 bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
23 namespace Consensus {
24 /**
25 * Check whether all inputs of this transaction are valid (no double spends and amounts)
26 * This does not modify the UTXO set. This does not check scripts and sigs.
27 * @param[out] txfee Set to the transaction fee if successful.
28 * Preconditions: tx.IsCoinBase() is false.
30 bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee);
31 } // namespace Consensus
33 /** Auxiliary functions for transaction validation (ideally should not be exposed) */
35 /**
36 * Count ECDSA signature operations the old-fashioned (pre-0.6) way
37 * @return number of sigops this transaction's outputs will produce when spent
38 * @see CTransaction::FetchInputs
40 unsigned int GetLegacySigOpCount(const CTransaction& tx);
42 /**
43 * Count ECDSA signature operations in pay-to-script-hash inputs.
45 * @param[in] mapInputs Map of previous transactions that have outputs we're spending
46 * @return maximum number of sigops required to validate this transaction's inputs
47 * @see CTransaction::FetchInputs
49 unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);
51 /**
52 * Compute total signature operation cost of a transaction.
53 * @param[in] tx Transaction for which we are computing the cost
54 * @param[in] inputs Map of previous transactions that have outputs we're spending
55 * @param[out] flags Script verification flags
56 * @return Total signature operation cost of tx
58 int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, int flags);
60 /**
61 * Check if transaction is final and can be included in a block with the
62 * specified height and time. Consensus critical.
64 bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);
66 /**
67 * Calculates the block height and previous block's median time past at
68 * which the transaction will be considered final in the context of BIP 68.
69 * Also removes from the vector of input heights any entries which did not
70 * correspond to sequence locked inputs as they do not affect the calculation.
72 std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block);
74 bool EvaluateSequenceLocks(const CBlockIndex& block, std::pair<int, int64_t> lockPair);
75 /**
76 * Check if transaction is final per BIP 68 sequence numbers and can be included in a block.
77 * Consensus critical. Takes as input a list of heights at which tx's inputs (in order) confirmed.
79 bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block);
81 #endif // BITCOIN_CONSENSUS_TX_VERIFY_H