1#include <xrpl/ledger/Sandbox.h>
2#include <xrpl/ledger/View.h>
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/ledger/helpers/DirectoryHelpers.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/InnerObjectFormats.h>
7#include <xrpl/protocol/TxFlags.h>
8#include <xrpl/protocol/digest.h>
9#include <xrpl/tx/transactors/oracle/OracleSet.h>
25 if (dataSeries.empty())
30 auto isInvalidLength = [&](
auto const& sField,
std::size_t length) {
32 (ctx.
tx[sField].length() == 0 || ctx.
tx[sField].length() > length);
74 if (entry[sfBaseAsset] == entry[sfQuoteAsset])
81 if (entry.isFieldPresent(sfAssetPrice))
99 auto const v = ctx.
tx[~field];
100 return !v || *v == (*sle)[field];
110 if (ctx.
tx[sfLastUpdateTime] <= (*sle)[sfLastUpdateTime])
116 for (
auto const& entry : sle->getFieldArray(sfPriceDataSeries))
131 if (!pairsDel.
empty())
134 auto const oldCount = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? 2 : 1;
135 auto const newCount = pairs.
size() > 5 ? 2 : 1;
136 adjustReserve = newCount - oldCount;
144 adjustReserve = pairs.
size() > 5 ? 2 : 1;
154 auto const& balance = sleSetter->getFieldAmount(sfBalance);
156 if (balance < reserve)
189 priceData.
setFieldCurrency(sfBaseAsset, entry.getFieldCurrency(sfBaseAsset));
190 priceData.
setFieldCurrency(sfQuoteAsset, entry.getFieldCurrency(sfQuoteAsset));
191 priceData.
setFieldU64(sfAssetPrice, entry.getFieldU64(sfAssetPrice));
192 if (entry.isFieldPresent(sfScale))
193 priceData.
setFieldU8(sfScale, entry.getFieldU8(sfScale));
204 for (
auto const& entry : sle->getFieldArray(sfPriceDataSeries))
208 priceData.
setFieldCurrency(sfBaseAsset, entry.getFieldCurrency(sfBaseAsset));
209 priceData.
setFieldCurrency(sfQuoteAsset, entry.getFieldCurrency(sfQuoteAsset));
212 auto const oldCount = pairs.
size() > 5 ? 2 : 1;
217 if (!entry.isFieldPresent(sfAssetPrice))
222 else if (
auto iter = pairs.
find(key); iter != pairs.
end())
225 iter->second.setFieldU64(sfAssetPrice, entry.getFieldU64(sfAssetPrice));
226 if (entry.isFieldPresent(sfScale))
227 iter->second.setFieldU8(sfScale, entry.getFieldU8(sfScale));
233 populatePriceData(priceData, entry);
234 pairs.
emplace(key, std::move(priceData));
238 for (
auto const& iter : pairs)
240 sle->setFieldArray(sfPriceDataSeries, updatedSeries);
242 sle->setFieldVL(sfURI,
ctx_.
tx[sfURI]);
243 sle->setFieldU32(sfLastUpdateTime,
ctx_.
tx[sfLastUpdateTime]);
244 if (!sle->isFieldPresent(sfOracleDocumentID) &&
247 (*sle)[sfOracleDocumentID] =
ctx_.
tx[sfOracleDocumentID];
250 auto const newCount = pairs.
size() > 5 ? 2 : 1;
251 auto const adjust = newCount - oldCount;
265 (*sle)[sfOracleDocumentID] =
ctx_.
tx[sfOracleDocumentID];
269 sle->setFieldVL(sfURI,
ctx_.
tx[sfURI]);
283 populatePriceData(priceData, entry);
284 pairs.
emplace(key, std::move(priceData));
286 for (
auto const& iter : pairs)
290 sle->setFieldArray(sfPriceDataSeries, series);
291 sle->setFieldVL(sfAssetClass,
ctx_.
tx[sfAssetClass]);
292 sle->setFieldU32(sfLastUpdateTime,
ctx_.
tx[sfLastUpdateTime]);
299 (*sle)[sfOwnerNode] = *page;
301 auto const count = series.
size() > 5 ? 2 : 1;
State information when applying a tx.
beast::Journal const journal
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Defines the fields and their attributes within a STObject.
void push_back(STObject const &object)
Currency const & currency() const
void setFieldU8(SField const &field, unsigned char)
STCurrency const & getFieldCurrency(SField const &field) const
void setFieldU64(SField const &field, std::uint64_t)
void setFieldVL(SField const &field, Blob const &)
STArray const & getFieldArray(SField const &field) const
bool isFieldPresent(SField const &field) const
void set(SOTemplate const &)
void setFieldCurrency(SField const &field, STCurrency const &)
AccountID getAccountID(SField const &field) const
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isConsistent(Book const &book)
std::size_t constexpr maxLastUpdateTimeDelta
The maximum allowed time difference between lastUpdateTime and the time of the last closed ledger.
static std::pair< Currency, Currency > tokenPairKey(STObject const &pair)
std::size_t constexpr maxOracleDataSeries
The maximum size of a data series array inside an Oracle.
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
static void setPriceDataInnerObjTemplate(STObject &obj)
std::size_t constexpr maxPriceScale
The maximum price scaling factor.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
std::size_t constexpr maxOracleSymbolClass
The maximum length of a SymbolClass inside an Oracle.
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
@ tecINSUFFICIENT_RESERVE
@ tecTOKEN_PAIR_NOT_FOUND
std::size_t constexpr maxOracleProvider
The maximum length of a Provider inside an Oracle.
std::size_t constexpr maxOracleURI
The maximum length of a URI inside an Oracle.
TERSubset< CanCvtToNotTEC > NotTEC
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.
T time_since_epoch(T... args)