1#include <xrpld/rpc/detail/AssetCache.h>
3#include <xrpld/rpc/detail/MPT.h>
4#include <xrpld/rpc/detail/TrustLine.h>
6#include <xrpl/basics/Log.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/ledger/ReadView.h>
10#include <xrpl/ledger/helpers/DirectoryHelpers.h>
11#include <xrpl/ledger/helpers/MPTokenHelpers.h>
12#include <xrpl/protocol/AccountID.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STLedgerEntry.h>
28 JLOG(
journal_.debug()) <<
"created for ledger " <<
ledger_->header().seq;
33 JLOG(
journal_.debug()) <<
"destroyed for ledger " <<
ledger_->header().seq <<
" with "
35 <<
" distinct trust lines.";
41 auto const hash =
hasher_(accountID);
50 auto [it, inserted] = [&]() {
51 if (
auto otheriter =
lines_.find(otherkey); otheriter !=
lines_.end())
56 auto const size = otheriter->second ? otheriter->second->size() : 0;
60 <<
" trust lines for account " << accountID <<
" found " << size
64 :
"Returning the superset of outgoing")
74 size <=
totalLineCount_,
"xrpl::AssetCache::getRippleLines : maximum lines");
89 return lines_.emplace(key,
nullptr);
94 XRPL_ASSERT(it->second ==
nullptr,
"xrpl::Asset::getRippleLines : null lines");
104 !it->second || !it->second->empty(),
105 "xrpl::AssetCache::getRippleLines : null or nonempty lines");
106 auto const size = it->second ? it->second->size() : 0;
107 JLOG(
journal_.trace()) <<
"getRippleLines for ledger " <<
ledger_->header().seq <<
" found "
110 <<
" lines for " << (inserted ?
"new " :
"existing ") << accountID
111 <<
" out of a total of " <<
lines_.size() <<
" accounts and "
122 if (
auto it =
mpts_.find(account); it !=
mpts_.end())
128 if (sle->getType() == ltMPTOKEN_ISSUANCE)
130 auto const mptID =
makeMptID(sle->getFieldU32(sfSequence), account);
131 bool const maxedOut = sle->at(sfOutstandingAmount) ==
maxMPTAmount(*sle);
134 else if (sle->getType() == ltMPTOKEN)
136 auto const mptID = sle->getFieldH192(sfMPTokenIssuanceID);
137 bool const zeroBalance = sle->at(sfMPTAmount) == 0;
138 bool const maxedOut = [&] {
141 return sleIssuance->at(sfOutstandingAmount) ==
maxMPTAmount(*sleIssuance);
152 mpts_.emplace(account,
nullptr);
159 return mpts_[account];
A generic endpoint for log messages.
AssetCache(std::shared_ptr< ReadView const > l, beast::Journal j)
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
hash_map< AccountID, std::shared_ptr< std::vector< PathFindMPT > > > mpts_
std::shared_ptr< std::vector< PathFindMPT > > const & getMPTs(AccountID const &account)
xrpl::HardenedHash hasher_
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
std::size_t totalLineCount_
std::shared_ptr< ReadView const > ledger_
static std::vector< PathFindTrustLine > getItems(AccountID const &accountID, ReadView const &view, LineDirection direction)
std::shared_ptr< STLedgerEntry const > const & const_ref
T emplace_back(T... args)
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::int64_t maxMPTAmount(SLE const &sleIssuance)
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::const_ref)> const &f)
Iterate all items in the given directory.
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)