rippled
Loading...
Searching...
No Matches
DeleteOracle.cpp
1#include <xrpld/app/tx/detail/DeleteOracle.h>
2
3#include <xrpl/ledger/View.h>
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/Rules.h>
6#include <xrpl/protocol/TxFlags.h>
7
8namespace ripple {
9
15
16TER
18{
19 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
20 return terNO_ACCOUNT; // LCOV_EXCL_LINE
21
22 if (auto const sle = ctx.view.read(keylet::oracle(
23 ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
24 !sle)
25 {
26 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
27 return tecNO_ENTRY;
28 }
29 else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
30 {
31 // this can't happen because of the above check
32 // LCOV_EXCL_START
33 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
34 return tecINTERNAL;
35 // LCOV_EXCL_STOP
36 }
37 return tesSUCCESS;
38}
39
40TER
42 ApplyView& view,
43 std::shared_ptr<SLE> const& sle,
44 AccountID const& account,
46{
47 if (!sle)
48 return tecINTERNAL; // LCOV_EXCL_LINE
49
50 if (!view.dirRemove(
51 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 =
64 sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
65
66 adjustOwnerCount(view, sleOwner, count, j);
67
68 view.erase(sle);
69
70 return tesSUCCESS;
71}
72
73TER
75{
76 if (auto sle = ctx_.view().peek(
77 keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
78 return deleteOracle(ctx_.view(), sle, account_, j_);
79
80 return tecINTERNAL; // LCOV_EXCL_LINE
81}
82
83} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:41
Stream fatal() const
Definition Journal.h:333
Stream debug() const
Definition Journal.h:309
ApplyView & view()
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
static TER preclaim(PreclaimContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
AccountID const account_
Definition Transactor.h:128
ApplyView & view()
Definition Transactor.h:144
beast::Journal const j_
Definition Transactor.h:126
ApplyContext & ctx_
Definition Transactor.h:124
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition Indexes.cpp:501
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:355
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1013
@ tefBAD_LEDGER
Definition TER.h:151
@ tecNO_ENTRY
Definition TER.h:288
@ tecINTERNAL
Definition TER.h:292
@ tesSUCCESS
Definition TER.h:226
@ terNO_ACCOUNT
Definition TER.h:198
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:590
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:16