xrpld
Loading...
Searching...
No Matches
AcceptedLedgerTx.cpp
1#include <xrpl/ledger/AcceptedLedgerTx.h>
2
3#include <xrpl/basics/StringUtilities.h>
4#include <xrpl/basics/strHex.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/ledger/helpers/TokenHelpers.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STObject.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/Serializer.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/TxFormats.h>
16#include <xrpl/protocol/jss.h>
17
18#include <memory>
19#include <string>
20#include <utility>
21
22namespace xrpl {
23
28 : txn_(txn)
29 , meta_(txn->getTransactionID(), ledger->seq(), *met)
30 , affected_(meta_.getAffectedAccounts())
31{
32 XRPL_ASSERT(!ledger->open(), "xrpl::AcceptedLedgerTx::AcceptedLedgerTx : valid ledger state");
33
34 Serializer s;
35 met->add(s);
36 rawMeta_ = std::move(s.modData());
37
39 json_[jss::transaction] = txn_->getJson(JsonOptions::Values::None);
40
41 json_[jss::meta] = meta_.getJson(JsonOptions::Values::None);
42 json_[jss::raw_meta] = strHex(rawMeta_);
43
44 json_[jss::result] = transHuman(meta_.getResultTER());
45
46 if (!affected_.empty())
47 {
48 json::Value& affected = (json_[jss::affected] = json::ValueType::Array);
49 for (auto const& account : affected_)
50 affected.append(toBase58(account));
51 }
52
53 if (txn_->getTxnType() == ttOFFER_CREATE)
54 {
55 auto const& account = txn_->getAccountID(sfAccount);
56 auto const amount = txn_->getFieldAmount(sfTakerGets);
57
58 // If the offer create is not self funded then add the owner balance
59 if (account != amount.getIssuer())
60 {
61 auto const ownerFunds = accountFunds(
62 *ledger,
63 account,
64 amount,
68 json_[jss::transaction][jss::owner_funds] = ownerFunds.getText();
69 }
70 }
71}
72
75{
76 XRPL_ASSERT(!rawMeta_.empty(), "xrpl::AcceptedLedgerTx::getEscMeta : metadata is set");
78}
79
80} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
static Sink & getNullSink()
Returns a Sink which does nothing.
Represents a JSON value.
Definition json_value.h:130
Value & append(Value const &value)
Append value to array at the end.
std::string getEscMeta() const
boost::container::flat_set< AccountID > affected_
std::shared_ptr< STTx const > txn_
AcceptedLedgerTx(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &, std::shared_ptr< STObject const > const &)
@ Array
array value (ordered list)
Definition json_value.h:25
@ Object
object value (collection of name/value pairs).
Definition json_value.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
std::string transHuman(TER code)
Definition TER.cpp:256
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".