20#include <xrpl/basics/Expected.h>
21#include <xrpl/basics/Log.h>
22#include <xrpl/basics/chrono.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/ledger/CredentialHelpers.h>
25#include <xrpl/ledger/ReadView.h>
26#include <xrpl/ledger/View.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/LedgerFormats.h>
30#include <xrpl/protocol/MPTIssue.h>
31#include <xrpl/protocol/Protocol.h>
32#include <xrpl/protocol/Quality.h>
33#include <xrpl/protocol/TER.h>
34#include <xrpl/protocol/TxFlags.h>
35#include <xrpl/protocol/digest.h>
36#include <xrpl/protocol/st.h>
59 auto const& svIndexes = page->getFieldV256(sfIndexes);
61 index <= svIndexes.size(),
62 "ripple::detail::internalDirNext : index inside range");
64 if (index >= svIndexes.size())
66 auto const next = page->getFieldU64(sfIndexNext);
79 XRPL_ASSERT(page,
"ripple::detail::internalDirNext : non-null root");
89 entry = svIndexes[index++];
221 if (issuer != account)
258 if (issuer != account)
291 for (
auto const& account : accounts)
297 for (
auto const& account : accounts)
319 auto const mptIssuance =
321 if (mptIssuance ==
nullptr)
324 auto const issuer = mptIssuance->getAccountID(sfIssuer);
326 if (mptIssuer ==
nullptr)
329 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null MPToken issuer");
334 if (!mptIssuer->isFieldPresent(sfVaultID))
339 if (vault ==
nullptr)
341 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null vault");
346 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
361 if (issuer == account)
403 auto const allowBalance = [&]() {
411 if (
isFrozen(view, account, currency, issuer) ||
426 else if (sleIssuer->isFieldPresent(sfAMMID))
435 (*sleAmm)[sfAsset].get<Issue>(),
436 (*sleAmm)[sfAsset2].get<Issue>()))
449 amount = sle->getFieldAmount(sfBalance);
450 if (account > issuer)
462 JLOG(j.
trace()) <<
"accountHolds:"
496 amount.
clear(mptIssue);
499 amount.
clear(mptIssue);
502 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
512 amount.
clear(mptIssue);
516 auto const sleIssuance =
523 amount.
clear(mptIssue);
530[[nodiscard]] STAmount
540 [&](
auto const& value) {
545 return accountHolds(view, account, value, zeroIfFrozen, j);
548 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
595 <<
"Account " << *
id <<
" owner count exceeds max!";
608 <<
"Account " << *
id <<
" owner count set below 0!";
611 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
630 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
637 auto const fullBalance = sle->getFieldAmount(sfBalance);
642 (balance < reserve) ?
STAmount{0} : balance - reserve;
644 JLOG(j.
trace()) <<
"accountHolds:"
647 <<
" fullBalance=" << fullBalance.getFullText()
648 <<
" balance=" << balance.getFullText()
649 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
650 <<
" ownerCountAdj=" << ownerCountAdj;
662 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
664 if (
root.type != ltDIR_NODE)
671 auto sle = view.
read(pos);
674 for (
auto const& key : sle->getFieldV256(sfIndexes))
676 auto const next = sle->getFieldU64(sfIndexNext);
693 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
695 if (
root.type != ltDIR_NODE)
698 auto currentIndex =
root;
701 if (
after.isNonZero())
705 if (
auto hintDir = view.
read(hintIndex))
707 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
712 currentIndex = hintIndex;
721 auto const ownerDir = view.
read(currentIndex);
724 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
737 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
747 auto const ownerDir = view.
read(currentIndex);
750 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
753 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
766 if (sle && sle->isFieldPresent(sfTransferRate))
767 return Rate{sle->getFieldU32(sfTransferRate)};
779 sle && sle->isFieldPresent(sfTransferFee))
780 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
814 if (hash && (*hash != validLedger.
info().
hash))
816 JLOG(s) << reason <<
" incompatible with valid ledger";
818 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
830 if (hash && (*hash != testLedger.
info().
hash))
832 JLOG(s) << reason <<
" incompatible preceding ledger";
834 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
844 JLOG(s) << reason <<
" incompatible ledger";
851 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
854 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
871 if (testLedger.
info().
seq > validIndex)
878 if (hash && (*hash != validHash))
880 JLOG(s) << reason <<
" incompatible following ledger";
881 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
887 (validIndex == testLedger.
info().
seq) &&
888 (testLedger.
info().
hash != validHash))
890 JLOG(s) << reason <<
" incompatible ledger";
897 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
899 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
909 auto const sleNode = view.
read(k);
912 if (!sleNode->getFieldV256(sfIndexes).empty())
917 return sleNode->getFieldU64(sfIndexNext) == 0;
927 if (sle->isFieldPresent(sfAmendments))
929 auto const& v = sle->getFieldV256(sfAmendments);
930 amendments.insert(v.begin(), v.end());
944 if (sle->isFieldPresent(sfMajorities))
947 using d = tp::duration;
949 auto const majorities = sle->getFieldArray(sfMajorities);
951 for (
auto const& m : majorities)
952 ret[m.getFieldH256(sfAmendment)] =
953 tp(d(m.getFieldU32(sfCloseTime)));
964 if (seq > ledger.
seq())
967 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
970 if (seq == ledger.
seq())
972 if (seq == (ledger.
seq() - 1))
975 if (
int diff = ledger.
seq() - seq; diff <= 256)
982 hashIndex->getFieldU32(sfLastLedgerSequence) ==
984 "ripple::hashOfSeq : matching ledger sequence");
985 STVector256 vec = hashIndex->getFieldV256(sfHashes);
986 if (vec.
size() >= diff)
987 return vec[vec.
size() - diff];
989 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
990 <<
" (" << vec.
size() <<
"," << diff <<
")";
995 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
996 <<
" missing normal list";
1000 if ((seq & 0xff) != 0)
1002 JLOG(journal.
debug())
1003 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1011 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1012 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
1014 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
1015 auto const diff = (lastSeq - seq) >> 8;
1016 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1017 if (vec.
size() > diff)
1018 return vec[vec.
size() - diff - 1];
1020 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1040 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1045 sle->at(sfOwnerCount) = adjusted;
1053 (*sle)[sfOwner] = account;
1064 object->setFieldU64(sfOwnerNode, *page);
1077 rsh(hash.data(), hash.size());
1100 "ripple::isPseudoAccount : unable to find account root ledger "
1104 auto const& soTemplate = ar->getSOTemplate();
1107 for (
auto const& field : soTemplate)
1112 return pseudoFields;
1114 return pseudoFields;
1124 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1126 fields.begin(), fields.end(), [&sleAcct](
SField const* sf) ->
bool {
1127 return sleAcct->isFieldPresent(*sf);
1131Expected<std::shared_ptr<SLE>,
TER>
1134 uint256 const& pseudoOwnerKey,
1135 SField const& ownerField)
1142 [&ownerField](
SField const* sf) ->
bool {
1143 return *sf == ownerField;
1145 "ripple::createPseudoAccount : valid owner field");
1148 if (accountId == beast::zero)
1153 account->setAccountID(sfAccount, accountId);
1154 account->setFieldAmount(sfBalance,
STAmount{});
1163 account->setFieldU32(sfSequence, seqno);
1167 account->setFieldU32(
1170 account->setFieldH256(ownerField, pseudoOwnerKey);
1227 auto const& issuerId = issue.
getIssuer();
1228 auto const& currency = issue.
currency;
1232 auto const& srcId = issuerId;
1233 auto const& dstId = accountID;
1234 auto const high = srcId > dstId;
1235 auto const index =
keylet::line(srcId, dstId, currency);
1238 if (!sleDst || !sleSrc)
1243 if (view.
read(index))
1256 STAmount{Issue{currency, noAccount()}},
1257 STAmount{Issue{currency, dstId}},
1271 auto const& mptID = mptIssue.
getMptID();
1272 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1277 if (view.
peek(keylet::mptoken(mptID, accountID)))
1287 MPTID const& mptIssuanceID,
1293 auto const sleAcct = view.
peek(keylet::account(account));
1307 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1308 auto const sleMpt = view.
peek(mptokenKey);
1309 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1313 keylet::ownerDir(account),
1314 (*sleMpt)[sfOwnerNode],
1334 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1336 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1339 if (priorBalance < reserveCreate)
1342 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1344 if (
auto ter =
dirLink(view, account, mptoken))
1347 (*mptoken)[sfAccount] = account;
1348 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1349 (*mptoken)[sfFlags] = 0;
1358 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1359 if (!sleMptIssuance)
1365 if (account != (*sleMptIssuance)[sfIssuer])
1368 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1378 flagsOut &= ~lsfMPTAuthorized;
1384 if (flagsIn != flagsOut)
1385 sleMpt->setFieldU32(sfFlags, flagsOut);
1394 bool const bSrcHigh,
1400 bool const bNoRipple,
1411 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1412 << to_string(uDstAccountID) <<
", "
1415 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1416 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1419 view.
insert(sleRippleState);
1422 keylet::ownerDir(uLowAccountID),
1423 sleRippleState->key(),
1430 keylet::ownerDir(uHighAccountID),
1431 sleRippleState->key(),
1437 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1438 bool const bSetHigh = bSrcHigh ^ bSetDst;
1440 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1445 sleAccount->getAccountID(sfAccount) ==
1446 (bSetHigh ? uHighAccountID : uLowAccountID),
1447 "ripple::trustCreate : matching account ID");
1448 auto const slePeer =
1449 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1454 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1455 sleRippleState->setFieldU64(sfHighNode, *highNode);
1457 sleRippleState->setFieldAmount(
1458 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1459 sleRippleState->setFieldAmount(
1460 bSetHigh ? sfLowLimit : sfHighLimit,
1462 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1465 sleRippleState->setFieldU32(
1466 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1469 sleRippleState->setFieldU32(
1470 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1497 sleRippleState->setFieldU32(sfFlags, uFlags);
1501 sleRippleState->setFieldAmount(
1502 sfBalance, bSetHigh ? -saBalance : saBalance);
1505 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1519 auto const sle = view.
read(keylet::account(accountID));
1522 auto const balance = sle->getFieldAmount(sfBalance);
1523 if (balance.xrp() != 0)
1529 auto const line = view.
peek(keylet::line(accountID, issue));
1532 if (line->at(sfBalance)->iou() != beast::zero)
1539 auto sleLowAccount =
1540 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1553 auto sleHighAccount =
1554 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1555 if (!sleHighAccount)
1567 line->at(sfLowLimit)->getIssuer(),
1568 line->at(sfHighLimit)->getIssuer(),
1579 auto const& mptID = mptIssue.
getMptID();
1580 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1583 if (mptoken->at(sfMPTAmount) != 0)
1605 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1606 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1608 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1611 keylet::ownerDir(uLowAccountID),
1613 sleRippleState->key(),
1619 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1622 keylet::ownerDir(uHighAccountID),
1624 sleRippleState->key(),
1630 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1631 view.
erase(sleRippleState);
1641 auto offerIndex = sle->key();
1642 auto owner = sle->getAccountID(sfAccount);
1645 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1648 keylet::ownerDir(owner),
1649 sle->getFieldU64(sfOwnerNode),
1657 keylet::page(uDirectory),
1658 sle->getFieldU64(sfBookNode),
1665 if (sle->isFieldPresent(sfAdditionalBooks))
1668 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1669 "ripple::offerDelete : should be a hybrid domain offer");
1671 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1673 for (
auto const& bookDir : additionalBookDirs)
1675 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1676 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1679 keylet::page(dirIndex), dirNode, offerIndex,
false))
1711 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1712 "ripple::rippleCreditIOU : matching issuer or don't care");
1717 uSenderID != uReceiverID,
1718 "ripple::rippleCreditIOU : sender is not receiver");
1720 bool const bSenderHigh = uSenderID > uReceiverID;
1721 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1725 "ripple::rippleCreditIOU : sender is not XRP");
1728 "ripple::rippleCreditIOU : receiver is not XRP");
1731 if (
auto const sleRippleState = view.
peek(index))
1733 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1738 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1740 STAmount const saBefore = saBalance;
1742 saBalance -= saAmount;
1744 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1745 << to_string(uReceiverID)
1750 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1751 bool bDelete =
false;
1755 if (saBefore > beast::zero
1757 && saBalance <= beast::zero
1765 view.
read(keylet::account(uSenderID))->getFlags() &
1768 !sleRippleState->getFieldAmount(
1769 !bSenderHigh ? sfLowLimit : sfHighLimit)
1771 && !sleRippleState->getFieldU32(
1772 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1774 && !sleRippleState->getFieldU32(
1775 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1780 view, view.
peek(keylet::account(uSenderID)), -1, j);
1783 sleRippleState->setFieldU32(
1785 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1788 bDelete = !saBalance
1797 sleRippleState->setFieldAmount(sfBalance, saBalance);
1805 bSenderHigh ? uReceiverID : uSenderID,
1806 !bSenderHigh ? uReceiverID : uSenderID,
1810 view.
update(sleRippleState);
1814 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1819 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1821 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1824 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1861 auto const issuer = saAmount.
getIssuer();
1865 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1867 uSenderID != uReceiverID,
1868 "ripple::rippleSendIOU : sender is not receiver");
1870 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1877 saActual = saAmount;
1885 saActual = (waiveFee == WaiveTransferFee::Yes)
1889 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1890 << to_string(uReceiverID)
1898 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1923 "ripple::accountSendIOU : minimum amount and not MPT");
1929 if (!saAmount || (uSenderID == uReceiverID))
1936 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1937 << to_string(uReceiverID) <<
" : "
1941 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1952 ? view.
peek(keylet::account(uSenderID))
1955 ? view.
peek(keylet::account(uReceiverID))
1958 if (
auto stream = j.
trace())
1964 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1967 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1969 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1970 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1971 << receiver_bal <<
") : " << saAmount.
getFullText();
1976 if (sender->getFieldAmount(sfBalance) < saAmount)
1985 auto const sndBal = sender->getFieldAmount(sfBalance);
1989 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1997 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1998 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2004 if (
auto stream = j.
trace())
2010 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2013 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2015 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2016 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2017 << receiver_bal <<
") : " << saAmount.
getFullText();
2033 auto const issuer = saAmount.
getIssuer();
2034 auto sleIssuance = view.
peek(mptID);
2037 if (uSenderID == issuer)
2039 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2040 view.
update(sleIssuance);
2044 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2045 if (
auto sle = view.
peek(mptokenID))
2047 auto const amt = sle->getFieldU64(sfMPTAmount);
2048 auto const pay = saAmount.
mpt().
value();
2051 (*sle)[sfMPTAmount] = amt - pay;
2058 if (uReceiverID == issuer)
2060 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2061 auto const redeem = saAmount.
mpt().
value();
2062 if (outstanding >= redeem)
2064 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2065 view.
update(sleIssuance);
2072 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2073 if (
auto sle = view.
peek(mptokenID))
2075 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2096 uSenderID != uReceiverID,
2097 "ripple::rippleSendMPT : sender is not receiver");
2100 auto const issuer = saAmount.
getIssuer();
2107 if (uSenderID == issuer || uReceiverID == issuer)
2111 if (uSenderID == issuer)
2113 auto const sendAmount = saAmount.
mpt().
value();
2114 auto const maximumAmount =
2116 if (sendAmount > maximumAmount ||
2117 sle->getFieldU64(sfOutstandingAmount) >
2118 maximumAmount - sendAmount)
2127 saActual = saAmount;
2132 saActual = (waiveFee == WaiveTransferFee::Yes)
2138 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2139 << to_string(uReceiverID)
2143 if (
auto const terResult =
2162 "ripple::accountSendMPT : minimum amount and MPT");
2167 if (!saAmount || (uSenderID == uReceiverID))
2173 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2189 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2192 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2211 auto sle = view.
peek(keylet::account(sender));
2216 if (before > beast::zero
2218 &&
after <= beast::zero
2222 &&
static_cast<bool>(
2226 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2228 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2231 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2240 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2260 "ripple::issueIOU : neither account nor issuer is XRP");
2263 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2267 issue.
account != account,
"ripple::issueIOU : not issuer account");
2269 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2272 bool bSenderHigh = issue.
account > account;
2274 auto const index = keylet::line(issue.
account, account, issue.
currency);
2276 if (
auto state = view.
peek(index))
2278 STAmount final_balance = state->getFieldAmount(sfBalance);
2283 STAmount const start_balance = final_balance;
2285 final_balance -= amount;
2304 state->setFieldAmount(sfBalance, final_balance);
2309 bSenderHigh ? account : issue.
account,
2310 bSenderHigh ? issue.
account : account,
2326 auto const receiverAccount = view.
peek(keylet::account(account));
2327 if (!receiverAccount)
2360 "ripple::redeemIOU : neither account nor issuer is XRP");
2363 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2367 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2369 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2372 bool bSenderHigh = account > issue.
account;
2377 STAmount final_balance = state->getFieldAmount(sfBalance);
2382 STAmount const start_balance = final_balance;
2384 final_balance -= amount;
2387 view, state, bSenderHigh, account, start_balance, final_balance, j);
2397 state->setFieldAmount(sfBalance, final_balance);
2404 bSenderHigh ? issue.
account : account,
2405 bSenderHigh ? account : issue.
account,
2416 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2418 <<
" but no trust line exists!";
2432 from != beast::zero,
"ripple::transferXRP : nonzero from account");
2433 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
2434 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
2435 XRPL_ASSERT(amount.
native(),
"ripple::transferXRP : amount is XRP");
2439 if (!sender || !receiver)
2442 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
2443 << to_string(to) <<
") : " << amount.
getFullText();
2445 if (sender->getFieldAmount(sfBalance) < amount)
2455 sender->setFieldAmount(
2456 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2459 receiver->setFieldAmount(
2460 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2476 auto const trustLine =
2479 if (!trustLine && authType == AuthType::StrongAuth)
2484 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2488 return ((*trustLine)[sfFlags] &
2506 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2507 auto const sleIssuance = view.
read(mptID);
2511 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2514 if (mptIssuer == account)
2523 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2527 if (sleIssuer->isFieldPresent(sfVaultID))
2529 auto const sleVault =
2530 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2534 auto const asset = sleVault->at(sfAsset);
2538 return requireAuth(view, issue, account, authType);
2541 view, issue, account, authType, depth + 1);
2549 auto const mptokenID = keylet::mptoken(mptID.key, account);
2550 auto const sleToken = view.
read(mptokenID);
2554 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2559 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2564 "ripple::requireAuth : issuance requires authorization");
2566 if (
auto const ter =
2567 credentials::validDomain(view, *maybeDomainID, account);
2587 MPTID const& mptIssuanceID,
2592 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2598 "ripple::enforceMPTokenAuthorization : authorization required");
2600 if (account == sleIssuance->at(sfIssuer))
2603 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2604 auto const sleToken = view.
read(keylet);
2605 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2607 bool const authorizedByDomain = [&]() ->
bool {
2609 if (!maybeDomainID.has_value())
2620 if (!authorizedByDomain && sleToken ==
nullptr)
2631 else if (!authorizedByDomain && maybeDomainID.has_value())
2638 else if (!authorizedByDomain)
2643 sleToken !=
nullptr && !maybeDomainID.has_value(),
2644 "ripple::enforceMPTokenAuthorization : found MPToken");
2650 else if (authorizedByDomain && sleToken !=
nullptr)
2655 maybeDomainID.has_value(),
2656 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2659 else if (authorizedByDomain)
2664 maybeDomainID.has_value() && sleToken ==
nullptr,
2665 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2680 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2692 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2693 auto const sleIssuance = view.
read(mptID);
2699 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2708 Keylet const& ownerDirKeylet,
2715 unsigned int uDirEntry{0};
2716 uint256 dirEntry{beast::zero};
2719 if (view.
exists(ownerDirKeylet) &&
2720 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2724 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2728 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);
2740 sleItem->getFieldU16(sfLedgerEntryType))};
2744 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2766 "ripple::cleanupOnAccountDelete : minimum dir entries");
2770 <<
"DeleteAccount iterator re-validation failed.";
2773 if (skipEntry == SkipEntry::No)
2777 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2790 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2794 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2795 sleState->getFieldAmount(sfHighLimit).getIssuer());
2796 auto sleLow = view.
peek(keylet::account(low));
2797 auto sleHigh = view.
peek(keylet::account(high));
2798 if (!sleLow || !sleHigh)
2800 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2801 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2804 if (ammLow && ammHigh)
2808 if (!ammLow && !ammHigh)
2812 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2815 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2819 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2824 if (!(sleState->getFlags() & uFlags))
2846 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2852 "ripple::rippleCredit : not checking issuer");
2854 view, uSenderID, uReceiverID, saAmount, j);
2868 "ripple::assetsToSharesDeposit : non-negative assets");
2870 assets.
asset() == vault->at(sfAsset),
2871 "ripple::assetsToSharesDeposit : assets and vault match");
2872 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2875 Number const assetTotal = vault->at(sfAssetsTotal);
2876 STAmount shares{vault->at(sfShareMPTID)};
2877 if (assetTotal == 0)
2883 Number const shareTotal = issuance->at(sfOutstandingAmount);
2884 shares = (shareTotal * (assets / assetTotal)).truncate();
2896 "ripple::sharesToAssetsDeposit : non-negative shares");
2898 shares.
asset() == vault->at(sfShareMPTID),
2899 "ripple::sharesToAssetsDeposit : shares and vault match");
2900 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2903 Number const assetTotal = vault->at(sfAssetsTotal);
2904 STAmount assets{vault->at(sfAsset)};
2905 if (assetTotal == 0)
2909 shares.
exponent() - vault->at(sfScale),
2912 Number const shareTotal = issuance->at(sfOutstandingAmount);
2913 assets = assetTotal * (shares / shareTotal);
2926 "ripple::assetsToSharesDeposit : non-negative assets");
2928 assets.
asset() == vault->at(sfAsset),
2929 "ripple::assetsToSharesWithdraw : assets and vault match");
2930 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2933 Number assetTotal = vault->at(sfAssetsTotal);
2934 assetTotal -= vault->at(sfLossUnrealized);
2935 STAmount shares{vault->at(sfShareMPTID)};
2936 if (assetTotal == 0)
2938 Number const shareTotal = issuance->at(sfOutstandingAmount);
2939 Number result = shareTotal * (assets / assetTotal);
2940 if (truncate == TruncateShares::yes)
2954 "ripple::sharesToAssetsDeposit : non-negative shares");
2956 shares.
asset() == vault->at(sfShareMPTID),
2957 "ripple::sharesToAssetsWithdraw : shares and vault match");
2958 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2961 Number assetTotal = vault->at(sfAssetsTotal);
2962 assetTotal -= vault->at(sfLossUnrealized);
2963 STAmount assets{vault->at(sfAsset)};
2964 if (assetTotal == 0)
2966 Number const shareTotal = issuance->at(sfOutstandingAmount);
2967 assets = assetTotal * (shares / shareTotal);
2979 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2980 auto sleIssuance = view.
peek(mptID);
2983 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
2984 << mptIssue.getMptID();
2991 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
2998 auto const mptokenID = keylet::mptoken(mptID.key, sender);
2999 auto sle = view.
peek(mptokenID);
3003 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3007 auto const amt = sle->getFieldU64(sfMPTAmount);
3008 auto const pay = amount.
mpt().
value();
3014 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3015 << to_string(sender) <<
": " << amt <<
" < " << pay;
3019 (*sle)[sfMPTAmount] = amt - pay;
3022 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3027 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3028 << to_string(sender) <<
": " << locked <<
" + " << pay;
3032 if (sle->isFieldPresent(sfLockedAmount))
3033 (*sle)[sfLockedAmount] += pay;
3035 sle->setFieldU64(sfLockedAmount, pay);
3043 uint64_t
const issuanceEscrowed =
3044 (*sleIssuance)[~sfLockedAmount].value_or(0);
3045 auto const pay = amount.
mpt().
value();
3051 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3052 "locked amount for "
3053 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3058 if (sleIssuance->isFieldPresent(sfLockedAmount))
3059 (*sleIssuance)[sfLockedAmount] += pay;
3061 sleIssuance->setFieldU64(sfLockedAmount, pay);
3063 view.
update(sleIssuance);
3079 netAmount == grossAmount,
3080 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3082 auto const& issuer = netAmount.
getIssuer();
3084 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3085 auto sleIssuance = view.
peek(mptID);
3088 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3089 << mptIssue.getMptID();
3095 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3098 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3099 << mptIssue.getMptID();
3103 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3104 auto const redeem = grossAmount.
mpt().
value();
3111 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3112 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3116 auto const newLocked = locked - redeem;
3118 sleIssuance->makeFieldAbsent(sfLockedAmount);
3120 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3121 view.
update(sleIssuance);
3124 if (issuer != receiver)
3127 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3128 auto sle = view.
peek(mptokenID);
3132 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3136 auto current = sle->getFieldU64(sfMPTAmount);
3137 auto delta = netAmount.
mpt().
value();
3143 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3144 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3148 (*sle)[sfMPTAmount] += delta;
3154 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3155 auto const redeem = netAmount.
mpt().
value();
3162 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3163 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3168 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3169 view.
update(sleIssuance);
3172 if (issuer == sender)
3174 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3175 "cannot unlock MPTs.";
3181 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3182 auto sle = view.
peek(mptokenID);
3186 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3190 if (!sle->isFieldPresent(sfLockedAmount))
3193 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3194 << to_string(sender);
3198 auto const locked = sle->getFieldU64(sfLockedAmount);
3199 auto const delta = grossAmount.
mpt().
value();
3205 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3206 << to_string(sender) <<
": " << locked <<
" < " << delta;
3210 auto const newLocked = locked - delta;
3212 sle->makeFieldAbsent(sfLockedAmount);
3214 sle->setFieldU64(sfLockedAmount, newLocked);
3225 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3231 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3232 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3236 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3237 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)
@ 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)