xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
tx
transactors
proposal
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
19
namespace
xrpl
{
20
21
NotTEC
22
TransactionProposalCancel::preflight
(
PreflightContext
const
& ctx)
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
33
TER
34
TransactionProposalCancel::preclaim
(
PreclaimContext
const
& ctx)
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
85
TER
86
TransactionProposalCancel::doApply
()
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
101
void
102
TransactionProposalCancel::visitInvariantEntry
(
bool
,
SLE::ConstRef
,
SLE::ConstRef
)
103
{
104
// No transaction-specific invariants yet (future work).
105
}
106
107
bool
108
TransactionProposalCancel::finalizeInvariants
(
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
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::debug
Stream debug() const
Definition
Journal.h:344
xrpl::ApplyView::peek
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::ReadView::read
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
xrpl::STLedgerEntry::ConstRef
std::shared_ptr< STLedgerEntry const > const & ConstRef
Definition
STLedgerEntry.h:37
xrpl::STObject
Definition
STObject.h:50
xrpl::STObject::getFieldObject
STObject getFieldObject(SField const &field) const
Definition
STObject.cpp:678
xrpl::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition
STObject.cpp:643
xrpl::STTx
Definition
STTx.h:43
xrpl::TransactionProposalCancel::visitInvariantEntry
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
Definition
TransactionProposalCancel.cpp:102
xrpl::TransactionProposalCancel::finalizeInvariants
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.
Definition
TransactionProposalCancel.cpp:108
xrpl::TransactionProposalCancel::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition
TransactionProposalCancel.cpp:22
xrpl::TransactionProposalCancel::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition
TransactionProposalCancel.cpp:34
xrpl::TransactionProposalCancel::doApply
TER doApply() override
Definition
TransactionProposalCancel.cpp:86
xrpl::Transactor::view
ApplyView & view()
Definition
Transactor.h:184
xrpl::Transactor::ctx_
ApplyContext & ctx_
Definition
Transactor.h:162
xrpl::XRPAmount
Definition
XRPAmount.h:29
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl::keylet::txProposal
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Definition
Indexes.cpp:378
xrpl::proposal::isTerminal
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).
Definition
libxrpl/ledger/helpers/ProposalHelpers.cpp:87
xrpl::proposal::deleteProposal
TER deleteProposal(ApplyView &view, SLE::pointer const &sleProposal, beast::Journal j)
Delete a TransactionProposal ledger entry.
Definition
libxrpl/ledger/helpers/ProposalHelpers.cpp:103
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::tefINTERNAL
@ tefINTERNAL
Definition
TER.h:167
xrpl::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition
TER.h:617
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::temMALFORMED
@ temMALFORMED
Definition
TER.h:75
xrpl::TER
TERSubset< CanCvtToTER > TER
Definition
TER.h:657
xrpl::tecNO_ENTRY
@ tecNO_ENTRY
Definition
TER.h:317
xrpl::tecNO_PERMISSION
@ tecNO_PERMISSION
Definition
TER.h:316
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:253
xrpl::uint256
UInt256 uint256
Definition
base_uint.h:587
xrpl::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition
Transactor.h:92
xrpl::PreclaimContext::view
ReadView const & view
Definition
Transactor.h:95
xrpl::PreclaimContext::tx
STTx const & tx
Definition
Transactor.h:98
xrpl::PreclaimContext::j
beast::Journal const j
Definition
Transactor.h:100
xrpl::PreflightContext
State information when preflighting a tx.
Definition
Transactor.h:39
xrpl::PreflightContext::j
beast::Journal const j
Definition
Transactor.h:46
xrpl::PreflightContext::tx
STTx const & tx
Definition
Transactor.h:42
Generated by
1.17.0