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/basics/Log.h>
22 #include <ripple/basics/StringUtilities.h>
23 #include <ripple/protocol/UintTypes.h>
24 #include <ripple/protocol/jss.h>
25 
26 namespace ripple {
27 
29  std::shared_ptr<ReadView const> const& ledger,
30  std::shared_ptr<STTx const> const& txn,
32  : mTxn(txn)
33  , mMeta(txn->getTransactionID(), ledger->seq(), *met)
34  , mAffected(mMeta.getAffectedAccounts())
35 {
36  assert(!ledger->open());
37 
38  Serializer s;
39  met->add(s);
40  mRawMeta = std::move(s.modData());
41 
43  mJson[jss::transaction] = mTxn->getJson(JsonOptions::none);
44 
45  mJson[jss::meta] = mMeta.getJson(JsonOptions::none);
46  mJson[jss::raw_meta] = strHex(mRawMeta);
47 
48  mJson[jss::result] = transHuman(mMeta.getResultTER());
49 
50  if (!mAffected.empty())
51  {
52  Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
53  for (auto const& account : mAffected)
54  affected.append(toBase58(account));
55  }
56 
57  if (mTxn->getTxnType() == ttOFFER_CREATE)
58  {
59  auto const& account = mTxn->getAccountID(sfAccount);
60  auto const amount = mTxn->getFieldAmount(sfTakerGets);
61 
62  // If the offer create is not self funded then add the owner balance
63  if (account != amount.issue().account)
64  {
65  auto const ownerFunds = accountFunds(
66  *ledger,
67  account,
68  amount,
71  mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText();
72  }
73  }
74 }
75 
78 {
79  assert(!mRawMeta.empty());
80  return sqlBlobLiteral(mRawMeta);
81 }
82 
83 } // namespace ripple
ripple::AcceptedLedgerTx::mMeta
TxMeta mMeta
Definition: AcceptedLedgerTx.h:99
std::string
STL class.
std::shared_ptr
STL class.
ripple::Serializer::modData
Blob & modData()
Definition: Serializer.h:178
Json::arrayValue
@ arrayValue
array value (ordered list)
Definition: json_value.h:42
ripple::AcceptedLedgerTx::mJson
Json::Value mJson
Definition: AcceptedLedgerTx.h:102
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
ripple::TxMeta::getResultTER
TER getResultTER() const
Definition: TxMeta.h:68
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::sfTakerGets
const SF_AMOUNT sfTakerGets
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::TxMeta::getJson
Json::Value getJson(JsonOptions p) const
Definition: TxMeta.h:90
ripple::AcceptedLedgerTx::mRawMeta
Blob mRawMeta
Definition: AcceptedLedgerTx.h:101
ripple::transHuman
std::string transHuman(TER code)
Definition: TER.cpp:219
ripple::accountFunds
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:267
ripple::ttOFFER_CREATE
@ ttOFFER_CREATE
This transaction type creates an offer to trade one asset for another.
Definition: TxFormats.h:80
ripple::AcceptedLedgerTx::getEscMeta
std::string getEscMeta() const
Definition: AcceptedLedgerTx.cpp:77
ripple::Serializer
Definition: Serializer.h:39
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:98
ripple::AcceptedLedgerTx::AcceptedLedgerTx
AcceptedLedgerTx(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &, std::shared_ptr< STObject const > const &)
Definition: AcceptedLedgerTx.cpp:28
std::vector::empty
T empty(T... args)
ripple::fhIGNORE_FREEZE
@ fhIGNORE_FREEZE
Definition: View.h:76
ripple::AcceptedLedgerTx::mAffected
boost::container::flat_set< AccountID > mAffected
Definition: AcceptedLedgerTx.h:100
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::strHex
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
ripple::sqlBlobLiteral
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
Definition: StringUtilities.cpp:33
Json::Value
Represents a JSON value.
Definition: json_value.h:145