mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Code cleanup in SetTrust
This commit is contained in:
@@ -179,14 +179,16 @@ SetTrust::preclaim(PreclaimContext const& ctx)
|
|||||||
|
|
||||||
// This might be nullptr
|
// This might be nullptr
|
||||||
auto const sleDst = ctx.view.read(keylet::account(uDstAccountID));
|
auto const sleDst = ctx.view.read(keylet::account(uDstAccountID));
|
||||||
|
if ((ctx.view.rules().enabled(featureDisallowIncoming) ||
|
||||||
|
ammEnabled(ctx.view.rules()) ||
|
||||||
|
ctx.view.rules().enabled(featureSingleAssetVault)) &&
|
||||||
|
sleDst == nullptr)
|
||||||
|
return tecNO_DST;
|
||||||
|
|
||||||
// If the destination has opted to disallow incoming trustlines
|
// If the destination has opted to disallow incoming trustlines
|
||||||
// then honour that flag
|
// then honour that flag
|
||||||
if (ctx.view.rules().enabled(featureDisallowIncoming))
|
if (ctx.view.rules().enabled(featureDisallowIncoming))
|
||||||
{
|
{
|
||||||
if (!sleDst)
|
|
||||||
return tecNO_DST;
|
|
||||||
|
|
||||||
if (sleDst->getFlags() & lsfDisallowIncomingTrustline)
|
if (sleDst->getFlags() & lsfDisallowIncomingTrustline)
|
||||||
{
|
{
|
||||||
// The original implementation of featureDisallowIncoming was
|
// The original implementation of featureDisallowIncoming was
|
||||||
@@ -204,18 +206,22 @@ SetTrust::preclaim(PreclaimContext const& ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If destination is AMM and the trustline doesn't exist then only
|
// In general, trust lines to pseudo accounts are not permitted, unless
|
||||||
// allow SetTrust if the asset is AMM LP token and AMM is not
|
// enabled in the code section below, for specific cases. This block is not
|
||||||
// in empty state.
|
// amendment-gated because sleDst will not have a pseudo-account designator
|
||||||
if (ammEnabled(ctx.view.rules()))
|
// field populated, unless the appropriate amendment was already enabled.
|
||||||
|
if (sleDst && isPseudoAccount(sleDst))
|
||||||
{
|
{
|
||||||
if (!sleDst)
|
// If destination is AMM and the trustline doesn't exist then only allow
|
||||||
return tecNO_DST;
|
// SetTrust if the asset is AMM LP token and AMM is not in empty state.
|
||||||
|
if (sleDst->isFieldPresent(sfAMMID))
|
||||||
if (sleDst->isFieldPresent(sfAMMID) &&
|
|
||||||
!ctx.view.read(keylet::line(id, uDstAccountID, currency)))
|
|
||||||
{
|
{
|
||||||
if (auto const ammSle =
|
if (ctx.view.read(keylet::line(id, uDstAccountID, currency)))
|
||||||
|
{
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
auto const ammSle =
|
||||||
ctx.view.read({ltAMM, sleDst->getFieldH256(sfAMMID)}))
|
ctx.view.read({ltAMM, sleDst->getFieldH256(sfAMMID)}))
|
||||||
{
|
{
|
||||||
if (auto const lpTokens =
|
if (auto const lpTokens =
|
||||||
@@ -226,29 +232,19 @@ SetTrust::preclaim(PreclaimContext const& ctx)
|
|||||||
return tecNO_PERMISSION;
|
return tecNO_PERMISSION;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return tecINTERNAL;
|
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
}
|
else if (sleDst->isFieldPresent(sfVaultID))
|
||||||
|
|
||||||
// If destination is Vault, allow changes to the existing trustline.
|
|
||||||
if (ctx.view.rules().enabled(featureSingleAssetVault))
|
|
||||||
{
|
{
|
||||||
if (!sleDst)
|
if (ctx.view.read(keylet::line(id, uDstAccountID, currency)))
|
||||||
return tecNO_DST;
|
|
||||||
|
|
||||||
bool const isVault = sleDst->isFieldPresent(sfVaultID);
|
|
||||||
if (isVault &&
|
|
||||||
!ctx.view.read(keylet::line(id, uDstAccountID, currency)))
|
|
||||||
return tecNO_PERMISSION;
|
|
||||||
else if (isVault)
|
|
||||||
{
|
{
|
||||||
if (ctx.view.read(keylet::vault(sleDst->getFieldH256(sfVaultID))))
|
// pass
|
||||||
{
|
|
||||||
// Allow updating the state of existing trust line for the vault
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return tecINTERNAL;
|
return tecNO_PERMISSION;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return tecPSEUDO_ACCOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking all freeze/deep freeze flag invariants.
|
// Checking all freeze/deep freeze flag invariants.
|
||||||
|
|||||||
Reference in New Issue
Block a user