forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Price Oracle (XLS-47d): (XRPLF#4789) (XRPLF#4789)
Implement native support for Price Oracles. A Price Oracle is used to bring real-world data, such as market prices, onto the blockchain, enabling dApps to access and utilize information that resides outside the blockchain. Add Price Oracle functionality: - OracleSet: create or update the Oracle object - OracleDelete: delete the Oracle object To support this functionality add: - New RPC method, `get_aggregate_price`, to calculate aggregate price for a token pair of the specified oracles - `ltOracle` object The `ltOracle` object maintains: - Oracle Owner's account - Oracle's metadata - Up to ten token pairs with the scaled price - The last update time the token pairs were updated Add Oracle unit-tests
- Loading branch information
1 parent
b1a4277
commit 0ffba60
Showing
40 changed files
with
2,865 additions
and
7 deletions.
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.