19 #include <ripple/app/ledger/LedgerMaster.h>
20 #include <ripple/app/misc/AMMUtils.h>
21 #include <ripple/json/json_value.h>
22 #include <ripple/ledger/ReadView.h>
23 #include <ripple/net/RPCErr.h>
24 #include <ripple/protocol/AMMCore.h>
25 #include <ripple/protocol/Issue.h>
26 #include <ripple/rpc/Context.h>
27 #include <ripple/rpc/impl/RPCHelpers.h>
28 #include <grpcpp/support/status.h>
40 for (
auto it = jv.begin(); it != jv.end(); ++it)
41 result[it.memberName()] = (*it);
48 Expected<Issue, error_code_i>
57 JLOG(j.
debug()) <<
"getIssue " << ex.
what();
68 "%Y-%Om-%dT%H:%M:%OS%z",
69 date::sys_time<system_clock::duration>(
76 auto const& params(context.
params);
84 struct ValuesFromContextParams
92 auto getValuesFromContextParams =
99 if ((params.isMember(jss::asset) != params.isMember(jss::asset2)) ||
100 (params.isMember(jss::asset) == params.isMember(jss::amm_account)))
103 if (params.isMember(jss::asset))
105 if (
auto const i =
getIssue(params[jss::asset], context.
j))
111 if (params.isMember(jss::asset2))
113 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
119 if (params.isMember(jss::amm_account))
121 auto const id =
getAccount(params[jss::amm_account], result);
127 ammID = sle->getFieldH256(
sfAMMID);
134 if (params.isMember(jss::account))
136 accountID =
getAccount(params[jss::account], result);
141 auto const ammKeylet = [&]() {
142 if (issue1 && issue2)
147 auto const amm = ledger->
read(ammKeylet);
150 if (!issue1 && !issue2)
156 return ValuesFromContextParams{
157 accountID, *issue1, *issue2, std::move(amm)};
160 auto const r = getValuesFromContextParams();
167 auto const& [accountID, issue1, issue2, amm] = *r;
172 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
177 FreezeHandling::fhIGNORE_FREEZE,
179 auto const lptAMMBalance = accountID
184 asset1Balance.setJson(ammResult[jss::amount]);
185 asset2Balance.setJson(ammResult[jss::amount2]);
186 lptAMMBalance.setJson(ammResult[jss::lp_token]);
192 for (
auto const& voteEntry : amm->getFieldArray(
sfVoteSlots))
198 voteSlots.
append(std::move(vote));
201 if (voteSlots.
size() > 0)
202 ammResult[jss::vote_slots] = std::move(voteSlots);
205 auto const& auctionSlot =
207 if (auctionSlot.isFieldPresent(
sfAccount))
213 auction[jss::time_interval] =
215 auctionSlot[
sfPrice].setJson(auction[jss::price]);
217 auction[jss::account] =
224 for (
auto const& acct :
231 auction[jss::auth_accounts] = auth;
233 ammResult[jss::auction_slot] = std::move(auction);
237 if (!
isXRP(asset1Balance))
238 ammResult[jss::asset_frozen] =
240 if (!
isXRP(asset2Balance))
241 ammResult[jss::asset2_frozen] =
244 result[jss::amm] = std::move(ammResult);
245 if (!result.
isMember(jss::ledger_index) &&
247 result[jss::ledger_current_index] = ledger->
info().
seq;
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
const SF_UINT16 sfDiscountedFee
A currency issued by an account.
constexpr std::uint16_t AUCTION_SLOT_TIME_INTERVALS
@ arrayValue
array value (ordered list)
const SF_AMOUNT sfLPTokenBalance
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
Unexpected(E(&)[N]) -> Unexpected< E const * >
LedgerMaster & ledgerMaster
const SF_UINT32 sfVoteWeight
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
const SF_UINT16 sfTradingFee
std::string to_iso8601(NetClock::time_point tp)
std::pair< STAmount, STAmount > ammPoolHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue1, Issue const &issue2, FreezeHandling freezeHandling, beast::Journal const j)
Get AMM pool balances.
const SF_UINT32 sfExpiration
constexpr static std::chrono::seconds epoch_offset
Clock for measuring the network time.
Integers of any length that is a multiple of 32-bits.
T time_since_epoch(T... args)
Value & append(const Value &value)
Append value to array at the end.
Issue getIssue(T const &amt)
Keylet account(AccountID const &id) noexcept
AccountID root.
const SField sfAuthAccounts
UInt size() const
Number of values in array or object.
bool isXRP(AccountID const &c)
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
Issue issueFromJson(Json::Value const &v)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::optional< AccountID > getAccount(Json::Value const &v, Json::Value &result)
Json::Value doAMMInfo(RPC::JsonContext &context)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isValidated(ReadView const &ledger)
STAmount ammLPHolds(ReadView const &view, Currency const &cur1, Currency const &cur2, AccountID const &ammAccount, AccountID const &lpAccount, beast::Journal const j)
Get the balance of LP tokens.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
const SField sfAuctionSlot
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
std::optional< std::uint8_t > ammAuctionTimeSlot(std::uint64_t current, STObject const &auctionSlot)
Get time slot of the auction slot.
std::string asString() const
Returns the unquoted string value.