6 #ifndef FABCOIN_PRIMITIVES_TRANSACTION_H 7 #define FABCOIN_PRIMITIVES_TRANSACTION_H 15 static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000;
29 template <
typename Stream,
typename Operation>
36 bool IsNull()
const {
return (hash.
IsNull() && n == (uint32_t) -1); }
41 return cmp < 0 || (cmp == 0 && a.
n < b.
n);
71 static const uint32_t SEQUENCE_FINAL = 0xffffffff;
76 static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
81 static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
85 static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
94 static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
98 nSequence = SEQUENCE_FINAL;
106 template <
typename Stream,
typename Operation>
146 template <
typename Stream,
typename Operation>
155 scriptPubKey.
clear();
160 return (nValue == -1);
166 scriptPubKey.
clear();
171 return (nValue == 0 && scriptPubKey.
empty());
207 template<
typename Stream,
typename TxType>
209 const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
212 unsigned char flags = 0;
217 if (tx.vin.size() == 0 && fAllowWitness) {
228 if ((flags & 1) && fAllowWitness) {
231 for (
size_t i = 0; i < tx.vin.size(); i++) {
232 s >> tx.vin[i].scriptWitness.stack;
237 throw std::ios_base::failure(
"Unknown transaction optional data");
242 template<
typename Stream,
typename TxType>
244 const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
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;
279 static const int32_t CURRENT_VERSION=2;
285 static const int32_t MAX_STANDARD_VERSION=2;
292 const std::vector<CTxIn>
vin;
293 const std::vector<CTxOut>
vout;
311 template <
typename Stream>
318 template <
typename Stream>
322 return vin.empty() && vout.empty();
330 uint256 GetWitnessHash()
const;
342 unsigned int GetTotalSize()
const;
345 bool HasCreateOrCall()
const;
346 bool HasOpSpend()
const;
351 return (vin.size() == 1 && vin[0].prevout.IsNull() && vout.size() >= 1);
357 return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].IsEmpty());
363 return !IsCoinBase() && !IsCoinStake();
380 for (
size_t i = 0; i < vin.size(); i++) {
381 if (!vin[i].scriptWitness.IsNull()) {
400 template <
typename Stream>
406 template <
typename Stream>
411 template <
typename Stream>
428 for (
size_t i = 0; i < vin.size(); i++) {
429 if (!vin[i].scriptWitness.IsNull()) {
438 static inline CTransactionRef MakeTransactionRef() {
return std::make_shared<const CTransaction>(); }
439 template <
typename Tx>
static inline CTransactionRef MakeTransactionRef(Tx&& txIn) {
return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
442 #endif // FABCOIN_PRIMITIVES_TRANSACTION_H
friend bool operator!=(const COutPoint &a, const COutPoint &b)
COutPoint(const uint256 &hashIn, uint32_t nIn)
CScriptWitness scriptWitness
constexpr deserialize_type deserialize
friend bool operator==(const CTxOut &a, const CTxOut &b)
void SerializationOp(Stream &s, Operation ser_action)
void Serialize(Stream &s) const
friend bool operator!=(const CTxOut &a, const CTxOut &b)
void UnserializeTransaction(TxType &tx, Stream &s)
Basic transaction serialization format:
const uint256 hash
Memory only.
std::shared_ptr< const CTransaction > CTransactionRef
Dummy data type to identify deserializing constructors.
const std::vector< CTxIn > vin
friend bool operator==(const COutPoint &a, const COutPoint &b)
void SerializeTransaction(const TxType &tx, Stream &s)
int64_t CAmount
Amount in lius (Can be negative)
An input of a transaction.
void Unserialize(Stream &s)
void SerializationOp(Stream &s, Operation ser_action)
const std::vector< CTxOut > vout
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
CTransaction(deserialize_type, Stream &s)
This deserializing constructor is provided instead of an Unserialize method.
friend bool operator==(const CMutableTransaction &a, const CMutableTransaction &b)
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
void SerializationOp(Stream &s, Operation ser_action)
std::string ToString() const
CMutableTransaction(deserialize_type, Stream &s)
int64_t GetTransactionWeight(const CTransaction &tx)
Serialized script, used inside transaction inputs and outputs.
void Unserialize(Stream &s, char &a)
int Compare(const base_blob &other) const
void Serialize(Stream &s) const
A mutable version of CTransaction.
const uint256 & GetHash() const
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)
friend bool operator!=(const CTxIn &a, const CTxIn &b)
friend bool operator==(const CTransaction &a, const CTransaction &b)
friend bool operator!=(const CTransaction &a, const CTransaction &b)