rippled
Loading...
Searching...
No Matches
Transactor.cpp
1#include <xrpld/app/misc/DelegateUtils.h>
2#include <xrpld/app/misc/LoadFeeTrack.h>
3#include <xrpld/app/tx/apply.h>
4#include <xrpld/app/tx/detail/NFTokenUtils.h>
5#include <xrpld/app/tx/detail/SignerEntries.h>
6#include <xrpld/app/tx/detail/Transactor.h>
7
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/contract.h>
10#include <xrpl/json/to_string.h>
11#include <xrpl/ledger/CredentialHelpers.h>
12#include <xrpl/ledger/View.h>
13#include <xrpl/protocol/Feature.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/Protocol.h>
16#include <xrpl/protocol/SystemParameters.h>
17#include <xrpl/protocol/TxFlags.h>
18#include <xrpl/protocol/UintTypes.h>
19
20namespace xrpl {
21
25{
26 if (isPseudoTx(ctx.tx) && ctx.tx.isFlag(tfInnerBatchTxn))
27 {
28 JLOG(ctx.j.warn()) << "Pseudo transactions cannot contain the "
29 "tfInnerBatchTxn flag.";
30 return temINVALID_FLAG;
31 }
32
33 if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID))
34 {
35 uint32_t nodeNID = ctx.app.config().NETWORK_ID;
36 std::optional<uint32_t> txNID = ctx.tx[~sfNetworkID];
37
38 if (nodeNID <= 1024)
39 {
40 // legacy networks have ids less than 1024, these networks cannot
41 // specify NetworkID in txn
42 if (txNID)
44 }
45 else
46 {
47 // new networks both require the field to be present and require it
48 // to match
49 if (!txNID)
51
52 if (*txNID != nodeNID)
53 return telWRONG_NETWORK;
54 }
55 }
56
57 auto const txID = ctx.tx.getTransactionID();
58
59 if (txID == beast::zero)
60 {
61 JLOG(ctx.j.warn()) << "applyTransaction: transaction id may not be zero";
62 return temINVALID;
63 }
64
65 if (ctx.tx.getFlags() & flagMask)
66 {
67 JLOG(ctx.j.debug()) << ctx.tx.peekAtField(sfTransactionType).getFullText() << ": invalid flags.";
68 return temINVALID_FLAG;
69 }
70
71 return tesSUCCESS;
72}
73
74namespace detail {
75
82{
83 if (auto const spk = sigObject.getFieldVL(sfSigningPubKey); !spk.empty() && !publicKeyType(makeSlice(spk)))
84 {
85 JLOG(j.debug()) << "preflightCheckSigningKey: invalid signing key";
86 return temBAD_SIGNATURE;
87 }
88 return tesSUCCESS;
89}
90
93{
94 if (flags & tapDRY_RUN) // simulation
95 {
96 std::optional<Slice> const signature = sigObject[~sfTxnSignature];
97 if (signature && !signature->empty())
98 {
99 // NOTE: This code should never be hit because it's checked in the
100 // `simulate` RPC
101 return temINVALID; // LCOV_EXCL_LINE
102 }
103
104 if (!sigObject.isFieldPresent(sfSigners))
105 {
106 // no signers, no signature - a valid simulation
107 return tesSUCCESS;
108 }
109
110 for (auto const& signer : sigObject.getFieldArray(sfSigners))
111 {
112 if (signer.isFieldPresent(sfTxnSignature) && !signer[sfTxnSignature].empty())
113 {
114 // NOTE: This code should never be hit because it's
115 // checked in the `simulate` RPC
116 return temINVALID; // LCOV_EXCL_LINE
117 }
118 }
119
120 Slice const signingPubKey = sigObject[sfSigningPubKey];
121 if (!signingPubKey.empty())
122 {
123 // trying to single-sign _and_ multi-sign a transaction
124 return temINVALID;
125 }
126 return tesSUCCESS;
127 }
128 return {};
129}
130
131} // namespace detail
132
134NotTEC
136{
137 if (ctx.tx.isFieldPresent(sfDelegate))
138 {
139 if (!ctx.rules.enabled(featurePermissionDelegationV1_1))
140 return temDISABLED;
141
142 if (ctx.tx[sfDelegate] == ctx.tx[sfAccount])
143 return temBAD_SIGNER;
144 }
145
146 if (auto const ret = preflight0(ctx, flagMask))
147 return ret;
148
149 auto const id = ctx.tx.getAccountID(sfAccount);
150 if (id == beast::zero)
151 {
152 JLOG(ctx.j.warn()) << "preflight1: bad account id";
153 return temBAD_SRC_ACCOUNT;
154 }
155
156 // No point in going any further if the transaction fee is malformed.
157 auto const fee = ctx.tx.getFieldAmount(sfFee);
158 if (!fee.native() || fee.negative() || !isLegalAmount(fee.xrp()))
159 {
160 JLOG(ctx.j.debug()) << "preflight1: invalid fee";
161 return temBAD_FEE;
162 }
163
164 if (auto const ret = detail::preflightCheckSigningKey(ctx.tx, ctx.j))
165 return ret;
166
167 // An AccountTxnID field constrains transaction ordering more than the
168 // Sequence field. Tickets, on the other hand, reduce ordering
169 // constraints. Because Tickets and AccountTxnID work against one
170 // another the combination is unsupported and treated as malformed.
171 //
172 // We return temINVALID for such transactions.
173 if (ctx.tx.getSeqProxy().isTicket() && ctx.tx.isFieldPresent(sfAccountTxnID))
174 return temINVALID;
175
176 if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatch))
177 return temINVALID_FLAG;
178
179 XRPL_ASSERT(
180 ctx.tx.isFlag(tfInnerBatchTxn) == ctx.parentBatchId.has_value() || !ctx.rules.enabled(featureBatch),
181 "Inner batch transaction must have a parent batch ID.");
182
183 return tesSUCCESS;
184}
185
187NotTEC
189{
190 if (auto const ret = detail::preflightCheckSimulateKeys(ctx.flags, ctx.tx, ctx.j))
191 // Skips following checks if the transaction is being simulated,
192 // regardless of success or failure
193 return *ret;
194
195 // It should be impossible for the InnerBatchTxn flag to be set without
196 // featureBatch being enabled
197 XRPL_ASSERT_PARTS(
198 !ctx.tx.isFlag(tfInnerBatchTxn) || ctx.rules.enabled(featureBatch),
199 "xrpl::Transactor::preflight2",
200 "InnerBatch flag only set if feature enabled");
201 // Skip signature check on batch inner transactions
202 if (ctx.tx.isFlag(tfInnerBatchTxn) && ctx.rules.enabled(featureBatch))
203 return tesSUCCESS;
204 // Do not add any checks after this point that are relevant for
205 // batch inner transactions. They will be skipped.
206
207 auto const sigValid = checkValidity(ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config());
208 if (sigValid.first == Validity::SigBad)
209 { // LCOV_EXCL_START
210 JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second;
211 return temINVALID;
212 // LCOV_EXCL_STOP
213 }
214
215 // Do not add any checks after this point that are relevant for
216 // batch inner transactions. They will be skipped.
217
218 return tesSUCCESS;
219}
220
221//------------------------------------------------------------------------------
222
224 : ctx_(ctx)
225 , sink_(ctx.journal, to_short_string(ctx.tx.getTransactionID()) + " ")
226 , j_(sink_)
227 , account_(ctx.tx.getAccountID(sfAccount))
228{
229}
230
231bool
233{
234 if (!slice)
235 return true;
236 return !slice->empty() && slice->length() <= maxLength;
237}
238
244
245NotTEC
250
251NotTEC
253{
254 auto const delegate = tx[~sfDelegate];
255 if (!delegate)
256 return tesSUCCESS;
257
258 auto const delegateKey = keylet::delegate(tx[sfAccount], *delegate);
259 auto const sle = view.read(delegateKey);
260
261 if (!sle)
263
264 return checkTxPermission(sle, tx);
265}
266
269{
270 // Returns the fee in fee units.
271
272 // The computation has two parts:
273 // * The base fee, which is the same for most transactions.
274 // * The additional cost of each multisignature on the transaction.
275 XRPAmount const baseFee = view.fees().base;
276
277 // Each signer adds one more baseFee to the minimum required fee
278 // for the transaction.
279 std::size_t const signerCount = tx.isFieldPresent(sfSigners) ? tx.getFieldArray(sfSigners).size() : 0;
280
281 return baseFee + (signerCount * baseFee);
282}
283
284// Returns the fee in fee units, not scaled for load.
287{
288 // Assumption: One reserve increment is typically much greater than one base
289 // fee.
290 // This check is in an assert so that it will come to the attention of
291 // developers if that assumption is not correct. If the owner reserve is not
292 // significantly larger than the base fee (or even worse, smaller), we will
293 // need to rethink charging an owner reserve as a transaction fee.
294 // TODO: This function is static, and I don't want to add more parameters.
295 // When it is finally refactored to be in a context that has access to the
296 // Application, include "app().overlay().networkID() > 2 ||" in the
297 // condition.
298 XRPL_ASSERT(
299 view.fees().increment > view.fees().base * 100,
300 "xrpl::Transactor::calculateOwnerReserveFee : Owner reserve is "
301 "reasonable");
302 return view.fees().increment;
303}
304
307{
308 return scaleFeeLoad(baseFee, app.getFeeTrack(), fees, flags & tapUNLIMITED);
309}
310
311TER
313{
314 if (!ctx.tx[sfFee].native())
315 return temBAD_FEE;
316
317 auto const feePaid = ctx.tx[sfFee].xrp();
318
319 if (ctx.flags & tapBATCH)
320 {
321 if (feePaid == beast::zero)
322 return tesSUCCESS;
323
324 JLOG(ctx.j.trace()) << "Batch: Fee must be zero.";
325 return temBAD_FEE; // LCOV_EXCL_LINE
326 }
327
328 if (!isLegalAmount(feePaid) || feePaid < beast::zero)
329 return temBAD_FEE;
330
331 // Only check fee is sufficient when the ledger is open.
332 if (ctx.view.open())
333 {
334 auto const feeDue = minimumFee(ctx.app, baseFee, ctx.view.fees(), ctx.flags);
335
336 if (feePaid < feeDue)
337 {
338 JLOG(ctx.j.trace()) << "Insufficient fee paid: " << to_string(feePaid) << "/" << to_string(feeDue);
339 return telINSUF_FEE_P;
340 }
341 }
342
343 if (feePaid == beast::zero)
344 return tesSUCCESS;
345
346 auto const id =
347 ctx.tx.isFieldPresent(sfDelegate) ? ctx.tx.getAccountID(sfDelegate) : ctx.tx.getAccountID(sfAccount);
348 auto const sle = ctx.view.read(keylet::account(id));
349 if (!sle)
350 return terNO_ACCOUNT;
351
352 auto const balance = (*sle)[sfBalance].xrp();
353
354 if (balance < feePaid)
355 {
356 JLOG(ctx.j.trace()) << "Insufficient balance:" << " balance=" << to_string(balance)
357 << " paid=" << to_string(feePaid);
358
359 if ((balance > beast::zero) && !ctx.view.open())
360 {
361 // Closed ledger, non-zero balance, less than fee
362 return tecINSUFF_FEE;
363 }
364
365 return terINSUF_FEE_B;
366 }
367
368 return tesSUCCESS;
369}
370
371TER
373{
374 auto const feePaid = ctx_.tx[sfFee].xrp();
375
376 if (ctx_.tx.isFieldPresent(sfDelegate))
377 {
378 // Delegated transactions are paid by the delegated account.
379 auto const delegate = ctx_.tx.getAccountID(sfDelegate);
380 auto const delegatedSle = view().peek(keylet::account(delegate));
381 if (!delegatedSle)
382 return tefINTERNAL; // LCOV_EXCL_LINE
383
384 delegatedSle->setFieldAmount(sfBalance, delegatedSle->getFieldAmount(sfBalance) - feePaid);
385 view().update(delegatedSle);
386 }
387 else
388 {
389 auto const sle = view().peek(keylet::account(account_));
390 if (!sle)
391 return tefINTERNAL; // LCOV_EXCL_LINE
392
393 // Deduct the fee, so it's not available during the transaction.
394 // Will only write the account back if the transaction succeeds.
395
396 mSourceBalance -= feePaid;
397 sle->setFieldAmount(sfBalance, mSourceBalance);
398
399 // VFALCO Should we call view().rawDestroyXRP() here as well?
400 }
401
402 return tesSUCCESS;
403}
404
405NotTEC
407{
408 auto const id = tx.getAccountID(sfAccount);
409
410 auto const sle = view.read(keylet::account(id));
411
412 if (!sle)
413 {
414 JLOG(j.trace()) << "applyTransaction: delay: source account does not exist " << toBase58(id);
415 return terNO_ACCOUNT;
416 }
417
418 SeqProxy const t_seqProx = tx.getSeqProxy();
419 SeqProxy const a_seq = SeqProxy::sequence((*sle)[sfSequence]);
420
421 if (t_seqProx.isSeq())
422 {
423 if (tx.isFieldPresent(sfTicketSequence))
424 {
425 JLOG(j.trace()) << "applyTransaction: has both a TicketSequence "
426 "and a non-zero Sequence number";
427 return temSEQ_AND_TICKET;
428 }
429 if (t_seqProx != a_seq)
430 {
431 if (a_seq < t_seqProx)
432 {
433 JLOG(j.trace()) << "applyTransaction: has future sequence number "
434 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
435 return terPRE_SEQ;
436 }
437 // It's an already-used sequence number.
438 JLOG(j.trace()) << "applyTransaction: has past sequence number "
439 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
440 return tefPAST_SEQ;
441 }
442 }
443 else if (t_seqProx.isTicket())
444 {
445 // Bypass the type comparison. Apples and oranges.
446 if (a_seq.value() <= t_seqProx.value())
447 {
448 // If the Ticket number is greater than or equal to the
449 // account sequence there's the possibility that the
450 // transaction to create the Ticket has not hit the ledger
451 // yet. Allow a retry.
452 JLOG(j.trace()) << "applyTransaction: has future ticket id "
453 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
454 return terPRE_TICKET;
455 }
456
457 // Transaction can never succeed if the Ticket is not in the ledger.
458 if (!view.exists(keylet::ticket(id, t_seqProx)))
459 {
460 JLOG(j.trace()) << "applyTransaction: ticket already used or never created "
461 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
462 return tefNO_TICKET;
463 }
464 }
465
466 return tesSUCCESS;
467}
468
469NotTEC
471{
472 auto const id = ctx.tx.getAccountID(sfAccount);
473
474 auto const sle = ctx.view.read(keylet::account(id));
475
476 if (!sle)
477 {
478 JLOG(ctx.j.trace()) << "applyTransaction: delay: source account does not exist " << toBase58(id);
479 return terNO_ACCOUNT;
480 }
481
482 if (ctx.tx.isFieldPresent(sfAccountTxnID) &&
483 (sle->getFieldH256(sfAccountTxnID) != ctx.tx.getFieldH256(sfAccountTxnID)))
484 return tefWRONG_PRIOR;
485
486 if (ctx.tx.isFieldPresent(sfLastLedgerSequence) && (ctx.view.seq() > ctx.tx.getFieldU32(sfLastLedgerSequence)))
487 return tefMAX_LEDGER;
488
489 if (ctx.view.txExists(ctx.tx.getTransactionID()))
490 return tefALREADY;
491
492 return tesSUCCESS;
493}
494
495TER
497{
498 XRPL_ASSERT(sleAccount, "xrpl::Transactor::consumeSeqProxy : non-null account");
499 SeqProxy const seqProx = ctx_.tx.getSeqProxy();
500 if (seqProx.isSeq())
501 {
502 // Note that if this transaction is a TicketCreate, then
503 // the transaction will modify the account root sfSequence
504 // yet again.
505 sleAccount->setFieldU32(sfSequence, seqProx.value() + 1);
506 return tesSUCCESS;
507 }
508 return ticketDelete(view(), account_, getTicketIndex(account_, seqProx), j_);
509}
510
511// Remove a single Ticket from the ledger.
512TER
513Transactor::ticketDelete(ApplyView& view, AccountID const& account, uint256 const& ticketIndex, beast::Journal j)
514{
515 // Delete the Ticket, adjust the account root ticket count, and
516 // reduce the owner count.
517 SLE::pointer const sleTicket = view.peek(keylet::ticket(ticketIndex));
518 if (!sleTicket)
519 {
520 // LCOV_EXCL_START
521 JLOG(j.fatal()) << "Ticket disappeared from ledger.";
522 return tefBAD_LEDGER;
523 // LCOV_EXCL_STOP
524 }
525
526 std::uint64_t const page{(*sleTicket)[sfOwnerNode]};
527 if (!view.dirRemove(keylet::ownerDir(account), page, ticketIndex, true))
528 {
529 // LCOV_EXCL_START
530 JLOG(j.fatal()) << "Unable to delete Ticket from owner.";
531 return tefBAD_LEDGER;
532 // LCOV_EXCL_STOP
533 }
534
535 // Update the account root's TicketCount. If the ticket count drops to
536 // zero remove the (optional) field.
537 auto sleAccount = view.peek(keylet::account(account));
538 if (!sleAccount)
539 {
540 // LCOV_EXCL_START
541 JLOG(j.fatal()) << "Could not find Ticket owner account root.";
542 return tefBAD_LEDGER;
543 // LCOV_EXCL_STOP
544 }
545
546 if (auto ticketCount = (*sleAccount)[~sfTicketCount])
547 {
548 if (*ticketCount == 1)
549 sleAccount->makeFieldAbsent(sfTicketCount);
550 else
551 ticketCount = *ticketCount - 1;
552 }
553 else
554 {
555 // LCOV_EXCL_START
556 JLOG(j.fatal()) << "TicketCount field missing from account root.";
557 return tefBAD_LEDGER;
558 // LCOV_EXCL_STOP
559 }
560
561 // Update the Ticket owner's reserve.
562 adjustOwnerCount(view, sleAccount, -1, j);
563
564 // Remove Ticket from ledger.
565 view.erase(sleTicket);
566 return tesSUCCESS;
567}
568
569// check stuff before you bother to lock the ledger
570void
572{
573 XRPL_ASSERT(account_ != beast::zero, "xrpl::Transactor::preCompute : nonzero account");
574}
575
576TER
578{
579 preCompute();
580
581 // If the transactor requires a valid account and the transaction doesn't
582 // list one, preflight will have already a flagged a failure.
583 auto const sle = view().peek(keylet::account(account_));
584
585 // sle must exist except for transactions
586 // that allow zero account.
587 XRPL_ASSERT(sle != nullptr || account_ == beast::zero, "xrpl::Transactor::apply : non-null SLE or zero account");
588
589 if (sle)
590 {
591 mPriorBalance = STAmount{(*sle)[sfBalance]}.xrp();
593
594 TER result = consumeSeqProxy(sle);
595 if (result != tesSUCCESS)
596 return result;
597
598 result = payFee();
599 if (result != tesSUCCESS)
600 return result;
601
602 if (sle->isFieldPresent(sfAccountTxnID))
603 sle->setFieldH256(sfAccountTxnID, ctx_.tx.getTransactionID());
604
605 view().update(sle);
606 }
607
608 return doApply();
609}
610
611NotTEC
613 ReadView const& view,
614 ApplyFlags flags,
615 std::optional<uint256 const> const& parentBatchId,
616 AccountID const& idAccount,
617 STObject const& sigObject,
618 beast::Journal const j)
619{
620 {
621 auto const sle = view.read(keylet::account(idAccount));
622
623 if (view.rules().enabled(featureLendingProtocol) && isPseudoAccount(sle))
624 // Pseudo-accounts can't sign transactions. This check is gated on
625 // the Lending Protocol amendment because that's the project it was
626 // added under, and it doesn't justify another amendment
627 return tefBAD_AUTH;
628 }
629
630 auto const pkSigner = sigObject.getFieldVL(sfSigningPubKey);
631 // Ignore signature check on batch inner transactions
632 if (parentBatchId && view.rules().enabled(featureBatch))
633 {
634 // Defensive Check: These values are also checked in Batch::preflight
635 if (sigObject.isFieldPresent(sfTxnSignature) || !pkSigner.empty() || sigObject.isFieldPresent(sfSigners))
636 {
637 return temINVALID_FLAG; // LCOV_EXCL_LINE
638 }
639 return tesSUCCESS;
640 }
641
642 if ((flags & tapDRY_RUN) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners))
643 {
644 // simulate: skip signature validation when neither SigningPubKey nor
645 // Signers are provided
646 return tesSUCCESS;
647 }
648
649 // If the pk is empty and not simulate or simulate and signers,
650 // then we must be multi-signing.
651 if (sigObject.isFieldPresent(sfSigners))
652 {
653 return checkMultiSign(view, flags, idAccount, sigObject, j);
654 }
655
656 // Check Single Sign
657 XRPL_ASSERT(!pkSigner.empty(), "xrpl::Transactor::checkSign : non-empty signer");
658
659 if (!publicKeyType(makeSlice(pkSigner)))
660 {
661 JLOG(j.trace()) << "checkSign: signing public key type is unknown";
662 return tefBAD_AUTH; // FIXME: should be better error!
663 }
664
665 // Look up the account.
666 auto const idSigner = pkSigner.empty() ? idAccount : calcAccountID(PublicKey(makeSlice(pkSigner)));
667 auto const sleAccount = view.read(keylet::account(idAccount));
668 if (!sleAccount)
669 return terNO_ACCOUNT;
670
671 return checkSingleSign(view, idSigner, idAccount, sleAccount, j);
672}
673
674NotTEC
676{
677 auto const idAccount =
678 ctx.tx.isFieldPresent(sfDelegate) ? ctx.tx.getAccountID(sfDelegate) : ctx.tx.getAccountID(sfAccount);
679 return checkSign(ctx.view, ctx.flags, ctx.parentBatchId, idAccount, ctx.tx, ctx.j);
680}
681
682NotTEC
684{
685 NotTEC ret = tesSUCCESS;
686 STArray const& signers{ctx.tx.getFieldArray(sfBatchSigners)};
687 for (auto const& signer : signers)
688 {
689 auto const idAccount = signer.getAccountID(sfAccount);
690
691 Blob const& pkSigner = signer.getFieldVL(sfSigningPubKey);
692 if (pkSigner.empty())
693 {
694 if (ret = checkMultiSign(ctx.view, ctx.flags, idAccount, signer, ctx.j); !isTesSuccess(ret))
695 return ret;
696 }
697 else
698 {
699 // LCOV_EXCL_START
700 if (!publicKeyType(makeSlice(pkSigner)))
701 return tefBAD_AUTH;
702 // LCOV_EXCL_STOP
703
704 auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner)));
705 auto const sleAccount = ctx.view.read(keylet::account(idAccount));
706
707 // A batch can include transactions from an un-created account ONLY
708 // when the account master key is the signer
709 if (!sleAccount)
710 {
711 if (idAccount != idSigner)
712 return tefBAD_AUTH;
713
714 return tesSUCCESS;
715 }
716
717 if (ret = checkSingleSign(ctx.view, idSigner, idAccount, sleAccount, ctx.j); !isTesSuccess(ret))
718 return ret;
719 }
720 }
721 return ret;
722}
723
724NotTEC
726 ReadView const& view,
727 AccountID const& idSigner,
728 AccountID const& idAccount,
730 beast::Journal const j)
731{
732 bool const isMasterDisabled = sleAccount->isFlag(lsfDisableMaster);
733
734 // Signed with regular key.
735 if ((*sleAccount)[~sfRegularKey] == idSigner)
736 {
737 return tesSUCCESS;
738 }
739
740 // Signed with enabled master key.
741 if (!isMasterDisabled && idAccount == idSigner)
742 {
743 return tesSUCCESS;
744 }
745
746 // Signed with disabled master key.
747 if (isMasterDisabled && idAccount == idSigner)
748 {
749 return tefMASTER_DISABLED;
750 }
751
752 // Signed with any other key.
753 return tefBAD_AUTH;
754}
755
756NotTEC
758 ReadView const& view,
759 ApplyFlags flags,
760 AccountID const& id,
761 STObject const& sigObject,
762 beast::Journal const j)
763{
764 // Get id's SignerList and Quorum.
766 // If the signer list doesn't exist the account is not multi-signing.
767 if (!sleAccountSigners)
768 {
769 JLOG(j.trace()) << "applyTransaction: Invalid: Not a multi-signing account.";
771 }
772
773 // We have plans to support multiple SignerLists in the future. The
774 // presence and defaulted value of the SignerListID field will enable that.
775 XRPL_ASSERT(
776 sleAccountSigners->isFieldPresent(sfSignerListID), "xrpl::Transactor::checkMultiSign : has signer list ID");
777 XRPL_ASSERT(
778 sleAccountSigners->getFieldU32(sfSignerListID) == 0, "xrpl::Transactor::checkMultiSign : signer list ID is 0");
779
780 auto accountSigners = SignerEntries::deserialize(*sleAccountSigners, j, "ledger");
781 if (!accountSigners)
782 return accountSigners.error();
783
784 // Get the array of transaction signers.
785 STArray const& txSigners(sigObject.getFieldArray(sfSigners));
786
787 // Walk the accountSigners performing a variety of checks and see if
788 // the quorum is met.
789
790 // Both the multiSigners and accountSigners are sorted by account. So
791 // matching multi-signers to account signers should be a simple
792 // linear walk. *All* signers must be valid or the transaction fails.
793 std::uint32_t weightSum = 0;
794 auto iter = accountSigners->begin();
795 for (auto const& txSigner : txSigners)
796 {
797 AccountID const txSignerAcctID = txSigner.getAccountID(sfAccount);
798
799 // Attempt to match the SignerEntry with a Signer;
800 while (iter->account < txSignerAcctID)
801 {
802 if (++iter == accountSigners->end())
803 {
804 JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account.";
805 return tefBAD_SIGNATURE;
806 }
807 }
808 if (iter->account != txSignerAcctID)
809 {
810 // The SigningAccount is not in the SignerEntries.
811 JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account.";
812 return tefBAD_SIGNATURE;
813 }
814
815 // We found the SigningAccount in the list of valid signers. Now we
816 // need to compute the accountID that is associated with the signer's
817 // public key.
818 auto const spk = txSigner.getFieldVL(sfSigningPubKey);
819
820 // spk being non-empty in non-simulate is checked in
821 // STTx::checkMultiSign
822 if (!spk.empty() && !publicKeyType(makeSlice(spk)))
823 {
824 JLOG(j.trace()) << "checkMultiSign: signing public key type is unknown";
825 return tefBAD_SIGNATURE;
826 }
827
828 XRPL_ASSERT(
829 (flags & tapDRY_RUN) || !spk.empty(),
830 "xrpl::Transactor::checkMultiSign : non-empty signer or "
831 "simulation");
832 AccountID const signingAcctIDFromPubKey =
833 spk.empty() ? txSignerAcctID : calcAccountID(PublicKey(makeSlice(spk)));
834
835 // Verify that the signingAcctID and the signingAcctIDFromPubKey
836 // belong together. Here are the rules:
837 //
838 // 1. "Phantom account": an account that is not in the ledger
839 // A. If signingAcctID == signingAcctIDFromPubKey and the
840 // signingAcctID is not in the ledger then we have a phantom
841 // account.
842 // B. Phantom accounts are always allowed as multi-signers.
843 //
844 // 2. "Master Key"
845 // A. signingAcctID == signingAcctIDFromPubKey, and signingAcctID
846 // is in the ledger.
847 // B. If the signingAcctID in the ledger does not have the
848 // asfDisableMaster flag set, then the signature is allowed.
849 //
850 // 3. "Regular Key"
851 // A. signingAcctID != signingAcctIDFromPubKey, and signingAcctID
852 // is in the ledger.
853 // B. If signingAcctIDFromPubKey == signingAcctID.RegularKey (from
854 // ledger) then the signature is allowed.
855 //
856 // No other signatures are allowed. (January 2015)
857
858 // In any of these cases we need to know whether the account is in
859 // the ledger. Determine that now.
860 auto const sleTxSignerRoot = view.read(keylet::account(txSignerAcctID));
861
862 if (signingAcctIDFromPubKey == txSignerAcctID)
863 {
864 // Either Phantom or Master. Phantoms automatically pass.
865 if (sleTxSignerRoot)
866 {
867 // Master Key. Account may not have asfDisableMaster set.
868 std::uint32_t const signerAccountFlags = sleTxSignerRoot->getFieldU32(sfFlags);
869
870 if (signerAccountFlags & lsfDisableMaster)
871 {
872 JLOG(j.trace()) << "applyTransaction: Signer:Account lsfDisableMaster.";
873 return tefMASTER_DISABLED;
874 }
875 }
876 }
877 else
878 {
879 // May be a Regular Key. Let's find out.
880 // Public key must hash to the account's regular key.
881 if (!sleTxSignerRoot)
882 {
883 JLOG(j.trace()) << "applyTransaction: Non-phantom signer "
884 "lacks account root.";
885 return tefBAD_SIGNATURE;
886 }
887
888 if (!sleTxSignerRoot->isFieldPresent(sfRegularKey))
889 {
890 JLOG(j.trace()) << "applyTransaction: Account lacks RegularKey.";
891 return tefBAD_SIGNATURE;
892 }
893 if (signingAcctIDFromPubKey != sleTxSignerRoot->getAccountID(sfRegularKey))
894 {
895 JLOG(j.trace()) << "applyTransaction: Account doesn't match RegularKey.";
896 return tefBAD_SIGNATURE;
897 }
898 }
899 // The signer is legitimate. Add their weight toward the quorum.
900 weightSum += iter->weight;
901 }
902
903 // Cannot perform transaction if quorum is not met.
904 if (weightSum < sleAccountSigners->getFieldU32(sfSignerQuorum))
905 {
906 JLOG(j.trace()) << "applyTransaction: Signers failed to meet quorum.";
907 return tefBAD_QUORUM;
908 }
909
910 // Met the quorum. Continue.
911 return tesSUCCESS;
912}
913
914//------------------------------------------------------------------------------
915
916static void
918{
919 int removed = 0;
920
921 for (auto const& index : offers)
922 {
923 if (auto const sleOffer = view.peek(keylet::offer(index)))
924 {
925 // offer is unfunded
926 offerDelete(view, sleOffer, viewJ);
927 if (++removed == unfundedOfferRemoveLimit)
928 return;
929 }
930 }
931}
932
933static void
935{
936 std::size_t removed = 0;
937
938 for (auto const& index : offers)
939 {
940 if (auto const offer = view.peek(keylet::nftoffer(index)))
941 {
942 nft::deleteTokenOffer(view, offer);
943 if (++removed == expiredOfferRemoveLimit)
944 return;
945 }
946 }
947}
948
949static void
951{
952 for (auto const& index : creds)
953 {
954 if (auto const sle = view.peek(keylet::credential(index)))
955 credentials::deleteSLE(view, sle, viewJ);
956 }
957}
958
959static void
961{
962 if (trustLines.size() > maxDeletableAMMTrustLines)
963 {
964 JLOG(viewJ.error()) << "removeDeletedTrustLines: deleted trustlines exceed max " << trustLines.size();
965 return;
966 }
967
968 for (auto const& index : trustLines)
969 {
970 if (auto const sleState = view.peek({ltRIPPLE_STATE, index});
971 deleteAMMTrustLine(view, sleState, std::nullopt, viewJ) != tesSUCCESS)
972 {
973 JLOG(viewJ.error()) << "removeDeletedTrustLines: failed to delete AMM trustline";
974 }
975 }
976}
977
985{
986 ctx_.discard();
987
988 auto const txnAcct = view().peek(keylet::account(ctx_.tx.getAccountID(sfAccount)));
989
990 // The account should never be missing from the ledger. But if it
991 // is missing then we can't very well charge it a fee, can we?
992 if (!txnAcct)
993 return {tefINTERNAL, beast::zero};
994
995 auto const payerSle =
996 ctx_.tx.isFieldPresent(sfDelegate) ? view().peek(keylet::account(ctx_.tx.getAccountID(sfDelegate))) : txnAcct;
997 if (!payerSle)
998 return {tefINTERNAL, beast::zero}; // LCOV_EXCL_LINE
999
1000 auto const balance = payerSle->getFieldAmount(sfBalance).xrp();
1001
1002 // balance should have already been checked in checkFee / preFlight.
1003 XRPL_ASSERT(
1004 balance != beast::zero && (!view().open() || balance >= fee), "xrpl::Transactor::reset : valid balance");
1005
1006 // We retry/reject the transaction if the account balance is zero or
1007 // we're applying against an open ledger and the balance is less than
1008 // the fee
1009 if (fee > balance)
1010 fee = balance;
1011
1012 // Since we reset the context, we need to charge the fee and update
1013 // the account's sequence number (or consume the Ticket) again.
1014 //
1015 // If for some reason we are unable to consume the ticket or sequence
1016 // then the ledger is corrupted. Rather than make things worse we
1017 // reject the transaction.
1018 payerSle->setFieldAmount(sfBalance, balance - fee);
1019 TER const ter{consumeSeqProxy(txnAcct)};
1020 XRPL_ASSERT(isTesSuccess(ter), "xrpl::Transactor::reset : result is tesSUCCESS");
1021
1022 if (isTesSuccess(ter))
1023 {
1024 view().update(txnAcct);
1025 if (payerSle != txnAcct)
1026 view().update(payerSle);
1027 }
1028
1029 return {ter, fee};
1030}
1031
1032// The sole purpose of this function is to provide a convenient, named
1033// location to set a breakpoint, to be used when replaying transactions.
1034void
1036{
1037 JLOG(j_.debug()) << "Transaction trapped: " << txHash;
1038}
1039
1040//------------------------------------------------------------------------------
1043{
1044 JLOG(j_.trace()) << "apply: " << ctx_.tx.getTransactionID();
1045
1046 // These global updates really should have been for every Transaction
1047 // step: preflight, preclaim, and doApply. And even calculateBaseFee. See
1048 // with_txn_type().
1049 //
1050 // raii classes for the current ledger rules.
1051 // fixUniversalNumber predate the rulesGuard and should be replaced.
1052 NumberSO stNumberSO{view().rules().enabled(fixUniversalNumber)};
1053 CurrentTransactionRulesGuard currentTransactionRulesGuard(view().rules());
1054
1055#ifdef DEBUG
1056 {
1057 Serializer ser;
1058 ctx_.tx.add(ser);
1059 SerialIter sit(ser.slice());
1060 STTx s2(sit);
1061
1062 if (!s2.isEquivalent(ctx_.tx))
1063 {
1064 // LCOV_EXCL_START
1065 JLOG(j_.fatal()) << "Transaction serdes mismatch";
1067 JLOG(j_.fatal()) << s2.getJson(JsonOptions::none);
1068 UNREACHABLE("xrpl::Transactor::operator() : transaction serdes mismatch");
1069 // LCOV_EXCL_STOP
1070 }
1071 }
1072#endif
1073
1074 if (auto const& trap = ctx_.app.trapTxID(); trap && *trap == ctx_.tx.getTransactionID())
1075 {
1076 trapTransaction(*trap);
1077 }
1078
1079 auto result = ctx_.preclaimResult;
1080 if (result == tesSUCCESS)
1081 result = apply();
1082
1083 // No transaction can return temUNKNOWN from apply,
1084 // and it can't be passed in from a preclaim.
1085 XRPL_ASSERT(result != temUNKNOWN, "xrpl::Transactor::operator() : result is not temUNKNOWN");
1086
1087 if (auto stream = j_.trace())
1088 stream << "preclaim result: " << transToken(result);
1089
1090 bool applied = isTesSuccess(result);
1091 auto fee = ctx_.tx.getFieldAmount(sfFee).xrp();
1092
1094 result = tecOVERSIZE;
1095
1096 if (isTecClaim(result) && (view().flags() & tapFAIL_HARD))
1097 {
1098 // If the tapFAIL_HARD flag is set, a tec result
1099 // must not do anything
1100 ctx_.discard();
1101 applied = false;
1102 }
1103 else if (
1104 (result == tecOVERSIZE) || (result == tecKILLED) || (result == tecINCOMPLETE) || (result == tecEXPIRED) ||
1105 (isTecClaimHardFail(result, view().flags())))
1106 {
1107 JLOG(j_.trace()) << "reapplying because of " << transToken(result);
1108
1109 // FIXME: This mechanism for doing work while returning a `tec` is
1110 // awkward and very limiting. A more general purpose approach
1111 // should be used, making it possible to do more useful work
1112 // when transactions fail with a `tec` code.
1113 std::vector<uint256> removedOffers;
1114 std::vector<uint256> removedTrustLines;
1115 std::vector<uint256> expiredNFTokenOffers;
1116 std::vector<uint256> expiredCredentials;
1117
1118 bool const doOffers = ((result == tecOVERSIZE) || (result == tecKILLED));
1119 bool const doLines = (result == tecINCOMPLETE);
1120 bool const doNFTokenOffers = (result == tecEXPIRED);
1121 bool const doCredentials = (result == tecEXPIRED);
1122 if (doOffers || doLines || doNFTokenOffers || doCredentials)
1123 {
1124 ctx_.visit([doOffers,
1125 &removedOffers,
1126 doLines,
1127 &removedTrustLines,
1128 doNFTokenOffers,
1129 &expiredNFTokenOffers,
1130 doCredentials,
1131 &expiredCredentials](
1132 uint256 const& index,
1133 bool isDelete,
1134 std::shared_ptr<SLE const> const& before,
1136 if (isDelete)
1137 {
1138 XRPL_ASSERT(
1139 before && after,
1140 "xrpl::Transactor::operator()::visit : non-null SLE "
1141 "inputs");
1142 if (doOffers && before && after && (before->getType() == ltOFFER) &&
1143 (before->getFieldAmount(sfTakerPays) == after->getFieldAmount(sfTakerPays)))
1144 {
1145 // Removal of offer found or made unfunded
1146 removedOffers.push_back(index);
1147 }
1148
1149 if (doLines && before && after && (before->getType() == ltRIPPLE_STATE))
1150 {
1151 // Removal of obsolete AMM trust line
1152 removedTrustLines.push_back(index);
1153 }
1154
1155 if (doNFTokenOffers && before && after && (before->getType() == ltNFTOKEN_OFFER))
1156 expiredNFTokenOffers.push_back(index);
1157
1158 if (doCredentials && before && after && (before->getType() == ltCREDENTIAL))
1159 expiredCredentials.push_back(index);
1160 }
1161 });
1162 }
1163
1164 // Reset the context, potentially adjusting the fee.
1165 {
1166 auto const resetResult = reset(fee);
1167 if (!isTesSuccess(resetResult.first))
1168 result = resetResult.first;
1169
1170 fee = resetResult.second;
1171 }
1172
1173 // If necessary, remove any offers found unfunded during processing
1174 if ((result == tecOVERSIZE) || (result == tecKILLED))
1175 removeUnfundedOffers(view(), removedOffers, ctx_.app.journal("View"));
1176
1177 if (result == tecEXPIRED)
1178 removeExpiredNFTokenOffers(view(), expiredNFTokenOffers, ctx_.app.journal("View"));
1179
1180 if (result == tecINCOMPLETE)
1181 removeDeletedTrustLines(view(), removedTrustLines, ctx_.app.journal("View"));
1182
1183 if (result == tecEXPIRED)
1184 removeExpiredCredentials(view(), expiredCredentials, ctx_.app.journal("View"));
1185
1186 applied = isTecClaim(result);
1187 }
1188
1189 if (applied)
1190 {
1191 // Check invariants: if `tecINVARIANT_FAILED` is not returned, we can
1192 // proceed to apply the tx
1193 result = ctx_.checkInvariants(result, fee);
1194
1195 if (result == tecINVARIANT_FAILED)
1196 {
1197 // if invariants checking failed again, reset the context and
1198 // attempt to only claim a fee.
1199 auto const resetResult = reset(fee);
1200 if (!isTesSuccess(resetResult.first))
1201 result = resetResult.first;
1202
1203 fee = resetResult.second;
1204
1205 // Check invariants again to ensure the fee claiming doesn't
1206 // violate invariants.
1207 if (isTesSuccess(result) || isTecClaim(result))
1208 result = ctx_.checkInvariants(result, fee);
1209 }
1210
1211 // We ran through the invariant checker, which can, in some cases,
1212 // return a tef error code. Don't apply the transaction in that case.
1213 if (!isTecClaim(result) && !isTesSuccess(result))
1214 applied = false;
1215 }
1216
1217 std::optional<TxMeta> metadata;
1218 if (applied)
1219 {
1220 // Transaction succeeded fully or (retries are not allowed and the
1221 // transaction could claim a fee)
1222
1223 // The transactor and invariant checkers guarantee that this will
1224 // *never* trigger but if it, somehow, happens, don't allow a tx
1225 // that charges a negative fee.
1226 if (fee < beast::zero)
1227 Throw<std::logic_error>("fee charged is negative!");
1228
1229 // Charge whatever fee they specified. The fee has already been
1230 // deducted from the balance of the account that issued the
1231 // transaction. We just need to account for it in the ledger
1232 // header.
1233 if (!view().open() && fee != beast::zero)
1234 ctx_.destroyXRP(fee);
1235
1236 // Once we call apply, we will no longer be able to look at view()
1237 metadata = ctx_.apply(result);
1238 }
1239
1240 if (ctx_.flags() & tapDRY_RUN)
1241 {
1242 applied = false;
1243 }
1244
1245 JLOG(j_.trace()) << (applied ? "applied " : "not applied ") << transToken(result);
1246
1247 return {result, applied, metadata};
1248}
1249
1250} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream fatal() const
Definition Journal.h:324
Stream error() const
Definition Journal.h:318
Stream debug() const
Definition Journal.h:300
Stream trace() const
Severity stream access functions.
Definition Journal.h:294
Stream warn() const
Definition Journal.h:312
virtual Config & config()=0
State information when applying a tx.
std::size_t size()
Get the number of unapplied changes.
STTx const & tx
void destroyXRP(XRPAmount const &fee)
ApplyFlags const & flags() const
void discard()
Discard changes and start fresh.
std::optional< TxMeta > apply(TER)
Apply the transaction result to the base.
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
TER const preclaimResult
Application & app
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.
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:114
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
uint32_t NETWORK_ID
Definition Config.h:138
RAII class to set and restore the current transaction rules.
Definition Rules.h:87
RAII class to set and restore the Number switchover.
Definition IOUAmount.h:190
A public key.
Definition PublicKey.h:42
A view into a ledger.
Definition ReadView.h:31
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
virtual bool open() const =0
Returns true if this reflects an open ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:97
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.
Definition Rules.cpp:118
XRPAmount xrp() const
Definition STAmount.cpp:249
size_type size() const
Definition STArray.h:223
virtual std::string getFullText() const
Definition STBase.cpp:62
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:624
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:327
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:576
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:663
void add(Serializer &s) const override
Definition STObject.cpp:117
bool isFlag(std::uint32_t) const
Definition STObject.cpp:486
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:606
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:384
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:632
std::uint32_t getFlags() const
Definition STObject.cpp:492
Json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:299
SeqProxy getSeqProxy() const
Definition STTx.cpp:193
uint256 getTransactionID() const
Definition STTx.h:192
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:36
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:56
constexpr bool isTicket() const
Definition SeqProxy.h:74
constexpr std::uint32_t value() const
Definition SeqProxy.h:62
constexpr bool isSeq() const
Definition SeqProxy.h:68
Slice slice() const noexcept
Definition Serializer.h:44
virtual LoadFeeTrack & getFeeTrack()=0
virtual std::optional< uint256 > const & trapTxID() const =0
virtual HashRouter & getHashRouter()=0
virtual beast::Journal journal(std::string const &name)=0
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
An immutable linear range of bytes.
Definition Slice.h:26
bool empty() const noexcept
Return true if the byte range is empty.
Definition Slice.h:49
static NotTEC preflight1(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the account and fee fields.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
TER consumeSeqProxy(SLE::pointer const &sleAccount)
AccountID const account_
Definition Transactor.h:112
void trapTransaction(uint256) const
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
static NotTEC checkSign(PreclaimContext const &ctx)
static XRPAmount calculateOwnerReserveFee(ReadView const &view, STTx const &tx)
ApplyResult operator()()
Process the transaction.
static NotTEC checkPermission(ReadView const &view, STTx const &tx)
static XRPAmount minimumFee(Application &app, XRPAmount baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
static NotTEC preflightSigValidated(PreflightContext const &ctx)
static NotTEC checkBatchSign(PreclaimContext const &ctx)
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
beast::Journal const j_
Definition Transactor.h:110
virtual TER doApply()=0
static NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
ApplyView & view()
Definition Transactor.h:128
static NotTEC checkSingleSign(ReadView const &view, AccountID const &idSigner, AccountID const &idAccount, std::shared_ptr< SLE const > sleAccount, beast::Journal const j)
Transactor(Transactor const &)=delete
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
XRPAmount mSourceBalance
Definition Transactor.h:114
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
XRPAmount mPriorBalance
Definition Transactor.h:113
static NotTEC checkMultiSign(ReadView const &view, ApplyFlags flags, AccountID const &id, STObject const &sigObject, beast::Journal const j)
static bool validDataLength(std::optional< Slice > const &slice, std::size_t maxLength)
virtual void preCompute()
ApplyContext & ctx_
Definition Transactor.h:108
std::pair< TER, XRPAmount > reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
T empty(T... args)
T is_same_v
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
NotTEC preflightCheckSigningKey(STObject const &sigObject, beast::Journal j)
Checks the validity of the transactor signing key.
std::optional< NotTEC > preflightCheckSimulateKeys(ApplyFlags flags, STObject const &sigObject, beast::Journal j)
Checks the special signing key state needed for simulation.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:287
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:375
static ticket_t const ticket
Definition Indexes.h:148
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:325
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:235
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Definition Indexes.cpp:406
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:486
bool deleteTokenOffer(ApplyView &view, std::shared_ptr< SLE > const &offer)
Deletes the given token offer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ telWRONG_NETWORK
Definition TER.h:45
@ telNETWORK_ID_MAKES_TX_NON_CANONICAL
Definition TER.h:47
@ telINSUF_FEE_P
Definition TER.h:37
@ telREQUIRES_NETWORK_ID
Definition TER.h:46
@ terPRE_SEQ
Definition TER.h:201
@ terINSUF_FEE_B
Definition TER.h:196
@ terNO_DELEGATE_PERMISSION
Definition TER.h:210
@ terNO_ACCOUNT
Definition TER.h:197
@ terPRE_TICKET
Definition TER.h:206
static void removeExpiredNFTokenOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
bool isLegalAmount(XRPAmount const &amount)
Returns true if the amount does not exceed the initial XRP in existence.
@ SigBad
Signature is bad. Didn't do local checks.
std::size_t constexpr expiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Definition Protocol.h:31
constexpr std::uint32_t tfInnerBatchTxn
Definition TxFlags.h:41
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:597
static void removeExpiredCredentials(ApplyView &view, std::vector< uint256 > const &creds, beast::Journal viewJ)
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
Definition applySteps.h:27
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
Definition Indexes.cpp:133
@ tefBAD_QUORUM
Definition TER.h:160
@ tefMAX_LEDGER
Definition TER.h:158
@ tefMASTER_DISABLED
Definition TER.h:157
@ tefALREADY
Definition TER.h:147
@ tefBAD_LEDGER
Definition TER.h:150
@ tefWRONG_PRIOR
Definition TER.h:156
@ tefNO_TICKET
Definition TER.h:165
@ tefBAD_SIGNATURE
Definition TER.h:159
@ tefINTERNAL
Definition TER.h:153
@ tefBAD_AUTH
Definition TER.h:149
@ tefPAST_SEQ
Definition TER.h:155
@ tefNOT_MULTI_SIGNING
Definition TER.h:161
std::uint16_t constexpr maxDeletableAMMTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:265
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:92
static void removeUnfundedOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
Definition View.cpp:3036
std::string transToken(TER code)
Definition TER.cpp:243
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Definition View.cpp:1020
std::size_t constexpr oversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
Definition Protocol.h:34
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:941
@ open
We haven't closed our ledger yet, but others might have.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3436
NotTEC checkTxPermission(std::shared_ptr< SLE const > const &delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
AccountID calcAccountID(PublicKey const &pk)
static void removeDeletedTrustLines(ApplyView &view, std::vector< uint256 > const &trustLines, beast::Journal viewJ)
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Definition apply.cpp:22
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1672
ApplyFlags
Definition ApplyView.h:10
@ tapDRY_RUN
Definition ApplyView.h:29
@ tapFAIL_HARD
Definition ApplyView.h:15
@ tapUNLIMITED
Definition ApplyView.h:22
@ tapBATCH
Definition ApplyView.h:25
@ temBAD_FEE
Definition TER.h:72
@ temINVALID
Definition TER.h:90
@ temINVALID_FLAG
Definition TER.h:91
@ temBAD_SRC_ACCOUNT
Definition TER.h:86
@ temSEQ_AND_TICKET
Definition TER.h:106
@ temDISABLED
Definition TER.h:94
@ temUNKNOWN
Definition TER.h:104
@ temBAD_SIGNATURE
Definition TER.h:85
@ temBAD_SIGNER
Definition TER.h:95
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
bool isTesSuccess(TER x) noexcept
Definition TER.h:649
std::size_t constexpr unfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
Definition Protocol.h:28
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid.
@ tecINSUFF_FEE
Definition TER.h:283
@ tecINCOMPLETE
Definition TER.h:316
@ tecINVARIANT_FAILED
Definition TER.h:294
@ tecEXPIRED
Definition TER.h:295
@ tecKILLED
Definition TER.h:297
@ tecOVERSIZE
Definition TER.h:292
bool isTecClaim(TER x) noexcept
Definition TER.h:656
@ lsfDisableMaster
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)
Definition Slice.h:213
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:580
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:776
@ tesSUCCESS
Definition TER.h:225
std::string to_short_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:604
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:43
T push_back(T... args)
T size(T... args)
Reflects the fee settings for a particular ledger.
XRPAmount increment
XRPAmount base
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:53
ReadView const & view
Definition Transactor.h:56
Application & app
Definition Transactor.h:55
beast::Journal const j
Definition Transactor.h:61
std::optional< uint256 const > const parentBatchId
Definition Transactor.h:60
State information when preflighting a tx.
Definition Transactor.h:15
beast::Journal const j
Definition Transactor.h:22
Application & app
Definition Transactor.h:17
std::optional< uint256 const > parentBatchId
Definition Transactor.h:21