1#include <xrpl/tx/transactors/system/TicketCreate.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/DirectoryHelpers.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/Keylet.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/XRPAmount.h>
16#include <xrpl/tx/Transactor.h>
17#include <xrpl/tx/applySteps.h>
44 auto const id = ctx.
tx[sfAccount];
51 std::uint32_t const curTicketCount = (*sleAccountRoot)[~sfTicketCount].value_or(0u);
92 std::uint32_t const firstTicketSeq = (*sleAccountRoot)[sfSequence];
97 txSeq != 0 && txSeq != (firstTicketSeq - 1))
106 sleTicket->setAccountID(sfAccount,
accountID_);
107 sleTicket->setFieldU32(sfTicketSequence, curTicketSeq);
113 JLOG(
j_.trace()) <<
"Creating ticket " <<
to_string(ticketKeylet.
key) <<
": "
114 << (page ?
"success" :
"failure");
119 sleTicket->setFieldU64(sfOwnerNode, *page);
123 std::uint32_t const oldTicketCount = (*sleAccountRoot)[~sfTicketCount].valueOr(0u);
125 sleAccountRoot->setFieldU32(sfTicketCount, oldTicketCount + ticketCount);
132 sleAccountRoot->setFieldU32(sfSequence, firstTicketSeq + ticketCount);
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void insert(SLE::ref sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(SLE::ref)> const &describe)
Insert an entry to a directory.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
SeqProxy getSeqProxy() const
constexpr bool isTicket() const
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
static constexpr std::uint32_t kMaxTicketThreshold
TER doApply() override
Precondition: fee collection is likely.
static TER preclaim(PreclaimContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static constexpr std::uint32_t kMaxValidCount
AccountID const accountID_
Class describing the consequences to the account of applying a transaction if the transaction consume...
Keylet ticket(AccountID const &id, std::uint32_t ticketSeq)
A ticket belonging to an account.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(BaseUInt< Bits, Tag > const &a)
TERSubset< CanCvtToNotTEC > NotTEC
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.