1#include <xrpl/tx/transactors/delegate/DelegateSet.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/DirectoryHelpers.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Protocol.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/XRPAmount.h>
16#include <xrpl/tx/Transactor.h>
32 if (ctx.
tx[sfAccount] == ctx.
tx[sfAuthorize])
37 for (
auto const& permission : permissions)
39 if (!permissionSet.
insert(permission[sfPermissionValue]).second)
79 auto const& authAccount =
ctx_.tx[sfAuthorize];
82 auto sle =
ctx_.view().peek(delegateKey);
85 auto const& permissions =
ctx_.tx.getFieldArray(sfPermissions);
86 if (permissions.empty())
92 sle->setFieldArray(sfPermissions, permissions);
93 ctx_.view().update(sle);
97 auto const& permissions =
ctx_.tx.getFieldArray(sfPermissions);
98 if (permissions.empty())
102 ctx_.view().fees().accountReserve(sleOwner->getFieldU32(sfOwnerCount) + 1)};
109 sle->setAccountID(sfAuthorize, authAccount);
111 sle->setFieldArray(sfPermissions, permissions);
114 auto const page =
ctx_.view().dirInsert(
120 (*sle)[sfOwnerNode] = *page;
124 auto const destPage =
ctx_.view().dirInsert(
130 (*sle)[sfDestinationNode] = *destPage;
132 ctx_.view().insert(sle);
144 auto const delegator = (*sle)[sfAccount];
145 auto const delegatee = (*sle)[sfAuthorize];
151 JLOG(j.
fatal()) <<
"Unable to delete Delegate from owner.";
157 if (
auto const optPage = (*sle)[~sfDestinationNode])
162 JLOG(j.
fatal()) <<
"Unable to delete Delegate from authorized account.";
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
static TER deleteDelegate(ApplyView &view, SLE::ref sle, beast::Journal j)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TER preclaim(PreclaimContext const &ctx)
static Permission const & getInstance()
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const & const_ref
STArray const & getFieldArray(SField const &field) const
AccountID const accountID_
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t kPermissionMaxSize
The maximum number of delegate permissions an account can grant.
TERSubset< CanCvtToNotTEC > NotTEC
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
bool isPseudoAccount(SLE::const_pointer sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Returns true if and only if sleAcct is a pseudo-account or specific pseudo-accounts in pseudoFieldFil...
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.