-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ledger account iterator for the unconfirmed ledger set.
- Loading branch information
Showing
17 changed files
with
189 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <nano/secure/account_iterator_impl.hpp> | ||
#include <nano/secure/ledger_set_any.hpp> | ||
|
||
template class nano::account_iterator<nano::ledger_set_any>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
#include <nano/lib/numbers.hpp> | ||
#include <nano/secure/account_info.hpp> | ||
|
||
#include <optional> | ||
#include <utility> | ||
|
||
namespace nano::secure | ||
{ | ||
class transaction; | ||
} | ||
|
||
namespace nano | ||
{ | ||
// This class iterates account entries | ||
template <typename Set> | ||
class account_iterator | ||
{ | ||
public: | ||
// Creates an end () iterator | ||
// 'transaction' and 'set' are nullptr so all end () iterators compare equal | ||
account_iterator (); | ||
account_iterator (secure::transaction const & transaction, Set const & set, std::optional<std::pair<nano::account, nano::account_info>> const & item); | ||
|
||
// Compares if these iterators hold the same 'item'. | ||
// Undefined behavior if this and other don't hold the same 'set' and 'transaction' | ||
bool operator== (account_iterator const & other) const; | ||
|
||
public: // Dereferencing, undefined behavior when called on an end () iterator | ||
// Advances the iterator to the next greater nano::account | ||
// If there are no more accounts, convert this to an end () iterator | ||
account_iterator & operator++ (); | ||
std::pair<nano::account, nano::account_info> const & operator* () const; | ||
std::pair<nano::account, nano::account_info> const * operator->() const; | ||
|
||
private: | ||
secure::transaction const * transaction; | ||
Set const * set{ nullptr }; | ||
// Current item at the position of the iterator | ||
// std::nullopt if an end () iterator | ||
std::optional<std::pair<nano::account, nano::account_info>> item; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <nano/secure/account_info.hpp> | ||
#include <nano/secure/account_iterator.hpp> | ||
|
||
template <typename Set> | ||
nano::account_iterator<Set>::account_iterator () | ||
{ | ||
} | ||
|
||
template <typename Set> | ||
nano::account_iterator<Set>::account_iterator (secure::transaction const & transaction, Set const & set, std::optional<std::pair<nano::account, nano::account_info>> const & item) : | ||
transaction{ &transaction }, | ||
set{ &set }, | ||
item{ item } | ||
{ | ||
} | ||
|
||
template <typename Set> | ||
bool nano::account_iterator<Set>::operator== (account_iterator const & other) const | ||
{ | ||
debug_assert (set == nullptr || other.set == nullptr || set == other.set); | ||
return item == other.item; | ||
} | ||
|
||
// Iteration is performed by calling set->account_lower_bound (tx, next) where next is one higher than the current iterator | ||
template <typename Set> | ||
auto nano::account_iterator<Set>::operator++ () -> account_iterator<Set> & | ||
{ | ||
auto next = item.value ().first.number () + 1; | ||
if (next != 0) | ||
{ | ||
*this = set->account_lower_bound (*transaction, next); | ||
} | ||
else | ||
{ | ||
// Convert to and end iterator if there are no more items | ||
*this = account_iterator<Set>{}; | ||
} | ||
return *this; | ||
} | ||
|
||
template <typename Set> | ||
std::pair<nano::account, nano::account_info> const & nano::account_iterator<Set>::operator* () const | ||
{ | ||
return item.value (); | ||
} | ||
|
||
template <typename Set> | ||
std::pair<nano::account, nano::account_info> const * nano::account_iterator<Set>::operator->() const | ||
{ | ||
return &item.value (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.