rippled
Loading...
Searching...
No Matches
TransactionEntry.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 <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/misc/DeliverMax.h>
22#include <xrpld/rpc/Context.h>
23#include <xrpld/rpc/detail/RPCHelpers.h>
24
25#include <xrpl/ledger/ReadView.h>
26#include <xrpl/protocol/jss.h>
27
28namespace ripple {
29
30// {
31// ledger_hash : <ledger>,
32// ledger_index : <ledger_index>
33// }
34//
35// XXX In this case, not specify either ledger does not mean ledger current. It
36// means any ledger.
39{
41 Json::Value jvResult = RPC::lookupLedger(lpLedger, context);
42
43 if (!lpLedger)
44 return jvResult;
45
46 if (!context.params.isMember(jss::tx_hash))
47 {
48 jvResult[jss::error] = "fieldNotFoundTransaction";
49 }
50 else if (jvResult.get(jss::ledger_hash, Json::nullValue).isNull())
51 {
52 // We don't work on ledger current.
53
54 // XXX We don't support any transaction yet.
55 jvResult[jss::error] = "notYetImplemented";
56 }
57 else
58 {
59 uint256 uTransID;
60 // XXX Relying on trusted WSS client. Would be better to have a strict
61 // routine, returning success or failure.
62 if (!uTransID.parseHex(context.params[jss::tx_hash].asString()))
63 {
64 jvResult[jss::error] = "malformedRequest";
65 return jvResult;
66 }
67
68 auto [sttx, stobj] = lpLedger->txRead(uTransID);
69 if (!sttx)
70 {
71 jvResult[jss::error] = "transactionNotFound";
72 }
73 else
74 {
75 if (context.apiVersion > 1)
76 {
77 jvResult[jss::tx_json] =
79 jvResult[jss::hash] = to_string(sttx->getTransactionID());
80
81 if (!lpLedger->open())
82 jvResult[jss::ledger_hash] = to_string(
83 context.ledgerMaster.getHashBySeq(lpLedger->seq()));
84
85 bool const validated =
86 context.ledgerMaster.isValidated(*lpLedger);
87
88 jvResult[jss::validated] = validated;
89 if (validated)
90 {
91 jvResult[jss::ledger_index] = lpLedger->seq();
92 if (auto closeTime = context.ledgerMaster.getCloseTimeBySeq(
93 lpLedger->seq()))
94 jvResult[jss::close_time_iso] =
95 to_string_iso(*closeTime);
96 }
97 }
98 else
99 jvResult[jss::tx_json] = sttx->getJson(JsonOptions::none);
100
102 jvResult[jss::tx_json], sttx->getTxnType(), context.apiVersion);
103
104 auto const json_meta =
105 (context.apiVersion > 1 ? jss::meta : jss::metadata);
106 if (stobj)
107 jvResult[json_meta] = stobj->getJson(JsonOptions::none);
108 // 'accounts'
109 // 'engine_...'
110 // 'ledger_...'
111 }
112 }
113
114 return jvResult;
115}
116
117} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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:503
@ nullValue
'null' value
Definition json_value.h:38
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Json::Value doTransactionEntry(RPC::JsonContext &)
std::string to_string_iso(date::sys_time< Duration > tp)
Definition chrono.h:92
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
unsigned int apiVersion
Definition Context.h:49
LedgerMaster & ledgerMaster
Definition Context.h:44