refactor: Add LIFETIMEBOUND to all (w)txid getters

Then, use the compiler warnings to create copies only where needed.

Also, fix iwyu includes while touching the includes.
This commit is contained in:
MarcoFalke
2023-10-27 12:38:21 +02:00
parent e789b30b25
commit faec889f93
6 changed files with 19 additions and 17 deletions

View File

@@ -6,8 +6,8 @@
#ifndef BITCOIN_PRIMITIVES_TRANSACTION_H
#define BITCOIN_PRIMITIVES_TRANSACTION_H
#include <attributes.h>
#include <consensus/amount.h>
#include <prevector.h>
#include <script/script.h>
#include <serialize.h>
#include <uint256.h>
@@ -335,8 +335,8 @@ public:
return vin.empty() && vout.empty();
}
const Txid& GetHash() const { return hash; }
const Wtxid& GetWitnessHash() const { return m_witness_hash; };
const Txid& GetHash() const LIFETIMEBOUND { return hash; }
const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return m_witness_hash; };
// Return sum of txouts.
CAmount GetValueOut() const;
@@ -433,7 +433,7 @@ public:
static GenTxid Txid(const uint256& hash) { return GenTxid{false, hash}; }
static GenTxid Wtxid(const uint256& hash) { return GenTxid{true, hash}; }
bool IsWtxid() const { return m_is_wtxid; }
const uint256& GetHash() const { return m_hash; }
const uint256& GetHash() const LIFETIMEBOUND { return m_hash; }
friend bool operator==(const GenTxid& a, const GenTxid& b) { return a.m_is_wtxid == b.m_is_wtxid && a.m_hash == b.m_hash; }
friend bool operator<(const GenTxid& a, const GenTxid& b) { return std::tie(a.m_is_wtxid, a.m_hash) < std::tie(b.m_is_wtxid, b.m_hash); }
};