Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/xrpl/ledger/ApplyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class ApplyView : public ReadView
// Called when the owner count changes
// This is required to support PaymentSandbox
virtual void
adjustOwnerCountHook(AccountID const& account, std::uint32_t cur, std::uint32_t next)
adjustOwnerCountHook(AccountID const& account, OwnerCounts const& cur, OwnerCounts const& next)
{
}

Expand Down
13 changes: 7 additions & 6 deletions include/xrpl/ledger/PaymentSandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ class DeferredCredits
issuerSelfDebitMPT(MPTIssue const& issue, std::uint64_t amount, std::int64_t origBalance);

void
ownerCount(AccountID const& id, std::uint32_t cur, std::uint32_t next);
ownerCount(AccountID const& id, OwnerCounts const& cur, OwnerCounts const& next);

// Get the adjusted owner count. Since DeferredCredits is meant to be used
// in payments, and payments only decrease owner counts, return the max
// remembered owner count.
[[nodiscard]] std::optional<std::uint32_t>
[[nodiscard]] std::optional<OwnerCounts>
ownerCount(AccountID const& id) const;

void
Expand All @@ -116,7 +116,7 @@ class DeferredCredits

std::map<KeyIOU, ValueIOU> creditsIOU_;
std::map<MPTID, IssuerValueMPT> creditsMPT_;
std::map<AccountID, std::uint32_t> ownerCounts_;
std::map<AccountID, OwnerCounts> ownerCounts_;
};

} // namespace detail
Expand Down Expand Up @@ -210,10 +210,11 @@ class PaymentSandbox final : public detail::ApplyViewBase
override;

void
adjustOwnerCountHook(AccountID const& account, std::uint32_t cur, std::uint32_t next) override;
adjustOwnerCountHook(AccountID const& account, OwnerCounts const& cur, OwnerCounts const& next)
override;

[[nodiscard]] std::uint32_t
ownerCountHook(AccountID const& account, std::uint32_t count) const override;
[[nodiscard]] OwnerCounts
ownerCountHook(AccountID const& account, OwnerCounts const& count) const override;

/** Apply changes to base view.

Expand Down
51 changes: 49 additions & 2 deletions include/xrpl/ledger/ReadView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,53 @@

namespace xrpl {

struct OwnerCounts
{
std::uint32_t owner = 0;
std::uint32_t sponsored = 0;
std::uint32_t sponsoring = 0;

OwnerCounts() = default;
OwnerCounts(SLE const& sle)
: owner(sle[sfOwnerCount])
, sponsored(sle[sfSponsoredOwnerCount])
, sponsoring(sle[sfSponsoringOwnerCount])
{
}

[[nodiscard]] std::uint32_t
count() const
{
int64_t const x = static_cast<int64_t>(owner) - sponsored + sponsoring;
if (x < 0)
return 0;
if (x > std::numeric_limits<std::uint32_t>::max())
return std::numeric_limits<std::uint32_t>::max();
return static_cast<std::uint32_t>(x);
}

auto
operator<=>(OwnerCounts const& o) const
{
return count() <=> o.count();
}

bool
operator==(OwnerCounts const& o) const
{
return this == &o || *this == o;
}

[[nodiscard]] bool
valid() const
{
int64_t const x = static_cast<int64_t>(owner) - sponsored + sponsoring;
if (x < 0 || x > std::numeric_limits<std::uint32_t>::max())
return false;
return owner >= sponsored;
}
};

//------------------------------------------------------------------------------

/** A view into a ledger.
Expand Down Expand Up @@ -182,8 +229,8 @@ class ReadView
// changes that accounts make during a payment. `ownerCountHook` adjusts the
// ownerCount so it returns the max value of the ownerCount so far.
// This is required to support PaymentSandbox.
[[nodiscard]] virtual std::uint32_t
ownerCountHook(AccountID const& account, std::uint32_t count) const
[[nodiscard]] virtual OwnerCounts
ownerCountHook(AccountID const& account, OwnerCounts const& count) const
{
return count;
}
Expand Down
Loading