Skip to content

Commit

Permalink
add AccountPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Oct 23, 2024
1 parent 63209c2 commit ef14541
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 79;
static constexpr std::size_t numFeatures = 80;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
11 changes: 11 additions & 0 deletions include/xrpl/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ 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;

Keylet
accountPermission(uint256 const& key) noexcept;
/** @} */

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

Expand Down
181 changes: 181 additions & 0 deletions include/xrpl/protocol/PermissionFormats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//------------------------------------------------------------------------------
/*
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_PROTOCOL_PERMISSIONFORMATS_H_INCLUDED
#define RIPPLE_PROTOCOL_PERMISSIONFORMATS_H_INCLUDED

#include <xrpl/protocol/KnownFormats.h>

namespace ripple {

/** Permission type identifiers.
These are part of the binary message format.
@ingroup protocol
*/
enum PermissionType : std::uint16_t {
tpPAYMENT = 1,

tpESCROW_CREATE = 2,

tpESCROW_FINISH = 3,

tpACCOUNT_SET = 4,

tpESCROW_CANCEL = 5,

tpREGULAR_KEY_SET = 6,

tpNICKNAME_SET [[deprecated(
"This transaction type is not supported and should not be used.")]] = 7,

tpOFFER_CREATE = 8,

tpOFFER_CANCEL = 9,

tpCONTRACT [[deprecated(
"This transaction type is not supported and should not be used.")]] =
10,

tpTICKET_CREATE = 11,

tpSPINAL_TAP [[deprecated(
"This transaction type is not supported and should not be used.")]] =
12,

tpSIGNER_LIST_SET = 13,

tpPAYCHAN_CREATE = 14,

tpPAYCHAN_FUND = 15,

tpPAYCHAN_CLAIM = 16,

tpCHECK_CREATE = 17,

tpCHECK_CASH = 18,

tpCHECK_CANCEL = 19,

tpDEPOSIT_PREAUTH = 20,

tpTRUST_SET = 21,

tpACCOUNT_DELETE = 22,

tpHOOK_SET [[maybe_unused]] = 23,

tpNFTOKEN_MINT = 26,

tpNFTOKEN_BURN = 27,

tpNFTOKEN_CREATE_OFFER = 28,

tpNFTOKEN_CANCEL_OFFER = 29,

tpNFTOKEN_ACCEPT_OFFER = 30,

tpCLAWBACK = 31,

tpAMM_CREATE = 36,

tpAMM_DEPOSIT = 37,

tpAMM_WITHDRAW = 38,

tpAMM_VOTE = 39,

tpAMM_BID = 40,

tpAMM_DELETE = 41,

tpXCHAIN_CREATE_CLAIM_ID = 42,

tpXCHAIN_COMMIT = 43,

tpXCHAIN_CLAIM = 44,

tpXCHAIN_ACCOUNT_CREATE_COMMIT = 45,

tpXCHAIN_ADD_CLAIM_ATTESTATION = 46,

tpXCHAIN_ADD_ACCOUNT_CREATE_AtpESTATION = 47,

tpXCHAIN_MODIFY_BRIDGE = 48,

tpXCHAIN_CREATE_BRIDGE = 49,

tpDID_SET = 50,

tpDID_DELETE = 51,

tpORACLE_SET = 52,

tpORACLE_DELETE = 53,

tpLEDGER_STATE_FIX = 54,
};

enum GranularPermissionType : std::uint32_t {
gpTrustlineAuthorize = 65537,

gpTrustlineFreeze = 65538,

gpTrustlineUnfreeze = 65539,

gpAccountDomainSet = 65540,

gpAccountEmailHashSet = 65541,

gpAccountMessageKeySet = 65542,

gpAccountTransferRateSet = 65543,

gpAccountTickSizeSet = 65544,

gpPaymentMint = 65545,

gpPaymentBurn = 65546,

gpMPTokenIssuanceLock = 65547,

gpMPTokenIssuanceUnlock = 65548,
};

/** Manages the list of known granular permission formats.
*/
class GranularPermissionFormats
: public KnownFormats<GranularPermissionType, GranularPermissionFormats>
{
private:
/** Create the object.
This will load the object with all the known granular permission
formats.
*/
GranularPermissionFormats();

public:
static GranularPermissionFormats const&
getInstance();
};

} // namespace ripple

#endif
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ XRPL_FIX (1513, Supported::yes, VoteBehavior::DefaultYe
XRPL_FEATURE(FlowCross, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FEATURE(Flow, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FEATURE(OwnerPaysFee, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(AccountPermission, Supported::yes, VoteBehavior::DefaultYes)

// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down
14 changes: 14 additions & 0 deletions include/xrpl/protocol/detail/ledger_entries.macro
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ LEDGER_ENTRY(ltSIGNER_LIST, 0x0053, SignerList, ({
{sfSignerEntries, soeREQUIRED},
{sfSignerListID, soeREQUIRED},
{sfPreviousTxnID, soeREQUIRED},

{sfPreviousTxnLgrSeq, soeREQUIRED},
}))

Expand Down Expand Up @@ -392,3 +393,16 @@ LEDGER_ENTRY(ltORACLE, 0x0080, Oracle, ({
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED},
}))

/** A ledger object representing permissions an account has delegated to another account.

\sa keylet::accountPermission
*/
LEDGER_ENTRY(ltACCOUNT_PERMISSION, 0x0081, AccountPermission, ({
{sfAccount, soeREQUIRED},
{sfAuthorize, soeREQUIRED},
{sfPermissions, soeREQUIRED},
{sfOwnerNode, soeREQUIRED},
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED},
}))
4 changes: 4 additions & 0 deletions include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TYPED_SFIELD(sfSignerWeight, UINT16, 3)
TYPED_SFIELD(sfTransferFee, UINT16, 4)
TYPED_SFIELD(sfTradingFee, UINT16, 5)
TYPED_SFIELD(sfDiscountedFee, UINT16, 6)
TYPED_SFIELD(sfPermissionValue, UINT16, 7)

// 16-bit integers (uncommon)
TYPED_SFIELD(sfVersion, UINT16, 16)
Expand Down Expand Up @@ -111,6 +112,7 @@ TYPED_SFIELD(sfEmitGeneration, UINT32, 46)
TYPED_SFIELD(sfVoteWeight, UINT32, 48)
TYPED_SFIELD(sfFirstNFTokenSequence, UINT32, 50)
TYPED_SFIELD(sfOracleDocumentID, UINT32, 51)
TYPED_SFIELD(sfGranularPermission, UINT32, 52)

// 64-bit integers (common)
TYPED_SFIELD(sfIndexNext, UINT64, 1)
Expand Down Expand Up @@ -309,6 +311,7 @@ UNTYPED_SFIELD(sfSignerEntry, OBJECT, 11)
UNTYPED_SFIELD(sfNFToken, OBJECT, 12)
UNTYPED_SFIELD(sfEmitDetails, OBJECT, 13)
UNTYPED_SFIELD(sfHook, OBJECT, 14)
UNTYPED_SFIELD(sfPermission, OBJECT, 15)

// inner object (uncommon)
UNTYPED_SFIELD(sfSigner, OBJECT, 16)
Expand Down Expand Up @@ -355,3 +358,4 @@ UNTYPED_SFIELD(sfXChainCreateAccountAttestations, ARRAY, 22)
// 23 unused
UNTYPED_SFIELD(sfPriceDataSeries, ARRAY, 24)
UNTYPED_SFIELD(sfAuthAccounts, ARRAY, 25)
UNTYPED_SFIELD(sfPermissions, ARRAY, 26)
6 changes: 6 additions & 0 deletions include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ TRANSACTION(ttLEDGER_STATE_FIX, 53, LedgerStateFix, ({
{sfOwner, soeOPTIONAL},
}))

/** This transaction type delegates authorized account specified permissions */
TRANSACTION(ttACCOUNT_PERMISSION_SET, 54, AccountPermissionSet, ({
{sfAuthorize, soeREQUIRED},
{sfPermissions, soeREQUIRED},
}))

/** 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
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,7 @@ namespace jss {
JSS(AL_size); // out: GetCounts
JSS(AL_hit_rate); // out: GetCounts
JSS(Account); // in: TransactionSign; field.
JSS(AccountPermission); // ledger type.
JSS(AccountRoot); // ledger type.
JSS(AMM); // ledger type
JSS(AMMID); // field
Expand Down Expand Up @@ -126,6 +127,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 Expand Up @@ -718,6 +720,7 @@ JSS(write_load); // out: GetCounts
JSS(xchain_owned_claim_id); // in: LedgerEntry, AccountObjects
JSS(xchain_owned_create_account_claim_id); // in: LedgerEntry
JSS(NegativeUNL); // out: ValidatorList; ledger type
JSS(TrustlineAuthorize);
// clang-format on

#pragma push_macro("TRANSACTION")
Expand Down
18 changes: 18 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,23 @@ 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
accountPermission(uint256 const& key) noexcept
{
return {ltACCOUNT_PERMISSION, key};
}

Keylet
bridge(STXChainBridge const& bridge, STXChainBridge::ChainType chainType)
{
Expand Down
40 changes: 40 additions & 0 deletions src/libxrpl/protocol/PermissionFormats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
/*
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 <xrpl/protocol/PermissionFormats.h>

#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/SOTemplate.h>
#include <xrpl/protocol/jss.h>

namespace ripple {

GranularPermissionFormats::GranularPermissionFormats()
{
add(jss::TrustlineAuthorize, gpTrustlineAuthorize, {});
}

GranularPermissionFormats const&
GranularPermissionFormats::getInstance()
{
static GranularPermissionFormats const instance;
return instance;
}

} // namespace ripple
Loading

0 comments on commit ef14541

Please sign in to comment.