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>
16 : env_(env), owner_{}, documentID_{}
24 if (now.time_since_epoch().count() == 0 || arg.
close)
38 jv[jss::TransactionType] = jss::OracleDelete;
43 else if (arg.
fee != 0)
48 jv[jss::Flags] = arg.
flags;
84 assert(account.isNonZero());
93 auto const& leSeries = sle->getFieldArray(sfPriceDataSeries);
94 if (leSeries.size() == 0 || leSeries.size() != series.
size())
96 for (
auto const&
data : series)
102 auto const& baseAsset = o.getFieldCurrency(sfBaseAsset);
103 auto const& quoteAsset =
104 o.getFieldCurrency(sfQuoteAsset);
105 auto const& price = o.getFieldU64(sfAssetPrice);
106 auto const& scale = o.getFieldU8(sfScale);
107 return baseAsset.getText() == std::get<0>(data) &&
108 quoteAsset.getText() == std::get<1>(data) &&
109 price == std::get<2>(data) &&
110 scale == std::get<3>(data);
111 }) == leSeries.end())
123 return sle && (*sle)[sfLastUpdateTime] == lastUpdateTime;
139 for (
auto const&
id : *oracles)
143 oracle[jss::account] =
to_string((*
id.first).
id());
145 toJson(oracle[jss::oracle_document_id], *
id.second);
148 jv[jss::oracles] = jvOracles;
151 toJson(jv[jss::trim], *trim);
153 toJson(jv[jss::base_asset], *baseAsset);
155 toJson(jv[jss::quote_asset], *quoteAsset);
157 toJson(jv[jss::time_threshold], *timeThreshold);
161 auto jr = env.
rpc(
"json",
"get_aggregate_price", str);
165 if (jr.isMember(jss::result) && jr[jss::result].isMember(jss::status))
166 return jr[jss::result];
167 else if (jr.isMember(jss::error))
190 jv[jss::TransactionType] = jss::OracleSet;
199 jv[jss::Flags] = arg.
flags;
202 else if (arg.
fee != 0)
218 duration_cast<seconds>(
219 env_.
current()->info().closeTime.time_since_epoch())
227 assert(s.size() <= 20);
242 priceData[jss::PriceData] = price;
243 dataSeries.
append(priceData);
245 jv[jss::PriceDataSeries] = dataSeries;
278 jvParams[jss::oracle][jss::account] =
281 jvParams[jss::oracle][jss::account] =
289 if (boost::conversion::try_lexical_convert(*index, i))
290 jvParams[jss::oracle][jss::ledger_index] = i;
292 jvParams[jss::oracle][jss::ledger_index] = *index;
297 auto jr = env.
rpc(
"json",
"ledger_entry", str);
301 if (jr.isMember(jss::error))
303 if (jr.isMember(jss::result) && jr[jss::result].isMember(jss::status))
304 return jr[jss::result];
319 [&]<
typename T>(T&& arg) {
322 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.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
ManualTimeKeeper & timeKeeper()
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Set a multisignature on a JTx.
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 &timeTreshold=std::nullopt)
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)
void set(CreateArg const &arg)
std::uint32_t documentID_
Oracle(Env &env, CreateArg const &arg, bool submit=true)
void remove(RemoveArg const &arg)
bool expectPrice(DataSeries const &pricess) const
bool expectLastUpdateTime(std::uint32_t lastUpdateTime) const
std::uint32_t documentID() const
void submit(Json::Value const &jv, std::optional< jtx::msig > const &msig, std::optional< jtx::seq > const &seq, std::optional< ter > const &err)
@ arrayValue
array value (ordered list)
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
static constexpr std::chrono::seconds testStartTime
constexpr char const * UnquotedNone
std::uint32_t asUInt(AnyValue const &v)
void toJson(Json::Value &jv, AnyValue const &v)
constexpr char const * NonePattern
bool validDocumentID(AnyValue const &v)
void toJsonHex(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 strHex(FwdIt begin, FwdIt end)
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
std::string to_string(base_uint< Bits, Tag > const &a)
std::optional< AnyValue > uri
std::optional< AnyValue > documentID
std::optional< AnyValue > lastUpdateTime
std::optional< AnyValue > assetClass
std::optional< AccountID > owner
std::optional< jtx::seq > seq
std::optional< jtx::msig > msig
std::optional< AnyValue > provider
std::optional< AccountID > const & owner
std::optional< AnyValue > const & documentID
std::optional< ter > const & err
std::optional< jtx::msig > const & msig
std::optional< jtx::seq > seq
std::optional< AnyValue > uri
std::optional< AnyValue > assetClass
std::optional< AnyValue > documentID
std::optional< AnyValue > lastUpdateTime
std::optional< AccountID > owner
std::optional< AnyValue > provider
std::optional< jtx::msig > msig
std::optional< jtx::seq > seq
Set the sequence number on a JTx.