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, delegatable, amendment, privileges, ...) \
89 return (privileges) & priv; \
97#include <xrpl/protocol/detail/transactions.macro>
105#pragma pop_macro("TRANSACTION")
127 JLOG(j.
fatal()) <<
"Invariant failed: fee paid was negative: "
136 JLOG(j.
fatal()) <<
"Invariant failed: fee paid exceeds system limit: "
145 JLOG(j.
fatal()) <<
"Invariant failed: fee paid is " << fee.
drops()
146 <<
" exceeds fee specified in transaction.";
170 switch (before->getType())
173 drops_ -= (*before)[sfBalance].xrp().drops();
177 ((*before)[sfAmount] - (*before)[sfBalance]).xrp().drops();
180 if (
isXRP((*before)[sfAmount]))
181 drops_ -= (*before)[sfAmount].xrp().drops();
190 switch (
after->getType())
193 drops_ += (*after)[sfBalance].xrp().drops();
197 drops_ += ((*after)[sfAmount] - (*after)[sfBalance])
203 drops_ += (*after)[sfAmount].xrp().drops();
223 JLOG(j.
fatal()) <<
"Invariant failed: XRP net change was positive: "
231 JLOG(j.
fatal()) <<
"Invariant failed: XRP net change of " <<
drops_
232 <<
" doesn't match fee " << fee.
drops();
247 auto isBad = [](
STAmount const& balance) {
248 if (!balance.native())
251 auto const drops = balance.xrp();
265 if (before && before->getType() == ltACCOUNT_ROOT)
266 bad_ |= isBad((*before)[sfBalance]);
268 if (
after &&
after->getType() == ltACCOUNT_ROOT)
282 JLOG(j.
fatal()) <<
"Invariant failed: incorrect account XRP balance";
299 if (pays < beast::zero)
302 if (gets < beast::zero)
306 return pays.
native() && gets.native();
309 if (before && before->getType() == ltOFFER)
310 bad_ |= isBad((*before)[sfTakerPays], (*before)[sfTakerGets]);
313 bad_ |= isBad((*
after)[sfTakerPays], (*after)[sfTakerGets]);
326 JLOG(j.
fatal()) <<
"Invariant failed: offer with a bad amount";
341 auto isBad = [](
STAmount const& amount) {
354 if (amount.holds<
Issue>())
356 if (amount <= beast::zero)
366 if (amount <= beast::zero)
376 if (before && before->getType() == ltESCROW)
377 bad_ |= isBad((*before)[sfAmount]);
387 if (
after &&
after->getType() == ltMPTOKEN_ISSUANCE)
389 auto const outstanding = (*after)[sfOutstandingAmount];
390 checkAmount(outstanding);
391 if (
auto const locked = (*
after)[~sfLockedAmount])
393 checkAmount(*locked);
394 bad_ = outstanding < *locked;
400 auto const mptAmount = (*after)[sfMPTAmount];
401 checkAmount(mptAmount);
402 if (
auto const locked = (*
after)[~sfLockedAmount])
404 checkAmount(*locked);
419 JLOG(j.
fatal()) <<
"Invariant failed: escrow specifies invalid amount";
434 if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
456 JLOG(j.
fatal()) <<
"Invariant failed: account deletion "
457 "succeeded without deleting an account";
459 JLOG(j.
fatal()) <<
"Invariant failed: account deletion "
460 "succeeded but deleted multiple accounts!";
474 JLOG(j.
fatal()) <<
"Invariant failed: an account root was deleted";
486 if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
502 [[maybe_unused]]
bool const enforce =
507 auto const objectExists = [&view, enforce, &j](
auto const& keylet) {
509 if (
auto const sle = view.
read(keylet))
512 auto const typeName = [&sle]() {
517 return item->getName();
522 <<
"Invariant failed: account deletion left behind a "
523 << typeName <<
" object";
528 "xrpl::AccountRootsDeletedClean::finalize::objectExists : "
529 "account deletion left no objects behind");
537 auto const accountID = before->getAccountID(sfAccount);
539 if (
after->at(sfBalance) != beast::zero)
541 JLOG(j.
fatal()) <<
"Invariant failed: account deletion left "
542 "behind a non-zero balance";
545 "xrpl::AccountRootsDeletedClean::finalize : "
546 "deleted account has zero balance");
551 if (
after->at(sfOwnerCount) != 0)
553 JLOG(j.
fatal()) <<
"Invariant failed: account deletion left "
554 "behind a non-zero owner count";
557 "xrpl::AccountRootsDeletedClean::finalize : "
558 "deleted account has zero owner count");
565 if (objectExists(
std::invoke(keyletfunc, accountID)) && enforce)
580 if (key && objectExists(
Keylet{ltNFTOKEN_PAGE, *key}) && enforce)
588 if (before->isFieldPresent(*field))
590 auto const key = before->getFieldH256(*field);
608 if (before &&
after && before->getType() !=
after->getType())
613#pragma push_macro("LEDGER_ENTRY")
616#define LEDGER_ENTRY(tag, ...) case tag:
618 switch (
after->getType())
620#include <xrpl/protocol/detail/ledger_entries.macro>
629#pragma pop_macro("LEDGER_ENTRY")
646 JLOG(j.
fatal()) <<
"Invariant failed: ledger entry type mismatch";
651 JLOG(j.
fatal()) <<
"Invariant failed: invalid ledger entry type added";
665 if (
after &&
after->getType() == ltRIPPLE_STATE)
687 JLOG(j.
fatal()) <<
"Invariant failed: an XRP trust line was created";
699 if (
after &&
after->getType() == ltRIPPLE_STATE)
709 (lowDeepFreeze && !lowFreeze) || (highDeepFreeze && !highFreeze);
724 JLOG(j.
fatal()) <<
"Invariant failed: a trust line with deep freeze flag "
725 "without normal freeze was created";
753 if (balanceChange.signum() == 0)
785 [[maybe_unused]]
bool const enforce =
790 auto const issuerSle =
findIssuer(issue.account, view);
799 "xrpl::TransfersNotFrozen::finalize : enforce "
823 XRPL_ASSERT(
after,
"xrpl::TransfersNotFrozen::isValidEntry : valid after.");
829 if (
after->getType() == ltACCOUNT_ROOT)
841 return after->getType() == ltRIPPLE_STATE &&
842 (!before || before->getType() == ltRIPPLE_STATE);
851 auto const getBalance = [](
auto const& line,
auto const& other,
bool zero) {
853 line ? line->at(sfBalance) : other->at(sfBalance).zeroed();
854 return zero ? amt.
zeroed() : amt;
862 auto const balanceBefore = getBalance(before,
after,
false);
869 auto const balanceAfter = getBalance(
after, before, isDelete);
871 return balanceAfter - balanceBefore;
879 "xrpl::TransfersNotFrozen::recordBalance : valid trustline "
883 changes.senders.emplace_back(std::move(change));
885 changes.receivers.emplace_back(std::move(change));
893 auto const balanceChangeSign = balanceChange.
signum();
894 auto const currency =
after->at(sfBalance).getCurrency();
898 {currency,
after->at(sfHighLimit).getIssuer()},
899 {
after, balanceChangeSign});
903 {currency,
after->at(sfLowLimit).getIssuer()},
904 {
after, -balanceChangeSign});
946 for (
auto const& change : actors)
948 bool const high = change.line->at(sfLowLimit).getIssuer() ==
949 issuer->at(sfAccount);
952 change, high, tx, j, enforce, globalFreeze))
972 bool const deepFreeze =
974 bool const frozen = globalFreeze || deepFreeze || freeze;
986 JLOG(j.
debug()) <<
"Invariant check allowing funds to be moved "
988 <<
" a frozen trustline for AMMClawback "
993 JLOG(j.
fatal()) <<
"Invariant failed: Attempting to move frozen funds for "
998 "xrpl::TransfersNotFrozen::validateFrozenState : enforce "
1017 if (!before &&
after->getType() == ltACCOUNT_ROOT)
1039 JLOG(j.
fatal()) <<
"Invariant failed: multiple accounts "
1040 "created in a single transaction";
1047 bool const pseudoAccount =
1054 JLOG(j.
fatal()) <<
"Invariant failed: pseudo-account created by a "
1055 "wrong transaction type";
1063 JLOG(j.
fatal()) <<
"Invariant failed: account created with "
1064 "wrong starting sequence number";
1075 <<
"Invariant failed: pseudo-account created with "
1084 JLOG(j.
fatal()) <<
"Invariant failed: account root created illegally";
1097 static constexpr uint256 const accountBits = ~pageBits;
1099 if ((before && before->getType() != ltNFTOKEN_PAGE) ||
1100 (
after &&
after->getType() != ltNFTOKEN_PAGE))
1104 uint256 const account = sle->
key() & accountBits;
1105 uint256 const hiLimit = sle->key() & pageBits;
1113 if (account != (*prev & accountBits))
1116 if (hiLimit <= (*prev & pageBits))
1120 if (
auto const next = (*sle)[~sfNextPageMin])
1122 if (account != (*next & accountBits))
1125 if (hiLimit >= (*next & pageBits))
1130 auto const& nftokens = sle->getFieldArray(sfNFTokens);
1133 if (
std::size_t const nftokenCount = nftokens.size();
1134 (!isDelete && nftokenCount == 0) ||
1141 prev ? *prev & pageBits :
uint256(beast::zero);
1145 for (
auto const& obj : nftokens)
1147 uint256 const tokenID = obj[sfNFTokenID];
1154 if (
uint256 const tokenPageBits = tokenID & pageBits;
1155 tokenPageBits < loLimit || tokenPageBits >= hiLimit)
1158 if (
auto uri = obj[~sfURI]; uri && uri->empty())
1172 before->isFieldPresent(sfPreviousPageMin))
1181 if (!isDelete && before &&
after)
1189 before->isFieldPresent(sfNextPageMin) &&
1190 !
after->isFieldPresent(sfNextPageMin))
1207 JLOG(j.
fatal()) <<
"Invariant failed: NFT page is improperly linked.";
1213 JLOG(j.
fatal()) <<
"Invariant failed: NFT found in incorrect page.";
1219 JLOG(j.
fatal()) <<
"Invariant failed: NFTs on page are not sorted.";
1225 JLOG(j.
fatal()) <<
"Invariant failed: NFT contains empty URI.";
1231 JLOG(j.
fatal()) <<
"Invariant failed: NFT page has invalid size.";
1239 JLOG(j.
fatal()) <<
"Invariant failed: Last NFT page deleted with "
1240 "non-empty directory.";
1245 JLOG(j.
fatal()) <<
"Invariant failed: Lost NextMinPage link.";
1260 if (before && before->getType() == ltACCOUNT_ROOT)
1266 if (
after &&
after->getType() == ltACCOUNT_ROOT)
1285 JLOG(j.
fatal()) <<
"Invariant failed: the number of minted tokens "
1286 "changed without a mint transaction!";
1292 JLOG(j.
fatal()) <<
"Invariant failed: the number of burned tokens "
1293 "changed without a burn transaction!";
1305 <<
"Invariant failed: successful minting didn't increase "
1306 "the number of minted tokens.";
1312 JLOG(j.
fatal()) <<
"Invariant failed: failed minting changed the "
1313 "number of minted tokens.";
1320 <<
"Invariant failed: minting changed the number of "
1333 <<
"Invariant failed: successful burning didn't increase "
1334 "the number of burned tokens.";
1341 JLOG(j.
fatal()) <<
"Invariant failed: failed burning changed the "
1342 "number of burned tokens.";
1349 <<
"Invariant failed: burning changed the number of "
1366 if (before && before->getType() == ltRIPPLE_STATE)
1369 if (before && before->getType() == ltMPTOKEN)
1389 <<
"Invariant failed: more than one trustline changed.";
1396 <<
"Invariant failed: more than one mptokens changed.";
1404 AccountID const& holder = amount.getIssuer();
1408 if (holderBalance.
signum() < 0)
1411 <<
"Invariant failed: trustline balance is negative";
1420 JLOG(j.
fatal()) <<
"Invariant failed: some trustlines were changed "
1421 "despite failure of the transaction.";
1427 JLOG(j.
fatal()) <<
"Invariant failed: some mptokens were changed "
1428 "despite failure of the transaction.";
1444 if (
after &&
after->getType() == ltMPTOKEN_ISSUANCE)
1460 if (mptIssue.getIssuer() ==
after->at(sfAccount))
1476 auto const& rules = view.
rules();
1478 bool enforceCreatedByIssuer = rules.
enabled(featureSingleAssetVault) ||
1479 rules.enabled(featureLendingProtocol);
1483 <<
"Invariant failed: MPToken created for the MPT issuer";
1487 enforceCreatedByIssuer,
1488 "xrpl::ValidMPTIssuance::finalize",
1489 "no issuer MPToken");
1490 if (enforceCreatedByIssuer)
1499 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1500 "succeeded without creating a MPT issuance";
1504 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1505 "succeeded while removing MPT issuances";
1509 JLOG(j.
fatal()) <<
"Invariant failed: transaction "
1510 "succeeded but created multiple issuances";
1520 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1521 "succeeded without removing a MPT issuance";
1525 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1526 "succeeded while creating MPT issuances";
1530 JLOG(j.
fatal()) <<
"Invariant failed: MPT issuance deletion "
1531 "succeeded but deleted multiple issuances";
1537 bool const lendingProtocolEnabled =
1542 bool const enforceEscrowFinish = (txnType == ttESCROW_FINISH) &&
1544 lendingProtocolEnabled);
1546 enforceEscrowFinish)
1552 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize "
1553 "succeeded but created MPT issuances";
1558 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize "
1559 "succeeded but deleted issuances";
1563 lendingProtocolEnabled &&
1566 JLOG(j.
fatal()) <<
"Invariant failed: MPT authorize succeeded "
1567 "but created/deleted bad number mptokens";
1571 submittedByIssuer &&
1575 <<
"Invariant failed: MPT authorize submitted by issuer "
1576 "succeeded but created/deleted mptokens";
1586 <<
"Invariant failed: MPT authorize submitted by holder "
1587 "succeeded but created/deleted bad number of mptokens";
1593 if (txnType == ttESCROW_FINISH)
1599 !enforceEscrowFinish,
1600 "xrpl::ValidMPTIssuance::finalize",
1601 "not escrow finish tx");
1613 JLOG(j.
fatal()) <<
"Invariant failed: a MPT issuance was created";
1617 JLOG(j.
fatal()) <<
"Invariant failed: a MPT issuance was deleted";
1621 JLOG(j.
fatal()) <<
"Invariant failed: a MPToken was created";
1625 JLOG(j.
fatal()) <<
"Invariant failed: a MPToken was deleted";
1640 if (before && before->getType() != ltPERMISSIONED_DOMAIN)
1642 if (
after &&
after->getType() != ltPERMISSIONED_DOMAIN)
1647 auto const& credentials = sle->getFieldArray(sfAcceptedCredentials);
1658 for (
auto const& cred : sorted)
1660 auto const& credTx = credentials[i++];
1661 sleStatus.
isSorted_ = (cred.first == credTx[sfIssuer]) &&
1662 (cred.second == credTx[sfCredentialType]);
1696 JLOG(j.
fatal()) <<
"Invariant failed: permissioned domain with "
1704 JLOG(j.
fatal()) <<
"Invariant failed: permissioned domain bad "
1713 <<
"Invariant failed: permissioned domain credentials "
1721 <<
"Invariant failed: permissioned domain credentials "
1745 if (
after &&
after->getType() == ltACCOUNT_ROOT)
1747 bool const isPseudo = [&]() {
1754 if (
after->at(sfSequence) == 0)
1775 return after->isFieldPresent(*sf);
1780 error <<
"pseudo-account has " << numFields
1781 <<
" pseudo-account fields set";
1785 if (before && before->at(sfSequence) !=
after->at(sfSequence))
1794 if (
after->isFieldPresent(sfRegularKey))
1810 bool const enforce = view.
rules().
enabled(featureSingleAssetVault);
1813 "xrpl::ValidPseudoAccounts::finalize : no bad "
1814 "changes or enforce invariant");
1817 for (
auto const& error :
errors_)
1819 JLOG(j.
fatal()) <<
"Invariant failed: " << error;
1837 if (
after->isFieldPresent(sfDomainID))
1843 if (
after->isFieldPresent(sfDomainID))
1851 (!
after->isFieldPresent(sfDomainID) ||
1852 !
after->isFieldPresent(sfAdditionalBooks) ||
1853 after->getFieldArray(sfAdditionalBooks).size() > 1))
1867 if ((txType != ttPAYMENT && txType != ttOFFER_CREATE) ||
1875 JLOG(j.
fatal()) <<
"Invariant failed: hybrid offer is malformed";
1886 JLOG(j.
fatal()) <<
"Invariant failed: domain doesn't exist";
1896 JLOG(j.
fatal()) <<
"Invariant failed: transaction"
1897 " consumed wrong domains";
1904 JLOG(j.
fatal()) <<
"Invariant failed: domain transaction"
1905 " affected regular offers";
1923 auto const type =
after->getType();
1933 (type == ltACCOUNT_ROOT &&
after->isFieldPresent(sfAMMID)))
1942 if (before->getType() == ltAMM)
1956 bool const positive = amount > beast::zero && amount2 > beast::zero &&
1957 lptAMMBalance > beast::zero;
1960 (amount == beast::zero && amount2 == beast::zero &&
1961 lptAMMBalance == beast::zero);
1972 JLOG(j.
error()) <<
"AMMVote invariant failed: "
1991 JLOG(j.
error()) <<
"AMMBid invariant failed: pool changed";
2024 <<
"AMMCreate invariant failed: AMM object is not created";
2034 tx[sfAmount].get<Issue>(),
2035 tx[sfAmount2].get<Issue>(),
2046 JLOG(j.
error()) <<
"AMMCreate invariant failed: " << amount <<
" "
2063 ?
"AMM object is not deleted on tesSUCCESS"
2064 :
"AMM object is changed on tecINCOMPLETE";
2065 JLOG(j.
error()) <<
"AMMDelete invariant failed: " << msg;
2080 JLOG(j.
error()) <<
"AMM swap invariant failed: AMM object changed";
2099 tx[sfAsset].get<Issue>(),
2100 tx[sfAsset2].get<Issue>(),
2107 auto const poolProductMean =
root2(amount * amount2);
2108 bool const nonNegativeBalances =
2112 auto weakInvariantCheck = [&]() {
2117 if (!nonNegativeBalances ||
2118 (!strongInvariantCheck && !weakInvariantCheck()))
2123 <<
" " << poolProductMean <<
" "
2145 JLOG(j.
error()) <<
"AMMDeposit invariant failed: AMM object is deleted";
2197 case ttAMM_CLAWBACK:
2198 case ttAMM_WITHDRAW:
2207 case ttOFFER_CREATE:
2225 if (isDelete || !before)
2240 static auto const fieldChanged =
2241 [](
auto const& before,
auto const&
after,
auto const& field) {
2242 bool const beforeField = before->isFieldPresent(field);
2243 bool const afterField =
after->isFieldPresent(field);
2244 return beforeField != afterField ||
2245 (afterField && before->at(field) !=
after->at(field));
2249 auto const& before = slePair.first;
2250 auto const&
after = slePair.second;
2251 auto const type =
after->getType();
2253 [[maybe_unused]]
bool enforce =
false;
2262 enforce = view.
rules().
enabled(featureLendingProtocol);
2263 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2264 fieldChanged(before,
after, sfLedgerIndex) ||
2265 fieldChanged(before,
after, sfSequence) ||
2266 fieldChanged(before,
after, sfOwnerNode) ||
2267 fieldChanged(before,
after, sfVaultNode) ||
2268 fieldChanged(before,
after, sfVaultID) ||
2269 fieldChanged(before,
after, sfAccount) ||
2270 fieldChanged(before,
after, sfOwner) ||
2271 fieldChanged(before,
after, sfManagementFeeRate) ||
2272 fieldChanged(before,
after, sfCoverRateMinimum) ||
2273 fieldChanged(before,
after, sfCoverRateLiquidation);
2281 enforce = view.
rules().
enabled(featureLendingProtocol);
2282 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2283 fieldChanged(before,
after, sfLedgerIndex) ||
2284 fieldChanged(before,
after, sfSequence) ||
2285 fieldChanged(before,
after, sfOwnerNode) ||
2286 fieldChanged(before,
after, sfLoanBrokerNode) ||
2287 fieldChanged(before,
after, sfLoanBrokerID) ||
2288 fieldChanged(before,
after, sfBorrower) ||
2289 fieldChanged(before,
after, sfLoanOriginationFee) ||
2290 fieldChanged(before,
after, sfLoanServiceFee) ||
2291 fieldChanged(before,
after, sfLatePaymentFee) ||
2292 fieldChanged(before,
after, sfClosePaymentFee) ||
2293 fieldChanged(before,
after, sfOverpaymentFee) ||
2294 fieldChanged(before,
after, sfInterestRate) ||
2295 fieldChanged(before,
after, sfLateInterestRate) ||
2296 fieldChanged(before,
after, sfCloseInterestRate) ||
2297 fieldChanged(before,
after, sfOverpaymentInterestRate) ||
2298 fieldChanged(before,
after, sfStartDate) ||
2299 fieldChanged(before,
after, sfPaymentInterval) ||
2300 fieldChanged(before,
after, sfGracePeriod) ||
2301 fieldChanged(before,
after, sfLoanScale);
2313 enforce = view.
rules().
enabled(featureLendingProtocol);
2314 bad = fieldChanged(before,
after, sfLedgerEntryType) ||
2315 fieldChanged(before,
after, sfLedgerIndex);
2319 "xrpl::NoModifiedUnmodifiableFields::finalize : no bad "
2320 "changes or enforce invariant");
2324 <<
"Invariant failed: changed an unchangable field for "
2343 if (
after->getType() == ltLOAN_BROKER)
2346 broker.brokerBefore = before;
2347 broker.brokerAfter =
after;
2350 after->getType() == ltACCOUNT_ROOT &&
2351 after->isFieldPresent(sfLoanBrokerID))
2353 auto const& loanBrokerID =
after->at(sfLoanBrokerID);
2357 else if (
after->getType() == ltRIPPLE_STATE)
2361 else if (
after->getType() == ltMPTOKEN)
2374 auto const next = dir->at(~sfIndexNext);
2375 auto const prev = dir->at(~sfIndexPrevious);
2376 if ((prev && *prev) || (next && *next))
2378 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker with zero "
2379 "OwnerCount has multiple directory pages";
2382 auto indexes = dir->getFieldV256(sfIndexes);
2383 if (indexes.size() > 1)
2386 <<
"Invariant failed: Loan Broker with zero "
2387 "OwnerCount has multiple indexes in the Directory root";
2390 if (indexes.size() == 1)
2392 auto const index = indexes.value().front();
2397 <<
"Invariant failed: Loan Broker directory corrupt";
2400 if (sle->getType() != ltRIPPLE_STATE && sle->getType() != ltMPTOKEN)
2403 <<
"Invariant failed: Loan Broker with zero "
2404 "OwnerCount has an unexpected entry in the directory";
2423 for (
auto const& line :
lines_)
2425 for (
auto const& field : {&sfLowLimit, &sfHighLimit})
2427 auto const account =
2432 if (account && account->isFieldPresent(sfLoanBrokerID))
2434 auto const& loanBrokerID = account->at(sfLoanBrokerID);
2440 for (
auto const& mpt :
mpts_)
2446 if (account && account->isFieldPresent(sfLoanBrokerID))
2448 auto const& loanBrokerID = account->at(sfLoanBrokerID);
2454 for (
auto const& [brokerID, broker] :
brokers_)
2456 auto const&
after = broker.brokerAfter
2457 ? broker.brokerAfter
2462 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker missing";
2466 auto const& before = broker.brokerBefore;
2472 if (
after->at(sfOwnerCount) == 0)
2483 if (before && before->at(sfLoanSequence) >
after->at(sfLoanSequence))
2485 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker sequence number "
2489 if (
after->at(sfDebtTotal) < 0)
2492 <<
"Invariant failed: Loan Broker debt total is negative";
2495 if (
after->at(sfCoverAvailable) < 0)
2498 <<
"Invariant failed: Loan Broker cover available is negative";
2505 <<
"Invariant failed: Loan Broker vault ID is invalid";
2508 auto const& vaultAsset = vault->at(sfAsset);
2511 after->at(sfAccount),
2517 JLOG(j.
fatal()) <<
"Invariant failed: Loan Broker cover available "
2518 "is less than pseudo-account asset balance";
2554 if (
after->at(sfPaymentRemaining) == 0 &&
2555 (
after->at(sfTotalValueOutstanding) != beast::zero ||
2556 after->at(sfPrincipalOutstanding) != beast::zero ||
2557 after->at(sfManagementFeeOutstanding) != beast::zero))
2559 JLOG(j.
fatal()) <<
"Invariant failed: Loan with zero payments "
2560 "remaining has not been paid off";
2565 if (
after->at(sfPaymentRemaining) != 0 &&
2566 after->at(sfTotalValueOutstanding) == beast::zero &&
2567 after->at(sfPrincipalOutstanding) == beast::zero &&
2568 after->at(sfManagementFeeOutstanding) == beast::zero)
2570 JLOG(j.
fatal()) <<
"Invariant failed: Loan with zero payments "
2571 "remaining has not been paid off";
2579 <<
"Invariant failed: Loan Overpayment flag changed";
2583 for (
auto const field :
2587 &sfPrincipalOutstanding,
2588 &sfTotalValueOutstanding,
2589 &sfManagementFeeOutstanding})
2591 if (
after->at(*field) < 0)
2593 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName()
2599 for (
auto const field : {
2603 if (
after->at(*field) <= 0)
2605 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName()
2606 <<
" is zero or negative ";
2619 "ValidVault::Vault::make : from Vault object");
2623 self.
asset = from.
at(sfAsset);
2637 from.
getType() == ltMPTOKEN_ISSUANCE,
2638 "ValidVault::Shares::make : from MPTokenIssuance object");
2658 after !=
nullptr && (before !=
nullptr || !isDelete),
2659 "xrpl::ValidVault::visitEntry : some object is available");
2670 switch (before->getType())
2675 case ltMPTOKEN_ISSUANCE:
2680 before->getFieldU64(sfOutstandingAmount));
2685 static_cast<std::int64_t>(before->getFieldU64(sfMPTAmount));
2688 case ltACCOUNT_ROOT:
2689 case ltRIPPLE_STATE:
2690 balanceDelta = before->getFieldAmount(sfBalance);
2697 if (!isDelete &&
after)
2699 switch (
after->getType())
2704 case ltMPTOKEN_ISSUANCE:
2709 after->getFieldU64(sfOutstandingAmount)));
2717 case ltACCOUNT_ROOT:
2718 case ltRIPPLE_STATE:
2719 balanceDelta -=
Number(
after->getFieldAmount(sfBalance));
2726 uint256 const key = (before ? before->key() :
after->key());
2744 bool const enforce = view.
rules().
enabled(featureSingleAssetVault);
2754 "Invariant failed: vault operation succeeded without modifying "
2757 enforce,
"xrpl::ValidVault::finalize : vault noop invariant");
2767 "Invariant failed: vault updated by a wrong transaction type";
2770 "xrpl::ValidVault::finalize : illegal vault transaction "
2778 "Invariant failed: vault operation updated more than single vault";
2780 enforce,
"xrpl::ValidVault::finalize : single vault invariant");
2790 if (txnType != ttVAULT_DELETE)
2793 "Invariant failed: vault deleted by a wrong transaction type";
2796 "xrpl::ValidVault::finalize : illegal vault deletion "
2811 if (e.share.getMptID() == beforeVault.shareMPTID)
2812 return std::move(e);
2819 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must also "
2823 "xrpl::ValidVault::finalize : shares deletion invariant");
2828 if (deletedShares->sharesTotal != 0)
2830 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2831 "shares outstanding";
2834 if (beforeVault.assetsTotal !=
zero)
2836 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2837 "assets outstanding";
2840 if (beforeVault.assetsAvailable !=
zero)
2842 JLOG(j.
fatal()) <<
"Invariant failed: deleted vault must have no "
2849 else if (txnType == ttVAULT_DELETE)
2851 JLOG(j.
fatal()) <<
"Invariant failed: vault deletion succeeded without "
2854 enforce,
"xrpl::ValidVault::finalize : vault deletion invariant");
2862 "xrpl::ValidVault::finalize : single vault operation");
2872 if (e.share.getMptID() == afterVault.shareMPTID)
2876 auto const sleShares =
2889 if (afterVault.asset != beforeVault.asset ||
2890 afterVault.pseudoId != beforeVault.pseudoId ||
2891 afterVault.shareMPTID != beforeVault.shareMPTID)
2894 <<
"Invariant failed: violation of vault immutable data";
2901 JLOG(j.
fatal()) <<
"Invariant failed: updated vault must have shares";
2903 enforce,
"xrpl::ValidVault::finalize : vault has shares invariant");
2907 if (updatedShares->sharesTotal == 0)
2909 if (afterVault.assetsTotal !=
zero)
2911 JLOG(j.
fatal()) <<
"Invariant failed: updated zero sized "
2912 "vault must have no assets outstanding";
2915 if (afterVault.assetsAvailable !=
zero)
2917 JLOG(j.
fatal()) <<
"Invariant failed: updated zero sized "
2918 "vault must have no assets available";
2922 else if (updatedShares->sharesTotal > updatedShares->sharesMaximum)
2925 <<
"Invariant failed: updated shares must not exceed maximum "
2926 << updatedShares->sharesMaximum;
2930 if (afterVault.assetsAvailable <
zero)
2933 <<
"Invariant failed: assets available must be positive";
2937 if (afterVault.assetsAvailable > afterVault.assetsTotal)
2939 JLOG(j.
fatal()) <<
"Invariant failed: assets available must "
2940 "not be greater than assets outstanding";
2944 afterVault.lossUnrealized >
2945 afterVault.assetsTotal - afterVault.assetsAvailable)
2948 <<
"Invariant failed: loss unrealized must not exceed "
2949 "the difference between assets outstanding and available";
2953 if (afterVault.assetsTotal <
zero)
2956 <<
"Invariant failed: assets outstanding must be positive";
2960 if (afterVault.assetsMaximum <
zero)
2962 JLOG(j.
fatal()) <<
"Invariant failed: assets maximum must be positive";
2971 "Invariant failed: vault created by a wrong transaction type";
2973 enforce,
"xrpl::ValidVault::finalize : vault creation invariant");
2978 afterVault.lossUnrealized !=
beforeVault_[0].lossUnrealized &&
2979 txnType != ttLOAN_MANAGE && txnType != ttLOAN_PAY)
2982 "Invariant failed: vault transaction must not change loss "
2994 if (e.share.getMptID() == beforeVault.shareMPTID)
2995 return std::move(e);
3000 if (!beforeShares &&
3005 JLOG(j.
fatal()) <<
"Invariant failed: vault operation succeeded "
3006 "without updating shares";
3008 enforce,
"xrpl::ValidVault::finalize : shares noop invariant");
3012 auto const& vaultAsset = afterVault.asset;
3019 return it->second *
sign;
3023 [&]<
typename TIss>(TIss
const& issue) {
3030 id > issue.getIssuer() ? -1 : 1);
3038 vaultAsset.value());
3041 auto ret = deltaAssets(tx[sfAccount]);
3043 if (!ret.has_value() || !vaultAsset.native())
3047 if (
auto const delegate = tx[~sfDelegate];
3048 delegate.has_value() && *delegate != tx[sfAccount])
3051 *ret += fee.
drops();
3058 auto const it = [&]() {
3059 if (
id == afterVault.pseudoId)
3076 case ttVAULT_CREATE: {
3082 <<
"Invariant failed: create operation must not have "
3087 if (afterVault.assetsAvailable !=
zero ||
3088 afterVault.assetsTotal !=
zero ||
3089 afterVault.lossUnrealized !=
zero ||
3090 updatedShares->sharesTotal != 0)
3093 <<
"Invariant failed: created vault must be empty";
3097 if (afterVault.pseudoId != updatedShares->share.getIssuer())
3100 <<
"Invariant failed: shares issuer and vault "
3101 "pseudo-account must be the same";
3105 auto const sleSharesIssuer = view.
read(
3107 if (!sleSharesIssuer)
3110 <<
"Invariant failed: shares issuer must exist";
3117 <<
"Invariant failed: shares issuer must be a "
3122 if (
auto const vaultId = (*sleSharesIssuer)[~sfVaultID];
3123 !vaultId || *vaultId != afterVault.key)
3126 <<
"Invariant failed: shares issuer pseudo-account "
3127 "must point back to the vault";
3138 "xrpl::ValidVault::finalize : set updated a vault");
3141 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3142 if (vaultDeltaAssets)
3145 "Invariant failed: set must not change vault balance";
3149 if (beforeVault.assetsTotal != afterVault.assetsTotal)
3152 "Invariant failed: set must not change assets "
3157 if (afterVault.assetsMaximum >
zero &&
3158 afterVault.assetsTotal > afterVault.assetsMaximum)
3161 "Invariant failed: set assets outstanding must not "
3162 "exceed assets maximum";
3166 if (beforeVault.assetsAvailable != afterVault.assetsAvailable)
3169 "Invariant failed: set must not change assets "
3174 if (beforeShares && updatedShares &&
3175 beforeShares->sharesTotal != updatedShares->sharesTotal)
3178 "Invariant failed: set must not change shares "
3185 case ttVAULT_DEPOSIT: {
3190 "xrpl::ValidVault::finalize : deposit updated a vault");
3193 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3195 if (!vaultDeltaAssets)
3198 "Invariant failed: deposit must change vault balance";
3202 if (*vaultDeltaAssets > tx[sfAmount])
3205 "Invariant failed: deposit must not change vault "
3206 "balance by more than deposited amount";
3210 if (*vaultDeltaAssets <=
zero)
3213 "Invariant failed: deposit must increase vault balance";
3219 bool const issuerDeposit = [&]() ->
bool {
3220 if (vaultAsset.native())
3222 return tx[sfAccount] == vaultAsset.getIssuer();
3227 auto const accountDeltaAssets = deltaAssetsTxAccount();
3228 if (!accountDeltaAssets)
3231 "Invariant failed: deposit must change depositor "
3236 if (*accountDeltaAssets >=
zero)
3239 "Invariant failed: deposit must decrease depositor "
3244 if (*accountDeltaAssets * -1 != *vaultDeltaAssets)
3247 "Invariant failed: deposit must change vault and "
3248 "depositor balance by equal amount";
3253 if (afterVault.assetsMaximum >
zero &&
3254 afterVault.assetsTotal > afterVault.assetsMaximum)
3257 "Invariant failed: deposit assets outstanding must not "
3258 "exceed assets maximum";
3262 auto const accountDeltaShares = deltaShares(tx[sfAccount]);
3263 if (!accountDeltaShares)
3266 "Invariant failed: deposit must change depositor "
3271 if (*accountDeltaShares <=
zero)
3274 "Invariant failed: deposit must increase depositor "
3279 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3280 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3283 "Invariant failed: deposit must change vault shares";
3287 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3290 "Invariant failed: deposit must change depositor and "
3291 "vault shares by equal amount";
3295 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3296 afterVault.assetsTotal)
3298 JLOG(j.
fatal()) <<
"Invariant failed: deposit and assets "
3299 "outstanding must add up";
3302 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3303 afterVault.assetsAvailable)
3305 JLOG(j.
fatal()) <<
"Invariant failed: deposit and assets "
3306 "available must add up";
3312 case ttVAULT_WITHDRAW: {
3317 "xrpl::ValidVault::finalize : withdrawal updated a "
3321 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3323 if (!vaultDeltaAssets)
3325 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal must "
3326 "change vault balance";
3330 if (*vaultDeltaAssets >=
zero)
3332 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal must "
3333 "decrease vault balance";
3339 bool const issuerWithdrawal = [&]() ->
bool {
3340 if (vaultAsset.native())
3342 auto const destination =
3343 tx[~sfDestination].value_or(tx[sfAccount]);
3344 return destination == vaultAsset.getIssuer();
3347 if (!issuerWithdrawal)
3349 auto const accountDeltaAssets = deltaAssetsTxAccount();
3350 auto const otherAccountDelta =
3352 if (
auto const destination = tx[~sfDestination];
3353 destination && *destination != tx[sfAccount])
3354 return deltaAssets(*destination);
3358 if (accountDeltaAssets.has_value() ==
3359 otherAccountDelta.has_value())
3362 "Invariant failed: withdrawal must change one "
3363 "destination balance";
3367 auto const destinationDelta =
3368 accountDeltaAssets ? *accountDeltaAssets
3369 : *otherAccountDelta;
3371 if (destinationDelta <=
zero)
3374 "Invariant failed: withdrawal must increase "
3375 "destination balance";
3379 if (*vaultDeltaAssets * -1 != destinationDelta)
3382 "Invariant failed: withdrawal must change vault "
3383 "and destination balance by equal amount";
3388 auto const accountDeltaShares = deltaShares(tx[sfAccount]);
3389 if (!accountDeltaShares)
3392 "Invariant failed: withdrawal must change depositor "
3397 if (*accountDeltaShares >=
zero)
3400 "Invariant failed: withdrawal must decrease depositor "
3405 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3406 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3409 "Invariant failed: withdrawal must change vault shares";
3413 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3416 "Invariant failed: withdrawal must change depositor "
3417 "and vault shares by equal amount";
3422 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3423 afterVault.assetsTotal)
3425 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal and "
3426 "assets outstanding must add up";
3430 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3431 afterVault.assetsAvailable)
3433 JLOG(j.
fatal()) <<
"Invariant failed: withdrawal and "
3434 "assets available must add up";
3440 case ttVAULT_CLAWBACK: {
3445 "xrpl::ValidVault::finalize : clawback updated a vault");
3448 if (vaultAsset.native() ||
3449 vaultAsset.getIssuer() != tx[sfAccount])
3452 "Invariant failed: clawback may only be performed by "
3457 auto const vaultDeltaAssets = deltaAssets(afterVault.pseudoId);
3459 if (!vaultDeltaAssets)
3462 "Invariant failed: clawback must change vault balance";
3466 if (*vaultDeltaAssets >=
zero)
3469 "Invariant failed: clawback must decrease vault "
3474 auto const accountDeltaShares = deltaShares(tx[sfHolder]);
3475 if (!accountDeltaShares)
3478 "Invariant failed: clawback must change holder shares";
3482 if (*accountDeltaShares >=
zero)
3485 "Invariant failed: clawback must decrease holder "
3490 auto const vaultDeltaShares = deltaShares(afterVault.pseudoId);
3491 if (!vaultDeltaShares || *vaultDeltaShares ==
zero)
3494 "Invariant failed: clawback must change vault shares";
3498 if (*vaultDeltaShares * -1 != *accountDeltaShares)
3501 "Invariant failed: clawback must change holder and "
3502 "vault shares by equal amount";
3506 if (beforeVault.assetsTotal + *vaultDeltaAssets !=
3507 afterVault.assetsTotal)
3510 "Invariant failed: clawback and assets outstanding "
3515 if (beforeVault.assetsAvailable + *vaultDeltaAssets !=
3516 afterVault.assetsAvailable)
3519 "Invariant failed: clawback and assets available must "
3537 "xrpl::ValidVault::finalize : unknown transaction type");
3547 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 &)