rippled
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 <ripple/app/ledger/AcceptedLedgerTx.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/basics/Log.h>
23 #include <ripple/basics/StringUtilities.h>
24 #include <ripple/protocol/UintTypes.h>
25 #include <ripple/protocol/jss.h>
26 
27 namespace ripple {
28 
30  std::shared_ptr<ReadView const> const& ledger,
31  std::shared_ptr<STTx const> const& txn,
33  AccountIDCache const& accountCache,
34  Logs& logs)
35  : mLedger(ledger)
36  , mTxn(txn)
37  , mMeta(std::make_shared<TxMeta>(
38  txn->getTransactionID(),
39  ledger->seq(),
40  *met))
41  , mAffected(mMeta->getAffectedAccounts(logs.journal("View")))
42  , accountCache_(accountCache)
43  , logs_(logs)
44 {
45  assert(!ledger->open());
46 
47  mResult = mMeta->getResultTER();
48 
49  Serializer s;
50  met->add(s);
51  mRawMeta = std::move(s.modData());
52 
53  buildJson();
54 }
55 
57  std::shared_ptr<ReadView const> const& ledger,
58  std::shared_ptr<STTx const> const& txn,
59  TER result,
60  AccountIDCache const& accountCache,
61  Logs& logs)
62  : mLedger(ledger)
63  , mTxn(txn)
64  , mResult(result)
65  , mAffected(txn->getMentionedAccounts())
66  , accountCache_(accountCache)
67  , logs_(logs)
68 {
69  assert(ledger->open());
70  buildJson();
71 }
72 
75 {
76  assert(!mRawMeta.empty());
77  return sqlEscape(mRawMeta);
78 }
79 
80 void
82 {
84  mJson[jss::transaction] = mTxn->getJson(JsonOptions::none);
85 
86  if (mMeta)
87  {
88  mJson[jss::meta] = mMeta->getJson(JsonOptions::none);
89  mJson[jss::raw_meta] = strHex(mRawMeta);
90  }
91 
92  mJson[jss::result] = transHuman(mResult);
93 
94  if (!mAffected.empty())
95  {
96  Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
97  for (auto const& account : mAffected)
98  affected.append(accountCache_.toBase58(account));
99  }
100 
101  if (mTxn->getTxnType() == ttOFFER_CREATE)
102  {
103  auto const& account = mTxn->getAccountID(sfAccount);
104  auto const amount = mTxn->getFieldAmount(sfTakerGets);
105 
106  // If the offer create is not self funded then add the owner balance
107  if (account != amount.issue().account)
108  {
109  auto const ownerFunds = accountFunds(
110  *mLedger,
111  account,
112  amount,
114  logs_.journal("View"));
115  mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText();
116  }
117  }
118 }
119 
120 } // namespace ripple
std::string
STL class.
std::shared_ptr
STL class.
ripple::AcceptedLedgerTx::mLedger
std::shared_ptr< ReadView const > mLedger
Definition: AcceptedLedgerTx.h:127
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
ripple::Serializer::modData
Blob & modData()
Definition: Serializer.h:176
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
ripple::ttOFFER_CREATE
@ ttOFFER_CREATE
Definition: TxFormats.h:43
ripple::AcceptedLedgerTx::mJson
Json::Value mJson
Definition: AcceptedLedgerTx.h:133
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:480
ripple::sqlEscape
static std::string sqlEscape(std::string const &strSrc)
Definition: StringUtilities.h:34
ripple::AccountIDCache
Caches the base58 representations of AccountIDs.
Definition: AccountID.h:147
ripple::AcceptedLedgerTx::AcceptedLedgerTx
AcceptedLedgerTx(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &, std::shared_ptr< STObject const > const &, AccountIDCache const &, Logs &)
Definition: AcceptedLedgerTx.cpp:29
ripple::TxMeta
Definition: TxMeta.h:32
ripple::AcceptedLedgerTx::logs_
Logs & logs_
Definition: AcceptedLedgerTx.h:135
ripple::AcceptedLedgerTx::accountCache_
AccountIDCache const & accountCache_
Definition: AcceptedLedgerTx.h:134
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:882
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::JsonOptions::none
@ none
ripple::TERSubset< CanCvtToTER >
ripple::AcceptedLedgerTx::mRawMeta
Blob mRawMeta
Definition: AcceptedLedgerTx.h:132
ripple::transHuman
std::string transHuman(TER code)
Definition: TER.cpp:202
ripple::accountFunds
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:136
ripple::AcceptedLedgerTx::getEscMeta
std::string getEscMeta() const
Definition: AcceptedLedgerTx.cpp:74
ripple::Serializer
Definition: Serializer.h:39
ripple::AcceptedLedgerTx::buildJson
void buildJson()
Definition: AcceptedLedgerTx.cpp:81
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::AcceptedLedgerTx::mTxn
std::shared_ptr< STTx const > mTxn
Definition: AcceptedLedgerTx.h:128
ripple::Logs::journal
beast::Journal journal(std::string const &name)
Definition: Log.cpp:144
std
STL namespace.
ripple::AcceptedLedgerTx::mMeta
std::shared_ptr< TxMeta > mMeta
Definition: AcceptedLedgerTx.h:129
ripple::sfTakerGets
const SF_Amount sfTakerGets(access, STI_AMOUNT, 5, "TakerGets")
Definition: SField.h:444
std::vector::empty
T empty(T... args)
ripple::fhIGNORE_FREEZE
@ fhIGNORE_FREEZE
Definition: View.h:53
ripple::AcceptedLedgerTx::mAffected
boost::container::flat_set< AccountID > mAffected
Definition: AcceptedLedgerTx.h:131
ripple::strHex
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:67
ripple::AcceptedLedgerTx::mResult
TER mResult
Definition: AcceptedLedgerTx.h:130
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::AccountIDCache::toBase58
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
Definition: AccountID.cpp:190