rippled
Loading...
Searching...
No Matches
RippleLineCache.h
1#pragma once
2
3#include <xrpld/rpc/detail/TrustLine.h>
4
5#include <xrpl/basics/CountedObject.h>
6#include <xrpl/basics/hardened_hash.h>
7#include <xrpl/ledger/Ledger.h>
8
9#include <cstddef>
10#include <mutex>
11#include <vector>
12
13namespace xrpl {
14
15// Used by Pathfinder
16class RippleLineCache final : public CountedObject<RippleLineCache>
17{
18public:
21
23 getLedger() const
24 {
25 return ledger_;
26 }
27
41 getRippleLines(AccountID const& accountID, LineDirection direction);
42
43private:
45
48
50
51 struct AccountKey final : public CountedObject<AccountKey>
52 {
56
57 AccountKey(AccountID const& account, LineDirection direction, std::size_t hash)
58 : account_(account), direction_(direction), hash_value_(hash)
59 {
60 }
61
62 AccountKey(AccountKey const& other) = default;
63
65 operator=(AccountKey const& other) = default;
66
67 bool
68 operator==(AccountKey const& lhs) const
69 {
70 return hash_value_ == lhs.hash_value_ && account_ == lhs.account_ &&
72 }
73
75 get_hash() const
76 {
77 return hash_value_;
78 }
79
80 struct Hash
81 {
82 Hash() = default;
83
85 operator()(AccountKey const& key) const noexcept
86 {
87 return key.get_hash();
88 }
89 };
90 };
91
92 // Use a shared_ptr so entries can be removed from the map safely.
93 // Even though a shared_ptr to a vector will take more memory just a vector,
94 // most accounts are not going to have any entries (estimated over 90%), so
95 // vectors will not need to be created for them. This should lead to far
96 // less memory usage overall.
99};
100
101} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Tracks the number of instances of an object.
std::shared_ptr< ReadView const > const & getLedger() const
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
std::shared_ptr< ReadView const > ledger_
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
beast::Journal journal_
xrpl::hardened_hash hasher_
Seed functor once per construction.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:21
std::size_t operator()(AccountKey const &key) const noexcept
AccountKey & operator=(AccountKey const &other)=default
AccountKey(AccountKey const &other)=default
bool operator==(AccountKey const &lhs) const
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)