mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add deep freeze check to LoanBrokerDelete (#6053)
- Add logging for missing vault - Fix unit test
This commit is contained in:
@@ -1063,6 +1063,20 @@ class LoanBroker_test : public beast::unit_test::suite
|
|||||||
|
|
||||||
// preclaim: tecHAS_OBLIGATIONS
|
// preclaim: tecHAS_OBLIGATIONS
|
||||||
env(del(alice, brokerKeylet.key), ter(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));
|
||||||
|
|
||||||
|
// successful delete the loan broker object
|
||||||
|
env(del(alice, brokerKeylet.key), ter(tesSUCCESS));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
env(del(alice, brokerKeylet.key));
|
env(del(alice, brokerKeylet.key));
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
|||||||
JLOG(ctx.j.warn()) << "LoanBroker does not exist.";
|
JLOG(ctx.j.warn()) << "LoanBroker does not exist.";
|
||||||
return tecNO_ENTRY;
|
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.";
|
JLOG(ctx.j.warn()) << "Account is not the owner of the LoanBroker.";
|
||||||
return tecNO_PERMISSION;
|
return tecNO_PERMISSION;
|
||||||
@@ -68,6 +71,30 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto const vault = ctx.view.read(keylet::vault(sleBroker->at(sfVaultID)));
|
||||||
|
if (!vault)
|
||||||
|
{
|
||||||
|
// LCOV_EXCL_START
|
||||||
|
JLOG(ctx.j.fatal()) << "Vault is missing for Broker " << brokerID;
|
||||||
|
return tefBAD_LEDGER;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user