clean up structs

This commit is contained in:
Mayukha Vadari
2026-05-18 17:48:08 -04:00
parent 4d349abb1d
commit e92c5c4532
12 changed files with 36 additions and 52 deletions

View File

@@ -75,14 +75,8 @@ Keylet const&
negativeUNL() noexcept;
/** The beginning of an order book */
struct BookT
{
explicit BookT() = default;
Keylet
operator()(Book const& b) const;
};
static BookT const kBook{};
Keylet
book(Book const& b);
/** The index of a trust line for a given currency
@@ -119,33 +113,23 @@ Keylet
quality(Keylet const& k, std::uint64_t q) noexcept;
/** The directory for the next lower quality */
struct NextT
{
explicit NextT() = default;
Keylet
operator()(Keylet const& k) const;
};
static NextT const kNext{};
Keylet
next(Keylet const& k);
/** A ticket belonging to an account */
struct TicketT
/** @{ */
Keylet
ticket(AccountID const& id, std::uint32_t ticketSeq);
Keylet
ticket(AccountID const& id, SeqProxy ticketSeq);
inline Keylet
ticket(uint256 const& key)
{
explicit TicketT() = default;
Keylet
operator()(AccountID const& id, std::uint32_t ticketSeq) const;
Keylet
operator()(AccountID const& id, SeqProxy ticketSeq) const;
Keylet
operator()(uint256 const& key) const
{
return {ltTICKET, key};
}
};
static TicketT const kTicket{};
return {ltTICKET, key};
}
/** @} */
/** A SignerList */
Keylet

View File

@@ -112,7 +112,7 @@ LEDGER_ENTRY(ltSIGNER_LIST, 0x0053, SignerList, signer_list, ({
/** A ledger object which describes a ticket.
\sa keylet::kTicket
\sa keylet::ticket
*/
LEDGER_ENTRY(ltTICKET, 0x0054, Ticket, ticket, ({
{sfAccount, SoeRequired},

View File

@@ -232,7 +232,7 @@ negativeUNL() noexcept
}
Keylet
BookT::operator()(Book const& b) const
book(Book const& b)
{
return {ltDIR_NODE, getBookBase(b)};
}
@@ -285,20 +285,20 @@ quality(Keylet const& k, std::uint64_t q) noexcept
}
Keylet
NextT::operator()(Keylet const& k) const
next(Keylet const& k)
{
XRPL_ASSERT(k.type == ltDIR_NODE, "xrpl::keylet::NextT::operator() : valid input type");
XRPL_ASSERT(k.type == ltDIR_NODE, "xrpl::keylet::next : valid input type");
return {ltDIR_NODE, getQualityNext(k.key)};
}
Keylet
TicketT::operator()(AccountID const& id, std::uint32_t ticketSeq) const
ticket(AccountID const& id, std::uint32_t ticketSeq)
{
return {ltTICKET, getTicketIndex(id, ticketSeq)};
}
Keylet
TicketT::operator()(AccountID const& id, SeqProxy ticketSeq) const
ticket(AccountID const& id, SeqProxy ticketSeq)
{
return {ltTICKET, getTicketIndex(id, ticketSeq)};
}

View File

@@ -492,7 +492,7 @@ Transactor::checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j
}
// Transaction can never succeed if the Ticket is not in the ledger.
if (!view.exists(keylet::kTicket(id, tSeqProx)))
if (!view.exists(keylet::ticket(id, tSeqProx)))
{
JLOG(j.trace()) << "applyTransaction: ticket already used or never created "
<< "a_seq=" << aSeq << " t_seq=" << tSeqProx;
@@ -557,7 +557,7 @@ Transactor::ticketDelete(
{
// Delete the Ticket, adjust the account root ticket count, and
// reduce the owner count.
SLE::pointer const sleTicket = view.peek(keylet::kTicket(ticketIndex));
SLE::pointer const sleTicket = view.peek(keylet::ticket(ticketIndex));
if (!sleTicket)
{
// LCOV_EXCL_START

View File

@@ -369,7 +369,7 @@ applyCreate(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Jou
<< lpTokens << " " << amount << " " << amount2;
auto addOrderBook = [&](Asset const& assetIn, Asset const& assetOut, std::uint64_t uRate) {
Book const book{assetIn, assetOut, std::nullopt};
auto const dir = keylet::quality(keylet::kBook(book), uRate);
auto const dir = keylet::quality(keylet::book(book), uRate);
if (auto const bookExisted = static_cast<bool>(sb.read(dir)); !bookExisted)
ctx.registry.get().getOrderBookDB().addOrderBook(book);
};

View File

@@ -559,7 +559,7 @@ OfferCreate::applyHybrid(
// if offer is hybrid, need to also place into open offer dir
Book const book{saTakerPays.asset(), saTakerGets.asset(), std::nullopt};
auto dir = keylet::quality(keylet::kBook(book), getRate(saTakerGets, saTakerPays));
auto dir = keylet::quality(keylet::book(book), getRate(saTakerGets, saTakerPays));
bool const bookExists = sb.exists(dir);
auto const bookNode = sb.dirAppend(dir, offerKey, [&](SLE::ref sle) {
@@ -871,7 +871,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel)
// Hybrid domain offer - BookDirectory points to domain directory,
// and AdditionalBooks field stores one entry that points to the open
// directory
auto dir = keylet::quality(keylet::kBook(book), uRate);
auto dir = keylet::quality(keylet::book(book), uRate);
bool const bookExisted = static_cast<bool>(sb.peek(dir));
auto setBookDir = [&](SLE::ref sle, std::optional<uint256> const& maybeDomain) {

View File

@@ -100,7 +100,7 @@ TicketCreate::doApply()
for (std::uint32_t i = 0; i < ticketCount; ++i)
{
std::uint32_t const curTicketSeq = firstTicketSeq + i;
Keylet const ticketKeylet = keylet::kTicket(accountID_, curTicketSeq);
Keylet const ticketKeylet = keylet::ticket(accountID_, curTicketSeq);
SLE::pointer const sleTicket = std::make_shared<SLE>(ticketKeylet);
sleTicket->setAccountID(sfAccount, accountID_);

View File

@@ -662,7 +662,7 @@ public:
BEAST_EXPECT(closed->exists(keylet::account(bob.id())));
for (std::uint32_t i = 0; i < 250; ++i)
{
BEAST_EXPECT(closed->exists(keylet::kTicket(bob.id(), ticketSeq + i)));
BEAST_EXPECT(closed->exists(keylet::ticket(bob.id(), ticketSeq + i)));
}
}
@@ -681,7 +681,7 @@ public:
BEAST_EXPECT(!closed->exists(keylet::account(bob.id())));
for (std::uint32_t i = 0; i < 250; ++i)
{
BEAST_EXPECT(!closed->exists(keylet::kTicket(bob.id(), ticketSeq + i)));
BEAST_EXPECT(!closed->exists(keylet::ticket(bob.id(), ticketSeq + i)));
}
}
}

View File

@@ -140,7 +140,7 @@ class PermissionedDEX_test : public beast::unit_test::Suite
static uint256
getBookDirKey(Book const& book, STAmount const& takerPays, STAmount const& takerGets)
{
return keylet::quality(keylet::kBook(book), getRate(takerGets, takerPays)).key;
return keylet::quality(keylet::book(book), getRate(takerGets, takerPays)).key;
}
static std::optional<uint256>

View File

@@ -619,7 +619,7 @@ TEST(AccountSet, Ticket)
// Verify alice has 1 owner object (the ticket)
EXPECT_EQ(env.getAccountRoot(alice.id()).getOwnerCount(), 1u);
// Verify ticket exists
EXPECT_TRUE(env.getClosedLedger().exists(keylet::kTicket(alice.id(), ticketSeq)));
EXPECT_TRUE(env.getClosedLedger().exists(keylet::ticket(alice.id(), ticketSeq)));
// Try using a ticket that alice doesn't have
EXPECT_EQ(
@@ -629,7 +629,7 @@ TEST(AccountSet, Ticket)
env.close();
// Verify ticket still exists
EXPECT_TRUE(env.getClosedLedger().exists(keylet::kTicket(alice.id(), ticketSeq)));
EXPECT_TRUE(env.getClosedLedger().exists(keylet::ticket(alice.id(), ticketSeq)));
// Get alice's sequence before using the ticket
std::uint32_t const aliceSeq = env.getAccountRoot(alice.id()).getSequence();
@@ -642,7 +642,7 @@ TEST(AccountSet, Ticket)
// Verify ticket is consumed (no owner objects)
EXPECT_EQ(env.getAccountRoot(alice.id()).getOwnerCount(), 0u);
EXPECT_FALSE(env.getClosedLedger().exists(keylet::kTicket(alice.id(), ticketSeq)));
EXPECT_FALSE(env.getClosedLedger().exists(keylet::ticket(alice.id(), ticketSeq)));
// Verify alice's sequence did NOT advance (ticket use doesn't increment seq)
EXPECT_EQ(env.getAccountRoot(alice.id()).getSequence(), aliceSeq);

View File

@@ -163,7 +163,7 @@ public:
// Ticket should have been created by now. Remove if ticket
// does not exist.
return !view.exists(keylet::kTicket(acctID, seqProx));
return !view.exists(keylet::ticket(acctID, seqProx));
});
}

View File

@@ -764,7 +764,7 @@ TxQ::apply(
// If the transaction needs a Ticket is that Ticket in the ledger?
SeqProxy const acctSeqProx = SeqProxy::sequence((*sleAccount)[sfSequence]);
SeqProxy const txSeqProx = tx->getSeqProxy();
if (txSeqProx.isTicket() && !view.exists(keylet::kTicket(account, txSeqProx)))
if (txSeqProx.isTicket() && !view.exists(keylet::ticket(account, txSeqProx)))
{
if (txSeqProx.value() < acctSeqProx.value())
{