mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-22 14:50:54 +00:00
refactor: Use STLedgerEntry type aliases instead of std::shared_ptr (#7282)
This commit is contained in:
@@ -49,7 +49,6 @@
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -755,11 +754,11 @@ public:
|
||||
}
|
||||
|
||||
// Helper function that returns the Offers on an account.
|
||||
static std::vector<std::shared_ptr<SLE const>>
|
||||
static std::vector<SLE::const_pointer>
|
||||
offersOnAccount(jtx::Env& env, jtx::Account const& account)
|
||||
{
|
||||
std::vector<std::shared_ptr<SLE const>> result;
|
||||
forEachItem(*env.current(), account, [&result](std::shared_ptr<SLE const> const& sle) {
|
||||
std::vector<SLE::const_pointer> result;
|
||||
forEachItem(*env.current(), account, [&result](SLE::const_ref sle) {
|
||||
if (sle->getType() == ltOFFER)
|
||||
result.push_back(sle);
|
||||
});
|
||||
@@ -3928,10 +3927,10 @@ public:
|
||||
// clang-format off
|
||||
TestData const tests[]{
|
||||
// btcStart --------------------- actor[0] --------------------- -------------------- actor[1] -------------------
|
||||
{.self=0, .leg0=0, .leg1=1, .btcStart=btc(20), .actors={{"ann", 0, drops(3900000'000000 - (4 * baseFee)), btc(20.0), usd(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), btc( 0), usd(750)}}}, // no BTC xfer fee
|
||||
{.self=0, .leg0=1, .leg1=0, .btcStart=btc(20), .actors={{"bev", 0, drops(4100000'000000 - (4 * baseFee)), btc( 7.5), usd(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), btc(10), usd( 0)}}}, // no USD xfer fee
|
||||
{.self=0, .leg0=0, .leg1=0, .btcStart=btc(20), .actors={{"cam", 0, drops(4000000'000000 - (5 * baseFee)), btc(20.0), usd(2000)} }}, // no xfer fee
|
||||
{.self=0, .leg0=1, .leg1=0, .btcStart=btc( 5), .actors={{"deb", 1, drops(4040000'000000 - (4 * baseFee)), btc( 0.0), usd(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), btc( 4), usd( 0)}}}, // no USD xfer fee
|
||||
{.self=0, .leg0=0, .leg1=1, .btcStart=btc(20), .actors={{.acct="ann", .offers=0, .xrp=drops(3900000'000000 - (4 * baseFee)), .btc=btc(20.0), .usd=usd(3000)}, {.acct="abe", .offers=0, .xrp=drops(4100000'000000 - (3 * baseFee)), .btc=btc( 0), .usd=usd(750)}}}, // no BTC xfer fee
|
||||
{.self=0, .leg0=1, .leg1=0, .btcStart=btc(20), .actors={{.acct="bev", .offers=0, .xrp=drops(4100000'000000 - (4 * baseFee)), .btc=btc( 7.5), .usd=usd(2000)}, {.acct="bob", .offers=0, .xrp=drops(3900000'000000 - (3 * baseFee)), .btc=btc(10), .usd=usd( 0)}}}, // no USD xfer fee
|
||||
{.self=0, .leg0=0, .leg1=0, .btcStart=btc(20), .actors={{.acct="cam", .offers=0, .xrp=drops(4000000'000000 - (5 * baseFee)), .btc=btc(20.0), .usd=usd(2000)} }}, // no xfer fee
|
||||
{.self=0, .leg0=1, .leg1=0, .btcStart=btc( 5), .actors={{.acct="deb", .offers=1, .xrp=drops(4040000'000000 - (4 * baseFee)), .btc=btc( 0.0), .usd=usd(2000)}, {.acct="dan", .offers=1, .xrp=drops(3960000'000000 - (3 * baseFee)), .btc=btc( 4), .usd=usd( 0)}}}, // no USD xfer fee
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@@ -3980,7 +3979,7 @@ public:
|
||||
auto actorOffers = offersOnAccount(env, actor.acct);
|
||||
auto const offerCount = std::distance(
|
||||
actorOffers.begin(),
|
||||
std::ranges::remove_if(actorOffers, [](std::shared_ptr<SLE const>& offer) {
|
||||
std::ranges::remove_if(actorOffers, [](SLE::const_pointer& offer) {
|
||||
return (*offer)[sfTakerGets].signum() == 0;
|
||||
}).begin());
|
||||
BEAST_EXPECT(offerCount == actor.offers);
|
||||
@@ -4076,8 +4075,8 @@ public:
|
||||
// clang-format off
|
||||
TestData const tests[]{
|
||||
// btcStart ------------------- actor[0] -------------------- ------------------- actor[1] --------------------
|
||||
{.self=0, .leg0=0, .leg1=1, .btcStart=btc(5), .actors={{"gay", 1, drops(3950000'000000 - (4 * baseFee)), btc(5), usd(2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), btc(0), usd(1375)}}}, // no BTC xfer fee
|
||||
{.self=0, .leg0=0, .leg1=0, .btcStart=btc(5), .actors={{"hye", 2, drops(4000000'000000 - (5 * baseFee)), btc(5), usd(2000)} }} // no xfer fee
|
||||
{.self=0, .leg0=0, .leg1=1, .btcStart=btc(5), .actors={{.acct="gay", .offers=1, .xrp=drops(3950000'000000 - (4 * baseFee)), .btc=btc(5), .usd=usd(2500)}, {.acct="gar", .offers=1, .xrp=drops(4050000'000000 - (3 * baseFee)), .btc=btc(0), .usd=usd(1375)}}}, // no BTC xfer fee
|
||||
{.self=0, .leg0=0, .leg1=0, .btcStart=btc(5), .actors={{.acct="hye", .offers=2, .xrp=drops(4000000'000000 - (5 * baseFee)), .btc=btc(5), .usd=usd(2000)} }} // no xfer fee
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@@ -4126,7 +4125,7 @@ public:
|
||||
auto actorOffers = offersOnAccount(env, actor.acct);
|
||||
auto const offerCount = std::distance(
|
||||
actorOffers.begin(),
|
||||
std::ranges::remove_if(actorOffers, [](std::shared_ptr<SLE const>& offer) {
|
||||
std::ranges::remove_if(actorOffers, [](SLE::const_pointer& offer) {
|
||||
return (*offer)[sfTakerGets].signum() == 0;
|
||||
}).begin());
|
||||
BEAST_EXPECT(offerCount == actor.offers);
|
||||
@@ -4641,7 +4640,7 @@ public:
|
||||
env(offer(alice, xts(30), xxx(10)), Json(jss::Flags, tfSell));
|
||||
|
||||
std::map<std::uint32_t, std::pair<STAmount, STAmount>> offers;
|
||||
forEachItem(*env.current(), alice, [&](std::shared_ptr<SLE const> const& sle) {
|
||||
forEachItem(*env.current(), alice, [&](SLE::const_ref sle) {
|
||||
if (sle->getType() == ltOFFER)
|
||||
{
|
||||
offers.emplace(
|
||||
@@ -4676,15 +4675,13 @@ public:
|
||||
}
|
||||
|
||||
// Helper function that returns offers on an account sorted by sequence.
|
||||
static std::vector<std::shared_ptr<SLE const>>
|
||||
static std::vector<SLE::const_pointer>
|
||||
sortedOffersOnAccount(jtx::Env& env, jtx::Account const& acct)
|
||||
{
|
||||
std::vector<std::shared_ptr<SLE const>> offers{offersOnAccount(env, acct)};
|
||||
std::ranges::sort(
|
||||
offers,
|
||||
[](std::shared_ptr<SLE const> const& rhs, std::shared_ptr<SLE const> const& lhs) {
|
||||
return (*rhs)[sfSequence] < (*lhs)[sfSequence];
|
||||
});
|
||||
std::vector<SLE::const_pointer> offers{offersOnAccount(env, acct)};
|
||||
std::ranges::sort(offers, [](SLE::const_ref rhs, SLE::const_ref lhs) {
|
||||
return (*rhs)[sfSequence] < (*lhs)[sfSequence];
|
||||
});
|
||||
return offers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user