Rework RPC ledger.

This commit is contained in:
Arthur Britto
2013-03-10 15:18:35 -07:00
parent 667b8ee1e7
commit 1479590af1
4 changed files with 40 additions and 20 deletions

View File

@@ -861,9 +861,11 @@ Json::Value Ledger::getJson(int options)
}
}
else
{
ledger["closed"] = false;
}
if (mTransactionMap && (bFull || ((options & LEDGER_JSON_DUMP_TXRP) != 0)))
if (mTransactionMap && (bFull || isSetBit(options, LEDGER_JSON_DUMP_TXRP)))
{
Json::Value txns(Json::arrayValue);
SHAMapTreeNode::TNType type;
@@ -871,7 +873,7 @@ Json::Value Ledger::getJson(int options)
for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem(type); !!item;
item = mTransactionMap->peekNextItem(item->getTag(), type))
{
if (bFull)
if (bFull || isSetBit(options, LEDGER_JSON_EXPAND))
{
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
{
@@ -904,14 +906,14 @@ Json::Value Ledger::getJson(int options)
ledger["transactions"] = txns;
}
if (mAccountStateMap && (bFull || ((options & LEDGER_JSON_DUMP_STATE) != 0)))
if (mAccountStateMap && (bFull || isSetBit(options, LEDGER_JSON_DUMP_STATE)))
{
Json::Value state(Json::arrayValue);
ScopedLock l(mAccountStateMap->Lock());
for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item;
item = mAccountStateMap->peekNextItem(item->getTag()))
{
if (bFull)
if (bFull || isSetBit(options, LEDGER_JSON_EXPAND))
{
SerializerIterator sit(item->peekSerializer());
SerializedLedgerEntry sle(sit, item->getTag());

View File

@@ -38,7 +38,8 @@ enum LedgerStateParms
#define LEDGER_JSON_DUMP_TXRP 0x10000000
#define LEDGER_JSON_DUMP_STATE 0x20000000
#define LEDGER_JSON_FULL 0x40000000
#define LEDGER_JSON_EXPAND 0x40000000
#define LEDGER_JSON_FULL 0x80000000
DEFINE_INSTANCE(Ledger);

View File

@@ -1636,12 +1636,19 @@ Json::Value RPCHandler::doLedger(Json::Value jvRequest, int& cost)
if (!lpLedger)
return jvResult;
bool full = jvRequest.isMember("full") && jvRequest["full"].asBool();
bool bFull = jvRequest.isMember("full") && jvRequest["full"].asBool();
bool bTransactions = jvRequest.isMember("transactions") && jvRequest["transactions"].asBool();
bool bAccounts = jvRequest.isMember("accounts") && jvRequest["accounts"].asBool();
bool bExpand = jvRequest.isMember("expand") && jvRequest["expand"].asBool();
int iOptions = (bFull ? LEDGER_JSON_FULL : 0)
| (bExpand ? LEDGER_JSON_EXPAND : 0)
| (bTransactions ? LEDGER_JSON_DUMP_TXRP : 0)
| (bAccounts ? LEDGER_JSON_DUMP_STATE : 0);
Json::Value ret(Json::objectValue);
ScopedUnlock(theApp->getMasterLock());
lpLedger->addJson(ret, full ? LEDGER_JSON_FULL : 0);
lpLedger->addJson(ret, iOptions);
return ret;
}

View File

@@ -727,16 +727,37 @@ Remote.prototype.request_server_info = function () {
// XXX This is a bad command. Some varients don't scale.
// XXX Require the server to be trusted.
Remote.prototype.request_ledger = function (ledger, full) {
Remote.prototype.request_ledger = function (ledger, opts) {
//utils.assert(this.trusted);
var request = new Request(this, 'ledger');
if (ledger)
{
// DEPRECATED: use .ledger_hash() or .ledger_index()
console.log("request_ledger: ledger parameter is deprecated");
request.message.ledger = ledger;
}
if (full)
if ('object' == typeof opts) {
if (opts.full)
request.message.full = true;
if (opts.expand)
request.message.expand = true;
if (opts.transactions)
request.message.transactions = true;
if (opts.accounts)
request.message.accounts = true;
}
// DEPRECATED:
else if (opts)
{
console.log("request_ledger: full parameter is deprecated");
request.message.full = true;
}
return request;
};
@@ -971,17 +992,6 @@ Remote.prototype.request_book_offers = function (gets, pays, taker) {
return request;
};
Remote.prototype.request_ledger = function (ledger, full) {
var request = new Request(this, 'ledger');
request.message.ledger = ledger;
if (full)
request.message.full = true;
return request;
};
Remote.prototype.request_wallet_accounts = function (seed) {
utils.assert(this.trusted); // Don't send secrets.