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 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 if (auto const sle = ctx.view.read(keylet::oracle(ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
23 !sle)
24 {
25 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
26 return tecNO_ENTRY;
27 }
28 else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
29 {
30 // this can't happen because of the above check
31 // LCOV_EXCL_START
32 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
33 return tecINTERNAL;
34 // LCOV_EXCL_STOP
35 }
36 return tesSUCCESS;
37}
38
39TER
41{
42 if (!sle)
43 return tecINTERNAL; // LCOV_EXCL_LINE
44
45 if (!view.dirRemove(keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
46 {
47 // LCOV_EXCL_START
48 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
49 return tefBAD_LEDGER;
50 // LCOV_EXCL_STOP
51 }
52
53 auto const sleOwner = view.peek(keylet::account(account));
54 if (!sleOwner)
55 return tecINTERNAL; // LCOV_EXCL_LINE
56
57 auto const count = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
58
59 adjustOwnerCount(view, sleOwner, count, j);
60
61 view.erase(sle);
62
63 return tesSUCCESS;
64}
65
66TER
68{
69 if (auto sle = ctx_.view().peek(keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
70 return deleteOracle(ctx_.view(), sle, account_, j_);
71
72 return tecINTERNAL; // LCOV_EXCL_LINE
73}
74
75} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:41
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:115
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 NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
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:618
AccountID const account_
Definition Transactor.h:113
beast::Journal const j_
Definition Transactor.h:111
ApplyView & view()
Definition Transactor.h:129
ApplyContext & ctx_
Definition Transactor.h:109
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition Indexes.cpp:456
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:325
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ terNO_ACCOUNT
Definition TER.h:198
@ tefBAD_LEDGER
Definition TER.h:151
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:941
@ tecNO_ENTRY
Definition TER.h:288
@ tecINTERNAL
Definition TER.h:292
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:581
@ tesSUCCESS
Definition TER.h:226
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:54
ReadView const & view
Definition Transactor.h:57
beast::Journal const j
Definition Transactor.h:62
State information when preflighting a tx.
Definition Transactor.h:16