20#include <xrpld/app/misc/DelegateUtils.h>
21#include <xrpld/app/tx/detail/SetAccount.h>
22#include <xrpld/core/Config.h>
24#include <xrpl/basics/Log.h>
25#include <xrpl/ledger/View.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/PublicKey.h>
29#include <xrpl/protocol/Quality.h>
30#include <xrpl/protocol/st.h>
39 auto getTxConsequencesCategory = [](
STTx const& tx) {
44 if (
auto const uSetFlag = tx[~sfSetFlag]; uSetFlag &&
49 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
77 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
79 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
86 bool bSetRequireAuth =
88 bool bClearRequireAuth =
91 if (bSetRequireAuth && bClearRequireAuth)
93 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
100 bool bSetRequireDest =
102 bool bClearRequireDest =
105 if (bSetRequireDest && bClearRequireDest)
107 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
114 bool bSetDisallowXRP =
116 bool bClearDisallowXRP =
119 if (bSetDisallowXRP && bClearDisallowXRP)
121 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
126 if (tx.isFieldPresent(sfTransferRate))
130 if (uRate && (uRate < QUALITY_ONE))
133 <<
"Malformed transaction: Transfer rate too small.";
137 if (uRate > 2 * QUALITY_ONE)
140 <<
"Malformed transaction: Transfer rate too large.";
146 if (tx.isFieldPresent(sfTickSize))
148 auto uTickSize = tx[sfTickSize];
150 ((uTickSize < Quality::minTickSize) ||
151 (uTickSize > Quality::maxTickSize)))
153 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
158 if (
auto const mk = tx[~sfMessageKey])
162 JLOG(j.trace()) <<
"Invalid message key specified.";
167 if (
auto const domain = tx[~sfDomain];
170 JLOG(j.trace()) <<
"domain too long";
178 !tx.isFieldPresent(sfNFTokenMinter))
182 tx.isFieldPresent(sfNFTokenMinter))
194 auto const delegate = tx[~sfDelegate];
199 auto const sle =
view.
read(delegateKey);
208 auto const uClearFlag = tx.
getFieldU32(sfClearFlag);
209 auto const uTxFlags = tx.
getFlags();
218 !granularPermissions.
contains(AccountEmailHashSet))
226 !granularPermissions.
contains(AccountMessageKeySet))
230 !granularPermissions.
contains(AccountDomainSet))
234 !granularPermissions.
contains(AccountTransferRateSet))
238 !granularPermissions.
contains(AccountTickSizeSet))
247 auto const id = ctx.
tx[sfAccount];
260 bool bSetRequireAuth =
270 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
284 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
290 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
300 <<
"Can't set NoFreeze if clawback is enabled";
325 bool const bSetRequireDest{
327 bool const bClearRequireDest{
329 bool const bSetRequireAuth{
331 bool const bClearRequireAuth{
333 bool const bSetDisallowXRP{
335 bool const bClearDisallowXRP{
338 bool const sigWithMaster{[&tx, &acct =
account_]() {
339 auto const spk = tx.getSigningPubKey();
356 JLOG(
j_.
trace()) <<
"Set RequireAuth.";
362 JLOG(
j_.
trace()) <<
"Clear RequireAuth.";
363 uFlagsOut &= ~lsfRequireAuth;
371 JLOG(
j_.
trace()) <<
"Set lsfRequireDestTag.";
377 JLOG(
j_.
trace()) <<
"Clear lsfRequireDestTag.";
378 uFlagsOut &= ~lsfRequireDestTag;
386 JLOG(
j_.
trace()) <<
"Set lsfDisallowXRP.";
392 JLOG(
j_.
trace()) <<
"Clear lsfDisallowXRP.";
393 uFlagsOut &= ~lsfDisallowXRP;
403 JLOG(
j_.
trace()) <<
"Must use master key to disable master key.";
407 if ((!sle->isFieldPresent(sfRegularKey)) &&
414 JLOG(
j_.
trace()) <<
"Set lsfDisableMaster.";
420 JLOG(
j_.
trace()) <<
"Clear lsfDisableMaster.";
421 uFlagsOut &= ~lsfDisableMaster;
429 JLOG(
j_.
trace()) <<
"Set lsfDefaultRipple.";
434 JLOG(
j_.
trace()) <<
"Clear lsfDefaultRipple.";
435 uFlagsOut &= ~lsfDefaultRipple;
445 JLOG(
j_.
trace()) <<
"Must use master key to set NoFreeze.";
449 JLOG(
j_.
trace()) <<
"Set NoFreeze flag";
456 JLOG(
j_.
trace()) <<
"Set GlobalFreeze flag";
466 JLOG(
j_.
trace()) <<
"Clear GlobalFreeze flag";
467 uFlagsOut &= ~lsfGlobalFreeze;
473 if ((uSetFlag ==
asfAccountTxnID) && !sle->isFieldPresent(sfAccountTxnID))
475 JLOG(
j_.
trace()) <<
"Set AccountTxnID.";
476 sle->makeFieldPresent(sfAccountTxnID);
479 if ((uClearFlag ==
asfAccountTxnID) && sle->isFieldPresent(sfAccountTxnID))
481 JLOG(
j_.
trace()) <<
"Clear AccountTxnID.";
482 sle->makeFieldAbsent(sfAccountTxnID);
488 if (
view().rules().enabled(featureDepositAuth))
492 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
497 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
498 uFlagsOut &= ~lsfDepositAuth;
505 if (tx.isFieldPresent(sfEmailHash))
507 uint128 const uHash = tx.getFieldH128(sfEmailHash);
511 JLOG(
j_.
trace()) <<
"unset email hash";
512 sle->makeFieldAbsent(sfEmailHash);
516 JLOG(
j_.
trace()) <<
"set email hash";
517 sle->setFieldH128(sfEmailHash, uHash);
524 if (tx.isFieldPresent(sfWalletLocator))
526 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
530 JLOG(
j_.
trace()) <<
"unset wallet locator";
531 sle->makeFieldAbsent(sfWalletLocator);
535 JLOG(
j_.
trace()) <<
"set wallet locator";
536 sle->setFieldH256(sfWalletLocator, uHash);
543 if (tx.isFieldPresent(sfMessageKey))
545 Blob const messageKey = tx.getFieldVL(sfMessageKey);
547 if (messageKey.
empty())
549 JLOG(
j_.
debug()) <<
"set message key";
550 sle->makeFieldAbsent(sfMessageKey);
554 JLOG(
j_.
debug()) <<
"set message key";
555 sle->setFieldVL(sfMessageKey, messageKey);
562 if (tx.isFieldPresent(sfDomain))
564 Blob const domain = tx.getFieldVL(sfDomain);
568 JLOG(
j_.
trace()) <<
"unset domain";
569 sle->makeFieldAbsent(sfDomain);
573 JLOG(
j_.
trace()) <<
"set domain";
574 sle->setFieldVL(sfDomain, domain);
581 if (tx.isFieldPresent(sfTransferRate))
585 if (uRate == 0 || uRate == QUALITY_ONE)
587 JLOG(
j_.
trace()) <<
"unset transfer rate";
588 sle->makeFieldAbsent(sfTransferRate);
592 JLOG(
j_.
trace()) <<
"set transfer rate";
593 sle->setFieldU32(sfTransferRate, uRate);
600 if (tx.isFieldPresent(sfTickSize))
602 auto uTickSize = tx[sfTickSize];
603 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
605 JLOG(
j_.
trace()) <<
"unset tick size";
606 sle->makeFieldAbsent(sfTickSize);
610 JLOG(
j_.
trace()) <<
"set tick size";
611 sle->setFieldU8(sfTickSize, uTickSize);
619 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
622 sle->isFieldPresent(sfNFTokenMinter))
623 sle->makeFieldAbsent(sfNFTokenMinter);
632 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
637 uFlagsOut &= ~lsfDisallowIncomingCheck;
642 uFlagsOut &= ~lsfDisallowIncomingPayChan;
647 uFlagsOut &= ~lsfDisallowIncomingTrustline;
656 uFlagsOut &= ~lsfAllowTrustLineLocking;
663 JLOG(
j_.
trace()) <<
"set allow clawback";
667 if (uFlagsIn != uFlagsOut)
668 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 TER 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
@ tecNO_DELEGATE_PERMISSION
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
constexpr std::uint32_t asfDisallowXRP
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.