20 #include <ripple/app/tx/impl/SetOracle.h>
21 #include <ripple/basics/UnorderedContainers.h>
22 #include <ripple/ledger/Sandbox.h>
23 #include <ripple/ledger/View.h>
24 #include <ripple/protocol/Feature.h>
25 #include <ripple/protocol/InnerObjectFormats.h>
26 #include <ripple/protocol/Rules.h>
27 #include <ripple/protocol/TxFlags.h>
28 #include <ripple/protocol/digest.h>
53 if (dataSeries.empty())
58 auto isInvalidLength = [&](
auto const& sField,
std::size_t length) {
60 (ctx.
tx[sField].length() == 0 || ctx.
tx[sField].length() > length);
74 auto const sleSetter =
91 Throw<std::runtime_error>(
92 "Oracle: close time is less than maxLastUpdateTimeDelta");
126 auto const v = ctx.
tx[~field];
127 return !v || *v == (*sle)[field];
154 if (!pairsDel.
empty())
157 auto const oldCount =
159 auto const newCount = pairs.
size() > 5 ? 2 : 1;
160 adjustReserve = newCount - oldCount;
169 adjustReserve = pairs.
size() > 5 ? 2 : 1;
179 auto const& balance = sleSetter->getFieldAmount(
sfBalance);
181 if (balance < reserve)
190 if (
auto const sleAccount =
226 priceData.setFieldCurrency(
228 priceData.setFieldCurrency(
232 auto const oldCount = pairs.
size() > 5 ? 2 : 1;
242 else if (
auto iter = pairs.
find(key); iter != pairs.
end())
245 iter->second.setFieldU64(
247 if (entry.isFieldPresent(
sfScale))
255 priceData.setFieldCurrency(
257 priceData.setFieldCurrency(
259 priceData.setFieldU64(
261 if (entry.isFieldPresent(
sfScale))
263 pairs.
emplace(key, std::move(priceData));
267 for (
auto const& iter : pairs)
268 updatedSeries.
push_back(std::move(iter.second));
274 auto const newCount = pairs.size() > 5 ? 2 : 1;
275 auto const adjust = newCount - oldCount;
285 sle = std::make_shared<SLE>(oracleID);
302 auto const count = series.size() > 5 ? 2 : 1;
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
const SF_UINT32 sfOwnerCount
const STArray & getFieldArray(SField const &field) const
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
const SF_UINT32 sfLastUpdateTime
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
@ tecTOKEN_PAIR_NOT_FOUND
const SF_UINT64 sfOwnerNode
static NotTEC preflight(PreflightContext const &ctx)
bool isConsistent(Book const &book)
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
const SF_CURRENCY sfBaseAsset
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
constexpr std::size_t maxOracleURI
The maximum length of a URI inside an Oracle.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
void push_back(STObject const &object)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
const beast::Journal journal
const STCurrency & getFieldCurrency(SField const &field) const
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
constexpr static std::chrono::seconds epoch_offset
Clock for measuring the network time.
T time_since_epoch(T... args)
Defines the fields and their attributes within a STObject.
Keylet account(AccountID const &id) noexcept
AccountID root.
constexpr std::size_t maxOracleSymbolClass
The maximum length of a SymbolClass inside an Oracle.
AccountID getAccountID(SField const &field) const
TERSubset< CanCvtToTER > TER
const SF_UINT32 sfOracleDocumentID
std::uint32_t getFlags() const
State information when applying a tx.
static std::pair< Currency, Currency > tokenPairKey(STObject const &pair)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
State information when determining if a tx is likely to claim a fee.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t maxLastUpdateTimeDelta
The maximum allowed time difference between lastUpdateTime and the time of the last closed ledger.
static TER preclaim(PreclaimContext const &ctx)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
bool isFieldPresent(SField const &field) const
const uint256 featurePriceOracle
const SF_AMOUNT sfBalance
static void setPriceDataInnerObjTemplate(STObject &obj)
@ tecINSUFFICIENT_RESERVE
constexpr std::size_t maxPriceScale
The maximum price scaling factor.
const SF_ACCOUNT sfAccount
State information when preflighting a tx.
Currency const & currency() const
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.
const SF_CURRENCY sfQuoteAsset
constexpr std::uint32_t tfUniversalMask
constexpr std::size_t maxOracleProvider
The maximum length of a Provider inside an Oracle.
void set(const SOTemplate &)
const SField sfPriceDataSeries
const SF_UINT64 sfAssetPrice
TERSubset< CanCvtToNotTEC > NotTEC
constexpr std::size_t maxOracleDataSeries
The maximum size of a data series array inside an Oracle.