xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
transaction
TransactionEntry.cpp
1
#include <xrpld/app/ledger/LedgerMaster.h>
2
#include <xrpld/app/misc/DeliverMax.h>
3
#include <xrpld/rpc/Context.h>
4
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
5
6
#include <xrpl/basics/base_uint.h>
7
#include <xrpl/basics/chrono.h>
8
#include <xrpl/json/json_value.h>
9
#include <xrpl/ledger/ReadView.h>
10
#include <xrpl/protocol/jss.h>
11
12
#include <
memory
>
13
14
namespace
xrpl
{
15
16
// {
17
// ledger_hash : <ledger>,
18
// ledger_index : <ledger_index>
19
// }
20
//
21
// XXX In this case, not specify either ledger does not mean ledger current. It
22
// means any ledger.
23
json::Value
24
doTransactionEntry
(
rpc::JsonContext
& context)
25
{
26
std::shared_ptr<ReadView const>
lpLedger;
27
json::Value
jvResult =
rpc::lookupLedger
(lpLedger, context);
28
29
if
(!lpLedger)
30
return
jvResult;
31
32
if
(!context.
params
.
isMember
(jss::tx_hash))
33
{
34
jvResult[jss::error] =
"fieldNotFoundTransaction"
;
35
}
36
else
if
(jvResult.
get
(jss::ledger_hash,
json::ValueType::Null
).
isNull
())
37
{
38
// We don't work on ledger current.
39
40
// XXX We don't support any transaction yet.
41
jvResult[jss::error] =
"notYetImplemented"
;
42
}
43
else
44
{
45
UInt256
uTransID;
46
// XXX Relying on trusted WSS client. Would be better to have a strict
47
// routine, returning success or failure.
48
if
(!uTransID.
parseHex
(context.
params
[jss::tx_hash].
asString
()))
49
{
50
jvResult[jss::error] =
"malformedRequest"
;
51
return
jvResult;
52
}
53
54
auto
[sttx, stobj] = lpLedger->txRead(uTransID);
55
if
(!sttx)
56
{
57
jvResult[jss::error] =
"transactionNotFound"
;
58
}
59
else
60
{
61
if
(context.
apiVersion
> 1)
62
{
63
jvResult[jss::tx_json] = sttx->getJson(
JsonOptions::Values::DisableApiPriorV2
);
64
jvResult[jss::hash] =
to_string
(sttx->getTransactionID());
65
66
if
(!lpLedger->open())
67
{
68
jvResult[jss::ledger_hash] =
69
to_string
(context.
ledgerMaster
.
getHashBySeq
(lpLedger->seq()));
70
}
71
72
bool
const
validated = context.
ledgerMaster
.
isValidated
(*lpLedger);
73
74
jvResult[jss::validated] = validated;
75
if
(validated)
76
{
77
jvResult[jss::ledger_index] = lpLedger->seq();
78
if
(
auto
closeTime = context.
ledgerMaster
.
getCloseTimeBySeq
(lpLedger->seq()))
79
jvResult[jss::close_time_iso] =
toStringIso
(*closeTime);
80
}
81
}
82
else
83
{
84
jvResult[jss::tx_json] = sttx->getJson(
JsonOptions::Values::None
);
85
}
86
87
rpc::insertDeliverMax
(jvResult[jss::tx_json], sttx->getTxnType(), context.
apiVersion
);
88
89
auto
const
jsonMeta = (context.
apiVersion
> 1 ? jss::meta : jss::metadata);
90
if
(stobj)
91
jvResult[jsonMeta] = stobj->getJson(
JsonOptions::Values::None
);
92
// 'accounts'
93
// 'engine_...'
94
// 'ledger_...'
95
}
96
}
97
98
return
jvResult;
99
}
100
101
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::isNull
bool isNull() const
isNull() tests to see if this field is null.
Definition
json_value.cpp:1092
json::Value::get
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Definition
json_value.cpp:941
json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition
json_value.cpp:494
json::Value::isMember
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition
json_value.cpp:1049
xrpl::BaseUInt::parseHex
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition
base_uint.h:525
xrpl::LedgerMaster::getHashBySeq
UInt256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
Definition
LedgerMaster.cpp:1685
xrpl::LedgerMaster::getCloseTimeBySeq
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
Definition
LedgerMaster.cpp:1659
xrpl::LedgerMaster::isValidated
bool isValidated(ReadView const &ledger)
Tests whether a ledger is on the validated chain, using the skip list when the ledger does not alread...
Definition
LedgerMaster.cpp:534
memory
json::ValueType::Null
@ Null
'null' value
Definition
json_value.h:22
xrpl::rpc::insertDeliverMax
void insertDeliverMax(json::Value &txJson, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition
DeliverMax.cpp:9
xrpl::rpc::lookupLedger
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, json::Value &result)
Looks up a ledger from a request and fills a json::Value with ledger data.
Definition
RPCLedgerHelpers.cpp:390
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::doTransactionEntry
json::Value doTransactionEntry(rpc::JsonContext &)
Definition
TransactionEntry.cpp:24
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::toStringIso
std::string toStringIso(date::sys_time< Duration > tp)
Definition
chrono.h:70
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
std::shared_ptr
xrpl::JsonOptions::Values::None
@ None
Definition
STBase.h:27
xrpl::JsonOptions::Values::DisableApiPriorV2
@ DisableApiPriorV2
Definition
STBase.h:29
xrpl::rpc::Context::apiVersion
unsigned int apiVersion
Definition
Context.h:37
xrpl::rpc::Context::ledgerMaster
LedgerMaster & ledgerMaster
Definition
Context.h:32
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::params
json::Value params
Definition
Context.h:51
Generated by
1.17.0