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/main/Application.h>
21 #include <ripple/app/ledger/AcceptedLedgerTx.h>
22 #include <ripple/basics/Log.h>
23 #include <ripple/basics/StringUtilities.h>
24 #include <ripple/protocol/jss.h>
25 #include <ripple/protocol/UintTypes.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(), ledger->seq(), *met))
39  , mAffected (mMeta->getAffectedAccounts (logs.journal("View")))
40  , accountCache_ (accountCache)
41  , logs_ (logs)
42 {
43  assert (! ledger->open());
44 
45  mResult = mMeta->getResultTER ();
46 
47  Serializer s;
48  met->add(s);
49  mRawMeta = std::move (s.modData());
50 
51  buildJson ();
52 }
53 
55  std::shared_ptr<ReadView const> const& ledger,
56  std::shared_ptr<STTx const> const& txn,
57  TER result,
58  AccountIDCache const& accountCache,
59  Logs& logs)
60  : mLedger (ledger)
61  , mTxn (txn)
62  , mResult (result)
63  , mAffected (txn->getMentionedAccounts ())
64  , accountCache_ (accountCache)
65  , logs_ (logs)
66 {
67  assert (ledger->open());
68  buildJson ();
69 }
70 
72 {
73  assert (!mRawMeta.empty ());
74  return sqlEscape (mRawMeta);
75 }
76 
78 {
80  mJson[jss::transaction] = mTxn->getJson (JsonOptions::none);
81 
82  if (mMeta)
83  {
84  mJson[jss::meta] = mMeta->getJson (JsonOptions::none);
85  mJson[jss::raw_meta] = strHex (mRawMeta);
86  }
87 
88  mJson[jss::result] = transHuman (mResult);
89 
90  if (! mAffected.empty ())
91  {
92  Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
93  for (auto const& account: mAffected)
94  affected.append (accountCache_.toBase58(account));
95  }
96 
97  if (mTxn->getTxnType () == ttOFFER_CREATE)
98  {
99  auto const& account = mTxn->getAccountID(sfAccount);
100  auto const amount = mTxn->getFieldAmount (sfTakerGets);
101 
102  // If the offer create is not self funded then add the owner balance
103  if (account != amount.issue ().account)
104  {
105  auto const ownerFunds = accountFunds(*mLedger,
106  account, amount, fhIGNORE_FREEZE, logs_.journal ("View"));
107  mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText ();
108  }
109  }
110 }
111 
112 } // ripple
std::string
STL class.
std::shared_ptr
STL class.
ripple::AcceptedLedgerTx::mLedger
std::shared_ptr< ReadView const > mLedger
Definition: AcceptedLedgerTx.h:117
ripple::Logs
Manages partitions for logging.
Definition: Log.h:49
ripple::Serializer::modData
Blob & modData()
Definition: Serializer.h:181
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:44
ripple::ttOFFER_CREATE
@ ttOFFER_CREATE
Definition: TxFormats.h:44
ripple::AcceptedLedgerTx::mJson
Json::Value mJson
Definition: AcceptedLedgerTx.h:123
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:460
ripple::sqlEscape
static std::string sqlEscape(std::string const &strSrc)
Definition: StringUtilities.h:33
ripple::AccountIDCache
Caches the base58 representations of AccountIDs.
Definition: AccountID.h:150
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:33
ripple::AcceptedLedgerTx::logs_
Logs & logs_
Definition: AcceptedLedgerTx.h:125
ripple::AcceptedLedgerTx::accountCache_
AccountIDCache const & accountCache_
Definition: AcceptedLedgerTx.h:124
Json::Value::append
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:907
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:45
ripple::JsonOptions::none
@ none
ripple::TERSubset< CanCvtToTER >
ripple::AcceptedLedgerTx::mRawMeta
Blob mRawMeta
Definition: AcceptedLedgerTx.h:122
ripple::transHuman
std::string transHuman(TER code)
Definition: TER.cpp:191
ripple::accountFunds
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:133
ripple::AcceptedLedgerTx::getEscMeta
std::string getEscMeta() const
Definition: AcceptedLedgerTx.cpp:71
ripple::Serializer
Definition: Serializer.h:43
ripple::AcceptedLedgerTx::buildJson
void buildJson()
Definition: AcceptedLedgerTx.cpp:77
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:118
ripple::Logs::journal
beast::Journal journal(std::string const &name)
Definition: Log.cpp:140
std
STL namespace.
ripple::AcceptedLedgerTx::mMeta
std::shared_ptr< TxMeta > mMeta
Definition: AcceptedLedgerTx.h:119
ripple::sfTakerGets
const SF_Amount sfTakerGets(access, STI_AMOUNT, 5, "TakerGets")
Definition: SField.h:427
std::vector::empty
T empty(T... args)
ripple::fhIGNORE_FREEZE
@ fhIGNORE_FREEZE
Definition: View.h:55
ripple::AcceptedLedgerTx::mAffected
boost::container::flat_set< AccountID > mAffected
Definition: AcceptedLedgerTx.h:121
ripple::strHex
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:70
ripple::AcceptedLedgerTx::mResult
TER mResult
Definition: AcceptedLedgerTx.h:120
Json::Value
Represents a JSON value.
Definition: json_value.h:141
ripple::AccountIDCache::toBase58
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
Definition: AccountID.cpp:199