diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-12-20 17:44:47 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-12-20 17:44:47 +0200 |
commit | f5176cb6e86e578fa866463638d56b3c6b145e4d (patch) | |
tree | be50063b61b1989ae140528959d7441ef4465050 /src/cryptonote_core/blockchain.cpp | |
parent | Merge pull request #1466 (diff) | |
parent | rpc: new function and RPC to get alternative chain info (diff) | |
download | monero-f5176cb6e86e578fa866463638d56b3c6b145e4d.tar.xz |
Merge pull request #1467
55fa0479 rpc: new function and RPC to get alternative chain info (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index ba369afbd..a23d51126 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3878,6 +3878,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; |