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() void Ledger::updateHash()
{ {
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
else mTransHash=0;
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
else mAccountHash=0;
Serializer s(116); Serializer s(116);
addRaw(s); addRaw(s);
mHash=s.getSHA512Half(); mHash=s.getSHA512Half();
@@ -265,7 +270,8 @@ Ledger::TransResult Ledger::hasTransaction(Transaction::pointer trans)
Ledger::pointer Ledger::closeLedger(uint64 timeStamp) Ledger::pointer Ledger::closeLedger(uint64 timeStamp)
{ // close this ledger, return a pointer to the next ledger { // 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(); setClosed();
return Ledger::pointer(new Ledger(*this, timeStamp)); return Ledger::pointer(new Ledger(*this, timeStamp));
} }
@@ -408,3 +414,22 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash)
sql.append("';"); sql.append("';");
return getSQL(sql); 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;
}

View File

@@ -7,6 +7,8 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include "json/value.h"
#include "Transaction.h" #include "Transaction.h"
#include "types.h" #include "types.h"
#include "BitcoinUtil.h" #include "BitcoinUtil.h"
@@ -104,6 +106,8 @@ public:
bool isCompatible(boost::shared_ptr<Ledger> other); bool isCompatible(boost::shared_ptr<Ledger> other);
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko); bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);
void addJson(Json::Value&);
static bool unitTest(); static bool unitTest();
}; };

View File

@@ -430,6 +430,25 @@ Json::Value RPCServer::doTx(Json::Value& params)
return "not implemented"; return "not implemented";
} }
Json::Value RPCServer::doLedger(Json::Value& params)
{
// ledger
// ledger <seq>
// ledger <account>
int paramCount=getParamCount(params);
if(paramCount==0);
{
Json::Value ret(Json::objectValue);
theApp->getMasterLedger().getCurrentLedger()->addJson(ret);
theApp->getMasterLedger().getClosingLedger()->addJson(ret);
return ret;
}
return "not implemented";
}
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params) Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
{ {
std::cerr << "RPC:" << command << std::endl; std::cerr << "RPC:" << command << std::endl;
@@ -447,7 +466,8 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
humanToPK(params[1u].asString(),pubKey); humanToPK(params[1u].asString(),pubKey);
theApp->getUNL().addNode(hanko,pubKey); theApp->getUNL().addNode(hanko,pubKey);
return "adding node"; return "adding node";
}else return "invalid params"; }
else return "invalid params";
} }
if(command=="getUNL") if(command=="getUNL")
{ {
@@ -464,6 +484,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
if(command=="sendto") return doSendTo(params); if(command=="sendto") return doSendTo(params);
if(command=="connect") return doConnect(params); if(command=="connect") return doConnect(params);
if(command=="tx") return doTx(params); if(command=="tx") return doTx(params);
if(command=="ledger") return doLedger(params);
return "unknown command"; return "unknown command";
} }

View File

@@ -42,6 +42,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
Json::Value doSendTo(Json::Value& params); Json::Value doSendTo(Json::Value& params);
Json::Value doConnect(Json::Value& params); Json::Value doConnect(Json::Value& params);
Json::Value doTx(Json::Value& params); Json::Value doTx(Json::Value& params);
Json::Value doLedger(Json::Value& params);
// parses a string account name into a uint160 // parses a string account name into a uint160
// can be local or remote // can be local or remote