xrpld
Loading...
Searching...
No Matches
TransactionProposalCancel.cpp
1#include <xrpl/tx/transactors/proposal/TransactionProposalCancel.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/helpers/ProposalHelpers.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STObject.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/XRPAmount.h>
17#include <xrpl/tx/Transactor.h>
18
19namespace xrpl {
20
23{
24 if (ctx.tx[sfProposalID] == beast::kZero)
25 {
26 JLOG(ctx.j.debug()) << "TransactionProposalCancel: zero ProposalID.";
27 return temMALFORMED;
28 }
29
30 return tesSUCCESS;
31}
32
33TER
35{
36 uint256 const proposalID = ctx.tx[sfProposalID];
37
38 // Never read the zero keylet. Preflight already rejected a zero
39 // ProposalID, and no real proposal can have one (every ProposalID is a
40 // hash), so reaching here with zero is an internal error (and a mathematical rarity).
41 if (proposalID == beast::kZero)
42 return tefINTERNAL; // LCOV_EXCL_LINE
43
44 auto const sleProposal = ctx.view.read(keylet::txProposal(proposalID));
45 if (!sleProposal)
46 {
47 JLOG(ctx.j.debug()) << "TransactionProposalCancel: proposal does not exist.";
48 return tecNO_ENTRY;
49 }
50
51 STObject const proposedTx = sleProposal->getFieldObject(sfProposedTransaction);
52
53 // A terminal proposal is closed to new signatures, so anyone may delete
54 // it and release the Owner's reserve (On-Chain Cosigner spec §7.2). Being
55 // terminal does not stop an already signed payload from executing; see
56 // proposal::isTerminal.
57 bool const terminal = proposal::isTerminal(ctx.view, (*sleProposal)[~sfExpiration], proposedTx);
58
59 // A live proposal may only be cancelled by its Owner (the proposer) or
60 // by its target. The target is the account the proposed transaction
61 // would execute against (its Account field) or the Delegate named in it.
62 // Targets may always refuse a proposal, because anyone can create one
63 // against any account and doing so ties up one of that account's
64 // tickets (On-Chain Cosigner spec §7.2).
65 //
66 // The Delegate is read from the stored payload as-is; whether that
67 // delegation exists on-ledger is not checked. The proposal asks that
68 // account to sign, so that account may refuse — and refusing only
69 // deletes the proposer's own entry and returns the proposer's own
70 // reserve.
71 AccountID const account = ctx.tx[sfAccount];
72 bool const ownerOrTarget = account == sleProposal->getAccountID(sfOwner) ||
73 account == proposedTx.getAccountID(sfAccount) || account == proposedTx[~sfDelegate];
74
75 if (!terminal && !ownerOrTarget)
76 {
77 JLOG(ctx.j.debug()) << "TransactionProposalCancel: proposal is live and "
78 "canceller is neither its Owner nor its target.";
79 return tecNO_PERMISSION;
80 }
81
82 return tesSUCCESS;
83}
84
85TER
87{
88 uint256 const proposalID = ctx_.tx[sfProposalID];
89
90 // Never read the zero keylet; see the matching guard in preclaim.
91 if (proposalID == beast::kZero)
92 return tefINTERNAL; // LCOV_EXCL_LINE
93
94 auto const sleProposal = view().peek(keylet::txProposal(proposalID));
95 if (!sleProposal)
96 return tefINTERNAL; // LCOV_EXCL_LINE
97
98 return proposal::deleteProposal(view(), sleProposal, ctx_.registry.get().getJournal("View"));
99}
100
101void
103{
104 // No transaction-specific invariants yet (future work).
105}
106
107bool
109 STTx const&,
110 TER,
111 XRPAmount,
112 ReadView const&,
113 beast::Journal const&)
114{
115 // No transaction-specific invariants yet (future work).
116 return true;
117}
118
119} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream debug() const
Definition Journal.h:344
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
A view into a ledger.
Definition ReadView.h:41
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & ConstRef
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:678
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:643
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
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 NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
ApplyView & view()
Definition Transactor.h:184
ApplyContext & ctx_
Definition Transactor.h:162
constexpr Zero kZero
Definition Zero.h:30
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Definition Indexes.cpp:378
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).
TER deleteProposal(ApplyView &view, SLE::pointer const &sleProposal, beast::Journal j)
Delete a TransactionProposal ledger entry.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:167
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:617
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
@ temMALFORMED
Definition TER.h:75
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecNO_ENTRY
Definition TER.h:317
@ tecNO_PERMISSION
Definition TER.h:316
@ tesSUCCESS
Definition TER.h:253
UInt256 uint256
Definition base_uint.h:587
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
ReadView const & view
Definition Transactor.h:95
beast::Journal const j
Definition Transactor.h:100
State information when preflighting a tx.
Definition Transactor.h:39
beast::Journal const j
Definition Transactor.h:46