From 55fa0479a0db599d81500e57e355124f1fb9c05e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 17 Dec 2016 11:25:15 +0000 Subject: rpc: new function and RPC to get alternative chain info --- src/cryptonote_core/blockchain.cpp | 32 ++++++++++++++++++++++++++++++++ src/cryptonote_core/blockchain.h | 7 +++++++ 2 files changed, 39 insertions(+) (limited to 'src/cryptonote_core') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 70b2ccc79..702d98944 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3880,6 +3880,38 @@ std::map> Blockchain:: get_ou return m_db->get_output_histogram(amounts, unlocked, recent_cutoff); } +std::list> Blockchain::get_alternative_chains() const +{ + std::list> chains; + + for (const auto &i: m_alternative_chains) + { + const crypto::hash &top = i.first; + bool found = false; + for (const auto &j: m_alternative_chains) + { + if (j.second.bl.prev_id == top) + { + found = true; + break; + } + } + if (!found) + { + uint64_t length = 1; + auto h = i.second.bl.prev_id; + blocks_ext_by_hash::const_iterator prev; + while ((prev = m_alternative_chains.find(h)) != m_alternative_chains.end()) + { + h = prev->second.bl.prev_id; + ++length; + } + chains.push_back(std::make_pair(i.second, length)); + } + } + return chains; +} + void Blockchain::cancel() { m_cancel = true; diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 9afc22657..245dc6e73 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -844,6 +844,13 @@ namespace cryptonote void block_longhash_worker(const uint64_t height, const std::vector &blocks, std::unordered_map &map) const; + /** + * @brief returns a set of known alternate chains + * + * @return a list of chains + */ + std::list> get_alternative_chains() const; + void cancel(); private: -- cgit v1.2.3