Skip to content

Commit

Permalink
[FOLD] Update to match the latest XLS-47d
Browse files Browse the repository at this point in the history
* Change sfOracleSequence to sfOracleDocumentID
* Store LastUpdateTime internally as Ripple Epoch
* Update the unit-tests
  • Loading branch information
gregtatcam committed Nov 30, 2023
1 parent f52a520 commit 7d516c4
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ripple/app/tx/impl/DeleteOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DeleteOracle::preclaim(PreclaimContext const& ctx)
return terNO_ACCOUNT;

if (auto const sle = ctx.view.read(keylet::oracle(
ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleSequence]));
ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID]));
!sle)
{
JLOG(ctx.j.debug()) << "Oracle Delete: Oracle does not exist.";
Expand All @@ -70,7 +70,7 @@ TER
DeleteOracle::doApply()
{
if (auto sle = ctx_.view().peek(
keylet::oracle(account_, ctx_.tx[sfOracleSequence]));
keylet::oracle(account_, ctx_.tx[sfOracleDocumentID]));
!sle)
return tecINTERNAL;
else
Expand Down
12 changes: 8 additions & 4 deletions src/ripple/app/tx/impl/SetOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ SetOracle::preclaim(PreclaimContext const& ctx)
}

if (auto const sle = ctx.view.read(keylet::oracle(
ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleSequence])))
ctx.tx.getAccountID(sfAccount), ctx.tx[sfOracleDocumentID])))
{
// update

Expand Down Expand Up @@ -160,7 +160,7 @@ adjustOwnerCount(ApplyContext& ctx, std::uint16_t count)
TER
SetOracle::doApply()
{
auto const oracleID = keylet::oracle(account_, ctx_.tx[sfOracleSequence]);
auto const oracleID = keylet::oracle(account_, ctx_.tx[sfOracleDocumentID]);

if (auto sle = ctx_.view().peek(oracleID))
{
Expand Down Expand Up @@ -213,7 +213,9 @@ SetOracle::doApply()
sle->setFieldArray(sfPriceDataSeries, updatedSeries);
if (ctx_.tx.isFieldPresent(sfURI))
sle->setFieldVL(sfURI, ctx_.tx[sfURI]);
sle->setFieldU32(sfLastUpdateTime, ctx_.tx[sfLastUpdateTime]);
// LastUpdateTime is Unix time, store internally as Ripple Epoch
sle->setFieldU32(
sfLastUpdateTime, ctx_.tx[sfLastUpdateTime] - epoch_offset.count());

auto const newCount = pairs.size() > 5 ? 2 : 1;
if (newCount > oldCount && !adjustOwnerCount(ctx_, 1))
Expand All @@ -233,7 +235,9 @@ SetOracle::doApply()
auto const& series = ctx_.tx.getFieldArray(sfPriceDataSeries);
sle->setFieldArray(sfPriceDataSeries, series);
sle->setFieldVL(sfAssetClass, ctx_.tx[sfAssetClass]);
sle->setFieldU32(sfLastUpdateTime, ctx_.tx[sfLastUpdateTime]);
// LastUpdateTime is Unix time, store internally as Ripple Epoch
sle->setFieldU32(
sfLastUpdateTime, ctx_.tx[sfLastUpdateTime] - epoch_offset.count());

auto page = ctx_.view().dirInsert(
keylet::ownerDir(account_), sle->key(), describeOwnerDir(account_));
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ extern SF_UINT32 const sfHookStateCount;
extern SF_UINT32 const sfEmitGeneration;
extern SF_UINT32 const sfVoteWeight;
extern SF_UINT32 const sfFirstNFTokenSequence;
extern SF_UINT32 const sfOracleSequence;
extern SF_UINT32 const sfOracleDocumentID;

// 64-bit integers (common)
extern SF_UINT64 const sfIndexNext;
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/SField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CONSTRUCT_TYPED_SFIELD(sfEmitGeneration, "EmitGeneration", UINT32,
// 47 is reserved for LockCount(Hooks)
CONSTRUCT_TYPED_SFIELD(sfVoteWeight, "VoteWeight", UINT32, 48);
CONSTRUCT_TYPED_SFIELD(sfFirstNFTokenSequence, "FirstNFTokenSequence", UINT32, 50);
CONSTRUCT_TYPED_SFIELD(sfOracleSequence, "OracleSequence", UINT32, 51);
CONSTRUCT_TYPED_SFIELD(sfOracleDocumentID, "OracleDocumentID", UINT32, 51);

// 64-bit integers (common)
CONSTRUCT_TYPED_SFIELD(sfIndexNext, "IndexNext", UINT64, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/impl/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ TxFormats::TxFormats()
add(jss::OracleSet,
ttORACLE_SET,
{
{sfOracleSequence, soeREQUIRED},
{sfOracleDocumentID, soeREQUIRED},
{sfProvider, soeOPTIONAL},
{sfURI, soeOPTIONAL},
{sfAssetClass, soeOPTIONAL},
Expand All @@ -499,7 +499,7 @@ TxFormats::TxFormats()
add(jss::OracleDelete,
ttORACLE_DELETE,
{
{sfOracleSequence, soeREQUIRED},
{sfOracleDocumentID, soeREQUIRED},
},
commonFields);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ JSS(OfferCreate); // transaction type.
JSS(OfferSequence); // field.
JSS(Oracle); // ledger type.
JSS(OracleDelete); // transaction type.
JSS(OracleSequence); // field
JSS(OracleDocumentID); // field
JSS(OracleSet); // transaction type.
JSS(Owner); // field
JSS(Paths); // in/out: TransactionSign
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/rpc/handlers/GetAggregatePrice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ doGetAggregatePrice(RPC::JsonContext& context)
return result;
}
}
result[jss::time] = latestTime;
// convert from Ripple Epoch to Unix time
result[jss::time] =
latestTime + static_cast<std::uint32_t>(epoch_offset.count());

// calculate stats
auto const [avg, sd, size] =
Expand Down
2 changes: 1 addition & 1 deletion src/test/app/Oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct Oracle_test : public beast::unit_test::suite
.lastUpdateTime = 500,
.ter = ter(tecINVALID_UPDATE_TIME)});
oracle.set(UpdateArg{.series = {{"XRP", "USD", 740, 1}}});
BEAST_EXPECT(oracle.expectLastUpdateTime(946684950));
BEAST_EXPECT(oracle.expectLastUpdateTime(150));
// Less than the previous lastUpdateTime
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
Expand Down
4 changes: 2 additions & 2 deletions src/test/jtx/impl/Oracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Oracle::remove(RemoveArg const& arg)
Json::Value jv;
jv[jss::TransactionType] = jss::OracleDelete;
jv[jss::Account] = to_string(arg.owner.value_or(owner_));
jv[jss::OracleSequence] = arg.sequence.value_or(sequence_);
jv[jss::OracleDocumentID] = arg.sequence.value_or(sequence_);
if (Oracle::fee != 0)
jv[jss::Fee] = std::to_string(Oracle::fee);
else if (arg.fee != 0)
Expand Down Expand Up @@ -181,7 +181,7 @@ Oracle::set(UpdateArg const& arg)
sequence_ = *arg.sequence;
jv[jss::TransactionType] = jss::OracleSet;
jv[jss::Account] = to_string(owner_);
jv[jss::OracleSequence] = sequence_;
jv[jss::OracleDocumentID] = sequence_;
if (arg.assetClass)
jv[jss::AssetClass] = strHex(*arg.assetClass);
if (arg.provider)
Expand Down

0 comments on commit 7d516c4

Please sign in to comment.