mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
fix: Amendment to add transaction flag checking functionality for Credentials (#5250)
CredentialCreate / CredentialAccept / CredentialDelete transactions will check sfFlags field in preflight() when the amendment is enabled.
This commit is contained in:
@@ -1058,6 +1058,38 @@ struct Credentials_test : public beast::unit_test::suite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testFlags(FeatureBitset features)
|
||||||
|
{
|
||||||
|
using namespace test::jtx;
|
||||||
|
|
||||||
|
testcase("Test flags");
|
||||||
|
|
||||||
|
const char credType[] = "abcde";
|
||||||
|
Account const issuer{"issuer"};
|
||||||
|
Account const subject{"subject"};
|
||||||
|
|
||||||
|
{
|
||||||
|
using namespace jtx;
|
||||||
|
Env env{*this, features};
|
||||||
|
|
||||||
|
env.fund(XRP(5000), subject, issuer);
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
{
|
||||||
|
env(credentials::create(subject, issuer, credType),
|
||||||
|
txflags(tfTransferable),
|
||||||
|
ter(temINVALID_FLAG));
|
||||||
|
env(credentials::accept(subject, issuer, credType),
|
||||||
|
txflags(tfSellNFToken),
|
||||||
|
ter(temINVALID_FLAG));
|
||||||
|
env(credentials::deleteCred(subject, subject, issuer, credType),
|
||||||
|
txflags(tfPassive),
|
||||||
|
ter(temINVALID_FLAG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
@@ -1069,6 +1101,7 @@ struct Credentials_test : public beast::unit_test::suite
|
|||||||
testAcceptFailed(all);
|
testAcceptFailed(all);
|
||||||
testDeleteFailed(all);
|
testDeleteFailed(all);
|
||||||
testFeatureFailed(all - featureCredentials);
|
testFeatureFailed(all - featureCredentials);
|
||||||
|
testFlags(all);
|
||||||
testRPC();
|
testRPC();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ CredentialCreate::preflight(PreflightContext const& ctx)
|
|||||||
auto const& tx = ctx.tx;
|
auto const& tx = ctx.tx;
|
||||||
auto& j = ctx.j;
|
auto& j = ctx.j;
|
||||||
|
|
||||||
|
if (tx.getFlags() & tfUniversalMask)
|
||||||
|
{
|
||||||
|
JLOG(ctx.j.debug()) << "CredentialCreate: invalid flags.";
|
||||||
|
return temINVALID_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tx[sfSubject])
|
if (!tx[sfSubject])
|
||||||
{
|
{
|
||||||
JLOG(j.trace()) << "Malformed transaction: Invalid Subject";
|
JLOG(j.trace()) << "Malformed transaction: Invalid Subject";
|
||||||
@@ -209,6 +215,12 @@ CredentialDelete::preflight(PreflightContext const& ctx)
|
|||||||
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
|
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
if (ctx.tx.getFlags() & tfUniversalMask)
|
||||||
|
{
|
||||||
|
JLOG(ctx.j.debug()) << "CredentialDelete: invalid flags.";
|
||||||
|
return temINVALID_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
auto const subject = ctx.tx[~sfSubject];
|
auto const subject = ctx.tx[~sfSubject];
|
||||||
auto const issuer = ctx.tx[~sfIssuer];
|
auto const issuer = ctx.tx[~sfIssuer];
|
||||||
|
|
||||||
@@ -289,6 +301,12 @@ CredentialAccept::preflight(PreflightContext const& ctx)
|
|||||||
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
|
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
if (ctx.tx.getFlags() & tfUniversalMask)
|
||||||
|
{
|
||||||
|
JLOG(ctx.j.debug()) << "CredentialAccept: invalid flags.";
|
||||||
|
return temINVALID_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ctx.tx[sfIssuer])
|
if (!ctx.tx[sfIssuer])
|
||||||
{
|
{
|
||||||
JLOG(ctx.j.trace()) << "Malformed transaction: Issuer field zeroed.";
|
JLOG(ctx.j.trace()) << "Malformed transaction: Issuer field zeroed.";
|
||||||
|
|||||||
Reference in New Issue
Block a user