mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
doc: Expand explanation for LoanBrokerCoverClawback::determineBrokerID
This commit is contained in:
@@ -57,26 +57,44 @@ LoanBrokerCoverClawback::preflight(PreflightContext const& ctx)
|
|||||||
Expected<uint256, TER>
|
Expected<uint256, TER>
|
||||||
determineBrokerID(ReadView const& view, STTx const& tx)
|
determineBrokerID(ReadView const& view, STTx const& tx)
|
||||||
{
|
{
|
||||||
|
// If the broker ID was provided in the transaction, that's all we
|
||||||
|
// need.
|
||||||
if (auto const brokerID = tx[~sfLoanBrokerID])
|
if (auto const brokerID = tx[~sfLoanBrokerID])
|
||||||
return *brokerID;
|
return *brokerID;
|
||||||
|
|
||||||
|
// If the broker ID was not provided, and the amount is either
|
||||||
|
// absent or holds a non-IOU - including MPT, something went wrong,
|
||||||
|
// because that should have been rejected in preflight().
|
||||||
auto const dstAmount = tx[~sfAmount];
|
auto const dstAmount = tx[~sfAmount];
|
||||||
if (!dstAmount || !dstAmount->holds<Issue>())
|
if (!dstAmount || !dstAmount->holds<Issue>())
|
||||||
return Unexpected{tecINTERNAL}; // LCOV_EXCL_LINE
|
return Unexpected{tecINTERNAL}; // LCOV_EXCL_LINE
|
||||||
|
|
||||||
// Since we don't have a LoanBrokerID, holder _should_ be the loan broker's
|
// Every trust line is bidirectional. Both sides are simultaneously
|
||||||
// pseudo-account, but we don't know yet whether it is, so use a generic
|
// issuer and holder. For this transaction, the Account is acting as
|
||||||
// placeholder name.
|
// a holder, and clawing back funds from the LoanBroker
|
||||||
auto const holder = dstAmount->getIssuer();
|
// Pseudo-account acting as holder. If the Amount is an IOU, and the
|
||||||
auto const sle = view.read(keylet::account(holder));
|
// `issuer` field specified in that Amount is a LoanBroker
|
||||||
|
// Pseudo-account, we can get the LoanBrokerID from there.
|
||||||
|
//
|
||||||
|
// Thus, Amount.issuer _should_ be the loan broker's
|
||||||
|
// pseudo-account, but we don't know yet whether it is.
|
||||||
|
auto const maybePseudo = dstAmount->getIssuer();
|
||||||
|
auto const sle = view.read(keylet::account(maybePseudo));
|
||||||
|
|
||||||
|
// If the account was not found, the transaction can't go further.
|
||||||
if (!sle)
|
if (!sle)
|
||||||
return Unexpected{tecNO_ENTRY};
|
return Unexpected{tecNO_ENTRY};
|
||||||
|
|
||||||
|
// If the account was found, and has a LoanBrokerID (and therefore
|
||||||
|
// is a pseudo-account), that's the
|
||||||
|
// answer we need.
|
||||||
if (auto const brokerID = sle->at(~sfLoanBrokerID))
|
if (auto const brokerID = sle->at(~sfLoanBrokerID))
|
||||||
return *brokerID;
|
return *brokerID;
|
||||||
|
|
||||||
// Or tecWRONG_ASSET?
|
// If the account does not have a LoanBrokerID, the transaction
|
||||||
|
// can't go further, even if it's a different type of Pseudo-account.
|
||||||
return Unexpected{tecOBJECT_NOT_FOUND};
|
return Unexpected{tecOBJECT_NOT_FOUND};
|
||||||
|
// Or tecWRONG_ASSET?
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<Asset, TER>
|
Expected<Asset, TER>
|
||||||
|
|||||||
Reference in New Issue
Block a user