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
22#include <xrpl/basics/Log.h>
23#include <xrpl/basics/StringUtilities.h>
24#include <xrpl/protocol/UintTypes.h>
25#include <xrpl/protocol/jss.h>
26
27namespace ripple {
28
33 : mTxn(txn)
34 , mMeta(txn->getTransactionID(), ledger->seq(), *met)
35 , mAffected(mMeta.getAffectedAccounts())
36{
37 XRPL_ASSERT(
38 !ledger->open(),
39 "ripple::AcceptedLedgerTx::AcceptedLedgerTx : valid ledger state");
40
41 Serializer s;
42 met->add(s);
43 mRawMeta = std::move(s.modData());
44
46 mJson[jss::transaction] = mTxn->getJson(JsonOptions::none);
47
49 mJson[jss::raw_meta] = strHex(mRawMeta);
50
51 mJson[jss::result] = transHuman(mMeta.getResultTER());
52
53 if (!mAffected.empty())
54 {
55 Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
56 for (auto const& account : mAffected)
57 affected.append(toBase58(account));
58 }
59
60 if (mTxn->getTxnType() == ttOFFER_CREATE)
61 {
62 auto const& account = mTxn->getAccountID(sfAccount);
63 auto const amount = mTxn->getFieldAmount(sfTakerGets);
64
65 // If the offer create is not self funded then add the owner balance
66 if (account != amount.issue().account)
67 {
68 auto const ownerFunds = accountFunds(
69 *ledger,
70 account,
71 amount,
74 mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText();
75 }
76 }
77}
78
81{
82 XRPL_ASSERT(
83 !mRawMeta.empty(),
84 "ripple::AcceptedLedgerTx::getEscMeta : metadata is set");
86}
87
88} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Value & append(Value const &value)
Append value to array at the end.
A generic endpoint for log messages.
Definition Journal.h:60
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:95
TER getResultTER() const
Definition TxMeta.h:73
T empty(T... args)
@ arrayValue
array value (ordered list)
Definition json_value.h:44
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string transHuman(TER code)
Definition TER.cpp:273
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition View.cpp:551
@ fhIGNORE_FREEZE
Definition View.h:77
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