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
22#include <xrpl/ledger/View.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/Rules.h>
25#include <xrpl/protocol/TxFlags.h>
26
27namespace ripple {
28
34
35TER
37{
38 if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount))))
39 return terNO_ACCOUNT; // LCOV_EXCL_LINE
40
41 if (auto const sle = ctx.view.read(keylet::oracle(
42 ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
43 !sle)
44 {
45 JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
46 return tecNO_ENTRY;
47 }
48 else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner))
49 {
50 // this can't happen because of the above check
51 // LCOV_EXCL_START
52 JLOG(ctx.j.debug()) << "Oracle Delete: invalid account.";
53 return tecINTERNAL;
54 // LCOV_EXCL_STOP
55 }
56 return tesSUCCESS;
57}
58
59TER
61 ApplyView& view,
62 std::shared_ptr<SLE> const& sle,
63 AccountID const& account,
65{
66 if (!sle)
67 return tecINTERNAL; // LCOV_EXCL_LINE
68
69 if (!view.dirRemove(
70 keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true))
71 {
72 // LCOV_EXCL_START
73 JLOG(j.fatal()) << "Unable to delete Oracle from owner.";
74 return tefBAD_LEDGER;
75 // LCOV_EXCL_STOP
76 }
77
78 auto const sleOwner = view.peek(keylet::account(account));
79 if (!sleOwner)
80 return tecINTERNAL; // LCOV_EXCL_LINE
81
82 auto const count =
83 sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
84
85 adjustOwnerCount(view, sleOwner, count, j);
86
87 view.erase(sle);
88
89 return tesSUCCESS;
90}
91
92TER
94{
95 if (auto sle = ctx_.view().peek(
96 keylet::oracle(account_, ctx_.tx[sfOracleDocumentID])))
97 return deleteOracle(ctx_.view(), sle, account_, j_);
98
99 return tecINTERNAL; // LCOV_EXCL_LINE
100}
101
102} // 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()
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:143
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:657
AccountID const account_
Definition Transactor.h:147
ApplyView & view()
Definition Transactor.h:163
beast::Journal const j_
Definition Transactor.h:145
ApplyContext & ctx_
Definition Transactor.h:143
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
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:1032
@ tefBAD_LEDGER
Definition TER.h:170
@ tecNO_ENTRY
Definition TER.h:307
@ tecINTERNAL
Definition TER.h:311
@ tesSUCCESS
Definition TER.h:245
@ terNO_ACCOUNT
Definition TER.h:217
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:609
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
ReadView const & view
Definition Transactor.h:83
beast::Journal const j
Definition Transactor.h:88
State information when preflighting a tx.
Definition Transactor.h:35