rippled
Loading...
Searching...
No Matches
OracleDelete.cpp
1#include <xrpl/ledger/View.h>
2#include <xrpl/ledger/helpers/AccountRootHelpers.h>
3#include <xrpl/protocol/Feature.h>
4#include <xrpl/protocol/Rules.h>
5#include <xrpl/protocol/TxFlags.h>
6#include <xrpl/tx/transactors/oracle/OracleDelete.h>
7
8namespace xrpl {
9
15
16TER
18{
19 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
20 return terNO_ACCOUNT; // LCOV_EXCL_LINE
21
22 auto const sle =
23 ctx.view.read(keylet::oracle(ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
24 if (!sle)
25 {
26 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
27 return tecNO_ENTRY;
28 }
29
30 if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
31 {
32 // this can't happen because of the above check
33 // LCOV_EXCL_START
34 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
35 return tecINTERNAL;
36 // LCOV_EXCL_STOP
37 }
38 return tesSUCCESS;
39}
40
41TER
43 ApplyView& view,
44 std::shared_ptr<SLE> const& sle,
45 AccountID const& account,
47{
48 if (!sle)
49 return tecINTERNAL; // LCOV_EXCL_LINE
50
51 if (!view.dirRemove(keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
52 {
53 // LCOV_EXCL_START
54 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
55 return tefBAD_LEDGER;
56 // LCOV_EXCL_STOP
57 }
58
59 auto const sleOwner = view.peek(keylet::account(account));
60 if (!sleOwner)
61 return tecINTERNAL; // LCOV_EXCL_LINE
62
63 auto const count = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
64
65 adjustOwnerCount(view, sleOwner, count, j);
66
67 view.erase(sle);
68
69 return tesSUCCESS;
70}
71
72TER
74{
75 if (auto sle = ctx_.view().peek(keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
76 return deleteOracle(ctx_.view(), sle, account_, j_);
77
78 return tecINTERNAL; // LCOV_EXCL_LINE
79}
80
81} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream fatal() const
Definition Journal.h:325
Stream debug() const
Definition Journal.h:301
STTx const & tx
ApplyView & view()
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
TER doApply() override
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:635
AccountID const account_
Definition Transactor.h:116
beast::Journal const j_
Definition Transactor.h:114
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition Indexes.cpp:468
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:336
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:197
@ tefBAD_LEDGER
Definition TER.h:150
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
@ tecNO_ENTRY
Definition TER.h:287
@ tecINTERNAL
Definition TER.h:291
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:582
@ tesSUCCESS
Definition TER.h:225
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:57
ReadView const & view
Definition Transactor.h:60
beast::Journal const j
Definition Transactor.h:65
State information when preflighting a tx.
Definition Transactor.h:14