Skip to content

Commit

Permalink
Add AccountPermission ledger object
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Oct 8, 2024
1 parent a753099 commit c7ac801
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ extern uint256 const fixEnforceNFTokenTrustline;
extern uint256 const fixInnerObjTemplate2;
extern uint256 const featureInvariantsV1_1;
extern uint256 const fixNFTokenPageLinks;
extern uint256 const featureAccountPermission;

} // namespace ripple

Expand Down
14 changes: 14 additions & 0 deletions include/xrpl/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ amm(Issue const& issue1, Issue const& issue2) noexcept;
Keylet
amm(uint256 const& amm) noexcept;

/** An AccountPermission */
/** @{ */
Keylet
AccountPermission(
AccountID const& account,
AccountID const& authorizedAccount) noexcept;

inline Keylet
AccountPermission(uint256 const& key) noexcept
{
return {ltACCOUNT_PERMISSION, key};
}
/** @} */

Keylet
bridge(STXChainBridge const& bridge, STXChainBridge::ChainType chainType);

Expand Down
6 changes: 6 additions & 0 deletions include/xrpl/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ enum LedgerEntryType : std::uint16_t
\sa keylet::oracle
*/
ltORACLE = 0x0080,

/** A ledger object representing permissions an account has delegated to another account.
\sa keylet::accountPermission
*/
ltACCOUNT_PERMISSION = 0x0081,

//---------------------------------------------------------------------------
/** A special type, matching any ledger entry type.
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ extern SField const sfHooks;
extern SField const sfVoteSlots;
extern SField const sfAuthAccounts;
extern SField const sfPriceDataSeries;
extern SField const sfPermissions;

// array of objects (uncommon)
extern SField const sfMajorities;
Expand Down
2 changes: 2 additions & 0 deletions include/xrpl/protocol/TxFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ enum TxType : std::uint16_t
/** This transaction type fixes a problem in the ledger state */
ttLEDGER_STATE_FIX = 53,

/** This transaction type delegates permissions to other account */
ttACCOUNT_PERMISSION_SET = 54,

/** This system-generated transaction type is used to update the status of the various amendments.
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ JSS(AL_size); // out: GetCounts
JSS(AL_hit_rate); // out: GetCounts
JSS(Account); // in: TransactionSign; field.
JSS(AccountDelete); // transaction type.
JSS(AccountPermission); // ledger type.
JSS(AccountPermissionSet); // transaction type.
JSS(AccountRoot); // ledger type.
JSS(AccountSet); // transaction type.
JSS(AMM); // ledger type
Expand Down Expand Up @@ -172,6 +174,7 @@ JSS(account_hash); // out: LedgerToJson
JSS(account_id); // out: WalletPropose
JSS(account_nfts); // out: AccountNFTs
JSS(account_objects); // out: AccountObjects
JSS(account_permission); // AccountPermission
JSS(account_root); // in: LedgerEntry
JSS(account_sequence_next); // out: SubmitTransaction
JSS(account_sequence_available); // out: SubmitTransaction
Expand Down
1 change: 1 addition & 0 deletions src/libxrpl/protocol/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ REGISTER_FIX (fixReducedOffersV2, Supported::yes, VoteBehavior::De
REGISTER_FIX (fixEnforceNFTokenTrustline, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixInnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixNFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(AccountPermission, Supported::yes, VoteBehavior::DefaultNo);
// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
REGISTER_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo);
Expand Down
12 changes: 12 additions & 0 deletions src/libxrpl/protocol/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum class LedgerNameSpace : std::uint16_t {
XCHAIN_CREATE_ACCOUNT_CLAIM_ID = 'K',
DID = 'I',
ORACLE = 'R',
ACCOUNT_PERMISSION = 'P',

// No longer used or supported. Left here to reserve the space
// to avoid accidental reuse.
Expand Down Expand Up @@ -398,6 +399,17 @@ amm(uint256 const& id) noexcept
return {ltAMM, id};
}

Keylet
accountPermission(
AccountID const& account,
AccountID const& authorizedAccount) noexcept
{
return {
ltACCOUNT_PERMISSION,
indexHash(
LedgerNameSpace::ACCOUNT_PERMISSION, account, authorizedAccount)};
}

Keylet
bridge(STXChainBridge const& bridge, STXChainBridge::ChainType chainType)
{
Expand Down
11 changes: 11 additions & 0 deletions src/libxrpl/protocol/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ LedgerFormats::LedgerFormats()
},
commonFields);

add(jss::AccountPermission,
ltACCOUNT_PERMISSION,
{
{sfAccount, soeREQUIRED},
{sfAuthorize, soeREQUIRED},
{sfPermissions, soeREQUIRED},
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED},
},
commonFields);

add(jss::Bridge,
ltBRIDGE,
{
Expand Down
8 changes: 8 additions & 0 deletions src/libxrpl/protocol/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ TxFormats::TxFormats()
{sfOwner, soeOPTIONAL},
},
commonFields);

add(jss::AccountPermissionSet,
ttACCOUNT_PERMISSION_SET,
{
{sfAuthorize, soeREQUIRED},
{sfPermissions, soeREQUIRED},
},
commonFields);
}

TxFormats const&
Expand Down
64 changes: 64 additions & 0 deletions src/xrpld/app/tx/detail/AccountPermissionSet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
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
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 <xrpld/app/tx/detail/AccountPermissionSet.h>
#include <xrpld/ledger/View.h>
#include <xrpl/basics/Log.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/TxFlags.h>
#include <xrpl/protocol/st.h>

namespace ripple {

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

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

return preflight2(ctx);
}

TER
AccountPermissionSet::preclaim(PreclaimContext const& ctx)
{
return tesSUCCESS;
}

TER
AccountPermissionSet::doApply()
{
return tesSUCCESS;
}

TER
AccountPermissionSet::deleteAccountPermission(
Application& app,
ApplyView& view,
uint256 const& delIndex,
beast::Journal j)
{
return tesSUCCESS;
}

} // namespace ripple
56 changes: 56 additions & 0 deletions src/xrpld/app/tx/detail/AccountPermissionSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
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
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_ACCOUNTPERMISSIONSET_H_INCLUDED
#define RIPPLE_TX_ACCOUNTPERMISSIONSET_H_INCLUDED

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

namespace ripple {

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

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

static NotTEC
preflight(PreflightContext const& ctx);

static TER
preclaim(PreclaimContext const& ctx);

TER
doApply() override;

// Interface used by DeleteAccount
static TER
deleteAccountPermission(
Application& app,
ApplyView& view,
uint256 const& delIndex,
beast::Journal j);
};

} // namespace ripple

#endif
16 changes: 16 additions & 0 deletions src/xrpld/app/tx/detail/DeleteAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================

#include <xrpld/app/tx/detail/AccountPermissionSet.h>
#include <xrpld/app/tx/detail/DID.h>
#include <xrpld/app/tx/detail/DeleteAccount.h>
#include <xrpld/app/tx/detail/DeleteOracle.h>
Expand Down Expand Up @@ -159,6 +160,19 @@ removeOracleFromLedger(
return DeleteOracle::deleteOracle(view, sleDel, account, j);
}

TER
removeAccountPermissionFromLedger(
Application& app,
ApplyView& view,
AccountID const& account,
uint256 const& delIndex,
std::shared_ptr<SLE> const& sleDel,
beast::Journal j)
{
return AccountPermissionSet::deleteAccountPermission(
app, view, delIndex, j);
}

// Return nullptr if the LedgerEntryType represents an obligation that can't
// be deleted. Otherwise return the pointer to the function that can delete
// the non-obligation
Expand All @@ -181,6 +195,8 @@ nonObligationDeleter(LedgerEntryType t)
return removeDIDFromLedger;
case ltORACLE:
return removeOracleFromLedger;
case ltACCOUNT_PERMISSION:
return removeAccountPermissionFromLedger;
default:
return nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions src/xrpld/app/tx/detail/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ LedgerEntryTypesMatch::visitEntry(
switch (after->getType())
{
case ltACCOUNT_ROOT:
case ltACCOUNT_PERMISSION:
case ltDIR_NODE:
case ltRIPPLE_STATE:
case ltTICKET:
Expand Down
3 changes: 3 additions & 0 deletions src/xrpld/app/tx/detail/applySteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <xrpld/app/tx/detail/AMMDeposit.h>
#include <xrpld/app/tx/detail/AMMVote.h>
#include <xrpld/app/tx/detail/AMMWithdraw.h>
#include <xrpld/app/tx/detail/AccountPermissionSet.h>
#include <xrpld/app/tx/detail/ApplyContext.h>
#include <xrpld/app/tx/detail/CancelCheck.h>
#include <xrpld/app/tx/detail/CancelOffer.h>
Expand Down Expand Up @@ -78,6 +79,8 @@ with_txn_type(TxType txnType, F&& f)
{
case ttACCOUNT_DELETE:
return f.template operator()<DeleteAccount>();
case ttACCOUNT_PERMISSION_SET:
return f.template operator()<AccountPermissionSet>();
case ttACCOUNT_SET:
return f.template operator()<SetAccount>();
case ttCHECK_CANCEL:
Expand Down
3 changes: 2 additions & 1 deletion src/xrpld/rpc/detail/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,9 +915,10 @@ chooseLedgerEntryType(Json::Value const& params)
std::pair<RPC::Status, LedgerEntryType> result{RPC::Status::OK, ltANY};
if (params.isMember(jss::type))
{
static constexpr std::array<std::pair<char const*, LedgerEntryType>, 22>
static constexpr std::array<std::pair<char const*, LedgerEntryType>, 23>
types{
{{jss::account, ltACCOUNT_ROOT},
{jss::account_permission, ltACCOUNT_PERMISSION},
{jss::amendments, ltAMENDMENTS},
{jss::amm, ltAMM},
{jss::bridge, ltBRIDGE},
Expand Down
4 changes: 4 additions & 0 deletions src/xrpld/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ doLedgerEntry(RPC::JsonContext& context)
uNodeIndex = keylet::oracle(*account, *documentID).key;
}
}
else if (context.params.isMember(jss::account_permission))
{
// to be implemented
}
else
{
if (context.params.isMember("params") &&
Expand Down

0 comments on commit c7ac801

Please sign in to comment.