20#include <xrpl/basics/Expected.h>
21#include <xrpl/basics/Log.h>
22#include <xrpl/basics/chrono.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/ledger/CredentialHelpers.h>
25#include <xrpl/ledger/ReadView.h>
26#include <xrpl/ledger/View.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/LedgerFormats.h>
30#include <xrpl/protocol/MPTIssue.h>
31#include <xrpl/protocol/Protocol.h>
32#include <xrpl/protocol/Quality.h>
33#include <xrpl/protocol/TER.h>
34#include <xrpl/protocol/TxFlags.h>
35#include <xrpl/protocol/digest.h>
36#include <xrpl/protocol/st.h>
59 auto const& svIndexes = page->getFieldV256(sfIndexes);
61 index <= svIndexes.size(),
62 "ripple::detail::internalDirNext : index inside range");
64 if (index >= svIndexes.size())
66 auto const next = page->getFieldU64(sfIndexNext);
79 XRPL_ASSERT(page,
"ripple::detail::internalDirNext : non-null root");
89 entry = svIndexes[index++];
221 if (issuer != account)
258 if (issuer != account)
291 for (
auto const& account : accounts)
297 for (
auto const& account : accounts)
319 auto const mptIssuance =
321 if (mptIssuance ==
nullptr)
324 auto const issuer = mptIssuance->getAccountID(sfIssuer);
326 if (mptIssuer ==
nullptr)
329 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null MPToken issuer");
334 if (!mptIssuer->isFieldPresent(sfVaultID))
339 if (vault ==
nullptr)
341 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null vault");
346 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
361 if (issuer == account)
403 auto const allowBalance = [&]() {
411 if (
isFrozen(view, account, currency, issuer) ||
426 else if (sleIssuer->isFieldPresent(sfAMMID))
435 (*sleAmm)[sfAsset].get<Issue>(),
436 (*sleAmm)[sfAsset2].get<Issue>()))
449 amount = sle->getFieldAmount(sfBalance);
450 if (account > issuer)
462 JLOG(j.
trace()) <<
"accountHolds:"
496 amount.
clear(mptIssue);
499 amount.
clear(mptIssue);
502 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
512 amount.
clear(mptIssue);
516 auto const sleIssuance =
523 amount.
clear(mptIssue);
530[[nodiscard]] STAmount
540 [&](
auto const& value) {
545 return accountHolds(view, account, value, zeroIfFrozen, j);
548 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
595 <<
"Account " << *
id <<
" owner count exceeds max!";
608 <<
"Account " << *
id <<
" owner count set below 0!";
611 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
630 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
637 auto const fullBalance = sle->getFieldAmount(sfBalance);
642 (balance < reserve) ?
STAmount{0} : balance - reserve;
644 JLOG(j.
trace()) <<
"accountHolds:"
647 <<
" fullBalance=" << fullBalance.getFullText()
648 <<
" balance=" << balance.getFullText()
649 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
650 <<
" ownerCountAdj=" << ownerCountAdj;
662 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
664 if (
root.type != ltDIR_NODE)
671 auto sle = view.
read(pos);
674 for (
auto const& key : sle->getFieldV256(sfIndexes))
676 auto const next = sle->getFieldU64(sfIndexNext);
693 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
695 if (
root.type != ltDIR_NODE)
698 auto currentIndex =
root;
701 if (
after.isNonZero())
705 if (
auto hintDir = view.
read(hintIndex))
707 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
712 currentIndex = hintIndex;
721 auto const ownerDir = view.
read(currentIndex);
724 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
737 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
747 auto const ownerDir = view.
read(currentIndex);
750 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
753 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
766 if (sle && sle->isFieldPresent(sfTransferRate))
767 return Rate{sle->getFieldU32(sfTransferRate)};
779 sle && sle->isFieldPresent(sfTransferFee))
780 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
814 if (hash && (*hash != validLedger.
info().
hash))
816 JLOG(s) << reason <<
" incompatible with valid ledger";
818 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
830 if (hash && (*hash != testLedger.
info().
hash))
832 JLOG(s) << reason <<
" incompatible preceding ledger";
834 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
844 JLOG(s) << reason <<
" incompatible ledger";
851 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
854 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
871 if (testLedger.
info().
seq > validIndex)
878 if (hash && (*hash != validHash))
880 JLOG(s) << reason <<
" incompatible following ledger";
881 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
887 (validIndex == testLedger.
info().
seq) &&
888 (testLedger.
info().
hash != validHash))
890 JLOG(s) << reason <<
" incompatible ledger";
897 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
899 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
909 auto const sleNode = view.
read(k);
912 if (!sleNode->getFieldV256(sfIndexes).empty())
917 return sleNode->getFieldU64(sfIndexNext) == 0;
927 if (sle->isFieldPresent(sfAmendments))
929 auto const& v = sle->getFieldV256(sfAmendments);
930 amendments.insert(v.begin(), v.end());
944 if (sle->isFieldPresent(sfMajorities))
947 using d = tp::duration;
949 auto const majorities = sle->getFieldArray(sfMajorities);
951 for (
auto const& m : majorities)
952 ret[m.getFieldH256(sfAmendment)] =
953 tp(d(m.getFieldU32(sfCloseTime)));
964 if (seq > ledger.
seq())
967 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
970 if (seq == ledger.
seq())
972 if (seq == (ledger.
seq() - 1))
975 if (
int diff = ledger.
seq() - seq; diff <= 256)
982 hashIndex->getFieldU32(sfLastLedgerSequence) ==
984 "ripple::hashOfSeq : matching ledger sequence");
985 STVector256 vec = hashIndex->getFieldV256(sfHashes);
986 if (vec.
size() >= diff)
987 return vec[vec.
size() - diff];
989 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
990 <<
" (" << vec.
size() <<
"," << diff <<
")";
995 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
996 <<
" missing normal list";
1000 if ((seq & 0xff) != 0)
1002 JLOG(journal.
debug())
1003 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1011 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1012 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
1014 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
1015 auto const diff = (lastSeq - seq) >> 8;
1016 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1017 if (vec.
size() > diff)
1018 return vec[vec.
size() - diff - 1];
1020 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1040 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1045 sle->at(sfOwnerCount) = adjusted;
1053 (*sle)[sfOwner] = account;
1064 object->setFieldU64(sfOwnerNode, *page);
1077 rsh(hash.data(), hash.size());
1100 "ripple::isPseudoAccount : unable to find account root ledger "
1104 auto const& soTemplate = ar->getSOTemplate();
1107 for (
auto const& field : soTemplate)
1112 return pseudoFields;
1114 return pseudoFields;
1124 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1126 fields.begin(), fields.end(), [&sleAcct](
SField const* sf) ->
bool {
1127 return sleAcct->isFieldPresent(*sf);
1131Expected<std::shared_ptr<SLE>,
TER>
1134 uint256 const& pseudoOwnerKey,
1135 SField const& ownerField)
1142 [&ownerField](
SField const* sf) ->
bool {
1143 return *sf == ownerField;
1145 "ripple::createPseudoAccount : valid owner field");
1148 if (accountId == beast::zero)
1153 account->setAccountID(sfAccount, accountId);
1154 account->setFieldAmount(sfBalance,
STAmount{});
1163 account->setFieldU32(sfSequence, seqno);
1167 account->setFieldU32(
1170 account->setFieldH256(ownerField, pseudoOwnerKey);
1227 auto const& issuerId = issue.
getIssuer();
1228 auto const& currency = issue.
currency;
1232 auto const& srcId = issuerId;
1233 auto const& dstId = accountID;
1234 auto const high = srcId > dstId;
1235 auto const index =
keylet::line(srcId, dstId, currency);
1238 if (!sleDst || !sleSrc)
1243 if (view.
read(index))
1256 STAmount{Issue{currency, noAccount()}},
1257 STAmount{Issue{currency, dstId}},
1271 auto const& mptID = mptIssue.
getMptID();
1272 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1277 if (view.
peek(keylet::mptoken(mptID, accountID)))
1287 MPTID const& mptIssuanceID,
1293 auto const sleAcct = view.
peek(keylet::account(account));
1307 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1308 auto const sleMpt = view.
peek(mptokenKey);
1309 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1313 keylet::ownerDir(account),
1314 (*sleMpt)[sfOwnerNode],
1334 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1336 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1339 if (priorBalance < reserveCreate)
1342 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1344 if (
auto ter =
dirLink(view, account, mptoken))
1347 (*mptoken)[sfAccount] = account;
1348 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1349 (*mptoken)[sfFlags] = 0;
1358 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1359 if (!sleMptIssuance)
1365 if (account != (*sleMptIssuance)[sfIssuer])
1368 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1378 flagsOut &= ~lsfMPTAuthorized;
1384 if (flagsIn != flagsOut)
1385 sleMpt->setFieldU32(sfFlags, flagsOut);
1394 bool const bSrcHigh,
1400 bool const bNoRipple,
1411 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1412 << to_string(uDstAccountID) <<
", "
1415 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1416 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1419 view.
insert(sleRippleState);
1422 keylet::ownerDir(uLowAccountID),
1423 sleRippleState->key(),
1430 keylet::ownerDir(uHighAccountID),
1431 sleRippleState->key(),
1437 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1438 bool const bSetHigh = bSrcHigh ^ bSetDst;
1440 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1445 sleAccount->getAccountID(sfAccount) ==
1446 (bSetHigh ? uHighAccountID : uLowAccountID),
1447 "ripple::trustCreate : matching account ID");
1448 auto const slePeer =
1449 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1454 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1455 sleRippleState->setFieldU64(sfHighNode, *highNode);
1457 sleRippleState->setFieldAmount(
1458 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1459 sleRippleState->setFieldAmount(
1460 bSetHigh ? sfLowLimit : sfHighLimit,
1462 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1465 sleRippleState->setFieldU32(
1466 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1469 sleRippleState->setFieldU32(
1470 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1497 sleRippleState->setFieldU32(sfFlags, uFlags);
1501 sleRippleState->setFieldAmount(
1502 sfBalance, bSetHigh ? -saBalance : saBalance);
1505 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1519 auto const sle = view.
read(keylet::account(accountID));
1523 auto const balance = sle->getFieldAmount(sfBalance);
1524 if (balance.xrp() != 0)
1531 auto const line = view.
peek(keylet::line(accountID, issue));
1534 if (line->at(sfBalance)->iou() != beast::zero)
1541 auto sleLowAccount =
1542 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1556 auto sleHighAccount =
1557 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1558 if (!sleHighAccount)
1571 line->at(sfLowLimit)->getIssuer(),
1572 line->at(sfHighLimit)->getIssuer(),
1583 auto const& mptID = mptIssue.
getMptID();
1584 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1587 if (mptoken->at(sfMPTAmount) != 0)
1609 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1610 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1612 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1615 keylet::ownerDir(uLowAccountID),
1617 sleRippleState->key(),
1623 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1626 keylet::ownerDir(uHighAccountID),
1628 sleRippleState->key(),
1634 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1635 view.
erase(sleRippleState);
1645 auto offerIndex = sle->key();
1646 auto owner = sle->getAccountID(sfAccount);
1649 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1652 keylet::ownerDir(owner),
1653 sle->getFieldU64(sfOwnerNode),
1661 keylet::page(uDirectory),
1662 sle->getFieldU64(sfBookNode),
1669 if (sle->isFieldPresent(sfAdditionalBooks))
1672 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1673 "ripple::offerDelete : should be a hybrid domain offer");
1675 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1677 for (
auto const& bookDir : additionalBookDirs)
1679 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1680 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1683 keylet::page(dirIndex), dirNode, offerIndex,
false))
1715 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1716 "ripple::rippleCreditIOU : matching issuer or don't care");
1721 uSenderID != uReceiverID,
1722 "ripple::rippleCreditIOU : sender is not receiver");
1724 bool const bSenderHigh = uSenderID > uReceiverID;
1725 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1729 "ripple::rippleCreditIOU : sender is not XRP");
1732 "ripple::rippleCreditIOU : receiver is not XRP");
1735 if (
auto const sleRippleState = view.
peek(index))
1737 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1742 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1744 STAmount const saBefore = saBalance;
1746 saBalance -= saAmount;
1748 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1749 << to_string(uReceiverID)
1754 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1755 bool bDelete =
false;
1759 if (saBefore > beast::zero
1761 && saBalance <= beast::zero
1769 view.
read(keylet::account(uSenderID))->getFlags() &
1772 !sleRippleState->getFieldAmount(
1773 !bSenderHigh ? sfLowLimit : sfHighLimit)
1775 && !sleRippleState->getFieldU32(
1776 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1778 && !sleRippleState->getFieldU32(
1779 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1784 view, view.
peek(keylet::account(uSenderID)), -1, j);
1787 sleRippleState->setFieldU32(
1789 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1792 bDelete = !saBalance
1801 sleRippleState->setFieldAmount(sfBalance, saBalance);
1809 bSenderHigh ? uReceiverID : uSenderID,
1810 !bSenderHigh ? uReceiverID : uSenderID,
1814 view.
update(sleRippleState);
1818 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1823 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1825 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1828 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1865 auto const issuer = saAmount.
getIssuer();
1869 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1871 uSenderID != uReceiverID,
1872 "ripple::rippleSendIOU : sender is not receiver");
1874 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1881 saActual = saAmount;
1889 saActual = (waiveFee == WaiveTransferFee::Yes)
1893 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1894 << to_string(uReceiverID)
1902 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1928 "ripple::accountSendIOU : minimum amount and not MPT");
1935 if (!saAmount || (uSenderID == uReceiverID))
1942 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1943 << to_string(uReceiverID) <<
" : "
1947 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1958 ? view.
peek(keylet::account(uSenderID))
1961 ? view.
peek(keylet::account(uReceiverID))
1964 if (
auto stream = j.
trace())
1970 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1973 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1975 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1976 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1977 << receiver_bal <<
") : " << saAmount.
getFullText();
1982 if (sender->getFieldAmount(sfBalance) < saAmount)
1993 auto const sndBal = sender->getFieldAmount(sfBalance);
1997 sender->setFieldAmount(sfBalance, sndBal - saAmount);
2005 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2006 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2012 if (
auto stream = j.
trace())
2018 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2021 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2023 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2024 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2025 << receiver_bal <<
") : " << saAmount.
getFullText();
2041 auto const issuer = saAmount.
getIssuer();
2042 auto sleIssuance = view.
peek(mptID);
2045 if (uSenderID == issuer)
2047 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2048 view.
update(sleIssuance);
2052 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2053 if (
auto sle = view.
peek(mptokenID))
2055 auto const amt = sle->getFieldU64(sfMPTAmount);
2056 auto const pay = saAmount.
mpt().
value();
2059 (*sle)[sfMPTAmount] = amt - pay;
2066 if (uReceiverID == issuer)
2068 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2069 auto const redeem = saAmount.
mpt().
value();
2070 if (outstanding >= redeem)
2072 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2073 view.
update(sleIssuance);
2080 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2081 if (
auto sle = view.
peek(mptokenID))
2083 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2104 uSenderID != uReceiverID,
2105 "ripple::rippleSendMPT : sender is not receiver");
2108 auto const issuer = saAmount.
getIssuer();
2115 if (uSenderID == issuer || uReceiverID == issuer)
2119 if (uSenderID == issuer)
2121 auto const sendAmount = saAmount.
mpt().
value();
2122 auto const maximumAmount =
2124 if (sendAmount > maximumAmount ||
2125 sle->getFieldU64(sfOutstandingAmount) >
2126 maximumAmount - sendAmount)
2135 saActual = saAmount;
2140 saActual = (waiveFee == WaiveTransferFee::Yes)
2146 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2147 << to_string(uReceiverID)
2151 if (
auto const terResult =
2170 "ripple::accountSendMPT : minimum amount and MPT");
2175 if (!saAmount || (uSenderID == uReceiverID))
2181 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2197 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2200 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2219 auto sle = view.
peek(keylet::account(sender));
2224 if (before > beast::zero
2226 &&
after <= beast::zero
2230 &&
static_cast<bool>(
2234 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2236 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2239 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2248 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2268 "ripple::issueIOU : neither account nor issuer is XRP");
2271 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2275 issue.
account != account,
"ripple::issueIOU : not issuer account");
2277 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2280 bool bSenderHigh = issue.
account > account;
2282 auto const index = keylet::line(issue.
account, account, issue.
currency);
2284 if (
auto state = view.
peek(index))
2286 STAmount final_balance = state->getFieldAmount(sfBalance);
2291 STAmount const start_balance = final_balance;
2293 final_balance -= amount;
2312 state->setFieldAmount(sfBalance, final_balance);
2317 bSenderHigh ? account : issue.
account,
2318 bSenderHigh ? issue.
account : account,
2334 auto const receiverAccount = view.
peek(keylet::account(account));
2335 if (!receiverAccount)
2368 "ripple::redeemIOU : neither account nor issuer is XRP");
2371 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2375 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2377 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2380 bool bSenderHigh = account > issue.
account;
2385 STAmount final_balance = state->getFieldAmount(sfBalance);
2390 STAmount const start_balance = final_balance;
2392 final_balance -= amount;
2395 view, state, bSenderHigh, account, start_balance, final_balance, j);
2405 state->setFieldAmount(sfBalance, final_balance);
2412 bSenderHigh ? issue.
account : account,
2413 bSenderHigh ? account : issue.
account,
2425 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2427 <<
" but no trust line exists!";
2442 from != beast::zero,
"ripple::transferXRP : nonzero from account");
2443 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
2444 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
2445 XRPL_ASSERT(amount.
native(),
"ripple::transferXRP : amount is XRP");
2449 if (!sender || !receiver)
2452 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
2453 << to_string(to) <<
") : " << amount.
getFullText();
2455 if (sender->getFieldAmount(sfBalance) < amount)
2467 sender->setFieldAmount(
2468 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2471 receiver->setFieldAmount(
2472 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2488 auto const trustLine =
2491 if (!trustLine && authType == AuthType::StrongAuth)
2496 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2500 return ((*trustLine)[sfFlags] &
2518 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2519 auto const sleIssuance = view.
read(mptID);
2523 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2526 if (mptIssuer == account)
2535 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2539 if (sleIssuer->isFieldPresent(sfVaultID))
2541 auto const sleVault =
2542 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2546 auto const asset = sleVault->at(sfAsset);
2550 return requireAuth(view, issue, account, authType);
2553 view, issue, account, authType, depth + 1);
2561 auto const mptokenID = keylet::mptoken(mptID.key, account);
2562 auto const sleToken = view.
read(mptokenID);
2566 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2571 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2576 "ripple::requireAuth : issuance requires authorization");
2578 if (
auto const ter =
2579 credentials::validDomain(view, *maybeDomainID, account);
2599 MPTID const& mptIssuanceID,
2604 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2610 "ripple::enforceMPTokenAuthorization : authorization required");
2612 if (account == sleIssuance->at(sfIssuer))
2615 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2616 auto const sleToken = view.
read(keylet);
2617 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2619 bool const authorizedByDomain = [&]() ->
bool {
2621 if (!maybeDomainID.has_value())
2632 if (!authorizedByDomain && sleToken ==
nullptr)
2643 else if (!authorizedByDomain && maybeDomainID.has_value())
2650 else if (!authorizedByDomain)
2655 sleToken !=
nullptr && !maybeDomainID.has_value(),
2656 "ripple::enforceMPTokenAuthorization : found MPToken");
2662 else if (authorizedByDomain && sleToken !=
nullptr)
2667 maybeDomainID.has_value(),
2668 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2671 else if (authorizedByDomain)
2676 maybeDomainID.has_value() && sleToken ==
nullptr,
2677 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2692 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2704 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2705 auto const sleIssuance = view.
read(mptID);
2711 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2720 Keylet const& ownerDirKeylet,
2727 unsigned int uDirEntry{0};
2728 uint256 dirEntry{beast::zero};
2731 if (view.
exists(ownerDirKeylet) &&
2732 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2736 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2740 auto sleItem = view.
peek(keylet::child(dirEntry));
2746 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
2747 <<
" has index to object that is missing: "
2748 << to_string(dirEntry);
2754 sleItem->getFieldU16(sfLedgerEntryType))};
2758 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2780 "ripple::cleanupOnAccountDelete : minimum dir entries");
2785 <<
"DeleteAccount iterator re-validation failed.";
2789 if (skipEntry == SkipEntry::No)
2793 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2806 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2810 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2811 sleState->getFieldAmount(sfHighLimit).getIssuer());
2812 auto sleLow = view.
peek(keylet::account(low));
2813 auto sleHigh = view.
peek(keylet::account(high));
2814 if (!sleLow || !sleHigh)
2817 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2818 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2821 if (ammLow && ammHigh)
2825 if (!ammLow && !ammHigh)
2829 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2832 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2836 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2841 if (!(sleState->getFlags() & uFlags))
2863 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2869 "ripple::rippleCredit : not checking issuer");
2871 view, uSenderID, uReceiverID, saAmount, j);
2885 "ripple::assetsToSharesDeposit : non-negative assets");
2887 assets.
asset() == vault->at(sfAsset),
2888 "ripple::assetsToSharesDeposit : assets and vault match");
2889 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2892 Number const assetTotal = vault->at(sfAssetsTotal);
2893 STAmount shares{vault->at(sfShareMPTID)};
2894 if (assetTotal == 0)
2900 Number const shareTotal = issuance->at(sfOutstandingAmount);
2901 shares = (shareTotal * (assets / assetTotal)).truncate();
2913 "ripple::sharesToAssetsDeposit : non-negative shares");
2915 shares.
asset() == vault->at(sfShareMPTID),
2916 "ripple::sharesToAssetsDeposit : shares and vault match");
2917 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2920 Number const assetTotal = vault->at(sfAssetsTotal);
2921 STAmount assets{vault->at(sfAsset)};
2922 if (assetTotal == 0)
2926 shares.
exponent() - vault->at(sfScale),
2929 Number const shareTotal = issuance->at(sfOutstandingAmount);
2930 assets = assetTotal * (shares / shareTotal);
2943 "ripple::assetsToSharesDeposit : non-negative assets");
2945 assets.
asset() == vault->at(sfAsset),
2946 "ripple::assetsToSharesWithdraw : assets and vault match");
2947 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2950 Number assetTotal = vault->at(sfAssetsTotal);
2951 assetTotal -= vault->at(sfLossUnrealized);
2952 STAmount shares{vault->at(sfShareMPTID)};
2953 if (assetTotal == 0)
2955 Number const shareTotal = issuance->at(sfOutstandingAmount);
2956 Number result = shareTotal * (assets / assetTotal);
2957 if (truncate == TruncateShares::yes)
2971 "ripple::sharesToAssetsDeposit : non-negative shares");
2973 shares.
asset() == vault->at(sfShareMPTID),
2974 "ripple::sharesToAssetsWithdraw : shares and vault match");
2975 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2978 Number assetTotal = vault->at(sfAssetsTotal);
2979 assetTotal -= vault->at(sfLossUnrealized);
2980 STAmount assets{vault->at(sfAsset)};
2981 if (assetTotal == 0)
2983 Number const shareTotal = issuance->at(sfOutstandingAmount);
2984 assets = assetTotal * (shares / shareTotal);
2996 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2997 auto sleIssuance = view.
peek(mptID);
3000 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
3001 << mptIssue.getMptID();
3008 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3015 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3016 auto sle = view.
peek(mptokenID);
3020 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3024 auto const amt = sle->getFieldU64(sfMPTAmount);
3025 auto const pay = amount.
mpt().
value();
3031 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3032 << to_string(sender) <<
": " << amt <<
" < " << pay;
3036 (*sle)[sfMPTAmount] = amt - pay;
3039 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3044 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3045 << to_string(sender) <<
": " << locked <<
" + " << pay;
3049 if (sle->isFieldPresent(sfLockedAmount))
3050 (*sle)[sfLockedAmount] += pay;
3052 sle->setFieldU64(sfLockedAmount, pay);
3060 uint64_t
const issuanceEscrowed =
3061 (*sleIssuance)[~sfLockedAmount].value_or(0);
3062 auto const pay = amount.
mpt().
value();
3068 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3069 "locked amount for "
3070 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3075 if (sleIssuance->isFieldPresent(sfLockedAmount))
3076 (*sleIssuance)[sfLockedAmount] += pay;
3078 sleIssuance->setFieldU64(sfLockedAmount, pay);
3080 view.
update(sleIssuance);
3096 netAmount == grossAmount,
3097 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3099 auto const& issuer = netAmount.
getIssuer();
3101 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3102 auto sleIssuance = view.
peek(mptID);
3105 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3106 << mptIssue.getMptID();
3112 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3115 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3116 << mptIssue.getMptID();
3120 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3121 auto const redeem = grossAmount.
mpt().
value();
3128 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3129 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3133 auto const newLocked = locked - redeem;
3135 sleIssuance->makeFieldAbsent(sfLockedAmount);
3137 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3138 view.
update(sleIssuance);
3141 if (issuer != receiver)
3144 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3145 auto sle = view.
peek(mptokenID);
3149 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3153 auto current = sle->getFieldU64(sfMPTAmount);
3154 auto delta = netAmount.
mpt().
value();
3160 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3161 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3165 (*sle)[sfMPTAmount] += delta;
3171 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3172 auto const redeem = netAmount.
mpt().
value();
3179 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3180 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3185 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3186 view.
update(sleIssuance);
3189 if (issuer == sender)
3191 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3192 "cannot unlock MPTs.";
3198 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3199 auto sle = view.
peek(mptokenID);
3203 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3207 if (!sle->isFieldPresent(sfLockedAmount))
3210 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3211 << to_string(sender);
3215 auto const locked = sle->getFieldU64(sfLockedAmount);
3216 auto const delta = grossAmount.
mpt().
value();
3222 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3223 << to_string(sender) <<
": " << locked <<
" < " << delta;
3227 auto const newLocked = locked - delta;
3229 sle->makeFieldAbsent(sfLockedAmount);
3231 sle->setFieldU64(sfLockedAmount, newLocked);
3242 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3248 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3249 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3253 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3254 view.
update(sleIssuance);
Provide a light-weight way to check active() before string formatting.
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
constexpr value_type const & value() const
A currency issued by an account.
AccountID const & getIssuer() const
constexpr value_type value() const
Returns the underlying value.
constexpr MPTID const & getMptID() const
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Number truncate() const noexcept
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
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 LedgerInfo const & info() const =0
Returns information about the ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
constexpr bool holds() const noexcept
int exponent() const noexcept
Asset const & asset() const
constexpr TIss const & get() const
void setIssuer(AccountID const &uIssuer)
Currency const & getCurrency() const
bool negative() const noexcept
AccountID const & getIssuer() const
Issue const & issue() const
std::uint64_t mantissa() const noexcept
std::string getFullText() const override
bool native() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
std::shared_ptr< STLedgerEntry > const & ref
T emplace_back(T... args)
bool internalDirFirst(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
bool internalDirNext(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet const & skip() noexcept
The index of the "short" skip list.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
AccountID const & noAccount()
A placeholder for empty accounts.
static bool updateTrustLine(ApplyView &view, SLE::pointer state, bool bSenderHigh, AccountID const &sender, STAmount const &before, STAmount const &after, beast::Journal j)
std::uint8_t constexpr maxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
FreezeHandling
Controls the treatment of frozen account balances.
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, char const *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
bool isXRP(AccountID const &c)
AccountID const & xrpAccount()
Compute AccountID from public key.
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
bool canSubtract(STAmount const &amt1, STAmount const &amt2)
Determines if it is safe to subtract one STAmount from another.
static TER rippleSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool canAdd(STAmount const &amt1, STAmount const &amt2)
Safely checks if two STAmount values can be added without overflow, underflow, or precision loss.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
STAmount multiply(STAmount const &amount, Rate const &rate)
AuthHandling
Controls the treatment of unauthorized MPT balances.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
std::optional< STAmount > assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets, TruncateShares truncate=TruncateShares::no)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
@ current
This was a new validation and was added.
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
@ expired
List is expired, but has the largest non-pending sequence seen so far.
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
static std::uint32_t confineOwnerCount(std::uint32_t current, std::int32_t adjustment, std::optional< AccountID > const &id=std::nullopt, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
static TER rippleCreditIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
constexpr std::uint32_t const tfMPTUnauthorize
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
static TER accountSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
std::map< uint256, NetClock::time_point > majorityAmendments_t
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items after an item in the given directory.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
@ tecINSUFFICIENT_RESERVE
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
Any transactors that call addEmptyHolding() in doApply must call canAddHolding() in preflight with th...
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
bool isTesSuccess(TER x) noexcept
majorityAmendments_t getMajorityAmendments(ReadView const &view)
bool cdirFirst(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
std::string to_string(base_uint< Bits, Tag > const &a)
LedgerEntryType
Identifiers for on-ledger objects.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uSrcQualityIn, std::uint32_t uSrcQualityOut, beast::Journal j)
Create a trust line.
Number root(Number f, unsigned d)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
TER canAddHolding(ReadView const &view, Asset const &asset)
bool cdirNext(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
static TER rippleSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
std::vector< SField const * > const & getPseudoAccountFields()
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
TERSubset< CanCvtToTER > TER
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
static TER rippleCreditMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
T time_since_epoch(T... args)