rippled
Loading...
Searching...
No Matches
AcceptedLedgerTx.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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/AcceptedLedgerTx.h>
21#include <xrpl/basics/Log.h>
22#include <xrpl/basics/StringUtilities.h>
23#include <xrpl/protocol/UintTypes.h>
24#include <xrpl/protocol/jss.h>
25
26namespace ripple {
27
32 : mTxn(txn)
33 , mMeta(txn->getTransactionID(), ledger->seq(), *met)
34 , mAffected(mMeta.getAffectedAccounts())
35{
36 XRPL_ASSERT(
37 !ledger->open(),
38 "ripple::AcceptedLedgerTx::AcceptedLedgerTx : valid ledger state");
39
40 Serializer s;
41 met->add(s);
42 mRawMeta = std::move(s.modData());
43
45 mJson[jss::transaction] = mTxn->getJson(JsonOptions::none);
46
48 mJson[jss::raw_meta] = strHex(mRawMeta);
49
50 mJson[jss::result] = transHuman(mMeta.getResultTER());
51
52 if (!mAffected.empty())
53 {
54 Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
55 for (auto const& account : mAffected)
56 affected.append(toBase58(account));
57 }
58
59 if (mTxn->getTxnType() == ttOFFER_CREATE)
60 {
61 auto const& account = mTxn->getAccountID(sfAccount);
62 auto const amount = mTxn->getFieldAmount(sfTakerGets);
63
64 // If the offer create is not self funded then add the owner balance
65 if (account != amount.issue().account)
66 {
67 auto const ownerFunds = accountFunds(
68 *ledger,
69 account,
70 amount,
73 mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText();
74 }
75 }
76}
77
80{
81 XRPL_ASSERT(
82 !mRawMeta.empty(),
83 "ripple::AcceptedLedgerTx::getEscMeta : metadata is set");
85}
86
87} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:891
A generic endpoint for log messages.
Definition: Journal.h:59
static Sink & getNullSink()
Returns a Sink which does nothing.
boost::container::flat_set< AccountID > mAffected
std::shared_ptr< STTx const > mTxn
AcceptedLedgerTx(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &, std::shared_ptr< STObject const > const &)
std::string getEscMeta() const
Json::Value getJson(JsonOptions p) const
Definition: TxMeta.h:90
TER getResultTER() const
Definition: TxMeta.h:68
T empty(T... args)
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string transHuman(TER code)
Definition: TER.cpp:260
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:106
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:442
@ fhIGNORE_FREEZE
Definition: View.h:80
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30