42 auto const& params(context.
params);
50 struct ValuesFromContextParams
65 return (params.isMember(jss::asset) != params.isMember(jss::asset2)) ||
66 (params.isMember(jss::asset) == params.isMember(jss::amm_account));
73 if (params.isMember(jss::asset))
75 if (
auto const i =
getIssue(params[jss::asset], context.
j))
81 if (params.isMember(jss::asset2))
83 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
89 if (params.isMember(jss::amm_account))
91 auto const id = parseBase58<AccountID>((params[jss::amm_account].asString()));
97 ammID = sle->getFieldH256(sfAMMID);
102 if (params.isMember(jss::account))
104 accountID = parseBase58<AccountID>(params[jss::account].asString());
115 "xrpl::doAMMInfo : issue1 and issue2 do match");
117 auto const ammKeylet = [&]() {
118 if (issue1 && issue2)
120 XRPL_ASSERT(ammID,
"xrpl::doAMMInfo::ammKeylet : ammID is set");
123 auto const amm = ledger->read(ammKeylet);
126 if (!issue1 && !issue2)
128 issue1 = (*amm)[sfAsset].get<
Issue>();
129 issue2 = (*amm)[sfAsset2].get<
Issue>();
132 return ValuesFromContextParams{accountID, *issue1, *issue2, std::move(amm)};
135 auto const r = getValuesFromContextParams();
142 auto const& [accountID, issue1, issue2, amm] = *r;
144 auto const ammAccountID = amm->getAccountID(sfAccount);
147 auto const [asset1Balance, asset2Balance] =
149 auto const lptAMMBalance = accountID ?
ammLPHolds(*ledger, *amm, *accountID, context.
j) : (*amm)[sfLPTokenBalance];
152 asset1Balance.setJson(ammResult[jss::amount]);
153 asset2Balance.setJson(ammResult[jss::amount2]);
154 lptAMMBalance.setJson(ammResult[jss::lp_token]);
155 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
156 ammResult[jss::account] =
to_string(ammAccountID);
158 if (amm->isFieldPresent(sfVoteSlots))
160 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
163 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
164 vote[jss::trading_fee] = voteEntry[sfTradingFee];
165 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
166 voteSlots.
append(std::move(vote));
169 if (voteSlots.
size() > 0)
170 ammResult[jss::vote_slots] = std::move(voteSlots);
172 !ledger->rules().enabled(fixInnerObjTemplate) || amm->isFieldPresent(sfAuctionSlot),
173 "xrpl::doAMMInfo : auction slot is set");
174 if (amm->isFieldPresent(sfAuctionSlot))
176 auto const& auctionSlot =
static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
177 if (auctionSlot.isFieldPresent(sfAccount))
180 auto const timeSlot =
181 ammAuctionTimeSlot(ledger->header().parentCloseTime.time_since_epoch().count(), auctionSlot);
183 auctionSlot[sfPrice].setJson(auction[jss::price]);
184 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
185 auction[jss::account] =
to_string(auctionSlot.getAccountID(sfAccount));
187 if (auctionSlot.isFieldPresent(sfAuthAccounts))
190 for (
auto const& acct : auctionSlot.getFieldArray(sfAuthAccounts))
193 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
196 auction[jss::auth_accounts] = auth;
198 ammResult[jss::auction_slot] = std::move(auction);
202 if (!
isXRP(asset1Balance))
203 ammResult[jss::asset_frozen] =
isFrozen(*ledger, ammAccountID, issue1.currency, issue1.account);
204 if (!
isXRP(asset2Balance))
205 ammResult[jss::asset2_frozen] =
isFrozen(*ledger, ammAccountID, issue2.currency, issue2.account);
207 result[jss::amm] = std::move(ammResult);
208 if (!result.
isMember(jss::ledger_index) && !result.
isMember(jss::ledger_hash))
209 result[jss::ledger_current_index] = ledger->header().seq;
LedgerMaster & ledgerMaster