xrpld
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/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
14namespace 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.
23json::Value
25{
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
Represents a JSON value.
Definition json_value.h:130
bool isNull() const
isNull() tests to see if this field is null.
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::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:507
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
bool isValidated(ReadView const &ledger)
@ Null
'null' value
Definition json_value.h:19
void insertDeliverMax(json::Value &txJson, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition DeliverMax.cpp:9
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
json::Value doTransactionEntry(RPC::JsonContext &)
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
std::string toStringIso(date::sys_time< Duration > tp)
Definition chrono.h:68
BaseUInt< 256 > uint256
Definition base_uint.h:562
unsigned int apiVersion
Definition Context.h:29
LedgerMaster & ledgerMaster
Definition Context.h:24
json::Value params
Definition Context.h:43