xrpld
Loading...
Searching...
No Matches
OracleDelete.cpp
1#include <xrpl/tx/transactors/oracle/OracleDelete.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/OracleHelpers.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/XRPAmount.h>
15#include <xrpl/tx/Transactor.h>
16
17#include <cstdint>
18
19namespace xrpl {
20
26
27TER
29{
30 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
31 return terNO_ACCOUNT; // LCOV_EXCL_LINE
32
33 auto const sle =
34 ctx.view.read(keylet::oracle(ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
35 if (!sle)
36 {
37 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
38 return tecNO_ENTRY;
39 }
40
41 if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
42 {
43 // this can't happen because of the above check
44 // LCOV_EXCL_START
45 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
46 return tecINTERNAL;
47 // LCOV_EXCL_STOP
48 }
49 return tesSUCCESS;
50}
51
52TER
55 SLE::ref sle,
56 AccountID const& account,
58{
59 if (!sle)
60 return tecINTERNAL; // LCOV_EXCL_LINE
61
62 if (!view.dirRemove(keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
63 {
64 // LCOV_EXCL_START
65 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
66 return tefBAD_LEDGER;
67 // LCOV_EXCL_STOP
68 }
69
70 auto const sleOwner = view.peek(keylet::account(account));
71 if (!sleOwner)
72 return tecINTERNAL; // LCOV_EXCL_LINE
73
74 std::uint32_t const count = calculateOracleReserve(sle);
75 decreaseOwnerCountForObject(view, sleOwner, sle, count, j);
76 view.erase(sle);
77
78 return tesSUCCESS;
79}
80
81TER
83{
84 if (auto sle = ctx_.view().peek(keylet::oracle(accountID_, ctx_.tx[sfOracleDocumentID])))
85 return deleteOracle(ctx_.view(), sle, accountID_, j_);
86
87 return tecINTERNAL; // LCOV_EXCL_LINE
88}
89
90void
92{
93 // No transaction-specific invariants yet (future work).
94}
95
96bool
98 STTx const&,
99 TER,
100 XRPAmount,
101 ReadView const&,
102 beast::Journal const&)
103{
104 // No transaction-specific invariants yet (future work).
105 return true;
106}
107
108} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream fatal() const
Definition Journal.h:368
Stream debug() const
Definition Journal.h:344
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:134
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
TER doApply() override
static TER deleteOracle(ApplyView &view, SLE::ref sle, AccountID const &account, beast::Journal j)
static NotTEC preflight(PreflightContext const &ctx)
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 TER preclaim(PreclaimContext const &ctx)
A view into a ledger.
Definition ReadView.h:41
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.
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:643
beast::Journal const j_
Definition Transactor.h:155
ApplyView & view()
Definition Transactor.h:175
AccountID const accountID_
Definition Transactor.h:157
ApplyContext & ctx_
Definition Transactor.h:153
Keylet oracle(AccountID const &account, std::uint32_t const documentID) noexcept
Definition Indexes.cpp:531
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:373
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:213
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.
@ tefBAD_LEDGER
Definition TER.h:162
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
std::uint32_t calculateOracleReserve(T const &priceDataSeries)
TERSubset< CanCvtToTER > TER
Definition TER.h:647
@ tecNO_ENTRY
Definition TER.h:309
@ tecINTERNAL
Definition TER.h:313
@ tesSUCCESS
Definition TER.h:245
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
ReadView const & view
Definition Transactor.h:86
beast::Journal const j
Definition Transactor.h:91
State information when preflighting a tx.
Definition Transactor.h:38