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/ReadView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/protocol/Feature.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/LedgerFormats.h>
11#include <xrpl/protocol/MPTIssue.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/Quality.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/TxFlags.h>
16#include <xrpl/protocol/digest.h>
17#include <xrpl/protocol/st.h>
40 auto const& svIndexes = page->getFieldV256(sfIndexes);
42 index <= svIndexes.size(),
43 "ripple::detail::internalDirNext : index inside range");
45 if (index >= svIndexes.size())
47 auto const next = page->getFieldU64(sfIndexNext);
60 XRPL_ASSERT(page,
"ripple::detail::internalDirNext : non-null root");
70 entry = svIndexes[index++];
202 if (issuer != account)
239 if (issuer != account)
272 for (
auto const& account : accounts)
278 for (
auto const& account : accounts)
300 auto const mptIssuance =
302 if (mptIssuance ==
nullptr)
305 auto const issuer = mptIssuance->getAccountID(sfIssuer);
307 if (mptIssuer ==
nullptr)
310 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null MPToken issuer");
315 if (!mptIssuer->isFieldPresent(sfVaultID))
320 if (vault ==
nullptr)
322 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null vault");
327 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
342 if (issuer == account)
385 if (
isFrozen(view, account, currency, issuer) ||
400 else if (sleIssuer->isFieldPresent(sfAMMID))
409 (*sleAmm)[sfAsset].get<Issue>(),
410 (*sleAmm)[sfAsset2].get<Issue>()))
428 bool includeOppositeLimit,
434 amount = sle->getFieldAmount(sfBalance);
435 bool const accountHigh = account > issuer;
436 auto const& oppositeField = accountHigh ? sfLowLimit : sfHighLimit;
442 if (includeOppositeLimit)
444 amount += sle->getFieldAmount(oppositeField);
446 amount.setIssuer(issuer);
450 amount.clear(
Issue{currency, issuer});
453 JLOG(j.
trace()) <<
"getTrustLineBalance:"
455 <<
" amount=" << amount.getFullText();
509 amount.clear(mptIssue);
512 amount.clear(mptIssue);
515 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
525 amount.clear(mptIssue);
529 auto const sleIssuance =
536 amount.clear(mptIssue);
543[[nodiscard]] STAmount
553 [&](
auto const& value) {
558 return accountHolds(view, account, value, zeroIfFrozen, j);
561 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
576 return accountHolds(view, account, currency, issuer, zeroIfFrozen, j);
578 if (account == issuer)
616 auto const issuance =
626 issuance->at(sfOutstandingAmount)};
630 view, account, mptIssue, zeroIfFrozen, zeroIfUnauthorized, j);
633[[nodiscard]] STAmount
643 [&](
auto const& value) {
651 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
698 <<
"Account " << *
id <<
" owner count exceeds max!";
711 <<
"Account " << *
id <<
" owner count set below 0!";
714 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
733 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
740 auto const fullBalance = sle->getFieldAmount(sfBalance);
745 (balance < reserve) ?
STAmount{0} : balance - reserve;
747 JLOG(j.
trace()) <<
"accountHolds:"
749 <<
" amount=" << amount.getFullText()
750 <<
" fullBalance=" << fullBalance.getFullText()
751 <<
" balance=" << balance.getFullText()
752 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
753 <<
" ownerCountAdj=" << ownerCountAdj;
765 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
767 if (
root.type != ltDIR_NODE)
774 auto sle = view.
read(pos);
777 for (
auto const& key : sle->getFieldV256(sfIndexes))
779 auto const next = sle->getFieldU64(sfIndexNext);
796 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
798 if (
root.type != ltDIR_NODE)
801 auto currentIndex =
root;
804 if (
after.isNonZero())
808 if (
auto hintDir = view.
read(hintIndex))
810 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
815 currentIndex = hintIndex;
824 auto const ownerDir = view.
read(currentIndex);
827 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
840 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
850 auto const ownerDir = view.
read(currentIndex);
853 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
856 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
869 if (sle && sle->isFieldPresent(sfTransferRate))
870 return Rate{sle->getFieldU32(sfTransferRate)};
882 sle && sle->isFieldPresent(sfTransferFee))
883 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
898 amount.asset().value());
917 if (hash && (*hash != validLedger.
info().
hash))
919 JLOG(s) << reason <<
" incompatible with valid ledger";
921 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
933 if (hash && (*hash != testLedger.
info().
hash))
935 JLOG(s) << reason <<
" incompatible preceding ledger";
937 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
947 JLOG(s) << reason <<
" incompatible ledger";
954 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
957 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
974 if (testLedger.
info().
seq > validIndex)
981 if (hash && (*hash != validHash))
983 JLOG(s) << reason <<
" incompatible following ledger";
984 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
990 (validIndex == testLedger.
info().
seq) &&
991 (testLedger.
info().
hash != validHash))
993 JLOG(s) << reason <<
" incompatible ledger";
1000 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
1002 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
1012 auto const sleNode = view.
read(k);
1015 if (!sleNode->getFieldV256(sfIndexes).empty())
1020 return sleNode->getFieldU64(sfIndexNext) == 0;
1030 if (sle->isFieldPresent(sfAmendments))
1032 auto const& v = sle->getFieldV256(sfAmendments);
1033 amendments.insert(v.begin(), v.end());
1047 if (sle->isFieldPresent(sfMajorities))
1050 using d = tp::duration;
1052 auto const majorities = sle->getFieldArray(sfMajorities);
1054 for (
auto const& m : majorities)
1055 ret[m.getFieldH256(sfAmendment)] =
1056 tp(d(m.getFieldU32(sfCloseTime)));
1067 if (seq > ledger.
seq())
1069 JLOG(journal.
warn())
1070 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
1073 if (seq == ledger.
seq())
1075 if (seq == (ledger.
seq() - 1))
1078 if (
int diff = ledger.
seq() - seq; diff <= 256)
1085 hashIndex->getFieldU32(sfLastLedgerSequence) ==
1087 "ripple::hashOfSeq : matching ledger sequence");
1088 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1089 if (vec.
size() >= diff)
1090 return vec[vec.
size() - diff];
1091 JLOG(journal.
warn())
1092 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
1093 <<
" (" << vec.
size() <<
"," << diff <<
")";
1097 JLOG(journal.
warn())
1098 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
1099 <<
" missing normal list";
1103 if ((seq & 0xff) != 0)
1105 JLOG(journal.
debug())
1106 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1114 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1115 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
1117 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
1118 auto const diff = (lastSeq - seq) >> 8;
1119 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1120 if (vec.
size() > diff)
1121 return vec[vec.
size() - diff - 1];
1123 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1143 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1148 sle->at(sfOwnerCount) = adjusted;
1156 (*sle)[sfOwner] = account;
1171 object->setFieldU64(node, *page);
1184 rsh(hash.data(), hash.size());
1207 "ripple::getPseudoAccountFields : unable to find account root "
1212 auto const& soTemplate = ar->getSOTemplate();
1215 for (
auto const& field : soTemplate)
1220 return pseudoFields;
1222 return pseudoFields;
1234 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1238 [&sleAcct, &pseudoFieldFilter](
SField const* sf) ->
bool {
1239 return sleAcct->isFieldPresent(*sf) &&
1240 (pseudoFieldFilter.empty() ||
1241 pseudoFieldFilter.contains(sf));
1245Expected<std::shared_ptr<SLE>,
TER>
1248 uint256 const& pseudoOwnerKey,
1249 SField const& ownerField)
1257 [&ownerField](
SField const* sf) ->
bool {
1258 return *sf == ownerField;
1260 "ripple::createPseudoAccount : valid owner field");
1263 if (accountId == beast::zero)
1268 account->setAccountID(sfAccount, accountId);
1269 account->setFieldAmount(sfBalance,
STAmount{});
1279 account->setFieldU32(sfSequence, seqno);
1283 account->setFieldU32(
1286 account->setFieldH256(ownerField, pseudoOwnerKey);
1334 if (toSle ==
nullptr)
1351 bool hasDestinationTag)
1373 bool hasDestinationTag)
1377 return canWithdraw(from, view, to, toSle, hasDestinationTag);
1383 auto const from = tx[sfAccount];
1384 auto const to = tx[~sfDestination].value_or(from);
1401 if (dstAcct == senderAcct)
1404 view, senderAcct, priorBalance, amount.asset(), j);
1426 JLOG(j.
error()) <<
"LoanBrokerCoverWithdraw: negative balance of "
1427 "broker cover assets.";
1450 auto const& issuerId = issue.
getIssuer();
1451 auto const& currency = issue.
currency;
1455 auto const& srcId = issuerId;
1456 auto const& dstId = accountID;
1457 auto const high = srcId > dstId;
1458 auto const index =
keylet::line(srcId, dstId, currency);
1461 if (!sleDst || !sleSrc)
1466 if (view.
read(index))
1485 STAmount{Issue{currency, noAccount()}},
1486 STAmount{Issue{currency, dstId}},
1500 auto const& mptID = mptIssue.
getMptID();
1501 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1506 if (view.
peek(keylet::mptoken(mptID, accountID)))
1518 MPTID const& mptIssuanceID,
1524 auto const sleAcct = view.
peek(keylet::account(account));
1538 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1539 auto const sleMpt = view.
peek(mptokenKey);
1540 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1544 keylet::ownerDir(account),
1545 (*sleMpt)[sfOwnerNode],
1565 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1567 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1570 if (priorBalance < reserveCreate)
1574 auto const mpt = view.
read(keylet::mptIssuance(mptIssuanceID));
1575 if (!mpt || mpt->getAccountID(sfIssuer) == account)
1579 "ripple::authorizeMPToken : invalid issuance or issuers token");
1585 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1587 if (
auto ter =
dirLink(view, account, mptoken))
1590 (*mptoken)[sfAccount] = account;
1591 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1592 (*mptoken)[sfFlags] = 0;
1601 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1602 if (!sleMptIssuance)
1608 if (account != (*sleMptIssuance)[sfIssuer])
1611 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1621 flagsOut &= ~lsfMPTAuthorized;
1627 if (flagsIn != flagsOut)
1628 sleMpt->setFieldU32(sfFlags, flagsOut);
1637 bool const bSrcHigh,
1643 bool const bNoRipple,
1654 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1655 << to_string(uDstAccountID) <<
", "
1658 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1659 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1660 if (uLowAccountID == uHighAccountID)
1663 UNREACHABLE(
"ripple::trustCreate : trust line to self");
1670 view.
insert(sleRippleState);
1673 keylet::ownerDir(uLowAccountID),
1674 sleRippleState->key(),
1681 keylet::ownerDir(uHighAccountID),
1682 sleRippleState->key(),
1688 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1689 bool const bSetHigh = bSrcHigh ^ bSetDst;
1691 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1696 sleAccount->getAccountID(sfAccount) ==
1697 (bSetHigh ? uHighAccountID : uLowAccountID),
1698 "ripple::trustCreate : matching account ID");
1699 auto const slePeer =
1700 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1705 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1706 sleRippleState->setFieldU64(sfHighNode, *highNode);
1708 sleRippleState->setFieldAmount(
1709 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1710 sleRippleState->setFieldAmount(
1711 bSetHigh ? sfLowLimit : sfHighLimit,
1713 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1716 sleRippleState->setFieldU32(
1717 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1720 sleRippleState->setFieldU32(
1721 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1748 sleRippleState->setFieldU32(sfFlags, uFlags);
1752 sleRippleState->setFieldAmount(
1753 sfBalance, bSetHigh ? -saBalance : saBalance);
1756 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1770 auto const sle = view.
read(keylet::account(accountID));
1774 auto const balance = sle->getFieldAmount(sfBalance);
1775 if (balance.xrp() != 0)
1784 bool const accountIsIssuer = accountID == issue.
account;
1785 auto const line = view.
peek(keylet::line(accountID, issue));
1788 if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::zero)
1795 auto sleLowAccount =
1796 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1810 auto sleHighAccount =
1811 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1812 if (!sleHighAccount)
1825 line->at(sfLowLimit)->getIssuer(),
1826 line->at(sfHighLimit)->getIssuer(),
1840 bool const accountIsIssuer = accountID == mptIssue.
getIssuer();
1841 auto const& mptID = mptIssue.
getMptID();
1842 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1849 if (mptoken->at(sfMPTAmount) != 0)
1871 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1872 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1874 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1877 keylet::ownerDir(uLowAccountID),
1879 sleRippleState->key(),
1885 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1888 keylet::ownerDir(uHighAccountID),
1890 sleRippleState->key(),
1896 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1897 view.
erase(sleRippleState);
1907 auto offerIndex = sle->key();
1908 auto owner = sle->getAccountID(sfAccount);
1911 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1914 keylet::ownerDir(owner),
1915 sle->getFieldU64(sfOwnerNode),
1923 keylet::page(uDirectory),
1924 sle->getFieldU64(sfBookNode),
1931 if (sle->isFieldPresent(sfAdditionalBooks))
1934 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1935 "ripple::offerDelete : should be a hybrid domain offer");
1937 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1939 for (
auto const& bookDir : additionalBookDirs)
1941 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1942 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1945 keylet::page(dirIndex), dirNode, offerIndex,
false))
1977 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1978 "ripple::rippleCreditIOU : matching issuer or don't care");
1983 uSenderID != uReceiverID,
1984 "ripple::rippleCreditIOU : sender is not receiver");
1986 bool const bSenderHigh = uSenderID > uReceiverID;
1987 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1991 "ripple::rippleCreditIOU : sender is not XRP");
1994 "ripple::rippleCreditIOU : receiver is not XRP");
1997 if (
auto const sleRippleState = view.
peek(index))
1999 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
2004 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
2006 STAmount const saBefore = saBalance;
2008 saBalance -= saAmount;
2010 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
2011 << to_string(uReceiverID)
2016 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
2017 bool bDelete =
false;
2021 if (saBefore > beast::zero
2023 && saBalance <= beast::zero
2031 view.
read(keylet::account(uSenderID))->getFlags() &
2034 !sleRippleState->getFieldAmount(
2035 !bSenderHigh ? sfLowLimit : sfHighLimit)
2037 && !sleRippleState->getFieldU32(
2038 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2040 && !sleRippleState->getFieldU32(
2041 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2046 view, view.
peek(keylet::account(uSenderID)), -1, j);
2049 sleRippleState->setFieldU32(
2051 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2054 bDelete = !saBalance
2063 sleRippleState->setFieldAmount(sfBalance, saBalance);
2071 bSenderHigh ? uReceiverID : uSenderID,
2072 !bSenderHigh ? uReceiverID : uSenderID,
2076 view.
update(sleRippleState);
2080 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
2085 JLOG(j.
debug()) <<
"rippleCreditIOU: "
2087 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
2090 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
2127 auto const& issuer = saAmount.
getIssuer();
2131 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
2133 uSenderID != uReceiverID,
2134 "ripple::rippleSendIOU : sender is not receiver");
2136 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
2143 saActual = saAmount;
2151 saActual = (waiveFee == WaiveTransferFee::Yes)
2155 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
2156 << to_string(uReceiverID)
2164 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
2185 !
isXRP(senderID),
"ripple::rippleSendMultiIOU : sender is not XRP");
2189 actual = takeFromSender;
2192 for (
auto const& r : receivers)
2194 auto const& receiverID = r.first;
2200 if (!amount || (senderID == receiverID))
2205 "ripple::rippleSendMultiIOU : receiver is not XRP");
2207 if (senderID == issuer || receiverID == issuer || issuer ==
noAccount())
2211 view, senderID, receiverID, amount,
false, j))
2224 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2227 actual += actualSend;
2228 takeFromSender += actualSend;
2230 JLOG(j.
debug()) <<
"rippleSendMultiIOU> " << to_string(senderID)
2231 <<
" - > " << to_string(receiverID)
2232 <<
" : deliver=" << amount.getFullText()
2235 if (
TER const terResult =
2240 if (senderID != issuer && takeFromSender)
2243 view, senderID, issuer, takeFromSender,
true, j))
2271 "ripple::accountSendIOU : minimum amount and not MPT");
2278 if (!saAmount || (uSenderID == uReceiverID))
2285 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
2286 << to_string(uReceiverID) <<
" : "
2290 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2301 ? view.
peek(keylet::account(uSenderID))
2304 ? view.
peek(keylet::account(uReceiverID))
2307 if (
auto stream = j.
trace())
2313 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2316 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2318 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
2319 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2320 << receiver_bal <<
") : " << saAmount.
getFullText();
2325 if (sender->getFieldAmount(sfBalance) < saAmount)
2336 auto const sndBal = sender->getFieldAmount(sfBalance);
2340 sender->setFieldAmount(sfBalance, sndBal - saAmount);
2348 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2349 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2355 if (
auto stream = j.
trace())
2361 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2364 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2366 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2367 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2368 << receiver_bal <<
") : " << saAmount.
getFullText();
2384 receivers.
size() > 1,
2385 "ripple::accountSendMultiIOU",
2386 "multiple recipients provided");
2391 JLOG(j.
trace()) <<
"accountSendMultiIOU: " << to_string(senderID)
2392 <<
" sending " << receivers.
size() <<
" IOUs";
2395 view, senderID, issue, receivers, actual, j, waiveFee);
2405 ? view.
peek(keylet::account(senderID))
2408 if (
auto stream = j.
trace())
2413 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2415 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" ("
2416 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2421 for (
auto const& r : receivers)
2423 auto const& receiverID = r.first;
2426 if (amount < beast::zero)
2434 if (!amount || (senderID == receiverID))
2438 ? view.
peek(keylet::account(receiverID))
2441 if (
auto stream = j.
trace())
2447 receiver->getFieldAmount(sfBalance).getFullText();
2449 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" -> "
2450 << to_string(receiverID) <<
" (" << receiver_bal
2451 <<
") : " << amount.getFullText();
2457 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2458 receiver->setFieldAmount(sfBalance, rcvBal + amount);
2464 takeFromSender += amount;
2467 if (
auto stream = j.
trace())
2473 receiver->getFieldAmount(sfBalance).getFullText();
2475 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" -> "
2476 << to_string(receiverID) <<
" (" << receiver_bal
2477 <<
") : " << amount.getFullText();
2483 if (sender->getFieldAmount(sfBalance) < takeFromSender)
2489 auto const sndBal = sender->getFieldAmount(sfBalance);
2493 sender->setFieldAmount(sfBalance, sndBal - takeFromSender);
2498 if (
auto stream = j.
trace())
2504 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2506 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" ("
2507 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2522 auto const& issuer = saAmount.
getIssuer();
2523 auto sleIssuance = view.
peek(mptID);
2526 if (uSenderID == issuer)
2528 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2529 view.
update(sleIssuance);
2533 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2534 if (
auto sle = view.
peek(mptokenID))
2536 auto const amt = sle->getFieldU64(sfMPTAmount);
2537 auto const pay = saAmount.
mpt().
value();
2540 (*sle)[sfMPTAmount] = amt - pay;
2547 if (uReceiverID == issuer)
2549 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2550 auto const redeem = saAmount.
mpt().
value();
2551 if (outstanding >= redeem)
2553 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2554 view.
update(sleIssuance);
2561 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2562 if (
auto sle = view.
peek(mptokenID))
2564 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2585 uSenderID != uReceiverID,
2586 "ripple::rippleSendMPT : sender is not receiver");
2589 auto const& issuer = saAmount.
getIssuer();
2596 if (uSenderID == issuer || uReceiverID == issuer)
2600 if (uSenderID == issuer)
2602 auto const sendAmount = saAmount.
mpt().
value();
2603 auto const maximumAmount =
2605 if (sendAmount > maximumAmount ||
2606 sle->getFieldU64(sfOutstandingAmount) >
2607 maximumAmount - sendAmount)
2616 saActual = saAmount;
2621 saActual = (waiveFee == WaiveTransferFee::Yes)
2627 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2628 << to_string(uReceiverID)
2632 if (
auto const terResult =
2652 auto const& issuer = mptIssue.
getIssuer();
2654 auto const sle = view.
read(keylet::mptIssuance(mptIssue.
getMptID()));
2660 actual = takeFromSender;
2662 for (
auto const& r : receivers)
2664 auto const& receiverID = r.first;
2665 STAmount amount{mptIssue, r.second};
2667 if (amount < beast::zero)
2675 if (!amount || (senderID == receiverID))
2678 if (senderID == issuer || receiverID == issuer)
2682 if (senderID == issuer)
2685 takeFromSender == beast::zero,
2686 "rippler::rippleSendMultiMPT",
2687 "sender == issuer, takeFromSender == zero");
2688 auto const sendAmount = amount.mpt().value();
2689 auto const maximumAmount =
2691 if (sendAmount > maximumAmount ||
2692 sle->getFieldU64(sfOutstandingAmount) >
2693 maximumAmount - sendAmount)
2698 if (
auto const ter =
2709 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2714 actual += actualSend;
2715 takeFromSender += actualSend;
2717 JLOG(j.
debug()) <<
"rippleSendMultiMPT> " << to_string(senderID)
2718 <<
" - > " << to_string(receiverID)
2719 <<
" : deliver=" << amount.getFullText()
2722 if (
auto const terResult =
2726 if (senderID != issuer && takeFromSender)
2728 if (
TER const terResult =
2747 "ripple::accountSendMPT : minimum amount and MPT");
2752 if (!saAmount || (uSenderID == uReceiverID))
2758 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2773 view, senderID, mptIssue, receivers, actual, j, waiveFee);
2789 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2792 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2807 receivers.
size() > 1,
2808 "ripple::accountSendMulti",
2809 "multiple recipients provided");
2814 view, senderID, issue, receivers, j, waiveFee);
2817 view, senderID, issue, receivers, j, waiveFee);
2836 auto sle = view.
peek(keylet::account(sender));
2841 if (before > beast::zero
2843 &&
after <= beast::zero
2847 &&
static_cast<bool>(
2851 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2853 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2856 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2865 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2885 "ripple::issueIOU : neither account nor issuer is XRP");
2888 XRPL_ASSERT(issue == amount.issue(),
"ripple::issueIOU : matching issue");
2892 issue.
account != account,
"ripple::issueIOU : not issuer account");
2894 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2895 << amount.getFullText();
2897 bool bSenderHigh = issue.
account > account;
2899 auto const index = keylet::line(issue.
account, account, issue.
currency);
2901 if (
auto state = view.
peek(index))
2903 STAmount final_balance = state->getFieldAmount(sfBalance);
2908 STAmount const start_balance = final_balance;
2910 final_balance -= amount;
2929 state->setFieldAmount(sfBalance, final_balance);
2934 bSenderHigh ? account : issue.
account,
2935 bSenderHigh ? issue.
account : account,
2951 auto const receiverAccount = view.
peek(keylet::account(account));
2952 if (!receiverAccount)
2985 "ripple::redeemIOU : neither account nor issuer is XRP");
2988 XRPL_ASSERT(issue == amount.issue(),
"ripple::redeemIOU : matching issue");
2992 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2994 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2995 << amount.getFullText();
2997 bool bSenderHigh = account > issue.
account;
3002 STAmount final_balance = state->getFieldAmount(sfBalance);
3007 STAmount const start_balance = final_balance;
3009 final_balance -= amount;
3012 view, state, bSenderHigh, account, start_balance, final_balance, j);
3022 state->setFieldAmount(sfBalance, final_balance);
3029 bSenderHigh ? issue.
account : account,
3030 bSenderHigh ? account : issue.
account,
3042 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
3043 <<
" attempts to redeem " << amount.getFullText()
3044 <<
" but no trust line exists!";
3059 from != beast::zero,
"ripple::transferXRP : nonzero from account");
3060 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
3061 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
3062 XRPL_ASSERT(amount.native(),
"ripple::transferXRP : amount is XRP");
3066 if (!sender || !receiver)
3069 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
3070 << to_string(to) <<
") : " << amount.getFullText();
3072 if (sender->getFieldAmount(sfBalance) < amount)
3084 sender->setFieldAmount(
3085 sfBalance, sender->getFieldAmount(sfBalance) - amount);
3088 receiver->setFieldAmount(
3089 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
3105 auto const trustLine =
3108 if (!trustLine && authType == AuthType::StrongAuth)
3113 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
3117 return ((*trustLine)[sfFlags] &
3135 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3136 auto const sleIssuance = view.
read(mptID);
3140 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
3143 if (mptIssuer == account)
3146 bool const featureSAVEnabled =
3149 if (featureSAVEnabled)
3155 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
3159 if (sleIssuer->isFieldPresent(sfVaultID))
3161 auto const sleVault =
3162 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
3166 auto const asset = sleVault->at(sfAsset);
3170 return requireAuth(view, issue, account, authType);
3173 view, issue, account, authType, depth + 1);
3181 auto const mptokenID = keylet::mptoken(mptID.key, account);
3182 auto const sleToken = view.
read(mptokenID);
3186 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
3191 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3196 "ripple::requireAuth : issuance requires authorization");
3198 if (
auto const ter =
3199 credentials::validDomain(view, *maybeDomainID, account);
3208 if (featureSAVEnabled)
3226 MPTID const& mptIssuanceID,
3231 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
3237 "ripple::enforceMPTokenAuthorization : authorization required");
3239 if (account == sleIssuance->at(sfIssuer))
3242 auto const keylet = keylet::mptoken(mptIssuanceID, account);
3243 auto const sleToken = view.
read(keylet);
3244 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3246 bool const authorizedByDomain = [&]() ->
bool {
3248 if (!maybeDomainID.has_value())
3259 if (!authorizedByDomain && sleToken ==
nullptr)
3270 else if (!authorizedByDomain && maybeDomainID.has_value())
3277 else if (!authorizedByDomain)
3282 sleToken !=
nullptr && !maybeDomainID.has_value(),
3283 "ripple::enforceMPTokenAuthorization : found MPToken");
3289 else if (authorizedByDomain && sleToken !=
nullptr)
3294 maybeDomainID.has_value(),
3295 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
3298 else if (authorizedByDomain)
3303 maybeDomainID.has_value() && sleToken ==
nullptr,
3304 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
3319 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
3331 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3332 auto const sleIssuance = view.
read(mptID);
3338 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
3354 auto const& issuerId = issue.
getIssuer();
3355 if (issuerId == from || issuerId == to)
3357 auto const sleIssuer = view.
read(keylet::account(issuerId));
3358 if (sleIssuer ==
nullptr)
3361 auto const isRippleDisabled = [&](
AccountID account) ->
bool {
3364 auto const line = view.
read(keylet::line(account, issue));
3367 bool const issuerHigh = issuerId > account;
3374 if (isRippleDisabled(from) && isRippleDisabled(to))
3383 Keylet const& ownerDirKeylet,
3390 unsigned int uDirEntry{0};
3391 uint256 dirEntry{beast::zero};
3394 if (view.
exists(ownerDirKeylet) &&
3395 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
3399 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
3403 auto sleItem = view.
peek(keylet::child(dirEntry));
3409 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
3410 <<
" has index to object that is missing: "
3411 << to_string(dirEntry);
3417 sleItem->getFieldU16(sfLedgerEntryType))};
3421 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
3443 "ripple::cleanupOnAccountDelete : minimum dir entries");
3448 <<
"DeleteAccount iterator re-validation failed.";
3452 if (skipEntry == SkipEntry::No)
3456 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
3469 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
3473 sleState->getFieldAmount(sfLowLimit).getIssuer(),
3474 sleState->getFieldAmount(sfHighLimit).getIssuer());
3475 auto sleLow = view.
peek(keylet::account(low));
3476 auto sleHigh = view.
peek(keylet::account(high));
3477 if (!sleLow || !sleHigh)
3480 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
3481 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
3484 if (ammLow && ammHigh)
3488 if (!ammLow && !ammHigh)
3492 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
3495 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
3499 <<
"deleteAMMTrustLine: failed to delete the trustline.";
3504 if (!(sleState->getFlags() & uFlags))
3526 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
3532 "ripple::rippleCredit : not checking issuer");
3534 view, uSenderID, uReceiverID, saAmount, j);
3548 "ripple::assetsToSharesDeposit : non-negative assets");
3550 assets.
asset() == vault->at(sfAsset),
3551 "ripple::assetsToSharesDeposit : assets and vault match");
3552 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3555 Number const assetTotal = vault->at(sfAssetsTotal);
3556 STAmount shares{vault->at(sfShareMPTID)};
3557 if (assetTotal == 0)
3563 Number const shareTotal = issuance->at(sfOutstandingAmount);
3564 shares = ((shareTotal * assets) / assetTotal).truncate();
3576 "ripple::sharesToAssetsDeposit : non-negative shares");
3578 shares.
asset() == vault->at(sfShareMPTID),
3579 "ripple::sharesToAssetsDeposit : shares and vault match");
3580 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3583 Number const assetTotal = vault->at(sfAssetsTotal);
3584 STAmount assets{vault->at(sfAsset)};
3585 if (assetTotal == 0)
3589 shares.
exponent() - vault->at(sfScale),
3592 Number const shareTotal = issuance->at(sfOutstandingAmount);
3593 assets = (assetTotal * shares) / shareTotal;
3606 "ripple::assetsToSharesDeposit : non-negative assets");
3608 assets.
asset() == vault->at(sfAsset),
3609 "ripple::assetsToSharesWithdraw : assets and vault match");
3610 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3613 Number assetTotal = vault->at(sfAssetsTotal);
3614 assetTotal -= vault->at(sfLossUnrealized);
3615 STAmount shares{vault->at(sfShareMPTID)};
3616 if (assetTotal == 0)
3618 Number const shareTotal = issuance->at(sfOutstandingAmount);
3619 Number result = (shareTotal * assets) / assetTotal;
3620 if (truncate == TruncateShares::yes)
3634 "ripple::sharesToAssetsDeposit : non-negative shares");
3636 shares.
asset() == vault->at(sfShareMPTID),
3637 "ripple::sharesToAssetsWithdraw : shares and vault match");
3638 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3641 Number assetTotal = vault->at(sfAssetsTotal);
3642 assetTotal -= vault->at(sfLossUnrealized);
3643 STAmount assets{vault->at(sfAsset)};
3644 if (assetTotal == 0)
3646 Number const shareTotal = issuance->at(sfOutstandingAmount);
3647 assets = (assetTotal * shares) / shareTotal;
3658 auto const mptIssue = amount.get<
MPTIssue>();
3659 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3660 auto sleIssuance = view.
peek(mptID);
3663 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
3664 << mptIssue.getMptID();
3668 if (amount.getIssuer() == sender)
3671 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3678 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3679 auto sle = view.
peek(mptokenID);
3683 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3687 auto const amt = sle->getFieldU64(sfMPTAmount);
3688 auto const pay = amount.mpt().value();
3694 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3695 << to_string(sender) <<
": " << amt <<
" < " << pay;
3699 (*sle)[sfMPTAmount] = amt - pay;
3702 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3707 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3708 << to_string(sender) <<
": " << locked <<
" + " << pay;
3712 if (sle->isFieldPresent(sfLockedAmount))
3713 (*sle)[sfLockedAmount] += pay;
3715 sle->setFieldU64(sfLockedAmount, pay);
3723 uint64_t
const issuanceEscrowed =
3724 (*sleIssuance)[~sfLockedAmount].value_or(0);
3725 auto const pay = amount.mpt().value();
3731 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3732 "locked amount for "
3733 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3738 if (sleIssuance->isFieldPresent(sfLockedAmount))
3739 (*sleIssuance)[sfLockedAmount] += pay;
3741 sleIssuance->setFieldU64(sfLockedAmount, pay);
3743 view.
update(sleIssuance);
3759 netAmount == grossAmount,
3760 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3762 auto const& issuer = netAmount.
getIssuer();
3764 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3765 auto sleIssuance = view.
peek(mptID);
3768 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3769 << mptIssue.getMptID();
3775 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3778 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3779 << mptIssue.getMptID();
3783 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3784 auto const redeem = grossAmount.
mpt().
value();
3791 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3792 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3796 auto const newLocked = locked - redeem;
3798 sleIssuance->makeFieldAbsent(sfLockedAmount);
3800 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3801 view.
update(sleIssuance);
3804 if (issuer != receiver)
3807 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3808 auto sle = view.
peek(mptokenID);
3812 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3816 auto current = sle->getFieldU64(sfMPTAmount);
3817 auto delta = netAmount.
mpt().
value();
3823 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3824 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3828 (*sle)[sfMPTAmount] += delta;
3834 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3835 auto const redeem = netAmount.
mpt().
value();
3842 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3843 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3848 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3849 view.
update(sleIssuance);
3852 if (issuer == sender)
3854 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3855 "cannot unlock MPTs.";
3861 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3862 auto sle = view.
peek(mptokenID);
3866 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3870 if (!sle->isFieldPresent(sfLockedAmount))
3873 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3874 << to_string(sender);
3878 auto const locked = sle->getFieldU64(sfLockedAmount);
3879 auto const delta = grossAmount.
mpt().
value();
3885 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3886 << to_string(sender) <<
": " << locked <<
" < " << delta;
3890 auto const newLocked = locked - delta;
3892 sle->makeFieldAbsent(sfLockedAmount);
3894 sle->setFieldU64(sfLockedAmount, newLocked);
3905 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3911 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3912 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3916 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3917 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.
AccountID const & getIssuer() const
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)
static int const cMaxOffset
Currency const & getCurrency() const
bool negative() const noexcept
AccountID const & getIssuer() const
static constexpr std::uint64_t cMaxValue
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 > const_pointer
std::shared_ptr< STLedgerEntry > const & ref
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 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.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
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.
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!...
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)
static TER accountSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
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)
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
FreezeHandling
Controls the treatment of frozen account balances.
static TER rippleSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Validates that the destination SLE and tag are valid.
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)
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, 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)
static SLE::const_pointer getLineIfUsable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
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.
TER canWithdraw(AccountID const &from, ReadView const &view, AccountID const &to, SLE::const_ref toSle, bool hasDestinationTag)
Checks that can withdraw funds from an object to itself or a destination.
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.
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
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.
static TER rippleSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
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)
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
static TER accountSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
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.
static STAmount getTrustLineBalance(ReadView const &view, SLE::const_ref sle, AccountID const &account, Currency const ¤cy, AccountID const &issuer, bool includeOppositeLimit, beast::Journal j)
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
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.
STAmount accountSpendable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
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.
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)