rippled
Loading...
Searching...
No Matches
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/ledger/ReadView.h>
7#include <xrpl/protocol/jss.h>
8
9namespace ripple {
10
11// {
12// ledger_hash : <ledger>,
13// ledger_index : <ledger_index>
14// }
15//
16// XXX In this case, not specify either ledger does not mean ledger current. It
17// means any ledger.
20{
22 Json::Value jvResult = RPC::lookupLedger(lpLedger, context);
23
24 if (!lpLedger)
25 return jvResult;
26
27 if (!context.params.isMember(jss::tx_hash))
28 {
29 jvResult[jss::error] = "fieldNotFoundTransaction";
30 }
31 else if (jvResult.get(jss::ledger_hash, Json::nullValue).isNull())
32 {
33 // We don't work on ledger current.
34
35 // XXX We don't support any transaction yet.
36 jvResult[jss::error] = "notYetImplemented";
37 }
38 else
39 {
40 uint256 uTransID;
41 // XXX Relying on trusted WSS client. Would be better to have a strict
42 // routine, returning success or failure.
43 if (!uTransID.parseHex(context.params[jss::tx_hash].asString()))
44 {
45 jvResult[jss::error] = "malformedRequest";
46 return jvResult;
47 }
48
49 auto [sttx, stobj] = lpLedger->txRead(uTransID);
50 if (!sttx)
51 {
52 jvResult[jss::error] = "transactionNotFound";
53 }
54 else
55 {
56 if (context.apiVersion > 1)
57 {
58 jvResult[jss::tx_json] =
60 jvResult[jss::hash] = to_string(sttx->getTransactionID());
61
62 if (!lpLedger->open())
63 jvResult[jss::ledger_hash] = to_string(
64 context.ledgerMaster.getHashBySeq(lpLedger->seq()));
65
66 bool const validated =
67 context.ledgerMaster.isValidated(*lpLedger);
68
69 jvResult[jss::validated] = validated;
70 if (validated)
71 {
72 jvResult[jss::ledger_index] = lpLedger->seq();
73 if (auto closeTime = context.ledgerMaster.getCloseTimeBySeq(
74 lpLedger->seq()))
75 jvResult[jss::close_time_iso] =
76 to_string_iso(*closeTime);
77 }
78 }
79 else
80 jvResult[jss::tx_json] = sttx->getJson(JsonOptions::none);
81
83 jvResult[jss::tx_json], sttx->getTxnType(), context.apiVersion);
84
85 auto const json_meta =
86 (context.apiVersion > 1 ? jss::meta : jss::metadata);
87 if (stobj)
88 jvResult[json_meta] = stobj->getJson(JsonOptions::none);
89 // 'accounts'
90 // 'engine_...'
91 // 'ledger_...'
92 }
93 }
94
95 return jvResult;
96}
97
98} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
std::string asString() const
Returns the unquoted string value.
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
bool isValidated(ReadView const &ledger)
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:484
@ nullValue
'null' value
Definition json_value.h:20
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition DeliverMax.cpp:9
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Json::Value doTransactionEntry(RPC::JsonContext &)
std::string to_string_iso(date::sys_time< Duration > tp)
Definition chrono.h:73
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
unsigned int apiVersion
Definition Context.h:30
LedgerMaster & ledgerMaster
Definition Context.h:25