Finish LoanBrokerSet

- Update changed field name.
- Modify modifiable fields in an update. Note there are only two.
- Add a node field to dirLink, defaulting sfOwnerNode, so other
  relationships can be updated.
This commit is contained in:
Ed Hennis
2025-03-27 17:31:04 -05:00
parent a04c07c5c4
commit f8c708f20c
4 changed files with 22 additions and 9 deletions

View File

@@ -536,7 +536,7 @@ LEDGER_ENTRY(ltLOAN, 0x0085, Loan, loan, ({
{sfPreviousPaymentDate, soeREQUIRED},
{sfNextPaymentDueDate, soeREQUIRED},
{sfPaymentRemaining, soeREQUIRED},
{sfAssetAvailable, soeREQUIRED},
{sfAssetsAvailable, soeREQUIRED},
{sfPrincipalOutstanding, soeREQUIRED},
}))

View File

@@ -142,9 +142,14 @@ LoanBrokerSet::doApply()
if (auto const brokerID = tx[~sfLoanBrokerID])
{
// Modify an existing LoanBroker
auto const sleBroker = view.read(keylet::loanbroker(*brokerID));
auto broker = view.peek(keylet::loanbroker(*brokerID));
assert(0);
if (auto const data = tx[~sfData])
broker->at(sfData) = *data;
if (auto const debtMax = tx[~sfDebtMaximum])
broker->at(sfDebtMaximum) = *debtMax;
view.update(broker);
}
else
{
@@ -160,7 +165,7 @@ LoanBrokerSet::doApply()
if (auto const ter = dirLink(view, account_, broker))
return ter;
if (auto const ter = dirLink(view, vaultPseudoID, broker))
if (auto const ter = dirLink(view, vaultPseudoID, broker, sfVaultNode))
return ter;
adjustOwnerCount(view, owner, 1, j_);
@@ -188,7 +193,7 @@ LoanBrokerSet::doApply()
broker->at(sfData) = *data;
if (auto const rate = tx[~sfManagementFeeRate])
broker->at(sfManagementFeeRate) = *rate;
if (auto const debtMax = tx[~sfDebtMaximum]; debtMax)
if (auto const debtMax = tx[~sfDebtMaximum])
broker->at(sfDebtMaximum) = *debtMax;
if (auto const coverMin = tx[~sfCoverRateMinimum])
broker->at(sfCoverRateMinimum) = *coverMin;
@@ -198,7 +203,7 @@ LoanBrokerSet::doApply()
view.insert(broker);
}
return temDISABLED;
return tesSUCCESS;
}
//------------------------------------------------------------------------------

View File

@@ -502,7 +502,11 @@ dirNext(
describeOwnerDir(AccountID const& account);
[[nodiscard]] TER
dirLink(ApplyView& view, AccountID const& owner, std::shared_ptr<SLE>& object);
dirLink(
ApplyView& view,
AccountID const& owner,
std::shared_ptr<SLE>& object,
SF_UINT64 const& node = sfOwnerNode);
AccountID
pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey);

View File

@@ -1030,13 +1030,17 @@ describeOwnerDir(AccountID const& account)
}
TER
dirLink(ApplyView& view, AccountID const& owner, std::shared_ptr<SLE>& object)
dirLink(
ApplyView& view,
AccountID const& owner,
std::shared_ptr<SLE>& object,
SF_UINT64 const& node)
{
auto const page = view.dirInsert(
keylet::ownerDir(owner), object->key(), describeOwnerDir(owner));
if (!page)
return tecDIR_FULL; // LCOV_EXCL_LINE
object->setFieldU64(sfOwnerNode, *page);
object->setFieldU64(node, *page);
return tesSUCCESS;
}