rippled
RippleState.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/paths/RippleState.h>
22 #include <ripple/protocol/STAmount.h>
23 #include <cstdint>
24 #include <memory>
25 
26 namespace ripple {
27 
30  AccountID const& accountID,
32 {
33  // VFALCO Does this ever happen in practice?
34  if (!sle || sle->getType() != ltRIPPLE_STATE)
35  return {};
36  return std::make_shared<RippleState>(std::move(sle), accountID);
37 }
38 
41  AccountID const& viewAccount)
42  : sle_(std::move(sle))
43  , mFlags(sle_->getFieldU32(sfFlags))
44  , mLowLimit(sle_->getFieldAmount(sfLowLimit))
45  , mHighLimit(sle_->getFieldAmount(sfHighLimit))
46  , mLowID(mLowLimit.getIssuer())
47  , mHighID(mHighLimit.getIssuer())
48  , lowQualityIn_(sle_->getFieldU32(sfLowQualityIn))
49  , lowQualityOut_(sle_->getFieldU32(sfLowQualityOut))
50  , highQualityIn_(sle_->getFieldU32(sfHighQualityIn))
51  , highQualityOut_(sle_->getFieldU32(sfHighQualityOut))
52  , mBalance(sle_->getFieldAmount(sfBalance))
53 {
54  mViewLowest = (mLowID == viewAccount);
55 
56  if (!mViewLowest)
57  mBalance.negate();
58 }
59 
62 {
64  ret["low_id"] = to_string(mLowID);
65  ret["high_id"] = to_string(mHighID);
66  return ret;
67 }
68 
70 getRippleStateItems(AccountID const& accountID, ReadView const& view)
71 {
74  view,
75  accountID,
76  [&items, &accountID](std::shared_ptr<SLE const> const& sleCur) {
77  auto ret = RippleState::makeItem(accountID, sleCur);
78  if (ret)
79  items.push_back(ret);
80  });
81 
82  return items;
83 }
84 
85 } // namespace ripple
ripple::RippleState::pointer
std::shared_ptr< RippleState > pointer
Definition: RippleState.h:43
ripple::sfHighQualityIn
const SF_UINT32 sfHighQualityIn
ripple::STAmount::negate
void negate()
Definition: STAmount.h:386
std::shared_ptr
STL class.
std::vector
STL class.
ripple::RippleState::mLowID
AccountID const & mLowID
Definition: RippleState.h:165
ripple::forEachItem
void forEachItem(ReadView const &view, AccountID const &id, std::function< void(std::shared_ptr< SLE const > const &)> f)
Iterate all items in an account's owner directory.
Definition: View.cpp:375
std::vector::push_back
T push_back(T... args)
ripple::getRippleStateItems
std::vector< RippleState::pointer > getRippleStateItems(AccountID const &accountID, ReadView const &view)
Definition: RippleState.cpp:70
ripple::base_uint< 160, detail::AccountIDTag >
ripple::sfLowQualityOut
const SF_UINT32 sfLowQualityOut
ripple::sfLowLimit
const SF_AMOUNT sfLowLimit
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::RippleState::makeItem
static RippleState::pointer makeItem(AccountID const &accountID, std::shared_ptr< SLE const > sle)
Definition: RippleState.cpp:29
ripple::sfLowQualityIn
const SF_UINT32 sfLowQualityIn
ripple::RippleState::getJson
Json::Value getJson(int)
Definition: RippleState.cpp:61
cstdint
ripple::sfHighLimit
const SF_AMOUNT sfHighLimit
memory
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sfFlags
const SF_UINT32 sfFlags
std
STL namespace.
ripple::RippleState::RippleState
RippleState()=delete
ripple::sfBalance
const SF_AMOUNT sfBalance
ripple::RippleState::mBalance
STAmount mBalance
Definition: RippleState.h:173
ripple::sfHighQualityOut
const SF_UINT32 sfHighQualityOut
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:38
ripple::ltRIPPLE_STATE
@ ltRIPPLE_STATE
A ledger object which describes a bidirectional trust line.
Definition: LedgerFormats.h:74
ripple::RippleState::mViewLowest
bool mViewLowest
Definition: RippleState.h:158
ripple::RippleState::mHighID
AccountID const & mHighID
Definition: RippleState.h:166
Json::Value
Represents a JSON value.
Definition: json_value.h:145