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/ledger/helpers/SponsorHelpers.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/SField.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_.getApplyViewContext(),
105 {.ownerCountDelta = 1},
112 sle->setAccountID(sfAuthorize, authAccount);
114 sle->setFieldArray(sfPermissions, permissions);
117 auto const page =
ctx_.view().dirInsert(
123 (*sle)[sfOwnerNode] = *page;
127 auto const destPage =
ctx_.view().dirInsert(
133 (*sle)[sfDestinationNode] = *destPage;
135 ctx_.view().insert(sle);
148 auto const delegator = (*sle)[sfAccount];
149 auto const delegatee = (*sle)[sfAuthorize];
155 JLOG(j.
fatal()) <<
"Unable to delete Delegate from owner.";
161 if (
auto const optPage = (*sle)[~sfDestinationNode])
166 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.
void decreaseOwnerCountForObject(ApplyView &view, SLE::ref accountSle, SLE::ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
void increaseOwnerCount(ApplyView &view, SLE::ref accountSle, SLE::ref sponsorSle, std::uint32_t count, beast::Journal j)
Increase owner-count fields when the caller supplies the sponsor.
constexpr std::size_t kPermissionMaxSize
The maximum number of delegate permissions an account can grant.
void addSponsorToLedgerEntry(SLE::ref sle, SLE::const_ref sponsorSle, SF_ACCOUNT const &field=sfSponsor)
Stamp a reserve sponsor onto a ledger entry using an explicit sponsor SLE.
TERSubset< CanCvtToNotTEC > NotTEC
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
TER checkReserve(ApplyViewContext ctx, SLE::const_ref accSle, XRPAmount accBalance, SLE::const_ref sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
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.