Fix dangling reference returns
This commit is contained in:
parent
e246aa4e40
commit
ffd46598ad
5 changed files with 38 additions and 49 deletions
|
|
@ -609,7 +609,7 @@ std::optional<nano::account> nano::send_block::destination_field () const
|
|||
return hashables.destination;
|
||||
}
|
||||
|
||||
nano::root const & nano::send_block::root () const
|
||||
nano::root nano::send_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
|
@ -899,7 +899,7 @@ std::optional<nano::block_hash> nano::open_block::source_field () const
|
|||
return hashables.source;
|
||||
}
|
||||
|
||||
nano::root const & nano::open_block::root () const
|
||||
nano::root nano::open_block::root () const
|
||||
{
|
||||
return hashables.account;
|
||||
}
|
||||
|
|
@ -1165,7 +1165,7 @@ bool nano::change_block::valid_predecessor (nano::block const & block_a) const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::root const & nano::change_block::root () const
|
||||
nano::root nano::change_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
|
@ -1482,7 +1482,7 @@ bool nano::state_block::valid_predecessor (nano::block const & block_a) const
|
|||
return true;
|
||||
}
|
||||
|
||||
nano::root const & nano::state_block::root () const
|
||||
nano::root nano::state_block::root () const
|
||||
{
|
||||
if (!hashables.previous.is_zero ())
|
||||
{
|
||||
|
|
@ -1836,7 +1836,7 @@ std::optional<nano::block_hash> nano::receive_block::source_field () const
|
|||
return hashables.source;
|
||||
}
|
||||
|
||||
nano::root const & nano::receive_block::root () const
|
||||
nano::root nano::receive_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
virtual uint64_t block_work () const = 0;
|
||||
virtual void block_work_set (uint64_t) = 0;
|
||||
// Previous block or account number for open blocks
|
||||
virtual nano::root const & root () const = 0;
|
||||
virtual nano::root root () const = 0;
|
||||
// Qualified root value based on previous() and root()
|
||||
virtual nano::qualified_root qualified_root () const;
|
||||
virtual void serialize (nano::stream &) const = 0;
|
||||
|
|
@ -123,7 +123,7 @@ public:
|
|||
virtual ~send_block () = default;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::root const & root () const override;
|
||||
nano::root root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
|
@ -177,7 +177,7 @@ public:
|
|||
virtual ~receive_block () = default;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::root const & root () const override;
|
||||
nano::root root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
|
@ -232,7 +232,7 @@ public:
|
|||
virtual ~open_block () = default;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::root const & root () const override;
|
||||
nano::root root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
|
@ -287,7 +287,7 @@ public:
|
|||
virtual ~change_block () = default;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::root const & root () const override;
|
||||
nano::root root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
|
@ -353,7 +353,7 @@ public:
|
|||
virtual ~state_block () = default;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::root const & root () const override;
|
||||
nano::root root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
|
|
|||
|
|
@ -735,6 +735,13 @@ std::ostream & nano::operator<< (std::ostream & os, const uint512_union & val)
|
|||
return os;
|
||||
}
|
||||
|
||||
std::ostream & nano::operator<< (std::ostream & os, const hash_or_account & val)
|
||||
{
|
||||
// TODO: Replace with streaming implementation
|
||||
os << val.to_string ();
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4146) // warning C4146: unary minus operator applied to unsigned type, result still unsigned
|
||||
|
|
|
|||
|
|
@ -189,10 +189,6 @@ public: // Keep operators inlined
|
|||
};
|
||||
static_assert (std::is_nothrow_move_constructible<uint256_union>::value, "uint256_union should be noexcept MoveConstructible");
|
||||
|
||||
class link;
|
||||
class root;
|
||||
class hash_or_account;
|
||||
|
||||
// All keys and hashes are 256 bit.
|
||||
class block_hash final : public uint256_union
|
||||
{
|
||||
|
|
@ -212,18 +208,6 @@ public: // Keep operators inlined
|
|||
{
|
||||
return number ();
|
||||
}
|
||||
operator nano::link () const
|
||||
{
|
||||
return nano::link{ *this };
|
||||
}
|
||||
operator nano::root () const
|
||||
{
|
||||
return nano::root{ *this };
|
||||
}
|
||||
operator nano::hash_or_account () const
|
||||
{
|
||||
return nano::hash_or_account{ *this };
|
||||
}
|
||||
};
|
||||
|
||||
class public_key final : public uint256_union
|
||||
|
|
@ -260,18 +244,6 @@ public: // Keep operators inlined
|
|||
{
|
||||
return number ();
|
||||
}
|
||||
operator nano::link () const
|
||||
{
|
||||
return nano::link{ *this };
|
||||
}
|
||||
operator nano::root () const
|
||||
{
|
||||
return nano::root{ *this };
|
||||
}
|
||||
operator nano::hash_or_account () const
|
||||
{
|
||||
return nano::hash_or_account{ *this };
|
||||
}
|
||||
};
|
||||
|
||||
class wallet_id : public uint256_union
|
||||
|
|
@ -289,7 +261,7 @@ public:
|
|||
account{} {};
|
||||
hash_or_account (uint64_t value) :
|
||||
raw{ value } {};
|
||||
explicit hash_or_account (uint256_union const & value) :
|
||||
hash_or_account (uint256_union const & value) :
|
||||
raw{ value } {};
|
||||
|
||||
void clear ()
|
||||
|
|
@ -325,11 +297,11 @@ public: // Keep operators inlined
|
|||
{
|
||||
return *this <=> other == 0;
|
||||
}
|
||||
operator nano::uint256_t () const
|
||||
explicit operator nano::uint256_t () const
|
||||
{
|
||||
return raw.number ();
|
||||
}
|
||||
operator nano::uint256_union () const
|
||||
explicit operator nano::uint256_union () const
|
||||
{
|
||||
return raw;
|
||||
}
|
||||
|
|
@ -399,13 +371,13 @@ class uint512_union
|
|||
{
|
||||
public:
|
||||
uint512_union () = default;
|
||||
uint512_union (nano::uint256_union const & upper, nano::uint256_union const & lower) :
|
||||
uint256s{ upper, lower } {};
|
||||
uint512_union (nano::uint512_t const & value)
|
||||
{
|
||||
bytes.fill (0);
|
||||
boost::multiprecision::export_bits (value, bytes.rbegin (), 8, false);
|
||||
}
|
||||
uint512_union (nano::uint256_union const & upper, nano::uint256_union const & lower) :
|
||||
uint256s{ upper, lower } {};
|
||||
|
||||
nano::uint512_union & operator^= (nano::uint512_union const & other)
|
||||
{
|
||||
|
|
@ -473,7 +445,11 @@ public:
|
|||
class qualified_root : public uint512_union
|
||||
{
|
||||
public:
|
||||
using uint512_union::uint512_union;
|
||||
qualified_root () = default;
|
||||
qualified_root (nano::root const & root, nano::block_hash const & previous) :
|
||||
uint512_union{ root.as_union (), previous.as_union () } {};
|
||||
qualified_root (nano::uint512_t const & value) :
|
||||
uint512_union{ value } {};
|
||||
|
||||
nano::root root () const
|
||||
{
|
||||
|
|
@ -501,6 +477,7 @@ bool from_string_hex (std::string const &, uint64_t &);
|
|||
std::ostream & operator<< (std::ostream &, const uint128_union &);
|
||||
std::ostream & operator<< (std::ostream &, const uint256_union &);
|
||||
std::ostream & operator<< (std::ostream &, const uint512_union &);
|
||||
std::ostream & operator<< (std::ostream &, const hash_or_account &);
|
||||
|
||||
/**
|
||||
* Convert a double to string in fixed format
|
||||
|
|
@ -643,6 +620,11 @@ struct fmt::formatter<nano::uint512_union> : fmt::ostream_formatter
|
|||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<nano::hash_or_account> : fmt::ostream_formatter
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<nano::block_hash> : fmt::formatter<nano::uint256_union>
|
||||
{
|
||||
|
|
@ -656,4 +638,4 @@ struct fmt::formatter<nano::public_key> : fmt::formatter<nano::uint256_union>
|
|||
template <>
|
||||
struct fmt::formatter<nano::qualified_root> : fmt::formatter<nano::uint512_union>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ void nano::pulls_cache::add (nano::pull_info const & pull_a)
|
|||
cache.erase (cache.begin ());
|
||||
}
|
||||
debug_assert (cache.size () <= cache_size_max);
|
||||
nano::uint512_union head_512 (pull_a.account_or_head, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.account_or_head.as_union (), pull_a.head_original);
|
||||
auto existing (cache.get<account_head_tag> ().find (head_512));
|
||||
if (existing == cache.get<account_head_tag> ().end ())
|
||||
{
|
||||
|
|
@ -336,7 +336,7 @@ void nano::pulls_cache::add (nano::pull_info const & pull_a)
|
|||
void nano::pulls_cache::update_pull (nano::pull_info & pull_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ pulls_cache_mutex };
|
||||
nano::uint512_union head_512 (pull_a.account_or_head, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.account_or_head.as_union (), pull_a.head_original);
|
||||
auto existing (cache.get<account_head_tag> ().find (head_512));
|
||||
if (existing != cache.get<account_head_tag> ().end ())
|
||||
{
|
||||
|
|
@ -347,7 +347,7 @@ void nano::pulls_cache::update_pull (nano::pull_info & pull_a)
|
|||
void nano::pulls_cache::remove (nano::pull_info const & pull_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ pulls_cache_mutex };
|
||||
nano::uint512_union head_512 (pull_a.account_or_head, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.account_or_head.as_union (), pull_a.head_original);
|
||||
cache.get<account_head_tag> ().erase (head_512);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue