mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 09:16:47 +00:00
add calculateReserve helper
This commit is contained in:
@@ -553,6 +553,9 @@ areCompatible(
|
||||
uint32_t
|
||||
ownerCount(std::shared_ptr<SLE const> const& sponsorSle);
|
||||
|
||||
XRPAmount
|
||||
calculateReserve(std::shared_ptr<SLE const> const& sle, Fees const& fees);
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx);
|
||||
|
||||
|
||||
@@ -732,20 +732,10 @@ xrpLiquid(
|
||||
std::uint32_t const ownerCount = confineOwnerCount(
|
||||
view.ownerCountHook(id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj);
|
||||
|
||||
std::size_t sponsoredOwnerCount = sle->getFieldU32(sfSponsoredOwnerCount);
|
||||
std::size_t sponsoringOwnerCount = sle->getFieldU32(sfSponsoringOwnerCount);
|
||||
bool isAccountSponsored = sle->isFieldPresent(sfSponsorAccount);
|
||||
std::size_t sponsoringAccountCount =
|
||||
sle->getFieldU32(sfSponsoringAccountCount);
|
||||
|
||||
// Pseudo-accounts have no reserve requirement
|
||||
auto const reserve = isPseudoAccount(sle) ? XRPAmount{0}
|
||||
: view.fees().accountReserve(
|
||||
ownerCount,
|
||||
sponsoredOwnerCount,
|
||||
sponsoringOwnerCount,
|
||||
isAccountSponsored,
|
||||
sponsoringAccountCount);
|
||||
auto const reserve = isPseudoAccount(sle)
|
||||
? XRPAmount{0}
|
||||
: calculateReserve(sle, view.fees());
|
||||
|
||||
auto const fullBalance = sle->getFieldAmount(sfBalance);
|
||||
|
||||
@@ -1146,6 +1136,21 @@ ownerCount(std::shared_ptr<SLE const> const& sponsorSle)
|
||||
return ownerCount + sponsoringOwnerCount - sponsoredOwnerCount;
|
||||
}
|
||||
|
||||
XRPAmount
|
||||
calculateReserve(std::shared_ptr<SLE const> const& sle, Fees const& fees)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
sle->getType() == ltACCOUNT_ROOT,
|
||||
"xrpl::calculateReserve : valid sle type");
|
||||
|
||||
return fees.accountReserve(
|
||||
sle->getFieldU32(sfOwnerCount),
|
||||
sle->getFieldU32(sfSponsoredOwnerCount),
|
||||
sle->getFieldU32(sfSponsoringOwnerCount),
|
||||
sle->isFieldPresent(sfSponsorAccount),
|
||||
sle->getFieldU32(sfSponsoringAccountCount));
|
||||
}
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx)
|
||||
{
|
||||
|
||||
@@ -612,24 +612,9 @@ Payment::doApply()
|
||||
if (!sleSrc)
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
// ownerCount is the number of entries in this ledger for this
|
||||
// account that require a reserve.
|
||||
auto const ownerCount = sleSrc->getFieldU32(sfOwnerCount);
|
||||
|
||||
// This is the total reserve in drops.
|
||||
std::size_t sponsoredOwnerCount =
|
||||
sleSrc->getFieldU32(sfSponsoredOwnerCount);
|
||||
std::size_t sponsoringOwnerCount =
|
||||
sleSrc->getFieldU32(sfSponsoringOwnerCount);
|
||||
bool isAccountSponsored = sleSrc->isFieldPresent(sfSponsorAccount);
|
||||
std::size_t sponsoringAccountCount =
|
||||
sleSrc->getFieldU32(sfSponsoringAccountCount);
|
||||
auto const reserve = view().fees().accountReserve(
|
||||
ownerCount,
|
||||
sponsoredOwnerCount,
|
||||
sponsoringOwnerCount,
|
||||
isAccountSponsored,
|
||||
sponsoringAccountCount);
|
||||
// the number of reserves in this ledger for this account that require a
|
||||
// reserve.
|
||||
auto const reserve = calculateReserve(sleSrc, view().fees());
|
||||
|
||||
// mPriorBalance is the balance on the sending account BEFORE the
|
||||
// fees were charged. We want to make sure we have enough reserve
|
||||
|
||||
@@ -428,20 +428,7 @@ transferHelper(
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
{
|
||||
auto const ownerCount = sleSrc->getFieldU32(sfOwnerCount);
|
||||
std::size_t sponsoredOwnerCount =
|
||||
sleSrc->getFieldU32(sfSponsoredOwnerCount);
|
||||
std::size_t sponsoringOwnerCount =
|
||||
sleSrc->getFieldU32(sfSponsoringOwnerCount);
|
||||
bool isAccountSponsored = sleSrc->isFieldPresent(sfSponsorAccount);
|
||||
std::size_t sponsoringAccountCount =
|
||||
sleSrc->getFieldU32(sfSponsoringAccountCount);
|
||||
auto const reserve = psb.fees().accountReserve(
|
||||
ownerCount,
|
||||
sponsoredOwnerCount,
|
||||
sponsoringOwnerCount,
|
||||
isAccountSponsored,
|
||||
sponsoringAccountCount);
|
||||
auto const reserve = calculateReserve(sleSrc, psb.fees());
|
||||
|
||||
auto const availableBalance = [&]() -> STAmount {
|
||||
STAmount const curBal = (*sleSrc)[sfBalance];
|
||||
|
||||
Reference in New Issue
Block a user