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.
header().
hash))
919 JLOG(s) << reason <<
" incompatible with valid ledger";
921 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
933 if (hash && (*hash != testLedger.
header().
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.
header().
seq <<
" "
957 JLOG(s) <<
"New: " << testLedger.
header().
seq <<
" "
974 if (testLedger.
header().
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.
header().
seq) &&
993 JLOG(s) << reason <<
" incompatible ledger";
1000 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
1002 JLOG(s) <<
"New: " << testLedger.
header().
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())
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);
1185 rsh(hash.data(), hash.size());
1208 "ripple::getPseudoAccountFields : unable to find account root "
1213 auto const& soTemplate = ar->getSOTemplate();
1216 for (
auto const& field : soTemplate)
1221 return pseudoFields;
1223 return pseudoFields;
1235 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1239 [&sleAcct, &pseudoFieldFilter](
SField const* sf) ->
bool {
1240 return sleAcct->isFieldPresent(*sf) &&
1241 (pseudoFieldFilter.empty() ||
1242 pseudoFieldFilter.contains(sf));
1246Expected<std::shared_ptr<SLE>,
TER>
1249 uint256 const& pseudoOwnerKey,
1250 SField const& ownerField)
1258 [&ownerField](
SField const* sf) ->
bool {
1259 return *sf == ownerField;
1261 "ripple::createPseudoAccount : valid owner field");
1264 if (accountId == beast::zero)
1269 account->setAccountID(sfAccount, accountId);
1270 account->setFieldAmount(sfBalance,
STAmount{});
1280 account->setFieldU32(sfSequence, seqno);
1284 account->setFieldU32(
1287 account->setFieldH256(ownerField, pseudoOwnerKey);
1335 if (toSle ==
nullptr)
1352 bool hasDestinationTag)
1374 bool hasDestinationTag)
1378 return canWithdraw(from, view, to, toSle, hasDestinationTag);
1384 auto const from = tx[sfAccount];
1385 auto const to = tx[~sfDestination].value_or(from);
1402 if (dstAcct == senderAcct)
1405 view, senderAcct, priorBalance, amount.asset(), j);
1427 JLOG(j.
error()) <<
"LoanBrokerCoverWithdraw: negative balance of "
1428 "broker cover assets.";
1451 auto const& issuerId = issue.
getIssuer();
1452 auto const& currency = issue.
currency;
1456 auto const& srcId = issuerId;
1457 auto const& dstId = accountID;
1458 auto const high = srcId > dstId;
1459 auto const index =
keylet::line(srcId, dstId, currency);
1462 if (!sleDst || !sleSrc)
1467 if (view.
read(index))
1486 STAmount{Issue{currency, noAccount()}},
1487 STAmount{Issue{currency, dstId}},
1501 auto const& mptID = mptIssue.
getMptID();
1502 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1507 if (view.
peek(keylet::mptoken(mptID, accountID)))
1519 MPTID const& mptIssuanceID,
1525 auto const sleAcct = view.
peek(keylet::account(account));
1539 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1540 auto const sleMpt = view.
peek(mptokenKey);
1541 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1545 keylet::ownerDir(account),
1546 (*sleMpt)[sfOwnerNode],
1566 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1568 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1571 if (priorBalance < reserveCreate)
1575 auto const mpt = view.
read(keylet::mptIssuance(mptIssuanceID));
1576 if (!mpt || mpt->getAccountID(sfIssuer) == account)
1580 "ripple::authorizeMPToken : invalid issuance or issuers token");
1586 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1588 if (
auto ter =
dirLink(view, account, mptoken))
1591 (*mptoken)[sfAccount] = account;
1592 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1593 (*mptoken)[sfFlags] = 0;
1602 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1603 if (!sleMptIssuance)
1609 if (account != (*sleMptIssuance)[sfIssuer])
1612 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1622 flagsOut &= ~lsfMPTAuthorized;
1628 if (flagsIn != flagsOut)
1629 sleMpt->setFieldU32(sfFlags, flagsOut);
1638 bool const bSrcHigh,
1644 bool const bNoRipple,
1655 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1656 << to_string(uDstAccountID) <<
", "
1659 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1660 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1661 if (uLowAccountID == uHighAccountID)
1664 UNREACHABLE(
"ripple::trustCreate : trust line to self");
1671 view.
insert(sleRippleState);
1674 keylet::ownerDir(uLowAccountID),
1675 sleRippleState->key(),
1682 keylet::ownerDir(uHighAccountID),
1683 sleRippleState->key(),
1689 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1690 bool const bSetHigh = bSrcHigh ^ bSetDst;
1692 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1697 sleAccount->getAccountID(sfAccount) ==
1698 (bSetHigh ? uHighAccountID : uLowAccountID),
1699 "ripple::trustCreate : matching account ID");
1700 auto const slePeer =
1701 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1706 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1707 sleRippleState->setFieldU64(sfHighNode, *highNode);
1709 sleRippleState->setFieldAmount(
1710 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1711 sleRippleState->setFieldAmount(
1712 bSetHigh ? sfLowLimit : sfHighLimit,
1714 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1717 sleRippleState->setFieldU32(
1718 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1721 sleRippleState->setFieldU32(
1722 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1749 sleRippleState->setFieldU32(sfFlags, uFlags);
1753 sleRippleState->setFieldAmount(
1754 sfBalance, bSetHigh ? -saBalance : saBalance);
1757 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1771 auto const sle = view.
read(keylet::account(accountID));
1775 auto const balance = sle->getFieldAmount(sfBalance);
1776 if (balance.xrp() != 0)
1785 bool const accountIsIssuer = accountID == issue.
account;
1786 auto const line = view.
peek(keylet::line(accountID, issue));
1789 if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::zero)
1796 auto sleLowAccount =
1797 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1811 auto sleHighAccount =
1812 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1813 if (!sleHighAccount)
1826 line->at(sfLowLimit)->getIssuer(),
1827 line->at(sfHighLimit)->getIssuer(),
1841 bool const accountIsIssuer = accountID == mptIssue.
getIssuer();
1842 auto const& mptID = mptIssue.
getMptID();
1843 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1850 if (mptoken->at(sfMPTAmount) != 0)
1872 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1873 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1875 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1878 keylet::ownerDir(uLowAccountID),
1880 sleRippleState->key(),
1886 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1889 keylet::ownerDir(uHighAccountID),
1891 sleRippleState->key(),
1897 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1898 view.
erase(sleRippleState);
1908 auto offerIndex = sle->key();
1909 auto owner = sle->getAccountID(sfAccount);
1912 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1915 keylet::ownerDir(owner),
1916 sle->getFieldU64(sfOwnerNode),
1924 keylet::page(uDirectory),
1925 sle->getFieldU64(sfBookNode),
1932 if (sle->isFieldPresent(sfAdditionalBooks))
1935 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1936 "ripple::offerDelete : should be a hybrid domain offer");
1938 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1940 for (
auto const& bookDir : additionalBookDirs)
1942 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1943 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1946 keylet::page(dirIndex), dirNode, offerIndex,
false))
1978 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1979 "ripple::rippleCreditIOU : matching issuer or don't care");
1984 uSenderID != uReceiverID,
1985 "ripple::rippleCreditIOU : sender is not receiver");
1987 bool const bSenderHigh = uSenderID > uReceiverID;
1988 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1992 "ripple::rippleCreditIOU : sender is not XRP");
1995 "ripple::rippleCreditIOU : receiver is not XRP");
1998 if (
auto const sleRippleState = view.
peek(index))
2000 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
2005 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
2007 STAmount const saBefore = saBalance;
2009 saBalance -= saAmount;
2011 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
2012 << to_string(uReceiverID)
2017 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
2018 bool bDelete =
false;
2022 if (saBefore > beast::zero
2024 && saBalance <= beast::zero
2032 view.
read(keylet::account(uSenderID))->getFlags() &
2035 !sleRippleState->getFieldAmount(
2036 !bSenderHigh ? sfLowLimit : sfHighLimit)
2038 && !sleRippleState->getFieldU32(
2039 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2041 && !sleRippleState->getFieldU32(
2042 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2047 view, view.
peek(keylet::account(uSenderID)), -1, j);
2050 sleRippleState->setFieldU32(
2052 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2055 bDelete = !saBalance
2064 sleRippleState->setFieldAmount(sfBalance, saBalance);
2072 bSenderHigh ? uReceiverID : uSenderID,
2073 !bSenderHigh ? uReceiverID : uSenderID,
2077 view.
update(sleRippleState);
2081 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
2086 JLOG(j.
debug()) <<
"rippleCreditIOU: "
2088 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
2091 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
2128 auto const& issuer = saAmount.
getIssuer();
2132 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
2134 uSenderID != uReceiverID,
2135 "ripple::rippleSendIOU : sender is not receiver");
2137 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
2144 saActual = saAmount;
2152 saActual = (waiveFee == WaiveTransferFee::Yes)
2156 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
2157 << to_string(uReceiverID)
2165 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
2186 !
isXRP(senderID),
"ripple::rippleSendMultiIOU : sender is not XRP");
2190 actual = takeFromSender;
2193 for (
auto const& r : receivers)
2195 auto const& receiverID = r.first;
2201 if (!amount || (senderID == receiverID))
2206 "ripple::rippleSendMultiIOU : receiver is not XRP");
2208 if (senderID == issuer || receiverID == issuer || issuer ==
noAccount())
2212 view, senderID, receiverID, amount,
false, j))
2225 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2228 actual += actualSend;
2229 takeFromSender += actualSend;
2231 JLOG(j.
debug()) <<
"rippleSendMultiIOU> " << to_string(senderID)
2232 <<
" - > " << to_string(receiverID)
2233 <<
" : deliver=" << amount.getFullText()
2236 if (
TER const terResult =
2241 if (senderID != issuer && takeFromSender)
2244 view, senderID, issuer, takeFromSender,
true, j))
2272 "ripple::accountSendIOU : minimum amount and not MPT");
2279 if (!saAmount || (uSenderID == uReceiverID))
2286 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
2287 << to_string(uReceiverID) <<
" : "
2291 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2302 ? view.
peek(keylet::account(uSenderID))
2305 ? view.
peek(keylet::account(uReceiverID))
2308 if (
auto stream = j.
trace())
2314 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2317 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2319 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
2320 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2321 << receiver_bal <<
") : " << saAmount.
getFullText();
2326 if (sender->getFieldAmount(sfBalance) < saAmount)
2337 auto const sndBal = sender->getFieldAmount(sfBalance);
2341 sender->setFieldAmount(sfBalance, sndBal - saAmount);
2349 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2350 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2356 if (
auto stream = j.
trace())
2362 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2365 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2367 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2368 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2369 << receiver_bal <<
") : " << saAmount.
getFullText();
2385 receivers.
size() > 1,
2386 "ripple::accountSendMultiIOU",
2387 "multiple recipients provided");
2392 JLOG(j.
trace()) <<
"accountSendMultiIOU: " << to_string(senderID)
2393 <<
" sending " << receivers.
size() <<
" IOUs";
2396 view, senderID, issue, receivers, actual, j, waiveFee);
2406 ? view.
peek(keylet::account(senderID))
2409 if (
auto stream = j.
trace())
2414 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2416 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" ("
2417 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2422 for (
auto const& r : receivers)
2424 auto const& receiverID = r.first;
2427 if (amount < beast::zero)
2435 if (!amount || (senderID == receiverID))
2439 ? view.
peek(keylet::account(receiverID))
2442 if (
auto stream = j.
trace())
2448 receiver->getFieldAmount(sfBalance).getFullText();
2450 stream <<
"accountSendMultiIOU> " << to_string(senderID) <<
" -> "
2451 << to_string(receiverID) <<
" (" << receiver_bal
2452 <<
") : " << amount.getFullText();
2458 auto const rcvBal = receiver->getFieldAmount(sfBalance);
2459 receiver->setFieldAmount(sfBalance, rcvBal + amount);
2465 takeFromSender += amount;
2468 if (
auto stream = j.
trace())
2474 receiver->getFieldAmount(sfBalance).getFullText();
2476 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" -> "
2477 << to_string(receiverID) <<
" (" << receiver_bal
2478 <<
") : " << amount.getFullText();
2484 if (sender->getFieldAmount(sfBalance) < takeFromSender)
2490 auto const sndBal = sender->getFieldAmount(sfBalance);
2494 sender->setFieldAmount(sfBalance, sndBal - takeFromSender);
2499 if (
auto stream = j.
trace())
2505 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2507 stream <<
"accountSendMultiIOU< " << to_string(senderID) <<
" ("
2508 << sender_bal <<
") -> " << receivers.
size() <<
" receivers.";
2523 auto const& issuer = saAmount.
getIssuer();
2524 auto sleIssuance = view.
peek(mptID);
2527 if (uSenderID == issuer)
2529 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2530 view.
update(sleIssuance);
2534 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2535 if (
auto sle = view.
peek(mptokenID))
2537 auto const amt = sle->getFieldU64(sfMPTAmount);
2538 auto const pay = saAmount.
mpt().
value();
2541 (*sle)[sfMPTAmount] = amt - pay;
2548 if (uReceiverID == issuer)
2550 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2551 auto const redeem = saAmount.
mpt().
value();
2552 if (outstanding >= redeem)
2554 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2555 view.
update(sleIssuance);
2562 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2563 if (
auto sle = view.
peek(mptokenID))
2565 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2586 uSenderID != uReceiverID,
2587 "ripple::rippleSendMPT : sender is not receiver");
2590 auto const& issuer = saAmount.
getIssuer();
2597 if (uSenderID == issuer || uReceiverID == issuer)
2601 if (uSenderID == issuer)
2603 auto const sendAmount = saAmount.
mpt().
value();
2604 auto const maximumAmount =
2606 if (sendAmount > maximumAmount ||
2607 sle->getFieldU64(sfOutstandingAmount) >
2608 maximumAmount - sendAmount)
2617 saActual = saAmount;
2622 saActual = (waiveFee == WaiveTransferFee::Yes)
2628 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2629 << to_string(uReceiverID)
2633 if (
auto const terResult =
2653 auto const& issuer = mptIssue.
getIssuer();
2655 auto const sle = view.
read(keylet::mptIssuance(mptIssue.
getMptID()));
2661 actual = takeFromSender;
2663 for (
auto const& r : receivers)
2665 auto const& receiverID = r.first;
2666 STAmount amount{mptIssue, r.second};
2668 if (amount < beast::zero)
2676 if (!amount || (senderID == receiverID))
2679 if (senderID == issuer || receiverID == issuer)
2683 if (senderID == issuer)
2686 takeFromSender == beast::zero,
2687 "rippler::rippleSendMultiMPT",
2688 "sender == issuer, takeFromSender == zero");
2689 auto const sendAmount = amount.mpt().value();
2690 auto const maximumAmount =
2692 if (sendAmount > maximumAmount ||
2693 sle->getFieldU64(sfOutstandingAmount) >
2694 maximumAmount - sendAmount)
2699 if (
auto const ter =
2710 STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
2715 actual += actualSend;
2716 takeFromSender += actualSend;
2718 JLOG(j.
debug()) <<
"rippleSendMultiMPT> " << to_string(senderID)
2719 <<
" - > " << to_string(receiverID)
2720 <<
" : deliver=" << amount.getFullText()
2723 if (
auto const terResult =
2727 if (senderID != issuer && takeFromSender)
2729 if (
TER const terResult =
2748 "ripple::accountSendMPT : minimum amount and MPT");
2753 if (!saAmount || (uSenderID == uReceiverID))
2759 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2774 view, senderID, mptIssue, receivers, actual, j, waiveFee);
2790 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2793 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2808 receivers.
size() > 1,
2809 "ripple::accountSendMulti",
2810 "multiple recipients provided");
2815 view, senderID, issue, receivers, j, waiveFee);
2818 view, senderID, issue, receivers, j, waiveFee);
2837 auto sle = view.
peek(keylet::account(sender));
2842 if (before > beast::zero
2844 &&
after <= beast::zero
2848 &&
static_cast<bool>(
2852 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2854 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2857 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2866 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2886 "ripple::issueIOU : neither account nor issuer is XRP");
2889 XRPL_ASSERT(issue == amount.issue(),
"ripple::issueIOU : matching issue");
2893 issue.
account != account,
"ripple::issueIOU : not issuer account");
2895 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2896 << amount.getFullText();
2898 bool bSenderHigh = issue.
account > account;
2900 auto const index = keylet::line(issue.
account, account, issue.
currency);
2902 if (
auto state = view.
peek(index))
2904 STAmount final_balance = state->getFieldAmount(sfBalance);
2909 STAmount const start_balance = final_balance;
2911 final_balance -= amount;
2930 state->setFieldAmount(sfBalance, final_balance);
2935 bSenderHigh ? account : issue.
account,
2936 bSenderHigh ? issue.
account : account,
2952 auto const receiverAccount = view.
peek(keylet::account(account));
2953 if (!receiverAccount)
2986 "ripple::redeemIOU : neither account nor issuer is XRP");
2989 XRPL_ASSERT(issue == amount.issue(),
"ripple::redeemIOU : matching issue");
2993 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2995 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2996 << amount.getFullText();
2998 bool bSenderHigh = account > issue.
account;
3003 STAmount final_balance = state->getFieldAmount(sfBalance);
3008 STAmount const start_balance = final_balance;
3010 final_balance -= amount;
3013 view, state, bSenderHigh, account, start_balance, final_balance, j);
3023 state->setFieldAmount(sfBalance, final_balance);
3030 bSenderHigh ? issue.
account : account,
3031 bSenderHigh ? account : issue.
account,
3043 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
3044 <<
" attempts to redeem " << amount.getFullText()
3045 <<
" but no trust line exists!";
3060 from != beast::zero,
"ripple::transferXRP : nonzero from account");
3061 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
3062 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
3063 XRPL_ASSERT(amount.native(),
"ripple::transferXRP : amount is XRP");
3067 if (!sender || !receiver)
3070 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
3071 << to_string(to) <<
") : " << amount.getFullText();
3073 if (sender->getFieldAmount(sfBalance) < amount)
3085 sender->setFieldAmount(
3086 sfBalance, sender->getFieldAmount(sfBalance) - amount);
3089 receiver->setFieldAmount(
3090 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
3106 auto const trustLine =
3109 if (!trustLine && authType == AuthType::StrongAuth)
3114 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
3118 return ((*trustLine)[sfFlags] &
3136 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3137 auto const sleIssuance = view.
read(mptID);
3141 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
3144 if (mptIssuer == account)
3147 bool const featureSAVEnabled =
3150 if (featureSAVEnabled)
3156 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
3160 if (sleIssuer->isFieldPresent(sfVaultID))
3162 auto const sleVault =
3163 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
3167 auto const asset = sleVault->at(sfAsset);
3171 return requireAuth(view, issue, account, authType);
3174 view, issue, account, authType, depth + 1);
3182 auto const mptokenID = keylet::mptoken(mptID.key, account);
3183 auto const sleToken = view.
read(mptokenID);
3187 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
3192 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3197 "ripple::requireAuth : issuance requires authorization");
3199 if (
auto const ter =
3200 credentials::validDomain(view, *maybeDomainID, account);
3209 if (featureSAVEnabled)
3227 MPTID const& mptIssuanceID,
3232 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
3238 "ripple::enforceMPTokenAuthorization : authorization required");
3240 if (account == sleIssuance->at(sfIssuer))
3243 auto const keylet = keylet::mptoken(mptIssuanceID, account);
3244 auto const sleToken = view.
read(keylet);
3245 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
3247 bool const authorizedByDomain = [&]() ->
bool {
3249 if (!maybeDomainID.has_value())
3260 if (!authorizedByDomain && sleToken ==
nullptr)
3271 else if (!authorizedByDomain && maybeDomainID.has_value())
3278 else if (!authorizedByDomain)
3283 sleToken !=
nullptr && !maybeDomainID.has_value(),
3284 "ripple::enforceMPTokenAuthorization : found MPToken");
3290 else if (authorizedByDomain && sleToken !=
nullptr)
3295 maybeDomainID.has_value(),
3296 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
3299 else if (authorizedByDomain)
3304 maybeDomainID.has_value() && sleToken ==
nullptr,
3305 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
3320 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
3332 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
3333 auto const sleIssuance = view.
read(mptID);
3339 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
3355 auto const& issuerId = issue.
getIssuer();
3356 if (issuerId == from || issuerId == to)
3358 auto const sleIssuer = view.
read(keylet::account(issuerId));
3359 if (sleIssuer ==
nullptr)
3362 auto const isRippleDisabled = [&](
AccountID account) ->
bool {
3365 auto const line = view.
read(keylet::line(account, issue));
3368 bool const issuerHigh = issuerId > account;
3375 if (isRippleDisabled(from) && isRippleDisabled(to))
3384 Keylet const& ownerDirKeylet,
3391 unsigned int uDirEntry{0};
3392 uint256 dirEntry{beast::zero};
3395 if (view.
exists(ownerDirKeylet) &&
3396 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
3400 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
3404 auto sleItem = view.
peek(keylet::child(dirEntry));
3410 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
3411 <<
" has index to object that is missing: "
3412 << to_string(dirEntry);
3418 sleItem->getFieldU16(sfLedgerEntryType))};
3422 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
3444 "ripple::cleanupOnAccountDelete : minimum dir entries");
3449 <<
"DeleteAccount iterator re-validation failed.";
3453 if (skipEntry == SkipEntry::No)
3457 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
3470 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
3474 sleState->getFieldAmount(sfLowLimit).getIssuer(),
3475 sleState->getFieldAmount(sfHighLimit).getIssuer());
3476 auto sleLow = view.
peek(keylet::account(low));
3477 auto sleHigh = view.
peek(keylet::account(high));
3478 if (!sleLow || !sleHigh)
3481 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
3482 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
3485 if (ammLow && ammHigh)
3489 if (!ammLow && !ammHigh)
3493 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
3496 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
3500 <<
"deleteAMMTrustLine: failed to delete the trustline.";
3505 if (!(sleState->getFlags() & uFlags))
3527 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
3533 "ripple::rippleCredit : not checking issuer");
3535 view, uSenderID, uReceiverID, saAmount, j);
3549 "ripple::assetsToSharesDeposit : non-negative assets");
3551 assets.
asset() == vault->at(sfAsset),
3552 "ripple::assetsToSharesDeposit : assets and vault match");
3553 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3556 Number const assetTotal = vault->at(sfAssetsTotal);
3557 STAmount shares{vault->at(sfShareMPTID)};
3558 if (assetTotal == 0)
3564 Number const shareTotal = issuance->at(sfOutstandingAmount);
3565 shares = ((shareTotal * assets) / assetTotal).truncate();
3577 "ripple::sharesToAssetsDeposit : non-negative shares");
3579 shares.
asset() == vault->at(sfShareMPTID),
3580 "ripple::sharesToAssetsDeposit : shares and vault match");
3581 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3584 Number const assetTotal = vault->at(sfAssetsTotal);
3585 STAmount assets{vault->at(sfAsset)};
3586 if (assetTotal == 0)
3590 shares.
exponent() - vault->at(sfScale),
3593 Number const shareTotal = issuance->at(sfOutstandingAmount);
3594 assets = (assetTotal * shares) / shareTotal;
3607 "ripple::assetsToSharesDeposit : non-negative assets");
3609 assets.
asset() == vault->at(sfAsset),
3610 "ripple::assetsToSharesWithdraw : assets and vault match");
3611 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3614 Number assetTotal = vault->at(sfAssetsTotal);
3615 assetTotal -= vault->at(sfLossUnrealized);
3616 STAmount shares{vault->at(sfShareMPTID)};
3617 if (assetTotal == 0)
3619 Number const shareTotal = issuance->at(sfOutstandingAmount);
3620 Number result = (shareTotal * assets) / assetTotal;
3621 if (truncate == TruncateShares::yes)
3635 "ripple::sharesToAssetsDeposit : non-negative shares");
3637 shares.
asset() == vault->at(sfShareMPTID),
3638 "ripple::sharesToAssetsWithdraw : shares and vault match");
3639 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3642 Number assetTotal = vault->at(sfAssetsTotal);
3643 assetTotal -= vault->at(sfLossUnrealized);
3644 STAmount assets{vault->at(sfAsset)};
3645 if (assetTotal == 0)
3647 Number const shareTotal = issuance->at(sfOutstandingAmount);
3648 assets = (assetTotal * shares) / shareTotal;
3659 auto const mptIssue = amount.get<
MPTIssue>();
3660 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3661 auto sleIssuance = view.
peek(mptID);
3664 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
3665 << mptIssue.getMptID();
3669 if (amount.getIssuer() == sender)
3672 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3679 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3680 auto sle = view.
peek(mptokenID);
3684 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3688 auto const amt = sle->getFieldU64(sfMPTAmount);
3689 auto const pay = amount.mpt().value();
3695 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3696 << to_string(sender) <<
": " << amt <<
" < " << pay;
3700 (*sle)[sfMPTAmount] = amt - pay;
3703 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3708 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3709 << to_string(sender) <<
": " << locked <<
" + " << pay;
3713 if (sle->isFieldPresent(sfLockedAmount))
3714 (*sle)[sfLockedAmount] += pay;
3716 sle->setFieldU64(sfLockedAmount, pay);
3724 uint64_t
const issuanceEscrowed =
3725 (*sleIssuance)[~sfLockedAmount].value_or(0);
3726 auto const pay = amount.mpt().value();
3732 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3733 "locked amount for "
3734 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3739 if (sleIssuance->isFieldPresent(sfLockedAmount))
3740 (*sleIssuance)[sfLockedAmount] += pay;
3742 sleIssuance->setFieldU64(sfLockedAmount, pay);
3744 view.
update(sleIssuance);
3760 netAmount == grossAmount,
3761 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3763 auto const& issuer = netAmount.
getIssuer();
3765 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3766 auto sleIssuance = view.
peek(mptID);
3769 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3770 << mptIssue.getMptID();
3776 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3779 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3780 << mptIssue.getMptID();
3784 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3785 auto const redeem = grossAmount.
mpt().
value();
3792 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3793 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3797 auto const newLocked = locked - redeem;
3799 sleIssuance->makeFieldAbsent(sfLockedAmount);
3801 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3802 view.
update(sleIssuance);
3805 if (issuer != receiver)
3808 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3809 auto sle = view.
peek(mptokenID);
3813 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3817 auto current = sle->getFieldU64(sfMPTAmount);
3818 auto delta = netAmount.
mpt().
value();
3824 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3825 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3829 (*sle)[sfMPTAmount] += delta;
3835 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3836 auto const redeem = netAmount.
mpt().
value();
3843 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3844 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3849 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3850 view.
update(sleIssuance);
3853 if (issuer == sender)
3855 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3856 "cannot unlock MPTs.";
3862 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3863 auto sle = view.
peek(mptokenID);
3867 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3871 if (!sle->isFieldPresent(sfLockedAmount))
3874 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3875 << to_string(sender);
3879 auto const locked = sle->getFieldU64(sfLockedAmount);
3880 auto const delta = grossAmount.
mpt().
value();
3886 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3887 << to_string(sender) <<
": " << locked <<
" < " << delta;
3891 auto const newLocked = locked - delta;
3893 sle->makeFieldAbsent(sfLockedAmount);
3895 sle->setFieldU64(sfLockedAmount, newLocked);
3906 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3912 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3913 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3917 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3918 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 LedgerHeader const & header() const =0
Returns information about the 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 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)