mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
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:
25
Ledger.cpp
25
Ledger.cpp
@@ -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();
|
||||
@@ -266,6 +271,7 @@ 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
|
||||
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;
|
||||
}
|
||||
|
||||
4
Ledger.h
4
Ledger.h
@@ -7,6 +7,8 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
|
||||
#include "json/value.h"
|
||||
|
||||
#include "Transaction.h"
|
||||
#include "types.h"
|
||||
#include "BitcoinUtil.h"
|
||||
@@ -104,6 +106,8 @@ public:
|
||||
bool isCompatible(boost::shared_ptr<Ledger> other);
|
||||
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);
|
||||
|
||||
void addJson(Json::Value&);
|
||||
|
||||
static bool unitTest();
|
||||
};
|
||||
|
||||
|
||||
@@ -430,6 +430,25 @@ Json::Value RPCServer::doTx(Json::Value& params)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
theApp->getUNL().addNode(hanko,pubKey);
|
||||
return "adding node";
|
||||
}else return "invalid params";
|
||||
}
|
||||
else return "invalid params";
|
||||
}
|
||||
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=="connect") return doConnect(params);
|
||||
if(command=="tx") return doTx(params);
|
||||
if(command=="ledger") return doLedger(params);
|
||||
|
||||
return "unknown command";
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
||||
Json::Value doSendTo(Json::Value& params);
|
||||
Json::Value doConnect(Json::Value& params);
|
||||
Json::Value doTx(Json::Value& params);
|
||||
Json::Value doLedger(Json::Value& params);
|
||||
|
||||
// parses a string account name into a uint160
|
||||
// can be local or remote
|
||||
|
||||
Reference in New Issue
Block a user