1#include <xrpld/app/misc/AMMHelpers.h>
2#include <xrpld/app/misc/AMMUtils.h>
3#include <xrpld/app/tx/detail/InvariantCheck.h>
4#include <xrpld/app/tx/detail/NFTokenUtils.h>
5#include <xrpld/app/tx/detail/PermissionedDomainSet.h>
7#include <xrpl/basics/Log.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/ledger/CredentialHelpers.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/ledger/View.h>
12#include <xrpl/protocol/Feature.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/MPTIssue.h>
16#include <xrpl/protocol/SField.h>
17#include <xrpl/protocol/STArray.h>
18#include <xrpl/protocol/STNumber.h>
19#include <xrpl/protocol/SystemParameters.h>
20#include <xrpl/protocol/TER.h>
21#include <xrpl/protocol/TxFormats.h>
22#include <xrpl/protocol/Units.h>
23#include <xrpl/protocol/nftPageMask.h>
79 return safe_cast<Privilege>(
84#pragma push_macro("TRANSACTION")
87#define TRANSACTION(tag, value, name, delegable, amendment, privileges, ...) \
89 return (privileges) & priv; \
97#include <xrpl/protocol/detail/transactions.macro>
106#pragma pop_macro("TRANSACTION")
128 JLOG(j.
fatal()) <<
"Invariant failed: fee paid was negative: "
137 JLOG(j.
fatal()) <<
"Invariant failed: fee paid exceeds system limit: "
146 JLOG(j.
fatal()) <<
"Invariant failed: fee paid is " << fee.
drops()
147 <<
" exceeds fee specified in transaction.";
171 switch (before->getType())
174 drops_ -= (*before)[sfBalance].xrp().drops();
178 ((*before)[sfAmount] - (*before)[sfBalance]).xrp().drops();
181 if (
isXRP((*before)[sfAmount]))
182 drops_ -= (*before)[sfAmount].xrp().drops();
191 switch (
after->getType())
194 drops_ += (*after)[sfBalance].xrp().drops();
198 drops_ += ((*after)[sfAmount] - (*after)[sfBalance])
204 drops_ += (*after)[sfAmount].xrp().drops();
224 JLOG(j.
fatal()) <<
"Invariant failed: XRP net change was positive: "
232 JLOG(j.
fatal()) <<
"Invariant failed: XRP net change of " <<
drops_
233 <<
" doesn't match fee " << fee.
drops();
248 auto isBad = [](
STAmount const& balance) {
249 if (!balance.native())
252 auto const drops = balance.xrp();
266 if (before && before->getType() == ltACCOUNT_ROOT)
267 bad_ |= isBad((*before)[sfBalance]);
269 if (
after &&
after->getType() == ltACCOUNT_ROOT)
283 JLOG(j.
fatal()) <<
"Invariant failed: incorrect account XRP balance";
300 if (pays < beast::zero)
303 if (gets < beast::zero)
307 return pays.
native() && gets.native();
310 if (before && before->getType() == ltOFFER)
311 bad_ |= isBad((*before)[sfTakerPays], (*before)[sfTakerGets]);
314 bad_ |= isBad((*
after)[sfTakerPays], (*after)[sfTakerGets]);
327 JLOG(j.
fatal()) <<
"Invariant failed: offer with a bad amount";
342 auto isBad = [](
STAmount const& amount) {
355 if (amount.holds<
Issue>())
357 if (amount <= beast::zero)
367 if (amount <= beast::zero)
377 if (before && before->getType() == ltESCROW)
378 bad_ |= isBad((*before)[sfAmount]);
388 if (
after &&
after->getType() == ltMPTOKEN_ISSUANCE)
390 auto const outstanding = (*after)[sfOutstandingAmount];
391 checkAmount(outstanding);
392 if (
auto const locked = (*
after)[~sfLockedAmount])
394 checkAmount(*locked);
395 bad_ = outstanding < *locked;
401 auto const mptAmount = (*after)[sfMPTAmount];
402 checkAmount(mptAmount);
403 if (
auto const locked = (*
after)[~sfLockedAmount])
405 checkAmount(*locked);
420 JLOG(j.
fatal()) <<
"Invariant failed: escrow specifies invalid amount";
435 if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
457 JLOG(j.
fatal()) <<
"Invariant failed: account deletion "
458 "succeeded without deleting an account";
460 JLOG(j.
fatal()) <<
"Invariant failed: account deletion "
461 "succeeded but deleted multiple accounts!";
475 JLOG(j.
fatal()) <<
"Invariant failed: an account root was deleted";
487 if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
503 [[maybe_unused]]
bool const enforce =
508 auto const objectExists = [&view, enforce, &j](
auto const& keylet) {
510 if (
auto const sle = view.
read(keylet))
513 auto const typeName = [&sle]() {
518 return item->getName();
523 <<
"Invariant failed: account deletion left behind a "
524 << typeName <<
" object";
529 "xrpl::AccountRootsDeletedClean::finalize::objectExists : "
530 "account deletion left no objects behind");
538 auto const accountID = before->getAccountID(sfAccount);
540 if (
after->at(sfBalance) != beast::zero)
542 JLOG(j.
fatal()) <<
"Invariant failed: account deletion left "
543 "behind a non-zero balance";
546 "xrpl::AccountRootsDeletedClean::finalize : "
547 "deleted account has zero balance");
552 if (
after->at(sfOwnerCount) != 0)
554 JLOG(j.
fatal()) <<
"Invariant failed: account deletion left "
555 "behind a non-zero owner count";
558 "xrpl::AccountRootsDeletedClean::finalize : "
559 "deleted account has zero owner count");
566 if (objectExists(
std::invoke(keyletfunc, accountID)) && enforce)
581 if (key && objectExists(
Keylet{ltNFTOKEN_PAGE, *key}) && enforce)
589 if (before->isFieldPresent(*field))
591 auto const key = before->getFieldH256(*field);
609 if (before &&
after && before->getType() !=
after->getType())
614#pragma push_macro("LEDGER_ENTRY")
617#define LEDGER_ENTRY(tag, ...) case tag:
619 switch (
after->getType())
621#include <xrpl/protocol/detail/ledger_entries.macro>
630#pragma pop_macro("LEDGER_ENTRY")
647 JLOG(j.
fatal()) <<
"Invariant failed: ledger entry type mismatch";
652 JLOG(j.
fatal()) <<
"Invariant failed: invalid ledger entry type added";
666 if (
after &&
after->getType() == ltRIPPLE_STATE)
688 JLOG(j.
fatal()) <<
"Invariant failed: an XRP trust line was created";
700 if (
after &&
after->getType() == ltRIPPLE_STATE)
710 (lowDeepFreeze && !lowFreeze) || (highDeepFreeze && !highFreeze);
725 JLOG(j.
fatal()) <<
"Invariant failed: a trust line with deep freeze flag "
726 "without normal freeze was created";
754 if (balanceChange.signum() == 0)
786 [[maybe_unused]]
bool const enforce =
791 auto const issuerSle =
findIssuer(issue.account, view);
800 "xrpl::TransfersNotFrozen::finalize : enforce "
824 XRPL_ASSERT(
after,
"xrpl::TransfersNotFrozen::isValidEntry : valid after.");
830 if (
after->getType() == ltACCOUNT_ROOT)
842 return after->getType() == ltRIPPLE_STATE &&
843 (!before || before->getType() == ltRIPPLE_STATE);
852 auto const getBalance = [](
auto const& line,
auto const& other,
bool zero) {
854 line ? line->at(sfBalance) : other->at(sfBalance).zeroed();
855 return zero ? amt.
zeroed() : amt;
863 auto const balanceBefore = getBalance(before,
after,
false);
870 auto const balanceAfter = getBalance(
after, before, isDelete);
872 return balanceAfter - balanceBefore;
880 "xrpl::TransfersNotFrozen::recordBalance : valid trustline "
884 changes.senders.emplace_back(std::move(change));
886 changes.receivers.emplace_back(std::move(change));
894 auto const balanceChangeSign = balanceChange.
signum();
895 auto const currency =
after->at(sfBalance).getCurrency();
899 {currency,
after->at(sfHighLimit).getIssuer()},
900 {
after, balanceChangeSign});
904 {currency,
after->at(sfLowLimit).getIssuer()},
905 {
after, -balanceChangeSign});
947 for (
auto const& change : actors)
949 bool const high = change.line->at(sfLowLimit).getIssuer() ==
950 issuer->at(sfAccount);
953 change, high, tx, j, enforce, globalFreeze))
973 bool const deepFreeze =
975 bool const frozen = globalFreeze || deepFreeze || freeze;
987 JLOG(j.
debug()) <<
"Invariant check allowing funds to be moved "
989 <<
" a frozen trustline for AMMClawback "
994 JLOG(j.
fatal()) <<
"Invariant failed: Attempting to move frozen funds for "
999 "xrpl::TransfersNotFrozen::validateFrozenState : enforce "
1018 if (!before &&
after->getType() == ltACCOUNT_ROOT)
1040 JLOG(j.
fatal()) <<
"Invariant failed: multiple accounts "
1041 "created in a single transaction";
1048 bool const pseudoAccount =
1055 JLOG(j.
fatal()) <<
"Invariant failed: pseudo-account created by a "
1056 "wrong transaction type";
1064 JLOG(j.
fatal()) <<
"Invariant failed: account created with "
1065 "wrong starting sequence number";
1076 <<
"Invariant failed: pseudo-account created with "
1085 JLOG(j.
fatal()) <<
"Invariant failed: account root created illegally";
1098 static constexpr uint256 const accountBits = ~pageBits;
1100 if ((before && before->getType() != ltNFTOKEN_PAGE) ||
1101 (
after &&
after->getType() != ltNFTOKEN_PAGE))
1105 uint256 const account = sle->
key() & accountBits;
1106 uint256 const hiLimit = sle->key() & pageBits;
1114 if (account != (*prev & accountBits))
1117 if (hiLimit <= (*prev & pageBits))
1121 if (
auto const next = (*sle)[~sfNextPageMin])
1123 if (account != (*next & accountBits))
1126 if (hiLimit >= (*next & pageBits))
1131 auto const& nftokens = sle->getFieldArray(sfNFTokens);
1134 if (
std::size_t const nftokenCount = nftokens.size();
1135 (!isDelete && nftokenCount == 0) ||
1142 prev ? *prev & pageBits :
uint256(beast::zero);
1146 for (
auto const& obj : nftokens)
1148 uint256 const tokenID = obj[sfNFTokenID];
1155 if (
uint256 const tokenPageBits = tokenID & pageBits;
1156 tokenPageBits < loLimit || tokenPageBits >= hiLimit)
1159 if (
auto uri = obj[~sfURI]; uri && uri->empty())
1173 before->isFieldPresent(sfPreviousPageMin))
1182 if (!isDelete && before &&
after)
1190 before->isFieldPresent(sfNextPageMin) &&
1191 !
after->isFieldPresent(sfNextPageMin))
1208 JLOG(j.
fatal()) <<
"Invariant failed: NFT page is improperly linked.";
1214 JLOG(j.
fatal()) <<
"Invariant failed: NFT found in incorrect page.";
1220 JLOG(j.
fatal()) <<
"Invariant failed: NFTs on page are not sorted.";
1226 JLOG(j.
fatal()) <<
"Invariant failed: NFT contains empty URI.";
1232 JLOG(j.
fatal()) <<
"Invariant failed: NFT page has invalid size.";
1240 JLOG(j.
fatal()) <<
"Invariant failed: Last NFT page deleted with "
1241 "non-empty directory.";
1246 JLOG(j.
fatal()) <<
"Invariant failed: Lost NextMinPage link.";
1261 if (before && before->getType() == ltACCOUNT_ROOT)
1267 if (
after &&
after->getType() == ltACCOUNT_ROOT)
1286 JLOG(j.
fatal()) <<
"Invariant failed: the number of minted tokens "
1287 "changed without a mint transaction!";
1293 JLOG(j.
fatal()) <<
"Invariant failed: the number of burned tokens "
1294 "changed without a burn transaction!";
1306 <<
"Invariant failed: successful minting didn't increase "
1307 "the number of minted tokens.";
1313 JLOG(j.
fatal()) <<
"Invariant failed: failed minting changed the "
1314 "number of minted tokens.";
1321 <<
"Invariant failed: minting changed the number of "
1334 <<
"Invariant failed: successful burning didn't increase "
1335 "the number of burned tokens.";
1342 JLOG(j.
fatal()) <<
"Invariant failed: failed burning changed the "
1343 "number of burned tokens.";
1350 <<
"Invariant failed: burning changed the number of "
1367 if (before && before->getType() == ltRIPPLE_STATE)
1370 if (before && before->getType() == ltMPTOKEN)
1390 <<
"Invariant failed: more than one trustline changed.";
1397 <<
"Invariant failed: more than one mptokens changed.";
1405 AccountID const& holder = amount.getIssuer();
1409 if (holderBalance.
signum() < 0)
1412 <<
"Invariant failed: trustline balance is negative";
1421 JLOG(j.
fatal()) <<
"Invariant failed: some trustlines were changed "
1422 "despite failure of the transaction.";
1428 JLOG(j.
fatal()) <<
"Invariant failed: some mptokens were changed "
1429 "despite failure of the transaction.";
1445 if (
after &&
after->getType() == ltMPTOKEN_ISSUANCE)
1461 if (mptIssue.getIssuer() ==
after->at(sfAccount))
1477 auto const& rules = view.
rules();
1479 bool enforceCreatedByIssuer = rules.
enabled(featureSingleAssetVault) ||
1480 rules.enabled(featureLendingProtocol);
1484 <<
"Invariant failed: MPToken created for the MPT issuer";
1488 enforceCreatedByIssuer,
1489 "xrpl::ValidMPTIssuance::finalize",
1490 "no issuer MPToken");
1491 if (enforceCreatedByIssuer)
1500 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1501 "succeeded without creating a MPT issuance";
1505 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1506 "succeeded while removing MPT issuances";
1510 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1511 "succeeded but created multiple issuances";
1521 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1522 "succeeded without removing a MPT issuance";
1526 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1527 "succeeded while creating MPT issuances";
1531 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1532 "succeeded but deleted multiple issuances";
1538 bool const lendingProtocolEnabled =
1543 bool const enforceEscrowFinish = (txnType == ttESCROW_FINISH) &&
1545 lendingProtocolEnabled);
1547 enforceEscrowFinish)
1553 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize "
1554 "succeeded but created MPT issuances";
1559 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize "
1560 "succeeded but deleted issuances";
1564 lendingProtocolEnabled &&
1567 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize succeeded "
1568 "but created/deleted bad number mptokens";
1572 submittedByIssuer &&
1576 <<
"Invariant failed: MPT authorize submitted by issuer "
1577 "succeeded but created/deleted mptokens";
1587 <<
"Invariant failed: MPT authorize submitted by holder "
1588 "succeeded but created/deleted bad number of mptokens";
1594 if (txnType == ttESCROW_FINISH)
1600 !enforceEscrowFinish,
1601 "xrpl::ValidMPTIssuance::finalize",
1602 "not escrow finish tx");
1614 JLOG(j.
fatal()) <<
"Invariant failed: a MPT issuance was created";
1618 JLOG(j.
fatal()) <<
"Invariant failed: a MPT issuance was deleted";
1622 JLOG(j.
fatal()) <<
"Invariant failed: a MPToken was created";
1626 JLOG(j.
fatal()) <<
"Invariant failed: a MPToken was deleted";
1641 if (before && before->getType() != ltPERMISSIONED_DOMAIN)
1643 if (
after &&
after->getType() != ltPERMISSIONED_DOMAIN)
1648 auto const& credentials = sle->getFieldArray(sfAcceptedCredentials);
1659 for (
auto const& cred : sorted)
1661 auto const& credTx = credentials[i++];
1662 sleStatus.
isSorted_ = (cred.first == credTx[sfIssuer]) &&
1663 (cred.second == credTx[sfCredentialType]);
1697 JLOG(j.
fatal()) <<
"Invariant failed: permissioned domain with "
1705 JLOG(j.
fatal()) <<
"Invariant failed: permissioned domain bad "
1714 <<
"Invariant failed: permissioned domain credentials "
1722 <<
"Invariant failed: permissioned domain credentials "
1746 if (
after &&
after->getType() == ltACCOUNT_ROOT)
1748 bool const isPseudo = [&]() {
1755 if (
after->at(sfSequence) == 0)
1776 return after->isFieldPresent(*sf);
1781 error <<
"pseudo-account has " << numFields
1782 <<
" pseudo-account fields set";
1786 if (before && before->at(sfSequence) !=
after->at(sfSequence))
1795 if (
after->isFieldPresent(sfRegularKey))
1811 bool const enforce = view.
rules().
enabled(featureSingleAssetVault);
1814 "xrpl::ValidPseudoAccounts::finalize : no bad "
1815 "changes or enforce invariant");
1818 for (
auto const& error :
errors_)
1820 JLOG(j.
fatal()) <<
"Invariant failed: " << error;
1838 if (
after->isFieldPresent(sfDomainID))
1844 if (
after->isFieldPresent(sfDomainID))
1852 (!
after->isFieldPresent(sfDomainID) ||
1853 !
after->isFieldPresent(sfAdditionalBooks) ||
1854 after->getFieldArray(sfAdditionalBooks).size() > 1))
1868 if ((txType != ttPAYMENT && txType != ttOFFER_CREATE) ||
1876 JLOG(j.
fatal()) <<
"Invariant failed: hybrid offer is malformed";
1887 JLOG(j.
fatal()) <<
"Invariant failed: domain doesn't exist";
1897 JLOG(j.
fatal()) <<
"Invariant failed: transaction"
1898 " consumed wrong domains";
1905 JLOG(j.
fatal()) <<
"Invariant failed: domain transaction"
1906 " affected regular offers";
1924 auto const type =
after->getType();
1934 (type == ltACCOUNT_ROOT &&
after->isFieldPresent(sfAMMID)))
1943 if (before->getType() == ltAMM)
1957 bool const positive = amount > beast::zero && amount2 > beast::zero &&
1958 lptAMMBalance > beast::zero;
1961 (amount == beast::zero && amount2 == beast::zero &&
1962 lptAMMBalance == beast::zero);
1973 JLOG(j.
error()) <<
"AMMVote invariant failed: "
1992 JLOG(j.
error()) <<
"AMMBid invariant failed: pool changed";
2025 <<
"AMMCreate invariant failed: AMM object is not created";
2035 tx[sfAmount].get<Issue>(),
2036 tx[sfAmount2].get<Issue>(),
2047 JLOG(j.
error()) <<
"AMMCreate invariant failed: " << amount <<
" "
2064 ?
"AMM object is not deleted on tesSUCCESS"
2065 :
"AMM object is changed on tecINCOMPLETE";
2066 JLOG(j.
error()) <<
"AMMDelete invariant failed: " << msg;
2081 JLOG(j.
error()) <<
"AMM swap invariant failed: AMM object changed";
2100 tx[sfAsset].get<Issue>(),
2101 tx[sfAsset2].get<Issue>(),
2108 auto const poolProductMean =
root2(amount * amount2);
2109 bool const nonNegativeBalances =
2113 auto weakInvariantCheck = [&]() {
2118 if (!nonNegativeBalances ||
2119 (!strongInvariantCheck && !weakInvariantCheck()))
2124 <<
" " << poolProductMean <<
" "
2146 JLOG(j.
error()) <<
"AMMDeposit invariant failed: AMM object is deleted";
2198 case ttAMM_CLAWBACK:
2199 case ttAMM_WITHDRAW:
2208 case ttOFFER_CREATE:
2226 if (isDelete || !before)
2241 static auto const fieldChanged =
2242 [](
auto const& before,
auto const&
after,
auto const& field) {
2243 bool const beforeField = before->isFieldPresent(field);
2244 bool const afterField =
after->isFieldPresent(field);
2245 return beforeField != afterField ||
2246 (afterField && before->at(field) !=
after->at(field));
2250 auto const& before = slePair.first;
2251 auto const&
after = slePair.second;
2252 auto const type =
after->getType();
2254 [[maybe_unused]]
bool enforce =
false;
2263 enforce = view.
rules().
enabled(featureLendingProtocol);
2264 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2265 fieldChanged(before,
after, sfLedgerIndex) ||
2266 fieldChanged(before,
after, sfSequence) ||
2267 fieldChanged(before,
after, sfOwnerNode) ||
2268 fieldChanged(before,
after, sfVaultNode) ||
2269 fieldChanged(before,
after, sfVaultID) ||
2270 fieldChanged(before,
after, sfAccount) ||
2271 fieldChanged(before,
after, sfOwner) ||
2272 fieldChanged(before,
after, sfManagementFeeRate) ||
2273 fieldChanged(before,
after, sfCoverRateMinimum) ||
2274 fieldChanged(before,
after, sfCoverRateLiquidation);
2282 enforce = view.
rules().
enabled(featureLendingProtocol);
2283 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2284 fieldChanged(before,
after, sfLedgerIndex) ||
2285 fieldChanged(before,
after, sfSequence) ||
2286 fieldChanged(before,
after, sfOwnerNode) ||
2287 fieldChanged(before,
after, sfLoanBrokerNode) ||
2288 fieldChanged(before,
after, sfLoanBrokerID) ||
2289 fieldChanged(before,
after, sfBorrower) ||
2290 fieldChanged(before,
after, sfLoanOriginationFee) ||
2291 fieldChanged(before,
after, sfLoanServiceFee) ||
2292 fieldChanged(before,
after, sfLatePaymentFee) ||
2293 fieldChanged(before,
after, sfClosePaymentFee) ||
2294 fieldChanged(before,
after, sfOverpaymentFee) ||
2295 fieldChanged(before,
after, sfInterestRate) ||
2296 fieldChanged(before,
after, sfLateInterestRate) ||
2297 fieldChanged(before,
after, sfCloseInterestRate) ||
2298 fieldChanged(before,
after, sfOverpaymentInterestRate) ||
2299 fieldChanged(before,
after, sfStartDate) ||
2300 fieldChanged(before,
after, sfPaymentInterval) ||
2301 fieldChanged(before,
after, sfGracePeriod) ||
2302 fieldChanged(before,
after, sfLoanScale);
2314 enforce = view.
rules().
enabled(featureLendingProtocol);
2315 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2316 fieldChanged(before,
after, sfLedgerIndex);
2320 "xrpl::NoModifiedUnmodifiableFields::finalize : no bad "
2321 "changes or enforce invariant");
2325 <<
"Invariant failed: changed an unchangeable field for "
2344 if (
after->getType() == ltLOAN_BROKER)
2347 broker.brokerBefore = before;
2348 broker.brokerAfter =
after;
2351 after->getType() == ltACCOUNT_ROOT &&
2352 after->isFieldPresent(sfLoanBrokerID))
2354 auto const& loanBrokerID =
after->at(sfLoanBrokerID);
2358 else if (
after->getType() == ltRIPPLE_STATE)
2362 else if (
after->getType() == ltMPTOKEN)
2375 auto const next = dir->at(~sfIndexNext);
2376 auto const prev = dir->at(~sfIndexPrevious);
2377 if ((prev && *prev) || (next && *next))
2379 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker with zero "
2380 "OwnerCount has multiple directory pages";
2383 auto indexes = dir->getFieldV256(sfIndexes);
2384 if (indexes.size() > 1)
2387 <<
"Invariant failed: Loan Broker with zero "
2388 "OwnerCount has multiple indexes in the Directory root";
2391 if (indexes.size() == 1)
2393 auto const index = indexes.value().front();
2398 <<
"Invariant failed: Loan Broker directory corrupt";
2401 if (sle->getType() != ltRIPPLE_STATE && sle->getType() != ltMPTOKEN)
2404 <<
"Invariant failed: Loan Broker with zero "
2405 "OwnerCount has an unexpected entry in the directory";
2424 for (
auto const& line :
lines_)
2426 for (
auto const& field : {&sfLowLimit, &sfHighLimit})
2428 auto const account =
2433 if (account && account->isFieldPresent(sfLoanBrokerID))
2435 auto const& loanBrokerID = account->at(sfLoanBrokerID);
2441 for (
auto const& mpt :
mpts_)
2447 if (account && account->isFieldPresent(sfLoanBrokerID))
2449 auto const& loanBrokerID = account->at(sfLoanBrokerID);
2455 for (
auto const& [brokerID, broker] :
brokers_)
2457 auto const&
after = broker.brokerAfter
2458 ? broker.brokerAfter
2463 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker missing";
2467 auto const& before = broker.brokerBefore;
2473 if (
after->at(sfOwnerCount) == 0)
2484 if (before && before->at(sfLoanSequence) >
after->at(sfLoanSequence))
2486 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker sequence number "
2490 if (
after->at(sfDebtTotal) < 0)
2493 <<
"Invariant failed: Loan Broker debt total is negative";
2496 if (
after->at(sfCoverAvailable) < 0)
2499 <<
"Invariant failed: Loan Broker cover available is negative";
2506 <<
"Invariant failed: Loan Broker vault ID is invalid";
2509 auto const& vaultAsset = vault->at(sfAsset);
2512 after->at(sfAccount),
2518 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker cover available "
2519 "is less than pseudo-account asset balance";
2555 if (
after->at(sfPaymentRemaining) == 0 &&
2556 (
after->at(sfTotalValueOutstanding) != beast::zero ||
2557 after->at(sfPrincipalOutstanding) != beast::zero ||
2558 after->at(sfManagementFeeOutstanding) != beast::zero))
2560 JLOG(j.
fatal()) <<
"Invariant failed: Loan with zero payments "
2561 "remaining has not been paid off";
2566 if (
after->at(sfPaymentRemaining) != 0 &&
2567 after->at(sfTotalValueOutstanding) == beast::zero &&
2568 after->at(sfPrincipalOutstanding) == beast::zero &&
2569 after->at(sfManagementFeeOutstanding) == beast::zero)
2571 JLOG(j.
fatal()) <<
"Invariant failed: Loan with zero payments "
2572 "remaining has not been paid off";
2580 <<
"Invariant failed: Loan Overpayment flag changed";
2584 for (
auto const field :
2588 &sfPrincipalOutstanding,
2589 &sfTotalValueOutstanding,
2590 &sfManagementFeeOutstanding})
2592 if (
after->at(*field) < 0)
2594 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName()
2600 for (
auto const field : {
2604 if (
after->at(*field) <= 0)
2606 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName()
2607 <<
" is zero or negative ";
2620 "ValidVault::Vault::make : from Vault object");
2624 self.
asset = from.
at(sfAsset);
2626 self.
owner = from.
at(sfOwner);
2639 from.
getType() == ltMPTOKEN_ISSUANCE,
2640 "ValidVault::Shares::make : from MPTokenIssuance object");
2660 after !=
nullptr && (before !=
nullptr || !isDelete),
2661 "xrpl::ValidVault::visitEntry : some object is available");
2672 switch (before->getType())
2677 case ltMPTOKEN_ISSUANCE:
2682 before->getFieldU64(sfOutstandingAmount));
2687 static_cast<std::int64_t>(before->getFieldU64(sfMPTAmount));
2690 case ltACCOUNT_ROOT:
2691 case ltRIPPLE_STATE:
2692 balanceDelta = before->getFieldAmount(sfBalance);
2699 if (!isDelete &&
after)
2701 switch (
after->getType())
2706 case ltMPTOKEN_ISSUANCE:
2711 after->getFieldU64(sfOutstandingAmount)));
2719 case ltACCOUNT_ROOT:
2720 case ltRIPPLE_STATE:
2721 balanceDelta -=
Number(
after->getFieldAmount(sfBalance));
2728 uint256 const key = (before ? before->key() :
after->key());
2746 bool const enforce = view.
rules().
enabled(featureSingleAssetVault);
2756 "Invariant failed: vault operation succeeded without modifying "
2759 enforce,
"xrpl::ValidVault::finalize : vault noop invariant");
2769 "Invariant failed: vault updated by a wrong transaction type";
2772 "xrpl::ValidVault::finalize : illegal vault transaction "
2780 "Invariant failed: vault operation updated more than single vault";
2782 enforce,
"xrpl::ValidVault::finalize : single vault invariant");
2792 if (txnType != ttVAULT_DELETE)
2795 "Invariant failed: vault deleted by a wrong transaction type";
2798 "xrpl::ValidVault::finalize : illegal vault deletion "
2813 if (e.share.getMptID() == beforeVault.shareMPTID)
2814 return std::move(e);
2821 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must also "
2825 "xrpl::ValidVault::finalize : shares deletion invariant");
2830 if (deletedShares->sharesTotal != 0)
2832 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2833 "shares outstanding";
2836 if (beforeVault.assetsTotal !=
zero)
2838 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2839 "assets outstanding";
2842 if (beforeVault.assetsAvailable !=
zero)
2844 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2851 else if (txnType == ttVAULT_DELETE)
2853 JLOG(j.
fatal()) <<
"Invariant failed: vault deletion succeeded without "
2856 enforce,
"xrpl::ValidVault::finalize : vault deletion invariant");
2864 "xrpl::ValidVault::finalize : single vault operation");
2874 if (e.share.getMptID() == afterVault.shareMPTID)
2878 auto const sleShares =
2891 if (afterVault.asset != beforeVault.asset ||
2892 afterVault.pseudoId != beforeVault.pseudoId ||
2893 afterVault.shareMPTID != beforeVault.shareMPTID)
2896 <<
"Invariant failed: violation of vault immutable data";
2903 JLOG(j.
fatal()) <<
"Invariant failed: updated vault must have shares";
2905 enforce,
"xrpl::ValidVault::finalize : vault has shares invariant");
2909 if (updatedShares->sharesTotal == 0)
2911 if (afterVault.assetsTotal !=
zero)
2913 JLOG(j.
fatal()) <<
"Invariant failed: updated zero sized "
2914 "vault must have no assets outstanding";
2917 if (afterVault.assetsAvailable !=
zero)
2919 JLOG(j.
fatal()) <<
"Invariant failed: updated zero sized "
2920 "vault must have no assets available";
2924 else if (updatedShares->sharesTotal > updatedShares->sharesMaximum)
2927 <<
"Invariant failed: updated shares must not exceed maximum "
2928 << updatedShares->sharesMaximum;
2932 if (afterVault.assetsAvailable <
zero)
2935 <<
"Invariant failed: assets available must be positive";
2939 if (afterVault.assetsAvailable > afterVault.assetsTotal)
2941 JLOG(j.
fatal()) <<
"Invariant failed: assets available must "
2942 "not be greater than assets outstanding";
2946 afterVault.lossUnrealized >
2947 afterVault.assetsTotal - afterVault.assetsAvailable)
2950 <<
"Invariant failed: loss unrealized must not exceed "
2951 "the difference between assets outstanding and available";
2955 if (afterVault.assetsTotal <
zero)
2958 <<
"Invariant failed: assets outstanding must be positive";
2962 if (afterVault.assetsMaximum <
zero)
2964 JLOG(j.
fatal()) <<
"Invariant failed: assets maximum must be positive";
2973 "Invariant failed: vault created by a wrong transaction type";
2975 enforce,
"xrpl::ValidVault::finalize : vault creation invariant");
2980 afterVault.lossUnrealized !=
beforeVault_[0].lossUnrealized &&
2981 txnType != ttLOAN_MANAGE && txnType != ttLOAN_PAY)
2984 "Invariant failed: vault transaction must not change loss "
2996 if (e.share.getMptID() == beforeVault.shareMPTID)
2997 return std::move(e);
3002 if (!beforeShares &&
3007 JLOG(j.
fatal()) <<
"Invariant failed: vault operation succeeded "
3008 "without updating shares";
3010 enforce,
"xrpl::ValidVault::finalize : shares noop invariant");
3014 auto const& vaultAsset = afterVault.asset;
3021 return it->second *
sign;
3025 [&]<
typename TIss>(TIss
const& issue) {
3032 id > issue.getIssuer() ? -1 : 1);
3040 vaultAsset.value());
3043 auto ret = deltaAssets(tx[sfAccount]);
3045 if (!ret.has_value() || !vaultAsset.native())
3049 if (
auto const delegate = tx[~sfDelegate];
3050 delegate.has_value() && *delegate != tx[sfAccount])
3053 *ret += fee.
drops();
3060 auto const it = [&]() {
3061 if (
id == afterVault.pseudoId)
3071 auto const vaultHoldsNoAssets = [&](
Vault const& vault) {
3072 return vault.assetsAvailable == 0 && vault.assetsTotal == 0;
3082 case ttVAULT_CREATE: {
3088 <<
"Invariant failed: create operation must not have "
3093 if (afterVault.assetsAvailable !=
zero ||
3094 afterVault.assetsTotal !=
zero ||
3095 afterVault.lossUnrealized !=
zero ||
3096 updatedShares->sharesTotal != 0)
3099 <<
"Invariant failed: created vault must be empty";
3103 if (afterVault.pseudoId != updatedShares->share.getIssuer())
3106 <<
"Invariant failed: shares issuer and vault "
3107 "pseudo-account must be the same";
3111 auto const sleSharesIssuer = view.
read(
3113 if (!sleSharesIssuer)
3116 <<
"Invariant failed: shares issuer must exist";
3123 <<
"Invariant failed: shares issuer must be a "
3128 if (
auto const vaultId = (*sleSharesIssuer)[~sfVaultID];
3129 !vaultId || *vaultId != afterVault.key)
3132 <<
"Invariant failed: shares issuer pseudo-account "
3133 "must point back to the vault";
3144 "xrpl::ValidVault::finalize : set updated a vault");
3147 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3148 if (vaultDeltaAssets)
3151 "Invariant failed: set must not change vault balance";
3155 if (beforeVault.assetsTotal != afterVault.assetsTotal)
3158 "Invariant failed: set must not change assets "
3163 if (afterVault.assetsMaximum >
zero &&
3164 afterVault.assetsTotal > afterVault.assetsMaximum)
3167 "Invariant failed: set assets outstanding must not "
3168 "exceed assets maximum";
3172 if (beforeVault.assetsAvailable != afterVault.assetsAvailable)
3175 "Invariant failed: set must not change assets "
3180 if (beforeShares && updatedShares &&
3181 beforeShares->sharesTotal != updatedShares->sharesTotal)
3184 "Invariant failed: set must not change shares "
3191 case ttVAULT_DEPOSIT: {
3196 "xrpl::ValidVault::finalize : deposit updated a vault");
3199 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3201 if (!vaultDeltaAssets)
3204 "Invariant failed: deposit must change vault balance";
3208 if (*vaultDeltaAssets > tx[sfAmount])
3211 "Invariant failed: deposit must not change vault "
3212 "balance by more than deposited amount";
3216 if (*vaultDeltaAssets <=
zero)
3219 "Invariant failed: deposit must increase vault balance";
3225 bool const issuerDeposit = [&]() ->
bool {
3226 if (vaultAsset.native())
3228 return tx[sfAccount] == vaultAsset.getIssuer();
3233 auto const accountDeltaAssets = deltaAssetsTxAccount();
3234 if (!accountDeltaAssets)
3237 "Invariant failed: deposit must change depositor "
3242 if (*accountDeltaAssets >=
zero)
3245 "Invariant failed: deposit must decrease depositor "
3250 if (*accountDeltaAssets * -1 != *vaultDeltaAssets)
3253 "Invariant failed: deposit must change vault and "
3254 "depositor balance by equal amount";
3259 if (afterVault.assetsMaximum >
zero &&
3260 afterVault.assetsTotal > afterVault.assetsMaximum)
3263 "Invariant failed: deposit assets outstanding must not "
3264 "exceed assets maximum";
3268 auto const accountDeltaShares = deltaShares(tx[sfAccount]);
3269 if (!accountDeltaShares)
3272 "Invariant failed: deposit must change depositor "
3277 if (*accountDeltaShares <=
zero)
3280 "Invariant failed: deposit must increase depositor "
3285 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3286 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3289 "Invariant failed: deposit must change vault shares";
3293 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3296 "Invariant failed: deposit must change depositor and "
3297 "vault shares by equal amount";
3301 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3302 afterVault.assetsTotal)
3304 JLOG(j.
fatal()) <<
"Invariant failed: deposit and assets "
3305 "outstanding must add up";
3308 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3309 afterVault.assetsAvailable)
3311 JLOG(j.
fatal()) <<
"Invariant failed: deposit and assets "
3312 "available must add up";
3318 case ttVAULT_WITHDRAW: {
3323 "xrpl::ValidVault::finalize : withdrawal updated a "
3327 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3329 if (!vaultDeltaAssets)
3331 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal must "
3332 "change vault balance";
3336 if (*vaultDeltaAssets >=
zero)
3338 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal must "
3339 "decrease vault balance";
3345 bool const issuerWithdrawal = [&]() ->
bool {
3346 if (vaultAsset.native())
3348 auto const destination =
3349 tx[~sfDestination].value_or(tx[sfAccount]);
3350 return destination == vaultAsset.getIssuer();
3353 if (!issuerWithdrawal)
3355 auto const accountDeltaAssets = deltaAssetsTxAccount();
3356 auto const otherAccountDelta =
3358 if (
auto const destination = tx[~sfDestination];
3359 destination && *destination != tx[sfAccount])
3360 return deltaAssets(*destination);
3364 if (accountDeltaAssets.has_value() ==
3365 otherAccountDelta.has_value())
3368 "Invariant failed: withdrawal must change one "
3369 "destination balance";
3373 auto const destinationDelta =
3374 accountDeltaAssets ? *accountDeltaAssets
3375 : *otherAccountDelta;
3377 if (destinationDelta <=
zero)
3380 "Invariant failed: withdrawal must increase "
3381 "destination balance";
3385 if (*vaultDeltaAssets * -1 != destinationDelta)
3388 "Invariant failed: withdrawal must change vault "
3389 "and destination balance by equal amount";
3394 auto const accountDeltaShares = deltaShares(tx[sfAccount]);
3395 if (!accountDeltaShares)
3398 "Invariant failed: withdrawal must change depositor "
3403 if (*accountDeltaShares >=
zero)
3406 "Invariant failed: withdrawal must decrease depositor "
3411 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3412 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3415 "Invariant failed: withdrawal must change vault shares";
3419 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3422 "Invariant failed: withdrawal must change depositor "
3423 "and vault shares by equal amount";
3428 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3429 afterVault.assetsTotal)
3431 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal and "
3432 "assets outstanding must add up";
3436 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3437 afterVault.assetsAvailable)
3439 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal and "
3440 "assets available must add up";
3446 case ttVAULT_CLAWBACK: {
3451 "xrpl::ValidVault::finalize : clawback updated a vault");
3454 if (vaultAsset.native() ||
3455 vaultAsset.getIssuer() != tx[sfAccount])
3459 if (!(beforeShares && beforeShares->sharesTotal > 0 &&
3460 vaultHoldsNoAssets(beforeVault) &&
3461 beforeVault.owner == tx[sfAccount]))
3464 "Invariant failed: clawback may only be performed "
3465 "by the asset issuer, or by the vault owner of an "
3471 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3472 if (vaultDeltaAssets)
3474 if (*vaultDeltaAssets >=
zero)
3477 "Invariant failed: clawback must decrease vault "
3482 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3483 afterVault.assetsTotal)
3486 "Invariant failed: clawback and assets outstanding "
3491 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3492 afterVault.assetsAvailable)
3495 "Invariant failed: clawback and assets available "
3500 else if (!vaultHoldsNoAssets(beforeVault))
3503 "Invariant failed: clawback must change vault balance";
3507 auto const accountDeltaShares = deltaShares(tx[sfHolder]);
3508 if (!accountDeltaShares)
3511 "Invariant failed: clawback must change holder shares";
3515 if (*accountDeltaShares >=
zero)
3518 "Invariant failed: clawback must decrease holder "
3523 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3524 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3527 "Invariant failed: clawback must change vault shares";
3531 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3534 "Invariant failed: clawback must change holder and "
3535 "vault shares by equal amount";
3552 "xrpl::ValidVault::finalize : unknown transaction type");
3562 XRPL_ASSERT(enforce,
"xrpl::ValidVault::finalize : vault invariants");
A generic endpoint for log messages.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< std::pair< std::shared_ptr< SLE const >, std::shared_ptr< SLE const > > > accountsDeleted_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t accountsDeleted_
A currency issued by an account.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::uint32_t beforeMintedTotal
std::uint32_t afterBurnedTotal
std::uint32_t afterMintedTotal
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t beforeBurnedTotal
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
bool deepFreezeWithoutFreeze_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::set< std::pair< SLE::const_pointer, SLE::const_pointer > > changedEntries_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
int signum() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
bool native() const noexcept
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
LedgerEntryType getType() const
uint192 getFieldH192(SField const &field) const
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
std::uint32_t getFieldU32(SField const &field) const
uint256 getHash(HashPrefix prefix) const
bool isFieldPresent(SField const &field) const
uint256 getFieldH256(SField const &field) const
AccountID getAccountID(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
TxType getTxnType() const
uint256 getTransactionID() const
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::shared_ptr< SLE const > findIssuer(AccountID const &issuerID, ReadView const &view)
void recordBalance(Issue const &issue, BalanceChange change)
bool isValidEntry(std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
bool validateIssuerChanges(std::shared_ptr< SLE const > const &issuer, IssuerChanges const &changes, STTx const &tx, beast::Journal const &j, bool enforce)
std::map< AccountID, std::shared_ptr< SLE const > const > possibleIssuers_
STAmount calculateBalanceChange(std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after, bool isDelete)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
bool validateFrozenState(BalanceChange const &change, bool high, STTx const &tx, beast::Journal const &j, bool enforce, bool globalFreeze)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
void recordBalanceChanges(std::shared_ptr< SLE const > const &after, STAmount const &balanceChange)
std::optional< AccountID > ammAccount_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
bool finalizeWithdraw(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool finalizeBid(bool enforce, beast::Journal const &) const
bool finalizeCreate(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool finalizeDEX(bool enforce, beast::Journal const &) const
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalizeDeposit(STTx const &, ReadView const &, bool enforce, beast::Journal const &) const
bool generalInvariant(STTx const &, ReadView const &, ZeroAllowed zeroAllowed, beast::Journal const &) const
std::optional< STAmount > lptAMMBalanceAfter_
bool finalizeVote(bool enforce, beast::Journal const &) const
bool finalizeDelete(bool enforce, TER res, beast::Journal const &) const
std::optional< STAmount > lptAMMBalanceBefore_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::uint32_t trustlinesChanged
std::uint32_t mptokensChanged
std::map< uint256, BrokerInfo > brokers_
bool goodZeroDirectory(ReadView const &view, SLE::const_ref dir, beast::Journal const &j) const
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::vector< SLE::const_pointer > mpts_
std::vector< SLE::const_pointer > lines_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::vector< std::pair< SLE::const_pointer, SLE::const_pointer > > loans_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t mptokensCreated_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t mptokensDeleted_
std::uint32_t mptIssuancesCreated_
std::uint32_t mptIssuancesDeleted_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::uint32_t accountsCreated_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::uint32_t accountSeq_
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
hash_set< uint256 > domains_
std::optional< SleStatus > sleStatus_[2]
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
std::vector< std::string > errors_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
static Number constexpr zero
std::vector< Shares > afterMPTs_
std::unordered_map< uint256, Number > deltas_
std::vector< Vault > afterVault_
std::vector< Shares > beforeMPTs_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< Vault > beforeVault_
constexpr value_type drops() const
Returns the number of drops.
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
T emplace_back(T... args)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet loanbroker(AccountID const &owner, std::uint32_t seq) noexcept
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
uint256 constexpr pageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
bool compareTokens(uint256 const &a, uint256 const &b)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::size_t constexpr dirMaxTokensPerPage
The maximum number of items in an NFT page.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
std::vector< SField const * > const & getPseudoAccountFields()
bool isXRP(AccountID const &c)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
STAmount ammLPTokens(STAmount const &asset1, STAmount const &asset2, Issue const &lptIssue)
Calculate LP Tokens given AMM pool reserves.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
static bool validBalances(STAmount const &amount, STAmount const &amount2, STAmount const &lptAMMBalance, ValidAMM::ZeroAllowed zeroAllowed)
bool hasPrivilege(STTx const &tx, Privilege priv)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
std::size_t constexpr maxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
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.
@ transactionID
transaction plus signature to give transaction ID
bool isTesSuccess(TER x) noexcept
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
bool withinRelativeDistance(Quality const &calcQuality, Quality const &reqQuality, Number const &dist)
Check if the relative distance between the qualities is within the requested distance.
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safe_cast(Src s) noexcept
std::array< keyletDesc< AccountID const & >, 6 > const directAccountKeylets
A pair of SHAMap key and LedgerEntryType.
int const balanceChangeSign
std::shared_ptr< SLE const > const line
std::vector< BalanceChange > senders
std::vector< BalanceChange > receivers
std::size_t credentialsSize_
std::uint64_t sharesMaximum
static Shares make(SLE const &)
std::uint64_t sharesTotal
static Vault make(SLE const &)