mirror of
https://github.com/monero-project/monero.git
synced 2025-07-23 00:40:36 -04:00
rpc: new function and RPC to get alternative chain info
This commit is contained in:
parent
29735c8f8f
commit
55fa0479a0
10 changed files with 147 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -844,6 +844,13 @@ namespace cryptonote
|
|||
void block_longhash_worker(const uint64_t height, const std::vector<block> &blocks,
|
||||
std::unordered_map<crypto::hash, crypto::hash> &map) const;
|
||||
|
||||
/**
|
||||
* @brief returns a set of known alternate chains
|
||||
*
|
||||
* @return a list of chains
|
||||
*/
|
||||
std::list<std::pair<block_extended_info,uint64_t>> get_alternative_chains() const;
|
||||
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue