20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/ledger/ReadView.h>
22#include <xrpld/ledger/View.h>
24#include <xrpl/basics/Expected.h>
25#include <xrpl/basics/Log.h>
26#include <xrpl/basics/chrono.h>
27#include <xrpl/beast/utility/instrumentation.h>
28#include <xrpl/protocol/Feature.h>
29#include <xrpl/protocol/Indexes.h>
30#include <xrpl/protocol/LedgerFormats.h>
31#include <xrpl/protocol/MPTIssue.h>
32#include <xrpl/protocol/Protocol.h>
33#include <xrpl/protocol/Quality.h>
34#include <xrpl/protocol/TER.h>
35#include <xrpl/protocol/TxFlags.h>
36#include <xrpl/protocol/digest.h>
37#include <xrpl/protocol/st.h>
60 auto const& svIndexes = page->getFieldV256(sfIndexes);
62 index <= svIndexes.size(),
63 "ripple::detail::internalDirNext : index inside range");
65 if (index >= svIndexes.size())
67 auto const next = page->getFieldU64(sfIndexNext);
80 XRPL_ASSERT(page,
"ripple::detail::internalDirNext : non-null root");
90 entry = svIndexes[index++];
222 if (issuer != account)
259 if (issuer != account)
292 for (
auto const& account : accounts)
298 for (
auto const& account : accounts)
320 auto const mptIssuance =
322 if (mptIssuance ==
nullptr)
325 auto const issuer = mptIssuance->getAccountID(sfIssuer);
327 if (mptIssuer ==
nullptr)
329 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null MPToken issuer");
333 if (!mptIssuer->isFieldPresent(sfVaultID))
338 if (vault ==
nullptr)
340 UNREACHABLE(
"ripple::isVaultPseudoAccountFrozen : null vault");
344 return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1);
359 if (issuer == account)
401 auto const allowBalance = [&]() {
409 if (
isFrozen(view, account, currency, issuer) ||
424 else if (sleIssuer->isFieldPresent(sfAMMID))
433 (*sleAmm)[sfAsset].get<Issue>(),
434 (*sleAmm)[sfAsset2].get<Issue>()))
447 amount = sle->getFieldAmount(sfBalance);
448 if (account > issuer)
460 JLOG(j.
trace()) <<
"accountHolds:"
494 amount.
clear(mptIssue);
497 amount.
clear(mptIssue);
500 amount =
STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)};
510 amount.
clear(mptIssue);
514 auto const sleIssuance =
521 amount.
clear(mptIssue);
528[[nodiscard]] STAmount
538 [&](
auto const& value) {
543 return accountHolds(view, account, value, zeroIfFrozen, j);
546 view, account, value, zeroIfFrozen, zeroIfUnauthorized, j);
593 <<
"Account " << *
id <<
" owner count exceeds max!";
606 <<
"Account " << *
id <<
" owner count set below 0!";
609 XRPL_ASSERT(!
id,
"ripple::confineOwnerCount : id is not set");
628 view.
ownerCountHook(
id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
631 auto const reserve = sle->isFieldPresent(sfAMMID)
635 auto const fullBalance = sle->getFieldAmount(sfBalance);
640 (balance < reserve) ?
STAmount{0} : balance - reserve;
642 JLOG(j.
trace()) <<
"accountHolds:"
645 <<
" fullBalance=" << fullBalance.getFullText()
646 <<
" balance=" << balance.getFullText()
647 <<
" reserve=" << reserve <<
" ownerCount=" << ownerCount
648 <<
" ownerCountAdj=" << ownerCountAdj;
660 root.type == ltDIR_NODE,
"ripple::forEachItem : valid root type");
662 if (
root.type != ltDIR_NODE)
669 auto sle = view.
read(pos);
672 for (
auto const& key : sle->getFieldV256(sfIndexes))
674 auto const next = sle->getFieldU64(sfIndexNext);
691 root.type == ltDIR_NODE,
"ripple::forEachItemAfter : valid root type");
693 if (
root.type != ltDIR_NODE)
696 auto currentIndex =
root;
699 if (
after.isNonZero())
703 if (
auto hintDir = view.
read(hintIndex))
705 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
710 currentIndex = hintIndex;
719 auto const ownerDir = view.
read(currentIndex);
722 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
735 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
745 auto const ownerDir = view.
read(currentIndex);
748 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
751 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
764 if (sle && sle->isFieldPresent(sfTransferRate))
765 return Rate{sle->getFieldU32(sfTransferRate)};
777 sle && sle->isFieldPresent(sfTransferFee))
778 return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
812 if (hash && (*hash != validLedger.
info().
hash))
814 JLOG(s) << reason <<
" incompatible with valid ledger";
816 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
828 if (hash && (*hash != testLedger.
info().
hash))
830 JLOG(s) << reason <<
" incompatible preceding ledger";
832 JLOG(s) <<
"Hash(NSeq): " <<
to_string(*hash);
842 JLOG(s) << reason <<
" incompatible ledger";
849 JLOG(s) <<
"Val: " << validLedger.
info().
seq <<
" "
852 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
869 if (testLedger.
info().
seq > validIndex)
876 if (hash && (*hash != validHash))
878 JLOG(s) << reason <<
" incompatible following ledger";
879 JLOG(s) <<
"Hash(VSeq): " <<
to_string(*hash);
885 (validIndex == testLedger.
info().
seq) &&
886 (testLedger.
info().
hash != validHash))
888 JLOG(s) << reason <<
" incompatible ledger";
895 JLOG(s) <<
"Val: " << validIndex <<
" " <<
to_string(validHash);
897 JLOG(s) <<
"New: " << testLedger.
info().
seq <<
" "
907 auto const sleNode = view.
read(k);
910 if (!sleNode->getFieldV256(sfIndexes).empty())
915 return sleNode->getFieldU64(sfIndexNext) == 0;
925 if (sle->isFieldPresent(sfAmendments))
927 auto const& v = sle->getFieldV256(sfAmendments);
928 amendments.insert(v.begin(), v.end());
942 if (sle->isFieldPresent(sfMajorities))
945 using d = tp::duration;
947 auto const majorities = sle->getFieldArray(sfMajorities);
949 for (
auto const& m : majorities)
950 ret[m.getFieldH256(sfAmendment)] =
951 tp(d(m.getFieldU32(sfCloseTime)));
962 if (seq > ledger.
seq())
965 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" future";
968 if (seq == ledger.
seq())
970 if (seq == (ledger.
seq() - 1))
973 if (
int diff = ledger.
seq() - seq; diff <= 256)
980 hashIndex->getFieldU32(sfLastLedgerSequence) ==
982 "ripple::hashOfSeq : matching ledger sequence");
983 STVector256 vec = hashIndex->getFieldV256(sfHashes);
984 if (vec.
size() >= diff)
985 return vec[vec.
size() - diff];
987 <<
"Ledger " << ledger.
seq() <<
" missing hash for " << seq
988 <<
" (" << vec.
size() <<
"," << diff <<
")";
993 <<
"Ledger " << ledger.
seq() <<
":" << ledger.
info().
hash
994 <<
" missing normal list";
998 if ((seq & 0xff) != 0)
1000 JLOG(journal.
debug())
1001 <<
"Can't get seq " << seq <<
" from " << ledger.
seq() <<
" past";
1009 auto const lastSeq = hashIndex->getFieldU32(sfLastLedgerSequence);
1010 XRPL_ASSERT(lastSeq >= seq,
"ripple::hashOfSeq : minimum last ledger");
1012 (lastSeq & 0xff) == 0,
"ripple::hashOfSeq : valid last ledger");
1013 auto const diff = (lastSeq - seq) >> 8;
1014 STVector256 vec = hashIndex->getFieldV256(sfHashes);
1015 if (vec.
size() > diff)
1016 return vec[vec.
size() - diff - 1];
1018 JLOG(journal.
warn()) <<
"Can't get seq " << seq <<
" from " << ledger.
seq()
1038 XRPL_ASSERT(amount,
"ripple::adjustOwnerCount : nonzero amount input");
1043 sle->setFieldU32(sfOwnerCount, adjusted);
1051 (*sle)[sfOwner] = account;
1062 object->setFieldU64(sfOwnerNode, *page);
1075 rsh(hash.data(), hash.size());
1093Expected<std::shared_ptr<SLE>,
TER>
1096 uint256 const& pseudoOwnerKey,
1097 SField const& ownerField)
1103 [&ownerField](
SField const* sf) ->
bool {
1104 return *sf == ownerField;
1106 "ripple::createPseudoAccount : valid owner field");
1109 if (accountId == beast::zero)
1114 account->setAccountID(sfAccount, accountId);
1115 account->setFieldAmount(sfBalance,
STAmount{});
1124 account->setFieldU32(sfSequence, seqno);
1128 account->setFieldU32(
1131 account->setFieldH256(ownerField, pseudoOwnerKey);
1143 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1147 [&sleAcct](
SField const* sf) ->
bool {
1148 return sleAcct->isFieldPresent(*sf);
1164 auto const& issuerId = issue.
getIssuer();
1165 auto const& currency = issue.
currency;
1169 auto const& srcId = issuerId;
1170 auto const& dstId = accountID;
1171 auto const high = srcId > dstId;
1172 auto const index =
keylet::line(srcId, dstId, currency);
1175 if (!sleDst || !sleSrc)
1180 if (view.
read(index))
1193 STAmount{Issue{currency, noAccount()}},
1194 STAmount{Issue{currency, dstId}},
1208 auto const& mptID = mptIssue.
getMptID();
1209 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1214 if (view.
peek(keylet::mptoken(mptID, accountID)))
1224 MPTID const& mptIssuanceID,
1230 auto const sleAcct = view.
peek(keylet::account(account));
1244 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1245 auto const sleMpt = view.
peek(mptokenKey);
1246 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1250 keylet::ownerDir(account),
1251 (*sleMpt)[sfOwnerNode],
1271 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1273 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1276 if (priorBalance < reserveCreate)
1279 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1281 if (
auto ter =
dirLink(view, account, mptoken))
1284 (*mptoken)[sfAccount] = account;
1285 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1286 (*mptoken)[sfFlags] = 0;
1295 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1296 if (!sleMptIssuance)
1302 if (account != (*sleMptIssuance)[sfIssuer])
1305 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1315 flagsOut &= ~lsfMPTAuthorized;
1321 if (flagsIn != flagsOut)
1322 sleMpt->setFieldU32(sfFlags, flagsOut);
1331 bool const bSrcHigh,
1337 bool const bNoRipple,
1348 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1349 << to_string(uDstAccountID) <<
", "
1352 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1353 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1356 view.
insert(sleRippleState);
1359 keylet::ownerDir(uLowAccountID),
1360 sleRippleState->key(),
1367 keylet::ownerDir(uHighAccountID),
1368 sleRippleState->key(),
1374 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1375 bool const bSetHigh = bSrcHigh ^ bSetDst;
1377 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1382 sleAccount->getAccountID(sfAccount) ==
1383 (bSetHigh ? uHighAccountID : uLowAccountID),
1384 "ripple::trustCreate : matching account ID");
1385 auto const slePeer =
1386 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1391 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1392 sleRippleState->setFieldU64(sfHighNode, *highNode);
1394 sleRippleState->setFieldAmount(
1395 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1396 sleRippleState->setFieldAmount(
1397 bSetHigh ? sfLowLimit : sfHighLimit,
1399 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1402 sleRippleState->setFieldU32(
1403 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1406 sleRippleState->setFieldU32(
1407 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1434 sleRippleState->setFieldU32(sfFlags, uFlags);
1438 sleRippleState->setFieldAmount(
1439 sfBalance, bSetHigh ? -saBalance : saBalance);
1442 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1456 auto const sle = view.
read(keylet::account(accountID));
1459 auto const balance = sle->getFieldAmount(sfBalance);
1460 if (balance.xrp() != 0)
1466 auto const line = view.
peek(keylet::line(accountID, issue));
1469 if (line->at(sfBalance)->iou() != beast::zero)
1476 auto sleLowAccount =
1477 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1490 auto sleHighAccount =
1491 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1492 if (!sleHighAccount)
1504 line->at(sfLowLimit)->getIssuer(),
1505 line->at(sfHighLimit)->getIssuer(),
1516 auto const& mptID = mptIssue.
getMptID();
1517 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1520 if (mptoken->at(sfMPTAmount) != 0)
1542 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1543 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1545 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1548 keylet::ownerDir(uLowAccountID),
1550 sleRippleState->key(),
1556 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1559 keylet::ownerDir(uHighAccountID),
1561 sleRippleState->key(),
1567 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1568 view.
erase(sleRippleState);
1578 auto offerIndex = sle->key();
1579 auto owner = sle->getAccountID(sfAccount);
1582 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1585 keylet::ownerDir(owner),
1586 sle->getFieldU64(sfOwnerNode),
1594 keylet::page(uDirectory),
1595 sle->getFieldU64(sfBookNode),
1602 if (sle->isFieldPresent(sfAdditionalBooks))
1605 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1606 "ripple::offerDelete : should be a hybrid domain offer");
1608 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1610 for (
auto const& bookDir : additionalBookDirs)
1612 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1613 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1616 keylet::page(dirIndex), dirNode, offerIndex,
false))
1648 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1649 "ripple::rippleCreditIOU : matching issuer or don't care");
1654 uSenderID != uReceiverID,
1655 "ripple::rippleCreditIOU : sender is not receiver");
1657 bool const bSenderHigh = uSenderID > uReceiverID;
1658 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1662 "ripple::rippleCreditIOU : sender is not XRP");
1665 "ripple::rippleCreditIOU : receiver is not XRP");
1668 if (
auto const sleRippleState = view.
peek(index))
1670 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1675 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1677 STAmount const saBefore = saBalance;
1679 saBalance -= saAmount;
1681 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1682 << to_string(uReceiverID)
1687 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1688 bool bDelete =
false;
1692 if (saBefore > beast::zero
1694 && saBalance <= beast::zero
1702 view.
read(keylet::account(uSenderID))->getFlags() &
1705 !sleRippleState->getFieldAmount(
1706 !bSenderHigh ? sfLowLimit : sfHighLimit)
1708 && !sleRippleState->getFieldU32(
1709 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1711 && !sleRippleState->getFieldU32(
1712 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1717 view, view.
peek(keylet::account(uSenderID)), -1, j);
1720 sleRippleState->setFieldU32(
1722 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1725 bDelete = !saBalance
1734 sleRippleState->setFieldAmount(sfBalance, saBalance);
1742 bSenderHigh ? uReceiverID : uSenderID,
1743 !bSenderHigh ? uReceiverID : uSenderID,
1747 view.
update(sleRippleState);
1751 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1756 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1758 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1761 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1798 auto const issuer = saAmount.
getIssuer();
1802 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1804 uSenderID != uReceiverID,
1805 "ripple::rippleSendIOU : sender is not receiver");
1807 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1814 saActual = saAmount;
1822 saActual = (waiveFee == WaiveTransferFee::Yes)
1826 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1827 << to_string(uReceiverID)
1835 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1860 "ripple::accountSendIOU : minimum amount and not MPT");
1866 if (!saAmount || (uSenderID == uReceiverID))
1873 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1874 << to_string(uReceiverID) <<
" : "
1878 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1889 ? view.
peek(keylet::account(uSenderID))
1892 ? view.
peek(keylet::account(uReceiverID))
1895 if (
auto stream = j.
trace())
1901 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1904 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1906 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1907 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1908 << receiver_bal <<
") : " << saAmount.
getFullText();
1913 if (sender->getFieldAmount(sfBalance) < saAmount)
1922 auto const sndBal = sender->getFieldAmount(sfBalance);
1926 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1934 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1935 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
1941 if (
auto stream = j.
trace())
1947 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1950 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1952 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
1953 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1954 << receiver_bal <<
") : " << saAmount.
getFullText();
1970 auto const issuer = saAmount.
getIssuer();
1971 auto sleIssuance = view.
peek(mptID);
1974 if (uSenderID == issuer)
1976 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
1977 view.
update(sleIssuance);
1981 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
1982 if (
auto sle = view.
peek(mptokenID))
1984 auto const amt = sle->getFieldU64(sfMPTAmount);
1985 auto const pay = saAmount.
mpt().
value();
1988 (*sle)[sfMPTAmount] = amt - pay;
1995 if (uReceiverID == issuer)
1997 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
1998 auto const redeem = saAmount.
mpt().
value();
1999 if (outstanding >= redeem)
2001 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2002 view.
update(sleIssuance);
2009 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2010 if (
auto sle = view.
peek(mptokenID))
2012 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2033 uSenderID != uReceiverID,
2034 "ripple::rippleSendMPT : sender is not receiver");
2037 auto const issuer = saAmount.
getIssuer();
2044 if (uSenderID == issuer || uReceiverID == issuer)
2048 if (uSenderID == issuer)
2050 auto const sendAmount = saAmount.
mpt().
value();
2051 auto const maximumAmount =
2053 if (sendAmount > maximumAmount ||
2054 sle->getFieldU64(sfOutstandingAmount) >
2055 maximumAmount - sendAmount)
2064 saActual = saAmount;
2069 saActual = (waiveFee == WaiveTransferFee::Yes)
2075 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2076 << to_string(uReceiverID)
2080 if (
auto const terResult =
2099 "ripple::accountSendMPT : minimum amount and MPT");
2104 if (!saAmount || (uSenderID == uReceiverID))
2110 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2126 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2129 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2148 auto sle = view.
peek(keylet::account(sender));
2153 if (before > beast::zero
2155 &&
after <= beast::zero
2159 &&
static_cast<bool>(
2163 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2165 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2168 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2177 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2197 "ripple::issueIOU : neither account nor issuer is XRP");
2200 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2204 issue.
account != account,
"ripple::issueIOU : not issuer account");
2206 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2209 bool bSenderHigh = issue.
account > account;
2211 auto const index = keylet::line(issue.
account, account, issue.
currency);
2213 if (
auto state = view.
peek(index))
2215 STAmount final_balance = state->getFieldAmount(sfBalance);
2220 STAmount const start_balance = final_balance;
2222 final_balance -= amount;
2241 state->setFieldAmount(sfBalance, final_balance);
2246 bSenderHigh ? account : issue.
account,
2247 bSenderHigh ? issue.
account : account,
2263 auto const receiverAccount = view.
peek(keylet::account(account));
2264 if (!receiverAccount)
2297 "ripple::redeemIOU : neither account nor issuer is XRP");
2300 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2304 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2306 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2309 bool bSenderHigh = account > issue.
account;
2314 STAmount final_balance = state->getFieldAmount(sfBalance);
2319 STAmount const start_balance = final_balance;
2321 final_balance -= amount;
2324 view, state, bSenderHigh, account, start_balance, final_balance, j);
2334 state->setFieldAmount(sfBalance, final_balance);
2341 bSenderHigh ? issue.
account : account,
2342 bSenderHigh ? account : issue.
account,
2353 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2355 <<
" but no trust line exists!";
2369 from != beast::zero,
"ripple::transferXRP : nonzero from account");
2370 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
2371 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
2372 XRPL_ASSERT(amount.
native(),
"ripple::transferXRP : amount is XRP");
2376 if (!sender || !receiver)
2379 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
2380 << to_string(to) <<
") : " << amount.
getFullText();
2382 if (sender->getFieldAmount(sfBalance) < amount)
2392 sender->setFieldAmount(
2393 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2396 receiver->setFieldAmount(
2397 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2413 auto const trustLine =
2416 if (!trustLine && authType == AuthType::StrongAuth)
2421 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2425 return ((*trustLine)[sfFlags] &
2443 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2444 auto const sleIssuance = view.
read(mptID);
2448 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2451 if (mptIssuer == account)
2460 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2464 if (sleIssuer->isFieldPresent(sfVaultID))
2466 auto const sleVault =
2467 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2471 auto const asset = sleVault->at(sfAsset);
2475 return requireAuth(view, issue, account, authType);
2478 view, issue, account, authType, depth + 1);
2486 auto const mptokenID = keylet::mptoken(mptID.key, account);
2487 auto const sleToken = view.
read(mptokenID);
2491 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2496 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2501 "ripple::requireAuth : issuance requires authorization");
2503 if (
auto const ter =
2504 credentials::validDomain(view, *maybeDomainID, account);
2524 MPTID const& mptIssuanceID,
2529 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2535 "ripple::enforceMPTokenAuthorization : authorization required");
2537 if (account == sleIssuance->at(sfIssuer))
2540 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2541 auto const sleToken = view.
read(keylet);
2542 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2544 bool const authorizedByDomain = [&]() ->
bool {
2546 if (!maybeDomainID.has_value())
2557 if (!authorizedByDomain && sleToken ==
nullptr)
2568 else if (!authorizedByDomain && maybeDomainID.has_value())
2575 else if (!authorizedByDomain)
2580 sleToken !=
nullptr && !maybeDomainID.has_value(),
2581 "ripple::enforceMPTokenAuthorization : found MPToken");
2587 else if (authorizedByDomain && sleToken !=
nullptr)
2592 maybeDomainID.has_value(),
2593 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2596 else if (authorizedByDomain)
2601 maybeDomainID.has_value() && sleToken ==
nullptr,
2602 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2617 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2628 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2629 auto const sleIssuance = view.
read(mptID);
2635 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2644 Keylet const& ownerDirKeylet,
2651 unsigned int uDirEntry{0};
2652 uint256 dirEntry{beast::zero};
2655 if (view.
exists(ownerDirKeylet) &&
2656 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2660 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2664 auto sleItem = view.
peek(keylet::child(dirEntry));
2669 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
2670 <<
" has index to object that is missing: "
2671 << to_string(dirEntry);
2676 sleItem->getFieldU16(sfLedgerEntryType))};
2680 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2702 "ripple::cleanupOnAccountDelete : minimum dir entries");
2706 <<
"DeleteAccount iterator re-validation failed.";
2709 if (skipEntry == SkipEntry::No)
2713 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2726 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2730 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2731 sleState->getFieldAmount(sfHighLimit).getIssuer());
2732 auto sleLow = view.
peek(keylet::account(low));
2733 auto sleHigh = view.
peek(keylet::account(high));
2734 if (!sleLow || !sleHigh)
2736 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2737 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2740 if (ammLow && ammHigh)
2744 if (!ammLow && !ammHigh)
2748 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2751 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2755 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2760 if (!(sleState->getFlags() & uFlags))
2782 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2788 "ripple::rippleCredit : not checking issuer");
2790 view, uSenderID, uReceiverID, saAmount, j);
2804 "ripple::assetsToSharesDeposit : non-negative assets");
2806 assets.
asset() == vault->at(sfAsset),
2807 "ripple::assetsToSharesDeposit : assets and vault match");
2808 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2811 Number const assetTotal = vault->at(sfAssetsTotal);
2812 STAmount shares{vault->at(sfShareMPTID)};
2813 if (assetTotal == 0)
2819 Number const shareTotal = issuance->at(sfOutstandingAmount);
2820 shares = (shareTotal * (assets / assetTotal)).truncate();
2832 "ripple::sharesToAssetsDeposit : non-negative shares");
2834 shares.
asset() == vault->at(sfShareMPTID),
2835 "ripple::sharesToAssetsDeposit : shares and vault match");
2836 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2839 Number const assetTotal = vault->at(sfAssetsTotal);
2840 STAmount assets{vault->at(sfAsset)};
2841 if (assetTotal == 0)
2845 shares.
exponent() - vault->at(sfScale),
2848 Number const shareTotal = issuance->at(sfOutstandingAmount);
2849 assets = assetTotal * (shares / shareTotal);
2862 "ripple::assetsToSharesDeposit : non-negative assets");
2864 assets.
asset() == vault->at(sfAsset),
2865 "ripple::assetsToSharesWithdraw : assets and vault match");
2866 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2869 Number assetTotal = vault->at(sfAssetsTotal);
2870 assetTotal -= vault->at(sfLossUnrealized);
2871 STAmount shares{vault->at(sfShareMPTID)};
2872 if (assetTotal == 0)
2874 Number const shareTotal = issuance->at(sfOutstandingAmount);
2875 Number result = shareTotal * (assets / assetTotal);
2876 if (truncate == TruncateShares::yes)
2890 "ripple::sharesToAssetsDeposit : non-negative shares");
2892 shares.
asset() == vault->at(sfShareMPTID),
2893 "ripple::sharesToAssetsWithdraw : shares and vault match");
2894 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2897 Number assetTotal = vault->at(sfAssetsTotal);
2898 assetTotal -= vault->at(sfLossUnrealized);
2899 STAmount assets{vault->at(sfAsset)};
2900 if (assetTotal == 0)
2902 Number const shareTotal = issuance->at(sfOutstandingAmount);
2903 assets = assetTotal * (shares / shareTotal);
2915 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2916 auto sleIssuance = view.
peek(mptID);
2919 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
2920 << mptIssue.getMptID();
2927 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
2934 auto const mptokenID = keylet::mptoken(mptID.key, sender);
2935 auto sle = view.
peek(mptokenID);
2939 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
2943 auto const amt = sle->getFieldU64(sfMPTAmount);
2944 auto const pay = amount.
mpt().
value();
2950 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
2951 << to_string(sender) <<
": " << amt <<
" < " << pay;
2955 (*sle)[sfMPTAmount] = amt - pay;
2958 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
2963 <<
"rippleLockEscrowMPT: overflow on locked amount for "
2964 << to_string(sender) <<
": " << locked <<
" + " << pay;
2968 if (sle->isFieldPresent(sfLockedAmount))
2969 (*sle)[sfLockedAmount] += pay;
2971 sle->setFieldU64(sfLockedAmount, pay);
2979 uint64_t
const issuanceEscrowed =
2980 (*sleIssuance)[~sfLockedAmount].value_or(0);
2981 auto const pay = amount.
mpt().
value();
2987 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
2988 "locked amount for "
2989 << mptIssue.getMptID() <<
": " << issuanceEscrowed
2994 if (sleIssuance->isFieldPresent(sfLockedAmount))
2995 (*sleIssuance)[sfLockedAmount] += pay;
2997 sleIssuance->setFieldU64(sfLockedAmount, pay);
2999 view.
update(sleIssuance);
3015 netAmount == grossAmount,
3016 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3018 auto const& issuer = netAmount.
getIssuer();
3020 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3021 auto sleIssuance = view.
peek(mptID);
3024 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3025 << mptIssue.getMptID();
3031 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3034 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3035 << mptIssue.getMptID();
3039 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3040 auto const redeem = grossAmount.
mpt().
value();
3047 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3048 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3052 auto const newLocked = locked - redeem;
3054 sleIssuance->makeFieldAbsent(sfLockedAmount);
3056 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3057 view.
update(sleIssuance);
3060 if (issuer != receiver)
3063 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3064 auto sle = view.
peek(mptokenID);
3068 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3072 auto current = sle->getFieldU64(sfMPTAmount);
3073 auto delta = netAmount.
mpt().
value();
3079 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3080 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3084 (*sle)[sfMPTAmount] += delta;
3090 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3091 auto const redeem = netAmount.
mpt().
value();
3098 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3099 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3104 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3105 view.
update(sleIssuance);
3108 if (issuer == sender)
3110 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3111 "cannot unlock MPTs.";
3117 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3118 auto sle = view.
peek(mptokenID);
3122 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3126 if (!sle->isFieldPresent(sfLockedAmount))
3129 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3130 << to_string(sender);
3134 auto const locked = sle->getFieldU64(sfLockedAmount);
3135 auto const delta = grossAmount.
mpt().
value();
3141 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3142 << to_string(sender) <<
": " << locked <<
" < " << delta;
3146 auto const newLocked = locked - delta;
3148 sle->makeFieldAbsent(sfLockedAmount);
3150 sle->setFieldU64(sfLockedAmount, newLocked);
3161 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3167 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3168 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3172 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3173 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
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.
TER rippleLockEscrowMPT(ApplyView &view, AccountID const &sender, STAmount const &amount, beast::Journal j)
AccountID const & noAccount()
A placeholder for empty accounts.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
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)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType)
Check if the account lacks required authorization.
FreezeHandling
Controls the treatment of frozen account balances.
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.
bool isXRP(AccountID const &c)
AccountID const & xrpAccount()
Compute AccountID from public key.
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)
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &sender, AccountID const &receiver, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
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.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
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)
std::optional< STAmount > assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets, TruncateShares truncate)
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)
TER transferXRP(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &amount, beast::Journal j)
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
static std::array< SField const *, 2 > const pseudoAccountOwnerFields
@ current
This was a new validation and was added.
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
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 canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
std::optional< STAmount > sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags, std::optional< AccountID > holderID)
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)
static bool adjustOwnerCount(ApplyContext &ctx, int count)
constexpr std::uint32_t const tfMPTUnauthorize
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 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.
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 uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
TER trustDelete(ApplyView &view, std::shared_ptr< SLE > const &sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
@ tecINSUFFICIENT_RESERVE
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
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)
std::string to_string(base_uint< Bits, Tag > const &a)
LedgerEntryType
Identifiers for on-ledger objects.
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.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< uint16_t > maxNodesToDelete)
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.
Number root(Number f, unsigned d)
TER verifyValidDomain(ApplyView &view, AccountID const &account, uint256 domainID, beast::Journal j)
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
static TER rippleSendIOU(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, STAmount &saActual, beast::Journal j, WaiveTransferFee waiveFee)
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, int depth)
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)
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,...
static TER rippleCreditMPT(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
Calls static accountSendIOU if saAmount represents Issue.
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)