Add ledger_get RPC command to fetch a ledger from the network

Conflicts:
	Builds/VisualStudio2013/RippleD.vcxproj
	Builds/VisualStudio2013/RippleD.vcxproj.filters
	Builds/VisualStudio2013/RippleD2.vcxproj
	Builds/VisualStudio2013/RippleD2.vcxproj.filters
	src/ripple_rpc/impl/Handlers.cpp
This commit is contained in:
JoelKatz
2014-05-19 22:21:21 -07:00
committed by Vinnie Falco
parent 37201ecaa6
commit 526bd88dc4
6 changed files with 213 additions and 0 deletions

View File

@@ -91,6 +91,7 @@ void printHelp (const po::options_description& desc)
cerr << " ledger_accept" << endl;
cerr << " ledger_closed" << endl;
cerr << " ledger_current" << endl;
cerr << " ledger_get <ledger>" << endl;
cerr << " ledger_header <ledger>" << endl;
cerr << " logrotate " << endl;
cerr << " peers" << endl;
@@ -101,6 +102,7 @@ void printHelp (const po::options_description& desc)
cerr << " ripple ..." << endl;
cerr << " ripple_path_find <json> [<ledger>]" << endl;
// cerr << " send <seed> <paying_account> <account_id> <amount> [<currency>] [<send_max>] [<send_currency>]" << endl;
cerr << " server_info" << endl;
cerr << " stop" << endl;
cerr << " tx <id>" << endl;
cerr << " unl_add <domain>|<public> [<comment>]" << endl;

View File

@@ -139,6 +139,7 @@ Json::Value RPCHandler::doCommand (const Json::Value& params, int iRole, Resourc
{ "ledger_current", &RPCHandler::doLedgerCurrent, false, optCurrent },
{ "ledger_data", &RPCHandler::doLedgerData, false, optCurrent },
{ "ledger_entry", &RPCHandler::doLedgerEntry, false, optCurrent },
{ "ledger_get", &RPCHandler::doLedgerGet, true, optNone },
{ "ledger_header", &RPCHandler::doLedgerHeader, false, optCurrent },
{ "log_level", &RPCHandler::doLogLevel, true, optNone },
{ "logrotate", &RPCHandler::doLogRotate, true, optNone },

View File

@@ -87,6 +87,7 @@ private:
Json::Value doLedgerCurrent (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLedgerData (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLedgerEntry (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLedgerGet (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLedgerHeader (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLogLevel (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLogRotate (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);

View File

@@ -813,6 +813,7 @@ public:
{ "ledger_closed", &RPCParser::parseAsIs, 0, 0 },
{ "ledger_current", &RPCParser::parseAsIs, 0, 0 },
// { "ledger_entry", &RPCParser::parseLedgerEntry, -1, -1 },
{ "ledger_get", &RPCParser::parseLedgerId, 1, 1 },
{ "ledger_header", &RPCParser::parseLedgerId, 1, 1 },
{ "log_level", &RPCParser::parseLogLevel, 0, 2 },
{ "logrotate", &RPCParser::parseAsIs, 0, 0 },

View File

@@ -0,0 +1,117 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
namespace ripple {
// {
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// }
Json::Value RPCHandler::doLedgerGet (
Json::Value params,
Resource::Charge&,
Application::ScopedLockType& masterLockHolder)
{
masterLockHolder.unlock ();
auto const hasHash = params.isMember (jss::ledger_hash);
auto const hasIndex = params.isMember (jss::ledger_index);
auto& ledgerMaster = getApp().getLedgerMaster();
LedgerHash ledgerHash;
if ((hasHash && hasIndex) || !(hasHash || hasIndex))
{
return RPC::make_param_error(
"Exactly one of ledger_hash and ledger_index can be set.");
}
if (hasHas)
{
auto const& jsonHash = params[jss::ledger_hash];
if (!jsonHash.isString() || !ledgerHash.SetHex (jsonHash.asString ()))
return RPC::invalid_field_message ("ledger_hash");
}
else
{
auto const& jsonIndex = params[jss::ledger_index];
if (!jsonIndex.isNumeric ())
return RPC::invalid_field_message ("ledger_index");
// We need a validated ledger to get the hash from the sequence
if (ledgerMaster.getValidatedLedgerAge() > 120)
return rpcError (rpcNO_CURRENT);
auto ledgerIndex = jsonIndex.asInt();
auto ledger = ledgerMaster.getValidatedLedger();
if (ledgerIndex >= ledger->getLedgerSeq())
return RPC::make_param_error("Ledger index too large");
// Try to get the hash of the desired ledger from the validated ledger
ledgerHash = ledger->getLedgerHash (ledgerIndex);
if (ledgerHash.isZero ())
{
// Find a ledger more likely to have the hash of the desired ledger
auto refIndex = (ledgerIndex + 255) & (~255);
auto refHash = ledger->getLedgerHash (refIndex);
assert (refHash.isNonZero ());
ledger = ledgerMaster.getLedgerByHash (refHash);
if (!ledger)
{
// We don't have the ledger we need to figure out whihc
// ledger they want. Try to get it.
getApp().getInboundLedgers().findCreate (
refHash, refIndex, InboundLedger::fcGENERIC);
Json::Value jvResult;
jvResult[jss::error] = "ledgerNotFound";
return jvResult;
}
ledgerHash = ledger->getLedgerHash (ledgerIndex);
assert (ledgerHash.isNonZero ());
}
}
auto ledger = ledgerMaster.getLedgerByHash (ledgerHash);
if (ledger)
{
// We already have the ledger they want
Json::Value jvResult;
jvResult[jss::ledger_index] = ledger->getLedgerSeq();
ledger->addJson (jvResult, 0);
return jvResult;
}
else
{
// Try to get the desired ledger
auto il = getApp().getInboundLedgers().findCreate (
ledgerHash, 0, InboundLedger::fcGENERIC);
return il->getJson (0);
}
}
} // ripple

View File

@@ -0,0 +1,91 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "../handlers/AccountCurrencies.cpp"
#include "../handlers/AccountInfo.cpp"
#include "../handlers/AccountLines.cpp"
#include "../handlers/AccountOffers.cpp"
#include "../handlers/AccountTx.cpp"
#include "../handlers/AccountTxOld.cpp"
#include "../handlers/AccountTxSwitch.cpp"
#include "../handlers/BlackList.cpp"
#include "../handlers/BookOffers.cpp"
#include "../handlers/Connect.cpp"
#include "../handlers/ConsensusInfo.cpp"
#include "../handlers/Feature.cpp"
#include "../handlers/FetchInfo.cpp"
#include "../handlers/GetCounts.cpp"
#include "../handlers/Ledger.cpp"
#include "../handlers/LedgerAccept.cpp"
#include "../handlers/LedgerCleaner.cpp"
#include "../handlers/LedgerClosed.cpp"
#include "../handlers/LedgerCurrent.cpp"
#include "../handlers/LedgerData.cpp"
#include "../handlers/LedgerEntry.cpp"
#include "../handlers/LedgerHeader.cpp"
#include "../handlers/LogLevel.cpp"
#include "../handlers/LogRotate.cpp"
#include "../handlers/NicknameInfo.cpp"
#include "../handlers/OwnerInfo.cpp"
#include "../handlers/PathFind.cpp"
#include "../handlers/Peers.cpp"
#include "../handlers/Ping.cpp"
#include "../handlers/Print.cpp"
#include "../handlers/Profile.cpp"
#include "../handlers/ProofCreate.cpp"
#include "../handlers/ProofSolve.cpp"
#include "../handlers/ProofVerify.cpp"
#include "../handlers/Random.cpp"
#include "../handlers/RipplePathFind.cpp"
#include "../handlers/SMS.cpp"
#include "../handlers/ServerInfo.cpp"
#include "../handlers/ServerState.cpp"
#include "../handlers/Sign.cpp"
#include "../handlers/Stop.cpp"
#include "../handlers/Submit.cpp"
#include "../handlers/Subscribe.cpp"
#include "../handlers/TransactionEntry.cpp"
#include "../handlers/Tx.cpp"
#include "../handlers/TxHistory.cpp"
#include "../handlers/UnlAdd.cpp"
#include "../handlers/UnlDelete.cpp"
#include "../handlers/UnlList.cpp"
#include "../handlers/UnlLoad.cpp"
#include "../handlers/UnlNetwork.cpp"
#include "../handlers/UnlReset.cpp"
#include "../handlers/UnlScore.cpp"
#include "../handlers/Unsubscribe.cpp"
#include "../handlers/ValidationCreate.cpp"
#include "../handlers/ValidationSeed.cpp"
#include "../handlers/WalletAccounts.cpp"
#include "../handlers/WalletPropose.cpp"
#include "../handlers/WalletSeed.cpp"
#include "AccountFromString.cpp"
#include "Accounts.cpp"
#include "Authorize.cpp"
#include "GetMasterGenerator.cpp"
#include "LegacyPathFind.cpp"
#include "LookupLedger.cpp"
#include "ParseAccountIds.cpp"
#include "TransactionSign.cpp"
#include "../../ripple_overlay/api/Overlay.h"
#include <tuple>