6 #ifndef BITCOIN_PRIMITIVES_TRANSACTION_H 7 #define BITCOIN_PRIMITIVES_TRANSACTION_H 34 static constexpr uint32_t
NULL_INDEX = std::numeric_limits<uint32_t>::max();
46 return std::tie(a.
hash, a.
n) < std::tie(b.
hash, b.
n);
215 template<
typename Stream,
typename TxType>
221 unsigned char flags = 0;
226 if (tx.vin.size() == 0 && fAllowWitness) {
237 if ((
flags & 1) && fAllowWitness) {
240 for (
size_t i = 0; i < tx.vin.size(); i++) {
241 s >> tx.vin[i].scriptWitness.stack;
243 if (!tx.HasWitness()) {
245 throw std::ios_base::failure(
"Superfluous witness record");
250 throw std::ios_base::failure(
"Unknown transaction optional data");
255 template<
typename Stream,
typename TxType>
261 unsigned char flags = 0;
265 if (tx.HasWitness()) {
271 std::vector<CTxIn> vinDummy;
278 for (
size_t i = 0; i < tx.vin.size(); i++) {
279 s << tx.vin[i].scriptWitness.stack;
285 template<
typename TxType>
288 return std::accumulate(tx.vout.cbegin(), tx.vout.cend(),
CAmount{0}, [](
CAmount sum,
const auto& txout) {
return sum + txout.nValue; });
306 const std::vector<CTxIn>
vin;
307 const std::vector<CTxOut>
vout;
327 template <
typename Stream>
334 template <
typename Stream>
336 template <
typename Stream>
340 return vin.empty() &&
vout.empty();
358 return (
vin.size() == 1 &&
vin[0].prevout.IsNull());
387 template <
typename Stream>
392 template <
typename Stream>
397 template <
typename Stream>
402 template <
typename Stream>
414 for (
size_t i = 0; i <
vin.size(); i++) {
442 #endif // BITCOIN_PRIMITIVES_TRANSACTION_H std::shared_ptr< const CTransaction > CTransactionRef
void SerializeTransaction(const TxType &tx, Stream &s, const TransactionSerParams ¶ms)
static GenTxid Wtxid(const uint256 &hash)
friend bool operator!=(const COutPoint &a, const COutPoint &b)
friend bool operator<(const GenTxid &a, const GenTxid &b)
CScriptWitness scriptWitness
Only serialized through CTransaction.
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_DISABLE_FLAG
If this flag is set, CTxIn::nSequence is NOT interpreted as a relative lock-time. ...
constexpr deserialize_type deserialize
const Wtxid m_witness_hash
friend bool operator==(const CTxOut &a, const CTxOut &b)
CAmount CalculateOutputValue(const TxType &tx)
static const int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration, and because blocks are naturally limited to occur every 600s on average, the minimum granularity for time-based relative lock-time is fixed at 512 seconds.
std::string ToString() const
std::string ToString() const
std::string ToString() const
friend bool operator!=(const CTxOut &a, const CTxOut &b)
Dummy data type to identify deserializing constructors.
SERIALIZE_METHODS(CTxOut, obj)
const std::vector< CTxIn > vin
friend bool operator==(const COutPoint &a, const COutPoint &b)
CAmount GetValueOut() const
int64_t CAmount
Amount in satoshis (Can be negative)
bool ComputeHasWitness() const
static const uint32_t CURRENT_VERSION
An input of a transaction.
CMutableTransaction(deserialize_type, const TransactionSerParams ¶ms, Stream &s)
void Unserialize(Stream &s)
Wtxid ComputeWitnessHash() const
const std::vector< CTxOut > vout
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
CTransaction(deserialize_type, const TransactionSerParams ¶ms, Stream &s)
This deserializing constructor is provided instead of an Unserialize method.
An output of a transaction.
Txid GetHash() const
Compute the hash of this CMutableTransaction.
static constexpr uint32_t NULL_INDEX
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...
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
CTransaction(deserialize_type, Stream &s)
friend bool operator==(const GenTxid &a, const GenTxid &b)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
CMutableTransaction(deserialize_type, Stream &s)
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...
const bool m_has_witness
Memory only.
Serialized script, used inside transaction inputs and outputs.
SERIALIZE_METHODS(CTxIn, obj)
void Serialize(Stream &s) const
std::string ToString() const
SERIALIZE_METHODS(COutPoint, obj)
void Serialize(Stream &s) const
A mutable version of CTransaction.
unsigned int GetTotalSize() const
Get the total transaction size in bytes, including witness data.
constexpr bool IsNull() const
Wrapped uint256 methods.
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65)...
COutPoint(const Txid &hashIn, uint32_t nIn)
friend bool operator<(const COutPoint &a, const COutPoint &b)
The basic transaction that is broadcasted on the network and contained in blocks. ...
friend bool operator==(const CTxIn &a, const CTxIn &b)
GenTxid(bool is_wtxid, const uint256 &hash)
friend bool operator!=(const CTxIn &a, const CTxIn &b)
A generic txid reference (txid or wtxid).
static GenTxid Txid(const uint256 &hash)
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
void UnserializeTransaction(TxType &tx, Stream &s, const TransactionSerParams ¶ms)
Basic transaction serialization format:
const uint256 & GetHash() const LIFETIMEBOUND
const Txid & GetHash() const LIFETIMEBOUND
friend bool operator==(const CTransaction &a, const CTransaction &b)
static constexpr TransactionSerParams TX_NO_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
CTransaction(const CMutableTransaction &tx)
Convert a CMutableTransaction into a CTransaction.
friend bool operator!=(const CTransaction &a, const CTransaction &b)