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/main/Application.h>
21
#include <ripple/app/misc/Transaction.h>
22
#include <ripple/core/DatabaseCon.h>
23
#include <ripple/core/SociDB.h>
24
#include <ripple/net/RPCErr.h>
25
#include <ripple/protocol/ErrorCodes.h>
26
#include <ripple/protocol/jss.h>
27
#include <ripple/resource/Fees.h>
28
#include <ripple/rpc/Context.h>
29
#include <ripple/rpc/Role.h>
30
#include <boost/format.hpp>
31
32
namespace
ripple
{
33
34
// {
35
// start: <index>
36
// }
37
Json::Value
38
doTxHistory
(
RPC::JsonContext
& context)
39
{
40
context.
loadType
=
Resource::feeMediumBurdenRPC
;
41
42
if
(!context.
params
.
isMember
(jss::start))
43
return
rpcError
(
rpcINVALID_PARAMS
);
44
45
unsigned
int
startIndex = context.
params
[jss::start].
asUInt
();
46
47
if
((startIndex > 10000) && (!
isUnlimited
(context.
role
)))
48
return
rpcError
(
rpcNO_PERMISSION
);
49
50
Json::Value
obj;
51
Json::Value
txs;
52
53
obj[jss::index] = startIndex;
54
55
std::string
sql = boost::str(
56
boost::format(
57
"SELECT LedgerSeq, Status, RawTxn "
58
"FROM Transactions ORDER BY LedgerSeq desc LIMIT %u,20;"
) %
59
startIndex);
60
61
{
62
auto
db = context.
app
.
getTxnDB
().
checkoutDb
();
63
64
boost::optional<std::uint64_t> ledgerSeq;
65
boost::optional<std::string> status;
66
soci::blob sociRawTxnBlob(*db);
67
soci::indicator rti;
68
Blob
rawTxn;
69
70
soci::statement st =
71
(db->prepare << sql,
72
soci::into(ledgerSeq),
73
soci::into(status),
74
soci::into(sociRawTxnBlob, rti));
75
76
st.execute();
77
while
(st.fetch())
78
{
79
if
(soci::i_ok == rti)
80
convert
(sociRawTxnBlob, rawTxn);
81
else
82
rawTxn.
clear
();
83
84
if
(
auto
trans =
Transaction::transactionFromSQL
(
85
ledgerSeq, status, rawTxn, context.
app
))
86
txs.
append
(trans->getJson(
JsonOptions::none
));
87
}
88
}
89
90
obj[jss::txs] = txs;
91
92
return
obj;
93
}
94
95
}
// namespace ripple
ripple::Transaction::transactionFromSQL
static Transaction::pointer transactionFromSQL(boost::optional< std::uint64_t > const &ledgerSeq, boost::optional< std::string > const &status, Blob const &rawTxn, Application &app)
Definition:
Transaction.cpp:89
ripple::RPC::JsonContext
Definition:
Context.h:53
std::string
STL class.
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition:
ErrorCodes.h:84
ripple::Resource::feeMediumBurdenRPC
const Charge feeMediumBurdenRPC
ripple::convert
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
Definition:
SociDB.cpp:156
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition:
Context.h:43
std::vector< unsigned char >
ripple::RPC::Context::role
Role role
Definition:
Context.h:47
std::vector::clear
T clear(T... args)
ripple::doTxHistory
Json::Value doTxHistory(RPC::JsonContext &)
Definition:
TxHistory.cpp:38
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition:
json_value.cpp:882
ripple::DatabaseCon::checkoutDb
LockedSociSession checkoutDb()
Definition:
DatabaseCon.h:176
ripple::JsonOptions::none
@ none
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::rpcError
Json::Value rpcError(int iError, Json::Value jvResult)
Definition:
RPCErr.cpp:29
ripple::isUnlimited
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition:
Role.cpp:94
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
ripple::Application::getTxnDB
virtual DatabaseCon & getTxnDB()=0
Generated by
1.8.17