rippled
LedgerHandler.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2014 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/ledger/LedgerToJson.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/LoadFeeTrack.h>
23 #include <ripple/json/Object.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/resource/Fees.h>
27 #include <ripple/rpc/Role.h>
28 #include <ripple/rpc/handlers/LedgerHandler.h>
29 #include <ripple/rpc/impl/RPCHelpers.h>
30 
31 namespace ripple {
32 namespace RPC {
33 
34 LedgerHandler::LedgerHandler(JsonContext& context) : context_(context)
35 {
36 }
37 
38 Status
40 {
41  auto const& params = context_.params;
42  bool needsLedger = params.isMember(jss::ledger) ||
43  params.isMember(jss::ledger_hash) || params.isMember(jss::ledger_index);
44  if (!needsLedger)
45  return Status::OK;
46 
47  if (auto s = lookupLedger(ledger_, context_, result_))
48  return s;
49 
50  bool const full = params[jss::full].asBool();
51  bool const transactions = params[jss::transactions].asBool();
52  bool const accounts = params[jss::accounts].asBool();
53  bool const expand = params[jss::expand].asBool();
54  bool const binary = params[jss::binary].asBool();
55  bool const owner_funds = params[jss::owner_funds].asBool();
56  bool const queue = params[jss::queue].asBool();
57  auto type = chooseLedgerEntryType(params);
58  if (type.first)
59  return type.first;
60  type_ = type.second;
61 
62  options_ = (full ? LedgerFill::full : 0) |
63  (expand ? LedgerFill::expand : 0) |
64  (transactions ? LedgerFill::dumpTxrp : 0) |
65  (accounts ? LedgerFill::dumpState : 0) |
66  (binary ? LedgerFill::binary : 0) |
67  (owner_funds ? LedgerFill::ownerFunds : 0) |
68  (queue ? LedgerFill::dumpQueue : 0);
69 
70  if (full || accounts)
71  {
72  // Until some sane way to get full ledgers has been implemented,
73  // disallow retrieving all state nodes.
75  return rpcNO_PERMISSION;
76 
79  {
80  return rpcTOO_BUSY;
81  }
84  }
85  if (queue)
86  {
87  if (!ledger_ || !ledger_->open())
88  {
89  // It doesn't make sense to request the queue
90  // with a non-existant or closed/validated ledger.
91  return rpcINVALID_PARAMS;
92  }
93 
95  }
96 
97  return Status::OK;
98 }
99 
100 } // namespace RPC
101 } // namespace ripple
ripple::LedgerFill::dumpTxrp
@ dumpTxrp
Definition: LedgerToJson.h:44
ripple::RPC::Status::OK
static constexpr Code OK
Definition: Status.h:46
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::RPC::LedgerHandler::context_
JsonContext & context_
Definition: LedgerHandler.h:80
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
ripple::TxQ::getTxs
std::vector< TxDetails > getTxs(ReadView const &view) const
Returns information about all transactions currently in the queue.
Definition: TxQ.cpp:1777
ripple::Resource::feeMediumBurdenRPC
const Charge feeMediumBurdenRPC
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition: Context.h:43
ripple::RPC::LedgerHandler::ledger_
std::shared_ptr< ReadView const > ledger_
Definition: LedgerHandler.h:81
ripple::LedgerFill::dumpQueue
@ dumpQueue
Definition: LedgerToJson.h:50
ripple::rpcTOO_BUSY
@ rpcTOO_BUSY
Definition: ErrorCodes.h:56
ripple::RPC::Context::role
Role role
Definition: Context.h:47
ripple::LedgerFill::expand
@ expand
Definition: LedgerToJson.h:46
ripple::RPC::lookupLedger
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Definition: RPCHelpers.cpp:487
ripple::Application::getFeeTrack
virtual LoadFeeTrack & getFeeTrack()=0
ripple::LoadFeeTrack::isLoadedLocal
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:123
ripple::LedgerFill::full
@ full
Definition: LedgerToJson.h:47
ripple::Application::getTxQ
virtual TxQ & getTxQ()=0
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
ripple::RPC::Status
Status represents the results of an operation that might fail.
Definition: Status.h:39
ripple::isUnlimited
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition: Role.cpp:94
ripple::LedgerFill::binary
@ binary
Definition: LedgerToJson.h:48
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerFill::ownerFunds
@ ownerFunds
Definition: LedgerToJson.h:49
ripple::RPC::LedgerHandler::LedgerHandler
LedgerHandler(JsonContext &)
Definition: LedgerHandler.cpp:34
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:787
ripple::rpcNO_PERMISSION
@ rpcNO_PERMISSION
Definition: ErrorCodes.h:53
ripple::RPC::LedgerHandler::type_
LedgerEntryType type_
Definition: LedgerHandler.h:85
ripple::RPC::LedgerHandler::check
Status check()
Definition: LedgerHandler.cpp:39
ripple::RPC::LedgerHandler::options_
int options_
Definition: LedgerHandler.h:84
ripple::RPC::LedgerHandler::queueTxs_
std::vector< TxQ::TxDetails > queueTxs_
Definition: LedgerHandler.h:82
ripple::LedgerFill::dumpState
@ dumpState
Definition: LedgerToJson.h:45
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::Resource::feeHighBurdenRPC
const Charge feeHighBurdenRPC
ripple::RPC::LedgerHandler::result_
Json::Value result_
Definition: LedgerHandler.h:83