-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PriceOracle
: Price Oracle (XLS-47d)
#4789
Merged
+2,865
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of rippled: https://github.com/ripple/rippled | ||
Copyright (c) 2023 Ripple Labs Inc. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#include <ripple/app/tx/impl/DeleteOracle.h> | ||
#include <ripple/ledger/Sandbox.h> | ||
#include <ripple/ledger/View.h> | ||
#include <ripple/protocol/Feature.h> | ||
#include <ripple/protocol/Rules.h> | ||
#include <ripple/protocol/TxFlags.h> | ||
|
||
namespace ripple { | ||
|
||
NotTEC | ||
DeleteOracle::preflight(PreflightContext const& ctx) | ||
{ | ||
if (!ctx.rules.enabled(featurePriceOracle)) | ||
return temDISABLED; | ||
|
||
if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) | ||
return ret; | ||
|
||
if (ctx.tx.getFlags() & tfUniversalMask) | ||
{ | ||
JLOG(ctx.j.debug()) << "Oracle Delete: invalid flags."; | ||
return temINVALID_FLAG; | ||
} | ||
|
||
return preflight2(ctx); | ||
} | ||
|
||
TER | ||
DeleteOracle::preclaim(PreclaimContext const& ctx) | ||
{ | ||
if (!ctx.view.exists(keylet::account(ctx.tx.getAccountID(sfAccount)))) | ||
return terNO_ACCOUNT; | ||
|
||
if (auto const sle = ctx.view.read(keylet::oracle( | ||
ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID])); | ||
!sle) | ||
{ | ||
JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist."; | ||
return tecNO_ENTRY; | ||
} | ||
else if (ctx.tx.getAccountID(sfAccount) != sle->getAccountID(sfOwner)) | ||
{ | ||
// this can't happen because of the above check | ||
JLOG(ctx.j.debug()) << "Oracle Delete: invalid account."; | ||
return tecINTERNAL; | ||
} | ||
return tesSUCCESS; | ||
} | ||
|
||
TER | ||
DeleteOracle::deleteOracle( | ||
ApplyView& view, | ||
std::shared_ptr<SLE> const& sle, | ||
AccountID const& account, | ||
beast::Journal j) | ||
{ | ||
if (!sle) | ||
return tesSUCCESS; | ||
|
||
if (!view.dirRemove( | ||
keylet::ownerDir(account), (*sle)[sfOwnerNode], sle->key(), true)) | ||
{ | ||
JLOG(j.fatal()) << "Unable to delete Oracle from owner."; | ||
return tefBAD_LEDGER; | ||
} | ||
|
||
auto const sleOwner = view.peek(keylet::account(account)); | ||
if (!sleOwner) | ||
return tecINTERNAL; | ||
|
||
auto const count = | ||
sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1; | ||
|
||
adjustOwnerCount(view, sleOwner, count, j); | ||
|
||
view.erase(sle); | ||
|
||
return tesSUCCESS; | ||
} | ||
|
||
TER | ||
DeleteOracle::doApply() | ||
{ | ||
if (auto sle = ctx_.view().peek( | ||
keylet::oracle(account_, ctx_.tx[sfOracleDocumentID]))) | ||
return deleteOracle(ctx_.view(), sle, account_, j_); | ||
|
||
return tecINTERNAL; | ||
} | ||
|
||
} // namespace ripple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of rippled: https://github.com/ripple/rippled | ||
Copyright (c) 2023 Ripple Labs Inc. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#ifndef RIPPLE_TX_DELETEORACLE_H_INCLUDED | ||
#define RIPPLE_TX_DELETEORACLE_H_INCLUDED | ||
|
||
#include <ripple/app/tx/impl/Transactor.h> | ||
|
||
namespace ripple { | ||
|
||
/** | ||
Price Oracle is a system that acts as a bridge between | ||
a blockchain network and the external world, providing off-chain price data | ||
to decentralized applications (dApps) on the blockchain. This implementation | ||
conforms to the requirements specified in the XLS-47d. | ||
The DeleteOracle transactor implements the deletion of Oracle objects. | ||
*/ | ||
|
||
class DeleteOracle : public Transactor | ||
{ | ||
public: | ||
static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; | ||
|
||
explicit DeleteOracle(ApplyContext& ctx) : Transactor(ctx) | ||
{ | ||
} | ||
|
||
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); | ||
}; | ||
|
||
} // namespace ripple | ||
|
||
#endif // RIPPLE_TX_DELETEORACLE_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
tecNO_ENTRY
? Or is that unneeded because it would have been caught inpreclaim
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preclaim
should catch it. This is just in case check. It should not happen, this is why it'stecINTERNAL
.