Skip to content

Commit f8b555d

Browse files
committed
adds sfData field to VaultDelete transaction
1 parent 6674500 commit f8b555d

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

include/xrpl/protocol/detail/transactions.macro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ TRANSACTION(ttVAULT_DELETE, 67, VaultDelete,
868868
mustDeleteAcct | destroyMPTIssuance | mustModifyVault,
869869
({
870870
{sfVaultID, soeREQUIRED},
871+
{sfData, soeOPTIONAL},
871872
}))
872873

873874
/** This transaction trades assets for shares with a vault. */

src/test/app/Vault_test.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4990,6 +4990,56 @@ class Vault_test : public beast::unit_test::suite
49904990
}
49914991
}
49924992

4993+
void
4994+
testVaultDeleteData()
4995+
{
4996+
using namespace test::jtx;
4997+
4998+
auto const test =
4999+
[&](std::string const& prefix, FeatureBitset features, std::string const& pl, TER expectedCode) {
5000+
Env env{*this, features};
5001+
testcase("VaultDelete data " + prefix);
5002+
Account const owner{"owner"};
5003+
5004+
Vault vault{env};
5005+
env.fund(XRP(1'000'000), owner);
5006+
env.close();
5007+
5008+
PrettyAsset const xrpAsset = xrpIssue();
5009+
5010+
auto const [tx, keylet] = vault.create({.owner = owner, .asset = xrpAsset});
5011+
env(tx, ter(tesSUCCESS), THISLINE);
5012+
5013+
auto delTx = vault.del({.owner = owner, .id = keylet.key});
5014+
env(delTx, data(pl), ter(expectedCode), THISLINE);
5015+
5016+
env.close();
5017+
};
5018+
5019+
auto const all = testable_amendments();
5020+
{
5021+
// Test VaultDelete with fixLendingProtocolV1_1 disabled
5022+
// Transaction succeeds even if the data field is provided
5023+
test(
5024+
"fixLendingProtocolV1_1 disabled",
5025+
all - fixLendingProtocolV1_1,
5026+
std::string(maxDataPayloadLength, 'A'),
5027+
tesSUCCESS);
5028+
}
5029+
5030+
{
5031+
// Transaction fails if the data field is too large
5032+
test(
5033+
"fixLendingProtocolV1_1 enabled data too large",
5034+
all,
5035+
std::string(maxDataPayloadLength + 1, 'A'),
5036+
temMALFORMED);
5037+
// Transaction fails if the data field is set, but is empty
5038+
test("fixLendingProtocolV1_1 enabled data empty", all, std::string(0, 'A'), temMALFORMED);
5039+
test("fixLendingProtocolV1_1 enabled data valid", all, std::string(maxDataPayloadLength, 'A'), tesSUCCESS);
5040+
}
5041+
}
5042+
49935043
public:
49945044
void
49955045
run() override
@@ -5011,6 +5061,7 @@ class Vault_test : public beast::unit_test::suite
50115061
testVaultClawbackBurnShares();
50125062
testVaultClawbackAssets();
50135063
testAssetsMaximum();
5064+
testVaultDeleteData();
50145065
}
50155066
};
50165067

src/xrpld/app/tx/detail/VaultDelete.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ VaultDelete::preflight(PreflightContext const& ctx)
1919
return temMALFORMED;
2020
}
2121

22+
if (ctx.rules.enabled(fixLendingProtocolV1_1))
23+
{
24+
// The sfData field is an optional field used to record the deletion reason.
25+
if (auto const data = ctx.tx[~sfData]; data && !validDataLength(data, maxDataPayloadLength))
26+
return temMALFORMED;
27+
}
28+
2229
return tesSUCCESS;
2330
}
2431

0 commit comments

Comments
 (0)