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/protocol/AccountID.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/STTx.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/XRPAmount.h>
14#include <xrpl/tx/Transactor.h>
15
16namespace xrpl {
17
23
24TER
26{
27 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
28 return terNO_ACCOUNT; // LCOV_EXCL_LINE
29
30 auto const sle =
31 ctx.view.read(keylet::oracle(ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
32 if (!sle)
33 {
34 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
35 return tecNO_ENTRY;
36 }
37
38 if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
39 {
40 // this can't happen because of the above check
41 // LCOV_EXCL_START
42 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
43 return tecINTERNAL;
44 // LCOV_EXCL_STOP
45 }
46 return tesSUCCESS;
47}
48
49TER
52 SLE::ref sle,
53 AccountID const& account,
55{
56 if (!sle)
57 return tecINTERNAL; // LCOV_EXCL_LINE
58
59 if (!view.dirRemove(keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
60 {
61 // LCOV_EXCL_START
62 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
63 return tefBAD_LEDGER;
64 // LCOV_EXCL_STOP
65 }
66
67 auto const sleOwner = view.peek(keylet::account(account));
68 if (!sleOwner)
69 return tecINTERNAL; // LCOV_EXCL_LINE
70
71 auto const count = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
72
73 adjustOwnerCount(view, sleOwner, count, j);
74
75 view.erase(sle);
76
77 return tesSUCCESS;
78}
79
80TER
82{
83 if (auto sle = ctx_.view().peek(keylet::oracle(accountID_, ctx_.tx[sfOracleDocumentID])))
84 return deleteOracle(ctx_.view(), sle, accountID_, j_);
85
86 return tecINTERNAL; // LCOV_EXCL_LINE
87}
88
89void
91{
92 // No transaction-specific invariants yet (future work).
93}
94
95bool
97 STTx const&,
98 TER,
100 ReadView const&,
101 beast::Journal const&)
102{
103 // No transaction-specific invariants yet (future work).
104 return true;
105}
106
107} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream fatal() const
Definition Journal.h:321
Stream debug() const
Definition Journal.h:297
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
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:31
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:633
beast::Journal const j_
Definition Transactor.h:118
ApplyView & view()
Definition Transactor.h:136
AccountID const accountID_
Definition Transactor.h:120
ApplyContext & ctx_
Definition Transactor.h:116
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition Indexes.cpp:515
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:357
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:209
@ tefBAD_LEDGER
Definition TER.h:160
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecNO_ENTRY
Definition TER.h:304
@ tecINTERNAL
Definition TER.h:308
@ tesSUCCESS
Definition TER.h:240
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
beast::Journal const j
Definition Transactor.h:69
State information when preflighting a tx.
Definition Transactor.h:18