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) {
24 if (
auto const uSetFlag = tx[~sfSetFlag];
28 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
55 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
57 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
67 if (bSetRequireAuth && bClearRequireAuth)
69 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
79 if (bSetRequireDest && bClearRequireDest)
81 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
91 if (bSetDisallowXRP && bClearDisallowXRP)
93 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
98 if (tx.isFieldPresent(sfTransferRate))
102 if (uRate && (uRate < QUALITY_ONE))
104 JLOG(j.trace()) <<
"Malformed transaction: Transfer rate too small.";
108 if (uRate > 2 * QUALITY_ONE)
110 JLOG(j.trace()) <<
"Malformed transaction: Transfer rate too large.";
116 if (tx.isFieldPresent(sfTickSize))
118 auto uTickSize = tx[sfTickSize];
119 if (uTickSize && ((uTickSize < Quality::minTickSize) || (uTickSize > Quality::maxTickSize)))
121 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
126 if (
auto const mk = tx[~sfMessageKey])
130 JLOG(j.trace()) <<
"Invalid message key specified.";
135 if (
auto const domain = tx[~sfDomain]; domain && domain->size() >
maxDomainLength)
137 JLOG(j.trace()) <<
"domain too long";
156 auto const delegate = tx[~sfDelegate];
161 auto const sle =
view.
read(delegateKey);
170 auto const uClearFlag = tx.
getFieldU32(sfClearFlag);
171 auto const uTxFlags = tx.
getFlags();
203 auto const id = ctx.
tx[sfAccount];
225 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
239 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
245 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
254 JLOG(ctx.
j.
trace()) <<
"Can't set NoFreeze if clawback is enabled";
286 bool const sigWithMaster{[&tx, &acct =
account_]() {
287 auto const spk = tx.getSigningPubKey();
304 JLOG(
j_.
trace()) <<
"Set RequireAuth.";
310 JLOG(
j_.
trace()) <<
"Clear RequireAuth.";
311 uFlagsOut &= ~lsfRequireAuth;
319 JLOG(
j_.
trace()) <<
"Set lsfRequireDestTag.";
325 JLOG(
j_.
trace()) <<
"Clear lsfRequireDestTag.";
326 uFlagsOut &= ~lsfRequireDestTag;
334 JLOG(
j_.
trace()) <<
"Set lsfDisallowXRP.";
340 JLOG(
j_.
trace()) <<
"Clear lsfDisallowXRP.";
341 uFlagsOut &= ~lsfDisallowXRP;
351 JLOG(
j_.
trace()) <<
"Must use master key to disable master key.";
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";
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);
436 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
441 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
442 uFlagsOut &= ~lsfDepositAuth;
448 if (tx.isFieldPresent(sfEmailHash))
450 uint128 const uHash = tx.getFieldH128(sfEmailHash);
454 JLOG(
j_.
trace()) <<
"unset email hash";
455 sle->makeFieldAbsent(sfEmailHash);
459 JLOG(
j_.
trace()) <<
"set email hash";
460 sle->setFieldH128(sfEmailHash, uHash);
467 if (tx.isFieldPresent(sfWalletLocator))
469 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
473 JLOG(
j_.
trace()) <<
"unset wallet locator";
474 sle->makeFieldAbsent(sfWalletLocator);
478 JLOG(
j_.
trace()) <<
"set wallet locator";
479 sle->setFieldH256(sfWalletLocator, uHash);
486 if (tx.isFieldPresent(sfMessageKey))
488 Blob const messageKey = tx.getFieldVL(sfMessageKey);
490 if (messageKey.
empty())
492 JLOG(
j_.
debug()) <<
"set message key";
493 sle->makeFieldAbsent(sfMessageKey);
497 JLOG(
j_.
debug()) <<
"set message key";
498 sle->setFieldVL(sfMessageKey, messageKey);
505 if (tx.isFieldPresent(sfDomain))
507 Blob const domain = tx.getFieldVL(sfDomain);
511 JLOG(
j_.
trace()) <<
"unset domain";
512 sle->makeFieldAbsent(sfDomain);
516 JLOG(
j_.
trace()) <<
"set domain";
517 sle->setFieldVL(sfDomain, domain);
524 if (tx.isFieldPresent(sfTransferRate))
528 if (uRate == 0 || uRate == QUALITY_ONE)
530 JLOG(
j_.
trace()) <<
"unset transfer rate";
531 sle->makeFieldAbsent(sfTransferRate);
535 JLOG(
j_.
trace()) <<
"set transfer rate";
536 sle->setFieldU32(sfTransferRate, uRate);
543 if (tx.isFieldPresent(sfTickSize))
545 auto uTickSize = tx[sfTickSize];
546 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
548 JLOG(
j_.
trace()) <<
"unset tick size";
549 sle->makeFieldAbsent(sfTickSize);
553 JLOG(
j_.
trace()) <<
"set tick size";
554 sle->setFieldU8(sfTickSize, uTickSize);
560 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
563 sle->makeFieldAbsent(sfNFTokenMinter);
568 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
573 uFlagsOut &= ~lsfDisallowIncomingCheck;
578 uFlagsOut &= ~lsfDisallowIncomingPayChan;
583 uFlagsOut &= ~lsfDisallowIncomingTrustline;
591 uFlagsOut &= ~lsfAllowTrustLineLocking;
597 JLOG(
j_.
trace()) <<
"set allow clawback";
601 if (uFlagsIn != uFlagsOut)
602 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 Rules const & rules() const =0
Returns the tx processing rules.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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 TxConsequences makeTxConsequences(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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 signers(AccountID const &account) noexcept
A SignerList.
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.
constexpr std::uint32_t asfAllowTrustLineClawback
@ terNO_DELEGATE_PERMISSION
constexpr std::uint32_t asfGlobalFreeze
constexpr std::uint32_t asfRequireDest
constexpr std::uint32_t asfDisableMaster
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
constexpr std::uint32_t asfAccountTxnID
constexpr std::uint32_t asfDisallowIncomingPayChan
constexpr std::uint32_t tfOptionalAuth
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t tfAccountSetMask
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
constexpr std::uint32_t tfRequireAuth
constexpr std::uint32_t asfDefaultRipple
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 asfDisallowIncomingTrustline
constexpr std::uint32_t tfAllowXRP
constexpr std::uint32_t asfAuthorizedNFTokenMinter
constexpr std::uint32_t tfRequireDestTag
constexpr std::uint32_t tfOptionalDestTag
AccountID calcAccountID(PublicKey const &pk)
std::size_t constexpr maxDomainLength
The maximum length of a domain.
constexpr std::uint32_t asfDisallowIncomingCheck
constexpr std::uint32_t asfRequireAuth
constexpr std::uint32_t asfNoFreeze
constexpr std::uint32_t asfDisallowXRP
@ lsfDisallowIncomingNFTokenOffer
@ lsfAllowTrustLineClawback
@ lsfDisallowIncomingPayChan
@ lsfDisallowIncomingCheck
@ lsfAllowTrustLineLocking
@ lsfDisallowIncomingTrustline
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 asfDisallowIncomingNFTokenOffer
constexpr std::uint32_t tfDisallowXRP
constexpr std::uint32_t asfAllowTrustLineLocking
constexpr std::uint32_t tfUniversalMask
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.