adds deep freeze check to LoanBrokerDelete

This commit is contained in:
Vito
2025-11-19 13:05:13 +01:00
parent bd0b651891
commit f50d47ed8f
2 changed files with 37 additions and 1 deletions

View File

@@ -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));

View File

@@ -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;
}