mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Make VaultWithdraw with destination use the payment engine
- Calls the same functions as LoanBrokerCoverWithdraw - Seeb34f59eafc,10b73525be,6b4236343a, ande6e6360c1a- Many unit test failures. I'm not sure how accurate they are
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include <xrpld/app/tx/detail/VaultWithdraw.h>
|
#include <xrpld/app/tx/detail/VaultWithdraw.h>
|
||||||
|
//
|
||||||
|
#include <xrpld/app/tx/detail/Payment.h>
|
||||||
|
|
||||||
#include <xrpl/ledger/CredentialHelpers.h>
|
#include <xrpl/ledger/CredentialHelpers.h>
|
||||||
#include <xrpl/ledger/View.h>
|
#include <xrpl/ledger/View.h>
|
||||||
@@ -229,7 +231,7 @@ VaultWithdraw::doApply()
|
|||||||
assetsAvailable -= assetsWithdrawn;
|
assetsAvailable -= assetsWithdrawn;
|
||||||
view().update(vault);
|
view().update(vault);
|
||||||
|
|
||||||
auto const& vaultAccount = vault->at(sfAccount);
|
AccountID const& vaultAccount = vault->at(sfAccount);
|
||||||
// Transfer shares from depositor to vault.
|
// Transfer shares from depositor to vault.
|
||||||
if (auto const ter = accountSend(
|
if (auto const ter = accountSend(
|
||||||
view(),
|
view(),
|
||||||
@@ -280,16 +282,66 @@ VaultWithdraw::doApply()
|
|||||||
return ter;
|
return ter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer assets from vault to depositor or destination account.
|
if (dstAcct != account_ && !assetsWithdrawn.native())
|
||||||
if (auto const ter = accountSend(
|
{
|
||||||
view(),
|
bool const mptDirect = assetsWithdrawn.holds<MPTIssue>();
|
||||||
vaultAccount,
|
STAmount const maxSourceAmount =
|
||||||
dstAcct,
|
Payment::getMaxSourceAmount(vaultAccount, assetsWithdrawn);
|
||||||
assetsWithdrawn,
|
SLE::pointer sleDst = view().peek(keylet::account(dstAcct));
|
||||||
j_,
|
if (!sleDst)
|
||||||
WaiveTransferFee::Yes);
|
return tecINTERNAL;
|
||||||
!isTesSuccess(ter))
|
|
||||||
return ter;
|
Payment::RipplePaymentParams paymentParams{
|
||||||
|
.ctx = ctx_,
|
||||||
|
.maxSourceAmount = maxSourceAmount,
|
||||||
|
.srcAccountID = vaultAccount,
|
||||||
|
.dstAccountID = dstAcct,
|
||||||
|
.sleDst = sleDst,
|
||||||
|
.dstAmount = assetsWithdrawn,
|
||||||
|
.paths = STPathSet{},
|
||||||
|
.deliverMin = std::nullopt,
|
||||||
|
.j = j_};
|
||||||
|
|
||||||
|
// If sending the assets to a different account, then this is
|
||||||
|
// effectively a payment. Use the Payment transaction code to call
|
||||||
|
// the payment engine, though only a subset of the functionality is
|
||||||
|
// supported in this transaction. e.g. No paths, no partial
|
||||||
|
// payments.
|
||||||
|
TER ret;
|
||||||
|
if (mptDirect)
|
||||||
|
{
|
||||||
|
ret = Payment::makeMPTDirectPayment(paymentParams);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = Payment::makeRipplePayment(paymentParams);
|
||||||
|
}
|
||||||
|
// Always claim a fee
|
||||||
|
if (!isTesSuccess(ret) && !isTecClaim(ret))
|
||||||
|
{
|
||||||
|
JLOG(j_.info())
|
||||||
|
<< "LoanBrokerCoverWithdraw: changing result from "
|
||||||
|
<< transToken(ret)
|
||||||
|
<< " to tecPATH_DRY for IOU payment with Destination";
|
||||||
|
return tecPATH_DRY;
|
||||||
|
}
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Transfer assets from vault to depositor or destination (only if XRP)
|
||||||
|
// account.
|
||||||
|
if (auto const ter = accountSend(
|
||||||
|
view(),
|
||||||
|
vaultAccount,
|
||||||
|
dstAcct,
|
||||||
|
assetsWithdrawn,
|
||||||
|
j_,
|
||||||
|
WaiveTransferFee::Yes);
|
||||||
|
!isTesSuccess(ter))
|
||||||
|
return ter;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (accountHolds(
|
if (accountHolds(
|
||||||
|
|||||||
Reference in New Issue
Block a user