20 #include <ripple/protocol/digest.h>
21 #include <ripple/protocol/jss.h>
22 #include <test/jtx/Oracle.h>
24 #include <boost/lexical_cast/try_lexical_convert.hpp>
34 : env_(env), owner_{}, documentID_{}
41 auto const now = env_.timeKeeper().now();
42 if (now.time_since_epoch().count() == 0 || arg.close)
47 documentID_ = *arg.documentID;
56 jv[jss::TransactionType] = jss::OracleDelete;
61 else if (arg.
fee != 0)
100 assert(account.isNonZero());
110 if (leSeries.size() == 0 || leSeries.size() != series.
size())
112 for (
auto const& data : series)
118 auto const& baseAsset = o.getFieldCurrency(sfBaseAsset);
119 auto const& quoteAsset =
120 o.getFieldCurrency(sfQuoteAsset);
121 auto const& price = o.getFieldU64(sfAssetPrice);
122 auto const& scale = o.getFieldU8(sfScale);
123 return baseAsset.getText() == std::get<0>(data) &&
124 quoteAsset.getText() == std::get<1>(data) &&
125 price == std::get<2>(data) &&
126 scale == std::get<3>(data);
127 }) == leSeries.end())
156 for (
auto const&
id : *oracles)
159 oracle[jss::account] =
to_string(
id.first.id());
160 oracle[jss::oracle_document_id] =
id.second;
163 jv[jss::oracles] = jvOracles;
166 jv[jss::trim] = *trim;
168 jv[jss::base_asset] = *baseAsset;
170 jv[jss::quote_asset] = *quoteAsset;
172 jv[jss::time_threshold] = *timeThreshold;
174 auto jr = env.
rpc(
"json",
"get_aggregate_price",
to_string(jv));
176 if (jr.isObject() && jr.isMember(jss::result) &&
177 jr[jss::result].isMember(jss::status))
178 return jr[jss::result];
191 jv[jss::TransactionType] = jss::OracleSet;
201 jv[jss::Flags] = arg.
flags;
204 else if (arg.
fee != 0)
210 jv[jss::LastUpdateTime] =
214 duration_cast<seconds>(
215 env_.
current()->info().closeTime.time_since_epoch())
223 assert(s.size() <= 20);
228 for (
auto const& data : arg.
series)
232 price[jss::BaseAsset] = assetToStr(std::get<0>(data));
233 price[jss::QuoteAsset] = assetToStr(std::get<1>(data));
234 if (std::get<2>(data))
235 price[jss::AssetPrice] = *std::get<2>(data);
236 if (std::get<3>(data))
237 price[jss::Scale] = *std::get<3>(data);
238 priceData[jss::PriceData] = price;
239 dataSeries.
append(priceData);
241 jv[jss::PriceDataSeries] = dataSeries;
271 jvParams[jss::oracle][jss::account] =
to_string(account);
272 if (std::holds_alternative<std::uint32_t>(
documentID))
273 jvParams[jss::oracle][jss::oracle_document_id] =
276 jvParams[jss::oracle][jss::oracle_document_id] =
281 if (boost::conversion::try_lexical_convert(*index, i))
282 jvParams[jss::oracle][jss::ledger_index] = i;
284 jvParams[jss::oracle][jss::ledger_index] = *index;
286 return env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
const SF_UINT32 sfLastUpdateTime
std::optional< std::string > provider
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::optional< std::uint32_t > lastUpdateTime
std::optional< jtx::msig > msig
@ arrayValue
array value (ordered list)
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
std::optional< jtx::msig > const & msig
std::optional< jtx::msig > msig
std::optional< jtx::seq > seq
std::uint32_t documentID() const
Set a multisignature on a JTx.
std::optional< AccountID > owner
std::optional< std::string > assetClass
constexpr static std::chrono::seconds epoch_offset
Clock for measuring the network time.
static Json::Value ledgerEntry(Env &env, AccountID const &account, std::variant< std::uint32_t, std::string > const &documentID, std::optional< std::string > const &index=std::nullopt)
void remove(RemoveArg const &arg)
Oracle(Env &env, CreateArg const &arg, bool submit=true)
std::optional< jtx::seq > seq
Value & append(const Value &value)
Append value to array at the end.
std::optional< AccountID > const & owner
std::optional< std::uint32_t > lastUpdateTime
constexpr static std::chrono::seconds testStartTime
bool expectPrice(DataSeries const &pricess) const
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
std::optional< std::string > uri
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
bool expectLastUpdateTime(std::uint32_t lastUpdateTime) const
std::uint32_t documentID_
Set the sequence number on a JTx.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< ter > const & err
std::optional< std::uint32_t > documentID
std::optional< AccountID > owner
std::optional< std::uint32_t > documentID
void set(CreateArg const &arg)
std::optional< std::uint32_t > const & documentID
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
std::optional< std::string > uri
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
std::string strHex(FwdIt begin, FwdIt end)
std::optional< jtx::seq > seq
static Json::Value aggregatePrice(Env &env, std::optional< std::string > const &baseAsset, std::optional< std::string > const "eAsset, std::optional< std::vector< std::pair< Account, std::uint32_t >>> const &oracles=std::nullopt, std::optional< std::uint8_t > const &trim=std::nullopt, std::optional< std::uint8_t > const &timeTreshold=std::nullopt)
const SField sfPriceDataSeries
std::optional< std::string > provider
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
A transaction testing environment.
void submit(Json::Value const &jv, std::optional< jtx::msig > const &msig, std::optional< jtx::seq > const &seq, std::optional< ter > const &err)
std::optional< std::string > assetClass