mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-25 16:10:57 +00:00
refactor: Move reserve checks from preclaim to doApply where relevant
This commit is contained in:
@@ -181,14 +181,17 @@ OracleSet::preclaim(PreclaimContext const& ctx)
|
||||
if (pairs.size() > kMaxOracleDataSeries)
|
||||
return tecARRAY_TOO_LARGE;
|
||||
|
||||
auto const& balance = sleSetter->getFieldAmount(sfBalance);
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx.view, ctx.tx);
|
||||
if (!sponsorSle)
|
||||
return sponsorSle.error(); // LCOV_EXCL_LINE
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx.view, ctx.tx, sleSetter, balance, *sponsorSle, adjustReserve, 0, ctx.j);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
if (!ctx.view.rules().enabled(featureSponsor))
|
||||
{
|
||||
auto const& balance = sleSetter->getFieldAmount(sfBalance);
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx.view, ctx.tx);
|
||||
if (!sponsorSle)
|
||||
return sponsorSle.error(); // LCOV_EXCL_LINE
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx.view, ctx.tx, sleSetter, balance, *sponsorSle, adjustReserve, 0, ctx.j);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
@@ -276,6 +279,28 @@ OracleSet::doApply()
|
||||
if (!accountSle)
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
if (ctx_.view().rules().enabled(featureSponsor))
|
||||
{
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx_.view(), ctx_.tx);
|
||||
if (!sponsorSle)
|
||||
return sponsorSle.error(); // LCOV_EXCL_LINE
|
||||
auto const delta = (getLedgerEntryReserveSponsorAccountID(sle) ==
|
||||
getTxReserveSponsorAccountID(ctx_.tx))
|
||||
? adjust
|
||||
: static_cast<std::int32_t>(newCount);
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(),
|
||||
ctx_.tx,
|
||||
accountSle,
|
||||
STAmount{preFeeBalance_},
|
||||
*sponsorSle,
|
||||
delta,
|
||||
0,
|
||||
j_);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (adjust > 0)
|
||||
{
|
||||
// To continue receiving sponsorship from the same account after the
|
||||
@@ -354,6 +379,21 @@ OracleSet::doApply()
|
||||
if (!accountSle)
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
if (ctx_.view().rules().enabled(featureSponsor))
|
||||
{
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(),
|
||||
ctx_.tx,
|
||||
accountSle,
|
||||
STAmount{preFeeBalance_},
|
||||
*sponsorSle,
|
||||
count,
|
||||
0,
|
||||
j_);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
}
|
||||
|
||||
adjustOwnerCount(ctx_.view(), accountSle, *sponsorSle, count, ctx_.journal);
|
||||
addSponsorToLedgerEntry(sle, *sponsorSle);
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ PaymentChannelCreate::preclaim(PreclaimContext const& ctx)
|
||||
return terNO_ACCOUNT;
|
||||
|
||||
// Check reserve and funds availability
|
||||
if (!ctx.view.rules().enabled(featureSponsor))
|
||||
{
|
||||
auto const balance = (*sle)[sfBalance];
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx.view, ctx.tx);
|
||||
@@ -137,6 +138,28 @@ PaymentChannelCreate::doApply()
|
||||
return tecEXPIRED;
|
||||
}
|
||||
|
||||
if (ctx_.view().rules().enabled(featureSponsor))
|
||||
{
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx_.view(), ctx_.tx);
|
||||
if (!sponsorSle)
|
||||
return sponsorSle.error(); // LCOV_EXCL_LINE
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(), ctx_.tx, sle, STAmount{preFeeBalance_}, *sponsorSle, 1, 0, j_);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(),
|
||||
ctx_.tx,
|
||||
sle,
|
||||
STAmount{preFeeBalance_ - ctx_.tx[sfAmount].xrp()},
|
||||
*sponsorSle,
|
||||
1,
|
||||
0,
|
||||
j_);
|
||||
!isTesSuccess(ret))
|
||||
return tecUNFUNDED;
|
||||
}
|
||||
|
||||
auto const dst = ctx_.tx[sfDestination];
|
||||
|
||||
// Create PayChan in ledger.
|
||||
|
||||
Reference in New Issue
Block a user