1#include <xrpld/app/misc/DelegateUtils.h>
2#include <xrpld/app/tx/detail/SetAccount.h>
3#include <xrpld/core/Config.h>
5#include <xrpl/basics/Log.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/Quality.h>
11#include <xrpl/protocol/st.h>
20 auto getTxConsequencesCategory = [](
STTx const& tx) {
25 if (
auto const uSetFlag = tx[~sfSetFlag]; uSetFlag &&
30 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
58 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
60 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
67 bool bSetRequireAuth =
69 bool bClearRequireAuth =
72 if (bSetRequireAuth && bClearRequireAuth)
74 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
81 bool bSetRequireDest =
83 bool bClearRequireDest =
86 if (bSetRequireDest && bClearRequireDest)
88 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
95 bool bSetDisallowXRP =
97 bool bClearDisallowXRP =
100 if (bSetDisallowXRP && bClearDisallowXRP)
102 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
107 if (tx.isFieldPresent(sfTransferRate))
111 if (uRate && (uRate < QUALITY_ONE))
114 <<
"Malformed transaction: Transfer rate too small.";
118 if (uRate > 2 * QUALITY_ONE)
121 <<
"Malformed transaction: Transfer rate too large.";
127 if (tx.isFieldPresent(sfTickSize))
129 auto uTickSize = tx[sfTickSize];
131 ((uTickSize < Quality::minTickSize) ||
132 (uTickSize > Quality::maxTickSize)))
134 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
139 if (
auto const mk = tx[~sfMessageKey])
143 JLOG(j.trace()) <<
"Invalid message key specified.";
148 if (
auto const domain = tx[~sfDomain];
151 JLOG(j.trace()) <<
"domain too long";
157 !tx.isFieldPresent(sfNFTokenMinter))
161 tx.isFieldPresent(sfNFTokenMinter))
172 auto const delegate = tx[~sfDelegate];
177 auto const sle =
view.
read(delegateKey);
186 auto const uClearFlag = tx.
getFieldU32(sfClearFlag);
187 auto const uTxFlags = tx.
getFlags();
196 !granularPermissions.
contains(AccountEmailHashSet))
204 !granularPermissions.
contains(AccountMessageKeySet))
208 !granularPermissions.
contains(AccountDomainSet))
212 !granularPermissions.
contains(AccountTransferRateSet))
216 !granularPermissions.
contains(AccountTickSizeSet))
225 auto const id = ctx.
tx[sfAccount];
238 bool bSetRequireAuth =
248 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
262 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
268 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
278 <<
"Can't set NoFreeze if clawback is enabled";
303 bool const bSetRequireDest{
305 bool const bClearRequireDest{
307 bool const bSetRequireAuth{
309 bool const bClearRequireAuth{
311 bool const bSetDisallowXRP{
313 bool const bClearDisallowXRP{
316 bool const sigWithMaster{[&tx, &acct =
account_]() {
317 auto const spk = tx.getSigningPubKey();
334 JLOG(
j_.
trace()) <<
"Set RequireAuth.";
340 JLOG(
j_.
trace()) <<
"Clear RequireAuth.";
341 uFlagsOut &= ~lsfRequireAuth;
349 JLOG(
j_.
trace()) <<
"Set lsfRequireDestTag.";
355 JLOG(
j_.
trace()) <<
"Clear lsfRequireDestTag.";
356 uFlagsOut &= ~lsfRequireDestTag;
364 JLOG(
j_.
trace()) <<
"Set lsfDisallowXRP.";
370 JLOG(
j_.
trace()) <<
"Clear lsfDisallowXRP.";
371 uFlagsOut &= ~lsfDisallowXRP;
381 JLOG(
j_.
trace()) <<
"Must use master key to disable master key.";
385 if ((!sle->isFieldPresent(sfRegularKey)) &&
392 JLOG(
j_.
trace()) <<
"Set lsfDisableMaster.";
398 JLOG(
j_.
trace()) <<
"Clear lsfDisableMaster.";
399 uFlagsOut &= ~lsfDisableMaster;
407 JLOG(
j_.
trace()) <<
"Set lsfDefaultRipple.";
412 JLOG(
j_.
trace()) <<
"Clear lsfDefaultRipple.";
413 uFlagsOut &= ~lsfDefaultRipple;
423 JLOG(
j_.
trace()) <<
"Must use master key to set NoFreeze.";
427 JLOG(
j_.
trace()) <<
"Set NoFreeze flag";
434 JLOG(
j_.
trace()) <<
"Set GlobalFreeze flag";
444 JLOG(
j_.
trace()) <<
"Clear GlobalFreeze flag";
445 uFlagsOut &= ~lsfGlobalFreeze;
451 if ((uSetFlag ==
asfAccountTxnID) && !sle->isFieldPresent(sfAccountTxnID))
453 JLOG(
j_.
trace()) <<
"Set AccountTxnID.";
454 sle->makeFieldPresent(sfAccountTxnID);
457 if ((uClearFlag ==
asfAccountTxnID) && sle->isFieldPresent(sfAccountTxnID))
459 JLOG(
j_.
trace()) <<
"Clear AccountTxnID.";
460 sle->makeFieldAbsent(sfAccountTxnID);
466 if (
view().rules().enabled(featureDepositAuth))
470 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
475 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
476 uFlagsOut &= ~lsfDepositAuth;
483 if (tx.isFieldPresent(sfEmailHash))
485 uint128 const uHash = tx.getFieldH128(sfEmailHash);
489 JLOG(
j_.
trace()) <<
"unset email hash";
490 sle->makeFieldAbsent(sfEmailHash);
494 JLOG(
j_.
trace()) <<
"set email hash";
495 sle->setFieldH128(sfEmailHash, uHash);
502 if (tx.isFieldPresent(sfWalletLocator))
504 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
508 JLOG(
j_.
trace()) <<
"unset wallet locator";
509 sle->makeFieldAbsent(sfWalletLocator);
513 JLOG(
j_.
trace()) <<
"set wallet locator";
514 sle->setFieldH256(sfWalletLocator, uHash);
521 if (tx.isFieldPresent(sfMessageKey))
523 Blob const messageKey = tx.getFieldVL(sfMessageKey);
525 if (messageKey.
empty())
527 JLOG(
j_.
debug()) <<
"set message key";
528 sle->makeFieldAbsent(sfMessageKey);
532 JLOG(
j_.
debug()) <<
"set message key";
533 sle->setFieldVL(sfMessageKey, messageKey);
540 if (tx.isFieldPresent(sfDomain))
542 Blob const domain = tx.getFieldVL(sfDomain);
546 JLOG(
j_.
trace()) <<
"unset domain";
547 sle->makeFieldAbsent(sfDomain);
551 JLOG(
j_.
trace()) <<
"set domain";
552 sle->setFieldVL(sfDomain, domain);
559 if (tx.isFieldPresent(sfTransferRate))
563 if (uRate == 0 || uRate == QUALITY_ONE)
565 JLOG(
j_.
trace()) <<
"unset transfer rate";
566 sle->makeFieldAbsent(sfTransferRate);
570 JLOG(
j_.
trace()) <<
"set transfer rate";
571 sle->setFieldU32(sfTransferRate, uRate);
578 if (tx.isFieldPresent(sfTickSize))
580 auto uTickSize = tx[sfTickSize];
581 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
583 JLOG(
j_.
trace()) <<
"unset tick size";
584 sle->makeFieldAbsent(sfTickSize);
588 JLOG(
j_.
trace()) <<
"set tick size";
589 sle->setFieldU8(sfTickSize, uTickSize);
595 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
598 sle->isFieldPresent(sfNFTokenMinter))
599 sle->makeFieldAbsent(sfNFTokenMinter);
607 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
612 uFlagsOut &= ~lsfDisallowIncomingCheck;
617 uFlagsOut &= ~lsfDisallowIncomingPayChan;
622 uFlagsOut &= ~lsfDisallowIncomingTrustline;
631 uFlagsOut &= ~lsfAllowTrustLineLocking;
638 JLOG(
j_.
trace()) <<
"set allow clawback";
642 if (uFlagsIn != uFlagsOut)
643 sle->setFieldU32(sfFlags, uFlagsOut);
Stream trace() const
Severity stream access functions.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::uint32_t getFieldU32(SField const &field) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
static NotTEC checkPermission(ReadView const &view, STTx const &tx)
static TER preclaim(PreclaimContext const &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
Class describing the consequences to the account of applying a transaction if the transaction consume...
@ normal
Moves currency around, creates offers, etc.
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Integers of any length that is a multiple of 32-bits.
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t tfAllowXRP
constexpr std::uint32_t asfGlobalFreeze
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t asfDisallowIncomingNFTokenOffer
constexpr std::uint32_t asfAllowTrustLineLocking
constexpr std::uint32_t asfRequireDest
constexpr std::uint32_t asfAuthorizedNFTokenMinter
constexpr std::uint32_t tfOptionalDestTag
@ lsfDisallowIncomingCheck
@ lsfAllowTrustLineClawback
@ lsfDisallowIncomingPayChan
@ lsfDisallowIncomingTrustline
@ lsfAllowTrustLineLocking
@ lsfDisallowIncomingNFTokenOffer
constexpr std::uint32_t tfAccountSetMask
constexpr std::uint32_t tfRequireDestTag
constexpr std::uint32_t asfNoFreeze
AccountID calcAccountID(PublicKey const &pk)
std::size_t constexpr maxDomainLength
The maximum length of a domain.
constexpr std::uint32_t asfDisableMaster
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
constexpr std::uint32_t asfDisallowIncomingTrustline
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
void loadGranularPermission(std::shared_ptr< SLE const > const &delegate, TxType const &type, std::unordered_set< GranularPermissionType > &granularPermissions)
Load the granular permissions granted to the delegate account for the specified transaction type.
constexpr std::uint32_t asfAccountTxnID
constexpr std::uint32_t asfDefaultRipple
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
constexpr std::uint32_t asfDisallowIncomingCheck
constexpr std::uint32_t tfRequireAuth
constexpr std::uint32_t tfOptionalAuth
constexpr std::uint32_t tfDisallowXRP
constexpr std::uint32_t asfDisallowIncomingPayChan
constexpr std::uint32_t tfUniversalMask
constexpr std::uint32_t asfAllowTrustLineClawback
constexpr std::uint32_t asfRequireAuth
@ terNO_DELEGATE_PERMISSION
constexpr std::uint32_t asfDisallowXRP
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.