Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ledger_get RPC command to fetch a ledger from the network. #389

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,101 changes: 0 additions & 4,101 deletions Builds/VisualStudio2013/RippleD.vcxproj

Large diffs are not rendered by default.

5,586 changes: 0 additions & 5,586 deletions Builds/VisualStudio2013/RippleD.vcxproj.filters

Large diffs are not rendered by default.

101 changes: 43 additions & 58 deletions src/ripple/module/app/main/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,64 +71,49 @@ void startServer ()

void printHelp (const po::options_description& desc)
{
using namespace std;

cerr << SYSTEM_NAME "d [options] <command> <params>" << endl;

cerr << desc << endl;

cerr << "Commands: " << endl;
cerr << " account_info <account>|<nickname>|<seed>|<pass_phrase>|<key> [<ledger>] [strict]" << endl;
cerr << " account_lines <account> <account>|\"\" [<ledger>]" << endl;
cerr << " account_offers <account>|<nickname>|<account_public_key> [<ledger>]" << endl;
cerr << " account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending]" << endl;
cerr << " book_offers <taker_pays> <taker_gets> [<taker [<ledger> [<limit> [<proof> [<marker>]]]]]" << endl;
cerr << " connect <ip> [<port>]" << endl;
cerr << " consensus_info" << endl;
cerr << " get_counts" << endl;
cerr << " json <method> <json>" << endl;
cerr << " ledger [<id>|current|closed|validated] [full]" << endl;
cerr << " ledger_accept" << endl;
cerr << " ledger_closed" << endl;
cerr << " ledger_current" << endl;
cerr << " ledger_header <ledger>" << endl;
cerr << " logrotate " << endl;
cerr << " peers" << endl;
cerr << " proof_create [<difficulty>] [<secret>]" << endl;
cerr << " proof_solve <token>" << endl;
cerr << " proof_verify <token> <solution> [<difficulty>] [<secret>]" << endl;
cerr << " random" << endl;
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 << " stop" << endl;
cerr << " tx <id>" << endl;
cerr << " unl_add <domain>|<public> [<comment>]" << endl;
cerr << " unl_delete <domain>|<public_key>" << endl;
cerr << " unl_list" << endl;
cerr << " unl_load" << endl;
cerr << " unl_network" << endl;
cerr << " unl_reset" << endl;
cerr << " validation_create [<seed>|<pass_phrase>|<key>]" << endl;
cerr << " validation_seed [<seed>|<pass_phrase>|<key>]" << endl;
cerr << " wallet_add <regular_seed> <paying_account> <master_seed> [<initial_funds>] [<account_annotation>]" << endl;
cerr << " wallet_accounts <seed>" << endl;
cerr << " wallet_claim <master_seed> <regular_seed> [<source_tag>] [<account_annotation>]" << endl;
cerr << " wallet_seed [<seed>|<passphrase>|<passkey>]" << endl;
cerr << " wallet_propose [<passphrase>]" << endl;

// Transaction helpers (that were removed):
// cerr << " account_domain_set <seed> <paying_account> [<domain>]" << endl;
// cerr << " account_email_set <seed> <paying_account> [<email_address>]" << endl;
// cerr << " account_rate_set <seed> <paying_account> <rate>" << endl;
// cerr << " account_wallet_set <seed> <paying_account> [<wallet_hash>]" << endl;
// cerr << " nickname_info <nickname>" << endl;
// cerr << " nickname_set <seed> <paying_account> <nickname> [<offer_minimum>] [<authorization>]" << endl;
// cerr << " offer_create <seed> <paying_account> <taker_pays_amount> <taker_pays_currency> <taker_pays_issuer> <takers_gets_amount> <takers_gets_currency> <takers_gets_issuer> <expires> [passive]" << endl;
// cerr << " offer_cancel <seed> <paying_account> <sequence>" << endl;
// cerr << " password_fund <seed> <paying_account> [<account>]" << endl;
// cerr << " password_set <master_seed> <regular_seed> [<account>]" << endl;
// cerr << " trust_set <seed> <paying_account> <destination_account> <limit_amount> <currency> [<quality_in>] [<quality_out>]" << endl;
std::cerr
<< SYSTEM_NAME "d [options] <command> <params>\n"
<< desc << std::endl
<< "Commands: \n"
" account_info <account>|<nickname>|<seed>|<pass_phrase>|<key> [<ledger>] [strict]\n"
" account_lines <account> <account>|\"\" [<ledger>]\n"
" account_offers <account>|<nickname>|<account_public_key> [<ledger>]\n"
" account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending]\n"
" book_offers <taker_pays> <taker_gets> [<taker [<ledger> [<limit> [<proof> [<marker>]]]]]\n"
" connect <ip> [<port>]\n"
" consensus_info\n"
" get_counts\n"
" json <method> <json>\n"
" ledger [<id>|current|closed|validated] [full]\n"
" ledger_accept\n"
" ledger_closed\n"
" ledger_current\n"
" ledger_request <ledger>\n"
" ledger_header <ledger>\n"
" logrotate \n"
" peers\n"
" proof_create [<difficulty>] [<secret>]\n"
" proof_solve <token>\n"
" proof_verify <token> <solution> [<difficulty>] [<secret>]\n"
" random\n"
" ripple ...\n"
" ripple_path_find <json> [<ledger>]\n"
" server_info\n"
" stop\n"
" tx <id>\n"
" unl_add <domain>|<public> [<comment>]\n"
" unl_delete <domain>|<public_key>\n"
" unl_list\n"
" unl_load\n"
" unl_network\n"
" unl_reset\n"
" validation_create [<seed>|<pass_phrase>|<key>]\n"
" validation_seed [<seed>|<pass_phrase>|<key>]\n"
" wallet_accounts <seed>\n"
" wallet_add <regular_seed> <paying_account> <master_seed> [<initial_funds>] [<account_annotation>]\n"
" wallet_claim <master_seed> <regular_seed> [<source_tag>] [<account_annotation>]\n"
" wallet_propose [<passphrase>]\n"
" wallet_seed [<seed>|<passphrase>|<passkey>]\n";
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/module/app/rpc/RPCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
//==============================================================================

#include <ripple/module/rpc/impl/Handlers.cpp>

namespace ripple {

//
Expand Down Expand Up @@ -140,6 +138,7 @@ Json::Value RPCHandler::doCommand (const Json::Value& params, int iRole, Resourc
{ "ledger_data", &RPCHandler::doLedgerData, false, optCurrent },
{ "ledger_entry", &RPCHandler::doLedgerEntry, false, optCurrent },
{ "ledger_header", &RPCHandler::doLedgerHeader, false, optCurrent },
{ "ledger_request", &RPCHandler::doLedgerRequest, true, optNone },
{ "log_level", &RPCHandler::doLogLevel, true, optNone },
{ "logrotate", &RPCHandler::doLogRotate, true, optNone },
// { "nickname_info", &RPCHandler::doNicknameInfo, false, optCurrent },
Expand Down
1 change: 1 addition & 0 deletions src/ripple/module/app/rpc/RPCHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class RPCHandler
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 doLedgerHeader (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Json::Value doLedgerRequest (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);
Json::Value doNicknameInfo (Json::Value params, Resource::Charge& loadType, Application::ScopedLockType& mlh);
Expand Down
1 change: 1 addition & 0 deletions src/ripple/module/net/rpc/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ class RPCParser
{ "ledger_current", &RPCParser::parseAsIs, 0, 0 },
// { "ledger_entry", &RPCParser::parseLedgerEntry, -1, -1 },
{ "ledger_header", &RPCParser::parseLedgerId, 1, 1 },
{ "ledger_request", &RPCParser::parseLedgerId, 1, 1 },
{ "log_level", &RPCParser::parseLogLevel, 0, 2 },
{ "logrotate", &RPCParser::parseAsIs, 0, 0 },
// { "nickname_info", &RPCParser::parseNicknameInfo, 1, 1 },
Expand Down
112 changes: 112 additions & 0 deletions src/ripple/module/rpc/handlers/LedgerRequest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//------------------------------------------------------------------------------
/*
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::doLedgerRequest (
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 (hasHash)
{
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 == zero)
{
// 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 which 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
2 changes: 1 addition & 1 deletion src/ripple/module/rpc/handlers/ProofCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
//==============================================================================

#include <ripple/module/app/misc/ProofOfWorkFactory.h>

namespace ripple {


// {
// // if either of these parameters is set, a custom generator is used
// difficulty: <number> // optional
Expand Down
91 changes: 0 additions & 91 deletions src/ripple/module/rpc/impl/Handlers.cpp

This file was deleted.

1 change: 1 addition & 0 deletions src/ripple/module/rpc/impl/TransactionSign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//==============================================================================

#include <ripple/module/rpc/impl/TransactionSign.h>
#include <beast/unit_test.h>

namespace ripple {

Expand Down
Loading