Skip to content

Commit

Permalink
update all AccountRoot related readSLE/peekSLE functions into the new…
Browse files Browse the repository at this point in the history
… wrapper function calls.
  • Loading branch information
ckeshava authored and scottschurr committed May 24, 2023
1 parent eb63249 commit c6d98e6
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 83 deletions.
12 changes: 6 additions & 6 deletions src/ripple/app/tx/impl/NFTokenCreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ NFTokenCreateOffer::preclaim(PreclaimContext const& ctx)
{
// If a destination is specified, the destination must already be in
// the ledger.
auto const sleDst = ctx.view.readSLE(keylet::account(*destination));
auto const dstAcct = ctx.view.read(keylet::account(*destination));

if (!sleDst)
if (!dstAcct)
return tecNO_DST;

// check if the destination has disallowed incoming offers
Expand All @@ -193,7 +193,7 @@ NFTokenCreateOffer::preclaim(PreclaimContext const& ctx)
// flag cannot be set unless amendment is enabled but
// out of an abundance of caution check anyway

if (sleDst->getFlags() & lsfDisallowIncomingNFTokenOffer)
if (dstAcct->flags() & lsfDisallowIncomingNFTokenOffer)
return tecNO_PERMISSION;
}
}
Expand All @@ -203,14 +203,14 @@ NFTokenCreateOffer::preclaim(PreclaimContext const& ctx)
// Check if the owner (buy offer) has disallowed incoming offers
if (ctx.view.rules().enabled(featureDisallowIncoming))
{
auto const sleOwner = ctx.view.readSLE(keylet::account(*owner));
auto const ownerAcct = ctx.view.read(keylet::account(*owner));

// defensively check
// it should not be possible to specify owner that doesn't exist
if (!sleOwner)
if (!ownerAcct)
return tecNO_TARGET;

if (sleOwner->getFlags() & lsfDisallowIncomingNFTokenOffer)
if (ownerAcct->flags() & lsfDisallowIncomingNFTokenOffer)
return tecNO_PERMISSION;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/ripple/app/tx/impl/SetTrust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ SetTrust::preclaim(PreclaimContext const& ctx)
// then honour that flag
if (ctx.view.rules().enabled(featureDisallowIncoming))
{
auto const sleDst = ctx.view.readSLE(keylet::account(uDstAccountID));
auto const dstAcct = ctx.view.read(keylet::account(uDstAccountID));

if (!sleDst)
if (!dstAcct)
return tecNO_DST;

auto const dstFlags = sleDst->getFlags();
if (dstFlags & lsfDisallowIncomingTrustline)
if (dstAcct->isFlag(lsfDisallowIncomingTrustline))
return tecNO_PERMISSION;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ripple/protocol/Keylet.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ struct AccountRootKeylet final : public KeyletBase

using KeyletBase::check;

AccountRootKeylet(uint256 const& key) : KeyletBase(ltACCOUNT_ROOT, key)
explicit AccountRootKeylet(uint256 const& key)
: KeyletBase(ltACCOUNT_ROOT, key)
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace keylet {
AccountRootKeylet
account(AccountID const& id) noexcept
{
return {indexHash(LedgerNameSpace::ACCOUNT, id)};
return AccountRootKeylet(indexHash(LedgerNameSpace::ACCOUNT, id));
}

Keylet
Expand Down
4 changes: 1 addition & 3 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,9 +2270,7 @@ class Offer_test : public beast::unit_test::suite
payment[jss::build_path] = true;
payment[jss::tx_json] = pay(bob, bob, bob["XXX"](1));
payment[jss::tx_json][jss::Sequence] =
env.current()
->readSLE(keylet::account(bob.id()))
->getFieldU32(sfSequence);
env.current()->read(keylet::account(bob.id()))->sequence();
payment[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base);
payment[jss::tx_json][jss::SendMax] =
bob["XTS"](1.5).value().getJson(JsonOptions::none);
Expand Down
6 changes: 3 additions & 3 deletions src/test/app/PayChan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ struct PayChan_test : public beast::unit_test::suite
jtx::Account const& account,
jtx::Account const& dst)
{
auto const sle = view.readSLE(keylet::account(account));
if (!sle)
auto const acctRoot = view.read(keylet::account(account));
if (!acctRoot)
return {};
auto const k = keylet::payChan(account, dst, (*sle)[sfSequence] - 1);
auto const k = keylet::payChan(account, dst, acctRoot->sequence() - 1);
return {k.key, view.readSLE(k)};
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/app/PayStrand_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,10 @@ struct ExistingElementPool
std::uint64_t totalXRP = 0;
auto add = [&](auto const& a) {
// XRP balance
auto const sle = v.readSLE(keylet::account(a));
if (!sle)
auto const acctRoot = v.read(keylet::account(a));
if (!acctRoot)
return;
auto const b = (*sle)[sfBalance];
auto const b = acctRoot->balance();
totalXRP += b.mantissa();
};
for (auto const& a : accounts)
Expand Down
16 changes: 8 additions & 8 deletions src/test/app/Regression_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ struct Regression_test : public beast::unit_test::suite
expectedDrops -= next->fees().base;
BEAST_EXPECT(next->info().drops == expectedDrops);
{
auto const sle =
next->readSLE(keylet::account(Account("alice").id()));
BEAST_EXPECT(sle);
auto balance = sle->getFieldAmount(sfBalance);
auto const acctRoot =
next->read(keylet::account(Account("alice").id()));
BEAST_EXPECT(acctRoot);
auto balance = acctRoot->balance();

BEAST_EXPECT(balance == aliceAmount);
}
Expand All @@ -107,10 +107,10 @@ struct Regression_test : public beast::unit_test::suite
accum.apply(*next);
}
{
auto const sle =
next->readSLE(keylet::account(Account("alice").id()));
BEAST_EXPECT(sle);
auto balance = sle->getFieldAmount(sfBalance);
auto const acctRoot =
next->read(keylet::account(Account("alice").id()));
BEAST_EXPECT(acctRoot);
auto balance = acctRoot->balance();

BEAST_EXPECT(balance == XRP(0));
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/jtx/impl/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ fill_seq(Json::Value& jv, ReadView const& view)
auto const account = parseBase58<AccountID>(jv[jss::Account].asString());
if (!account)
Throw<parse_error>("unexpected invalid Account");
auto const ar = view.readSLE(keylet::account(*account));
if (!ar)
auto const acctRoot = view.read(keylet::account(*account));
if (!acctRoot)
Throw<parse_error>("unexpected missing account root");
jv[jss::Sequence] = ar->getFieldU32(sfSequence);
jv[jss::Sequence] = acctRoot->sequence();
}

} // namespace jtx
Expand Down
102 changes: 51 additions & 51 deletions src/test/ledger/Invariants_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class Invariants_test : public beast::unit_test::suite
{{"XRP net change was positive: 500"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// put a single account in the view and "manufacture" some XRP
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto amt = sle->getFieldAmount(sfBalance);
sle->setFieldAmount(sfBalance, amt + STAmount{500});
ac.view().update(sle);
auto amt = acctRoot->balance();
acctRoot->setBalance(amt + STAmount{500});
ac.view().update(*acctRoot);
return true;
});
}
Expand All @@ -124,10 +124,10 @@ class Invariants_test : public beast::unit_test::suite
{{"an account root was deleted"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// remove an account from the view
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
ac.view().erase(sle);
ac.view().erase(*acctRoot);
return true;
});

Expand All @@ -150,12 +150,12 @@ class Invariants_test : public beast::unit_test::suite
{{"account deletion succeeded but deleted multiple accounts"}},
[](Account const& A1, Account const& A2, ApplyContext& ac) {
// remove two accounts from the view
auto const sleA1 = ac.view().peekSLE(keylet::account(A1.id()));
auto const sleA2 = ac.view().peekSLE(keylet::account(A2.id()));
if (!sleA1 || !sleA2)
auto acctRoot1 = ac.view().peek(keylet::account(A1.id()));
auto acctRoot2 = ac.view().peek(keylet::account(A2.id()));
if (!acctRoot1 || !acctRoot2)
return false;
ac.view().erase(sleA1);
ac.view().erase(sleA2);
ac.view().erase(*acctRoot1);
ac.view().erase(*acctRoot2);
return true;
},
XRPAmount{},
Expand Down Expand Up @@ -184,15 +184,15 @@ class Invariants_test : public beast::unit_test::suite
{{"invalid ledger entry type added"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// add an entry in the table with an SLE of an invalid type
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;

// make a dummy escrow ledger entry, then change the type to an
// unsupported value so that the valid type invariant check
// will fail.
auto sleNew = std::make_shared<SLE>(
keylet::escrow(A1, (*sle)[sfSequence] + 2));
keylet::escrow(A1, acctRoot->sequence() + 2));

// We don't use ltNICKNAME directly since it's marked deprecated
// to prevent accidental use elsewhere.
Expand Down Expand Up @@ -228,12 +228,12 @@ class Invariants_test : public beast::unit_test::suite
{{"Cannot return non-native STAmount as XRPAmount"}},
[](Account const& A1, Account const& A2, ApplyContext& ac) {
// non-native balance
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
STAmount nonNative(A2["USD"](51));
sle->setFieldAmount(sfBalance, nonNative);
ac.view().update(sle);
acctRoot->setBalance(nonNative);
ac.view().update(*acctRoot);
return true;
});

Expand All @@ -242,14 +242,14 @@ class Invariants_test : public beast::unit_test::suite
{"XRP net change was positive: 99999999000000001"}},
[this](Account const& A1, Account const&, ApplyContext& ac) {
// balance exceeds genesis amount
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
// Use `drops(1)` to bypass a call to STAmount::canonicalize
// with an invalid value
sle->setFieldAmount(sfBalance, INITIAL_XRP + drops(1));
BEAST_EXPECT(!sle->getFieldAmount(sfBalance).negative());
ac.view().update(sle);
acctRoot->setBalance(INITIAL_XRP + drops(1));
BEAST_EXPECT(!acctRoot->balance().negative());
ac.view().update(*acctRoot);
return true;
});

Expand All @@ -258,12 +258,12 @@ class Invariants_test : public beast::unit_test::suite
{"XRP net change of -1000000001 doesn't match fee 0"}},
[this](Account const& A1, Account const&, ApplyContext& ac) {
// balance is negative
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
sle->setFieldAmount(sfBalance, STAmount{1, true});
BEAST_EXPECT(sle->getFieldAmount(sfBalance).negative());
ac.view().update(sle);
acctRoot->setBalance(STAmount{1, true});
BEAST_EXPECT(acctRoot->balance().negative());
ac.view().update(*acctRoot);
return true;
});
}
Expand Down Expand Up @@ -308,13 +308,13 @@ class Invariants_test : public beast::unit_test::suite
{{"offer with a bad amount"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// offer with negative takerpays
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::offer(A1.id(), (*sle)[sfSequence]));
keylet::offer(A1.id(), acctRoot->sequence()));
sleNew->setAccountID(sfAccount, A1.id());
sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
sleNew->setFieldU32(sfSequence, acctRoot->sequence());
sleNew->setFieldAmount(sfTakerPays, XRP(-1));
ac.view().insert(sleNew);
return true;
Expand All @@ -324,13 +324,13 @@ class Invariants_test : public beast::unit_test::suite
{{"offer with a bad amount"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// offer with negative takergets
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::offer(A1.id(), (*sle)[sfSequence]));
keylet::offer(A1.id(), acctRoot->sequence()));
sleNew->setAccountID(sfAccount, A1.id());
sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
sleNew->setFieldU32(sfSequence, acctRoot->sequence());
sleNew->setFieldAmount(sfTakerPays, A1["USD"](10));
sleNew->setFieldAmount(sfTakerGets, XRP(-1));
ac.view().insert(sleNew);
Expand All @@ -341,13 +341,13 @@ class Invariants_test : public beast::unit_test::suite
{{"offer with a bad amount"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// offer XRP to XRP
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::offer(A1.id(), (*sle)[sfSequence]));
keylet::offer(A1.id(), acctRoot->sequence()));
sleNew->setAccountID(sfAccount, A1.id());
sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
sleNew->setFieldU32(sfSequence, acctRoot->sequence());
sleNew->setFieldAmount(sfTakerPays, XRP(10));
sleNew->setFieldAmount(sfTakerGets, XRP(11));
ac.view().insert(sleNew);
Expand All @@ -365,11 +365,11 @@ class Invariants_test : public beast::unit_test::suite
{{"Cannot return non-native STAmount as XRPAmount"}},
[](Account const& A1, Account const& A2, ApplyContext& ac) {
// escrow with nonnative amount
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::escrow(A1, (*sle)[sfSequence] + 2));
keylet::escrow(A1, acctRoot->sequence() + 2));
STAmount nonNative(A2["USD"](51));
sleNew->setFieldAmount(sfAmount, nonNative);
ac.view().insert(sleNew);
Expand All @@ -381,11 +381,11 @@ class Invariants_test : public beast::unit_test::suite
{"escrow specifies invalid amount"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// escrow with negative amount
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::escrow(A1, (*sle)[sfSequence] + 2));
keylet::escrow(A1, acctRoot->sequence() + 2));
sleNew->setFieldAmount(sfAmount, XRP(-1));
ac.view().insert(sleNew);
return true;
Expand All @@ -396,11 +396,11 @@ class Invariants_test : public beast::unit_test::suite
{"escrow specifies invalid amount"}},
[](Account const& A1, Account const&, ApplyContext& ac) {
// escrow with too-large amount
auto const sle = ac.view().peekSLE(keylet::account(A1.id()));
if (!sle)
auto acctRoot = ac.view().peek(keylet::account(A1.id()));
if (!acctRoot)
return false;
auto sleNew = std::make_shared<SLE>(
keylet::escrow(A1, (*sle)[sfSequence] + 2));
keylet::escrow(A1, acctRoot->sequence() + 2));
// Use `drops(1)` to bypass a call to STAmount::canonicalize
// with an invalid value
sleNew->setFieldAmount(sfAmount, INITIAL_XRP + drops(1));
Expand Down

0 comments on commit c6d98e6

Please sign in to comment.