mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-02 10:02:27 +00:00
Move Trustline to xrpl/ledger
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
224
include/xrpl/ledger/TrustLine.h
Normal file
224
include/xrpl/ledger/TrustLine.h
Normal file
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
* @file TrustLine.h
|
||||
* @brief Wrapper for trust line (RippleState) ledger entries.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/Rate.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
#include <xrpl/protocol_autogen/ledger_entries/RippleState.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/**
|
||||
* @brief Describes how an account was found in a path.
|
||||
*
|
||||
* "Outgoing" is defined as the source account, or an account found via a
|
||||
* trust line that has rippling enabled on the account's side.
|
||||
*
|
||||
* "Incoming" is defined as an account found via a trust line that has rippling
|
||||
* disabled on the account's side. Any trust lines for an incoming account that
|
||||
* have rippling disabled are unusable in paths.
|
||||
*/
|
||||
enum class LineDirection : bool { incoming = false, outgoing = true };
|
||||
|
||||
/**
|
||||
* @brief Wraps a trust line SLE for convenience.
|
||||
*
|
||||
* The complication of trust lines is that there is a "low" account and a
|
||||
* "high" account. This wraps the SLE and expresses its data from the
|
||||
* perspective of a chosen account on the line.
|
||||
*
|
||||
* This class uses a thin wrapper around the SLE to minimise memory usage.
|
||||
* The SLE must remain valid for the lifetime of this object.
|
||||
*/
|
||||
class TrustLine final : public CountedObject<TrustLine>
|
||||
{
|
||||
public:
|
||||
TrustLine() = delete;
|
||||
|
||||
/**
|
||||
* @brief Construct a TrustLine from a RippleState ledger entry.
|
||||
* @param rippleState The RippleState ledger entry.
|
||||
* @param viewAccount The account from whose perspective to view the line.
|
||||
*/
|
||||
TrustLine(ledger_entries::RippleState const& rippleState, AccountID const& viewAccount);
|
||||
|
||||
/**
|
||||
* @brief Create a TrustLine from an SLE if it is a valid RippleState.
|
||||
* @param accountID The account from whose perspective to view the line.
|
||||
* @param sle The shared ledger entry.
|
||||
* @return The TrustLine, or nullopt if the SLE is not a RippleState.
|
||||
*/
|
||||
static std::optional<TrustLine>
|
||||
makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
|
||||
|
||||
/**
|
||||
* @brief Get all trust lines for an account.
|
||||
* @param accountID The account to get trust lines for.
|
||||
* @param view The ledger view to read from.
|
||||
* @param direction Filter by line direction (default: outgoing).
|
||||
* @return A vector of TrustLine objects.
|
||||
*/
|
||||
static std::vector<TrustLine>
|
||||
getItems(
|
||||
AccountID const& accountID,
|
||||
ReadView const& view,
|
||||
LineDirection direction = LineDirection::outgoing);
|
||||
|
||||
/**
|
||||
* @brief Returns the state map key for the ledger entry.
|
||||
* @return The key (hash) of the RippleState entry.
|
||||
*/
|
||||
uint256 const&
|
||||
key() const;
|
||||
|
||||
/**
|
||||
* @brief Get our account ID.
|
||||
* @return The account ID from whose perspective this line is viewed.
|
||||
*/
|
||||
AccountID const&
|
||||
getAccountID() const;
|
||||
|
||||
/**
|
||||
* @brief Get the peer's account ID.
|
||||
* @return The account ID of the other party on this trust line.
|
||||
*/
|
||||
AccountID const&
|
||||
getAccountIDPeer() const;
|
||||
|
||||
/**
|
||||
* @brief Check if we have authorised the peer.
|
||||
* @return True if we have provided authorisation to the peer.
|
||||
*/
|
||||
bool
|
||||
getAuth() const;
|
||||
|
||||
/**
|
||||
* @brief Check if the peer has authorised us.
|
||||
* @return True if the peer has provided authorisation to us.
|
||||
*/
|
||||
bool
|
||||
getAuthPeer() const;
|
||||
|
||||
/**
|
||||
* @brief Check if we have the NoRipple flag set.
|
||||
* @return True if NoRipple is set on our side.
|
||||
*/
|
||||
bool
|
||||
getNoRipple() const;
|
||||
|
||||
/**
|
||||
* @brief Check if the peer has the NoRipple flag set.
|
||||
* @return True if NoRipple is set on the peer's side.
|
||||
*/
|
||||
bool
|
||||
getNoRipplePeer() const;
|
||||
|
||||
/**
|
||||
* @brief Get our line direction based on NoRipple flag.
|
||||
* @return Incoming if NoRipple is set, outgoing otherwise.
|
||||
*/
|
||||
LineDirection
|
||||
getDirection() const
|
||||
{
|
||||
return getNoRipple() ? LineDirection::incoming : LineDirection::outgoing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the peer's line direction based on their NoRipple flag.
|
||||
* @return Incoming if peer's NoRipple is set, outgoing otherwise.
|
||||
*/
|
||||
LineDirection
|
||||
getDirectionPeer() const
|
||||
{
|
||||
return getNoRipplePeer() ? LineDirection::incoming : LineDirection::outgoing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if we have frozen the peer.
|
||||
* @return True if we have set the freeze flag on the peer.
|
||||
*/
|
||||
bool
|
||||
getFreeze() const;
|
||||
|
||||
/**
|
||||
* @brief Check if we have deep frozen the peer.
|
||||
* @return True if we have set the deep freeze flag on the peer.
|
||||
*/
|
||||
bool
|
||||
getDeepFreeze() const;
|
||||
|
||||
/**
|
||||
* @brief Check if the peer has frozen us.
|
||||
* @return True if the peer has set the freeze flag on us.
|
||||
*/
|
||||
bool
|
||||
getFreezePeer() const;
|
||||
|
||||
/**
|
||||
* @brief Check if the peer has deep frozen us.
|
||||
* @return True if the peer has set the deep freeze flag on us.
|
||||
*/
|
||||
bool
|
||||
getDeepFreezePeer() const;
|
||||
|
||||
/**
|
||||
* @brief Get the balance on this trust line.
|
||||
* @return The balance from our perspective (positive = we hold IOUs).
|
||||
*/
|
||||
STAmount
|
||||
getBalance() const;
|
||||
|
||||
/**
|
||||
* @brief Get our trust limit.
|
||||
* @return The maximum amount we are willing to hold.
|
||||
*/
|
||||
STAmount
|
||||
getLimit() const;
|
||||
|
||||
/**
|
||||
* @brief Get the peer's trust limit.
|
||||
* @return The maximum amount the peer is willing to hold.
|
||||
*/
|
||||
STAmount
|
||||
getLimitPeer() const;
|
||||
|
||||
/**
|
||||
* @brief Get the quality in rate.
|
||||
* @return The rate applied to incoming payments.
|
||||
*/
|
||||
Rate
|
||||
getQualityIn() const;
|
||||
|
||||
/**
|
||||
* @brief Get the quality out rate.
|
||||
* @return The rate applied to outgoing payments.
|
||||
*/
|
||||
Rate
|
||||
getQualityOut() const;
|
||||
|
||||
/**
|
||||
* @brief Get a JSON representation of this trust line.
|
||||
* @param level Detail level for the JSON output.
|
||||
* @return JSON value representing this trust line.
|
||||
*/
|
||||
Json::Value
|
||||
getJson(int level);
|
||||
|
||||
private:
|
||||
TrustLine(std::shared_ptr<SLE const> sle, AccountID const& viewAccount);
|
||||
|
||||
ledger_entries::RippleState rippleState_; /**< The underlying RippleState entry. */
|
||||
bool viewLowest_; /**< True if viewAccount is the low account. */
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
165
src/libxrpl/ledger/TrustLine.cpp
Normal file
165
src/libxrpl/ledger/TrustLine.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/LedgerFormats.h>
|
||||
#include <xrpl/protocol/Quality.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
TrustLine::TrustLine(std::shared_ptr<SLE const> sle, AccountID const& viewAccount)
|
||||
: rippleState_(std::move(sle))
|
||||
, viewLowest_(rippleState_.getLowLimit().getIssuer() == viewAccount)
|
||||
{
|
||||
}
|
||||
|
||||
TrustLine::TrustLine(ledger_entries::RippleState const& rippleState, AccountID const& viewAccount)
|
||||
: rippleState_(rippleState), viewLowest_(rippleState_.getLowLimit().getIssuer() == viewAccount)
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<TrustLine>
|
||||
TrustLine::makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle)
|
||||
{
|
||||
if (!sle || sle->getType() != ltRIPPLE_STATE)
|
||||
return {};
|
||||
return TrustLine{sle, accountID};
|
||||
}
|
||||
|
||||
std::vector<TrustLine>
|
||||
TrustLine::getItems(AccountID const& accountID, ReadView const& view, LineDirection direction)
|
||||
{
|
||||
std::vector<TrustLine> items;
|
||||
forEachItem(
|
||||
view,
|
||||
accountID,
|
||||
[&items, &accountID, &direction](std::shared_ptr<SLE const> const& sleCur) {
|
||||
auto line = TrustLine::makeItem(accountID, sleCur);
|
||||
if (line && (direction == LineDirection::outgoing || !line->getNoRipple()))
|
||||
items.push_back(std::move(*line));
|
||||
});
|
||||
items.shrink_to_fit();
|
||||
return items;
|
||||
}
|
||||
|
||||
uint256 const&
|
||||
TrustLine::key() const
|
||||
{
|
||||
return rippleState_.getSle()->key();
|
||||
}
|
||||
|
||||
AccountID const&
|
||||
TrustLine::getAccountID() const
|
||||
{
|
||||
return viewLowest_ ? rippleState_.getLowLimit().getIssuer()
|
||||
: rippleState_.getHighLimit().getIssuer();
|
||||
}
|
||||
|
||||
AccountID const&
|
||||
TrustLine::getAccountIDPeer() const
|
||||
{
|
||||
return !viewLowest_ ? rippleState_.getLowLimit().getIssuer()
|
||||
: rippleState_.getHighLimit().getIssuer();
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getAuth() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (viewLowest_ ? lsfLowAuth : lsfHighAuth);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getAuthPeer() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (!viewLowest_ ? lsfLowAuth : lsfHighAuth);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getNoRipple() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getNoRipplePeer() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (!viewLowest_ ? lsfLowNoRipple : lsfHighNoRipple);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getFreeze() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (viewLowest_ ? lsfLowFreeze : lsfHighFreeze);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getDeepFreeze() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getFreezePeer() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (!viewLowest_ ? lsfLowFreeze : lsfHighFreeze);
|
||||
}
|
||||
|
||||
bool
|
||||
TrustLine::getDeepFreezePeer() const
|
||||
{
|
||||
auto const flags = rippleState_.getFlags();
|
||||
return flags & (!viewLowest_ ? lsfLowDeepFreeze : lsfHighDeepFreeze);
|
||||
}
|
||||
|
||||
STAmount
|
||||
TrustLine::getBalance() const
|
||||
{
|
||||
auto balance = rippleState_.getBalance();
|
||||
if (!viewLowest_)
|
||||
balance.negate();
|
||||
return balance;
|
||||
}
|
||||
|
||||
STAmount
|
||||
TrustLine::getLimit() const
|
||||
{
|
||||
return viewLowest_ ? rippleState_.getLowLimit() : rippleState_.getHighLimit();
|
||||
}
|
||||
|
||||
STAmount
|
||||
TrustLine::getLimitPeer() const
|
||||
{
|
||||
return !viewLowest_ ? rippleState_.getLowLimit() : rippleState_.getHighLimit();
|
||||
}
|
||||
|
||||
Rate
|
||||
TrustLine::getQualityIn() const
|
||||
{
|
||||
auto const quality =
|
||||
viewLowest_ ? rippleState_.getLowQualityIn() : rippleState_.getHighQualityIn();
|
||||
return Rate{quality.value_or(QUALITY_ONE)};
|
||||
}
|
||||
|
||||
Rate
|
||||
TrustLine::getQualityOut() const
|
||||
{
|
||||
auto const quality =
|
||||
viewLowest_ ? rippleState_.getLowQualityOut() : rippleState_.getHighQualityOut();
|
||||
return Rate{quality.value_or(QUALITY_ONE)};
|
||||
}
|
||||
|
||||
Json::Value
|
||||
TrustLine::getJson(int)
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
ret["low_id"] = to_string(rippleState_.getLowLimit().getIssuer());
|
||||
ret["high_id"] = to_string(rippleState_.getHighLimit().getIssuer());
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -18,7 +18,7 @@ accountSourceCurrencies(
|
||||
{
|
||||
for (auto const& rspEntry : *lines)
|
||||
{
|
||||
auto& saBalance = rspEntry.getBalance();
|
||||
auto saBalance = rspEntry.getBalance();
|
||||
|
||||
// Filter out non
|
||||
if (saBalance > beast::zero
|
||||
@@ -52,7 +52,7 @@ accountDestCurrencies(
|
||||
{
|
||||
for (auto const& rspEntry : *lines)
|
||||
{
|
||||
auto& saBalance = rspEntry.getBalance();
|
||||
auto saBalance = rspEntry.getBalance();
|
||||
|
||||
if (saBalance < rspEntry.getLimit()) // Can take more
|
||||
currencies.insert(saBalance.getCurrency());
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/DeliveredAmount.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <xrpld/rpc/detail/RippleLineCache.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -16,7 +17,7 @@ RippleLineCache::~RippleLineCache()
|
||||
<< " distinct trust lines.";
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<PathFindTrustLine>>
|
||||
std::shared_ptr<std::vector<TrustLine>>
|
||||
RippleLineCache::getRippleLines(AccountID const& accountID, LineDirection direction)
|
||||
{
|
||||
auto const hash = hasher_(accountID);
|
||||
@@ -75,10 +76,10 @@ RippleLineCache::getRippleLines(AccountID const& accountID, LineDirection direct
|
||||
if (inserted)
|
||||
{
|
||||
XRPL_ASSERT(it->second == nullptr, "xrpl::RippleLineCache::getRippleLines : null lines");
|
||||
auto lines = PathFindTrustLine::getItems(accountID, *ledger_, direction);
|
||||
auto lines = TrustLine::getItems(accountID, *ledger_, direction);
|
||||
if (lines.size())
|
||||
{
|
||||
it->second = std::make_shared<std::vector<PathFindTrustLine>>(std::move(lines));
|
||||
it->second = std::make_shared<std::vector<TrustLine>>(std::move(lines));
|
||||
totalLineCount_ += it->second->size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
#include <xrpl/basics/hardened_hash.h>
|
||||
#include <xrpl/ledger/Ledger.h>
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <mutex>
|
||||
@@ -37,7 +36,7 @@ public:
|
||||
@accountID's side.
|
||||
@return Returns a vector of the usable trust lines.
|
||||
*/
|
||||
std::shared_ptr<std::vector<PathFindTrustLine>>
|
||||
std::shared_ptr<std::vector<TrustLine>>
|
||||
getRippleLines(AccountID const& accountID, LineDirection direction);
|
||||
|
||||
private:
|
||||
@@ -94,7 +93,7 @@ private:
|
||||
// most accounts are not going to have any entries (estimated over 90%), so
|
||||
// vectors will not need to be created for them. This should lead to far
|
||||
// less memory usage overall.
|
||||
hash_map<AccountKey, std::shared_ptr<std::vector<PathFindTrustLine>>, AccountKey::Hash> lines_;
|
||||
hash_map<AccountKey, std::shared_ptr<std::vector<TrustLine>>, AccountKey::Hash> lines_;
|
||||
std::size_t totalLineCount_ = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/protocol/STAmount.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
TrustLineBase::TrustLineBase(std::shared_ptr<SLE const> const& sle, AccountID const& viewAccount)
|
||||
: key_(sle->key())
|
||||
, mLowLimit(sle->getFieldAmount(sfLowLimit))
|
||||
, mHighLimit(sle->getFieldAmount(sfHighLimit))
|
||||
, mBalance(sle->getFieldAmount(sfBalance))
|
||||
, mFlags(sle->getFieldU32(sfFlags))
|
||||
, mViewLowest(mLowLimit.getIssuer() == viewAccount)
|
||||
{
|
||||
if (!mViewLowest)
|
||||
mBalance.negate();
|
||||
}
|
||||
|
||||
Json::Value
|
||||
TrustLineBase::getJson(int)
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
ret["low_id"] = to_string(mLowLimit.getIssuer());
|
||||
ret["high_id"] = to_string(mHighLimit.getIssuer());
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<PathFindTrustLine>
|
||||
PathFindTrustLine::makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle)
|
||||
{
|
||||
if (!sle || sle->getType() != ltRIPPLE_STATE)
|
||||
return {};
|
||||
return std::optional{PathFindTrustLine{sle, accountID}};
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <class T>
|
||||
std::vector<T>
|
||||
getTrustLineItems(
|
||||
AccountID const& accountID,
|
||||
ReadView const& view,
|
||||
LineDirection direction = LineDirection::outgoing)
|
||||
{
|
||||
std::vector<T> items;
|
||||
forEachItem(
|
||||
view,
|
||||
accountID,
|
||||
[&items, &accountID, &direction](std::shared_ptr<SLE const> const& sleCur) {
|
||||
auto ret = T::makeItem(accountID, sleCur);
|
||||
if (ret && (direction == LineDirection::outgoing || !ret->getNoRipple()))
|
||||
items.push_back(std::move(*ret));
|
||||
});
|
||||
// This list may be around for a while, so free up any unneeded
|
||||
// capacity
|
||||
items.shrink_to_fit();
|
||||
|
||||
return items;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
std::vector<PathFindTrustLine>
|
||||
PathFindTrustLine::getItems(
|
||||
AccountID const& accountID,
|
||||
ReadView const& view,
|
||||
LineDirection direction)
|
||||
{
|
||||
return detail::getTrustLineItems<PathFindTrustLine>(accountID, view, direction);
|
||||
}
|
||||
|
||||
RPCTrustLine::RPCTrustLine(std::shared_ptr<SLE const> const& sle, AccountID const& viewAccount)
|
||||
: TrustLineBase(sle, viewAccount)
|
||||
, lowQualityIn_(sle->getFieldU32(sfLowQualityIn))
|
||||
, lowQualityOut_(sle->getFieldU32(sfLowQualityOut))
|
||||
, highQualityIn_(sle->getFieldU32(sfHighQualityIn))
|
||||
, highQualityOut_(sle->getFieldU32(sfHighQualityOut))
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<RPCTrustLine>
|
||||
RPCTrustLine::makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle)
|
||||
{
|
||||
if (!sle || sle->getType() != ltRIPPLE_STATE)
|
||||
return {};
|
||||
return std::optional{RPCTrustLine{sle, accountID}};
|
||||
}
|
||||
|
||||
std::vector<RPCTrustLine>
|
||||
RPCTrustLine::getItems(AccountID const& accountID, ReadView const& view)
|
||||
{
|
||||
return detail::getTrustLineItems<RPCTrustLine>(accountID, view);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,218 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/Rate.h>
|
||||
#include <xrpl/protocol/STAmount.h>
|
||||
#include <xrpl/protocol/STLedgerEntry.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/** Describes how an account was found in a path, and how to find the next set
|
||||
of paths. "Outgoing" is defined as the source account, or an account found via a
|
||||
trustline that has rippling enabled on the account's side.
|
||||
"Incoming" is defined as an account found via a trustline that has rippling
|
||||
disabled on the account's side. Any trust lines for an incoming account that
|
||||
have rippling disabled are unusable in paths.
|
||||
*/
|
||||
enum class LineDirection : bool { incoming = false, outgoing = true };
|
||||
|
||||
/** Wraps a trust line SLE for convenience.
|
||||
The complication of trust lines is that there is a
|
||||
"low" account and a "high" account. This wraps the
|
||||
SLE and expresses its data from the perspective of
|
||||
a chosen account on the line.
|
||||
|
||||
This wrapper is primarily used in the path finder and there can easily be
|
||||
tens of millions of instances of this class. When modifying this class think
|
||||
carefully about the memory implications.
|
||||
*/
|
||||
class TrustLineBase
|
||||
{
|
||||
protected:
|
||||
// This class should not be instantiated directly. Use one of the derived
|
||||
// classes.
|
||||
TrustLineBase(std::shared_ptr<SLE const> const& sle, AccountID const& viewAccount);
|
||||
|
||||
~TrustLineBase() = default;
|
||||
TrustLineBase(TrustLineBase const&) = default;
|
||||
TrustLineBase&
|
||||
operator=(TrustLineBase const&) = delete;
|
||||
TrustLineBase(TrustLineBase&&) = default;
|
||||
|
||||
public:
|
||||
/** Returns the state map key for the ledger entry. */
|
||||
uint256 const&
|
||||
key() const
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
// VFALCO Take off the "get" from each function name
|
||||
|
||||
AccountID const&
|
||||
getAccountID() const
|
||||
{
|
||||
return mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer();
|
||||
}
|
||||
|
||||
AccountID const&
|
||||
getAccountIDPeer() const
|
||||
{
|
||||
return !mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer();
|
||||
}
|
||||
|
||||
// True, Provided auth to peer.
|
||||
bool
|
||||
getAuth() const
|
||||
{
|
||||
return mFlags & (mViewLowest ? lsfLowAuth : lsfHighAuth);
|
||||
}
|
||||
|
||||
bool
|
||||
getAuthPeer() const
|
||||
{
|
||||
return mFlags & (!mViewLowest ? lsfLowAuth : lsfHighAuth);
|
||||
}
|
||||
|
||||
bool
|
||||
getNoRipple() const
|
||||
{
|
||||
return mFlags & (mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
|
||||
}
|
||||
|
||||
bool
|
||||
getNoRipplePeer() const
|
||||
{
|
||||
return mFlags & (!mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
|
||||
}
|
||||
|
||||
LineDirection
|
||||
getDirection() const
|
||||
{
|
||||
return getNoRipple() ? LineDirection::incoming : LineDirection::outgoing;
|
||||
}
|
||||
|
||||
LineDirection
|
||||
getDirectionPeer() const
|
||||
{
|
||||
return getNoRipplePeer() ? LineDirection::incoming : LineDirection::outgoing;
|
||||
}
|
||||
|
||||
/** Have we set the freeze flag on our peer */
|
||||
bool
|
||||
getFreeze() const
|
||||
{
|
||||
return mFlags & (mViewLowest ? lsfLowFreeze : lsfHighFreeze);
|
||||
}
|
||||
|
||||
/** Have we set the deep freeze flag on our peer */
|
||||
bool
|
||||
getDeepFreeze() const
|
||||
{
|
||||
return mFlags & (mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze);
|
||||
}
|
||||
|
||||
/** Has the peer set the freeze flag on us */
|
||||
bool
|
||||
getFreezePeer() const
|
||||
{
|
||||
return mFlags & (!mViewLowest ? lsfLowFreeze : lsfHighFreeze);
|
||||
}
|
||||
|
||||
/** Has the peer set the deep freeze flag on us */
|
||||
bool
|
||||
getDeepFreezePeer() const
|
||||
{
|
||||
return mFlags & (!mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze);
|
||||
}
|
||||
|
||||
STAmount const&
|
||||
getBalance() const
|
||||
{
|
||||
return mBalance;
|
||||
}
|
||||
|
||||
STAmount const&
|
||||
getLimit() const
|
||||
{
|
||||
return mViewLowest ? mLowLimit : mHighLimit;
|
||||
}
|
||||
|
||||
STAmount const&
|
||||
getLimitPeer() const
|
||||
{
|
||||
return !mViewLowest ? mLowLimit : mHighLimit;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
getJson(int);
|
||||
|
||||
protected:
|
||||
uint256 key_;
|
||||
|
||||
STAmount const mLowLimit;
|
||||
STAmount const mHighLimit;
|
||||
|
||||
STAmount mBalance;
|
||||
|
||||
std::uint32_t mFlags;
|
||||
|
||||
bool mViewLowest;
|
||||
};
|
||||
|
||||
// This wrapper is used for the path finder
|
||||
class PathFindTrustLine final : public TrustLineBase, public CountedObject<PathFindTrustLine>
|
||||
{
|
||||
using TrustLineBase::TrustLineBase;
|
||||
|
||||
public:
|
||||
PathFindTrustLine() = delete;
|
||||
|
||||
static std::optional<PathFindTrustLine>
|
||||
makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
|
||||
|
||||
static std::vector<PathFindTrustLine>
|
||||
getItems(AccountID const& accountID, ReadView const& view, LineDirection direction);
|
||||
};
|
||||
|
||||
// This wrapper is used for the `AccountLines` command and includes the quality
|
||||
// in and quality out values.
|
||||
class RPCTrustLine final : public TrustLineBase, public CountedObject<RPCTrustLine>
|
||||
{
|
||||
using TrustLineBase::TrustLineBase;
|
||||
|
||||
public:
|
||||
RPCTrustLine() = delete;
|
||||
|
||||
RPCTrustLine(std::shared_ptr<SLE const> const& sle, AccountID const& viewAccount);
|
||||
|
||||
Rate const&
|
||||
getQualityIn() const
|
||||
{
|
||||
return mViewLowest ? lowQualityIn_ : highQualityIn_;
|
||||
}
|
||||
|
||||
Rate const&
|
||||
getQualityOut() const
|
||||
{
|
||||
return mViewLowest ? lowQualityOut_ : highQualityOut_;
|
||||
}
|
||||
|
||||
static std::optional<RPCTrustLine>
|
||||
makeItem(AccountID const& accountID, std::shared_ptr<SLE const> const& sle);
|
||||
|
||||
static std::vector<RPCTrustLine>
|
||||
getItems(AccountID const& accountID, ReadView const& view);
|
||||
|
||||
private:
|
||||
Rate lowQualityIn_;
|
||||
Rate lowQualityOut_;
|
||||
Rate highQualityIn_;
|
||||
Rate highQualityOut_;
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
@@ -50,7 +50,7 @@ doAccountCurrencies(RPC::JsonContext& context)
|
||||
return rpcError(rpcACT_NOT_FOUND);
|
||||
|
||||
std::set<Currency> send, receive;
|
||||
for (auto const& rspEntry : RPCTrustLine::getItems(accountID, *ledger))
|
||||
for (auto const& rspEntry : TrustLine::getItems(accountID, *ledger))
|
||||
{
|
||||
STAmount const& saBalance = rspEntry.getBalance();
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace xrpl {
|
||||
|
||||
void
|
||||
addLine(Json::Value& jsonLines, RPCTrustLine const& line)
|
||||
addLine(Json::Value& jsonLines, TrustLine const& line)
|
||||
{
|
||||
STAmount const& saBalance(line.getBalance());
|
||||
STAmount const& saLimit(line.getLimit());
|
||||
@@ -110,7 +110,7 @@ doAccountLines(RPC::JsonContext& context)
|
||||
Json::Value& jsonLines(result[jss::lines] = Json::arrayValue);
|
||||
struct VisitData
|
||||
{
|
||||
std::vector<RPCTrustLine> items;
|
||||
std::vector<TrustLine> items;
|
||||
AccountID const& accountID;
|
||||
std::optional<AccountID> const& raPeerAccount;
|
||||
bool ignoreDefault;
|
||||
@@ -198,7 +198,7 @@ doAccountLines(RPC::JsonContext& context)
|
||||
|
||||
if (!ignore && count <= limit)
|
||||
{
|
||||
auto const line = RPCTrustLine::makeItem(visitData.accountID, sleCur);
|
||||
auto const line = TrustLine::makeItem(visitData.accountID, sleCur);
|
||||
|
||||
if (line &&
|
||||
(!visitData.raPeerAccount ||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
@@ -158,7 +158,7 @@ doGatewayBalances(RPC::JsonContext& context)
|
||||
}
|
||||
}
|
||||
|
||||
auto rs = PathFindTrustLine::makeItem(accountID, sle);
|
||||
auto rs = TrustLine::makeItem(accountID, sle);
|
||||
|
||||
if (!rs)
|
||||
return;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/TrustLine.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/TrustLine.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/TxFlags.h>
|
||||
|
||||
Reference in New Issue
Block a user