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 "xrpl::detail::internalDirNext : index inside range");
45 if (index >= svIndexes.size())
47 auto const next = page->getFieldU64(sfIndexNext);
60 XRPL_ASSERT(page,
"xrpl::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(
"xrpl::isVaultPseudoAccountFrozen : null MPToken issuer");
315 if (!mptIssuer->isFieldPresent(sfVaultID))
320 if (vault ==
nullptr)
322 UNREACHABLE(
"xrpl::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,
"xrpl::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;
764 XRPL_ASSERT(
root.type == ltDIR_NODE,
"xrpl::forEachItem : valid root type");
766 if (
root.type != ltDIR_NODE)
773 auto sle = view.
read(pos);
776 for (
auto const& key : sle->getFieldV256(sfIndexes))
778 auto const next = sle->getFieldU64(sfIndexNext);
795 root.type == ltDIR_NODE,
"xrpl::forEachItemAfter : valid root type");
797 if (
root.type != ltDIR_NODE)
800 auto currentIndex =
root;
803 if (
after.isNonZero())
807 if (
auto hintDir = view.
read(hintIndex))
809 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
814 currentIndex = hintIndex;
823 auto const ownerDir = view.
read(currentIndex);
826 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
839 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
849 auto const ownerDir = view.
read(currentIndex);
852 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
855 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
868 if (sle && sle->isFieldPresent(sfTransferRate))
869 return Rate{sle->getFieldU32(sfTransferRate)};
881 sle && sle->isFieldPresent(sfTransferFee))
882 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
897 amount.asset().value());
916 if (hash && (*hash != validLedger.
header().
hash))
918 JLOG(s) << reason <<
" incompatible with valid ledger";
920 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
932 if (hash && (*hash != testLedger.
header().
hash))
934 JLOG(s) << reason <<
" incompatible preceding ledger";
936 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
946 JLOG(s) << reason <<
" incompatible ledger";
953 JLOG(s) <<
"Val: " << validLedger.
header().
seq <<
" "
956 JLOG(s) <<
"New: " << testLedger.
header().
seq <<
" "
973 if (testLedger.
header().
seq > validIndex)
980 if (hash && (*hash != validHash))
982 JLOG(s) << reason <<
" incompatible following ledger";
983 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
989 (validIndex == testLedger.
header().
seq) &&
992 JLOG(s) << reason <<
" incompatible ledger";
999 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
1001 JLOG(s) <<
"New: " << testLedger.
header().
seq <<
" "
1011 auto const sleNode = view.
read(k);
1014 if (!sleNode->getFieldV256(sfIndexes).empty())
1019 return sleNode->getFieldU64(sfIndexNext) == 0;
1029 if (sle->isFieldPresent(sfAmendments))
1031 auto const& v = sle->getFieldV256(sfAmendments);
1032 amendments.insert(v.begin(), v.end());
1046 if (sle->isFieldPresent(sfMajorities))
1049 using d = tp::duration;
1051 auto const majorities = sle->getFieldArray(sfMajorities);
1053 for (
auto const& m : majorities)
1054 ret[m.getFieldH256(sfAmendment)] =
1055 tp(d(m.getFieldU32(sfCloseTime)));
1066 if (seq > ledger.
seq())
1068 JLOG(journal.
warn())
1069 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
1072 if (seq == ledger.
seq())
1074 if (seq == (ledger.
seq() - 1))
1077 if (
int diff = ledger.
seq() - seq; diff <= 256)
1084 hashIndex->getFieldU32(sfLastLedgerSequence) ==
1086 "xrpl::hashOfSeq : matching ledger sequence");
1087 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1088 if (vec.
size() >= diff)
1089 return vec[vec.
size() - diff];
1090 JLOG(journal.
warn())
1091 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
1092 <<
" (" << vec.
size() <<
"," << diff <<
")";
1096 JLOG(journal.
warn())
1098 <<
" missing normal list";
1102 if ((seq & 0xff) != 0)
1104 JLOG(journal.
debug())
1105 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1113 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1114 XRPL_ASSERT(lastSeq >= seq,
"xrpl::hashOfSeq : minimum last ledger");
1116 (lastSeq & 0xff) == 0,
"xrpl::hashOfSeq : valid last ledger");
1117 auto const diff = (lastSeq - seq) >> 8;
1118 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1119 if (vec.
size() > diff)
1120 return vec[vec.
size() - diff - 1];
1122 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1142 XRPL_ASSERT(amount,
"xrpl::adjustOwnerCount : nonzero amount input");
1147 sle->at(sfOwnerCount) = adjusted;
1155 (*sle)[sfOwner] = account;
1170 object->setFieldU64(node, *page);
1184 rsh(hash.data(), hash.size());
1207 "xrpl::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 "xrpl::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 "xrpl::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(
"xrpl::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,
"xrpl::trustCreate : non-null SLE");
1696 sleAccount->getAccountID(sfAccount) ==
1697 (bSetHigh ? uHighAccountID : uLowAccountID),
1698 "xrpl::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 "xrpl::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 "xrpl::rippleCreditIOU : matching issuer or don't care");
1983 uSenderID != uReceiverID,
1984 "xrpl::rippleCreditIOU : sender is not receiver");
1986 bool const bSenderHigh = uSenderID > uReceiverID;
1987 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1991 "xrpl::rippleCreditIOU : sender is not XRP");
1994 "xrpl::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 "xrpl::rippleSendIOU : neither sender nor receiver is XRP");
2133 uSenderID != uReceiverID,
2134 "xrpl::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),
"xrpl::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 "xrpl::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 "xrpl::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 "xrpl::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 "xrpl::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 "xrpl::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 "xrpl::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 "xrpl::issueIOU : neither account nor issuer is XRP");
2888 XRPL_ASSERT(issue == amount.issue(),
"xrpl::issueIOU : matching issue");
2892 issue.
account != account,
"xrpl::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 "xrpl::redeemIOU : neither account nor issuer is XRP");
2988 XRPL_ASSERT(issue == amount.issue(),
"xrpl::redeemIOU : matching issue");
2992 issue.
account != account,
"xrpl::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,
"xrpl::transferXRP : nonzero from account");
3060 XRPL_ASSERT(to != beast::zero,
"xrpl::transferXRP : nonzero to account");
3061 XRPL_ASSERT(from != to,
"xrpl::transferXRP : sender is not receiver");
3062 XRPL_ASSERT(amount.native(),
"xrpl::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 "xrpl::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 "xrpl::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 "xrpl::enforceMPTokenAuthorization : found MPToken");
3289 else if (authorizedByDomain && sleToken !=
nullptr)
3294 maybeDomainID.has_value(),
3295 "xrpl::enforceMPTokenAuthorization : found MPToken for domain");
3298 else if (authorizedByDomain)
3303 maybeDomainID.has_value() && sleToken ==
nullptr,
3304 "xrpl::enforceMPTokenAuthorization : new MPToken for domain");
3319 "xrpl::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 "xrpl::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);
3531 !bCheckIssuer,
"xrpl::rippleCredit : not checking issuer");
3533 view, uSenderID, uReceiverID, saAmount, j);
3547 "xrpl::assetsToSharesDeposit : non-negative assets");
3549 assets.
asset() == vault->at(sfAsset),
3550 "xrpl::assetsToSharesDeposit : assets and vault match");
3551 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3554 Number const assetTotal = vault->at(sfAssetsTotal);
3555 STAmount shares{vault->at(sfShareMPTID)};
3556 if (assetTotal == 0)
3562 Number const shareTotal = issuance->at(sfOutstandingAmount);
3563 shares = ((shareTotal * assets) / assetTotal).truncate();
3575 "xrpl::sharesToAssetsDeposit : non-negative shares");
3577 shares.
asset() == vault->at(sfShareMPTID),
3578 "xrpl::sharesToAssetsDeposit : shares and vault match");
3579 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3582 Number const assetTotal = vault->at(sfAssetsTotal);
3583 STAmount assets{vault->at(sfAsset)};
3584 if (assetTotal == 0)
3588 shares.
exponent() - vault->at(sfScale),
3591 Number const shareTotal = issuance->at(sfOutstandingAmount);
3592 assets = (assetTotal * shares) / shareTotal;
3605 "xrpl::assetsToSharesDeposit : non-negative assets");
3607 assets.
asset() == vault->at(sfAsset),
3608 "xrpl::assetsToSharesWithdraw : assets and vault match");
3609 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
3612 Number assetTotal = vault->at(sfAssetsTotal);
3613 assetTotal -= vault->at(sfLossUnrealized);
3614 STAmount shares{vault->at(sfShareMPTID)};
3615 if (assetTotal == 0)
3617 Number const shareTotal = issuance->at(sfOutstandingAmount);
3618 Number result = (shareTotal * assets) / assetTotal;
3619 if (truncate == TruncateShares::yes)
3633 "xrpl::sharesToAssetsDeposit : non-negative shares");
3635 shares.
asset() == vault->at(sfShareMPTID),
3636 "xrpl::sharesToAssetsWithdraw : shares and vault match");
3637 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
3640 Number assetTotal = vault->at(sfAssetsTotal);
3641 assetTotal -= vault->at(sfLossUnrealized);
3642 STAmount assets{vault->at(sfAsset)};
3643 if (assetTotal == 0)
3645 Number const shareTotal = issuance->at(sfOutstandingAmount);
3646 assets = (assetTotal * shares) / shareTotal;
3657 auto const mptIssue = amount.get<
MPTIssue>();
3658 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3659 auto sleIssuance = view.
peek(mptID);
3662 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
3663 << mptIssue.getMptID();
3667 if (amount.getIssuer() == sender)
3670 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3677 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3678 auto sle = view.
peek(mptokenID);
3682 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3686 auto const amt = sle->getFieldU64(sfMPTAmount);
3687 auto const pay = amount.mpt().value();
3693 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3694 << to_string(sender) <<
": " << amt <<
" < " << pay;
3698 (*sle)[sfMPTAmount] = amt - pay;
3701 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3706 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3707 << to_string(sender) <<
": " << locked <<
" + " << pay;
3711 if (sle->isFieldPresent(sfLockedAmount))
3712 (*sle)[sfLockedAmount] += pay;
3714 sle->setFieldU64(sfLockedAmount, pay);
3722 uint64_t
const issuanceEscrowed =
3723 (*sleIssuance)[~sfLockedAmount].value_or(0);
3724 auto const pay = amount.mpt().value();
3730 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3731 "locked amount for "
3732 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3737 if (sleIssuance->isFieldPresent(sfLockedAmount))
3738 (*sleIssuance)[sfLockedAmount] += pay;
3740 sleIssuance->setFieldU64(sfLockedAmount, pay);
3742 view.
update(sleIssuance);
3758 netAmount == grossAmount,
3759 "xrpl::rippleUnlockEscrowMPT : netAmount == grossAmount");
3761 auto const& issuer = netAmount.
getIssuer();
3763 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3764 auto sleIssuance = view.
peek(mptID);
3767 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3768 << mptIssue.getMptID();
3774 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3777 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3778 << mptIssue.getMptID();
3782 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3783 auto const redeem = grossAmount.
mpt().
value();
3790 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3791 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3795 auto const newLocked = locked - redeem;
3797 sleIssuance->makeFieldAbsent(sfLockedAmount);
3799 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3800 view.
update(sleIssuance);
3803 if (issuer != receiver)
3806 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3807 auto sle = view.
peek(mptokenID);
3811 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3815 auto current = sle->getFieldU64(sfMPTAmount);
3816 auto delta = netAmount.
mpt().
value();
3822 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3823 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3827 (*sle)[sfMPTAmount] += delta;
3833 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3834 auto const redeem = netAmount.
mpt().
value();
3841 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3842 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3847 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3848 view.
update(sleIssuance);
3851 if (issuer == sender)
3853 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3854 "cannot unlock MPTs.";
3860 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3861 auto sle = view.
peek(mptokenID);
3865 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3869 if (!sle->isFieldPresent(sfLockedAmount))
3872 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3873 << to_string(sender);
3877 auto const locked = sle->getFieldU64(sfLockedAmount);
3878 auto const delta = grossAmount.
mpt().
value();
3884 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3885 << to_string(sender) <<
": " << locked <<
" < " << delta;
3889 auto const newLocked = locked - delta;
3891 sle->makeFieldAbsent(sfLockedAmount);
3893 sle->setFieldU64(sfLockedAmount, newLocked);
3904 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3910 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3911 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3915 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3916 view.
update(sleIssuance);
Provide a light-weight way to check active() before string formatting.
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
constexpr value_type const & value() const
A currency issued by an account.
AccountID const & getIssuer() const
constexpr value_type value() const
Returns the underlying value.
constexpr MPTID const & getMptID() const
AccountID const & getIssuer() const
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Number truncate() const noexcept
virtual Rules const & rules() const =0
Returns the tx processing rules.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
virtual bool open() const =0
Returns true if this reflects an open ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
constexpr bool holds() const noexcept
constexpr TIss const & get() const
std::string getFullText() const override
static constexpr std::uint64_t cMaxValue
void setIssuer(AccountID const &uIssuer)
std::uint64_t mantissa() const noexcept
bool negative() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
static int const cMaxOffset
Currency const & getCurrency() const
bool native() const noexcept
Asset const & asset() const
int exponent() const noexcept
AccountID const & getIssuer() const
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const_pointer
bool isFieldPresent(SField const &field) const
T emplace_back(T... args)
bool internalDirFirst(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
bool internalDirNext(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
Keylet const & skip() noexcept
The index of the "short" skip list.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uSrcQualityIn, std::uint32_t uSrcQualityOut, beast::Journal j)
Create a trust line.
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
std::vector< SField const * > const & getPseudoAccountFields()
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
Any transactors that call addEmptyHolding() in doApply must call canAddHolding() in preflight with th...
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
FreezeHandling
Controls the treatment of frozen account balances.
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
bool isXRP(AccountID const &c)
TER canAddHolding(ReadView const &view, Asset const &asset)
std::uint8_t constexpr maxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
std::map< uint256, NetClock::time_point > majorityAmendments_t
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
std::string to_string(base_uint< Bits, Tag > const &a)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, beast::Journal j)
static TER accountSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
static TER rippleSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
@ expired
List is expired, but has the largest non-pending sequence seen so far.
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
Number root(Number f, unsigned d)
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
static TER rippleCreditMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
bool cdirNext(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
STAmount multiply(STAmount const &amount, Rate const &rate)
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
static TER rippleCreditIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
bool cdirFirst(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
static TER rippleSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
static TER rippleSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
@ current
This was a new validation and was added.
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, char const *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
static std::uint32_t confineOwnerCount(std::uint32_t current, std::int32_t adjustment, std::optional< AccountID > const &id=std::nullopt, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
std::optional< STAmount > assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets, TruncateShares truncate=TruncateShares::no)
static TER rippleSendMultiIOU(ApplyView &view, AccountID const &senderID, Issue const &issue, MultiplePaymentDestinations const &receivers, STAmount &actual, beast::Journal j, WaiveTransferFee waiveFee)
bool canAdd(STAmount const &amt1, STAmount const &amt2)
Safely checks if two STAmount values can be added without overflow, underflow, or precision loss.
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
static STAmount getTrustLineBalance(ReadView const &view, SLE::const_ref sle, AccountID const &account, Currency const ¤cy, AccountID const &issuer, bool includeOppositeLimit, beast::Journal j)
AuthHandling
Controls the treatment of unauthorized MPT balances.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
static SLE::const_pointer getLineIfUsable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
majorityAmendments_t getMajorityAmendments(ReadView const &view)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
constexpr std::uint32_t const tfMPTUnauthorize
TER 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.
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
STAmount accountSpendable(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
AccountID const & noAccount()
A placeholder for empty accounts.
static bool updateTrustLine(ApplyView &view, SLE::pointer state, bool bSenderHigh, AccountID const &sender, STAmount const &before, STAmount const &after, beast::Journal j)
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
static TER accountSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
bool canSubtract(STAmount const &amt1, STAmount const &amt2)
Determines if it is safe to subtract one STAmount from another.
bool isTesSuccess(TER x) noexcept
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
LedgerEntryType
Identifiers for on-ledger objects.
AccountID const & xrpAccount()
Compute AccountID from public key.
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items after an item in the given directory.
static TER accountSendMultiMPT(ApplyView &view, AccountID const &senderID, MPTIssue const &mptIssue, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee)
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
TER checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag)
Validates that the destination SLE and tag are valid.
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.
A field with a type known at compile time.
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
T time_since_epoch(T... args)