rippled
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 <ripple/app/tx/impl/DeleteOracle.h>
21 #include <ripple/ledger/Sandbox.h>
22 #include <ripple/ledger/View.h>
23 #include <ripple/protocol/Feature.h>
24 #include <ripple/protocol/Rules.h>
25 #include <ripple/protocol/TxFlags.h>
26 
27 namespace ripple {
28 
29 NotTEC
31 {
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 
47 TER
49 {
51  return terNO_ACCOUNT;
52 
53  if (auto const sle = ctx.view.read(keylet::oracle(
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  JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
64  return tecINTERNAL;
65  }
66  return tesSUCCESS;
67 }
68 
69 TER
71  ApplyView& view,
72  std::shared_ptr<SLE> const& sle,
73  AccountID const& account,
75 {
76  if (!sle)
77  return tesSUCCESS;
78 
79  if (!view.dirRemove(
80  keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
81  {
82  JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
83  return tefBAD_LEDGER;
84  }
85 
86  auto const sleOwner = view.peek(keylet::account(account));
87  if (!sleOwner)
88  return tecINTERNAL;
89 
90  auto const count =
91  sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
92 
93  adjustOwnerCount(view, sleOwner, count, j);
94 
95  view.erase(sle);
96 
97  return tesSUCCESS;
98 }
99 
100 TER
102 {
103  if (auto sle = ctx_.view().peek(
105  return deleteOracle(ctx_.view(), sle, account_, j_);
106 
107  return tecINTERNAL;
108 }
109 
110 } // namespace ripple
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:338
ripple::keylet::ownerDir
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:313
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:133
ripple::Rules::enabled
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:94
std::shared_ptr
STL class.
ripple::PreclaimContext::view
ReadView const & view
Definition: Transactor.h:56
ripple::sfOwnerNode
const SF_UINT64 sfOwnerNode
ripple::PreclaimContext::j
const beast::Journal j
Definition: Transactor.h:60
ripple::ApplyView::peek
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
ripple::Transactor::j_
const beast::Journal j_
Definition: Transactor.h:89
ripple::isTesSuccess
bool isTesSuccess(TER x)
Definition: TER.h:643
ripple::DeleteOracle::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: DeleteOracle.cpp:30
ripple::sfOwner
const SF_ACCOUNT sfOwner
ripple::keylet::oracle
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Definition: Indexes.cpp:449
ripple::ApplyView::erase
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
ripple::DeleteOracle::deleteOracle
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
Definition: DeleteOracle.cpp:70
ripple::adjustOwnerCount
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:188
ripple::DeleteOracle::doApply
TER doApply() override
Definition: DeleteOracle.cpp:101
ripple::PreflightContext::j
const beast::Journal j
Definition: Transactor.h:38
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:81
ripple::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:134
ripple::DeleteOracle::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: DeleteOracle.cpp:48
ripple::ApplyView::dirRemove
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
Definition: ApplyView.cpp:189
ripple::base_uint< 160, detail::AccountIDTag >
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition: TER.h:110
ripple::tefBAD_LEDGER
@ tefBAD_LEDGER
Definition: TER.h:167
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:143
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:605
ripple::TERSubset< CanCvtToTER >
ripple::ReadView::exists
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
ripple::sfOracleDocumentID
const SF_UINT32 sfOracleDocumentID
ripple::tecINTERNAL
@ tecINTERNAL
Definition: TER.h:293
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:497
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::ApplyContext::view
ApplyView & view()
Definition: ApplyContext.h:54
ripple::PreclaimContext::tx
STTx const & tx
Definition: Transactor.h:58
ripple::terNO_ACCOUNT
@ terNO_ACCOUNT
Definition: TER.h:213
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:52
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:107
ripple::temDISABLED
@ temDISABLED
Definition: TER.h:113
ripple::featurePriceOracle
const uint256 featurePriceOracle
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition: Transactor.h:88
beast::Journal::debug
Stream debug() const
Definition: Journal.h:314
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::tecNO_ENTRY
@ tecNO_ENTRY
Definition: TER.h:289
ripple::PreflightContext::tx
STTx const & tx
Definition: Transactor.h:35
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:31
ripple::PreflightContext::rules
const Rules rules
Definition: Transactor.h:36
ripple::tfUniversalMask
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:60
ripple::sfPriceDataSeries
const SField sfPriceDataSeries
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:238
ripple::Transactor::account_
const AccountID account_
Definition: Transactor.h:91
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:48
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:574