mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Function to retrieve previous ledger hashes from the ledger.
This commit is contained in:
@@ -647,14 +647,6 @@ Json::Value Ledger::getJson(int options)
|
||||
}
|
||||
ledger["accountState"] = state;
|
||||
}
|
||||
if (mAccountStateMap && ((options & LEDGER_JSON_HISTORY) != 0))
|
||||
{
|
||||
SLE::pointer hashIndex = getSLE(getLedgerHashIndex());
|
||||
if (hashIndex)
|
||||
ledger["previousHashes"] = hashIndex->getJson(0);
|
||||
else
|
||||
ledger["previousHashes"] = "missing";
|
||||
}
|
||||
ledger["seqNum"] = boost::lexical_cast<std::string>(mLedgerSeq);
|
||||
return ledger;
|
||||
}
|
||||
@@ -962,6 +954,40 @@ int Ledger::getLedgerHashOffset(uint32 desiredLedgerIndex, uint32 currentLedgerI
|
||||
return currentLedgerIndex - desiredLedgerIndex - 1;
|
||||
}
|
||||
|
||||
uint256 Ledger::getLedgerHash(uint32 ledgerIndex)
|
||||
{ // return the hash of the specified ledger, 0 if not available
|
||||
|
||||
// easy cases
|
||||
if (ledgerIndex > mLedgerSeq)
|
||||
return uint256();
|
||||
if (ledgerIndex == mLedgerSeq)
|
||||
return getHash();
|
||||
if (ledgerIndex == (mLedgerSeq - 1))
|
||||
return mParentHash;
|
||||
|
||||
// within 255
|
||||
int offset = getLedgerHashOffset(ledgerIndex, mLedgerSeq);
|
||||
if (offset != -1)
|
||||
{
|
||||
SLE::pointer hashIndex = getSLE(getLedgerHashIndex());
|
||||
if (hashIndex)
|
||||
return hashIndex->getFieldV256(sfHashes).peekValue().at(offset);
|
||||
else
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if ((ledgerIndex & 0xff) != 0)
|
||||
return uint256();
|
||||
|
||||
SLE::pointer hashIndex = getSLE(getLedgerHashIndex(ledgerIndex));
|
||||
if (hashIndex)
|
||||
return hashIndex->getFieldV256(sfHashes).peekValue().at(getLedgerHashOffset(ledgerIndex, mLedgerSeq));
|
||||
else
|
||||
assert(false);
|
||||
|
||||
return uint256();
|
||||
}
|
||||
|
||||
uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
|
||||
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user