6#ifndef BITCOIN_PRIMITIVES_TRANSACTION_H
7#define BITCOIN_PRIMITIVES_TRANSACTION_H
35 static constexpr uint32_t
NULL_INDEX = std::numeric_limits<uint32_t>::max();
47 return std::tie(a.
hash, a.
n) < std::tie(b.
hash, b.
n);
201template<
typename Stream,
typename TxType>
207 unsigned char flags = 0;
212 if (tx.vin.size() == 0 && fAllowWitness) {
223 if ((
flags & 1) && fAllowWitness) {
226 for (
size_t i = 0; i < tx.vin.size(); i++) {
227 s >> tx.vin[i].scriptWitness.stack;
229 if (!tx.HasWitness()) {
231 throw std::ios_base::failure(
"Superfluous witness record");
236 throw std::ios_base::failure(
"Unknown transaction optional data");
241template<
typename Stream,
typename TxType>
247 unsigned char flags = 0;
251 if (tx.HasWitness()) {
257 std::vector<CTxIn> vinDummy;
264 for (
size_t i = 0; i < tx.vin.size(); i++) {
265 s << tx.vin[i].scriptWitness.stack;
271template<
typename TxType>
274 return std::accumulate(tx.vout.cbegin(), tx.vout.cend(),
CAmount{0}, [](
CAmount sum,
const auto& txout) { return sum + txout.nValue; });
297 const std::vector<CTxIn>
vin;
298 const std::vector<CTxOut>
vout;
318 template <
typename Stream>
325 template <
typename Stream>
327 template <
typename Stream>
331 return vin.empty() &&
vout.empty();
349 return (
vin.size() == 1 &&
vin[0].prevout.IsNull());
357 std::ranges::equal(
vin, other.
vin, [&opts](
const CTxIn& self,
const CTxIn& other) {
358 return self.prevout == other.prevout &&
359 self.nSequence == other.nSequence &&
360 (opts.include_script_sig ? self.scriptSig == other.scriptSig : true) &&
361 (opts.include_witness_data ? self.scriptWitness.stack == other.scriptWitness.stack : true);
381 template <
typename Stream>
386 template <
typename Stream>
391 template <
typename Stream>
396 template <
typename Stream>
408 for (
size_t i = 0; i <
vin.size(); i++) {
int64_t CAmount
Amount in satoshis (Can be negative)
An outpoint - a combination of a transaction hash and an index n into its vout.
friend bool operator==(const COutPoint &a, const COutPoint &b)
SERIALIZE_METHODS(COutPoint, obj)
COutPoint(const Txid &hashIn, uint32_t nIn)
friend bool operator<(const COutPoint &a, const COutPoint &b)
std::string ToString() const
static constexpr uint32_t NULL_INDEX
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
CTransaction(deserialize_type, const TransactionSerParams ¶ms, Stream &s)
This deserializing constructor is provided instead of an Unserialize method.
static constexpr uint32_t CURRENT_VERSION
CTransaction(deserialize_type, Stream &s)
bool Equals(const CTransaction &other, const EqualsOptions opts={}) const
unsigned int ComputeTotalSize() const
Calculate the total transaction size in bytes, including witness data.
bool ComputeHasWitness() const
CTransaction(const CMutableTransaction &tx)
Convert a CMutableTransaction into a CTransaction.
const Wtxid m_witness_hash
void Serialize(Stream &s) const
const std::vector< CTxOut > vout
std::string ToString() const
const bool m_has_witness
Memory only.
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
Wtxid ComputeWitnessHash() const
CAmount GetValueOut() const
const Txid & GetHash() const LIFETIMEBOUND
const std::vector< CTxIn > vin
An input of a transaction.
static constexpr uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
friend bool operator==(const CTxIn &a, const CTxIn &b)
static constexpr int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration,...
static constexpr 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 constexpr uint32_t SEQUENCE_LOCKTIME_MASK
If CTxIn::nSequence encodes a relative lock-time, this mask is applied to extract that lock-time from...
static constexpr uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
If this flag is set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
std::string ToString() const
CScriptWitness scriptWitness
Only serialized through CTransaction.
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
SERIALIZE_METHODS(CTxIn, obj)
An output of a transaction.
SERIALIZE_METHODS(CTxOut, obj)
friend bool operator==(const CTxOut &a, const CTxOut &b)
std::string ToString() const
constexpr bool IsNull() const
Wrapped uint256 methods.
constexpr TransactionSerParams TX_NO_WITNESS
void UnserializeTransaction(TxType &tx, Stream &s, const TransactionSerParams ¶ms)
Basic transaction serialization format:
constexpr TransactionSerParams TX_WITH_WITNESS
void SerializeTransaction(const TxType &tx, Stream &s, const TransactionSerParams ¶ms)
CAmount CalculateOutputValue(const TxType &tx)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
constexpr deserialize_type deserialize
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
A mutable version of CTransaction.
CMutableTransaction(deserialize_type, const TransactionSerParams ¶ms, Stream &s)
void Unserialize(Stream &s)
void Serialize(Stream &s) const
CMutableTransaction(deserialize_type, Stream &s)
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
bool include_witness_data
Dummy data type to identify deserializing constructors.
size_t operator()(const CTransactionRef &) const =delete