20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/LoadFeeTrack.h>
22 #include <ripple/app/tx/apply.h>
23 #include <ripple/app/tx/impl/SignerEntries.h>
24 #include <ripple/app/tx/impl/Transactor.h>
25 #include <ripple/app/tx/impl/details/NFTokenUtils.h>
26 #include <ripple/basics/Log.h>
27 #include <ripple/basics/contract.h>
28 #include <ripple/core/Config.h>
29 #include <ripple/json/to_string.h>
30 #include <ripple/ledger/View.h>
31 #include <ripple/protocol/Feature.h>
32 #include <ripple/protocol/Indexes.h>
33 #include <ripple/protocol/Protocol.h>
34 #include <ripple/protocol/STAccount.h>
35 #include <ripple/protocol/UintTypes.h>
45 if (txID == beast::zero)
48 <<
"applyTransaction: transaction id may not be zero";
72 if (
id == beast::zero)
74 JLOG(ctx.
j.
warn()) <<
"preflight1: bad account id";
80 if (!fee.native() || fee.negative() || !
isLegalAmount(fee.xrp()))
82 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid fee";
90 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid signing key";
115 JLOG(ctx.
j.
debug()) <<
"preflight2: bad signature. " << sigValid.second;
129 : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_)
136 : ctx_(ctx), j_(ctx.journal), account_(ctx.tx.getAccountID(
sfAccount))
155 return baseFee + (signerCount * baseFee);
174 auto const feePaid = ctx.
tx[
sfFee].xrp();
184 if (feePaid < feeDue)
187 <<
"Insufficient fee paid: " <<
to_string(feePaid) <<
"/"
193 if (feePaid == beast::zero)
201 auto const balance = (*sle)[
sfBalance].xrp();
203 if (balance < feePaid)
205 JLOG(ctx.
j.
trace()) <<
"Insufficient balance:"
209 if ((balance > beast::zero) && !ctx.
view.
open())
254 <<
"applyTransaction: delay: source account does not exist "
262 if (t_seqProx.
isSeq())
267 JLOG(j.
trace()) <<
"applyTransaction: has both a TicketSequence "
268 "and a non-zero Sequence number";
271 if (t_seqProx != a_seq)
273 if (a_seq < t_seqProx)
276 <<
"applyTransaction: has future sequence number "
277 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
281 JLOG(j.
trace()) <<
"applyTransaction: has past sequence number "
282 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
295 JLOG(j.
trace()) <<
"applyTransaction: has future ticket id "
296 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
304 <<
"applyTransaction: ticket already used or never created "
305 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
323 <<
"applyTransaction: delay: source account does not exist "
373 JLOG(j.
fatal()) <<
"Ticket disappeared from ledger.";
380 JLOG(j.
fatal()) <<
"Unable to delete Ticket from owner.";
389 JLOG(j.
fatal()) <<
"Could not find Ticket owner account root.";
395 if (*ticketCount == 1)
398 ticketCount = *ticketCount - 1;
402 JLOG(j.
fatal()) <<
"TicketCount field missing from account root.";
432 assert(sle !=
nullptr ||
account_ == beast::zero);
474 <<
"checkSingleSign: signing public key type is unknown";
496 if (!isMasterDisabled && idAccount == idSigner)
502 if (isMasterDisabled && idAccount == idSigner)
511 if (idSigner == idAccount)
514 if (isMasterDisabled)
525 <<
"checkSingleSign: Not authorized to use account.";
533 <<
"checkSingleSign: Not authorized to use account.";
548 if (!sleAccountSigners)
551 <<
"applyTransaction: Invalid: Not a multi-signing account.";
560 auto accountSigners =
563 return accountSigners.error();
575 auto iter = accountSigners->begin();
576 for (
auto const& txSigner : txSigners)
581 while (iter->account < txSignerAcctID)
583 if (++iter == accountSigners->end())
586 <<
"applyTransaction: Invalid SigningAccount.Account.";
590 if (iter->account != txSignerAcctID)
594 <<
"applyTransaction: Invalid SigningAccount.Account.";
606 <<
"checkMultiSign: signing public key type is unknown";
610 AccountID const signingAcctIDFromPubKey =
640 if (signingAcctIDFromPubKey == txSignerAcctID)
647 sleTxSignerRoot->getFieldU32(
sfFlags);
652 <<
"applyTransaction: Signer:Account lsfDisableMaster.";
661 if (!sleTxSignerRoot)
663 JLOG(ctx.
j.
trace()) <<
"applyTransaction: Non-phantom signer "
664 "lacks account root.";
671 <<
"applyTransaction: Account lacks RegularKey.";
674 if (signingAcctIDFromPubKey !=
678 <<
"applyTransaction: Account doesn't match RegularKey.";
683 weightSum += iter->weight;
690 <<
"applyTransaction: Signers failed to meet quorum.";
708 for (
auto const& index : offers)
728 for (
auto const& index : offers)
752 auto const balance = txnAcct->getFieldAmount(
sfBalance).xrp();
755 assert(balance != beast::zero && (!
view().
open() || balance >= fee));
768 txnAcct->setFieldAmount(
sfBalance, balance - fee);
795 JLOG(
j_.
fatal()) <<
"Transaction serdes mismatch";
812 stream <<
"preclaim result: " <<
transToken(result);
849 assert(before &&
after);
850 if (before &&
after && (before->getType() ==
ltOFFER) &&
872 assert(before &&
after);
873 if (before &&
after &&
882 auto const resetResult =
reset(fee);
884 result = resetResult.first;
886 fee = resetResult.second;
911 auto const resetResult =
reset(fee);
913 result = resetResult.first;
915 fee = resetResult.second;
937 if (fee < beast::zero)
938 Throw<std::logic_error>(
"fee charged is negative!");
944 if (!
view().
open() && fee != beast::zero)
951 JLOG(
j_.
trace()) << (applied ?
"applied" :
"not applied")
954 return {result, applied};
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
const SF_UINT32 sfSignerListID
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
const STArray & getFieldArray(SField const &field) const
RAII class to set and restore the STAmount canonicalize switchover.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
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)
static NotTEC checkMultiSign(PreclaimContext const &ctx)
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
bool isLegalAmount(XRPAmount const &amount)
Returns true if the amount does not exceed the initial XRP in existence.
const SF_UINT64 sfOwnerNode
Stream trace() const
Severity stream access functions.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string const &annotation)
static NotTEC checkSingleSign(PreclaimContext const &ctx)
const SF_UINT32 sfSequence
const SF_ACCOUNT sfRegularKey
std::pair< TER, bool > operator()()
Process the transaction.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
const SF_VL sfSigningPubKey
const uint256 fixSTAmountCanonicalize
constexpr std::size_t expiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
std::string transToken(TER code)
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
SeqProxy getSeqProxy() const
const SF_UINT32 sfTicketSequence
static const ticket_t ticket
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
static XRPAmount minimumFee(Application &app, FeeUnit64 baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
constexpr std::size_t unfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
uint256 getTicketIndex(AccountID const &account, std::uint32_t ticketSeq)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Writeable view to a ledger, for applying a transaction.
virtual LoadFeeTrack & getFeeTrack()=0
constexpr bool isTicket() const
const SF_UINT32 sfSignerQuorum
bool isEquivalent(const STBase &t) const override
constexpr bool isSeq() const
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
const SF_AMOUNT sfTakerPays
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
@ ltOFFER
A ledger object which describes an offer on the DEX.
static NotTEC checkSign(PreclaimContext const &ctx)
Reflects the fee settings for a particular ledger.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Keylet account(AccountID const &id) noexcept
AccountID root.
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
AccountID getAccountID(SField const &field) const
void destroyXRP(XRPAmount const &fee)
virtual Config & config()=0
@ ltNFTOKEN_OFFER
A ledger object which identifies an offer to buy or sell an NFT.
AccountID calcAccountID(PublicKey const &pk)
const SF_UINT32 sfTicketCount
const SF_UINT256 sfAccountTxnID
void discard()
Discard changes and start fresh.
Slice slice() const noexcept
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
const uint256 fixMasterKeyAsRegularKey
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
State information when applying a tx.
Blob getSigningPubKey() const
A generic endpoint for log messages.
TER consumeSeqProxy(SLE::pointer const &sleAccount)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Json::Value getJson(JsonOptions options) const override
Transactor(Transactor const &)=delete
void apply(TER)
Apply the transaction result to the base.
void visit(std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func)
Visit unapplied changes.
uint256 getTransactionID() const
PreflightContext(Application &app_, STTx const &tx_, Rules const &rules_, ApplyFlags flags_, beast::Journal j_)
State information when determining if a tx is likely to claim a fee.
void add(Serializer &s) const override
constexpr std::uint32_t value() const
std::pair< TER, XRPAmount > reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual beast::Journal journal(std::string const &name)=0
constexpr std::size_t oversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool isFieldPresent(SField const &field) const
const SF_AMOUNT sfBalance
A type that represents either a sequence value or a ticket value.
Rules controlling protocol behavior.
const uint256 featureTicketBatch
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
static void removeExpiredNFTokenOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
std::uint32_t getFieldU32(SField const &field) const
State information when preflighting a tx.
@ SigBad
Signature is bad. Didn't do local checks.
const SF_UINT32 sfLastLedgerSequence
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
std::size_t size()
Get the number of unapplied changes.
static void removeUnfundedOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
static TER checkFee(PreclaimContext const &ctx, FeeUnit64 baseFee)
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual HashRouter & getHashRouter()=0
virtual void preCompute()
STAmount const & getFieldAmount(SField const &field) const
bool deleteTokenOffer(ApplyView &view, std::shared_ptr< SLE > const &offer)
Deletes the given token offer.
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
TERSubset< CanCvtToNotTEC > NotTEC
uint256 getFieldH256(SField const &field) const