20#include <xrpld/app/tx/detail/SetAccount.h>
21#include <xrpld/core/Config.h>
22#include <xrpld/ledger/View.h>
24#include <xrpl/basics/Log.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/PublicKey.h>
28#include <xrpl/protocol/Quality.h>
29#include <xrpl/protocol/st.h>
38 auto getTxConsequencesCategory = [](
STTx const& tx) {
43 if (
auto const uSetFlag = tx[~sfSetFlag]; uSetFlag &&
48 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
72 JLOG(j.trace()) <<
"Malformed transaction: Invalid flags set.";
79 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
81 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
88 bool bSetRequireAuth =
90 bool bClearRequireAuth =
93 if (bSetRequireAuth && bClearRequireAuth)
95 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
102 bool bSetRequireDest =
104 bool bClearRequireDest =
107 if (bSetRequireDest && bClearRequireDest)
109 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
116 bool bSetDisallowXRP =
118 bool bClearDisallowXRP =
121 if (bSetDisallowXRP && bClearDisallowXRP)
123 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
128 if (tx.isFieldPresent(sfTransferRate))
132 if (uRate && (uRate < QUALITY_ONE))
135 <<
"Malformed transaction: Transfer rate too small.";
139 if (uRate > 2 * QUALITY_ONE)
142 <<
"Malformed transaction: Transfer rate too large.";
148 if (tx.isFieldPresent(sfTickSize))
150 auto uTickSize = tx[sfTickSize];
152 ((uTickSize < Quality::minTickSize) ||
153 (uTickSize > Quality::maxTickSize)))
155 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
160 if (
auto const mk = tx[~sfMessageKey])
164 JLOG(j.trace()) <<
"Invalid message key specified.";
169 if (
auto const domain = tx[~sfDomain];
172 JLOG(j.trace()) <<
"domain too long";
180 !tx.isFieldPresent(sfNFTokenMinter))
184 tx.isFieldPresent(sfNFTokenMinter))
194 auto const id = ctx.
tx[sfAccount];
207 bool bSetRequireAuth =
217 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
231 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
237 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
247 <<
"Can't set NoFreeze if clawback is enabled";
272 bool const bSetRequireDest{
274 bool const bClearRequireDest{
276 bool const bSetRequireAuth{
278 bool const bClearRequireAuth{
280 bool const bSetDisallowXRP{
282 bool const bClearDisallowXRP{
285 bool const sigWithMaster{[&tx, &acct =
account_]() {
286 auto const spk = tx.getSigningPubKey();
303 JLOG(
j_.
trace()) <<
"Set RequireAuth.";
309 JLOG(
j_.
trace()) <<
"Clear RequireAuth.";
310 uFlagsOut &= ~lsfRequireAuth;
318 JLOG(
j_.
trace()) <<
"Set lsfRequireDestTag.";
324 JLOG(
j_.
trace()) <<
"Clear lsfRequireDestTag.";
325 uFlagsOut &= ~lsfRequireDestTag;
333 JLOG(
j_.
trace()) <<
"Set lsfDisallowXRP.";
339 JLOG(
j_.
trace()) <<
"Clear lsfDisallowXRP.";
340 uFlagsOut &= ~lsfDisallowXRP;
350 JLOG(
j_.
trace()) <<
"Must use master key to disable master key.";
354 if ((!sle->isFieldPresent(sfRegularKey)) &&
361 JLOG(
j_.
trace()) <<
"Set lsfDisableMaster.";
367 JLOG(
j_.
trace()) <<
"Clear lsfDisableMaster.";
368 uFlagsOut &= ~lsfDisableMaster;
376 JLOG(
j_.
trace()) <<
"Set lsfDefaultRipple.";
381 JLOG(
j_.
trace()) <<
"Clear lsfDefaultRipple.";
382 uFlagsOut &= ~lsfDefaultRipple;
392 JLOG(
j_.
trace()) <<
"Must use master key to set NoFreeze.";
396 JLOG(
j_.
trace()) <<
"Set NoFreeze flag";
403 JLOG(
j_.
trace()) <<
"Set GlobalFreeze flag";
413 JLOG(
j_.
trace()) <<
"Clear GlobalFreeze flag";
414 uFlagsOut &= ~lsfGlobalFreeze;
420 if ((uSetFlag ==
asfAccountTxnID) && !sle->isFieldPresent(sfAccountTxnID))
422 JLOG(
j_.
trace()) <<
"Set AccountTxnID.";
423 sle->makeFieldPresent(sfAccountTxnID);
426 if ((uClearFlag ==
asfAccountTxnID) && sle->isFieldPresent(sfAccountTxnID))
428 JLOG(
j_.
trace()) <<
"Clear AccountTxnID.";
429 sle->makeFieldAbsent(sfAccountTxnID);
435 if (
view().rules().enabled(featureDepositAuth))
439 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
444 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
445 uFlagsOut &= ~lsfDepositAuth;
452 if (tx.isFieldPresent(sfEmailHash))
454 uint128 const uHash = tx.getFieldH128(sfEmailHash);
458 JLOG(
j_.
trace()) <<
"unset email hash";
459 sle->makeFieldAbsent(sfEmailHash);
463 JLOG(
j_.
trace()) <<
"set email hash";
464 sle->setFieldH128(sfEmailHash, uHash);
471 if (tx.isFieldPresent(sfWalletLocator))
473 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
477 JLOG(
j_.
trace()) <<
"unset wallet locator";
478 sle->makeFieldAbsent(sfWalletLocator);
482 JLOG(
j_.
trace()) <<
"set wallet locator";
483 sle->setFieldH256(sfWalletLocator, uHash);
490 if (tx.isFieldPresent(sfMessageKey))
492 Blob const messageKey = tx.getFieldVL(sfMessageKey);
494 if (messageKey.
empty())
496 JLOG(
j_.
debug()) <<
"set message key";
497 sle->makeFieldAbsent(sfMessageKey);
501 JLOG(
j_.
debug()) <<
"set message key";
502 sle->setFieldVL(sfMessageKey, messageKey);
509 if (tx.isFieldPresent(sfDomain))
511 Blob const domain = tx.getFieldVL(sfDomain);
515 JLOG(
j_.
trace()) <<
"unset domain";
516 sle->makeFieldAbsent(sfDomain);
520 JLOG(
j_.
trace()) <<
"set domain";
521 sle->setFieldVL(sfDomain, domain);
528 if (tx.isFieldPresent(sfTransferRate))
532 if (uRate == 0 || uRate == QUALITY_ONE)
534 JLOG(
j_.
trace()) <<
"unset transfer rate";
535 sle->makeFieldAbsent(sfTransferRate);
539 JLOG(
j_.
trace()) <<
"set transfer rate";
540 sle->setFieldU32(sfTransferRate, uRate);
547 if (tx.isFieldPresent(sfTickSize))
549 auto uTickSize = tx[sfTickSize];
550 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
552 JLOG(
j_.
trace()) <<
"unset tick size";
553 sle->makeFieldAbsent(sfTickSize);
557 JLOG(
j_.
trace()) <<
"set tick size";
558 sle->setFieldU8(sfTickSize, uTickSize);
566 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
569 sle->isFieldPresent(sfNFTokenMinter))
570 sle->makeFieldAbsent(sfNFTokenMinter);
579 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
584 uFlagsOut &= ~lsfDisallowIncomingCheck;
589 uFlagsOut &= ~lsfDisallowIncomingPayChan;
594 uFlagsOut &= ~lsfDisallowIncomingTrustline;
601 JLOG(
j_.
trace()) <<
"set allow clawback";
605 if (uFlagsIn != uFlagsOut)
606 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
std::uint32_t getFlags() const
static TER preclaim(PreclaimContext const &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static NotTEC preflight(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 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 asfRequireDest
constexpr std::uint32_t asfAuthorizedNFTokenMinter
constexpr std::uint32_t tfOptionalDestTag
@ lsfDisallowIncomingCheck
@ lsfAllowTrustLineClawback
@ lsfDisallowIncomingPayChan
@ lsfDisallowIncomingTrustline
@ lsfDisallowIncomingNFTokenOffer
constexpr std::uint32_t tfAccountSetMask
constexpr std::uint32_t tfRequireDestTag
constexpr std::uint32_t asfNoFreeze
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
AccountID calcAccountID(PublicKey const &pk)
std::size_t constexpr maxDomainLength
The maximum length of a domain.
constexpr std::uint32_t asfDisableMaster
constexpr std::uint32_t asfDisallowIncomingTrustline
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
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 asfAllowTrustLineClawback
constexpr std::uint32_t asfRequireAuth
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
constexpr std::uint32_t asfDisallowXRP
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.