aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-12-17 11:25:15 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-12-17 11:28:49 +0000
commit55fa0479a0db599d81500e57e355124f1fb9c05e (patch)
treed394bf9b6ad9f8d8320cc3a34e860c7af5bc671c /src/cryptonote_core/blockchain.cpp
parentMerge pull request #1459 (diff)
downloadmonero-55fa0479a0db599d81500e57e355124f1fb9c05e.tar.xz
rpc: new function and RPC to get alternative chain info
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp32
1 files changed, 32 insertions, 0 deletions
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<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> Blockchain:: get_ou
return m_db->get_output_histogram(amounts, unlocked, recent_cutoff);
}
+std::list<std::pair<Blockchain::block_extended_info,uint64_t>> Blockchain::get_alternative_chains() const
+{
+ std::list<std::pair<Blockchain::block_extended_info,uint64_t>> 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;