mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Compare commits
20 Commits
ximinez/le
...
ximinez/le
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d41fabf48 | ||
|
|
5aab5de8cd | ||
|
|
89d17442e2 | ||
|
|
bb5585e34b | ||
|
|
abff92d52c | ||
|
|
b9ca539c49 | ||
|
|
3b1bc3d497 | ||
|
|
c58f5abcc9 | ||
|
|
4760885955 | ||
|
|
3249461379 | ||
|
|
11479cdf68 | ||
|
|
27af46b111 | ||
|
|
5e860ec749 | ||
|
|
4719e05d89 | ||
|
|
c8394eb52f | ||
|
|
5a3df22cea | ||
|
|
b44859ff15 | ||
|
|
fe8d931992 | ||
|
|
0008e2d1db | ||
|
|
060b6d3231 |
@@ -3176,24 +3176,6 @@ requireAuth(
|
||||
!isTesSuccess(err))
|
||||
return err;
|
||||
}
|
||||
|
||||
// requireAuth is also recursive if the _account_ is a vault
|
||||
auto const sleAccount = view.read(keylet::account(account));
|
||||
if (!sleAccount)
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
if (sleAccount->isFieldPresent(sfVaultID))
|
||||
{
|
||||
auto const sleVault =
|
||||
view.read(keylet::vault(sleAccount->getFieldH256(sfVaultID)));
|
||||
if (!sleVault)
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
auto const ownerAcct = sleVault->getAccountID(sfOwner);
|
||||
if (auto const err =
|
||||
requireAuth(view, mptIssue, ownerAcct, authType, depth + 1);
|
||||
!isTesSuccess(err))
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
auto const mptokenID = keylet::mptoken(mptID.key, account);
|
||||
|
||||
@@ -2738,8 +2738,12 @@ protected:
|
||||
broker.params.managementFeeRate);
|
||||
|
||||
BEAST_EXPECT(
|
||||
paymentComponents.trackedValueDelta <=
|
||||
roundedPeriodicPayment);
|
||||
paymentComponents.trackedValueDelta ==
|
||||
roundedPeriodicPayment ||
|
||||
(paymentComponents.specialCase ==
|
||||
detail::PaymentSpecialCase::final &&
|
||||
paymentComponents.trackedValueDelta <
|
||||
roundedPeriodicPayment));
|
||||
|
||||
ripple::LoanState const nextTrueState = computeRawLoanState(
|
||||
state.periodicPayment,
|
||||
|
||||
@@ -2358,18 +2358,6 @@ class Vault_test : public beast::unit_test::suite
|
||||
.amount = asset(100)});
|
||||
env(tx, ter(tecNO_AUTH));
|
||||
|
||||
// Withdrawal to other (authorized) accounts doesn't work.
|
||||
// Issuer would have to VaultClawback
|
||||
tx[sfDestination] = issuer.human();
|
||||
env(tx, ter(tecNO_AUTH));
|
||||
tx[sfDestination] = owner.human();
|
||||
env(tx, ter(tecNO_AUTH));
|
||||
env.close();
|
||||
|
||||
// Issuer reauthorizes
|
||||
mptt.authorize({.account = issuer, .holder = depositor});
|
||||
env.close();
|
||||
|
||||
// Withdrawal to other (authorized) accounts works
|
||||
tx[sfDestination] = issuer.human();
|
||||
env(tx);
|
||||
@@ -2380,13 +2368,6 @@ class Vault_test : public beast::unit_test::suite
|
||||
env.close();
|
||||
}
|
||||
|
||||
// Re-unauthorize
|
||||
mptt.authorize(
|
||||
{.account = issuer,
|
||||
.holder = depositor,
|
||||
.flags = tfMPTUnauthorize});
|
||||
env.close();
|
||||
|
||||
{
|
||||
// Cannot deposit some more
|
||||
auto tx = vault.deposit(
|
||||
|
||||
@@ -1075,6 +1075,23 @@ computePaymentComponents(
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"excess non-negative");
|
||||
};
|
||||
auto giveTo =
|
||||
[](Number& component, Number& shortage, Number const& maximum) {
|
||||
if (shortage > beast::zero)
|
||||
{
|
||||
// Put as much of the shortage as we can into the provided part
|
||||
// and the total
|
||||
auto part = std::min(maximum - component, shortage);
|
||||
component += part;
|
||||
shortage -= part;
|
||||
}
|
||||
// If the shortage goes negative, we put too much, which should be
|
||||
// impossible
|
||||
XRPL_ASSERT_PARTS(
|
||||
shortage >= beast::zero,
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"excess non-negative");
|
||||
};
|
||||
// Helper to reduce deltas when they collectively exceed a limit.
|
||||
// Order matters: we prefer to reduce interest first (most flexible),
|
||||
// then management fee, then principal (least flexible).
|
||||
@@ -1084,6 +1101,19 @@ computePaymentComponents(
|
||||
takeFrom(deltas.managementFee, excess);
|
||||
takeFrom(deltas.principal, excess);
|
||||
};
|
||||
// Helper to increase deltas when they collectively do not reach an
|
||||
// expected value.
|
||||
// Order matters: we prefer to increase interest first (most flexible),
|
||||
// then management fee, then principal (least flexible).
|
||||
auto addressShortage = [&giveTo](
|
||||
LoanDeltas& deltas,
|
||||
Number& shortage,
|
||||
LoanState const& current) {
|
||||
giveTo(deltas.interestDueDelta, shortage, current.interestDue);
|
||||
giveTo(
|
||||
deltas.managementFeeDueDelta, shortage, current.managementFeeDue);
|
||||
giveTo(deltas.principalDelta, shortage, current.principalOutstanding);
|
||||
};
|
||||
|
||||
// Check if deltas exceed the total outstanding value. This should never
|
||||
// happen due to earlier caps, but handle it defensively.
|
||||
@@ -1115,12 +1145,19 @@ computePaymentComponents(
|
||||
addressExcess(deltas, excess);
|
||||
shortage = -excess;
|
||||
}
|
||||
else if (shortage > beast::zero && totalOverpayment < beast::zero)
|
||||
{
|
||||
// If there's a shortage, and there's room in the loan itself, we can
|
||||
// top up the parts to make the payment correct.
|
||||
shortage = std::min(-totalOverpayment, shortage);
|
||||
addressShortage(deltas, shortage, currentLedgerState);
|
||||
}
|
||||
|
||||
// At this point, shortage >= 0 means we're paying less than the full
|
||||
// periodic payment (due to rounding or component caps).
|
||||
// shortage < 0 would mean we're trying to pay more than allowed (bug).
|
||||
// shortage < 0 means mean we're trying to pay more than allowed (bug).
|
||||
XRPL_ASSERT_PARTS(
|
||||
shortage >= beast::zero,
|
||||
shortage == beast::zero,
|
||||
"ripple::detail::computePaymentComponents",
|
||||
"no shortage or excess");
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include <xrpld/app/tx/detail/VaultWithdraw.h>
|
||||
//
|
||||
#include <xrpld/app/tx/detail/Payment.h>
|
||||
|
||||
#include <xrpl/ledger/CredentialHelpers.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
@@ -199,7 +197,7 @@ VaultWithdraw::doApply()
|
||||
assetsAvailable -= assetsWithdrawn;
|
||||
view().update(vault);
|
||||
|
||||
AccountID const& vaultAccount = vault->at(sfAccount);
|
||||
auto const& vaultAccount = vault->at(sfAccount);
|
||||
// Transfer shares from depositor to vault.
|
||||
if (auto const ter = accountSend(
|
||||
view(),
|
||||
|
||||
Reference in New Issue
Block a user