Allow resetting DomainID

This commit is contained in:
Bronek Kozicki
2025-04-28 15:21:34 +01:00
parent 5bfbb09970
commit d46a2d8a71
2 changed files with 35 additions and 37 deletions

View File

@@ -199,13 +199,6 @@ class Vault_test : public beast::unit_test::suite
env(tx);
}
{
testcase(prefix + " fail to set zero domain");
auto tx = vault.set({.owner = owner, .id = keylet.key});
tx[sfDomainID] = to_string(base_uint<256>(beast::zero));
env(tx, ter(temMALFORMED));
}
{
testcase(prefix + " fail to set domain on public vault");
auto tx = vault.set({.owner = owner, .id = keylet.key});
@@ -1501,26 +1494,24 @@ class Vault_test : public beast::unit_test::suite
}
{
testcase("private vault no authorization needed to withdraw");
env(credentials::deleteCred(
depositor, depositor, credIssuer2, credType));
testcase("private vault reset domainId");
auto tx = vault.set({.owner = owner, .id = keylet.key});
tx[sfDomainID] = "0";
env(tx);
env.close();
auto tx = vault.withdraw(
{.depositor = depositor,
.id = keylet.key,
.amount = asset(100)});
env(tx);
}
{
testcase("private vault depositor not authorized");
auto tx = vault.deposit(
tx = vault.deposit(
{.depositor = depositor,
.id = keylet.key,
.amount = asset(50)});
env(tx, ter{tecNO_AUTH});
env.close();
tx = vault.withdraw(
{.depositor = depositor,
.id = keylet.key,
.amount = asset(100)});
env(tx);
}
}

View File

@@ -55,12 +55,6 @@ VaultSet::preflight(PreflightContext const& ctx)
return temMALFORMED;
}
if (auto const domain = ctx.tx[~sfDomainID])
{
if (*domain == beast::zero)
return temMALFORMED;
}
if (auto const assetMax = ctx.tx[~sfAssetsMaximum])
{
if (*assetMax < beast::zero)
@@ -97,10 +91,13 @@ VaultSet::preclaim(PreclaimContext const& ctx)
if ((vault->getFlags() & tfVaultPrivate) == 0)
return tecNO_PERMISSION;
auto const sleDomain =
ctx.view.read(keylet::permissionedDomain(*domain));
if (!sleDomain)
return tecOBJECT_NOT_FOUND;
if (*domain != beast::zero)
{
auto const sleDomain =
ctx.view.read(keylet::permissionedDomain(*domain));
if (!sleDomain)
return tecOBJECT_NOT_FOUND;
}
// Sanity check only, this should be enforced by VaultCreate
if ((sleIssuance->getFlags() & lsfMPTRequireAuth) == 0)
@@ -139,14 +136,24 @@ VaultSet::doApply()
return tecLIMIT_EXCEEDED;
vault->at(sfAssetsMaximum) = tx[sfAssetsMaximum];
}
if (tx.isFieldPresent(sfDomainID))
if (auto const domainId = tx[~sfDomainID]; domainId)
{
// In VaultSet::preclaim we enforce that tfVaultPrivate must have been
// set in the vault. We currently do not support making such a vault
// public (i.e. removal of tfVaultPrivate flag). The sfDomainID flag
// must be set in the MPTokenIssuance object and can be freely updated.
sleIssuance->setFieldH256(sfDomainID, tx.getFieldH256(sfDomainID));
view().update(sleIssuance);
if (*domainId != beast::zero)
{
// In VaultSet::preclaim we enforce that tfVaultPrivate must have
// been set in the vault. We currently do not support making such a
// vault public (i.e. removal of tfVaultPrivate flag). The
// sfDomainID flag must be set in the MPTokenIssuance object and can
// be freely updated.
sleIssuance->setFieldH256(sfDomainID, *domainId);
view().update(sleIssuance);
}
else if (sleIssuance->isFieldPresent(sfDomainID))
{
sleIssuance->makeFieldAbsent(sfDomainID);
view().update(sleIssuance);
}
}
view().update(vault);