20#include <xrpld/app/tx/detail/SetAccount.h>
21#include <xrpld/core/Config.h>
22#include <xrpld/ledger/View.h>
23#include <xrpl/basics/Log.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/Indexes.h>
26#include <xrpl/protocol/PublicKey.h>
27#include <xrpl/protocol/Quality.h>
28#include <xrpl/protocol/st.h>
37 auto getTxConsequencesCategory = [](
STTx const& tx) {
42 if (
auto const uSetFlag = tx[~sfSetFlag]; uSetFlag &&
47 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
71 JLOG(j.trace()) <<
"Malformed transaction: Invalid flags set.";
78 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
80 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
87 bool bSetRequireAuth =
89 bool bClearRequireAuth =
92 if (bSetRequireAuth && bClearRequireAuth)
94 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
101 bool bSetRequireDest =
103 bool bClearRequireDest =
106 if (bSetRequireDest && bClearRequireDest)
108 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
115 bool bSetDisallowXRP =
117 bool bClearDisallowXRP =
120 if (bSetDisallowXRP && bClearDisallowXRP)
122 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
127 if (tx.isFieldPresent(sfTransferRate))
131 if (uRate && (uRate < QUALITY_ONE))
134 <<
"Malformed transaction: Transfer rate too small.";
138 if (uRate > 2 * QUALITY_ONE)
141 <<
"Malformed transaction: Transfer rate too large.";
147 if (tx.isFieldPresent(sfTickSize))
149 auto uTickSize = tx[sfTickSize];
151 ((uTickSize < Quality::minTickSize) ||
152 (uTickSize > Quality::maxTickSize)))
154 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
159 if (
auto const mk = tx[~sfMessageKey])
163 JLOG(j.trace()) <<
"Invalid message key specified.";
168 if (
auto const domain = tx[~sfDomain];
171 JLOG(j.trace()) <<
"domain too long";
179 !tx.isFieldPresent(sfNFTokenMinter))
183 tx.isFieldPresent(sfNFTokenMinter))
193 auto const id = ctx.
tx[sfAccount];
206 bool bSetRequireAuth =
216 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
230 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
236 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
246 <<
"Can't set NoFreeze if clawback is enabled";
271 bool const bSetRequireDest{
273 bool const bClearRequireDest{
275 bool const bSetRequireAuth{
277 bool const bClearRequireAuth{
279 bool const bSetDisallowXRP{
281 bool const bClearDisallowXRP{
284 bool const sigWithMaster{[&tx, &acct =
account_]() {
285 auto const spk = tx.getSigningPubKey();
302 JLOG(
j_.
trace()) <<
"Set RequireAuth.";
308 JLOG(
j_.
trace()) <<
"Clear RequireAuth.";
309 uFlagsOut &= ~lsfRequireAuth;
317 JLOG(
j_.
trace()) <<
"Set lsfRequireDestTag.";
323 JLOG(
j_.
trace()) <<
"Clear lsfRequireDestTag.";
324 uFlagsOut &= ~lsfRequireDestTag;
332 JLOG(
j_.
trace()) <<
"Set lsfDisallowXRP.";
338 JLOG(
j_.
trace()) <<
"Clear lsfDisallowXRP.";
339 uFlagsOut &= ~lsfDisallowXRP;
349 JLOG(
j_.
trace()) <<
"Must use master key to disable master key.";
353 if ((!sle->isFieldPresent(sfRegularKey)) &&
360 JLOG(
j_.
trace()) <<
"Set lsfDisableMaster.";
366 JLOG(
j_.
trace()) <<
"Clear lsfDisableMaster.";
367 uFlagsOut &= ~lsfDisableMaster;
375 JLOG(
j_.
trace()) <<
"Set lsfDefaultRipple.";
380 JLOG(
j_.
trace()) <<
"Clear lsfDefaultRipple.";
381 uFlagsOut &= ~lsfDefaultRipple;
391 JLOG(
j_.
trace()) <<
"Must use master key to set NoFreeze.";
395 JLOG(
j_.
trace()) <<
"Set NoFreeze flag";
402 JLOG(
j_.
trace()) <<
"Set GlobalFreeze flag";
412 JLOG(
j_.
trace()) <<
"Clear GlobalFreeze flag";
413 uFlagsOut &= ~lsfGlobalFreeze;
419 if ((uSetFlag ==
asfAccountTxnID) && !sle->isFieldPresent(sfAccountTxnID))
421 JLOG(
j_.
trace()) <<
"Set AccountTxnID.";
422 sle->makeFieldPresent(sfAccountTxnID);
425 if ((uClearFlag ==
asfAccountTxnID) && sle->isFieldPresent(sfAccountTxnID))
427 JLOG(
j_.
trace()) <<
"Clear AccountTxnID.";
428 sle->makeFieldAbsent(sfAccountTxnID);
434 if (
view().rules().enabled(featureDepositAuth))
438 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
443 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
444 uFlagsOut &= ~lsfDepositAuth;
451 if (tx.isFieldPresent(sfEmailHash))
453 uint128 const uHash = tx.getFieldH128(sfEmailHash);
457 JLOG(
j_.
trace()) <<
"unset email hash";
458 sle->makeFieldAbsent(sfEmailHash);
462 JLOG(
j_.
trace()) <<
"set email hash";
463 sle->setFieldH128(sfEmailHash, uHash);
470 if (tx.isFieldPresent(sfWalletLocator))
472 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
476 JLOG(
j_.
trace()) <<
"unset wallet locator";
477 sle->makeFieldAbsent(sfWalletLocator);
481 JLOG(
j_.
trace()) <<
"set wallet locator";
482 sle->setFieldH256(sfWalletLocator, uHash);
489 if (tx.isFieldPresent(sfMessageKey))
491 Blob const messageKey = tx.getFieldVL(sfMessageKey);
493 if (messageKey.
empty())
495 JLOG(
j_.
debug()) <<
"set message key";
496 sle->makeFieldAbsent(sfMessageKey);
500 JLOG(
j_.
debug()) <<
"set message key";
501 sle->setFieldVL(sfMessageKey, messageKey);
508 if (tx.isFieldPresent(sfDomain))
510 Blob const domain = tx.getFieldVL(sfDomain);
514 JLOG(
j_.
trace()) <<
"unset domain";
515 sle->makeFieldAbsent(sfDomain);
519 JLOG(
j_.
trace()) <<
"set domain";
520 sle->setFieldVL(sfDomain, domain);
527 if (tx.isFieldPresent(sfTransferRate))
531 if (uRate == 0 || uRate == QUALITY_ONE)
533 JLOG(
j_.
trace()) <<
"unset transfer rate";
534 sle->makeFieldAbsent(sfTransferRate);
538 JLOG(
j_.
trace()) <<
"set transfer rate";
539 sle->setFieldU32(sfTransferRate, uRate);
546 if (tx.isFieldPresent(sfTickSize))
548 auto uTickSize = tx[sfTickSize];
549 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
551 JLOG(
j_.
trace()) <<
"unset tick size";
552 sle->makeFieldAbsent(sfTickSize);
556 JLOG(
j_.
trace()) <<
"set tick size";
557 sle->setFieldU8(sfTickSize, uTickSize);
565 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
568 sle->isFieldPresent(sfNFTokenMinter))
569 sle->makeFieldAbsent(sfNFTokenMinter);
578 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
583 uFlagsOut &= ~lsfDisallowIncomingCheck;
588 uFlagsOut &= ~lsfDisallowIncomingPayChan;
593 uFlagsOut &= ~lsfDisallowIncomingTrustline;
600 JLOG(
j_.
trace()) <<
"set allow clawback";
604 if (uFlagsIn != uFlagsOut)
605 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.