diff --git a/src/ripple/module/app/main/Main.cpp b/src/ripple/module/app/main/Main.cpp index a39dcc20a..650cfcad7 100644 --- a/src/ripple/module/app/main/Main.cpp +++ b/src/ripple/module/app/main/Main.cpp @@ -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 " << endl; cerr << " ledger_header " << 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 []" << endl; // cerr << " send [] [] []" << endl; + cerr << " server_info" << endl; cerr << " stop" << endl; cerr << " tx " << endl; cerr << " unl_add | []" << endl; diff --git a/src/ripple/module/app/rpc/RPCHandler.cpp b/src/ripple/module/app/rpc/RPCHandler.cpp index 78ac483ae..cddc2fd1c 100644 --- a/src/ripple/module/app/rpc/RPCHandler.cpp +++ b/src/ripple/module/app/rpc/RPCHandler.cpp @@ -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 }, diff --git a/src/ripple/module/app/rpc/RPCHandler.h b/src/ripple/module/app/rpc/RPCHandler.h index 21dcd979d..47387b84e 100644 --- a/src/ripple/module/app/rpc/RPCHandler.h +++ b/src/ripple/module/app/rpc/RPCHandler.h @@ -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); diff --git a/src/ripple/module/net/rpc/RPCCall.cpp b/src/ripple/module/net/rpc/RPCCall.cpp index 5d6fcc8f0..aa90d997e 100644 --- a/src/ripple/module/net/rpc/RPCCall.cpp +++ b/src/ripple/module/net/rpc/RPCCall.cpp @@ -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 }, diff --git a/src/ripple_rpc/handlers/LedgerGet.cpp b/src/ripple_rpc/handlers/LedgerGet.cpp new file mode 100644 index 000000000..99eda3721 --- /dev/null +++ b/src/ripple_rpc/handlers/LedgerGet.cpp @@ -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_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 diff --git a/src/ripple_rpc/impl/Handlers.cpp b/src/ripple_rpc/impl/Handlers.cpp new file mode 100644 index 000000000..d73c057a0 --- /dev/null +++ b/src/ripple_rpc/impl/Handlers.cpp @@ -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 +