aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp20
-rw-r--r--src/cryptonote_core/blockchain.h5
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp38
-rw-r--r--src/cryptonote_core/blockchain_storage.h5
4 files changed, 68 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index c38b58841..08587491e 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -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);;
+}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 3a663a342..21bbfb447 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -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;
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 4a4d348ba..16aaf7079 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -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;
+}
diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h
index 2a4cfcd49..4a4fc14c2 100644
--- a/src/cryptonote_core/blockchain_storage.h
+++ b/src/cryptonote_core/blockchain_storage.h
@@ -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(); }