Skip to content

Commit

Permalink
clang
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed May 3, 2024
1 parent cb6dcd8 commit 3c0a079
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ripple/app/tx/impl/Payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ Payment::doApply()
ter != tesSUCCESS)
return ter;

if (auto const ter =
canTransfer(view(), saDstAmount.mptIssue(), account_, uDstAccountID);
if (auto const ter = canTransfer(
view(), saDstAmount.mptIssue(), account_, uDstAccountID);
ter != tesSUCCESS)
return ter;

Expand Down
10 changes: 7 additions & 3 deletions src/ripple/ledger/impl/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,14 +1699,18 @@ requireAuth(ReadView const& view, MPTIssue const& mpt, AccountID const& account)
}

TER
canTransfer(ReadView const& view, MPTIssue const& mpt, AccountID const& from, AccountID const& to)
canTransfer(
ReadView const& view,
MPTIssue const& mpt,
AccountID const& from,
AccountID const& to)
{
auto const mptID = keylet::mptIssuance(mpt.mpt());
if (auto const sle = view.read(mptID);
sle && !(sle->getFieldU32(sfFlags) & lsfMPTCanTransfer))
{
if(from != (*sle)[sfIssuer] && to != (*sle)[sfIssuer])
return TER{tecNO_AUTH};
if (from != (*sle)[sfIssuer] && to != (*sle)[sfIssuer])
return TER{tecNO_AUTH};
}
return tesSUCCESS;
}
Expand Down
30 changes: 20 additions & 10 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ class MPToken_test : public beast::unit_test::suite

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

mptAlice.create({.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanTransfer});
mptAlice.create(
{.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanTransfer});

// env(mpt::authorize(alice, id.key, std::nullopt));
// env.close();
Expand All @@ -646,7 +647,9 @@ class MPToken_test : public beast::unit_test::suite
MPTTester mptAlice(env, alice, {.holders = {&bob}});

mptAlice.create(
{.ownerCount = 1, .holderCount = 0, .flags = tfMPTRequireAuth | tfMPTCanTransfer});
{.ownerCount = 1,
.holderCount = 0,
.flags = tfMPTRequireAuth | tfMPTCanTransfer});

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

Expand All @@ -661,7 +664,9 @@ class MPToken_test : public beast::unit_test::suite
MPTTester mptAlice(env, alice, {.holders = {&bob}});

mptAlice.create(
{.ownerCount = 1, .holderCount = 0, .flags = tfMPTRequireAuth | tfMPTCanTransfer});
{.ownerCount = 1,
.holderCount = 0,
.flags = tfMPTRequireAuth | tfMPTCanTransfer});

// bob creates an empty MPToken
mptAlice.authorize({.account = &bob});
Expand Down Expand Up @@ -707,7 +712,8 @@ class MPToken_test : public beast::unit_test::suite

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

mptAlice.create({.ownerCount = 1, .flags = tfMPTCanLock | tfMPTCanTransfer});
mptAlice.create(
{.ownerCount = 1, .flags = tfMPTCanLock | tfMPTCanTransfer});

mptAlice.authorize({.account = &bob});
mptAlice.authorize({.account = &carol});
Expand Down Expand Up @@ -745,7 +751,11 @@ class MPToken_test : public beast::unit_test::suite

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

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

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

Expand Down Expand Up @@ -807,7 +817,8 @@ class MPToken_test : public beast::unit_test::suite
mptAlice.pay(bob, carol, 100);
}

// Test that non-issuer cannot send to each other if MPTCanTransfer isn't set
// Test that non-issuer cannot send to each other if MPTCanTransfer
// isn't set
{
Env env(*this, features);
Account const alice{"alice"};
Expand All @@ -817,9 +828,7 @@ class MPToken_test : public beast::unit_test::suite
MPTTester mptAlice(env, alice, {.holders = {&bob, &cindy}});

// alice creates issuance without MPTCanTransfer
mptAlice.create(
{.ownerCount = 1,
.holderCount = 0});
mptAlice.create({.ownerCount = 1, .holderCount = 0});

// bob creates a MPToken
mptAlice.authorize({.account = &bob});
Expand All @@ -830,7 +839,8 @@ class MPToken_test : public beast::unit_test::suite
// alice pays bob 100 tokens
mptAlice.pay(alice, bob, 100);

// bob tries to send cindy 10 tokens, but fails because canTransfer is off
// bob tries to send cindy 10 tokens, but fails because canTransfer
// is off
mptAlice.pay(bob, cindy, 10, tecNO_AUTH);

// bob can send back to alice(issuer) just fine
Expand Down

0 comments on commit 3c0a079

Please sign in to comment.