mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-22 06:40:53 +00:00
fix: Assorted AI comments (#7569)
This commit is contained in:
@@ -463,34 +463,10 @@ getAsfFlagMap()
|
||||
#pragma pop_macro("ACCOUNTSET_FLAG_TO_MAP")
|
||||
#pragma pop_macro("ACCOUNTSET_FLAGS")
|
||||
|
||||
#pragma push_macro("SPONSOR_FLAGS")
|
||||
#pragma push_macro("SPONSOR_FLAG_TO_VALUE")
|
||||
#pragma push_macro("SPONSOR_FLAG_TO_MAP")
|
||||
// Sponsor flags (spf)
|
||||
|
||||
// Sponsor Flag values
|
||||
#define SPONSOR_FLAGS(SPF_FLAG) \
|
||||
SPF_FLAG(spfSponsorFee, 1) \
|
||||
SPF_FLAG(spfSponsorReserve, 2)
|
||||
|
||||
#define SPONSOR_FLAG_TO_VALUE(name, value) inline constexpr FlagValue name = value;
|
||||
#define SPONSOR_FLAG_TO_MAP(name, value) {#name, value},
|
||||
|
||||
SPONSOR_FLAGS(SPONSOR_FLAG_TO_VALUE)
|
||||
|
||||
inline std::map<std::string, FlagValue> const&
|
||||
getspfFlagMap()
|
||||
{
|
||||
static std::map<std::string, FlagValue> const flags = {SPONSOR_FLAGS(SPONSOR_FLAG_TO_MAP)};
|
||||
return flags;
|
||||
}
|
||||
|
||||
#undef SPONSOR_FLAG_TO_VALUE
|
||||
#undef SPONSOR_FLAG_TO_MAP
|
||||
#undef SPONSOR_FLAGS
|
||||
|
||||
#pragma pop_macro("SPONSOR_FLAG_TO_VALUE")
|
||||
#pragma pop_macro("SPONSOR_FLAG_TO_MAP")
|
||||
#pragma pop_macro("SPONSOR_FLAGS")
|
||||
inline constexpr FlagValue spfSponsorFee = 1;
|
||||
inline constexpr FlagValue spfSponsorReserve = 2;
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
|
||||
@@ -613,7 +613,7 @@ LEDGER_ENTRY(ltLOAN, 0x0089, Loan, loan, ({
|
||||
}))
|
||||
|
||||
/** A ledger object representing a sponsorship.
|
||||
\sa keylet::sponsor
|
||||
\sa keylet::sponsorship
|
||||
*/
|
||||
LEDGER_ENTRY(ltSPONSORSHIP, 0x0090, Sponsorship, sponsorship, ({
|
||||
{sfPreviousTxnID, SoeRequired},
|
||||
|
||||
@@ -22,7 +22,7 @@ class SponsorshipOwnerCountsMatch
|
||||
std::int64_t deltaSponsoredOwnerCount_ = 0;
|
||||
std::int64_t deltaSponsoringOwnerCount_ = 0;
|
||||
std::int64_t deltaSponsoredObjectOwnerCount_ = 0;
|
||||
std::uint64_t invalidOwnerCountLessThanSponsoredOwnerCount_ = 0;
|
||||
std::uint64_t ownerCountBelowSponsored_ = 0;
|
||||
|
||||
public:
|
||||
void
|
||||
|
||||
@@ -753,7 +753,7 @@ repairNFTokenDirectoryLinks(ApplyView& view, AccountID const& owner)
|
||||
{
|
||||
Throw<std::runtime_error>(
|
||||
"NFTokenPage directory for " + to_string(owner) +
|
||||
" cannot be repaired. std::unexpected link problem.");
|
||||
" cannot be repaired. Unexpected link problem.");
|
||||
}
|
||||
newPrev->at(sfNextPageMin) = nextPage->key();
|
||||
view.update(newPrev);
|
||||
|
||||
@@ -93,7 +93,7 @@ SponsorshipOwnerCountsMatch::visitEntry(
|
||||
(afterSponsoredObjectOwnerCount - beforeSponsoredObjectOwnerCount);
|
||||
|
||||
if (getOwnerCount(after) < getSponsored(after))
|
||||
invalidOwnerCountLessThanSponsoredOwnerCount_ += 1;
|
||||
ownerCountBelowSponsored_ += 1;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -111,6 +111,13 @@ SponsorshipOwnerCountsMatch::finalize(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ownerCountBelowSponsored_ > 0)
|
||||
{
|
||||
JLOG(j.fatal())
|
||||
<< "Invariant failed: OwnerCount must be greater than or equal to SponsoredOwnerCount.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deltaSponsoredObjectOwnerCount_ != deltaSponsoredOwnerCount_)
|
||||
{
|
||||
JLOG(j.fatal()) << "Invariant failed: SponsoredObjectOwnerCount does not "
|
||||
@@ -118,13 +125,6 @@ SponsorshipOwnerCountsMatch::finalize(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (invalidOwnerCountLessThanSponsoredOwnerCount_ > 0)
|
||||
{
|
||||
JLOG(j.fatal())
|
||||
<< "Invariant failed: OwnerCount must be greater than or equal to SponsoredOwnerCount.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5077,6 +5077,7 @@ public:
|
||||
testInvariantOverwrite(defaultAmendments() - fixCleanup3_1_3);
|
||||
testVaultComputeCoarsestScale();
|
||||
testAMM();
|
||||
testSponsorship();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <test/jtx/offer.h>
|
||||
#include <test/jtx/pay.h>
|
||||
#include <test/jtx/permissioned_domains.h>
|
||||
#include <test/jtx/sponsor.h>
|
||||
#include <test/jtx/ticket.h>
|
||||
#include <test/jtx/token.h>
|
||||
#include <test/jtx/txflags.h>
|
||||
@@ -93,6 +94,8 @@ std::vector<std::pair<json::StaticString, FieldType>> gMappings{
|
||||
{jss::oracle_document_id, FieldType::UInt32Field},
|
||||
{jss::owner, FieldType::AccountField},
|
||||
{jss::seq, FieldType::UInt32Field},
|
||||
{jss::sponsor, FieldType::AccountField},
|
||||
{jss::sponsee, FieldType::AccountField},
|
||||
{jss::subject, FieldType::AccountField},
|
||||
{jss::ticket_seq, FieldType::UInt32Field},
|
||||
};
|
||||
@@ -107,7 +110,7 @@ getFieldType(json::StaticString fieldName)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Throw<std::runtime_error>("`mappings` is missing field " + std::string(fieldName.cStr()));
|
||||
Throw<std::runtime_error>("`gMappings` is missing field " + std::string(fieldName.cStr()));
|
||||
}
|
||||
|
||||
std::string
|
||||
@@ -1886,6 +1889,59 @@ class LedgerEntry_test : public beast::unit_test::Suite
|
||||
runLedgerEntryTest(env, jss::signer_list);
|
||||
}
|
||||
|
||||
void
|
||||
testSponsorship()
|
||||
{
|
||||
testcase("Sponsorship");
|
||||
|
||||
using namespace test::jtx;
|
||||
|
||||
Env env{*this};
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(10000), alice, bob);
|
||||
env.close();
|
||||
env(sponsor::set(alice, 0), sponsor::SponseeAcc(bob));
|
||||
env.close();
|
||||
std::string const ledgerHash{to_string(env.closed()->header().hash)};
|
||||
auto const sponsorshipIndex = to_string(keylet::sponsorship(alice.id(), bob.id()).key);
|
||||
|
||||
{
|
||||
// Request by sponsor and sponsee.
|
||||
json::Value jvParams;
|
||||
jvParams[jss::sponsorship][jss::sponsor] = alice.human();
|
||||
jvParams[jss::sponsorship][jss::sponsee] = bob.human();
|
||||
jvParams[jss::ledger_hash] = ledgerHash;
|
||||
auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
|
||||
BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.human());
|
||||
BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.human());
|
||||
BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
|
||||
}
|
||||
{
|
||||
// Request by index.
|
||||
json::Value jvParams;
|
||||
jvParams[jss::sponsorship] = sponsorshipIndex;
|
||||
jvParams[jss::ledger_hash] = ledgerHash;
|
||||
json::Value const jrr =
|
||||
env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
|
||||
BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.human());
|
||||
BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.human());
|
||||
BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
|
||||
}
|
||||
{
|
||||
// Check all malformed cases.
|
||||
runLedgerEntryTest(
|
||||
env,
|
||||
jss::sponsorship,
|
||||
{
|
||||
{.fieldName = jss::sponsor, .malformedErrorMsg = "malformedSponsor"},
|
||||
{.fieldName = jss::sponsee, .malformedErrorMsg = "malformedSponsee"},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testTicket()
|
||||
{
|
||||
@@ -2678,6 +2734,7 @@ public:
|
||||
testPayChan();
|
||||
testRippleState();
|
||||
testSignerList();
|
||||
testSponsorship();
|
||||
testTicket();
|
||||
testDID();
|
||||
testInvalidOracleLedgerEntry();
|
||||
|
||||
@@ -719,6 +719,30 @@ parseSignerList(
|
||||
return parseObjectID(params, fieldName, "hex string");
|
||||
}
|
||||
|
||||
static std::expected<uint256, json::Value>
|
||||
parseSponsorship(
|
||||
json::Value const& params,
|
||||
json::StaticString const fieldName,
|
||||
[[maybe_unused]] unsigned const apiVersion)
|
||||
{
|
||||
if (!params.isObject())
|
||||
{
|
||||
return parseObjectID(params, fieldName);
|
||||
}
|
||||
|
||||
auto const sponsorID =
|
||||
LedgerEntryHelpers::requiredAccountID(params, jss::sponsor, "malformedSponsor");
|
||||
if (!sponsorID)
|
||||
return std::unexpected(sponsorID.error());
|
||||
|
||||
auto const sponseeID =
|
||||
LedgerEntryHelpers::requiredAccountID(params, jss::sponsee, "malformedSponsee");
|
||||
if (!sponseeID)
|
||||
return std::unexpected(sponseeID.error());
|
||||
|
||||
return keylet::sponsorship(*sponsorID, *sponseeID).key;
|
||||
}
|
||||
|
||||
static std::expected<uint256, json::Value>
|
||||
parseTicket(
|
||||
json::Value const& params,
|
||||
@@ -764,30 +788,6 @@ parseVault(
|
||||
return keylet::vault(*id, *seq).key;
|
||||
}
|
||||
|
||||
static std::expected<uint256, json::Value>
|
||||
parseSponsorship(
|
||||
json::Value const& params,
|
||||
json::StaticString const fieldName,
|
||||
[[maybe_unused]] unsigned const apiVersion)
|
||||
{
|
||||
if (!params.isObject())
|
||||
{
|
||||
return parseObjectID(params, fieldName);
|
||||
}
|
||||
|
||||
auto const sponsorAccountID =
|
||||
LedgerEntryHelpers::requiredAccountID(params, jss::sponsor, "malformedSponsor");
|
||||
if (!sponsorAccountID)
|
||||
return std::unexpected(sponsorAccountID.error());
|
||||
|
||||
auto const sponseeAccountID =
|
||||
LedgerEntryHelpers::requiredAccountID(params, jss::sponsee, "malformedSponsee");
|
||||
if (!sponseeAccountID)
|
||||
return std::unexpected(sponseeAccountID.error());
|
||||
|
||||
return keylet::sponsorship(*sponsorAccountID, *sponseeAccountID).key;
|
||||
}
|
||||
|
||||
static std::expected<uint256, json::Value>
|
||||
parseXChainOwnedClaimID(
|
||||
json::Value const& claimId,
|
||||
|
||||
Reference in New Issue
Block a user