1#include <xrpl/protocol/STPathSet.h>
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/UnorderedContainers.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/basics/contract.h>
8#include <xrpl/beast/hash/uhash.h>
9#include <xrpl/beast/utility/instrumentation.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/STBase.h>
14#include <xrpl/protocol/Serializer.h>
15#include <xrpl/protocol/UintTypes.h>
16#include <xrpl/protocol/detail/STVar.h>
17#include <xrpl/protocol/jss.h>
45 hashAccount += (hashAccount * 257) ^ x;
53 for (
auto const x : currency)
54 hashCurrency += (hashCurrency * 509) ^ x;
58 hashIssuer += (hashIssuer * 911) ^ x;
60 return (hashAccount ^ hashCurrency ^ hashIssuer);
73 "STPathSet is too large to fit in STVar's small object optimization. Please verify if it "
74 "should, if the kMaxSize should be increased, or if STPathSet should be stored on the heap "
75 "instead of in STVar.");
84 , value_{other.value_}
103 seen_ = std::move(newSeen);
112 int const iType = sit.
get8();
118 JLOG(
debugLog().error()) <<
"Empty path in pathset";
131 JLOG(
debugLog().error()) <<
"Bad path element " << iType <<
" in pathset";
148 if (hasCurrency && hasMPT)
150 JLOG(
debugLog().error()) <<
"Bad path element MPT and Currency in pathset";
163 path.emplace_back(account, asset, issuer, hasCurrency || hasMPT);
177 return emplace(n, buf, std::move(*
this));
183 XRPL_ASSERT(
seen_ !=
nullptr,
"xrpl::STPathSet::assembleAdd : DeduplicationTag");
186 return appendUnique([&](
auto& value) { value.push_back(std::move(combined)); });
192 auto const* v =
dynamic_cast<STPathSet const*
>(&t);
193 return (v !=
nullptr) && (
value_ == v->value_);
206 return p.getAccountID() == account && p.getPathAsset() == asset &&
207 p.getIssuerID() == issuer;
216 for (
auto const& it :
path_)
219 auto const iType = it.getNodeType();
221 elem[jss::type] = iType;
224 elem[jss::account] =
to_string(it.getAccountID());
229 "xrpl::STPath::getJson : not type Currency and MPT");
231 elem[jss::currency] =
to_string(it.getCurrency());
234 elem[jss::mpt_issuance_id] =
to_string(it.getMPTID());
237 elem[jss::issuer] =
to_string(it.getIssuerID());
249 for (
auto const& it :
value_)
250 ret.
append(it.getJson(options));
264 XRPL_ASSERT(
getFName().isBinary(),
"xrpl::STPathSet::add : field is binary");
265 XRPL_ASSERT(
getFName().fieldType == STI_PATHSET,
"xrpl::STPathSet::add : valid field type");
268 for (
auto const& spPath :
value_)
273 for (
auto const& speElement : spPath)
275 int const iType = speElement.getNodeType();
Value & append(Value const &value)
Append value to array at the end.
static BaseUInt fromRaw(Container const &c)
CountedObject & operator=(CountedObject const &) noexcept=default
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
A type which can be exported to a well known binary format.
SField const & getFName() const
static STBase * emplace(std::size_t n, void *buf, T &&val)
STBase & operator=(STBase const &t)
static std::size_t getHash(STPathElement const &element)
AccountID const & getAccountID() const
PathAsset const & getPathAsset() const
AccountID const & getIssuerID() const
void add(Serializer &s) const override
bool assembleAdd(STPath const &base, STPathElement const &tail)
assembleAdd adds a path to the set by combining a base path and a tail element.
STBase * copy(std::size_t n, void *buf) const override
json::Value getJson(JsonOptions) const override
std::vector< STPath > value_
STBase * move(std::size_t n, void *buf) override
bool isEquivalent(STBase const &t) const override
std::unique_ptr< HardenedHashSet< STPath > > seen_
Deduplication index over value_, for pathfinding.
bool isDefault() const override
SerializedTypeID getSType() const override
STPathSet & operator=(STPathSet const &other)
bool appendUnique(Append &&append)
Append a path via append, then register it in the deduplication index.
std::vector< STPathElement > path_
bool hasSeen(AccountID const &account, PathAsset const &asset, AccountID const &issuer) const
void pushBack(STPathElement const &e)
json::Value getJson(JsonOptions) const
int addBitString(BaseUInt< Bits, Tag > const &v)
int add8(unsigned char byteValue)
static constexpr std::size_t kMaxSize
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::unordered_set< Value, Hash, Pred, Allocator > HardenedHashSet
beast::Journal debugLog()
Returns a debug journal.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
std::string to_string(BaseUInt< Bits, Tag > const &a)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Note, should be treated as flags that can be | and &.