mirror of
https://github.com/monero-project/monero.git
synced 2025-07-23 15:20:50 -04:00
Add functions to iterate through blocks, txes, outputs, key images
This commit is contained in:
parent
0a5a5e8597
commit
5f397e4412
9 changed files with 362 additions and 0 deletions
|
@ -3188,3 +3188,23 @@ bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, ui
|
|||
{
|
||||
return m_hardfork->get_voting_info(version, window, votes, threshold, voting);
|
||||
}
|
||||
|
||||
bool Blockchain::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const
|
||||
{
|
||||
return m_db->for_all_key_images(f);
|
||||
}
|
||||
|
||||
bool Blockchain::for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)> f) const
|
||||
{
|
||||
return m_db->for_all_blocks(f);
|
||||
}
|
||||
|
||||
bool Blockchain::for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)> f) const
|
||||
{
|
||||
return m_db->for_all_transactions(f);
|
||||
}
|
||||
|
||||
bool Blockchain::for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const
|
||||
{
|
||||
return m_db->for_all_outputs(f);;
|
||||
}
|
||||
|
|
|
@ -165,6 +165,11 @@ namespace cryptonote
|
|||
uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); }
|
||||
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const;
|
||||
|
||||
bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
|
||||
bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)>) const;
|
||||
bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const;
|
||||
bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const;
|
||||
|
||||
BlockchainDB& get_db()
|
||||
{
|
||||
return *m_db;
|
||||
|
|
|
@ -1890,3 +1890,41 @@ void blockchain_storage::set_enforce_dns_checkpoints(bool enforce_checkpoints)
|
|||
{
|
||||
m_enforce_dns_checkpoints = enforce_checkpoints;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const
|
||||
{
|
||||
for (key_images_container::const_iterator i = m_spent_keys.begin(); i != m_spent_keys.end(); ++i) {
|
||||
if (!f(*i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::for_all_blocks(std::function<bool(uint64_t, const block&)> f) const
|
||||
{
|
||||
for (blocks_container::const_iterator i = m_blocks.begin(); i != m_blocks.end(); ++i) {
|
||||
if (!f(i->height, i->bl))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::for_all_transactions(std::function<bool(const transaction&)> f) const
|
||||
{
|
||||
for (transactions_container::const_iterator i = m_transactions.begin(); i != m_transactions.end(); ++i) {
|
||||
if (!f(i->second.tx))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::for_all_outputs(std::function<bool(uint64_t, const crypto::hash&, size_t)> f) const
|
||||
{
|
||||
for (outputs_container::const_iterator i = m_outputs.begin(); i != m_outputs.end(); ++i) {
|
||||
for (size_t n = 0; n < i->second.size(); ++n) {
|
||||
if (!f(i->first, i->second[n].first, i->second[n].second))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -185,6 +185,11 @@ namespace cryptonote
|
|||
difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return m_blocks[height].cumulative_difficulty; }
|
||||
uint64_t get_block_coins_generated(uint64_t height) const { return m_blocks[height].already_generated_coins; }
|
||||
|
||||
bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
|
||||
bool for_all_blocks(std::function<bool(uint64_t height, const block&)>) const;
|
||||
bool for_all_transactions(std::function<bool(const transaction&)>) const;
|
||||
bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const;
|
||||
|
||||
// use for testing only
|
||||
bool debug_pop_block_from_blockchain() { return pop_block_from_blockchain(); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue