Skip to content

Commit 0fee8ba

Browse files
committed
Replace canTrade with canTransfer in CheckCreate/Cash (Check is not DEX tx).
1 parent 454a289 commit 0fee8ba

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

src/libxrpl/tx/invariants/MPTInvariant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ ValidMPTTransfer::finalize(
424424
auto const amount = tx[sfAmount];
425425
return tx[~sfSendMax].value_or(amount).asset() != amount.asset();
426426
}
427-
return txnType == ttCHECK_CASH || txnType == ttOFFER_CREATE;
427+
return txnType == ttOFFER_CREATE;
428428
}();
429429

430430
// Only enforce once MPTokensV2 is enabled to preserve consensus with non-V2 nodes.

src/libxrpl/tx/transactors/check/CheckCash.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ CheckCash::preclaim(PreclaimContext const& ctx)
243243
return tecLOCKED;
244244
}
245245

246-
if (auto const err = canTrade(ctx.view, value.asset()); !isTesSuccess(err))
246+
if (auto const err = canTransfer(ctx.view, issue, srcId, dstId);
247+
!isTesSuccess(err))
247248
{
248-
JLOG(ctx.j.warn()) << "MPT DEX is not allowed.";
249+
JLOG(ctx.j.warn()) << "MPT transfer is disabled.";
249250
return err;
250251
}
251252

src/libxrpl/tx/transactors/check/CheckCreate.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,21 @@ CheckCreate::preclaim(PreclaimContext const& ctx)
136136
},
137137
[&](MPTIssue const& issue) -> std::optional<TER> {
138138
if (srcId != issuerId && isFrozen(ctx.view, srcId, issue))
139+
{
140+
JLOG(ctx.j.warn()) << "Creating a check for locked MPT.";
139141
return tecLOCKED;
142+
}
140143
if (dstId != issuerId && isFrozen(ctx.view, dstId, issue))
144+
{
145+
JLOG(ctx.j.warn()) << "Creating a check for locked MPT.";
141146
return tecLOCKED;
147+
}
148+
if (auto const ter = canTransfer(ctx.view, issue, srcId, dstId);
149+
!isTesSuccess(ter))
150+
{
151+
JLOG(ctx.j.warn()) << "MPT transfer is disabled.";
152+
return ter;
153+
}
142154

143155
return std::nullopt;
144156
});
@@ -152,7 +164,7 @@ CheckCreate::preclaim(PreclaimContext const& ctx)
152164
return tecEXPIRED;
153165
}
154166

155-
return canTrade(ctx.view, ctx.tx[sfSendMax].asset());
167+
return tesSUCCESS;
156168
}
157169

158170
TER

src/test/app/MPToken_test.cpp

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5833,7 +5833,7 @@ class MPToken_test : public beast::unit_test::suite
58335833
env.close();
58345834
}
58355835

5836-
// MPTCanTransfer disabled
5836+
// MPTCanTransfer is disabled
58375837
{
58385838
Env env{*this, features};
58395839
env.fund(XRP(1'000), gw, alice, carol);
@@ -5874,49 +5874,44 @@ class MPToken_test : public beast::unit_test::suite
58745874
BEAST_EXPECT(env.balance(alice, mpt) == mpt(0));
58755875
BEAST_EXPECT(env.balance(gw, mpt) == mpt(0));
58765876

5877-
// neither src nor dst is issuer, can still create
5877+
// neither src nor dst is issuer, can't create
58785878
checkId = keylet::check(alice, env.seq(alice)).key;
5879-
env(check::create(alice, carol, mpt(100)));
5880-
env.close();
5881-
5882-
// can't cash
5883-
env(check::cash(carol, checkId, mpt(10)), ter(tecPATH_PARTIAL));
5879+
env(check::create(alice, carol, mpt(100)), ter(tecNO_AUTH));
58845880
env.close();
58855881

5886-
// can cash now
5882+
// can create now
58875883
mpt.set({.account = gw, .mutableFlags = tmfMPTSetCanTransfer});
5884+
checkId = keylet::check(alice, env.seq(alice)).key;
5885+
env(check::create(alice, carol, mpt(100)));
5886+
env.close();
5887+
// can cash
58885888
env(pay(gw, alice, mpt(10)));
58895889
env.close();
58905890
env(check::cash(carol, checkId, mpt(10)));
58915891
env.close();
58925892
}
58935893

5894-
// MPTCanTrade disabled
5894+
// MPTCanTrade is disabled
58955895
{
58965896
Env env{*this, features};
58975897
env.fund(XRP(1'000), gw, alice, carol);
58985898
env.close();
58995899

5900-
MPTTester mpt(
5900+
MPT const mpt = MPTTester(
59015901
{.env = env,
59025902
.issuer = gw,
59035903
.holders = {alice, carol},
5904-
.flags = tfMPTCanTransfer,
5905-
.mutableFlags = tmfMPTCanMutateCanTrade});
5904+
.pay = 10,
5905+
.flags = tfMPTCanTransfer});
59065906

5907-
uint256 checkId{keylet::check(gw, env.seq(gw)).key};
5907+
uint256 const checkId{keylet::check(alice, env.seq(alice)).key};
59085908

5909-
// can't create
5910-
env(check::create(gw, alice, mpt(100)), ter(tecNO_PERMISSION));
5909+
// can create
5910+
env(check::create(alice, carol, mpt(100)));
59115911
env.close();
5912-
mpt.set({.account = gw, .mutableFlags = tmfMPTSetCanTrade});
59135912

5914-
// can't cash
5915-
checkId = keylet::check(gw, env.seq(gw)).key;
5916-
env(check::create(gw, carol, mpt(100)));
5917-
env.close();
5918-
mpt.set({.account = gw, .mutableFlags = tmfMPTClearCanTrade});
5919-
env(check::cash(carol, checkId, mpt(10)), ter(tecNO_PERMISSION));
5913+
// can cash
5914+
env(check::cash(carol, checkId, mpt(10)));
59205915
env.close();
59215916
}
59225917

@@ -5971,33 +5966,6 @@ class MPToken_test : public beast::unit_test::suite
59715966
env.close();
59725967
}
59735968

5974-
// MPTCanTransfer is not set and the account is not the issuer of MPT
5975-
{
5976-
Env env{*this, features};
5977-
env.fund(XRP(1'000), gw, alice, carol);
5978-
5979-
auto EUR = MPTTester(
5980-
{.env = env, .issuer = gw, .holders = {alice, carol}, .flags = tfMPTCanTrade});
5981-
uint256 const chkId{getCheckIndex(alice, env.seq(alice))};
5982-
// alice can create
5983-
env(check::create(alice, carol, EUR(1)));
5984-
env.close();
5985-
5986-
// carol can't cash
5987-
env(check::cash(carol, chkId, EUR(1)), ter(tecPATH_PARTIAL));
5988-
env.close();
5989-
5990-
// if issuer creates a check then carol can cash since
5991-
// it's a transfer from the issuer
5992-
uint256 const chkId1{getCheckIndex(gw, env.seq(gw))};
5993-
// alice can't create since CanTransfer is not set
5994-
env(check::create(gw, carol, EUR(1)));
5995-
env.close();
5996-
5997-
env(check::cash(carol, chkId1, EUR(1)));
5998-
env.close();
5999-
}
6000-
60015969
// Can create check if src/dst don't own MPT
60025970
{
60035971
Env env{*this, features};

0 commit comments

Comments
 (0)