Skip to content

Commit

Permalink
fix maximum amt (#34)
Browse files Browse the repository at this point in the history
* fix maximum amt

* add if check to return tecMPT_ISSUANCE_NOT_FOUND
  • Loading branch information
shawnxie999 authored Sep 10, 2024
1 parent 8fd18a5 commit 6364440
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,28 @@ class MPToken_test : public beast::unit_test::suite
// destroyed, it should fail
mptAlice.pay(alice, bob, 100, tecMPT_ISSUANCE_NOT_FOUND);
}

// Issuers issues maximum amount of MPT to a holder, the holder should
// be able to transfer the max amount to someone else
{
Env env{*this, features};
Account const alice("alice");
Account const carol("bob");
Account const bob("carol");

MPTTester mptAlice(env, alice, {.holders = {&bob, &carol}});

mptAlice.create(
{.maxAmt = 100, .ownerCount = 1, .flags = tfMPTCanTransfer});

mptAlice.authorize({.account = &bob});
mptAlice.authorize({.account = &carol});

mptAlice.pay(alice, bob, 100);

// transfer max amount to another holder
mptAlice.pay(bob, carol, 100);
}
}

void
Expand Down
22 changes: 16 additions & 6 deletions src/xrpld/ledger/detail/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,20 @@ rippleSend(

if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount())
{
// if sender is issuer, check that the new OutstandingAmount will not
// exceed MaximumAmount
if (uSenderID == issuer)
{
auto const mptID = keylet::mptIssuance(saAmount.issue().getMptID());
auto const sle = view.peek(mptID);
if (!sle)
return tecMPT_ISSUANCE_NOT_FOUND;

if (sle->getFieldU64(sfOutstandingAmount) + saAmount.value() >
(*sle)[~sfMaximumAmount].value_or(maxMPTokenAmount))
return tecMPT_MAX_AMOUNT_EXCEEDED;
}

// Direct send: redeeming IOUs and/or sending own IOUs.
auto const ter =
rippleCredit(view, uSenderID, uReceiverID, saAmount, j);
Expand Down Expand Up @@ -1380,8 +1394,8 @@ rippleSend(
rippleCredit(view, issuer, uReceiverID, saAmount, j);
terResult != tesSUCCESS)
return terResult;
else
return rippleCredit(view, uSenderID, issuer, saActual, j);

return rippleCredit(view, uSenderID, issuer, saActual, j);
}

return tecINTERNAL;
Expand Down Expand Up @@ -1872,10 +1886,6 @@ rippleCredit(
sfOutstandingAmount,
sle->getFieldU64(sfOutstandingAmount) + saAmount.value());

if (sle->getFieldU64(sfOutstandingAmount) >
(*sle)[~sfMaximumAmount].value_or(maxMPTokenAmount))
return tecMPT_MAX_AMOUNT_EXCEEDED;

view.update(sle);
}
else
Expand Down

0 comments on commit 6364440

Please sign in to comment.