rippled
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 <ripple/app/main/Application.h>
21 #include <ripple/ledger/ReadView.h>
22 #include <ripple/protocol/jss.h>
23 #include <ripple/rpc/Context.h>
24 #include <ripple/rpc/impl/RPCHelpers.h>
25 
26 namespace ripple {
27 
28 // {
29 // ledger_hash : <ledger>,
30 // ledger_index : <ledger_index>
31 // }
32 //
33 // XXX In this case, not specify either ledger does not mean ledger current. It
34 // means any ledger.
37 {
39  Json::Value jvResult = RPC::lookupLedger(lpLedger, context);
40 
41  if (!lpLedger)
42  return jvResult;
43 
44  if (!context.params.isMember(jss::tx_hash))
45  {
46  jvResult[jss::error] = "fieldNotFoundTransaction";
47  }
48  else if (jvResult.get(jss::ledger_hash, Json::nullValue).isNull())
49  {
50  // We don't work on ledger current.
51 
52  // XXX We don't support any transaction yet.
53  jvResult[jss::error] = "notYetImplemented";
54  }
55  else
56  {
57  uint256 uTransID;
58  // XXX Relying on trusted WSS client. Would be better to have a strict
59  // routine, returning success or failure.
60  if (!uTransID.parseHex(context.params[jss::tx_hash].asString()))
61  {
62  jvResult[jss::error] = "malformedRequest";
63  return jvResult;
64  }
65 
66  auto [sttx, stobj] = lpLedger->txRead(uTransID);
67  if (!sttx)
68  {
69  jvResult[jss::error] = "transactionNotFound";
70  }
71  else
72  {
73  jvResult[jss::tx_json] = sttx->getJson(JsonOptions::none);
74  if (stobj)
75  jvResult[jss::metadata] = stobj->getJson(JsonOptions::none);
76  // 'accounts'
77  // 'engine_...'
78  // 'ledger_...'
79  }
80  }
81 
82  return jvResult;
83 }
84 
85 } // namespace ripple
ripple::RPC::JsonContext
Definition: Context.h:53
std::shared_ptr
STL class.
Json::Value::get
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Definition: json_value.cpp:834
Json::Value::isNull
bool isNull() const
isNull() tests to see if this field is null.
Definition: json_value.cpp:967
ripple::RPC::lookupLedger
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.
Definition: RPCHelpers.cpp:675
ripple::base_uint< 256 >
ripple::JsonOptions::none
@ none
ripple::ReadView::txRead
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
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::doTransactionEntry
Json::Value doTransactionEntry(RPC::JsonContext &)
Definition: TransactionEntry.cpp:36
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
Json::nullValue
@ nullValue
'null' value
Definition: json_value.h:36
ripple::base_uint::parseHex
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition: base_uint.h:496
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
Json::Value
Represents a JSON value.
Definition: json_value.h:145
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469