44 auto const& params(context.
params);
52 struct ValuesFromContextParams
67 return (params.isMember(jss::asset) != params.isMember(jss::asset2)) ||
68 (params.isMember(jss::asset) == params.isMember(jss::amm_account));
75 if (params.isMember(jss::asset))
77 if (
auto const i =
getIssue(params[jss::asset], context.
j))
87 if (params.isMember(jss::asset2))
89 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
99 if (params.isMember(jss::amm_account))
101 auto const id = parseBase58<AccountID>((params[jss::amm_account].asString()));
107 ammID = sle->getFieldH256(sfAMMID);
112 if (params.isMember(jss::account))
114 accountID = parseBase58<AccountID>(params[jss::account].asString());
125 "xrpl::doAMMInfo : issue1 and issue2 do match");
127 auto const ammKeylet = [&]() {
128 if (issue1 && issue2)
130 XRPL_ASSERT(ammID,
"xrpl::doAMMInfo::ammKeylet : ammID is set");
133 auto const amm = ledger->read(ammKeylet);
136 if (!issue1 && !issue2)
138 issue1 = (*amm)[sfAsset].get<
Issue>();
139 issue2 = (*amm)[sfAsset2].get<
Issue>();
142 return ValuesFromContextParams{accountID, *issue1, *issue2, amm};
145 auto const r = getValuesFromContextParams();
152 auto const& [accountID, issue1, issue2, amm] = *r;
154 auto const ammAccountID = amm->getAccountID(sfAccount);
157 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
159 auto const lptAMMBalance =
160 accountID ?
ammLPHolds(*ledger, *amm, *accountID, context.
j) : (*amm)[sfLPTokenBalance];
163 asset1Balance.setJson(ammResult[jss::amount]);
164 asset2Balance.setJson(ammResult[jss::amount2]);
165 lptAMMBalance.setJson(ammResult[jss::lp_token]);
166 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
167 ammResult[jss::account] =
to_string(ammAccountID);
169 if (amm->isFieldPresent(sfVoteSlots))
171 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
174 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
175 vote[jss::trading_fee] = voteEntry[sfTradingFee];
176 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
177 voteSlots.
append(std::move(vote));
180 if (voteSlots.
size() > 0)
181 ammResult[jss::vote_slots] = std::move(voteSlots);
183 !ledger->rules().enabled(fixInnerObjTemplate) || amm->isFieldPresent(sfAuctionSlot),
184 "xrpl::doAMMInfo : auction slot is set");
185 if (amm->isFieldPresent(sfAuctionSlot))
187 auto const& auctionSlot = safe_downcast<STObject const&>(amm->peekAtField(sfAuctionSlot));
188 if (auctionSlot.isFieldPresent(sfAccount))
192 ledger->header().parentCloseTime.time_since_epoch().count(), auctionSlot);
194 auctionSlot[sfPrice].setJson(auction[jss::price]);
195 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
196 auction[jss::account] =
to_string(auctionSlot.getAccountID(sfAccount));
197 auction[jss::expiration] =
199 if (auctionSlot.isFieldPresent(sfAuthAccounts))
202 for (
auto const& acct : auctionSlot.getFieldArray(sfAuthAccounts))
205 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
208 auction[jss::auth_accounts] = auth;
210 ammResult[jss::auction_slot] = std::move(auction);
214 if (!
isXRP(asset1Balance))
216 ammResult[jss::asset_frozen] =
217 isFrozen(*ledger, ammAccountID, issue1.currency, issue1.account);
219 if (!
isXRP(asset2Balance))
221 ammResult[jss::asset2_frozen] =
222 isFrozen(*ledger, ammAccountID, issue2.currency, issue2.account);
225 result[jss::amm] = std::move(ammResult);
226 if (!result.
isMember(jss::ledger_index) && !result.
isMember(jss::ledger_hash))
227 result[jss::ledger_current_index] = ledger->header().seq;
LedgerMaster & ledgerMaster