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#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/Rules.h>
24#include <xrpl/protocol/TxFlags.h>
25
26namespace ripple {
27
30{
31 if (!ctx.rules.enabled(featurePriceOracle))
32 return temDISABLED;
33
34 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
35 return ret;
36
37 if (ctx.tx.getFlags() & tfUniversalMask)
38 {
39 JLOG(ctx.j.debug()) << "Oracle Delete: invalid flags.";
40 return temINVALID_FLAG;
41 }
42
43 return preflight2(ctx);
44}
45
46TER
48{
49 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
50 return terNO_ACCOUNT; // LCOV_EXCL_LINE
51
52 if (auto const sle = ctx.view.read(keylet::oracle(
53 ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
54 !sle)
55 {
56 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
57 return tecNO_ENTRY;
58 }
59 else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
60 {
61 // this can't happen because of the above check
62 // LCOV_EXCL_START
63 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
64 return tecINTERNAL;
65 // LCOV_EXCL_STOP
66 }
67 return tesSUCCESS;
68}
69
70TER
72 ApplyView& view,
73 std::shared_ptr<SLE> const& sle,
74 AccountID const& account,
76{
77 if (!sle)
78 return tecINTERNAL; // LCOV_EXCL_LINE
79
80 if (!view.dirRemove(
81 keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
82 {
83 // LCOV_EXCL_START
84 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
85 return tefBAD_LEDGER;
86 // LCOV_EXCL_STOP
87 }
88
89 auto const sleOwner = view.peek(keylet::account(account));
90 if (!sleOwner)
91 return tecINTERNAL; // LCOV_EXCL_LINE
92
93 auto const count =
94 sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
95
96 adjustOwnerCount(view, sleOwner, count, j);
97
98 view.erase(sle);
99
100 return tesSUCCESS;
101}
102
103TER
105{
106 if (auto sle = ctx_.view().peek(
107 keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
108 return deleteOracle(ctx_.view(), sle, account_, j_);
109
110 return tecINTERNAL; // LCOV_EXCL_LINE
111}
112
113} // 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:54
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
Definition: ApplyView.cpp:189
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:91
ApplyView & view()
Definition: Transactor.h:107
beast::Journal const j_
Definition: Transactor.h:89
ApplyContext & ctx_
Definition: Transactor.h:88
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition: Indexes.cpp:503
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:175
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:365
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isTesSuccess(TER x)
Definition: TER.h:656
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:81
@ tefBAD_LEDGER
Definition: TER.h:170
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:185
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:133
@ tecNO_ENTRY
Definition: TER.h:293
@ tecINTERNAL
Definition: TER.h:297
@ tesSUCCESS
Definition: TER.h:242
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:62
@ terNO_ACCOUNT
Definition: TER.h:217
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:587
@ 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:53
ReadView const & view
Definition: Transactor.h:56
beast::Journal const j
Definition: Transactor.h:60
State information when preflighting a tx.
Definition: Transactor.h:32
beast::Journal const j
Definition: Transactor.h:38