mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 07:00:21 +00:00
[still WIP] make more progress
This commit is contained in:
@@ -398,7 +398,7 @@ public:
|
||||
emptyDirDelete(Keylet const& directory);
|
||||
};
|
||||
|
||||
struct ReserveTxContext
|
||||
struct ReserveContext
|
||||
{
|
||||
AccountID const accountID;
|
||||
SLE::pointer accountSle;
|
||||
@@ -411,7 +411,7 @@ struct ReserveTxContext
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
sponsorID.has_value() == !!sponsorSle,
|
||||
"ReserveTxContext::isSponsored : sponsor existence matches sponsorSle existence");
|
||||
"ReserveContext::isSponsored : sponsor existence matches sponsorSle existence");
|
||||
return sponsorID.has_value();
|
||||
}
|
||||
|
||||
@@ -421,8 +421,8 @@ struct ReserveTxContext
|
||||
return !!sponsorshipSle;
|
||||
}
|
||||
|
||||
static ReserveTxContext
|
||||
make(ApplyView& view, STTx const& tx)
|
||||
static ReserveContext
|
||||
makeFromTx(ApplyView& view, STTx const& tx)
|
||||
{
|
||||
auto const account = tx[sfAccount];
|
||||
auto const sponsor = tx[~sfSponsor];
|
||||
@@ -435,13 +435,16 @@ struct ReserveTxContext
|
||||
sponsor ? view.peek(keylet::sponsorship(*sponsor, account)) : nullptr,
|
||||
};
|
||||
}
|
||||
|
||||
static ReserveContext
|
||||
makeFromObject(ApplyView& view, SLE::ref objectSle, SLE::pointer ownerSle);
|
||||
};
|
||||
|
||||
struct ApplyViewContext
|
||||
{
|
||||
ApplyView& view;
|
||||
STTx const& tx;
|
||||
ReserveTxContext reserveContext;
|
||||
ReserveContext reserveContext;
|
||||
};
|
||||
|
||||
namespace directory {
|
||||
|
||||
@@ -88,24 +88,11 @@ adjustOwnerCount(
|
||||
|
||||
void
|
||||
adjustOwnerCountObj(
|
||||
ApplyView& view,
|
||||
SLE::ref accountSle,
|
||||
ApplyViewContext& ctx,
|
||||
SLE::ref objectSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
|
||||
|
||||
inline void
|
||||
adjustOwnerCountObj(
|
||||
ApplyView& view,
|
||||
AccountID const& account,
|
||||
SLE::ref objectSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()})
|
||||
{
|
||||
SLE::ref accountSle = view.peek(keylet::account(account));
|
||||
adjustOwnerCountObj(view, accountSle, objectSle, amount, j);
|
||||
}
|
||||
|
||||
/** Returns IOU issuer transfer fee as Rate. Rate specifies
|
||||
* the fee as fractions of 1 billion. For example, 1% transfer rate
|
||||
* is represented as 1,010,000,000.
|
||||
|
||||
@@ -21,6 +21,6 @@ namespace xrpl {
|
||||
*/
|
||||
// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile.
|
||||
TER
|
||||
offerDelete(ApplyView& view, SLE::ref sle, beast::Journal j);
|
||||
offerDelete(ApplyViewContext& ctx, SLE::ref sle, beast::Journal j);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/helpers/SponsorHelpers.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
#include <xrpl/protocol/Keylet.h>
|
||||
@@ -415,4 +416,17 @@ ApplyView::dirDelete(Keylet const& directory, std::function<void(uint256 const&)
|
||||
return true;
|
||||
}
|
||||
|
||||
static ReserveContext
|
||||
ReserveContext::makeFromObject(ApplyView& view, SLE::ref objectSle, SLE::pointer ownerSle)
|
||||
{
|
||||
SLE::ref sponsorSle = getLedgerEntryReserveSponsor(view, objectSle);
|
||||
std::optional<AccountID> const sponsorID =
|
||||
sponsorSle ? sponsorSle->getAccountID(sfAccount) : std::nullopt;
|
||||
return
|
||||
{
|
||||
ownerSle->getAccountID(sfAccount), ownerSle, sponsorID, sponsorSle,
|
||||
sponsorID ? view.peek(keylet::sponsorship(*sponsorID, account)) : nullptr,
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
@@ -226,7 +226,7 @@ transferRate(ReadView const& view, AccountID const& issuer)
|
||||
}
|
||||
|
||||
static void
|
||||
adjustOwnerCountHlp(
|
||||
adjustOwnerCountValue(
|
||||
ApplyView& view,
|
||||
SLE::ref sle,
|
||||
SF_UINT32 const& sfield,
|
||||
@@ -244,14 +244,18 @@ adjustOwnerCountHlp(
|
||||
}
|
||||
|
||||
void
|
||||
adjustOwnerCount(ApplyViewContext& ctx, std::int32_t adjustment, beast::Journal j)
|
||||
adjustOwnerCountImpl(
|
||||
ApplyView& view,
|
||||
ReserveContext& reserveCtx,
|
||||
std::int32_t adjustment,
|
||||
beast::Journal j)
|
||||
{
|
||||
auto& accountSle = ctx.reserveContext.accountSle;
|
||||
auto& accountSle = reserveCtx.accountSle;
|
||||
if (!accountSle)
|
||||
Throw<std::runtime_error>("xrpl::adjustOwnerCount : valid account sle");
|
||||
|
||||
auto const sleType = ctx.reserveContext.accountSle->getType();
|
||||
bool const validType = ctx.reserveContext.sponsorSle
|
||||
auto const sleType = reserveCtx.accountSle->getType();
|
||||
bool const validType = reserveCtx.sponsorSle
|
||||
? sleType == ltACCOUNT_ROOT
|
||||
: sleType == ltLOAN_BROKER || sleType == ltACCOUNT_ROOT;
|
||||
if (!validType)
|
||||
@@ -261,54 +265,54 @@ adjustOwnerCount(ApplyViewContext& ctx, std::int32_t adjustment, beast::Journal
|
||||
if (adjustment == 0)
|
||||
return;
|
||||
|
||||
if (ctx.reserveContext.isSponsored())
|
||||
if (reserveCtx.isSponsored())
|
||||
{
|
||||
if (ctx.reserveContext.sponsorSle->getType() != ltACCOUNT_ROOT)
|
||||
if (reserveCtx.sponsorSle->getType() != ltACCOUNT_ROOT)
|
||||
Throw<std::logic_error>("xrpl::adjustOwnerCount : valid sponsor sle type");
|
||||
|
||||
adjustOwnerCountHlp(
|
||||
adjustOwnerCountValue(
|
||||
ctx.view,
|
||||
ctx.reserveContext.accountSle,
|
||||
reserveCtx.accountSle,
|
||||
sfSponsoredOwnerCount,
|
||||
ctx.reserveContext.accountID,
|
||||
reserveCtx.accountID,
|
||||
adjustment,
|
||||
j);
|
||||
adjustOwnerCountHlp(
|
||||
adjustOwnerCountValue(
|
||||
ctx.view,
|
||||
ctx.reserveContext.sponsorSle,
|
||||
reserveCtx.sponsorSle,
|
||||
sfSponsoringOwnerCount,
|
||||
*ctx.reserveContext.sponsorID,
|
||||
*reserveCtx.sponsorID,
|
||||
adjustment,
|
||||
j);
|
||||
|
||||
if (ctx.reserveContext.sponsorshipSle && adjustment > 0)
|
||||
if (reserveCtx.sponsorshipSle && adjustment > 0)
|
||||
{
|
||||
// update the pre-funded RemainingOwnerCount on Sponsorship ledger object
|
||||
// Remaining owner count moves opposite to adjustment:
|
||||
// +adjustment => consume reserve (-),
|
||||
adjustOwnerCountHlp(
|
||||
adjustOwnerCountValue(
|
||||
ctx.view,
|
||||
ctx.reserveContext.sponsorshipSle,
|
||||
reserveCtx.sponsorshipSle,
|
||||
sfRemainingOwnerCount,
|
||||
*ctx.reserveContext.sponsorID,
|
||||
*reserveCtx.sponsorID,
|
||||
-adjustment,
|
||||
j,
|
||||
false);
|
||||
}
|
||||
}
|
||||
adjustOwnerCountHlp(
|
||||
ctx.view,
|
||||
ctx.reserveContext.accountSle,
|
||||
sfOwnerCount,
|
||||
ctx.reserveContext.accountID,
|
||||
adjustment,
|
||||
j);
|
||||
adjustOwnerCountValue(
|
||||
ctx.view, reserveCtx.accountSle, sfOwnerCount, reserveCtx.accountID, adjustment, j);
|
||||
}
|
||||
|
||||
void
|
||||
adjustOwnerCount(ApplyViewContext& ctx, std::int32_t amount, beast::Journal j)
|
||||
{
|
||||
return adjustOwnerCountImpl(ctx.view, ctx.reserveCtx, amount, j);
|
||||
}
|
||||
|
||||
void
|
||||
adjustOwnerCountObj(
|
||||
ApplyViewContext& view,
|
||||
SLE::ref accountSle,
|
||||
ApplyViewContext& ctx,
|
||||
SLE::ref objectSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j)
|
||||
@@ -318,8 +322,12 @@ adjustOwnerCountObj(
|
||||
if (objectSle->getType() == ltACCOUNT_ROOT)
|
||||
Throw<std::logic_error>("xrpl::adjustOwnerCount : valid object sle type");
|
||||
|
||||
SLE::ref sponsorSle = getLedgerEntryReserveSponsor(view, objectSle);
|
||||
adjustOwnerCount(view, accountSle, sponsorSle, amount, j);
|
||||
SLE::ref sponsorSle = getLedgerEntryReserveSponsor(ctx.view, objectSle);
|
||||
adjustOwnerCountImpl(
|
||||
ctx.view,
|
||||
ReserveContext::makeFromObj(ctx.view, objectSle, ctx.reserveCtx.accountSle),
|
||||
amount,
|
||||
j);
|
||||
}
|
||||
|
||||
XRPAmount
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
namespace xrpl {
|
||||
|
||||
TER
|
||||
offerDelete(ApplyView& view, SLE::ref sle, beast::Journal j)
|
||||
offerDelete(ApplyViewContext& ctx, SLE::ref sle, beast::Journal j)
|
||||
{
|
||||
if (!sle)
|
||||
return tesSUCCESS;
|
||||
@@ -55,7 +55,7 @@ offerDelete(ApplyView& view, SLE::ref sle, beast::Journal j)
|
||||
}
|
||||
}
|
||||
|
||||
adjustOwnerCountObj(view, owner, sle, -1, j);
|
||||
adjustOwnerCountObj(ctx, sle, -1, j);
|
||||
|
||||
view.erase(sle);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ ApplyContext::ApplyContext(
|
||||
, flags_(flags)
|
||||
, view_{std::in_place, &base_, flags_}
|
||||
, parentBatchId_(parentBatchId)
|
||||
, viewCtx_{.view = *view_, .tx = tx, .reserveContext = ReserveTxContext::make(*view_, tx)}
|
||||
, viewCtx_{.view = *view_, .tx = tx, .reserveContext = ReserveContext::makeFromTx(*view_, tx)}
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
parentBatchId.has_value() == ((flags_ & TapBatch) == TapBatch),
|
||||
|
||||
Reference in New Issue
Block a user