1#include <test/jtx/Oracle.h>
3#include <xrpl/protocol/jss.h>
5#include <boost/lexical_cast/try_lexical_convert.hpp>
6#include <boost/regex.hpp>
23 if (now.time_since_epoch().count() == 0 || arg.
close)
37 jv[jss::TransactionType] = jss::OracleDelete;
42 else if (arg.
fee != 0)
47 jv[jss::Flags] = arg.
flags;
83 assert(account.isNonZero());
92 auto const& leSeries = sle->getFieldArray(sfPriceDataSeries);
93 if (leSeries.size() == 0 || leSeries.size() != series.
size())
95 for (
auto const&
data : series)
98 auto const& baseAsset = o.getFieldCurrency(sfBaseAsset);
99 auto const& quoteAsset = o.getFieldCurrency(sfQuoteAsset);
100 auto const& price = o.getFieldU64(sfAssetPrice);
101 auto const& scale = o.getFieldU8(sfScale);
102 return baseAsset.getText() == std::get<0>(data) && quoteAsset.getText() == std::get<1>(data) &&
103 price == std::get<2>(data) && scale == std::get<3>(data);
104 }) == leSeries.end())
116 return sle && (*sle)[sfLastUpdateTime] == lastUpdateTime;
132 for (
auto const&
id : *oracles)
136 oracle[jss::account] =
to_string((*
id.first).
id());
138 toJson(oracle[jss::oracle_document_id], *
id.second);
141 jv[jss::oracles] = jvOracles;
144 toJson(jv[jss::trim], *trim);
146 toJson(jv[jss::base_asset], *baseAsset);
148 toJson(jv[jss::quote_asset], *quoteAsset);
150 toJson(jv[jss::time_threshold], *timeThreshold);
154 auto jr = env.
rpc(
"json",
"get_aggregate_price", str);
158 if (jr.isMember(jss::result) && jr[jss::result].isMember(jss::status))
159 return jr[jss::result];
160 else if (jr.isMember(jss::error))
182 jv[jss::TransactionType] = jss::OracleSet;
191 jv[jss::Flags] = arg.
flags;
194 else if (arg.
fee != 0)
208 duration_cast<seconds>(
env_.
current()->header().closeTime.time_since_epoch()).count() +
215 assert(s.size() <= 20);
230 priceData[jss::PriceData] = price;
231 dataSeries.
append(priceData);
233 jv[jss::PriceDataSeries] = dataSeries;
275 if (boost::conversion::try_lexical_convert(*index, i))
276 jvParams[jss::oracle][jss::ledger_index] = i;
278 jvParams[jss::oracle][jss::ledger_index] = *index;
283 auto jr = env.
rpc(
"json",
"ledger_entry", str);
287 if (jr.isMember(jss::error))
289 if (jr.isMember(jss::result) && jr[jss::result].isMember(jss::status))
290 return jr[jss::result];
305 [&]<
typename T>(T&& arg) {
308 if (arg.starts_with(
"##"))
Value & append(Value const &value)
Append value to array at the end.
time_point now() const override
Returns the current time.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
ManualTimeKeeper & timeKeeper()
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Set a multisignature on a JTx.
void set(CreateArg const &arg)
static Json::Value ledgerEntry(Env &env, std::optional< std::variant< AccountID, std::string > > const &account, std::optional< AnyValue > const &documentID, std::optional< std::string > const &index=std::nullopt)
static Json::Value aggregatePrice(Env &env, std::optional< AnyValue > const &baseAsset, std::optional< AnyValue > const "eAsset, std::optional< OraclesData > const &oracles=std::nullopt, std::optional< AnyValue > const &trim=std::nullopt, std::optional< AnyValue > const &timeThreshold=std::nullopt)
std::uint32_t documentID_
void submit(Json::Value const &jv, std::optional< jtx::msig > const &msig, std::optional< jtx::seq > const &seq, std::optional< ter > const &err)
bool expectLastUpdateTime(std::uint32_t lastUpdateTime) const
std::uint32_t documentID() const
Oracle(Env &env, CreateArg const &arg, bool submit=true)
bool expectPrice(DataSeries const &prices) const
void remove(RemoveArg const &arg)
@ arrayValue
array value (ordered list)
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
std::uint32_t asUInt(AnyValue const &v)
constexpr char const * UnquotedNone
static constexpr std::chrono::seconds testStartTime
bool validDocumentID(AnyValue const &v)
constexpr char const * NonePattern
void toJsonHex(Json::Value &jv, AnyValue const &v)
void toJson(Json::Value &jv, AnyValue const &v)
auto const data
General field definitions, or fields used in multiple transaction namespaces.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
std::optional< AnyValue > documentID
std::optional< AccountID > owner
std::optional< AnyValue > lastUpdateTime
std::optional< AnyValue > provider
std::optional< jtx::seq > seq
std::optional< AnyValue > assetClass
std::optional< jtx::msig > msig
std::optional< AnyValue > uri
std::optional< jtx::msig > const & msig
std::optional< AnyValue > const & documentID
std::optional< ter > const & err
std::optional< jtx::seq > seq
std::optional< AccountID > const & owner
std::optional< AccountID > owner
std::optional< jtx::msig > msig
std::optional< AnyValue > documentID
std::optional< AnyValue > uri
std::optional< jtx::seq > seq
std::optional< AnyValue > provider
std::optional< AnyValue > lastUpdateTime
std::optional< AnyValue > assetClass
Set the sequence number on a JTx.