Skip to content

Commit 6364440

Browse files
authored
fix maximum amt (XRPLF#34)
* fix maximum amt * add if check to return tecMPT_ISSUANCE_NOT_FOUND
1 parent 8fd18a5 commit 6364440

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/test/app/MPToken_test.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,28 @@ class MPToken_test : public beast::unit_test::suite
10151015
// destroyed, it should fail
10161016
mptAlice.pay(alice, bob, 100, tecMPT_ISSUANCE_NOT_FOUND);
10171017
}
1018+
1019+
// Issuers issues maximum amount of MPT to a holder, the holder should
1020+
// be able to transfer the max amount to someone else
1021+
{
1022+
Env env{*this, features};
1023+
Account const alice("alice");
1024+
Account const carol("bob");
1025+
Account const bob("carol");
1026+
1027+
MPTTester mptAlice(env, alice, {.holders = {&bob, &carol}});
1028+
1029+
mptAlice.create(
1030+
{.maxAmt = 100, .ownerCount = 1, .flags = tfMPTCanTransfer});
1031+
1032+
mptAlice.authorize({.account = &bob});
1033+
mptAlice.authorize({.account = &carol});
1034+
1035+
mptAlice.pay(alice, bob, 100);
1036+
1037+
// transfer max amount to another holder
1038+
mptAlice.pay(bob, carol, 100);
1039+
}
10181040
}
10191041

10201042
void

src/xrpld/ledger/detail/View.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,20 @@ rippleSend(
13531353

13541354
if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount())
13551355
{
1356+
// if sender is issuer, check that the new OutstandingAmount will not
1357+
// exceed MaximumAmount
1358+
if (uSenderID == issuer)
1359+
{
1360+
auto const mptID = keylet::mptIssuance(saAmount.issue().getMptID());
1361+
auto const sle = view.peek(mptID);
1362+
if (!sle)
1363+
return tecMPT_ISSUANCE_NOT_FOUND;
1364+
1365+
if (sle->getFieldU64(sfOutstandingAmount) + saAmount.value() >
1366+
(*sle)[~sfMaximumAmount].value_or(maxMPTokenAmount))
1367+
return tecMPT_MAX_AMOUNT_EXCEEDED;
1368+
}
1369+
13561370
// Direct send: redeeming IOUs and/or sending own IOUs.
13571371
auto const ter =
13581372
rippleCredit(view, uSenderID, uReceiverID, saAmount, j);
@@ -1380,8 +1394,8 @@ rippleSend(
13801394
rippleCredit(view, issuer, uReceiverID, saAmount, j);
13811395
terResult != tesSUCCESS)
13821396
return terResult;
1383-
else
1384-
return rippleCredit(view, uSenderID, issuer, saActual, j);
1397+
1398+
return rippleCredit(view, uSenderID, issuer, saActual, j);
13851399
}
13861400

13871401
return tecINTERNAL;
@@ -1872,10 +1886,6 @@ rippleCredit(
18721886
sfOutstandingAmount,
18731887
sle->getFieldU64(sfOutstandingAmount) + saAmount.value());
18741888

1875-
if (sle->getFieldU64(sfOutstandingAmount) >
1876-
(*sle)[~sfMaximumAmount].value_or(maxMPTokenAmount))
1877-
return tecMPT_MAX_AMOUNT_EXCEEDED;
1878-
18791889
view.update(sle);
18801890
}
18811891
else

0 commit comments

Comments
 (0)