rippled
ripple
rpc
handlers
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 <ripple/app/ledger/LedgerMaster.h>
21
#include <ripple/app/main/Application.h>
22
#include <ripple/app/misc/Transaction.h>
23
#include <ripple/app/rdb/RelationalDatabase.h>
24
#include <ripple/core/DatabaseCon.h>
25
#include <ripple/core/Pg.h>
26
#include <ripple/core/SociDB.h>
27
#include <ripple/net/RPCErr.h>
28
#include <ripple/protocol/ErrorCodes.h>
29
#include <ripple/protocol/jss.h>
30
#include <ripple/resource/Fees.h>
31
#include <ripple/rpc/Context.h>
32
#include <ripple/rpc/Role.h>
33
#include <ripple/rpc/Status.h>
34
#include <boost/format.hpp>
35
36
namespace
ripple
{
37
38
// {
39
// start: <index>
40
// }
41
Json::Value
42
doTxHistory
(
RPC::JsonContext
& context)
43
{
44
if
(!context.
app
.
config
().
useTxTables
())
45
return
rpcError
(
rpcNOT_ENABLED
);
46
47
context.
loadType
=
Resource::feeMediumBurdenRPC
;
48
49
if
(!context.
params
.
isMember
(jss::start))
50
return
rpcError
(
rpcINVALID_PARAMS
);
51
52
unsigned
int
startIndex = context.
params
[jss::start].
asUInt
();
53
54
if
((startIndex > 10000) && (!
isUnlimited
(context.
role
)))
55
return
rpcError
(
rpcNO_PERMISSION
);
56
57
auto
trans = context.
app
.
getRelationalDatabase
().
getTxHistory
(startIndex);
58
59
Json::Value
obj;
60
Json::Value
& txs = obj[jss::txs];
61
obj[jss::index] = startIndex;
62
if
(context.
app
.
config
().
reporting
())
63
obj[
"used_postgres"
] =
true
;
64
65
for
(
auto
const
& t : trans)
66
txs.
append
(t->getJson(
JsonOptions::none
));
67
68
return
obj;
69
}
70
71
}
// namespace ripple
ripple::RPC::JsonContext
Definition:
Context.h:53
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition:
ErrorCodes.h:84
ripple::rpcError
Json::Value rpcError(int iError)
Definition:
RPCErr.cpp:29
ripple::Resource::feeMediumBurdenRPC
const Charge feeMediumBurdenRPC
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition:
Context.h:43
ripple::RelationalDatabase::getTxHistory
virtual std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex)=0
getTxHistory Returns the 20 most recent transactions starting from the given number.
ripple::RPC::Context::role
Role role
Definition:
Context.h:47
ripple::doTxHistory
Json::Value doTxHistory(RPC::JsonContext &)
Definition:
TxHistory.cpp:42
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition:
json_value.cpp:882
ripple::Config::reporting
bool reporting() const
Definition:
Config.h:337
ripple::JsonOptions::none
@ none
ripple::Application::config
virtual Config & config()=0
ripple::Application::getRelationalDatabase
virtual RelationalDatabase & getRelationalDatabase()=0
ripple::Config::useTxTables
bool useTxTables() const
Definition:
Config.h:343
ripple::RPC::Context::app
Application & app
Definition:
Context.h:42
ripple::rpcNOT_ENABLED
@ rpcNOT_ENABLED
Definition:
ErrorCodes.h:59
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::isUnlimited
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition:
Role.cpp:124
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::rpcNO_PERMISSION
@ rpcNO_PERMISSION
Definition:
ErrorCodes.h:53
Json::Value::asUInt
UInt asUInt() const
Definition:
json_value.cpp:545
ripple::RPC::JsonContext::params
Json::Value params
Definition:
Context.h:64
Json::Value
Represents a JSON value.
Definition:
json_value.h:145
Generated by
1.8.17