Skip to content

Commit

Permalink
address comments (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 authored Oct 18, 2024
1 parent 780af7a commit e4009c8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
21 changes: 16 additions & 5 deletions src/xrpld/app/tx/detail/MPTokenAuthorize.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -63,9 +63,11 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)
std::shared_ptr<SLE const> sleMpt = ctx.view.read(
keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], accountID));

// There is an edge case where holder deletes MPT after issuance has
// already been destroyed. So we must check for unauthorize before
// fetching the MPTIssuance object(since it doesn't exist)
// There is an edge case where all holders have zero balance, issuance
// is legally destroyed, then outstanding MPT(s) are deleted afterwards.
// Thus, there is no need to check for the existence of the issuance if
// the MPT is being deleted with a zero balance. Check for unauthorize
// before fetching the MPTIssuance object.

// if holder wants to delete/unauthorize a mpt
if (ctx.tx.getFlags() & tfMPTUnauthorize)
Expand All @@ -74,7 +76,15 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)
return tecOBJECT_NOT_FOUND;

if ((*sleMpt)[sfMPTAmount] != 0)
{
auto const sleMptIssuance = ctx.view.read(
keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID]));
assert(sleMptIssuance);
if (!sleMptIssuance)
return tefINTERNAL;

return tecHAS_OBLIGATIONS;
}

return tesSUCCESS;
}
Expand Down Expand Up @@ -118,6 +128,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)
if (!(mptIssuanceFlags & lsfMPTRequireAuth))
return tecNO_AUTH;

// The holder must create the MPT before the issuer can authorize it.
if (!ctx.view.exists(
keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], *holderID)))
return tecOBJECT_NOT_FOUND;
Expand Down Expand Up @@ -148,7 +159,7 @@ MPTokenAuthorize::authorize(
auto const mptokenKey =
keylet::mptoken(args.mptIssuanceID, args.account);
auto const sleMpt = view.peek(mptokenKey);
if (!sleMpt)
if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0)
return tecINTERNAL;

if (!view.dirRemove(
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/MPTokenAuthorize.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -55,7 +55,7 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx)
return temMALFORMED;
}

// Check if maximumAmount is within 63 bit range
// Check if maximumAmount is within unsigned 63 bit range
if (auto const maxAmt = ctx.tx[~sfMaximumAmount])
{
if (maxAmt == 0)
Expand Down
12 changes: 7 additions & 5 deletions src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand All @@ -18,6 +18,7 @@
//==============================================================================

#include <xrpld/app/tx/detail/MPTokenIssuanceDestroy.h>

#include <xrpld/ledger/View.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/TxFlags.h>
Expand Down Expand Up @@ -66,17 +67,18 @@ MPTokenIssuanceDestroy::doApply()
{
auto const mpt =
view().peek(keylet::mptIssuance(ctx_.tx[sfMPTokenIssuanceID]));
auto const issuer = (*mpt)[sfIssuer];
if (account_ != mpt->getAccountID(sfIssuer))
return tecINTERNAL;

if (!view().dirRemove(
keylet::ownerDir(issuer), (*mpt)[sfOwnerNode], mpt->key(), false))
keylet::ownerDir(account_), (*mpt)[sfOwnerNode], mpt->key(), false))
return tefBAD_LEDGER;

view().erase(mpt);

adjustOwnerCount(view(), view().peek(keylet::account(issuer)), -1, j_);
adjustOwnerCount(view(), view().peek(keylet::account(account_)), -1, j_);

return tesSUCCESS;
}

} // namespace ripple
} // namespace ripple
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -45,4 +45,4 @@ class MPTokenIssuanceDestroy : public Transactor

} // namespace ripple

#endif
#endif
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -115,4 +115,4 @@ MPTokenIssuanceSet::doApply()
return tesSUCCESS;
}

} // namespace ripple
} // namespace ripple
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/MPTokenIssuanceSet.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 Ripple Labs Inc.
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down

0 comments on commit e4009c8

Please sign in to comment.