mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
adds deep freeze check to LoanBrokerDelete
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <xrpl/beast/unit_test/suite.h>
|
||||
|
||||
#include "test/jtx/TestHelpers.h"
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
@@ -1057,6 +1059,17 @@ class LoanBroker_test : public beast::unit_test::suite
|
||||
|
||||
// preclaim: tecHAS_OBLIGATIONS
|
||||
env(del(alice, brokerKeylet.key), ter(tecHAS_OBLIGATIONS));
|
||||
|
||||
// Repay and delete the loan
|
||||
auto const loanKeylet = keylet::loan(brokerKeylet.key, 1);
|
||||
env(loan::pay(borrower, loanKeylet.key, asset(50).value()));
|
||||
env(loan::del(alice, loanKeylet.key));
|
||||
|
||||
env(trust(issuer, asset(0), alice, tfSetFreeze | tfSetDeepFreeze));
|
||||
// preclaim: tecFROZEN (deep frozen)
|
||||
env(del(alice, brokerKeylet.key), ter(tecFROZEN));
|
||||
env(trust(
|
||||
issuer, asset(0), alice, tfClearFreeze | tfClearDeepFreeze));
|
||||
}
|
||||
else
|
||||
env(del(alice, brokerKeylet.key));
|
||||
|
||||
@@ -33,7 +33,10 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
||||
JLOG(ctx.j.warn()) << "LoanBroker does not exist.";
|
||||
return tecNO_ENTRY;
|
||||
}
|
||||
if (account != sleBroker->at(sfOwner))
|
||||
|
||||
auto const brokerOwner = sleBroker->at(sfOwner);
|
||||
|
||||
if (account != brokerOwner)
|
||||
{
|
||||
JLOG(ctx.j.warn()) << "Account is not the owner of the LoanBroker.";
|
||||
return tecNO_PERMISSION;
|
||||
@@ -44,6 +47,26 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
||||
return tecHAS_OBLIGATIONS;
|
||||
}
|
||||
|
||||
auto const vault = ctx.view.read(keylet::vault(sleBroker->at(sfVaultID)));
|
||||
if (!vault)
|
||||
// Should be impossible
|
||||
return tefBAD_LEDGER; // LCOV_EXCL_LINE
|
||||
|
||||
Asset const asset = vault->at(sfAsset);
|
||||
|
||||
auto const coverAvailable =
|
||||
STAmount{asset, sleBroker->at(sfCoverAvailable)};
|
||||
// If there are assets in the cover, broker will receive them on deletion.
|
||||
// So we need to check if the broker owner is deep frozen for that asset.
|
||||
if (coverAvailable > beast::zero)
|
||||
{
|
||||
if (auto const ret = checkDeepFrozen(ctx.view, brokerOwner, asset))
|
||||
{
|
||||
JLOG(ctx.j.warn()) << "Broker owner account is frozen.";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user