rippled
Loading...
Searching...
No Matches
DeleteOracle.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/DeleteOracle.h>
21#include <xrpld/ledger/View.h>
22
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/Rules.h>
25#include <xrpl/protocol/TxFlags.h>
26
27namespace ripple {
28
31{
32 if (!ctx.rules.enabled(featurePriceOracle))
33 return temDISABLED;
34
35 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
36 return ret;
37
38 if (ctx.tx.getFlags() & tfUniversalMask)
39 {
40 JLOG(ctx.j.debug()) << "Oracle Delete: invalid flags.";
41 return temINVALID_FLAG;
42 }
43
44 return preflight2(ctx);
45}
46
47TER
49{
50 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
51 return terNO_ACCOUNT; // LCOV_EXCL_LINE
52
53 if (auto const sle = ctx.view.read(keylet::oracle(
54 ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
55 !sle)
56 {
57 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
58 return tecNO_ENTRY;
59 }
60 else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
61 {
62 // this can't happen because of the above check
63 // LCOV_EXCL_START
64 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
65 return tecINTERNAL;
66 // LCOV_EXCL_STOP
67 }
68 return tesSUCCESS;
69}
70
71TER
73 ApplyView& view,
74 std::shared_ptr<SLE> const& sle,
75 AccountID const& account,
77{
78 if (!sle)
79 return tecINTERNAL; // LCOV_EXCL_LINE
80
81 if (!view.dirRemove(
82 keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
83 {
84 // LCOV_EXCL_START
85 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
86 return tefBAD_LEDGER;
87 // LCOV_EXCL_STOP
88 }
89
90 auto const sleOwner = view.peek(keylet::account(account));
91 if (!sleOwner)
92 return tecINTERNAL; // LCOV_EXCL_LINE
93
94 auto const count =
95 sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
96
97 adjustOwnerCount(view, sleOwner, count, j);
98
99 view.erase(sle);
100
101 return tesSUCCESS;
102}
103
104TER
106{
107 if (auto sle = ctx_.view().peek(
108 keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
109 return deleteOracle(ctx_.view(), sle, account_, j_);
110
111 return tecINTERNAL; // LCOV_EXCL_LINE
112}
113
114} // namespace ripple
A generic endpoint for log messages.
Definition: Journal.h:60
Stream fatal() const
Definition: Journal.h:352
Stream debug() const
Definition: Journal.h:328
ApplyView & view()
Definition: ApplyContext.h:78
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:144
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
Definition: ApplyView.cpp:190
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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:651
std::uint32_t getFlags() const
Definition: STObject.cpp:537
AccountID const account_
Definition: Transactor.h:143
ApplyView & view()
Definition: Transactor.h:159
beast::Journal const j_
Definition: Transactor.h:141
ApplyContext & ctx_
Definition: Transactor.h:140
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition: Indexes.cpp:520
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:184
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:374
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:91
@ tefBAD_LEDGER
Definition: TER.h:170
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:186
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:160
@ tecNO_ENTRY
Definition: TER.h:306
@ tecINTERNAL
Definition: TER.h:310
@ tesSUCCESS
Definition: TER.h:244
bool isTesSuccess(TER x) noexcept
Definition: TER.h:674
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:63
@ terNO_ACCOUNT
Definition: TER.h:217
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:605
@ temINVALID_FLAG
Definition: TER.h:111
@ temDISABLED
Definition: TER.h:114
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:79
ReadView const & view
Definition: Transactor.h:82
beast::Journal const j
Definition: Transactor.h:87
State information when preflighting a tx.
Definition: Transactor.h:34
beast::Journal const j
Definition: Transactor.h:41