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)
328 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null MPToken issuer");
332 if (!mptIssuer->isFieldPresent(sfVaultID))
337 if (vault ==
nullptr)
339 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null vault");
343 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
358 if (issuer == account)
400 auto const allowBalance = [&]() {
408 if (
isFrozen(view, account, currency, issuer) ||
423 else if (sleIssuer->isFieldPresent(sfAMMID))
432 (*sleAmm)[sfAsset].get<Issue>(),
433 (*sleAmm)[sfAsset2].get<Issue>()))
446 amount = sle->getFieldAmount(sfBalance);
447 if (account > issuer)
459 JLOG(j.
trace()) <<
"accountHolds:"
493 amount.
clear(mptIssue);
496 amount.
clear(mptIssue);
499 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
509 amount.
clear(mptIssue);
513 auto const sleIssuance =
520 amount.
clear(mptIssue);
527[[nodiscard]] STAmount
537 [&](
auto const& value) {
542 return accountHolds(view, account, value, zeroIfFrozen, j);
545 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
592 <<
"Account " << *
id <<
" owner count exceeds max!";
605 <<
"Account " << *
id <<
" owner count set below 0!";
608 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
627 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
634 auto const fullBalance = sle->getFieldAmount(sfBalance);
639 (balance < reserve) ?
STAmount{0} : balance - reserve;
641 JLOG(j.
trace()) <<
"accountHolds:"
644 <<
" fullBalance=" << fullBalance.getFullText()
645 <<
" balance=" << balance.getFullText()
646 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
647 <<
" ownerCountAdj=" << ownerCountAdj;
659 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
661 if (
root.type != ltDIR_NODE)
668 auto sle = view.
read(pos);
671 for (
auto const& key : sle->getFieldV256(sfIndexes))
673 auto const next = sle->getFieldU64(sfIndexNext);
690 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
692 if (
root.type != ltDIR_NODE)
695 auto currentIndex =
root;
698 if (
after.isNonZero())
702 if (
auto hintDir = view.
read(hintIndex))
704 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
709 currentIndex = hintIndex;
718 auto const ownerDir = view.
read(currentIndex);
721 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
734 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
744 auto const ownerDir = view.
read(currentIndex);
747 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
750 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
763 if (sle && sle->isFieldPresent(sfTransferRate))
764 return Rate{sle->getFieldU32(sfTransferRate)};
776 sle && sle->isFieldPresent(sfTransferFee))
777 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
811 if (hash && (*hash != validLedger.
info().
hash))
813 JLOG(s) << reason <<
" incompatible with valid ledger";
815 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
827 if (hash && (*hash != testLedger.
info().
hash))
829 JLOG(s) << reason <<
" incompatible preceding ledger";
831 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
841 JLOG(s) << reason <<
" incompatible ledger";
848 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
851 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
868 if (testLedger.
info().
seq > validIndex)
875 if (hash && (*hash != validHash))
877 JLOG(s) << reason <<
" incompatible following ledger";
878 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
884 (validIndex == testLedger.
info().
seq) &&
885 (testLedger.
info().
hash != validHash))
887 JLOG(s) << reason <<
" incompatible ledger";
894 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
896 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
906 auto const sleNode = view.
read(k);
909 if (!sleNode->getFieldV256(sfIndexes).empty())
914 return sleNode->getFieldU64(sfIndexNext) == 0;
924 if (sle->isFieldPresent(sfAmendments))
926 auto const& v = sle->getFieldV256(sfAmendments);
927 amendments.insert(v.begin(), v.end());
941 if (sle->isFieldPresent(sfMajorities))
944 using d = tp::duration;
946 auto const majorities = sle->getFieldArray(sfMajorities);
948 for (
auto const& m : majorities)
949 ret[m.getFieldH256(sfAmendment)] =
950 tp(d(m.getFieldU32(sfCloseTime)));
961 if (seq > ledger.
seq())
964 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
967 if (seq == ledger.
seq())
969 if (seq == (ledger.
seq() - 1))
972 if (
int diff = ledger.
seq() - seq; diff <= 256)
979 hashIndex->getFieldU32(sfLastLedgerSequence) ==
981 "ripple::hashOfSeq : matching ledger sequence");
982 STVector256 vec = hashIndex->getFieldV256(sfHashes);
983 if (vec.
size() >= diff)
984 return vec[vec.
size() - diff];
986 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
987 <<
" (" << vec.
size() <<
"," << diff <<
")";
992 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
993 <<
" missing normal list";
997 if ((seq & 0xff) != 0)
999 JLOG(journal.
debug())
1000 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1008 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1009 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
1011 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
1012 auto const diff = (lastSeq - seq) >> 8;
1013 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1014 if (vec.
size() > diff)
1015 return vec[vec.
size() - diff - 1];
1017 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1037 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1042 sle->at(sfOwnerCount) = adjusted;
1050 (*sle)[sfOwner] = account;
1061 object->setFieldU64(sfOwnerNode, *page);
1074 rsh(hash.data(), hash.size());
1097 "ripple::isPseudoAccount : unable to find account root ledger "
1101 auto const& soTemplate = ar->getSOTemplate();
1104 for (
auto const& field : soTemplate)
1109 return pseudoFields;
1111 return pseudoFields;
1121 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1123 fields.begin(), fields.end(), [&sleAcct](
SField const* sf) ->
bool {
1124 return sleAcct->isFieldPresent(*sf);
1128Expected<std::shared_ptr<SLE>,
TER>
1131 uint256 const& pseudoOwnerKey,
1132 SField const& ownerField)
1139 [&ownerField](
SField const* sf) ->
bool {
1140 return *sf == ownerField;
1142 "ripple::createPseudoAccount : valid owner field");
1145 if (accountId == beast::zero)
1150 account->setAccountID(sfAccount, accountId);
1151 account->setFieldAmount(sfBalance,
STAmount{});
1160 account->setFieldU32(sfSequence, seqno);
1164 account->setFieldU32(
1167 account->setFieldH256(ownerField, pseudoOwnerKey);
1224 auto const& issuerId = issue.
getIssuer();
1225 auto const& currency = issue.
currency;
1229 auto const& srcId = issuerId;
1230 auto const& dstId = accountID;
1231 auto const high = srcId > dstId;
1232 auto const index =
keylet::line(srcId, dstId, currency);
1235 if (!sleDst || !sleSrc)
1240 if (view.
read(index))
1253 STAmount{Issue{currency, noAccount()}},
1254 STAmount{Issue{currency, dstId}},
1268 auto const& mptID = mptIssue.
getMptID();
1269 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1274 if (view.
peek(keylet::mptoken(mptID, accountID)))
1284 MPTID const& mptIssuanceID,
1290 auto const sleAcct = view.
peek(keylet::account(account));
1304 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1305 auto const sleMpt = view.
peek(mptokenKey);
1306 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1310 keylet::ownerDir(account),
1311 (*sleMpt)[sfOwnerNode],
1331 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1333 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1336 if (priorBalance < reserveCreate)
1339 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1341 if (
auto ter =
dirLink(view, account, mptoken))
1344 (*mptoken)[sfAccount] = account;
1345 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1346 (*mptoken)[sfFlags] = 0;
1355 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1356 if (!sleMptIssuance)
1362 if (account != (*sleMptIssuance)[sfIssuer])
1365 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1375 flagsOut &= ~lsfMPTAuthorized;
1381 if (flagsIn != flagsOut)
1382 sleMpt->setFieldU32(sfFlags, flagsOut);
1391 bool const bSrcHigh,
1397 bool const bNoRipple,
1408 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1409 << to_string(uDstAccountID) <<
", "
1412 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1413 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1416 view.
insert(sleRippleState);
1419 keylet::ownerDir(uLowAccountID),
1420 sleRippleState->key(),
1427 keylet::ownerDir(uHighAccountID),
1428 sleRippleState->key(),
1434 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1435 bool const bSetHigh = bSrcHigh ^ bSetDst;
1437 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1442 sleAccount->getAccountID(sfAccount) ==
1443 (bSetHigh ? uHighAccountID : uLowAccountID),
1444 "ripple::trustCreate : matching account ID");
1445 auto const slePeer =
1446 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1451 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1452 sleRippleState->setFieldU64(sfHighNode, *highNode);
1454 sleRippleState->setFieldAmount(
1455 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1456 sleRippleState->setFieldAmount(
1457 bSetHigh ? sfLowLimit : sfHighLimit,
1459 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1462 sleRippleState->setFieldU32(
1463 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1466 sleRippleState->setFieldU32(
1467 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1494 sleRippleState->setFieldU32(sfFlags, uFlags);
1498 sleRippleState->setFieldAmount(
1499 sfBalance, bSetHigh ? -saBalance : saBalance);
1502 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1516 auto const sle = view.
read(keylet::account(accountID));
1519 auto const balance = sle->getFieldAmount(sfBalance);
1520 if (balance.xrp() != 0)
1526 auto const line = view.
peek(keylet::line(accountID, issue));
1529 if (line->at(sfBalance)->iou() != beast::zero)
1536 auto sleLowAccount =
1537 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1550 auto sleHighAccount =
1551 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1552 if (!sleHighAccount)
1564 line->at(sfLowLimit)->getIssuer(),
1565 line->at(sfHighLimit)->getIssuer(),
1576 auto const& mptID = mptIssue.
getMptID();
1577 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1580 if (mptoken->at(sfMPTAmount) != 0)
1602 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1603 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1605 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1608 keylet::ownerDir(uLowAccountID),
1610 sleRippleState->key(),
1616 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1619 keylet::ownerDir(uHighAccountID),
1621 sleRippleState->key(),
1627 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1628 view.
erase(sleRippleState);
1638 auto offerIndex = sle->key();
1639 auto owner = sle->getAccountID(sfAccount);
1642 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1645 keylet::ownerDir(owner),
1646 sle->getFieldU64(sfOwnerNode),
1654 keylet::page(uDirectory),
1655 sle->getFieldU64(sfBookNode),
1662 if (sle->isFieldPresent(sfAdditionalBooks))
1665 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1666 "ripple::offerDelete : should be a hybrid domain offer");
1668 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1670 for (
auto const& bookDir : additionalBookDirs)
1672 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1673 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1676 keylet::page(dirIndex), dirNode, offerIndex,
false))
1708 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1709 "ripple::rippleCreditIOU : matching issuer or don't care");
1714 uSenderID != uReceiverID,
1715 "ripple::rippleCreditIOU : sender is not receiver");
1717 bool const bSenderHigh = uSenderID > uReceiverID;
1718 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1722 "ripple::rippleCreditIOU : sender is not XRP");
1725 "ripple::rippleCreditIOU : receiver is not XRP");
1728 if (
auto const sleRippleState = view.
peek(index))
1730 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1735 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1737 STAmount const saBefore = saBalance;
1739 saBalance -= saAmount;
1741 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1742 << to_string(uReceiverID)
1747 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1748 bool bDelete =
false;
1752 if (saBefore > beast::zero
1754 && saBalance <= beast::zero
1762 view.
read(keylet::account(uSenderID))->getFlags() &
1765 !sleRippleState->getFieldAmount(
1766 !bSenderHigh ? sfLowLimit : sfHighLimit)
1768 && !sleRippleState->getFieldU32(
1769 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1771 && !sleRippleState->getFieldU32(
1772 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1777 view, view.
peek(keylet::account(uSenderID)), -1, j);
1780 sleRippleState->setFieldU32(
1782 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1785 bDelete = !saBalance
1794 sleRippleState->setFieldAmount(sfBalance, saBalance);
1802 bSenderHigh ? uReceiverID : uSenderID,
1803 !bSenderHigh ? uReceiverID : uSenderID,
1807 view.
update(sleRippleState);
1811 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1816 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1818 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1821 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1858 auto const issuer = saAmount.
getIssuer();
1862 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1864 uSenderID != uReceiverID,
1865 "ripple::rippleSendIOU : sender is not receiver");
1867 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1874 saActual = saAmount;
1882 saActual = (waiveFee == WaiveTransferFee::Yes)
1886 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1887 << to_string(uReceiverID)
1895 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1920 "ripple::accountSendIOU : minimum amount and not MPT");
1926 if (!saAmount || (uSenderID == uReceiverID))
1933 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1934 << to_string(uReceiverID) <<
" : "
1938 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1949 ? view.
peek(keylet::account(uSenderID))
1952 ? view.
peek(keylet::account(uReceiverID))
1955 if (
auto stream = j.
trace())
1961 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1964 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1966 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1967 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1968 << receiver_bal <<
") : " << saAmount.
getFullText();
1973 if (sender->getFieldAmount(sfBalance) < saAmount)
1982 auto const sndBal = sender->getFieldAmount(sfBalance);
1986 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1994 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1995 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
2001 if (
auto stream = j.
trace())
2007 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
2010 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
2012 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
2013 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
2014 << receiver_bal <<
") : " << saAmount.
getFullText();
2030 auto const issuer = saAmount.
getIssuer();
2031 auto sleIssuance = view.
peek(mptID);
2034 if (uSenderID == issuer)
2036 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
2037 view.
update(sleIssuance);
2041 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
2042 if (
auto sle = view.
peek(mptokenID))
2044 auto const amt = sle->getFieldU64(sfMPTAmount);
2045 auto const pay = saAmount.
mpt().
value();
2048 (*sle)[sfMPTAmount] = amt - pay;
2055 if (uReceiverID == issuer)
2057 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
2058 auto const redeem = saAmount.
mpt().
value();
2059 if (outstanding >= redeem)
2061 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2062 view.
update(sleIssuance);
2069 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2070 if (
auto sle = view.
peek(mptokenID))
2072 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2093 uSenderID != uReceiverID,
2094 "ripple::rippleSendMPT : sender is not receiver");
2097 auto const issuer = saAmount.
getIssuer();
2104 if (uSenderID == issuer || uReceiverID == issuer)
2108 if (uSenderID == issuer)
2110 auto const sendAmount = saAmount.
mpt().
value();
2111 auto const maximumAmount =
2113 if (sendAmount > maximumAmount ||
2114 sle->getFieldU64(sfOutstandingAmount) >
2115 maximumAmount - sendAmount)
2124 saActual = saAmount;
2129 saActual = (waiveFee == WaiveTransferFee::Yes)
2135 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2136 << to_string(uReceiverID)
2140 if (
auto const terResult =
2159 "ripple::accountSendMPT : minimum amount and MPT");
2164 if (!saAmount || (uSenderID == uReceiverID))
2170 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2186 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2189 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2208 auto sle = view.
peek(keylet::account(sender));
2213 if (before > beast::zero
2215 &&
after <= beast::zero
2219 &&
static_cast<bool>(
2223 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2225 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2228 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2237 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2257 "ripple::issueIOU : neither account nor issuer is XRP");
2260 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2264 issue.
account != account,
"ripple::issueIOU : not issuer account");
2266 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2269 bool bSenderHigh = issue.
account > account;
2271 auto const index = keylet::line(issue.
account, account, issue.
currency);
2273 if (
auto state = view.
peek(index))
2275 STAmount final_balance = state->getFieldAmount(sfBalance);
2280 STAmount const start_balance = final_balance;
2282 final_balance -= amount;
2301 state->setFieldAmount(sfBalance, final_balance);
2306 bSenderHigh ? account : issue.
account,
2307 bSenderHigh ? issue.
account : account,
2323 auto const receiverAccount = view.
peek(keylet::account(account));
2324 if (!receiverAccount)
2357 "ripple::redeemIOU : neither account nor issuer is XRP");
2360 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2364 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2366 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2369 bool bSenderHigh = account > issue.
account;
2374 STAmount final_balance = state->getFieldAmount(sfBalance);
2379 STAmount const start_balance = final_balance;
2381 final_balance -= amount;
2384 view, state, bSenderHigh, account, start_balance, final_balance, j);
2394 state->setFieldAmount(sfBalance, final_balance);
2401 bSenderHigh ? issue.
account : account,
2402 bSenderHigh ? account : issue.
account,
2413 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2415 <<
" 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)
2452 sender->setFieldAmount(
2453 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2456 receiver->setFieldAmount(
2457 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2473 auto const trustLine =
2476 if (!trustLine && authType == AuthType::StrongAuth)
2481 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2485 return ((*trustLine)[sfFlags] &
2503 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2504 auto const sleIssuance = view.
read(mptID);
2508 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2511 if (mptIssuer == account)
2520 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2524 if (sleIssuer->isFieldPresent(sfVaultID))
2526 auto const sleVault =
2527 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2531 auto const asset = sleVault->at(sfAsset);
2535 return requireAuth(view, issue, account, authType);
2538 view, issue, account, authType, depth + 1);
2546 auto const mptokenID = keylet::mptoken(mptID.key, account);
2547 auto const sleToken = view.
read(mptokenID);
2551 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2556 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2561 "ripple::requireAuth : issuance requires authorization");
2563 if (
auto const ter =
2564 credentials::validDomain(view, *maybeDomainID, account);
2584 MPTID const& mptIssuanceID,
2589 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2595 "ripple::enforceMPTokenAuthorization : authorization required");
2597 if (account == sleIssuance->at(sfIssuer))
2600 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2601 auto const sleToken = view.
read(keylet);
2602 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2604 bool const authorizedByDomain = [&]() ->
bool {
2606 if (!maybeDomainID.has_value())
2617 if (!authorizedByDomain && sleToken ==
nullptr)
2628 else if (!authorizedByDomain && maybeDomainID.has_value())
2635 else if (!authorizedByDomain)
2640 sleToken !=
nullptr && !maybeDomainID.has_value(),
2641 "ripple::enforceMPTokenAuthorization : found MPToken");
2647 else if (authorizedByDomain && sleToken !=
nullptr)
2652 maybeDomainID.has_value(),
2653 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2656 else if (authorizedByDomain)
2661 maybeDomainID.has_value() && sleToken ==
nullptr,
2662 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2677 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2688 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2689 auto const sleIssuance = view.
read(mptID);
2695 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2704 Keylet const& ownerDirKeylet,
2711 unsigned int uDirEntry{0};
2712 uint256 dirEntry{beast::zero};
2715 if (view.
exists(ownerDirKeylet) &&
2716 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2720 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2724 auto sleItem = view.
peek(keylet::child(dirEntry));
2729 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
2730 <<
" has index to object that is missing: "
2731 << to_string(dirEntry);
2736 sleItem->getFieldU16(sfLedgerEntryType))};
2740 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2762 "ripple::cleanupOnAccountDelete : minimum dir entries");
2766 <<
"DeleteAccount iterator re-validation failed.";
2769 if (skipEntry == SkipEntry::No)
2773 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2786 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2790 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2791 sleState->getFieldAmount(sfHighLimit).getIssuer());
2792 auto sleLow = view.
peek(keylet::account(low));
2793 auto sleHigh = view.
peek(keylet::account(high));
2794 if (!sleLow || !sleHigh)
2796 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2797 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2800 if (ammLow && ammHigh)
2804 if (!ammLow && !ammHigh)
2808 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2811 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2815 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2820 if (!(sleState->getFlags() & uFlags))
2842 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2848 "ripple::rippleCredit : not checking issuer");
2850 view, uSenderID, uReceiverID, saAmount, j);
2864 "ripple::assetsToSharesDeposit : non-negative assets");
2866 assets.
asset() == vault->at(sfAsset),
2867 "ripple::assetsToSharesDeposit : assets and vault match");
2868 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2871 Number const assetTotal = vault->at(sfAssetsTotal);
2872 STAmount shares{vault->at(sfShareMPTID)};
2873 if (assetTotal == 0)
2879 Number const shareTotal = issuance->at(sfOutstandingAmount);
2880 shares = (shareTotal * (assets / assetTotal)).truncate();
2892 "ripple::sharesToAssetsDeposit : non-negative shares");
2894 shares.
asset() == vault->at(sfShareMPTID),
2895 "ripple::sharesToAssetsDeposit : shares and vault match");
2896 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2899 Number const assetTotal = vault->at(sfAssetsTotal);
2900 STAmount assets{vault->at(sfAsset)};
2901 if (assetTotal == 0)
2905 shares.
exponent() - vault->at(sfScale),
2908 Number const shareTotal = issuance->at(sfOutstandingAmount);
2909 assets = assetTotal * (shares / shareTotal);
2922 "ripple::assetsToSharesDeposit : non-negative assets");
2924 assets.
asset() == vault->at(sfAsset),
2925 "ripple::assetsToSharesWithdraw : assets and vault match");
2926 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2929 Number assetTotal = vault->at(sfAssetsTotal);
2930 assetTotal -= vault->at(sfLossUnrealized);
2931 STAmount shares{vault->at(sfShareMPTID)};
2932 if (assetTotal == 0)
2934 Number const shareTotal = issuance->at(sfOutstandingAmount);
2935 Number result = shareTotal * (assets / assetTotal);
2936 if (truncate == TruncateShares::yes)
2950 "ripple::sharesToAssetsDeposit : non-negative shares");
2952 shares.
asset() == vault->at(sfShareMPTID),
2953 "ripple::sharesToAssetsWithdraw : shares and vault match");
2954 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2957 Number assetTotal = vault->at(sfAssetsTotal);
2958 assetTotal -= vault->at(sfLossUnrealized);
2959 STAmount assets{vault->at(sfAsset)};
2960 if (assetTotal == 0)
2962 Number const shareTotal = issuance->at(sfOutstandingAmount);
2963 assets = assetTotal * (shares / shareTotal);
2975 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2976 auto sleIssuance = view.
peek(mptID);
2979 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
2980 << mptIssue.getMptID();
2987 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
2994 auto const mptokenID = keylet::mptoken(mptID.key, sender);
2995 auto sle = view.
peek(mptokenID);
2999 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
3003 auto const amt = sle->getFieldU64(sfMPTAmount);
3004 auto const pay = amount.
mpt().
value();
3010 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
3011 << to_string(sender) <<
": " << amt <<
" < " << pay;
3015 (*sle)[sfMPTAmount] = amt - pay;
3018 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
3023 <<
"rippleLockEscrowMPT: overflow on locked amount for "
3024 << to_string(sender) <<
": " << locked <<
" + " << pay;
3028 if (sle->isFieldPresent(sfLockedAmount))
3029 (*sle)[sfLockedAmount] += pay;
3031 sle->setFieldU64(sfLockedAmount, pay);
3039 uint64_t
const issuanceEscrowed =
3040 (*sleIssuance)[~sfLockedAmount].value_or(0);
3041 auto const pay = amount.
mpt().
value();
3047 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
3048 "locked amount for "
3049 << mptIssue.getMptID() <<
": " << issuanceEscrowed
3054 if (sleIssuance->isFieldPresent(sfLockedAmount))
3055 (*sleIssuance)[sfLockedAmount] += pay;
3057 sleIssuance->setFieldU64(sfLockedAmount, pay);
3059 view.
update(sleIssuance);
3075 netAmount == grossAmount,
3076 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3078 auto const& issuer = netAmount.
getIssuer();
3080 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3081 auto sleIssuance = view.
peek(mptID);
3084 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3085 << mptIssue.getMptID();
3091 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3094 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3095 << mptIssue.getMptID();
3099 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3100 auto const redeem = grossAmount.
mpt().
value();
3107 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3108 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3112 auto const newLocked = locked - redeem;
3114 sleIssuance->makeFieldAbsent(sfLockedAmount);
3116 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3117 view.
update(sleIssuance);
3120 if (issuer != receiver)
3123 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3124 auto sle = view.
peek(mptokenID);
3128 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3132 auto current = sle->getFieldU64(sfMPTAmount);
3133 auto delta = netAmount.
mpt().
value();
3139 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3140 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3144 (*sle)[sfMPTAmount] += delta;
3150 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3151 auto const redeem = netAmount.
mpt().
value();
3158 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3159 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3164 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3165 view.
update(sleIssuance);
3168 if (issuer == sender)
3170 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3171 "cannot unlock MPTs.";
3177 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3178 auto sle = view.
peek(mptokenID);
3182 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3186 if (!sle->isFieldPresent(sfLockedAmount))
3189 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3190 << to_string(sender);
3194 auto const locked = sle->getFieldU64(sfLockedAmount);
3195 auto const delta = grossAmount.
mpt().
value();
3201 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3202 << to_string(sender) <<
": " << locked <<
" < " << delta;
3206 auto const newLocked = locked - delta;
3208 sle->makeFieldAbsent(sfLockedAmount);
3210 sle->setFieldU64(sfLockedAmount, newLocked);
3221 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3227 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3228 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3232 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3233 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)