Add "ledger" command to get ledger information. Make the command

work with no parameters. Fix a bug where the ledger's account/txn
hashes didn't get properly synchronized to the SHA maps. Add function
to get ledger as json object.
This commit is contained in:
JoelKatz
2012-01-23 13:31:39 -08:00
parent 017a606f3b
commit 6112a443cf
4 changed files with 53 additions and 2 deletions

View File

@@ -44,6 +44,11 @@ Ledger::Ledger(Ledger &prevLedger, uint64 ts) : mTimeStamp(ts),
void Ledger::updateHash()
{
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
else mTransHash=0;
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
else mAccountHash=0;
Serializer s(116);
addRaw(s);
mHash=s.getSHA512Half();
@@ -265,7 +270,8 @@ Ledger::TransResult Ledger::hasTransaction(Transaction::pointer trans)
Ledger::pointer Ledger::closeLedger(uint64 timeStamp)
{ // close this ledger, return a pointer to the next ledger
// CAUTION: New ledger needs its SHAMap's connected to storage
// CAUTION: New ledger needs its SHAMap's connected to storage
updateHash();
setClosed();
return Ledger::pointer(new Ledger(*this, timeStamp));
}
@@ -408,3 +414,22 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash)
sql.append("';");
return getSQL(sql);
}
void Ledger::addJson(Json::Value& ret)
{
Json::Value ledger(Json::objectValue);
boost::recursive_mutex::scoped_lock sl(mLock);
ledger["ParentHash"]=mParentHash.GetHex();
if(mClosed)
{
ledger["Hash"]=mHash.GetHex();
ledger["TransactionHash"]=mTransHash.GetHex();
ledger["AccountHash"]=mAccountHash.GetHex();
ledger["Closed"]=true;
ledger["Accepted"]=mAccepted;
}
else ledger["Closed"]=false;
ret[boost::lexical_cast<std::string>(mLedgerSeq)]=ledger;
}