1#include <xrpl/basics/Expected.h>
2#include <xrpl/basics/Log.h>
3#include <xrpl/basics/chrono.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/ledger/CredentialHelpers.h>
6#include <xrpl/ledger/Credit.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/ledger/View.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/MPTIssue.h>
13#include <xrpl/protocol/Protocol.h>
14#include <xrpl/protocol/Quality.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/TxFlags.h>
17#include <xrpl/protocol/digest.h>
18#include <xrpl/protocol/st.h>
41 auto const& svIndexes = page->getFieldV256(sfIndexes);
43 index <= svIndexes.size(),
44 "xrpl::detail::internalDirNext : index inside range");
46 if (index >= svIndexes.size())
48 auto const next = page->getFieldU64(sfIndexNext);
61 XRPL_ASSERT(page,
"xrpl::detail::internalDirNext : non-null root");
71 entry = svIndexes[index++];
203 if (issuer != account)
240 if (issuer != account)
273 for (
auto const& account : accounts)
279 for (
auto const& account : accounts)
301 auto const mptIssuance =
303 if (mptIssuance ==
nullptr)
306 auto const issuer = mptIssuance->getAccountID(sfIssuer);
308 if (mptIssuer ==
nullptr)
311 UNREACHABLE(
"xrpl::isVaultPseudoAccountFrozen : null MPToken issuer");
316 if (!mptIssuer->isFieldPresent(sfVaultID))
321 if (vault ==
nullptr)
323 UNREACHABLE(
"xrpl::isVaultPseudoAccountFrozen : null vault");
328 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
343 if (issuer == account)
386 if (
isFrozen(view, account, currency, issuer) ||
401 else if (sleIssuer->isFieldPresent(sfAMMID))
410 (*sleAmm)[sfAsset].get<Issue>(),
411 (*sleAmm)[sfAsset2].get<Issue>()))
429 bool includeOppositeLimit,
435 amount = sle->getFieldAmount(sfBalance);
436 bool const accountHigh = account > issuer;
437 auto const& oppositeField = accountHigh ? sfLowLimit : sfHighLimit;
443 if (includeOppositeLimit)
445 amount += sle->getFieldAmount(oppositeField);
447 amount.setIssuer(issuer);
451 amount.clear(
Issue{currency, issuer});
454 JLOG(j.
trace()) <<
"getTrustLineBalance:"
456 <<
" amount=" << amount.getFullText();
477 bool const returnSpendable = (includeFullBalance ==
shFULL_BALANCE);
478 if (returnSpendable && account == issuer)
489 view, sle, account, currency, issuer, returnSpendable, j);
521 bool const returnSpendable = (includeFullBalance ==
shFULL_BALANCE);
523 if (returnSpendable && account == mptIssue.
getIssuer())
527 auto const issuance =
537 issuance->at(sfOutstandingAmount)};
546 amount.clear(mptIssue);
549 amount.clear(mptIssue);
552 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
562 amount.clear(mptIssue);
566 auto const sleIssuance =
573 amount.clear(mptIssue);
580[[nodiscard]] STAmount
595 view, account, value, zeroIfFrozen, j, includeFullBalance);
654 <<
"Account " << *
id <<
" owner count exceeds max!";
667 <<
"Account " << *
id <<
" owner count set below 0!";
670 XRPL_ASSERT(!
id,
"xrpl::confineOwnerCount : id is not set");
689 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
696 auto const fullBalance = sle->getFieldAmount(sfBalance);
701 (balance < reserve) ?
STAmount{0} : balance - reserve;
703 JLOG(j.
trace()) <<
"accountHolds:"
705 <<
" amount=" << amount.getFullText()
706 <<
" fullBalance=" << fullBalance.getFullText()
707 <<
" balance=" << balance.getFullText()
708 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
709 <<
" ownerCountAdj=" << ownerCountAdj;
720 XRPL_ASSERT(
root.type == ltDIR_NODE,
"xrpl::forEachItem : valid root type");
722 if (
root.type != ltDIR_NODE)
729 auto sle = view.
read(pos);
732 for (
auto const& key : sle->getFieldV256(sfIndexes))
734 auto const next = sle->getFieldU64(sfIndexNext);
751 root.type == ltDIR_NODE,
"xrpl::forEachItemAfter : valid root type");
753 if (
root.type != ltDIR_NODE)
756 auto currentIndex =
root;
759 if (
after.isNonZero())
763 if (
auto hintDir = view.
read(hintIndex))
765 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
770 currentIndex = hintIndex;
779 auto const ownerDir = view.
read(currentIndex);
782 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
795 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
805 auto const ownerDir = view.
read(currentIndex);
808 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
811 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
824 if (sle && sle->isFieldPresent(sfTransferRate))
825 return Rate{sle->getFieldU32(sfTransferRate)};
837 sle && sle->isFieldPresent(sfTransferFee))
838 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
853 amount.asset().value());
872 if (hash && (*hash != validLedger.
header().
hash))
874 JLOG(s) << reason <<
" incompatible with valid ledger";
876 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
888 if (hash && (*hash != testLedger.
header().
hash))
890 JLOG(s) << reason <<
" incompatible preceding ledger";
892 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
902 JLOG(s) << reason <<
" incompatible ledger";
909 JLOG(s) <<
"Val: " << validLedger.
header().
seq <<
" "
912 JLOG(s) <<
"New: " << testLedger.
header().
seq <<
" "
929 if (testLedger.
header().
seq > validIndex)
936 if (hash && (*hash != validHash))
938 JLOG(s) << reason <<
" incompatible following ledger";
939 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
945 (validIndex == testLedger.
header().
seq) &&
948 JLOG(s) << reason <<
" incompatible ledger";
955 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
957 JLOG(s) <<
"New: " << testLedger.
header().
seq <<
" "
967 auto const sleNode = view.
read(k);
970 if (!sleNode->getFieldV256(sfIndexes).empty())
975 return sleNode->getFieldU64(sfIndexNext) == 0;
985 if (sle->isFieldPresent(sfAmendments))
987 auto const& v = sle->getFieldV256(sfAmendments);
988 amendments.insert(v.begin(), v.end());
1002 if (sle->isFieldPresent(sfMajorities))
1005 using d = tp::duration;
1007 auto const majorities = sle->getFieldArray(sfMajorities);
1009 for (
auto const& m : majorities)
1010 ret[m.getFieldH256(sfAmendment)] =
1011 tp(d(m.getFieldU32(sfCloseTime)));
1022 if (seq > ledger.
seq())
1024 JLOG(journal.
warn())
1025 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
1028 if (seq == ledger.
seq())
1030 if (seq == (ledger.
seq() - 1))
1033 if (
int diff = ledger.
seq() - seq; diff <= 256)
1040 hashIndex->getFieldU32(sfLastLedgerSequence) ==
1042 "xrpl::hashOfSeq : matching ledger sequence");
1043 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1044 if (vec.
size() >= diff)
1045 return vec[vec.
size() - diff];
1046 JLOG(journal.
warn())
1047 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
1048 <<
" (" << vec.
size() <<
"," << diff <<
")";
1052 JLOG(journal.
warn())
1054 <<
" missing normal list";
1058 if ((seq & 0xff) != 0)
1060 JLOG(journal.
debug())
1061 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1069 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1070 XRPL_ASSERT(lastSeq >= seq,
"xrpl::hashOfSeq : minimum last ledger");
1072 (lastSeq & 0xff) == 0,
"xrpl::hashOfSeq : valid last ledger");
1073 auto const diff = (lastSeq - seq) >> 8;
1074 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1075 if (vec.
size() > diff)
1076 return vec[vec.
size() - diff - 1];
1078 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1098 XRPL_ASSERT(amount,
"xrpl::adjustOwnerCount : nonzero amount input");
1103 sle->at(sfOwnerCount) = adjusted;
1111 (*sle)[sfOwner] = account;
1126 object->setFieldU64(node, *page);
1140 rsh(hash.data(), hash.size());
1163 "xrpl::getPseudoAccountFields : unable to find account root "
1167 auto const& soTemplate = ar->getSOTemplate();
1170 for (
auto const& field : soTemplate)
1175 return pseudoFields;
1177 return pseudoFields;
1189 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1193 [&sleAcct, &pseudoFieldFilter](
SField const* sf) ->
bool {
1194 return sleAcct->isFieldPresent(*sf) &&
1195 (pseudoFieldFilter.empty() ||
1196 pseudoFieldFilter.contains(sf));
1200Expected<std::shared_ptr<SLE>,
TER>
1203 uint256 const& pseudoOwnerKey,
1204 SField const& ownerField)
1212 [&ownerField](
SField const* sf) ->
bool {
1213 return *sf == ownerField;
1215 "xrpl::createPseudoAccount : valid owner field");
1218 if (accountId == beast::zero)
1223 account->setAccountID(sfAccount, accountId);
1224 account->setFieldAmount(sfBalance,
STAmount{});
1234 account->setFieldU32(sfSequence, seqno);
1238 account->setFieldU32(
1241 account->setFieldH256(ownerField, pseudoOwnerKey);
1289 if (toSle ==
nullptr)
1323 auto const& issuer = amount.getIssuer();
1324 if (from == to || to == issuer ||
isXRP(issuer))
1331 auto const& currency = issue.currency;
1332 auto const owed =
creditBalance(view, to, issuer, currency);
1333 if (owed <= beast::zero)
1335 auto const limit =
creditLimit(view, to, issuer, currency);
1336 if (-owed >= limit || amount > (limit + owed))
1342 amount.asset().value());
1352 bool hasDestinationTag)
1375 bool hasDestinationTag)
1379 return canWithdraw(view, from, to, toSle, amount, hasDestinationTag);
1385 auto const from = tx[sfAccount];
1386 auto const to = tx[~sfDestination].value_or(from);
1389 view, from, to, tx[sfAmount], tx.
isFieldPresent(sfDestinationTag));
1404 if (dstAcct == senderAcct)
1407 view, senderAcct, priorBalance, amount.asset(), j);
1429 JLOG(j.
error()) <<
"LoanBrokerCoverWithdraw: negative balance of "
1430 "broker cover assets.";
1453 auto const& issuerId = issue.
getIssuer();
1454 auto const& currency = issue.
currency;
1458 auto const& srcId = issuerId;
1459 auto const& dstId = accountID;
1460 auto const high = srcId > dstId;
1461 auto const index =
keylet::line(srcId, dstId, currency);
1464 if (!sleDst || !sleSrc)
1469 if (view.
read(index))
1488 STAmount{Issue{currency, noAccount()}},
1489 STAmount{Issue{currency, dstId}},
1503 auto const& mptID = mptIssue.
getMptID();
1504 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1509 if (view.
peek(keylet::mptoken(mptID, accountID)))
1521 MPTID const& mptIssuanceID,
1527 auto const sleAcct = view.
peek(keylet::account(account));
1541 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1542 auto const sleMpt = view.
peek(mptokenKey);
1543 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1547 keylet::ownerDir(account),
1548 (*sleMpt)[sfOwnerNode],
1568 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1570 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1573 if (priorBalance < reserveCreate)
1577 auto const mpt = view.
read(keylet::mptIssuance(mptIssuanceID));
1578 if (!mpt || mpt->getAccountID(sfIssuer) == account)
1582 "xrpl::authorizeMPToken : invalid issuance or issuers token");
1588 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1590 if (
auto ter =
dirLink(view, account, mptoken))
1593 (*mptoken)[sfAccount] = account;
1594 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1595 (*mptoken)[sfFlags] = 0;
1604 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1605 if (!sleMptIssuance)
1611 if (account != (*sleMptIssuance)[sfIssuer])
1614 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1624 flagsOut &= ~lsfMPTAuthorized;
1630 if (flagsIn != flagsOut)
1631 sleMpt->setFieldU32(sfFlags, flagsOut);
1640 bool const bSrcHigh,
1646 bool const bNoRipple,
1657 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1658 << to_string(uDstAccountID) <<
", "
1661 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1662 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1663 if (uLowAccountID == uHighAccountID)
1666 UNREACHABLE(
"xrpl::trustCreate : trust line to self");
1673 view.
insert(sleRippleState);
1676 keylet::ownerDir(uLowAccountID),
1677 sleRippleState->key(),
1684 keylet::ownerDir(uHighAccountID),
1685 sleRippleState->key(),
1691 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1692 bool const bSetHigh = bSrcHigh ^ bSetDst;
1694 XRPL_ASSERT(sleAccount,
"xrpl::trustCreate : non-null SLE");
1699 sleAccount->getAccountID(sfAccount) ==
1700 (bSetHigh ? uHighAccountID : uLowAccountID),
1701 "xrpl::trustCreate : matching account ID");
1702 auto const slePeer =
1703 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1708 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1709 sleRippleState->setFieldU64(sfHighNode, *highNode);
1711 sleRippleState->setFieldAmount(
1712 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1713 sleRippleState->setFieldAmount(
1714 bSetHigh ? sfLowLimit : sfHighLimit,
1716 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1719 sleRippleState->setFieldU32(
1720 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1723 sleRippleState->setFieldU32(
1724 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1751 sleRippleState->setFieldU32(sfFlags, uFlags);
1755 sleRippleState->setFieldAmount(
1756 sfBalance, bSetHigh ? -saBalance : saBalance);
1759 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1773 auto const sle = view.
read(keylet::account(accountID));
1777 auto const balance = sle->getFieldAmount(sfBalance);
1778 if (balance.xrp() != 0)
1787 bool const accountIsIssuer = accountID == issue.
account;
1788 auto const line = view.
peek(keylet::line(accountID, issue));
1791 if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::zero)
1798 auto sleLowAccount =
1799 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1813 auto sleHighAccount =
1814 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1815 if (!sleHighAccount)
1828 line->at(sfLowLimit)->getIssuer(),
1829 line->at(sfHighLimit)->getIssuer(),
1843 bool const accountIsIssuer = accountID == mptIssue.
getIssuer();
1844 auto const& mptID = mptIssue.
getMptID();
1845 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1852 if (mptoken->at(sfMPTAmount) != 0)
1874 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1875 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1877 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1880 keylet::ownerDir(uLowAccountID),
1882 sleRippleState->key(),
1888 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1891 keylet::ownerDir(uHighAccountID),
1893 sleRippleState->key(),
1899 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1900 view.
erase(sleRippleState);
1910 auto offerIndex = sle->key();
1911 auto owner = sle->getAccountID(sfAccount);
1914 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1917 keylet::ownerDir(owner),
1918 sle->getFieldU64(sfOwnerNode),
1926 keylet::page(uDirectory),
1927 sle->getFieldU64(sfBookNode),
1934 if (sle->isFieldPresent(sfAdditionalBooks))
1937 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1938 "xrpl::offerDelete : should be a hybrid domain offer");
1940 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1942 for (
auto const& bookDir : additionalBookDirs)
1944 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1945 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1948 keylet::page(dirIndex), dirNode, offerIndex,
false))
1980 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1981 "xrpl::rippleCreditIOU : matching issuer or don't care");
1986 uSenderID != uReceiverID,
1987 "xrpl::rippleCreditIOU : sender is not receiver");
1989 bool const bSenderHigh = uSenderID > uReceiverID;
1990 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1994 "xrpl::rippleCreditIOU : sender is not XRP");
1997 "xrpl::rippleCreditIOU : receiver is not XRP");
2000 if (
auto const sleRippleState = view.
peek(index))
2002 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
2007 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
2009 STAmount const saBefore = saBalance;
2011 saBalance -= saAmount;
2013 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
2014 << to_string(uReceiverID)
2019 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
2020 bool bDelete =
false;
2024 if (saBefore > beast::zero
2026 && saBalance <= beast::zero
2034 view.
read(keylet::account(uSenderID))->getFlags() &
2037 !sleRippleState->getFieldAmount(
2038 !bSenderHigh ? sfLowLimit : sfHighLimit)
2040 && !sleRippleState->getFieldU32(
2041 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2043 && !sleRippleState->getFieldU32(
2044 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2049 view, view.
peek(keylet::account(uSenderID)), -1, j);
2052 sleRippleState->setFieldU32(
2054 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2057 bDelete = !saBalance
2066 sleRippleState->setFieldAmount(sfBalance, saBalance);
2074 bSenderHigh ? uReceiverID : uSenderID,
2075 !bSenderHigh ? uReceiverID : uSenderID,
2079 view.
update(sleRippleState);
2083 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
2088 JLOG(j.
debug()) <<
"rippleCreditIOU: "
2090 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
2093 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
2130 auto const& issuer = saAmount.
getIssuer();
2134 "xrpl::rippleSendIOU : neither sender nor receiver is XRP");
2136 uSenderID != uReceiverID,
2137 "xrpl::rippleSendIOU : sender is not receiver");
2139 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
2146 saActual = saAmount;
2154 saActual = (waiveFee == WaiveTransferFee::Yes)
2158 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
2159 << to_string(uReceiverID)
2167 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
2188 !
isXRP(senderID),
"xrpl::rippleSendMultiIOU : sender is not XRP");
2192 actual = takeFromSender;
2195 for (
auto const& r : receivers)
2197 auto const& receiverID = r.first;
2203 if (!amount || (senderID == receiverID))
2208 "xrpl::rippleSendMultiIOU : receiver is not XRP");
2210 if (senderID == issuer || receiverID == issuer || issuer ==
noAccount())
2214 view, senderID, receiverID, amount,
false, j))
2227 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2230 actual += actualSend;
2231 takeFromSender += actualSend;
2233 JLOG(j.
debug()) <<
"rippleSendMultiIOU> " << to_string(senderID)
2234 <<
" - > " << to_string(receiverID)
2235 <<
" : deliver=" << amount.getFullText()
2238 if (
TER const terResult =
2243 if (senderID != issuer && takeFromSender)
2246 view, senderID, issuer, takeFromSender,
true, j))
2274 "xrpl::accountSendIOU : minimum amount and not MPT");
2281 if (!saAmount || (uSenderID == uReceiverID))
2288 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
2289 << to_string(uReceiverID) <<
" : "
2293 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2304 ? view.
peek(keylet::account(uSenderID))
2307 ? view.
peek(keylet::account(uReceiverID))
2310 if (
auto stream = j.
trace())
2316 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2319 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2321 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
2322 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2323 << receiver_bal <<
") : " << saAmount.
getFullText();
2328 if (sender->getFieldAmount(sfBalance) < saAmount)
2339 auto const sndBal = sender->getFieldAmount(sfBalance);
2343 sender->setFieldAmount(sfBalance, sndBal - saAmount);
2351 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2352 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2358 if (
auto stream = j.
trace())
2364 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2367 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2369 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2370 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2371 << receiver_bal <<
") : " << saAmount.
getFullText();
2387 receivers.
size() > 1,
2388 "xrpl::accountSendMultiIOU",
2389 "multiple recipients provided");
2394 JLOG(j.
trace()) <<
"accountSendMultiIOU: " << to_string(senderID)
2395 <<
" sending " << receivers.
size() <<
" IOUs";
2398 view, senderID, issue, receivers, actual, j, waiveFee);
2408 ? view.
peek(keylet::account(senderID))
2411 if (
auto stream = j.
trace())
2416 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2418 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" ("
2419 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2424 for (
auto const& r : receivers)
2426 auto const& receiverID = r.first;
2429 if (amount < beast::zero)
2437 if (!amount || (senderID == receiverID))
2441 ? view.
peek(keylet::account(receiverID))
2444 if (
auto stream = j.
trace())
2450 receiver->getFieldAmount(sfBalance).getFullText();
2452 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" -> "
2453 << to_string(receiverID) <<
" (" << receiver_bal
2454 <<
") : " << amount.getFullText();
2460 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2461 receiver->setFieldAmount(sfBalance, rcvBal + amount);
2467 takeFromSender += amount;
2470 if (
auto stream = j.
trace())
2476 receiver->getFieldAmount(sfBalance).getFullText();
2478 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" -> "
2479 << to_string(receiverID) <<
" (" << receiver_bal
2480 <<
") : " << amount.getFullText();
2486 if (sender->getFieldAmount(sfBalance) < takeFromSender)
2492 auto const sndBal = sender->getFieldAmount(sfBalance);
2496 sender->setFieldAmount(sfBalance, sndBal - takeFromSender);
2501 if (
auto stream = j.
trace())
2507 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2509 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" ("
2510 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2525 auto const& issuer = saAmount.
getIssuer();
2526 auto sleIssuance = view.
peek(mptID);
2529 if (uSenderID == issuer)
2531 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2532 view.
update(sleIssuance);
2536 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2537 if (
auto sle = view.
peek(mptokenID))
2539 auto const amt = sle->getFieldU64(sfMPTAmount);
2540 auto const pay = saAmount.
mpt().
value();
2543 (*sle)[sfMPTAmount] = amt - pay;
2550 if (uReceiverID == issuer)
2552 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2553 auto const redeem = saAmount.
mpt().
value();
2554 if (outstanding >= redeem)
2556 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2557 view.
update(sleIssuance);
2564 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2565 if (
auto sle = view.
peek(mptokenID))
2567 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2588 uSenderID != uReceiverID,
2589 "xrpl::rippleSendMPT : sender is not receiver");
2592 auto const& issuer = saAmount.
getIssuer();
2599 if (uSenderID == issuer || uReceiverID == issuer)
2603 if (uSenderID == issuer)
2605 auto const sendAmount = saAmount.
mpt().
value();
2606 auto const maximumAmount =
2608 if (sendAmount > maximumAmount ||
2609 sle->getFieldU64(sfOutstandingAmount) >
2610 maximumAmount - sendAmount)
2619 saActual = saAmount;
2624 saActual = (waiveFee == WaiveTransferFee::Yes)
2630 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2631 << to_string(uReceiverID)
2635 if (
auto const terResult =
2655 auto const& issuer = mptIssue.
getIssuer();
2657 auto const sle = view.
read(keylet::mptIssuance(mptIssue.
getMptID()));
2663 actual = takeFromSender;
2665 for (
auto const& r : receivers)
2667 auto const& receiverID = r.first;
2668 STAmount amount{mptIssue, r.second};
2670 if (amount < beast::zero)
2678 if (!amount || (senderID == receiverID))
2681 if (senderID == issuer || receiverID == issuer)
2685 if (senderID == issuer)
2688 takeFromSender == beast::zero,
2689 "rippler::rippleSendMultiMPT",
2690 "sender == issuer, takeFromSender == zero");
2691 auto const sendAmount = amount.mpt().value();
2692 auto const maximumAmount =
2694 if (sendAmount > maximumAmount ||
2695 sle->getFieldU64(sfOutstandingAmount) >
2696 maximumAmount - sendAmount)
2701 if (
auto const ter =
2712 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2717 actual += actualSend;
2718 takeFromSender += actualSend;
2720 JLOG(j.
debug()) <<
"rippleSendMultiMPT> " << to_string(senderID)
2721 <<
" - > " << to_string(receiverID)
2722 <<
" : deliver=" << amount.getFullText()
2725 if (
auto const terResult =
2729 if (senderID != issuer && takeFromSender)
2731 if (
TER const terResult =
2750 "xrpl::accountSendMPT : minimum amount and MPT");
2755 if (!saAmount || (uSenderID == uReceiverID))
2761 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2776 view, senderID, mptIssue, receivers, actual, j, waiveFee);
2792 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2795 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2810 receivers.
size() > 1,
2811 "xrpl::accountSendMulti",
2812 "multiple recipients provided");
2817 view, senderID, issue, receivers, j, waiveFee);
2820 view, senderID, issue, receivers, j, waiveFee);
2839 auto sle = view.
peek(keylet::account(sender));
2844 if (before > beast::zero
2846 &&
after <= beast::zero
2850 &&
static_cast<bool>(
2854 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2856 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2859 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2868 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2888 "xrpl::issueIOU : neither account nor issuer is XRP");
2891 XRPL_ASSERT(issue == amount.issue(),
"xrpl::issueIOU : matching issue");
2895 issue.
account != account,
"xrpl::issueIOU : not issuer account");
2897 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2898 << amount.getFullText();
2900 bool bSenderHigh = issue.
account > account;
2902 auto const index = keylet::line(issue.
account, account, issue.
currency);
2904 if (
auto state = view.
peek(index))
2906 STAmount final_balance = state->getFieldAmount(sfBalance);
2911 STAmount const start_balance = final_balance;
2913 final_balance -= amount;
2932 state->setFieldAmount(sfBalance, final_balance);
2937 bSenderHigh ? account : issue.
account,
2938 bSenderHigh ? issue.
account : account,
2954 auto const receiverAccount = view.
peek(keylet::account(account));
2955 if (!receiverAccount)
2988 "xrpl::redeemIOU : neither account nor issuer is XRP");
2991 XRPL_ASSERT(issue == amount.issue(),
"xrpl::redeemIOU : matching issue");
2995 issue.
account != account,
"xrpl::redeemIOU : not issuer account");
2997 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2998 << amount.getFullText();
3000 bool bSenderHigh = account > issue.
account;
3005 STAmount final_balance = state->getFieldAmount(sfBalance);
3010 STAmount const start_balance = final_balance;
3012 final_balance -= amount;
3015 view, state, bSenderHigh, account, start_balance, final_balance, j);
3025 state->setFieldAmount(sfBalance, final_balance);
3032 bSenderHigh ? issue.
account : account,
3033 bSenderHigh ? account : issue.
account,
3045 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
3046 <<
" attempts to redeem " << amount.getFullText()
3047 <<
" but no trust line exists!";
3062 from != beast::zero,
"xrpl::transferXRP : nonzero from account");
3063 XRPL_ASSERT(to != beast::zero,
"xrpl::transferXRP : nonzero to account");
3064 XRPL_ASSERT(from != to,
"xrpl::transferXRP : sender is not receiver");
3065 XRPL_ASSERT(amount.native(),
"xrpl::transferXRP : amount is XRP");
3069 if (!sender || !receiver)
3072 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
3073 << to_string(to) <<
") : " << amount.getFullText();
3075 if (sender->getFieldAmount(sfBalance) < amount)
3087 sender->setFieldAmount(
3088 sfBalance, sender->getFieldAmount(sfBalance) - amount);
3091 receiver->setFieldAmount(
3092 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
3108 auto const trustLine =
3111 if (!trustLine && authType == AuthType::StrongAuth)
3116 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
3120 return ((*trustLine)[sfFlags] &
3138 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3139 auto const sleIssuance = view.
read(mptID);
3143 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
3146 if (mptIssuer == account)
3149 bool const featureSAVEnabled =
3152 if (featureSAVEnabled)
3158 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
3162 if (sleIssuer->isFieldPresent(sfVaultID))
3164 auto const sleVault =
3165 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
3169 auto const asset = sleVault->at(sfAsset);
3173 return requireAuth(view, issue, account, authType);
3176 view, issue, account, authType, depth + 1);
3184 auto const mptokenID = keylet::mptoken(mptID.key, account);
3185 auto const sleToken = view.
read(mptokenID);
3189 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
3194 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3199 "xrpl::requireAuth : issuance requires authorization");
3201 if (
auto const ter =
3202 credentials::validDomain(view, *maybeDomainID, account);
3211 if (featureSAVEnabled)
3229 MPTID const& mptIssuanceID,
3234 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
3240 "xrpl::enforceMPTokenAuthorization : authorization required");
3242 if (account == sleIssuance->at(sfIssuer))
3245 auto const keylet = keylet::mptoken(mptIssuanceID, account);
3246 auto const sleToken = view.
read(keylet);
3247 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3249 bool const authorizedByDomain = [&]() ->
bool {
3251 if (!maybeDomainID.has_value())
3262 if (!authorizedByDomain && sleToken ==
nullptr)
3273 else if (!authorizedByDomain && maybeDomainID.has_value())
3280 else if (!authorizedByDomain)
3285 sleToken !=
nullptr && !maybeDomainID.has_value(),
3286 "xrpl::enforceMPTokenAuthorization : found MPToken");
3292 else if (authorizedByDomain && sleToken !=
nullptr)
3297 maybeDomainID.has_value(),
3298 "xrpl::enforceMPTokenAuthorization : found MPToken for domain");
3301 else if (authorizedByDomain)
3306 maybeDomainID.has_value() && sleToken ==
nullptr,
3307 "xrpl::enforceMPTokenAuthorization : new MPToken for domain");
3322 "xrpl::enforceMPTokenAuthorization : condition list is incomplete");
3334 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3335 auto const sleIssuance = view.
read(mptID);
3341 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
3357 auto const& issuerId = issue.
getIssuer();
3358 if (issuerId == from || issuerId == to)
3360 auto const sleIssuer = view.
read(keylet::account(issuerId));
3361 if (sleIssuer ==
nullptr)
3364 auto const isRippleDisabled = [&](
AccountID account) ->
bool {
3367 auto const line = view.
read(keylet::line(account, issue));
3370 bool const issuerHigh = issuerId > account;
3377 if (isRippleDisabled(from) && isRippleDisabled(to))
3386 Keylet const& ownerDirKeylet,
3393 unsigned int uDirEntry{0};
3394 uint256 dirEntry{beast::zero};
3397 if (view.
exists(ownerDirKeylet) &&
3398 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
3402 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
3406 auto sleItem = view.
peek(keylet::child(dirEntry));
3412 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
3413 <<
" has index to object that is missing: "
3414 << to_string(dirEntry);
3420 sleItem->getFieldU16(sfLedgerEntryType))};
3424 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
3446 "xrpl::cleanupOnAccountDelete : minimum dir entries");
3451 <<
"DeleteAccount iterator re-validation failed.";
3455 if (skipEntry == SkipEntry::No)
3459 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
3472 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
3476 sleState->getFieldAmount(sfLowLimit).getIssuer(),
3477 sleState->getFieldAmount(sfHighLimit).getIssuer());
3478 auto sleLow = view.
peek(keylet::account(low));
3479 auto sleHigh = view.
peek(keylet::account(high));
3480 if (!sleLow || !sleHigh)
3483 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
3484 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
3487 if (ammLow && ammHigh)
3491 if (!ammLow && !ammHigh)
3495 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
3498 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
3502 <<
"deleteAMMTrustLine: failed to delete the trustline.";
3507 if (!(sleState->getFlags() & uFlags))
3529 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
3534 !bCheckIssuer,
"xrpl::rippleCredit : not checking issuer");
3536 view, uSenderID, uReceiverID, saAmount, j);
3550 "xrpl::assetsToSharesDeposit : non-negative assets");
3552 assets.
asset() == vault->at(sfAsset),
3553 "xrpl::assetsToSharesDeposit : assets and vault match");
3554 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3557 Number const assetTotal = vault->at(sfAssetsTotal);
3558 STAmount shares{vault->at(sfShareMPTID)};
3559 if (assetTotal == 0)
3565 Number const shareTotal = issuance->at(sfOutstandingAmount);
3566 shares = ((shareTotal * assets) / assetTotal).truncate();
3578 "xrpl::sharesToAssetsDeposit : non-negative shares");
3580 shares.
asset() == vault->at(sfShareMPTID),
3581 "xrpl::sharesToAssetsDeposit : shares and vault match");
3582 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3585 Number const assetTotal = vault->at(sfAssetsTotal);
3586 STAmount assets{vault->at(sfAsset)};
3587 if (assetTotal == 0)
3591 shares.
exponent() - vault->at(sfScale),
3594 Number const shareTotal = issuance->at(sfOutstandingAmount);
3595 assets = (assetTotal * shares) / shareTotal;
3608 "xrpl::assetsToSharesDeposit : non-negative assets");
3610 assets.
asset() == vault->at(sfAsset),
3611 "xrpl::assetsToSharesWithdraw : assets and vault match");
3612 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3615 Number assetTotal = vault->at(sfAssetsTotal);
3616 assetTotal -= vault->at(sfLossUnrealized);
3617 STAmount shares{vault->at(sfShareMPTID)};
3618 if (assetTotal == 0)
3620 Number const shareTotal = issuance->at(sfOutstandingAmount);
3621 Number result = (shareTotal * assets) / assetTotal;
3622 if (truncate == TruncateShares::yes)
3636 "xrpl::sharesToAssetsDeposit : non-negative shares");
3638 shares.
asset() == vault->at(sfShareMPTID),
3639 "xrpl::sharesToAssetsWithdraw : shares and vault match");
3640 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3643 Number assetTotal = vault->at(sfAssetsTotal);
3644 assetTotal -= vault->at(sfLossUnrealized);
3645 STAmount assets{vault->at(sfAsset)};
3646 if (assetTotal == 0)
3648 Number const shareTotal = issuance->at(sfOutstandingAmount);
3649 assets = (assetTotal * shares) / shareTotal;
3660 auto const mptIssue = amount.get<
MPTIssue>();
3661 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3662 auto sleIssuance = view.
peek(mptID);
3665 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
3666 << mptIssue.getMptID();
3670 if (amount.getIssuer() == sender)
3673 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3680 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3681 auto sle = view.
peek(mptokenID);
3685 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3689 auto const amt = sle->getFieldU64(sfMPTAmount);
3690 auto const pay = amount.mpt().value();
3696 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3697 << to_string(sender) <<
": " << amt <<
" < " << pay;
3701 (*sle)[sfMPTAmount] = amt - pay;
3704 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3709 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3710 << to_string(sender) <<
": " << locked <<
" + " << pay;
3714 if (sle->isFieldPresent(sfLockedAmount))
3715 (*sle)[sfLockedAmount] += pay;
3717 sle->setFieldU64(sfLockedAmount, pay);
3725 uint64_t
const issuanceEscrowed =
3726 (*sleIssuance)[~sfLockedAmount].value_or(0);
3727 auto const pay = amount.mpt().value();
3733 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3734 "locked amount for "
3735 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3740 if (sleIssuance->isFieldPresent(sfLockedAmount))
3741 (*sleIssuance)[sfLockedAmount] += pay;
3743 sleIssuance->setFieldU64(sfLockedAmount, pay);
3745 view.
update(sleIssuance);
3761 netAmount == grossAmount,
3762 "xrpl::rippleUnlockEscrowMPT : netAmount == grossAmount");
3764 auto const& issuer = netAmount.
getIssuer();
3766 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3767 auto sleIssuance = view.
peek(mptID);
3770 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3771 << mptIssue.getMptID();
3777 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3780 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3781 << mptIssue.getMptID();
3785 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3786 auto const redeem = grossAmount.
mpt().
value();
3793 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3794 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3798 auto const newLocked = locked - redeem;
3800 sleIssuance->makeFieldAbsent(sfLockedAmount);
3802 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3803 view.
update(sleIssuance);
3806 if (issuer != receiver)
3809 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3810 auto sle = view.
peek(mptokenID);
3814 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3818 auto current = sle->getFieldU64(sfMPTAmount);
3819 auto delta = netAmount.
mpt().
value();
3825 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3826 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3830 (*sle)[sfMPTAmount] += delta;
3836 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3837 auto const redeem = netAmount.
mpt().
value();
3844 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3845 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3850 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3851 view.
update(sleIssuance);
3854 if (issuer == sender)
3856 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3857 "cannot unlock MPTs.";
3863 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3864 auto sle = view.
peek(mptokenID);
3868 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3872 if (!sle->isFieldPresent(sfLockedAmount))
3875 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3876 << to_string(sender);
3880 auto const locked = sle->getFieldU64(sfLockedAmount);
3881 auto const delta = grossAmount.
mpt().
value();
3887 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3888 << to_string(sender) <<
": " << locked <<
" < " << delta;
3892 auto const newLocked = locked - delta;
3894 sle->makeFieldAbsent(sfLockedAmount);
3896 sle->setFieldU64(sfLockedAmount, newLocked);
3907 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3913 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3914 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3918 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3919 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 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 erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
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.
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
AccountID const & getIssuer() const
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Number truncate() const noexcept
virtual Rules const & rules() const =0
Returns the tx processing rules.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous 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.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
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.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
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.
constexpr bool holds() const noexcept
constexpr TIss const & get() const
std::string getFullText() const override
static constexpr std::uint64_t cMaxValue
void setIssuer(AccountID const &uIssuer)
std::uint64_t mantissa() const noexcept
bool negative() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
static int const cMaxOffset
Currency const & getCurrency() const
bool native() const noexcept
Asset const & asset() const
int exponent() const noexcept
AccountID const & getIssuer() const
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const_pointer
bool isFieldPresent(SField const &field) const
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 const & skip() noexcept
The index of the "short" skip list.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet const & amendments() noexcept
The index of the amendment table.
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 amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
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 mptoken(MPTID const &issuanceID, AccountID const &holder) 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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
std::vector< SField const * > const & getPseudoAccountFields()
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
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...
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
FreezeHandling
Controls the treatment of frozen account balances.
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
SpendableHandling
Controls whether to include the account's full spendable balance.
bool isXRP(AccountID const &c)
TER canAddHolding(ReadView const &view, Asset const &asset)
std::uint8_t constexpr maxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
std::map< uint256, NetClock::time_point > majorityAmendments_t
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
std::string to_string(base_uint< Bits, Tag > const &a)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, beast::Journal j)
static TER accountSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
static TER rippleSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
@ expired
List is expired, but has the largest non-pending sequence seen so far.
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
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.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=shSIMPLE_BALANCE)
Number root(Number f, unsigned d)
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
static TER rippleCreditMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
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.
STAmount multiply(STAmount const &amount, Rate const &rate)
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
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)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
STAmount creditLimit(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const ¤cy)
Calculate the maximum amount of IOUs that an account can hold.
static TER rippleCreditIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
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.
static TER rippleSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
static TER rippleSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
@ current
This was a new validation and was added.
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 isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
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()})
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.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
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)
static TER rippleSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
bool canAdd(STAmount const &amt1, STAmount const &amt2)
Safely checks if two STAmount values can be added without overflow, underflow, or precision loss.
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
static STAmount getTrustLineBalance(ReadView const &view, SLE::const_ref sle, AccountID const &account, Currency const ¤cy, AccountID const &issuer, bool includeOppositeLimit, beast::Journal j)
static TER withdrawToDestExceedsLimit(ReadView const &view, AccountID const &from, AccountID const &to, STAmount const &amount)
AuthHandling
Controls the treatment of unauthorized MPT balances.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
static SLE::const_pointer getLineIfUsable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
majorityAmendments_t getMajorityAmendments(ReadView const &view)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
STAmount creditBalance(ReadView const &view, AccountID const &account, AccountID const &issuer, Currency const ¤cy)
Returns the amount of IOUs issued by issuer that are held by an account.
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
constexpr std::uint32_t const tfMPTUnauthorize
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
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)
TER redeemIOU(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)
bool canSubtract(STAmount const &amt1, STAmount const &amt2)
Determines if it is safe to subtract one STAmount from another.
bool isTesSuccess(TER x) noexcept
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
LedgerEntryType
Identifiers for on-ledger objects.
AccountID const & xrpAccount()
Compute AccountID from public key.
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
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.
static TER accountSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
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 canWithdraw(ReadView const &view, AccountID const &from, AccountID const &to, SLE::const_ref toSle, STAmount const &amount, bool hasDestinationTag)
Checks that can withdraw funds from an object to itself or a destination.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Validates that the destination SLE and tag are valid.
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
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.
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.
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.
A field with a type known at compile time.
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
T time_since_epoch(T... args)