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);
630 auto const reserve = sle->isFieldPresent(sfAMMID)
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->setFieldU32(sfOwnerCount, adjusted);
1050 (*sle)[sfOwner] = account;
1061 object->setFieldU64(sfOwnerNode, *page);
1074 rsh(hash.data(), hash.size());
1092Expected<std::shared_ptr<SLE>,
TER>
1095 uint256 const& pseudoOwnerKey,
1096 SField const& ownerField)
1102 [&ownerField](
SField const* sf) ->
bool {
1103 return *sf == ownerField;
1105 "ripple::createPseudoAccount : valid owner field");
1108 if (accountId == beast::zero)
1113 account->setAccountID(sfAccount, accountId);
1114 account->setFieldAmount(sfBalance,
STAmount{});
1123 account->setFieldU32(sfSequence, seqno);
1127 account->setFieldU32(
1130 account->setFieldH256(ownerField, pseudoOwnerKey);
1142 return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT &&
1146 [&sleAcct](
SField const* sf) ->
bool {
1147 return sleAcct->isFieldPresent(*sf);
1163 auto const& issuerId = issue.
getIssuer();
1164 auto const& currency = issue.
currency;
1168 auto const& srcId = issuerId;
1169 auto const& dstId = accountID;
1170 auto const high = srcId > dstId;
1171 auto const index =
keylet::line(srcId, dstId, currency);
1174 if (!sleDst || !sleSrc)
1179 if (view.
read(index))
1192 STAmount{Issue{currency, noAccount()}},
1193 STAmount{Issue{currency, dstId}},
1207 auto const& mptID = mptIssue.
getMptID();
1208 auto const mpt = view.
peek(keylet::mptIssuance(mptID));
1213 if (view.
peek(keylet::mptoken(mptID, accountID)))
1223 MPTID const& mptIssuanceID,
1229 auto const sleAcct = view.
peek(keylet::account(account));
1243 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1244 auto const sleMpt = view.
peek(mptokenKey);
1245 if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
1249 keylet::ownerDir(account),
1250 (*sleMpt)[sfOwnerNode],
1270 std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount);
1272 (uOwnerCount < 2) ?
XRPAmount(beast::zero)
1275 if (priorBalance < reserveCreate)
1278 auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
1280 if (
auto ter =
dirLink(view, account, mptoken))
1283 (*mptoken)[sfAccount] = account;
1284 (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
1285 (*mptoken)[sfFlags] = 0;
1294 auto const sleMptIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
1295 if (!sleMptIssuance)
1301 if (account != (*sleMptIssuance)[sfIssuer])
1304 auto const sleMpt = view.
peek(keylet::mptoken(mptIssuanceID, *holderID));
1314 flagsOut &= ~lsfMPTAuthorized;
1320 if (flagsIn != flagsOut)
1321 sleMpt->setFieldU32(sfFlags, flagsOut);
1330 bool const bSrcHigh,
1336 bool const bNoRipple,
1347 JLOG(j.
trace()) <<
"trustCreate: " << to_string(uSrcAccountID) <<
", "
1348 << to_string(uDstAccountID) <<
", "
1351 auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
1352 auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
1355 view.
insert(sleRippleState);
1358 keylet::ownerDir(uLowAccountID),
1359 sleRippleState->key(),
1366 keylet::ownerDir(uHighAccountID),
1367 sleRippleState->key(),
1373 bool const bSetDst = saLimit.
getIssuer() == uDstAccountID;
1374 bool const bSetHigh = bSrcHigh ^ bSetDst;
1376 XRPL_ASSERT(sleAccount,
"ripple::trustCreate : non-null SLE");
1381 sleAccount->getAccountID(sfAccount) ==
1382 (bSetHigh ? uHighAccountID : uLowAccountID),
1383 "ripple::trustCreate : matching account ID");
1384 auto const slePeer =
1385 view.
peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID));
1390 sleRippleState->setFieldU64(sfLowNode, *lowNode);
1391 sleRippleState->setFieldU64(sfHighNode, *highNode);
1393 sleRippleState->setFieldAmount(
1394 bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
1395 sleRippleState->setFieldAmount(
1396 bSetHigh ? sfLowLimit : sfHighLimit,
1398 saBalance.
getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID}));
1401 sleRippleState->setFieldU32(
1402 bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
1405 sleRippleState->setFieldU32(
1406 bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
1433 sleRippleState->setFieldU32(sfFlags, uFlags);
1437 sleRippleState->setFieldAmount(
1438 sfBalance, bSetHigh ? -saBalance : saBalance);
1441 uSrcAccountID, uDstAccountID, saBalance, saBalance.
zeroed());
1455 auto const sle = view.
read(keylet::account(accountID));
1458 auto const balance = sle->getFieldAmount(sfBalance);
1459 if (balance.xrp() != 0)
1465 auto const line = view.
peek(keylet::line(accountID, issue));
1468 if (line->at(sfBalance)->iou() != beast::zero)
1475 auto sleLowAccount =
1476 view.
peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
1489 auto sleHighAccount =
1490 view.
peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
1491 if (!sleHighAccount)
1503 line->at(sfLowLimit)->getIssuer(),
1504 line->at(sfHighLimit)->getIssuer(),
1515 auto const& mptID = mptIssue.
getMptID();
1516 auto const mptoken = view.
peek(keylet::mptoken(mptID, accountID));
1519 if (mptoken->at(sfMPTAmount) != 0)
1541 std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode);
1542 std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode);
1544 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: low";
1547 keylet::ownerDir(uLowAccountID),
1549 sleRippleState->key(),
1555 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: high";
1558 keylet::ownerDir(uHighAccountID),
1560 sleRippleState->key(),
1566 JLOG(j.
trace()) <<
"trustDelete: Deleting ripple line: state";
1567 view.
erase(sleRippleState);
1577 auto offerIndex = sle->key();
1578 auto owner = sle->getAccountID(sfAccount);
1581 uint256 uDirectory = sle->getFieldH256(sfBookDirectory);
1584 keylet::ownerDir(owner),
1585 sle->getFieldU64(sfOwnerNode),
1593 keylet::page(uDirectory),
1594 sle->getFieldU64(sfBookNode),
1601 if (sle->isFieldPresent(sfAdditionalBooks))
1604 sle->isFlag(
lsfHybrid) && sle->isFieldPresent(sfDomainID),
1605 "ripple::offerDelete : should be a hybrid domain offer");
1607 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
1609 for (
auto const& bookDir : additionalBookDirs)
1611 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
1612 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
1615 keylet::page(dirIndex), dirNode, offerIndex,
false))
1647 !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer,
1648 "ripple::rippleCreditIOU : matching issuer or don't care");
1653 uSenderID != uReceiverID,
1654 "ripple::rippleCreditIOU : sender is not receiver");
1656 bool const bSenderHigh = uSenderID > uReceiverID;
1657 auto const index = keylet::line(uSenderID, uReceiverID, currency);
1661 "ripple::rippleCreditIOU : sender is not XRP");
1664 "ripple::rippleCreditIOU : receiver is not XRP");
1667 if (
auto const sleRippleState = view.
peek(index))
1669 STAmount saBalance = sleRippleState->getFieldAmount(sfBalance);
1674 view.
creditHook(uSenderID, uReceiverID, saAmount, saBalance);
1676 STAmount const saBefore = saBalance;
1678 saBalance -= saAmount;
1680 JLOG(j.
trace()) <<
"rippleCreditIOU: " << to_string(uSenderID) <<
" -> "
1681 << to_string(uReceiverID)
1686 std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags));
1687 bool bDelete =
false;
1691 if (saBefore > beast::zero
1693 && saBalance <= beast::zero
1701 view.
read(keylet::account(uSenderID))->getFlags() &
1704 !sleRippleState->getFieldAmount(
1705 !bSenderHigh ? sfLowLimit : sfHighLimit)
1707 && !sleRippleState->getFieldU32(
1708 !bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
1710 && !sleRippleState->getFieldU32(
1711 !bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
1716 view, view.
peek(keylet::account(uSenderID)), -1, j);
1719 sleRippleState->setFieldU32(
1721 uFlags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
1724 bDelete = !saBalance
1733 sleRippleState->setFieldAmount(sfBalance, saBalance);
1741 bSenderHigh ? uReceiverID : uSenderID,
1742 !bSenderHigh ? uReceiverID : uSenderID,
1746 view.
update(sleRippleState);
1750 STAmount const saReceiverLimit(
Issue{currency, uReceiverID});
1755 JLOG(j.
debug()) <<
"rippleCreditIOU: "
1757 << to_string(uSenderID) <<
" -> " << to_string(uReceiverID)
1760 auto const sleAccount = view.
peek(keylet::account(uReceiverID));
1797 auto const issuer = saAmount.
getIssuer();
1801 "ripple::rippleSendIOU : neither sender nor receiver is XRP");
1803 uSenderID != uReceiverID,
1804 "ripple::rippleSendIOU : sender is not receiver");
1806 if (uSenderID == issuer || uReceiverID == issuer || issuer ==
noAccount())
1813 saActual = saAmount;
1821 saActual = (waiveFee == WaiveTransferFee::Yes)
1825 JLOG(j.
debug()) <<
"rippleSendIOU> " << to_string(uSenderID) <<
" - > "
1826 << to_string(uReceiverID)
1834 terResult =
rippleCreditIOU(view, uSenderID, issuer, saActual,
true, j);
1859 "ripple::accountSendIOU : minimum amount and not MPT");
1865 if (!saAmount || (uSenderID == uReceiverID))
1872 JLOG(j.
trace()) <<
"accountSendIOU: " << to_string(uSenderID) <<
" -> "
1873 << to_string(uReceiverID) <<
" : "
1877 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
1888 ? view.
peek(keylet::account(uSenderID))
1891 ? view.
peek(keylet::account(uReceiverID))
1894 if (
auto stream = j.
trace())
1900 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1903 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1905 stream <<
"accountSendIOU> " << to_string(uSenderID) <<
" ("
1906 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1907 << receiver_bal <<
") : " << saAmount.
getFullText();
1912 if (sender->getFieldAmount(sfBalance) < saAmount)
1921 auto const sndBal = sender->getFieldAmount(sfBalance);
1925 sender->setFieldAmount(sfBalance, sndBal - saAmount);
1933 auto const rcvBal = receiver->getFieldAmount(sfBalance);
1934 receiver->setFieldAmount(sfBalance, rcvBal + saAmount);
1940 if (
auto stream = j.
trace())
1946 sender_bal = sender->getFieldAmount(sfBalance).getFullText();
1949 receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
1951 stream <<
"accountSendIOU< " << to_string(uSenderID) <<
" ("
1952 << sender_bal <<
") -> " << to_string(uReceiverID) <<
" ("
1953 << receiver_bal <<
") : " << saAmount.
getFullText();
1969 auto const issuer = saAmount.
getIssuer();
1970 auto sleIssuance = view.
peek(mptID);
1973 if (uSenderID == issuer)
1975 (*sleIssuance)[sfOutstandingAmount] += saAmount.
mpt().
value();
1976 view.
update(sleIssuance);
1980 auto const mptokenID = keylet::mptoken(mptID.key, uSenderID);
1981 if (
auto sle = view.
peek(mptokenID))
1983 auto const amt = sle->getFieldU64(sfMPTAmount);
1984 auto const pay = saAmount.
mpt().
value();
1987 (*sle)[sfMPTAmount] = amt - pay;
1994 if (uReceiverID == issuer)
1996 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
1997 auto const redeem = saAmount.
mpt().
value();
1998 if (outstanding >= redeem)
2000 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
2001 view.
update(sleIssuance);
2008 auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID);
2009 if (
auto sle = view.
peek(mptokenID))
2011 (*sle)[sfMPTAmount] += saAmount.
mpt().
value();
2032 uSenderID != uReceiverID,
2033 "ripple::rippleSendMPT : sender is not receiver");
2036 auto const issuer = saAmount.
getIssuer();
2043 if (uSenderID == issuer || uReceiverID == issuer)
2047 if (uSenderID == issuer)
2049 auto const sendAmount = saAmount.
mpt().
value();
2050 auto const maximumAmount =
2052 if (sendAmount > maximumAmount ||
2053 sle->getFieldU64(sfOutstandingAmount) >
2054 maximumAmount - sendAmount)
2063 saActual = saAmount;
2068 saActual = (waiveFee == WaiveTransferFee::Yes)
2074 JLOG(j.
debug()) <<
"rippleSendMPT> " << to_string(uSenderID) <<
" - > "
2075 << to_string(uReceiverID)
2079 if (
auto const terResult =
2098 "ripple::accountSendMPT : minimum amount and MPT");
2103 if (!saAmount || (uSenderID == uReceiverID))
2109 view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee);
2125 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2128 view, uSenderID, uReceiverID, saAmount, j, waiveFee);
2147 auto sle = view.
peek(keylet::account(sender));
2152 if (before > beast::zero
2154 &&
after <= beast::zero
2158 &&
static_cast<bool>(
2162 !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit)
2164 && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn)
2167 !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut))
2176 sfFlags, flags & (!bSenderHigh ? ~
lsfLowReserve : ~lsfHighReserve));
2196 "ripple::issueIOU : neither account nor issuer is XRP");
2199 XRPL_ASSERT(issue == amount.
issue(),
"ripple::issueIOU : matching issue");
2203 issue.
account != account,
"ripple::issueIOU : not issuer account");
2205 JLOG(j.
trace()) <<
"issueIOU: " << to_string(account) <<
": "
2208 bool bSenderHigh = issue.
account > account;
2210 auto const index = keylet::line(issue.
account, account, issue.
currency);
2212 if (
auto state = view.
peek(index))
2214 STAmount final_balance = state->getFieldAmount(sfBalance);
2219 STAmount const start_balance = final_balance;
2221 final_balance -= amount;
2240 state->setFieldAmount(sfBalance, final_balance);
2245 bSenderHigh ? account : issue.
account,
2246 bSenderHigh ? issue.
account : account,
2262 auto const receiverAccount = view.
peek(keylet::account(account));
2263 if (!receiverAccount)
2296 "ripple::redeemIOU : neither account nor issuer is XRP");
2299 XRPL_ASSERT(issue == amount.
issue(),
"ripple::redeemIOU : matching issue");
2303 issue.
account != account,
"ripple::redeemIOU : not issuer account");
2305 JLOG(j.
trace()) <<
"redeemIOU: " << to_string(account) <<
": "
2308 bool bSenderHigh = account > issue.
account;
2313 STAmount final_balance = state->getFieldAmount(sfBalance);
2318 STAmount const start_balance = final_balance;
2320 final_balance -= amount;
2323 view, state, bSenderHigh, account, start_balance, final_balance, j);
2333 state->setFieldAmount(sfBalance, final_balance);
2340 bSenderHigh ? issue.
account : account,
2341 bSenderHigh ? account : issue.
account,
2352 JLOG(j.
fatal()) <<
"redeemIOU: " << to_string(account)
2354 <<
" but no trust line exists!";
2368 from != beast::zero,
"ripple::transferXRP : nonzero from account");
2369 XRPL_ASSERT(to != beast::zero,
"ripple::transferXRP : nonzero to account");
2370 XRPL_ASSERT(from != to,
"ripple::transferXRP : sender is not receiver");
2371 XRPL_ASSERT(amount.
native(),
"ripple::transferXRP : amount is XRP");
2375 if (!sender || !receiver)
2378 JLOG(j.
trace()) <<
"transferXRP: " << to_string(from) <<
" -> "
2379 << to_string(to) <<
") : " << amount.
getFullText();
2381 if (sender->getFieldAmount(sfBalance) < amount)
2391 sender->setFieldAmount(
2392 sfBalance, sender->getFieldAmount(sfBalance) - amount);
2395 receiver->setFieldAmount(
2396 sfBalance, receiver->getFieldAmount(sfBalance) + amount);
2412 auto const trustLine =
2415 if (!trustLine && authType == AuthType::StrongAuth)
2420 if (
auto const issuerAccount = view.
read(keylet::account(issue.
account));
2424 return ((*trustLine)[sfFlags] &
2442 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2443 auto const sleIssuance = view.
read(mptID);
2447 auto const mptIssuer = sleIssuance->getAccountID(sfIssuer);
2450 if (mptIssuer == account)
2459 auto const sleIssuer = view.
read(keylet::account(mptIssuer));
2463 if (sleIssuer->isFieldPresent(sfVaultID))
2465 auto const sleVault =
2466 view.
read(keylet::vault(sleIssuer->getFieldH256(sfVaultID)));
2470 auto const asset = sleVault->at(sfAsset);
2474 return requireAuth(view, issue, account, authType);
2477 view, issue, account, authType, depth + 1);
2485 auto const mptokenID = keylet::mptoken(mptID.key, account);
2486 auto const sleToken = view.
read(mptokenID);
2490 (authType == AuthType::StrongAuth || authType == AuthType::Legacy))
2495 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2500 "ripple::requireAuth : issuance requires authorization");
2502 if (
auto const ter =
2503 credentials::validDomain(view, *maybeDomainID, account);
2523 MPTID const& mptIssuanceID,
2528 auto const sleIssuance = view.
read(keylet::mptIssuance(mptIssuanceID));
2534 "ripple::enforceMPTokenAuthorization : authorization required");
2536 if (account == sleIssuance->at(sfIssuer))
2539 auto const keylet = keylet::mptoken(mptIssuanceID, account);
2540 auto const sleToken = view.
read(keylet);
2541 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
2543 bool const authorizedByDomain = [&]() ->
bool {
2545 if (!maybeDomainID.has_value())
2556 if (!authorizedByDomain && sleToken ==
nullptr)
2567 else if (!authorizedByDomain && maybeDomainID.has_value())
2574 else if (!authorizedByDomain)
2579 sleToken !=
nullptr && !maybeDomainID.has_value(),
2580 "ripple::enforceMPTokenAuthorization : found MPToken");
2586 else if (authorizedByDomain && sleToken !=
nullptr)
2591 maybeDomainID.has_value(),
2592 "ripple::enforceMPTokenAuthorization : found MPToken for domain");
2595 else if (authorizedByDomain)
2600 maybeDomainID.has_value() && sleToken ==
nullptr,
2601 "ripple::enforceMPTokenAuthorization : new MPToken for domain");
2616 "ripple::enforceMPTokenAuthorization : condition list is incomplete");
2627 auto const mptID = keylet::mptIssuance(mptIssue.
getMptID());
2628 auto const sleIssuance = view.
read(mptID);
2634 if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
2643 Keylet const& ownerDirKeylet,
2650 unsigned int uDirEntry{0};
2651 uint256 dirEntry{beast::zero};
2654 if (view.
exists(ownerDirKeylet) &&
2655 dirFirst(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry))
2659 if (maxNodesToDelete && ++deleted > *maxNodesToDelete)
2663 auto sleItem = view.
peek(keylet::child(dirEntry));
2668 <<
"DeleteAccount: Directory node in ledger " << view.
seq()
2669 <<
" has index to object that is missing: "
2670 << to_string(dirEntry);
2675 sleItem->getFieldU16(sfLedgerEntryType))};
2679 auto const [ter, skipEntry] = deleter(nodeType, dirEntry, sleItem);
2701 "ripple::cleanupOnAccountDelete : minimum dir entries");
2705 <<
"DeleteAccount iterator re-validation failed.";
2708 if (skipEntry == SkipEntry::No)
2712 dirNext(view, ownerDirKeylet.
key, sleDirNode, uDirEntry, dirEntry));
2725 if (!sleState || sleState->getType() != ltRIPPLE_STATE)
2729 sleState->getFieldAmount(sfLowLimit).getIssuer(),
2730 sleState->getFieldAmount(sfHighLimit).getIssuer());
2731 auto sleLow = view.
peek(keylet::account(low));
2732 auto sleHigh = view.
peek(keylet::account(high));
2733 if (!sleLow || !sleHigh)
2735 bool const ammLow = sleLow->isFieldPresent(sfAMMID);
2736 bool const ammHigh = sleHigh->isFieldPresent(sfAMMID);
2739 if (ammLow && ammHigh)
2743 if (!ammLow && !ammHigh)
2747 if (ammAccountID && (low != *ammAccountID && high != *ammAccountID))
2750 if (
auto const ter =
trustDelete(view, sleState, low, high, j);
2754 <<
"deleteAMMTrustLine: failed to delete the trustline.";
2759 if (!(sleState->getFlags() & uFlags))
2781 view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j);
2787 "ripple::rippleCredit : not checking issuer");
2789 view, uSenderID, uReceiverID, saAmount, j);
2803 "ripple::assetsToSharesDeposit : non-negative assets");
2805 assets.
asset() == vault->at(sfAsset),
2806 "ripple::assetsToSharesDeposit : assets and vault match");
2807 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2810 Number const assetTotal = vault->at(sfAssetsTotal);
2811 STAmount shares{vault->at(sfShareMPTID)};
2812 if (assetTotal == 0)
2818 Number const shareTotal = issuance->at(sfOutstandingAmount);
2819 shares = (shareTotal * (assets / assetTotal)).truncate();
2831 "ripple::sharesToAssetsDeposit : non-negative shares");
2833 shares.
asset() == vault->at(sfShareMPTID),
2834 "ripple::sharesToAssetsDeposit : shares and vault match");
2835 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2838 Number const assetTotal = vault->at(sfAssetsTotal);
2839 STAmount assets{vault->at(sfAsset)};
2840 if (assetTotal == 0)
2844 shares.
exponent() - vault->at(sfScale),
2847 Number const shareTotal = issuance->at(sfOutstandingAmount);
2848 assets = assetTotal * (shares / shareTotal);
2861 "ripple::assetsToSharesDeposit : non-negative assets");
2863 assets.
asset() == vault->at(sfAsset),
2864 "ripple::assetsToSharesWithdraw : assets and vault match");
2865 if (assets.
negative() || assets.
asset() != vault->at(sfAsset))
2868 Number assetTotal = vault->at(sfAssetsTotal);
2869 assetTotal -= vault->at(sfLossUnrealized);
2870 STAmount shares{vault->at(sfShareMPTID)};
2871 if (assetTotal == 0)
2873 Number const shareTotal = issuance->at(sfOutstandingAmount);
2874 Number result = shareTotal * (assets / assetTotal);
2875 if (truncate == TruncateShares::yes)
2889 "ripple::sharesToAssetsDeposit : non-negative shares");
2891 shares.
asset() == vault->at(sfShareMPTID),
2892 "ripple::sharesToAssetsWithdraw : shares and vault match");
2893 if (shares.
negative() || shares.
asset() != vault->at(sfShareMPTID))
2896 Number assetTotal = vault->at(sfAssetsTotal);
2897 assetTotal -= vault->at(sfLossUnrealized);
2898 STAmount assets{vault->at(sfAsset)};
2899 if (assetTotal == 0)
2901 Number const shareTotal = issuance->at(sfOutstandingAmount);
2902 assets = assetTotal * (shares / shareTotal);
2914 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
2915 auto sleIssuance = view.
peek(mptID);
2918 JLOG(j.
error()) <<
"rippleLockEscrowMPT: MPT issuance not found for "
2919 << mptIssue.getMptID();
2926 <<
"rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs.";
2933 auto const mptokenID = keylet::mptoken(mptID.key, sender);
2934 auto sle = view.
peek(mptokenID);
2938 <<
"rippleLockEscrowMPT: MPToken not found for " << sender;
2942 auto const amt = sle->getFieldU64(sfMPTAmount);
2943 auto const pay = amount.
mpt().
value();
2949 <<
"rippleLockEscrowMPT: insufficient MPTAmount for "
2950 << to_string(sender) <<
": " << amt <<
" < " << pay;
2954 (*sle)[sfMPTAmount] = amt - pay;
2957 uint64_t
const locked = (*sle)[~sfLockedAmount].value_or(0);
2962 <<
"rippleLockEscrowMPT: overflow on locked amount for "
2963 << to_string(sender) <<
": " << locked <<
" + " << pay;
2967 if (sle->isFieldPresent(sfLockedAmount))
2968 (*sle)[sfLockedAmount] += pay;
2970 sle->setFieldU64(sfLockedAmount, pay);
2978 uint64_t
const issuanceEscrowed =
2979 (*sleIssuance)[~sfLockedAmount].value_or(0);
2980 auto const pay = amount.
mpt().
value();
2986 JLOG(j.
error()) <<
"rippleLockEscrowMPT: overflow on issuance "
2987 "locked amount for "
2988 << mptIssue.getMptID() <<
": " << issuanceEscrowed
2993 if (sleIssuance->isFieldPresent(sfLockedAmount))
2994 (*sleIssuance)[sfLockedAmount] += pay;
2996 sleIssuance->setFieldU64(sfLockedAmount, pay);
2998 view.
update(sleIssuance);
3014 netAmount == grossAmount,
3015 "ripple::rippleUnlockEscrowMPT : netAmount == grossAmount");
3017 auto const& issuer = netAmount.
getIssuer();
3019 auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
3020 auto sleIssuance = view.
peek(mptID);
3023 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: MPT issuance not found for "
3024 << mptIssue.getMptID();
3030 if (!sleIssuance->isFieldPresent(sfLockedAmount))
3033 <<
"rippleUnlockEscrowMPT: no locked amount in issuance for "
3034 << mptIssue.getMptID();
3038 auto const locked = sleIssuance->getFieldU64(sfLockedAmount);
3039 auto const redeem = grossAmount.
mpt().
value();
3046 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3047 << mptIssue.getMptID() <<
": " << locked <<
" < " << redeem;
3051 auto const newLocked = locked - redeem;
3053 sleIssuance->makeFieldAbsent(sfLockedAmount);
3055 sleIssuance->setFieldU64(sfLockedAmount, newLocked);
3056 view.
update(sleIssuance);
3059 if (issuer != receiver)
3062 auto const mptokenID = keylet::mptoken(mptID.key, receiver);
3063 auto sle = view.
peek(mptokenID);
3067 <<
"rippleUnlockEscrowMPT: MPToken not found for " << receiver;
3071 auto current = sle->getFieldU64(sfMPTAmount);
3072 auto delta = netAmount.
mpt().
value();
3078 <<
"rippleUnlockEscrowMPT: overflow on MPTAmount for "
3079 << to_string(receiver) <<
": " <<
current <<
" + " << delta;
3083 (*sle)[sfMPTAmount] += delta;
3089 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3090 auto const redeem = netAmount.
mpt().
value();
3097 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3098 << mptIssue.getMptID() <<
": " << outstanding <<
" < "
3103 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
3104 view.
update(sleIssuance);
3107 if (issuer == sender)
3109 JLOG(j.
error()) <<
"rippleUnlockEscrowMPT: sender is the issuer, "
3110 "cannot unlock MPTs.";
3116 auto const mptokenID = keylet::mptoken(mptID.key, sender);
3117 auto sle = view.
peek(mptokenID);
3121 <<
"rippleUnlockEscrowMPT: MPToken not found for " << sender;
3125 if (!sle->isFieldPresent(sfLockedAmount))
3128 <<
"rippleUnlockEscrowMPT: no locked amount in MPToken for "
3129 << to_string(sender);
3133 auto const locked = sle->getFieldU64(sfLockedAmount);
3134 auto const delta = grossAmount.
mpt().
value();
3140 <<
"rippleUnlockEscrowMPT: insufficient locked amount for "
3141 << to_string(sender) <<
": " << locked <<
" < " << delta;
3145 auto const newLocked = locked - delta;
3147 sle->makeFieldAbsent(sfLockedAmount);
3149 sle->setFieldU64(sfLockedAmount, newLocked);
3160 auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
3166 <<
"rippleUnlockEscrowMPT: insufficient outstanding amount for "
3167 << mptIssue.getMptID() <<
": " << outstanding <<
" < " << diff;
3171 sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff);
3172 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.
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)
static std::array< SField const *, 2 > const pseudoAccountOwnerFields
@ 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)
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.
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)
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)
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)