rippled
Fee1.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2015 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/OpenLedger.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/misc/TxQ.h>
23 #include <ripple/basics/mulDiv.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/Feature.h>
26 #include <ripple/rpc/Context.h>
27 #include <ripple/rpc/GRPCHandlers.h>
28 
29 namespace ripple {
32 {
33  auto result = context.app.getTxQ().doRPC(context.app);
34  if (result.type() == Json::objectValue)
35  return result;
36  assert(false);
38  return context.params;
39 }
40 
43 {
44  org::xrpl::rpc::v1::GetFeeResponse reply;
45  grpc::Status status = grpc::Status::OK;
46 
47  Application& app = context.app;
48  auto const view = app.openLedger().current();
49  if (!view)
50  {
51  BOOST_ASSERT(false);
52  return {reply, status};
53  }
54 
55  auto const metrics = app.getTxQ().getMetrics(*view);
56 
57  // current ledger data
58  reply.set_current_ledger_size(metrics.txInLedger);
59  reply.set_current_queue_size(metrics.txCount);
60  reply.set_expected_ledger_size(metrics.txPerLedger);
61  reply.set_ledger_current_index(view->info().seq);
62  reply.set_max_queue_size(*metrics.txQMaxSize);
63 
64  // fee levels data
65  org::xrpl::rpc::v1::FeeLevels& levels = *reply.mutable_levels();
66  levels.set_median_level(metrics.medFeeLevel.fee());
67  levels.set_minimum_level(metrics.minProcessingFeeLevel.fee());
68  levels.set_open_ledger_level(metrics.openLedgerFeeLevel.fee());
69  levels.set_reference_level(metrics.referenceFeeLevel.fee());
70 
71  // fee data
72  org::xrpl::rpc::v1::Fee& fee = *reply.mutable_fee();
73  auto const baseFee = view->fees().base;
74  fee.mutable_base_fee()->set_drops(
75  toDrops(metrics.referenceFeeLevel, baseFee).drops());
76  fee.mutable_minimum_fee()->set_drops(
77  toDrops(metrics.minProcessingFeeLevel, baseFee).drops());
78  fee.mutable_median_fee()->set_drops(
79  toDrops(metrics.medFeeLevel, baseFee).drops());
80 
81  fee.mutable_open_ledger_fee()->set_drops(
82  (toDrops(metrics.openLedgerFeeLevel - FeeLevel64{1}, baseFee) + 1)
83  .drops());
84  return {reply, status};
85 }
86 } // namespace ripple
ripple::Application
Definition: Application.h:101
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::OpenLedger::current
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Definition: OpenLedger.cpp:50
std::pair
ripple::XRPAmount::drops
constexpr value_type drops() const
Returns the number of drops.
Definition: XRPAmount.h:172
ripple::Application::openLedger
virtual OpenLedger & openLedger()=0
ripple::toDrops
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount const &baseFee)
Definition: TxQ.h:826
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::RPC::GRPCContext
Definition: Context.h:70
ripple::Application::getTxQ
virtual TxQ & getTxQ()=0
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:70
ripple::TxQ::doRPC
Json::Value doRPC(Application &app) const
Summarize current fee metrics for the fee RPC command.
Definition: TxQ.cpp:1792
ripple::rpcINTERNAL
@ rpcINTERNAL
Definition: ErrorCodes.h:130
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::doFeeGrpc
std::pair< org::xrpl::rpc::v1::GetFeeResponse, grpc::Status > doFeeGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetFeeRequest > &context)
Definition: Fee1.cpp:42
ripple::TxQ::getMetrics
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition: TxQ.cpp:1713
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::RPC::inject_error
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition: ErrorCodes.h:193
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::doFee
Json::Value doFee(RPC::JsonContext &context)
Definition: Fee1.cpp:31