mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Tidy up and move sources
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/Quality.h>
|
||||
#include <ripple/protocol/STArray.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -434,6 +436,78 @@ getMajorityAmendments (ReadView const& view)
|
||||
return majorities;
|
||||
}
|
||||
|
||||
boost::optional<uint256>
|
||||
hashOfSeq (ReadView const& ledger, LedgerIndex seq,
|
||||
beast::Journal journal)
|
||||
{
|
||||
// Easy cases...
|
||||
if (seq > ledger.seq())
|
||||
{
|
||||
if (journal.warning) journal.warning <<
|
||||
"Can't get seq " << seq <<
|
||||
" from " << ledger.seq() << " future";
|
||||
return boost::none;
|
||||
}
|
||||
if (seq == ledger.seq())
|
||||
return ledger.info().hash;
|
||||
if (seq == (ledger.seq() - 1))
|
||||
return ledger.info().parentHash;
|
||||
|
||||
// Within 256...
|
||||
{
|
||||
int diff = ledger.seq() - seq;
|
||||
if (diff <= 256)
|
||||
{
|
||||
auto const hashIndex =
|
||||
ledger.read(keylet::skip());
|
||||
if (hashIndex)
|
||||
{
|
||||
assert (hashIndex->getFieldU32 (sfLastLedgerSequence) ==
|
||||
(ledger.seq() - 1));
|
||||
STVector256 vec = hashIndex->getFieldV256 (sfHashes);
|
||||
if (vec.size () >= diff)
|
||||
return vec[vec.size () - diff];
|
||||
if (journal.warning) journal.warning <<
|
||||
"Ledger " << ledger.seq() <<
|
||||
" missing hash for " << seq <<
|
||||
" (" << vec.size () << "," << diff << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (journal.warning) journal.warning <<
|
||||
"Ledger " << ledger.seq() <<
|
||||
":" << ledger.info().hash << " missing normal list";
|
||||
}
|
||||
}
|
||||
if ((seq & 0xff) != 0)
|
||||
{
|
||||
if (journal.debug) journal.debug <<
|
||||
"Can't get seq " << seq <<
|
||||
" from " << ledger.seq() << " past";
|
||||
return boost::none;
|
||||
}
|
||||
}
|
||||
|
||||
// in skiplist
|
||||
auto const hashIndex =
|
||||
ledger.read(keylet::skip(seq));
|
||||
if (hashIndex)
|
||||
{
|
||||
auto const lastSeq =
|
||||
hashIndex->getFieldU32 (sfLastLedgerSequence);
|
||||
assert (lastSeq >= seq);
|
||||
assert ((lastSeq & 0xff) == 0);
|
||||
auto const diff = (lastSeq - seq) >> 8;
|
||||
STVector256 vec = hashIndex->getFieldV256 (sfHashes);
|
||||
if (vec.size () > diff)
|
||||
return vec[vec.size () - diff - 1];
|
||||
}
|
||||
if (journal.warning) journal.warning <<
|
||||
"Can't get seq " << seq <<
|
||||
" from " << ledger.seq() << " error";
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Modifiers
|
||||
|
||||
Reference in New Issue
Block a user