mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
kernel: add btck_block_tree_entry_equals
BlockTreeEntry objects are often compared. By exposing an equality function, clients don't have to implement more expensive comparisons based on height and block hash.
This commit is contained in:
@@ -1104,6 +1104,11 @@ const btck_BlockHash* btck_block_tree_entry_get_block_hash(const btck_BlockTreeE
|
||||
return btck_BlockHash::ref(btck_BlockTreeEntry::get(entry).phashBlock);
|
||||
}
|
||||
|
||||
int btck_block_tree_entry_equals(const btck_BlockTreeEntry* entry1, const btck_BlockTreeEntry* entry2)
|
||||
{
|
||||
return &btck_BlockTreeEntry::get(entry1) == &btck_BlockTreeEntry::get(entry2);
|
||||
}
|
||||
|
||||
btck_BlockHash* btck_block_hash_create(const unsigned char block_hash[32])
|
||||
{
|
||||
return btck_BlockHash::create(std::span<const unsigned char>{block_hash, 32});
|
||||
|
||||
@@ -922,6 +922,17 @@ BITCOINKERNEL_API int32_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_tree_entry
|
||||
BITCOINKERNEL_API const btck_BlockHash* BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_tree_entry_get_block_hash(
|
||||
const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* @brief Check if two block tree entries are equal. Two block tree entries are equal when they
|
||||
* point to the same block.
|
||||
*
|
||||
* @param[in] entry1 Non-null.
|
||||
* @param[in] entry2 Non-null.
|
||||
* @return 1 if the block tree entries are equal, 0 otherwise.
|
||||
*/
|
||||
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_tree_entry_equals(
|
||||
const btck_BlockTreeEntry* entry1, const btck_BlockTreeEntry* entry2) BITCOINKERNEL_ARG_NONNULL(1, 2);
|
||||
|
||||
///@}
|
||||
|
||||
/** @name ChainstateManagerOptions
|
||||
|
||||
@@ -786,6 +786,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const BlockTreeEntry& other) const
|
||||
{
|
||||
return btck_block_tree_entry_equals(get(), other.get()) != 0;
|
||||
}
|
||||
|
||||
std::optional<BlockTreeEntry> GetPrevious() const
|
||||
{
|
||||
auto entry{btck_block_tree_entry_get_previous(get())};
|
||||
|
||||
Reference in New Issue
Block a user