1#include <xrpld/app/misc/DelegateUtils.h>
2#include <xrpld/app/tx/detail/SetAccount.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/protocol/Feature.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/Quality.h>
10#include <xrpl/protocol/st.h>
19 auto getTxConsequencesCategory = [](
STTx const& tx) {
23 if (
auto const uSetFlag = tx[~sfSetFlag];
27 if (
auto const uClearFlag = tx[~sfClearFlag]; uClearFlag &&
54 if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
56 JLOG(j.trace()) <<
"Malformed transaction: Set and clear same flag.";
66 if (bSetRequireAuth && bClearRequireAuth)
68 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
78 if (bSetRequireDest && bClearRequireDest)
80 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
90 if (bSetDisallowXRP && bClearDisallowXRP)
92 JLOG(j.trace()) <<
"Malformed transaction: Contradictory flags set.";
97 if (tx.isFieldPresent(sfTransferRate))
101 if (uRate && (uRate < QUALITY_ONE))
103 JLOG(j.trace()) <<
"Malformed transaction: Transfer rate too small.";
107 if (uRate > 2 * QUALITY_ONE)
109 JLOG(j.trace()) <<
"Malformed transaction: Transfer rate too large.";
115 if (tx.isFieldPresent(sfTickSize))
117 auto uTickSize = tx[sfTickSize];
118 if (uTickSize && ((uTickSize < Quality::minTickSize) || (uTickSize > Quality::maxTickSize)))
120 JLOG(j.trace()) <<
"Malformed transaction: Bad tick size.";
125 if (
auto const mk = tx[~sfMessageKey])
129 JLOG(j.trace()) <<
"Invalid message key specified.";
134 if (
auto const domain = tx[~sfDomain]; domain && domain->size() >
maxDomainLength)
136 JLOG(j.trace()) <<
"domain too long";
155 auto const delegate = tx[~sfDelegate];
160 auto const sle =
view.
read(delegateKey);
169 auto const uClearFlag = tx.
getFieldU32(sfClearFlag);
170 auto const uTxFlags = tx.
getFlags();
202 auto const id = ctx.
tx[sfAccount];
224 JLOG(ctx.
j.
trace()) <<
"Retry: Owner directory not empty.";
238 JLOG(ctx.
j.
trace()) <<
"Can't set Clawback if NoFreeze is set";
244 JLOG(ctx.
j.
trace()) <<
"Owner directory not empty.";
253 JLOG(ctx.
j.
trace()) <<
"Can't set NoFreeze if clawback is enabled";
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.";
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";
411 JLOG(
j_.
trace()) <<
"Clear GlobalFreeze flag";
412 uFlagsOut &= ~lsfGlobalFreeze;
418 if ((uSetFlag ==
asfAccountTxnID) && !sle->isFieldPresent(sfAccountTxnID))
420 JLOG(
j_.
trace()) <<
"Set AccountTxnID.";
421 sle->makeFieldPresent(sfAccountTxnID);
424 if ((uClearFlag ==
asfAccountTxnID) && sle->isFieldPresent(sfAccountTxnID))
426 JLOG(
j_.
trace()) <<
"Clear AccountTxnID.";
427 sle->makeFieldAbsent(sfAccountTxnID);
435 JLOG(
j_.
trace()) <<
"Set lsfDepositAuth.";
440 JLOG(
j_.
trace()) <<
"Clear lsfDepositAuth.";
441 uFlagsOut &= ~lsfDepositAuth;
447 if (tx.isFieldPresent(sfEmailHash))
449 uint128 const uHash = tx.getFieldH128(sfEmailHash);
453 JLOG(
j_.
trace()) <<
"unset email hash";
454 sle->makeFieldAbsent(sfEmailHash);
458 JLOG(
j_.
trace()) <<
"set email hash";
459 sle->setFieldH128(sfEmailHash, uHash);
466 if (tx.isFieldPresent(sfWalletLocator))
468 uint256 const uHash = tx.getFieldH256(sfWalletLocator);
472 JLOG(
j_.
trace()) <<
"unset wallet locator";
473 sle->makeFieldAbsent(sfWalletLocator);
477 JLOG(
j_.
trace()) <<
"set wallet locator";
478 sle->setFieldH256(sfWalletLocator, uHash);
485 if (tx.isFieldPresent(sfMessageKey))
487 Blob const messageKey = tx.getFieldVL(sfMessageKey);
489 if (messageKey.
empty())
491 JLOG(
j_.
debug()) <<
"set message key";
492 sle->makeFieldAbsent(sfMessageKey);
496 JLOG(
j_.
debug()) <<
"set message key";
497 sle->setFieldVL(sfMessageKey, messageKey);
504 if (tx.isFieldPresent(sfDomain))
506 Blob const domain = tx.getFieldVL(sfDomain);
510 JLOG(
j_.
trace()) <<
"unset domain";
511 sle->makeFieldAbsent(sfDomain);
515 JLOG(
j_.
trace()) <<
"set domain";
516 sle->setFieldVL(sfDomain, domain);
523 if (tx.isFieldPresent(sfTransferRate))
527 if (uRate == 0 || uRate == QUALITY_ONE)
529 JLOG(
j_.
trace()) <<
"unset transfer rate";
530 sle->makeFieldAbsent(sfTransferRate);
534 JLOG(
j_.
trace()) <<
"set transfer rate";
535 sle->setFieldU32(sfTransferRate, uRate);
542 if (tx.isFieldPresent(sfTickSize))
544 auto uTickSize = tx[sfTickSize];
545 if ((uTickSize == 0) || (uTickSize == Quality::maxTickSize))
547 JLOG(
j_.
trace()) <<
"unset tick size";
548 sle->makeFieldAbsent(sfTickSize);
552 JLOG(
j_.
trace()) <<
"set tick size";
553 sle->setFieldU8(sfTickSize, uTickSize);
559 sle->setAccountID(sfNFTokenMinter,
ctx_.
tx[sfNFTokenMinter]);
562 sle->makeFieldAbsent(sfNFTokenMinter);
567 uFlagsOut &= ~lsfDisallowIncomingNFTokenOffer;
572 uFlagsOut &= ~lsfDisallowIncomingCheck;
577 uFlagsOut &= ~lsfDisallowIncomingPayChan;
582 uFlagsOut &= ~lsfDisallowIncomingTrustline;
590 uFlagsOut &= ~lsfAllowTrustLineLocking;
596 JLOG(
j_.
trace()) <<
"set allow clawback";
600 if (uFlagsIn != uFlagsOut)
601 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.