Add NetworkOPs::isValidate functions to check if a ledger is fully validated.

This commit is contained in:
JoelKatz
2013-02-15 19:01:48 -08:00
parent fd009a750a
commit 862dbd7234
4 changed files with 27 additions and 3 deletions

View File

@@ -93,6 +93,14 @@ public:
Ledger::pointer closeLedger(bool recoverHeldTransactions);
uint256 getHashBySeq(uint32 index)
{
uint256 hash = mLedgerHistory.getLedgerHash(index);
if (hash.isNonZero())
return hash;
return Ledger::getHashByIndex(index);
}
Ledger::pointer getLedgerBySeq(uint32 index)
{
if (mCurrentLedger && (mCurrentLedger->getLedgerSeq() == index))

View File

@@ -119,6 +119,19 @@ bool NetworkOPs::haveLedger(uint32 seq)
return mLedgerMaster->haveLedger(seq);
}
bool NetworkOPs::isValidated(uint32 seq, const uint256& hash)
{
if (!isValidated(seq))
return false;
return mLedgerMaster->getHashBySeq(seq) == hash;
}
bool NetworkOPs::isValidated(uint32 seq)
{ // use when ledger was retrieved by seq
return haveLedger(seq) && (seq <= mLedgerMaster->getValidatedLedger()->getLedgerSeq());
}
bool NetworkOPs::addWantedHash(const uint256& h)
{
boost::recursive_mutex::scoped_lock sl(mWantedHashLock);

View File

@@ -156,6 +156,9 @@ public:
// Do we have this inclusive range of ledgers in our database
bool haveLedgerRange(uint32 from, uint32 to);
bool haveLedger(uint32 seq);
bool isValidated(uint32 seq);
bool isValidated(uint32 seq, const uint256& hash);
bool isValidated(Ledger::ref l) { return isValidated(l->getLedgerSeq(), l->getHash()); }
SerializedValidation::ref getLastValidation() { return mLastValidation; }
void setLastValidation(SerializedValidation::ref v) { mLastValidation = v; }

View File

@@ -1447,10 +1447,10 @@ Json::Value RPCHandler::doTx(Json::Value jvRequest)
{
TransactionMetaSet::pointer set;
if (lgr->getTransactionMeta(txid, set))
{
ret["meta"] = set->getJson(0);
ret["validated"] =
theApp->getOPs().haveLedger(lgr->getLedgerSeq()) &&
(lgr->getLedgerSeq() <= theApp->getLedgerMaster().getValidatedLedger()->getLedgerSeq());
ret["validated"] = theApp->getOPs().isValidated(lgr);
}
}
}