43 auto const& params(context.
params);
51 struct ValuesFromContextParams
59 auto getValuesFromContextParams =
67 return (params.isMember(jss::asset) !=
68 params.isMember(jss::asset2)) ||
69 (params.isMember(jss::asset) ==
70 params.isMember(jss::amm_account));
77 if (params.isMember(jss::asset))
79 if (
auto const i =
getIssue(params[jss::asset], context.
j))
85 if (params.isMember(jss::asset2))
87 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
93 if (params.isMember(jss::amm_account))
96 parseBase58<AccountID>((params[jss::amm_account].asString()));
102 ammID = sle->getFieldH256(sfAMMID);
107 if (params.isMember(jss::account))
109 accountID = parseBase58<AccountID>(params[jss::account].asString());
121 "xrpl::doAMMInfo : issue1 and issue2 do match");
123 auto const ammKeylet = [&]() {
124 if (issue1 && issue2)
126 XRPL_ASSERT(ammID,
"xrpl::doAMMInfo::ammKeylet : ammID is set");
129 auto const amm = ledger->read(ammKeylet);
132 if (!issue1 && !issue2)
134 issue1 = (*amm)[sfAsset].get<
Issue>();
135 issue2 = (*amm)[sfAsset2].get<
Issue>();
138 return ValuesFromContextParams{
139 accountID, *issue1, *issue2, std::move(amm)};
142 auto const r = getValuesFromContextParams();
149 auto const& [accountID, issue1, issue2, amm] = *r;
151 auto const ammAccountID = amm->getAccountID(sfAccount);
154 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
161 auto const lptAMMBalance = accountID
163 : (*amm)[sfLPTokenBalance];
166 asset1Balance.setJson(ammResult[jss::amount]);
167 asset2Balance.setJson(ammResult[jss::amount2]);
168 lptAMMBalance.setJson(ammResult[jss::lp_token]);
169 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
170 ammResult[jss::account] =
to_string(ammAccountID);
172 if (amm->isFieldPresent(sfVoteSlots))
174 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
177 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
178 vote[jss::trading_fee] = voteEntry[sfTradingFee];
179 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
180 voteSlots.
append(std::move(vote));
183 if (voteSlots.
size() > 0)
184 ammResult[jss::vote_slots] = std::move(voteSlots);
186 !ledger->rules().enabled(fixInnerObjTemplate) ||
187 amm->isFieldPresent(sfAuctionSlot),
188 "xrpl::doAMMInfo : auction slot is set");
189 if (amm->isFieldPresent(sfAuctionSlot))
191 auto const& auctionSlot =
192 static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
193 if (auctionSlot.isFieldPresent(sfAccount))
197 ledger->header().parentCloseTime.time_since_epoch().count(),
199 auction[jss::time_interval] =
201 auctionSlot[sfPrice].setJson(auction[jss::price]);
202 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
203 auction[jss::account] =
204 to_string(auctionSlot.getAccountID(sfAccount));
207 if (auctionSlot.isFieldPresent(sfAuthAccounts))
210 for (
auto const& acct :
211 auctionSlot.getFieldArray(sfAuthAccounts))
214 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
217 auction[jss::auth_accounts] = auth;
219 ammResult[jss::auction_slot] = std::move(auction);
223 if (!
isXRP(asset1Balance))
224 ammResult[jss::asset_frozen] =
225 isFrozen(*ledger, ammAccountID, issue1.currency, issue1.account);
226 if (!
isXRP(asset2Balance))
227 ammResult[jss::asset2_frozen] =
228 isFrozen(*ledger, ammAccountID, issue2.currency, issue2.account);
230 result[jss::amm] = std::move(ammResult);
231 if (!result.
isMember(jss::ledger_index) &&
233 result[jss::ledger_current_index] = ledger->header().seq;
LedgerMaster & ledgerMaster