add claim reward flag (#139)

This commit is contained in:
Denis Angell
2023-10-18 10:09:47 +02:00
committed by GitHub
parent d734fe600b
commit 251a79e897
3 changed files with 8 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ ClaimReward::preflight(PreflightContext const& ctx)
return ret;
// can have flag 1 set to opt-out of rewards
if (ctx.tx.isFieldPresent(sfFlags) && ctx.tx.getFieldU32(sfFlags) > 1)
if (ctx.tx.isFieldPresent(sfFlags) && ctx.tx.getFieldU32(sfFlags) > tfOptOut)
return temINVALID_FLAG;
if (ctx.tx.isFieldPresent(sfIssuer) && ctx.tx.getAccountID(sfIssuer) == ctx.tx.getAccountID(sfAccount))
@@ -73,7 +73,7 @@ ClaimReward::preclaim(PreclaimContext const& ctx)
std::optional<uint32_t> flags = ctx.tx[~sfFlags];
std::optional<AccountID const> issuer = ctx.tx[~sfIssuer];
bool isOptOut = flags && *flags == 1;
bool isOptOut = flags && *flags == tfOptOut;
if ((issuer && isOptOut) || (!issuer && !isOptOut))
return temMALFORMED;
@@ -92,7 +92,7 @@ ClaimReward::doApply()
std::optional<uint32_t> flags = ctx_.tx[~sfFlags];
bool isOptOut = flags && *flags == 1;
bool isOptOut = flags && *flags == tfOptOut;
if (isOptOut)
{
if (sle->isFieldPresent(sfRewardLgrFirst))

View File

@@ -164,6 +164,9 @@ constexpr std::uint32_t const tfNFTokenAcceptOfferMask = ~tfUniversal;
constexpr std::uint32_t const tfURITokenMintMask = ~(tfUniversal | tfBurnable);
constexpr std::uint32_t const tfURITokenNonMintMask = ~tfUniversal;
// ClaimReward flags:
constexpr std::uint32_t const tfOptOut = 0x00000001;
// clang-format on
} // namespace ripple

View File

@@ -275,7 +275,7 @@ struct ClaimReward_test : public beast::unit_test::suite
env.fund(XRP(1000), alice, issuer);
env.close();
env(claim(alice, issuer, 1), ter(temMALFORMED));
env(claim(alice, issuer, tfOptOut), ter(temMALFORMED));
env.close();
}
// (!issuer && !isOptOut)
@@ -345,7 +345,7 @@ struct ClaimReward_test : public beast::unit_test::suite
true);
// test claim rewards - opt out
env(claim(alice, std::nullopt, 1), ter(tesSUCCESS));
env(claim(alice, std::nullopt, tfOptOut), ter(tesSUCCESS));
env.close();
BEAST_EXPECT(expectNoRewards(env, alice) == true);