rippled
Loading...
Searching...
No Matches
TxHistory.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 <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/misc/DeliverMax.h>
23#include <xrpld/app/misc/Transaction.h>
24#include <xrpld/app/rdb/RelationalDatabase.h>
25#include <xrpld/rpc/Context.h>
26#include <xrpld/rpc/Role.h>
27
28#include <xrpl/protocol/ErrorCodes.h>
29#include <xrpl/protocol/RPCErr.h>
30#include <xrpl/protocol/jss.h>
31#include <xrpl/resource/Fees.h>
32
33namespace ripple {
34
35// {
36// start: <index>
37// }
40{
41 if (!context.app.config().useTxTables())
43
45
46 if (!context.params.isMember(jss::start))
48
49 unsigned int startIndex = context.params[jss::start].asUInt();
50
51 if ((startIndex > 10000) && (!isUnlimited(context.role)))
53
54 auto trans = context.app.getRelationalDatabase().getTxHistory(startIndex);
55
56 Json::Value obj;
57 Json::Value& txs = obj[jss::txs];
58 obj[jss::index] = startIndex;
59
60 for (auto const& t : trans)
61 {
62 Json::Value tx_json = t->getJson(JsonOptions::none);
64 tx_json, t->getSTransaction()->getTxnType(), context.apiVersion);
65 txs.append(tx_json);
66 }
67
68 return obj;
69}
70
71} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
UInt asUInt() const
Definition: json_value.cpp:551
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:897
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:949
virtual Config & config()=0
virtual RelationalDatabase & getRelationalDatabase()=0
bool useTxTables() const
Definition: Config.h:343
virtual std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex)=0
getTxHistory Returns the 20 most recent transactions starting from the given number.
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition: DeliverMax.cpp:28
Charge const feeMediumBurdenRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Json::Value doTxHistory(RPC::JsonContext &)
Definition: TxHistory.cpp:39
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
@ rpcNOT_ENABLED
Definition: ErrorCodes.h:59
@ rpcNO_PERMISSION
Definition: ErrorCodes.h:53
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:31
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition: Role.cpp:125
unsigned int apiVersion
Definition: Context.h:49
Resource::Charge & loadType
Definition: Context.h:42
Application & app
Definition: Context.h:41
Json::Value params
Definition: Context.h:63