Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address more comments #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading