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)
384 auto const allowBalance = [&]() {
392 if (
isFrozen(view, account, currency, issuer) ||
407 else if (sleIssuer->isFieldPresent(sfAMMID))
416 (*sleAmm)[sfAsset].get<Issue>(),
417 (*sleAmm)[sfAsset2].get<Issue>()))
430 amount = sle->getFieldAmount(sfBalance);
431 if (account > issuer)
443 JLOG(j.
trace()) <<
"accountHolds:"
477 amount.
clear(mptIssue);
480 amount.
clear(mptIssue);
483 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
493 amount.
clear(mptIssue);
497 auto const sleIssuance =
504 amount.
clear(mptIssue);
511[[nodiscard]] STAmount
521 [&](
auto const& value) {
526 return accountHolds(view, account, value, zeroIfFrozen, j);
529 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
576 <<
"Account " << *
id <<
" owner count exceeds max!";
589 <<
"Account " << *
id <<
" owner count set below 0!";
592 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
611 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
618 auto const fullBalance = sle->getFieldAmount(sfBalance);
623 (balance < reserve) ?
STAmount{0} : balance - reserve;
625 JLOG(j.
trace()) <<
"accountHolds:"
628 <<
" fullBalance=" << fullBalance.getFullText()
629 <<
" balance=" << balance.getFullText()
630 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
631 <<
" ownerCountAdj=" << ownerCountAdj;
643 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
645 if (
root.type != ltDIR_NODE)
652 auto sle = view.
read(pos);
655 for (
auto const& key : sle->getFieldV256(sfIndexes))
657 auto const next = sle->getFieldU64(sfIndexNext);
674 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
676 if (
root.type != ltDIR_NODE)
679 auto currentIndex =
root;
682 if (
after.isNonZero())
686 if (
auto hintDir = view.
read(hintIndex))
688 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
693 currentIndex = hintIndex;
702 auto const ownerDir = view.
read(currentIndex);
705 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
718 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
728 auto const ownerDir = view.
read(currentIndex);
731 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
734 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
747 if (sle && sle->isFieldPresent(sfTransferRate))
748 return Rate{sle->getFieldU32(sfTransferRate)};
760 sle && sle->isFieldPresent(sfTransferFee))
761 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
795 if (hash && (*hash != validLedger.
info().
hash))
797 JLOG(s) << reason <<
" incompatible with valid ledger";
799 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
811 if (hash && (*hash != testLedger.
info().
hash))
813 JLOG(s) << reason <<
" incompatible preceding ledger";
815 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
825 JLOG(s) << reason <<
" incompatible ledger";
832 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
835 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
852 if (testLedger.
info().
seq > validIndex)
859 if (hash && (*hash != validHash))
861 JLOG(s) << reason <<
" incompatible following ledger";
862 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
868 (validIndex == testLedger.
info().
seq) &&
869 (testLedger.
info().
hash != validHash))
871 JLOG(s) << reason <<
" incompatible ledger";
878 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
880 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
890 auto const sleNode = view.
read(k);
893 if (!sleNode->getFieldV256(sfIndexes).empty())
898 return sleNode->getFieldU64(sfIndexNext) == 0;
908 if (sle->isFieldPresent(sfAmendments))
910 auto const& v = sle->getFieldV256(sfAmendments);
911 amendments.insert(v.begin(), v.end());
925 if (sle->isFieldPresent(sfMajorities))
928 using d = tp::duration;
930 auto const majorities = sle->getFieldArray(sfMajorities);
932 for (
auto const& m : majorities)
933 ret[m.getFieldH256(sfAmendment)] =
934 tp(d(m.getFieldU32(sfCloseTime)));
945 if (seq > ledger.
seq())
948 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
951 if (seq == ledger.
seq())
953 if (seq == (ledger.
seq() - 1))
956 if (
int diff = ledger.
seq() - seq; diff <= 256)
963 hashIndex->getFieldU32(sfLastLedgerSequence) ==
965 "ripple::hashOfSeq : matching ledger sequence");
966 STVector256 vec = hashIndex->getFieldV256(sfHashes);
967 if (vec.
size() >= diff)
968 return vec[vec.
size() - diff];
970 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
971 <<
" (" << vec.
size() <<
"," << diff <<
")";
976 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
977 <<
" missing normal list";
981 if ((seq & 0xff) != 0)
983 JLOG(journal.
debug())
984 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
992 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
993 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
995 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
996 auto const diff = (lastSeq - seq) >> 8;
997 STVector256 vec = hashIndex->getFieldV256(sfHashes);
998 if (vec.
size() > diff)
999 return vec[vec.
size() - diff - 1];
1001 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1021 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1026 sle->at(sfOwnerCount) = adjusted;
1034 (*sle)[sfOwner] = account;
1045 object->setFieldU64(sfOwnerNode, *page);
1058 rsh(hash.data(), hash.size());
1081 "ripple::isPseudoAccount : unable to find account root ledger "
1085 auto const& soTemplate = ar->getSOTemplate();
1088 for (
auto const& field : soTemplate)
1093 return pseudoFields;
1095 return pseudoFields;
1105 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1107 fields.begin(), fields.end(), [&sleAcct](
SField const* sf) ->
bool {
1108 return sleAcct->isFieldPresent(*sf);
1112Expected<std::shared_ptr<SLE>,
TER>
1115 uint256 const& pseudoOwnerKey,
1116 SField const& ownerField)
1123 [&ownerField](
SField const* sf) ->
bool {
1124 return *sf == ownerField;
1126 "ripple::createPseudoAccount : valid owner field");
1129 if (accountId == beast::zero)
1134 account->setAccountID(sfAccount, accountId);
1135 account->setFieldAmount(sfBalance,
STAmount{});
1144 account->setFieldU32(sfSequence, seqno);
1148 account->setFieldU32(
1151 account->setFieldH256(ownerField, pseudoOwnerKey);
1208 auto const& issuerId = issue.
getIssuer();
1209 auto const& currency = issue.
currency;
1213 auto const& srcId = issuerId;
1214 auto const& dstId = accountID;
1215 auto const high = srcId > dstId;
1216 auto const index =
keylet::line(srcId, dstId, currency);
1219 if (!sleDst || !sleSrc)
1224 if (view.
read(index))
1243 STAmount{Issue{currency, noAccount()}},
1244 STAmount{Issue{currency, dstId}},
1258 auto const& mptID = mptIssue.
getMptID();
1259 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1264 if (view.
peek(keylet::mptoken(mptID, accountID)))
1274 MPTID const& mptIssuanceID,
1280 auto const sleAcct = view.
peek(keylet::account(account));
1294 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1295 auto const sleMpt = view.
peek(mptokenKey);
1296 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1300 keylet::ownerDir(account),
1301 (*sleMpt)[sfOwnerNode],
1321 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1323 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1326 if (priorBalance < reserveCreate)
1329 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1331 if (
auto ter =
dirLink(view, account, mptoken))
1334 (*mptoken)[sfAccount] = account;
1335 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1336 (*mptoken)[sfFlags] = 0;
1345 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1346 if (!sleMptIssuance)
1352 if (account != (*sleMptIssuance)[sfIssuer])
1355 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1365 flagsOut &= ~lsfMPTAuthorized;
1371 if (flagsIn != flagsOut)
1372 sleMpt->setFieldU32(sfFlags, flagsOut);
1381 bool const bSrcHigh,
1387 bool const bNoRipple,
1398 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1399 << to_string(uDstAccountID) <<
", "
1402 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1403 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1406 view.
insert(sleRippleState);
1409 keylet::ownerDir(uLowAccountID),
1410 sleRippleState->key(),
1417 keylet::ownerDir(uHighAccountID),
1418 sleRippleState->key(),
1424 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1425 bool const bSetHigh = bSrcHigh ^ bSetDst;
1427 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1432 sleAccount->getAccountID(sfAccount) ==
1433 (bSetHigh ? uHighAccountID : uLowAccountID),
1434 "ripple::trustCreate : matching account ID");
1435 auto const slePeer =
1436 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1441 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1442 sleRippleState->setFieldU64(sfHighNode, *highNode);
1444 sleRippleState->setFieldAmount(
1445 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1446 sleRippleState->setFieldAmount(
1447 bSetHigh ? sfLowLimit : sfHighLimit,
1449 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1452 sleRippleState->setFieldU32(
1453 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1456 sleRippleState->setFieldU32(
1457 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1484 sleRippleState->setFieldU32(sfFlags, uFlags);
1488 sleRippleState->setFieldAmount(
1489 sfBalance, bSetHigh ? -saBalance : saBalance);
1492 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1506 auto const sle = view.
read(keylet::account(accountID));
1510 auto const balance = sle->getFieldAmount(sfBalance);
1511 if (balance.xrp() != 0)
1518 auto const line = view.
peek(keylet::line(accountID, issue));
1521 if (line->at(sfBalance)->iou() != beast::zero)
1528 auto sleLowAccount =
1529 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1543 auto sleHighAccount =
1544 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1545 if (!sleHighAccount)
1558 line->at(sfLowLimit)->getIssuer(),
1559 line->at(sfHighLimit)->getIssuer(),
1570 auto const& mptID = mptIssue.
getMptID();
1571 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1574 if (mptoken->at(sfMPTAmount) != 0)
1596 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1597 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1599 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1602 keylet::ownerDir(uLowAccountID),
1604 sleRippleState->key(),
1610 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1613 keylet::ownerDir(uHighAccountID),
1615 sleRippleState->key(),
1621 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1622 view.
erase(sleRippleState);
1632 auto offerIndex = sle->key();
1633 auto owner = sle->getAccountID(sfAccount);
1636 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1639 keylet::ownerDir(owner),
1640 sle->getFieldU64(sfOwnerNode),
1648 keylet::page(uDirectory),
1649 sle->getFieldU64(sfBookNode),
1656 if (sle->isFieldPresent(sfAdditionalBooks))
1659 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1660 "ripple::offerDelete : should be a hybrid domain offer");
1662 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1664 for (
auto const& bookDir : additionalBookDirs)
1666 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1667 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1670 keylet::page(dirIndex), dirNode, offerIndex,
false))
1702 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1703 "ripple::rippleCreditIOU : matching issuer or don't care");
1708 uSenderID != uReceiverID,
1709 "ripple::rippleCreditIOU : sender is not receiver");
1711 bool const bSenderHigh = uSenderID > uReceiverID;
1712 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1716 "ripple::rippleCreditIOU : sender is not XRP");
1719 "ripple::rippleCreditIOU : receiver is not XRP");
1722 if (
auto const sleRippleState = view.
peek(index))
1724 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1729 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1731 STAmount const saBefore = saBalance;
1733 saBalance -= saAmount;
1735 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1736 << to_string(uReceiverID)
1741 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1742 bool bDelete =
false;
1746 if (saBefore > beast::zero
1748 && saBalance <= beast::zero
1756 view.
read(keylet::account(uSenderID))->getFlags() &
1759 !sleRippleState->getFieldAmount(
1760 !bSenderHigh ? sfLowLimit : sfHighLimit)
1762 && !sleRippleState->getFieldU32(
1763 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1765 && !sleRippleState->getFieldU32(
1766 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1771 view, view.
peek(keylet::account(uSenderID)), -1, j);
1774 sleRippleState->setFieldU32(
1776 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1779 bDelete = !saBalance
1788 sleRippleState->setFieldAmount(sfBalance, saBalance);
1796 bSenderHigh ? uReceiverID : uSenderID,
1797 !bSenderHigh ? uReceiverID : uSenderID,
1801 view.
update(sleRippleState);
1805 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1810 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1812 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1815 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1852 auto const issuer = saAmount.
getIssuer();
1856 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1858 uSenderID != uReceiverID,
1859 "ripple::rippleSendIOU : sender is not receiver");
1861 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1868 saActual = saAmount;
1876 saActual = (waiveFee == WaiveTransferFee::Yes)
1880 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1881 << to_string(uReceiverID)
1889 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1915 "ripple::accountSendIOU : minimum amount and not MPT");
1922 if (!saAmount || (uSenderID == uReceiverID))
1929 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1930 << to_string(uReceiverID) <<
" : "
1934 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1945 ? view.
peek(keylet::account(uSenderID))
1948 ? view.
peek(keylet::account(uReceiverID))
1951 if (
auto stream = j.
trace())
1957 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1960 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1962 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1963 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1964 << receiver_bal <<
") : " << saAmount.
getFullText();
1969 if (sender->getFieldAmount(sfBalance) < saAmount)
1980 auto const sndBal = sender->getFieldAmount(sfBalance);
1984 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1992 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1993 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
1999 if (
auto stream = j.
trace())
2005 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2008 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2010 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2011 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2012 << receiver_bal <<
") : " << saAmount.
getFullText();
2028 auto const issuer = saAmount.
getIssuer();
2029 auto sleIssuance = view.
peek(mptID);
2032 if (uSenderID == issuer)
2034 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2035 view.
update(sleIssuance);
2039 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2040 if (
auto sle = view.
peek(mptokenID))
2042 auto const amt = sle->getFieldU64(sfMPTAmount);
2043 auto const pay = saAmount.
mpt().
value();
2046 (*sle)[sfMPTAmount] = amt - pay;
2053 if (uReceiverID == issuer)
2055 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2056 auto const redeem = saAmount.
mpt().
value();
2057 if (outstanding >= redeem)
2059 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2060 view.
update(sleIssuance);
2067 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2068 if (
auto sle = view.
peek(mptokenID))
2070 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2091 uSenderID != uReceiverID,
2092 "ripple::rippleSendMPT : sender is not receiver");
2095 auto const issuer = saAmount.
getIssuer();
2102 if (uSenderID == issuer || uReceiverID == issuer)
2106 if (uSenderID == issuer)
2108 auto const sendAmount = saAmount.
mpt().
value();
2109 auto const maximumAmount =
2111 if (sendAmount > maximumAmount ||
2112 sle->getFieldU64(sfOutstandingAmount) >
2113 maximumAmount - sendAmount)
2122 saActual = saAmount;
2127 saActual = (waiveFee == WaiveTransferFee::Yes)
2133 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2134 << to_string(uReceiverID)
2138 if (
auto const terResult =
2157 "ripple::accountSendMPT : minimum amount and MPT");
2162 if (!saAmount || (uSenderID == uReceiverID))
2168 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2184 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2187 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2206 auto sle = view.
peek(keylet::account(sender));
2211 if (before > beast::zero
2213 &&
after <= beast::zero
2217 &&
static_cast<bool>(
2221 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2223 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2226 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2235 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2255 "ripple::issueIOU : neither account nor issuer is XRP");
2258 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2262 issue.
account != account,
"ripple::issueIOU : not issuer account");
2264 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2267 bool bSenderHigh = issue.
account > account;
2269 auto const index = keylet::line(issue.
account, account, issue.
currency);
2271 if (
auto state = view.
peek(index))
2273 STAmount final_balance = state->getFieldAmount(sfBalance);
2278 STAmount const start_balance = final_balance;
2280 final_balance -= amount;
2299 state->setFieldAmount(sfBalance, final_balance);
2304 bSenderHigh ? account : issue.
account,
2305 bSenderHigh ? issue.
account : account,
2321 auto const receiverAccount = view.
peek(keylet::account(account));
2322 if (!receiverAccount)
2355 "ripple::redeemIOU : neither account nor issuer is XRP");
2358 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2362 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2364 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2367 bool bSenderHigh = account > issue.
account;
2372 STAmount final_balance = state->getFieldAmount(sfBalance);
2377 STAmount const start_balance = final_balance;
2379 final_balance -= amount;
2382 view, state, bSenderHigh, account, start_balance, final_balance, j);
2392 state->setFieldAmount(sfBalance, final_balance);
2399 bSenderHigh ? issue.
account : account,
2400 bSenderHigh ? account : issue.
account,
2412 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2414 <<
" but no trust line exists!";
2429 from != beast::zero,
"ripple::transferXRP : nonzero from account");
2430 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
2431 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
2432 XRPL_ASSERT(amount.
native(),
"ripple::transferXRP : amount is XRP");
2436 if (!sender || !receiver)
2439 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
2440 << to_string(to) <<
") : " << amount.
getFullText();
2442 if (sender->getFieldAmount(sfBalance) < amount)
2454 sender->setFieldAmount(
2455 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2458 receiver->setFieldAmount(
2459 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2475 auto const trustLine =
2478 if (!trustLine && authType == AuthType::StrongAuth)
2483 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2487 return ((*trustLine)[sfFlags] &
2505 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2506 auto const sleIssuance = view.
read(mptID);
2510 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2513 if (mptIssuer == account)
2522 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2526 if (sleIssuer->isFieldPresent(sfVaultID))
2528 auto const sleVault =
2529 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2533 auto const asset = sleVault->at(sfAsset);
2537 return requireAuth(view, issue, account, authType);
2540 view, issue, account, authType, depth + 1);
2548 auto const mptokenID = keylet::mptoken(mptID.key, account);
2549 auto const sleToken = view.
read(mptokenID);
2553 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2558 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2563 "ripple::requireAuth : issuance requires authorization");
2565 if (
auto const ter =
2566 credentials::validDomain(view, *maybeDomainID, account);
2586 MPTID const& mptIssuanceID,
2591 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2597 "ripple::enforceMPTokenAuthorization : authorization required");
2599 if (account == sleIssuance->at(sfIssuer))
2602 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2603 auto const sleToken = view.
read(keylet);
2604 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2606 bool const authorizedByDomain = [&]() ->
bool {
2608 if (!maybeDomainID.has_value())
2619 if (!authorizedByDomain && sleToken ==
nullptr)
2630 else if (!authorizedByDomain && maybeDomainID.has_value())
2637 else if (!authorizedByDomain)
2642 sleToken !=
nullptr && !maybeDomainID.has_value(),
2643 "ripple::enforceMPTokenAuthorization : found MPToken");
2649 else if (authorizedByDomain && sleToken !=
nullptr)
2654 maybeDomainID.has_value(),
2655 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2658 else if (authorizedByDomain)
2663 maybeDomainID.has_value() && sleToken ==
nullptr,
2664 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2679 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2691 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2692 auto const sleIssuance = view.
read(mptID);
2698 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2707 Keylet const& ownerDirKeylet,
2714 unsigned int uDirEntry{0};
2715 uint256 dirEntry{beast::zero};
2718 if (view.
exists(ownerDirKeylet) &&
2719 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2723 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2727 auto sleItem = view.
peek(keylet::child(dirEntry));
2733 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
2734 <<
" has index to object that is missing: "
2735 << to_string(dirEntry);
2741 sleItem->getFieldU16(sfLedgerEntryType))};
2745 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2767 "ripple::cleanupOnAccountDelete : minimum dir entries");
2772 <<
"DeleteAccount iterator re-validation failed.";
2776 if (skipEntry == SkipEntry::No)
2780 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2793 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2797 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2798 sleState->getFieldAmount(sfHighLimit).getIssuer());
2799 auto sleLow = view.
peek(keylet::account(low));
2800 auto sleHigh = view.
peek(keylet::account(high));
2801 if (!sleLow || !sleHigh)
2804 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2805 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2808 if (ammLow && ammHigh)
2812 if (!ammLow && !ammHigh)
2816 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2819 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2823 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2828 if (!(sleState->getFlags() & uFlags))
2850 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2856 "ripple::rippleCredit : not checking issuer");
2858 view, uSenderID, uReceiverID, saAmount, j);
2872 "ripple::assetsToSharesDeposit : non-negative assets");
2874 assets.
asset() == vault->at(sfAsset),
2875 "ripple::assetsToSharesDeposit : assets and vault match");
2876 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2879 Number const assetTotal = vault->at(sfAssetsTotal);
2880 STAmount shares{vault->at(sfShareMPTID)};
2881 if (assetTotal == 0)
2887 Number const shareTotal = issuance->at(sfOutstandingAmount);
2888 shares = ((shareTotal * assets) / assetTotal).truncate();
2900 "ripple::sharesToAssetsDeposit : non-negative shares");
2902 shares.
asset() == vault->at(sfShareMPTID),
2903 "ripple::sharesToAssetsDeposit : shares and vault match");
2904 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2907 Number const assetTotal = vault->at(sfAssetsTotal);
2908 STAmount assets{vault->at(sfAsset)};
2909 if (assetTotal == 0)
2913 shares.
exponent() - vault->at(sfScale),
2916 Number const shareTotal = issuance->at(sfOutstandingAmount);
2917 assets = (assetTotal * shares) / shareTotal;
2930 "ripple::assetsToSharesDeposit : non-negative assets");
2932 assets.
asset() == vault->at(sfAsset),
2933 "ripple::assetsToSharesWithdraw : assets and vault match");
2934 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2937 Number assetTotal = vault->at(sfAssetsTotal);
2938 assetTotal -= vault->at(sfLossUnrealized);
2939 STAmount shares{vault->at(sfShareMPTID)};
2940 if (assetTotal == 0)
2942 Number const shareTotal = issuance->at(sfOutstandingAmount);
2943 Number result = (shareTotal * assets) / assetTotal;
2944 if (truncate == TruncateShares::yes)
2958 "ripple::sharesToAssetsDeposit : non-negative shares");
2960 shares.
asset() == vault->at(sfShareMPTID),
2961 "ripple::sharesToAssetsWithdraw : shares and vault match");
2962 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2965 Number assetTotal = vault->at(sfAssetsTotal);
2966 assetTotal -= vault->at(sfLossUnrealized);
2967 STAmount assets{vault->at(sfAsset)};
2968 if (assetTotal == 0)
2970 Number const shareTotal = issuance->at(sfOutstandingAmount);
2971 assets = (assetTotal * shares) / shareTotal;
2983 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2984 auto sleIssuance = view.
peek(mptID);
2987 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
2988 << mptIssue.getMptID();
2995 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
3002 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3003 auto sle = view.
peek(mptokenID);
3007 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3011 auto const amt = sle->getFieldU64(sfMPTAmount);
3012 auto const pay = amount.
mpt().
value();
3018 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3019 << to_string(sender) <<
": " << amt <<
" < " << pay;
3023 (*sle)[sfMPTAmount] = amt - pay;
3026 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3031 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3032 << to_string(sender) <<
": " << locked <<
" + " << pay;
3036 if (sle->isFieldPresent(sfLockedAmount))
3037 (*sle)[sfLockedAmount] += pay;
3039 sle->setFieldU64(sfLockedAmount, pay);
3047 uint64_t
const issuanceEscrowed =
3048 (*sleIssuance)[~sfLockedAmount].value_or(0);
3049 auto const pay = amount.
mpt().
value();
3055 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3056 "locked amount for "
3057 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3062 if (sleIssuance->isFieldPresent(sfLockedAmount))
3063 (*sleIssuance)[sfLockedAmount] += pay;
3065 sleIssuance->setFieldU64(sfLockedAmount, pay);
3067 view.
update(sleIssuance);
3083 netAmount == grossAmount,
3084 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3086 auto const& issuer = netAmount.
getIssuer();
3088 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3089 auto sleIssuance = view.
peek(mptID);
3092 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3093 << mptIssue.getMptID();
3099 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3102 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3103 << mptIssue.getMptID();
3107 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3108 auto const redeem = grossAmount.
mpt().
value();
3115 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3116 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3120 auto const newLocked = locked - redeem;
3122 sleIssuance->makeFieldAbsent(sfLockedAmount);
3124 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3125 view.
update(sleIssuance);
3128 if (issuer != receiver)
3131 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3132 auto sle = view.
peek(mptokenID);
3136 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3140 auto current = sle->getFieldU64(sfMPTAmount);
3141 auto delta = netAmount.
mpt().
value();
3147 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3148 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3152 (*sle)[sfMPTAmount] += delta;
3158 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3159 auto const redeem = netAmount.
mpt().
value();
3166 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3167 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3172 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3173 view.
update(sleIssuance);
3176 if (issuer == sender)
3178 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3179 "cannot unlock MPTs.";
3185 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3186 auto sle = view.
peek(mptokenID);
3190 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3194 if (!sle->isFieldPresent(sfLockedAmount))
3197 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3198 << to_string(sender);
3202 auto const locked = sle->getFieldU64(sfLockedAmount);
3203 auto const delta = grossAmount.
mpt().
value();
3209 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3210 << to_string(sender) <<
": " << locked <<
" < " << delta;
3214 auto const newLocked = locked - delta;
3216 sle->makeFieldAbsent(sfLockedAmount);
3218 sle->setFieldU64(sfLockedAmount, newLocked);
3229 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3235 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3236 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3240 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3241 view.
update(sleIssuance);
Provide a light-weight way to check active() before string formatting.
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
constexpr value_type const & value() const
A currency issued by an account.
AccountID const & getIssuer() const
constexpr value_type value() const
Returns the underlying value.
constexpr MPTID const & getMptID() const
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Number truncate() const noexcept
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
constexpr bool holds() const noexcept
int exponent() const noexcept
Asset const & asset() const
constexpr TIss const & get() const
void setIssuer(AccountID const &uIssuer)
Currency const & getCurrency() const
bool negative() const noexcept
AccountID const & getIssuer() const
Issue const & issue() const
std::uint64_t mantissa() const noexcept
std::string getFullText() const override
bool native() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
std::shared_ptr< STLedgerEntry > const & ref
T emplace_back(T... args)
bool internalDirFirst(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
bool internalDirNext(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet const & skip() noexcept
The index of the "short" skip list.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
AccountID const & noAccount()
A placeholder for empty accounts.
static bool updateTrustLine(ApplyView &view, SLE::pointer state, bool bSenderHigh, AccountID const &sender, STAmount const &before, STAmount const &after, beast::Journal j)
std::uint8_t constexpr maxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
FreezeHandling
Controls the treatment of frozen account balances.
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, char const *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
bool isXRP(AccountID const &c)
AccountID const & xrpAccount()
Compute AccountID from public key.
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
bool canSubtract(STAmount const &amt1, STAmount const &amt2)
Determines if it is safe to subtract one STAmount from another.
static TER rippleSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool dirNext(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
bool canAdd(STAmount const &amt1, STAmount const &amt2)
Safely checks if two STAmount values can be added without overflow, underflow, or precision loss.
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
TER redeemIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
STAmount multiply(STAmount const &amount, Rate const &rate)
AuthHandling
Controls the treatment of unauthorized MPT balances.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
std::optional< STAmount > assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets, TruncateShares truncate=TruncateShares::no)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
@ current
This was a new validation and was added.
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
@ expired
List is expired, but has the largest non-pending sequence seen so far.
std::set< uint256 > getEnabledAmendments(ReadView const &view)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
static std::uint32_t confineOwnerCount(std::uint32_t current, std::int32_t adjustment, std::optional< AccountID > const &id=std::nullopt, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
static TER rippleCreditIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
constexpr std::uint32_t const tfMPTUnauthorize
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
bool isVaultPseudoAccountFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptShare, int depth)
TER issueIOU(ApplyView &view, AccountID const &account, STAmount const &amount, Issue const &issue, beast::Journal j)
static TER accountSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
std::map< uint256, NetClock::time_point > majorityAmendments_t
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items after an item in the given directory.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
Any transactors that call addEmptyHolding() in doApply must call canAddHolding() in preflight with th...
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool isLPTokenFrozen(ReadView const &view, AccountID const &account, Issue const &asset, Issue const &asset2)
bool isTesSuccess(TER x) noexcept
majorityAmendments_t getMajorityAmendments(ReadView const &view)
bool cdirFirst(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
std::string to_string(base_uint< Bits, Tag > const &a)
LedgerEntryType
Identifiers for on-ledger objects.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uSrcQualityIn, std::uint32_t uSrcQualityOut, beast::Journal j)
Create a trust line.
Number root(Number f, unsigned d)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
TER canAddHolding(ReadView const &view, Asset const &asset)
bool cdirNext(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
static TER rippleSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth=0)
std::vector< SField const * > const & getPseudoAccountFields()
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
TERSubset< CanCvtToTER > TER
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
static TER rippleCreditMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
static TER accountSendMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
T time_since_epoch(T... args)