20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/ledger/TransactionMaster.h>
22 #include <ripple/app/misc/NetworkOPs.h>
23 #include <ripple/app/misc/Transaction.h>
24 #include <ripple/basics/ToString.h>
25 #include <ripple/net/RPCErr.h>
26 #include <ripple/protocol/ErrorCodes.h>
27 #include <ripple/protocol/jss.h>
28 #include <ripple/rpc/Context.h>
29 #include <ripple/rpc/DeliveredAmount.h>
30 #include <ripple/rpc/GRPCHandlers.h>
31 #include <ripple/rpc/impl/GRPCHelpers.h>
32 #include <ripple/rpc/impl/RPCHelpers.h>
73 Throw<std::runtime_error>(
74 "Called doTxPostgres yet not in reporting mode");
79 JLOG(context.
j.
debug()) <<
"Fetching from postgres";
99 return {res, {
rpcINTERNAL,
"Error making SHAMap node"}};
101 auto item = (
static_cast<SHAMapLeafNode*
>(node.get()))->peekItem();
105 return {res, {
rpcINTERNAL,
"Error reading SHAMap node"}};
109 JLOG(context.
j.
debug()) <<
"Successfully fetched from db";
114 return {res, {
rpcINTERNAL,
"Error deserializing SHAMap node"}};
117 res.
txn = std::make_shared<Transaction>(sttx, reason, context.
app);
125 res.
meta = std::move(blob);
129 res.
meta = std::make_shared<TxMeta>(
137 JLOG(context.
j.
error()) <<
"Failed to fetch from db";
139 return {res, {
rpcINTERNAL,
"Containing SHAMap node not found"}};
142 JLOG(context.
j.
debug()) <<
"tx flat fetch time : "
143 << ((end - start).count() / 1000000000.0);
154 if (min >=
range.lower() && max <=
range.upper())
167 return {res, {
rpcINTERNAL,
"unexpected Postgres response"}};
181 constexpr uint16_t MAX_RANGE = 1000;
210 if (
auto e = std::get_if<TxSearched>(&v))
216 auto [txn, meta] = std::get<TxPair>(v);
229 if (txn->getLedger() == 0)
241 result.
meta = meta->getAsObject().getSerializer().getData();
260 org::xrpl::rpc::v1::GetTransactionResponse response;
261 grpc::Status status = grpc::Status::OK;
271 grpc::StatusCode::NOT_FOUND,
272 "txn not found. searched_all = " +
280 status = {grpc::StatusCode::NOT_FOUND,
"txn not found"};
282 status = {grpc::StatusCode::INTERNAL, error.message()};
288 auto& txn = result.
txn;
294 response.set_transaction_binary(s.
data(), s.
size());
301 response.set_hash(context.
params.hash());
303 auto ledgerIndex = txn->getLedger();
304 response.set_ledger_index(ledgerIndex);
310 response.mutable_date()->set_value(
311 ct->time_since_epoch().count());
315 *response.mutable_meta()->mutable_transaction_result(),
317 response.mutable_meta()->mutable_transaction_result()->set_result(
321 if (
auto blob = std::get_if<Blob>(&result.
meta))
325 response.set_meta_binary(slice.
data(), slice.
size());
335 getDeliveredAmount(context, stTxn, *meta, txn->getLedger());
339 *response.mutable_meta()->mutable_delivered_amount(),
344 response.set_validated(result.
validated);
346 return {response, status};
365 response[jss::searched_all] =
367 error.inject(response);
371 error.inject(response);
380 if (
auto blob = std::get_if<Blob>(&result.
meta))
392 insertDeliveredAmount(
393 response[jss::meta], context, result.
txn, *meta);
396 response[jss::validated] = result.
validated;
447 {grpc::StatusCode::UNIMPLEMENTED,
"Not enabled in configuration."}};
451 org::xrpl::rpc::v1::GetTransactionResponse response;
452 grpc::Status status = grpc::Status::OK;
455 org::xrpl::rpc::v1::GetTransactionRequest& request = context.
params;
465 grpc::Status errorStatus{
466 grpc::StatusCode::INVALID_ARGUMENT,
"tx hash malformed"};
467 return {response, errorStatus};
470 args.
binary = request.binary();
472 if (request.ledger_range().ledger_index_min() != 0 &&
473 request.ledger_range().ledger_index_max() != 0)
476 request.ledger_range().ledger_index_min(),
477 request.ledger_range().ledger_index_max());
std::size_t size() const noexcept
Returns the number of bytes in the storage.
virtual Family & getNodeFamily()=0
@ ledgerMaster
ledger master data for signing
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Json::Value getJson(JsonOptions options, bool binary=false) const
Json::Value rpcError(int iError)
An immutable linear range of bytes.
uint256 const & getNodestoreHash()
std::pair< org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse, grpc::Status > populateProtoResponse(std::pair< AccountTxResult, RPC::Status > const &res, AccountTxArgs const &args, RPC::GRPCContext< org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest > const &context)
void setLedger(LedgerIndex ledger)
LedgerMaster & ledgerMaster
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
Serializer getSerializer() const
std::string transToken(TER code)
static std::optional< base_uint > fromVoidChecked(T const &from)
virtual NodeStore::Database & db()=0
void const * data() const noexcept
Integers of any length that is a multiple of 32-bits.
LedgerInfo const & info() const override
Returns information about the ledger.
void convert(org::xrpl::rpc::v1::TransactionResult &to, TER from)
@ objectValue
object value (collection of name/value pairs).
virtual LedgerMaster & getLedgerMaster()=0
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > deserializeTxPlusMeta(SHAMapItem const &item)
Deserialize a SHAMapItem containing STTx + STObject metadata.
LedgerIndex getLedger() const
std::optional< std::pair< uint32_t, uint32_t > > ledgerRange
virtual Config & config()=0
std::pair< org::xrpl::rpc::v1::GetTransactionResponse, grpc::Status > doTxGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetTransactionRequest > &context)
static Locator locate(uint256 const &id, Application &app)
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
bool isMember(const char *key) const
Return true if the object has a member named key.
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Status represents the results of an operation that might fail.
static std::shared_ptr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value populateJsonResponse(std::pair< AccountTxResult, RPC::Status > const &res, AccountTxArgs const &args, RPC::JsonContext const &context)
std::pair< TxResult, RPC::Status > doTxPostgres(RPC::Context &context, TxArgs const &args)
std::size_t size() const noexcept
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
std::pair< TxResult, RPC::Status > doTxHelp(RPC::Context &context, TxArgs const &args)
void setStatus(TransStatus status, std::uint32_t ledgerSeq)
Json::Value doTxJson(RPC::JsonContext &)
std::variant< std::shared_ptr< TxMeta >, Blob > meta
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
std::variant< std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > >, TxSearched > fetch(uint256 const &, error_code_i &ec)
std::string strHex(FwdIt begin, FwdIt end)
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
Fetch a node object.
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
static bool isValidated(LedgerMaster &ledgerMaster, std::uint32_t seq, uint256 const &hash)
uint32_t getLedgerSequence()
The context of information needed to call an RPC.
std::string asString() const
Returns the unquoted string value.
virtual TransactionMaster & getMasterTransaction()=0
ClosedInterval< uint32_t > const & getLedgerRangeSearched()