Skip to content

Commit

Permalink
destiory wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed Oct 31, 2023
1 parent 08a1bb5 commit 05b2144
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 0 deletions.
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ target_sources (rippled PRIVATE
src/ripple/app/tx/impl/ApplyContext.cpp
src/ripple/app/tx/impl/BookTip.cpp
src/ripple/app/tx/impl/CFTokenIssuanceCreate.cpp
src/ripple/app/tx/impl/CFTokenIssuanceDestroy.cpp
src/ripple/app/tx/impl/CancelCheck.cpp
src/ripple/app/tx/impl/CancelOffer.cpp
src/ripple/app/tx/impl/CashCheck.cpp
Expand Down
81 changes: 81 additions & 0 deletions src/ripple/app/tx/impl/CFTokenIssuanceDestory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 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
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <ripple/app/tx/impl/CFTokenIssuanceDestroy.h>
#include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/st.h>

namespace ripple {

NotTEC
CFTokenIssuanceDestroy::preflight(PreflightContext const& ctx)
{
if (!ctx.rules.enabled(featureCFTokensV1))
return temDISABLED;

if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

return preflight2(ctx);
}

TER
CFTokenIssuanceDestroy::preclaim(PreclaimContext const& ctx)
{
// ensure that issuance exists
auto const sleCFT =
ctx.view.read(keylet::cftIssuance(ctx.tx[sfCFTokenIssuanceID]));
if (!sleCFT)
return tecOBJECT_NOT_FOUND;

// ensure it is issued by the tx submitter
if ((*sleCFT)[sfIssuer] != ctx.tx[sfAccount])
return tecNO_PERMISSION;

// ensure it has no outstanding balances
if ((*sleCFT)[~sfOutstandingAmount] != 0)
return tecHAS_OBLIGATIONS;

return tesSUCCESS;
}

TER
CFTokenIssuanceDestroy::doApply()
{
auto const cft =
view().peek(keylet::cftIssuance(ctx_.tx[sfCFTokenIssuanceID]));
auto const issuer = (*cft)[sfIssuer];

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

view().erase(cft);

adjustOwnerCount(
view(),
view().peek(keylet::account(issuer)),
-1,
beast::Journal{beast::Journal::getNullSink()});

return tesSUCCESS;
}

} // namespace ripple
48 changes: 48 additions & 0 deletions src/ripple/app/tx/impl/CFTokenIssuanceDestory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 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
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_TX_CFTOKENISSUANCEDESTROY_H_INCLUDED
#define RIPPLE_TX_CFTOKENISSUANCEDESTROY_H_INCLUDED

#include <ripple/app/tx/impl/Transactor.h>

namespace ripple {

class CFTokenIssuanceDestroy : public Transactor
{
public:
static constexpr ConsequencesFactoryType ConsequencesFactory{Normal};

explicit CFTokenIssuanceDestroy(ApplyContext& ctx) : Transactor(ctx)
{
}

static NotTEC
preflight(PreflightContext const& ctx);

static TER
preclaim(PreclaimContext const& ctx);

TER
doApply() override;
};

} // namespace ripple

#endif
21 changes: 21 additions & 0 deletions src/ripple/app/tx/impl/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,27 @@ ValidCFTIssuance::finalize(
return cftsCreated_ == 1 && cftsDeleted_ == 0;
}

if (tx.getTxnType() == ttCFTOKEN_ISSUANCE_DESTROY && result == tesSUCCESS)
{
if (cftsDeleted_ == 0)
{
JLOG(j.fatal()) << "Invariant failed: CFT issuance deletion "
"succeeded without removing a CFT issuance";
}
else if (cftsCreated_ > 0)
{
JLOG(j.fatal()) << "Invariant failed: CFT issuance deletion "
"succeeded while creating CFT issuances";
}
else if (cftsDeleted_ > 1)
{
JLOG(j.fatal()) << "Invariant failed: CFT issuance deletion "
"succeeded but deleted multiple issuances";
}

return cftsCreated_ == 0 && cftsDeleted_ == 1;
}

if (cftsCreated_ != 0)
{
JLOG(j.fatal()) << "Invariant failed: a CFT issuance was created";
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/app/tx/impl/applySteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ with_txn_type(TxType txnType, F&& f)
return f.template operator()<DIDDelete>();
case ttCFTOKEN_ISSUANCE_CREATE:
return f.template operator()<CFTokenIssuanceCreate>();
case ttCFTOKEN_ISSUANCE_DESTORY:
return f.template operator()<CFTokenIssuanceDestory>();
default:
throw UnknownTxnType(txnType);
}
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ extern SF_UINT256 const sfEmitParentTxnID;
extern SF_UINT256 const sfEmitNonce;
extern SF_UINT256 const sfEmitHookHash;
extern SF_UINT256 const sfAMMID;
extern SF_UINT256 const sfCFTokenIssuanceID;

// 256-bit (uncommon)
extern SF_UINT256 const sfBookDirectory;
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/protocol/TxFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ enum TxType : std::uint16_t
/** This transaction creates a new CFTokenIssuance object. */
ttCFTOKEN_ISSUANCE_CREATE = 51,

/** This transaction destroys an existing CFTokenIssuance object. */
ttCFTOKEN_ISSUANCE_DESTROY = 52,

/** This system-generated transaction type is used to update the status of the various amendments.
For details, see: https://xrpl.org/amendments.html
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/SField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ CONSTRUCT_TYPED_SFIELD(sfEmitParentTxnID, "EmitParentTxnID", UINT256,
CONSTRUCT_TYPED_SFIELD(sfEmitNonce, "EmitNonce", UINT256, 12);
CONSTRUCT_TYPED_SFIELD(sfEmitHookHash, "EmitHookHash", UINT256, 13);
CONSTRUCT_TYPED_SFIELD(sfAMMID, "AMMID", UINT256, 14);
CONSTRUCT_TYPED_SFIELD(sfCFTokenIssuanceID, "CFTokenIssuanceID", UINT256, 15);

// 256-bit (uncommon)
CONSTRUCT_TYPED_SFIELD(sfBookDirectory, "BookDirectory", UINT256, 16);
Expand Down
7 changes: 7 additions & 0 deletions src/ripple/protocol/impl/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ TxFormats::TxFormats()
{sfCFTokenMetadata, soeOPTIONAL},
},
commonFields);

add(jss::CFTokenIssuanceDestroy,
ttCFTOKEN_ISSUANCE_DESTROY,
{
{sfCFTokenIssuanceID, soeREQUIRED},
},
commonFields);
}

TxFormats const&
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ JSS(AuthAccounts); // in: AMM Auction Slot
JSS(Bridge); // ledger type.
JSS(CFTokenIssuance); // ledger type.
JSS(CFTokenIssuanceCreate); // transaction type.
JSS(CFTokenIssuanceDestroy); // transaction type.
JSS(CFTokenIssuanceID); // in: CFTokenIssuanceDestroy.
JSS(Check); // ledger type.
JSS(CheckCancel); // transaction type.
JSS(CheckCash); // transaction type.
Expand Down

0 comments on commit 05b2144

Please sign in to comment.