1#include <xrpl/ledger/helpers/ProposalHelpers.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/ledger/View.h>
10#include <xrpl/ledger/helpers/AccountRootHelpers.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/Keylet.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STArray.h>
17#include <xrpl/protocol/STLedgerEntry.h>
18#include <xrpl/protocol/STObject.h>
19#include <xrpl/protocol/STTx.h>
20#include <xrpl/protocol/Serializer.h>
21#include <xrpl/protocol/TER.h>
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/TxFormats.h>
36constexpr auto kProposalTxTypes = std::to_array<TxType>({
37 ttTRANSACTION_PROPOSAL_CREATE,
38 ttTRANSACTION_PROPOSAL_CANCEL,
49 auto const type = proposedTx.
getFieldU16(sfTransactionType);
61 if (type == ttBATCH && proposedTx.
isFieldPresent(sfRawTransactions))
64 for (
STObject const& inner : innerTxns)
69 if (!inner.isFieldPresent(sfTransactionType))
72 auto const innerType = inner.getFieldU16(sfTransactionType);
105 if (!sleProposal || sleProposal->getType() != ltTRANSACTION_PROPOSAL ||
106 !view.
exists(
Keylet{ltTRANSACTION_PROPOSAL, sleProposal->key()}))
109 JLOG(j.
fatal()) <<
"Invalid TransactionProposal deletion.";
114 AccountID const owner = sleProposal->getAccountID(sfOwner);
120 JLOG(j.
fatal()) <<
"Unable to delete TransactionProposal from owner.";
129 JLOG(j.
fatal()) <<
"Could not find TransactionProposal owner account root.";
143 view.
erase(sleProposal);
152 "xrpl::proposal::payloadMatches : transaction-shaped inputs");
162 auto const payloadBytes = [](
STObject const& obj) {
164 copy.setFieldVL(sfSigningPubKey,
Slice{});
166 copy.addWithoutSigningFields(s);
170 return payloadBytes(proposedTx) == payloadBytes(tx);
177 if (!seqProx.isTicket())
181 UNREACHABLE(
"xrpl::proposal::canConsumeTicket : tx spends a Sequence");
186 auto const sleProposal =
191 return payloadMatches(sleProposal->getFieldObject(sfProposedTransaction), tx);
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
bool dirRemove(Keylet const &directory, std::uint64_t page, UInt256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(SLE::Ref sle)=0
Remove a peeked SLE.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
std::shared_ptr< STLedgerEntry > pointer
std::uint32_t getFieldU32(SField const &field) const
STArray const & getFieldArray(SField const &field) const
bool isFieldPresent(SField const &field) const
AccountID getAccountID(SField const &field) const
std::uint16_t getFieldU16(SField const &field) const
SeqProxy getSeqProxy() const
An immutable linear range of bytes.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Keylet account(AccountID const &id) noexcept
AccountID root.
bool isTerminal(ReadView const &view, std::optional< std::uint32_t > expiration, STObject const &proposedTx)
Whether the proposal is terminal (On-Chain Cosigner spec §4.5).
std::uint32_t proposalOwnerCount(STObject const &proposedTx)
Owner-reserve increments held by a proposal of the given transaction.
bool payloadMatches(STObject const &proposedTx, STObject const &tx)
Whether tx carries the same payload as a proposal's stored ProposedTransaction (On-Chain Cosigner spe...
bool canConsumeTicket(ReadView const &view, STTx const &tx)
Whether tx may consume its Ticket.
bool isValidProposalTxnType(STObject const &proposedTx)
Whether the proposed transaction is independently submittable through the ordinary multi-sign path: n...
TER deleteProposal(ApplyView &view, SLE::pointer const &sleProposal, beast::Journal j)
Delete a TransactionProposal ledger entry.
constexpr FlagValue tfInnerBatchTxn
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp, ExpiryComparison comparison=ExpiryComparison::Inclusive)
Determines whether the given expiration time has passed.
void decreaseOwnerCountForObject(ApplyView &view, SLE::Ref accountSle, SLE::Ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
A pair of SHAMap key and LedgerEntryType.