rippled
applySteps.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/tx/applySteps.h>
21 #include <ripple/app/tx/impl/AMMBid.h>
22 #include <ripple/app/tx/impl/AMMCreate.h>
23 #include <ripple/app/tx/impl/AMMDelete.h>
24 #include <ripple/app/tx/impl/AMMDeposit.h>
25 #include <ripple/app/tx/impl/AMMVote.h>
26 #include <ripple/app/tx/impl/AMMWithdraw.h>
27 #include <ripple/app/tx/impl/ApplyContext.h>
28 #include <ripple/app/tx/impl/CancelCheck.h>
29 #include <ripple/app/tx/impl/CancelOffer.h>
30 #include <ripple/app/tx/impl/CashCheck.h>
31 #include <ripple/app/tx/impl/Change.h>
32 #include <ripple/app/tx/impl/Clawback.h>
33 #include <ripple/app/tx/impl/CreateCheck.h>
34 #include <ripple/app/tx/impl/CreateOffer.h>
35 #include <ripple/app/tx/impl/CreateTicket.h>
36 #include <ripple/app/tx/impl/DeleteAccount.h>
37 #include <ripple/app/tx/impl/DepositPreauth.h>
38 #include <ripple/app/tx/impl/Escrow.h>
39 #include <ripple/app/tx/impl/NFTokenAcceptOffer.h>
40 #include <ripple/app/tx/impl/NFTokenBurn.h>
41 #include <ripple/app/tx/impl/NFTokenCancelOffer.h>
42 #include <ripple/app/tx/impl/NFTokenCreateOffer.h>
43 #include <ripple/app/tx/impl/NFTokenMint.h>
44 #include <ripple/app/tx/impl/PayChan.h>
45 #include <ripple/app/tx/impl/Payment.h>
46 #include <ripple/app/tx/impl/SetAccount.h>
47 #include <ripple/app/tx/impl/SetRegularKey.h>
48 #include <ripple/app/tx/impl/SetSignerList.h>
49 #include <ripple/app/tx/impl/SetTrust.h>
50 #include <ripple/app/tx/impl/XChainBridge.h>
51 #include <ripple/protocol/TxFormats.h>
52 
53 namespace ripple {
54 
55 // Templates so preflight does the right thing with T::ConsequencesFactory.
56 //
57 // This could be done more easily using if constexpr, but Visual Studio
58 // 2017 doesn't handle if constexpr correctly. So once we're no longer
59 // building with Visual Studio 2017 we can consider replacing the four
60 // templates with a single template function that uses if constexpr.
61 //
62 // For Transactor::Normal
63 template <
64  class T,
66 TxConsequences
68 {
69  return TxConsequences(ctx.tx);
70 };
71 
72 // For Transactor::Blocker
73 template <
74  class T,
76 TxConsequences
77 consequences_helper(PreflightContext const& ctx)
78 {
79  return TxConsequences(ctx.tx, TxConsequences::blocker);
80 };
81 
82 // For Transactor::Custom
83 template <
84  class T,
86 TxConsequences
87 consequences_helper(PreflightContext const& ctx)
88 {
89  return T::makeTxConsequences(ctx);
90 };
91 
92 template <class T>
95 {
96  auto const tec = T::preflight(ctx);
97  return {
98  tec,
99  isTesSuccess(tec) ? consequences_helper<T>(ctx) : TxConsequences{tec}};
100 }
101 
104 {
105  switch (ctx.tx.getTxnType())
106  {
107  case ttACCOUNT_DELETE:
108  return invoke_preflight_helper<DeleteAccount>(ctx);
109  case ttACCOUNT_SET:
110  return invoke_preflight_helper<SetAccount>(ctx);
111  case ttCHECK_CANCEL:
112  return invoke_preflight_helper<CancelCheck>(ctx);
113  case ttCHECK_CASH:
114  return invoke_preflight_helper<CashCheck>(ctx);
115  case ttCHECK_CREATE:
116  return invoke_preflight_helper<CreateCheck>(ctx);
117  case ttDEPOSIT_PREAUTH:
118  return invoke_preflight_helper<DepositPreauth>(ctx);
119  case ttOFFER_CANCEL:
120  return invoke_preflight_helper<CancelOffer>(ctx);
121  case ttOFFER_CREATE:
122  return invoke_preflight_helper<CreateOffer>(ctx);
123  case ttESCROW_CREATE:
124  return invoke_preflight_helper<EscrowCreate>(ctx);
125  case ttESCROW_FINISH:
126  return invoke_preflight_helper<EscrowFinish>(ctx);
127  case ttESCROW_CANCEL:
128  return invoke_preflight_helper<EscrowCancel>(ctx);
129  case ttPAYCHAN_CLAIM:
130  return invoke_preflight_helper<PayChanClaim>(ctx);
131  case ttPAYCHAN_CREATE:
132  return invoke_preflight_helper<PayChanCreate>(ctx);
133  case ttPAYCHAN_FUND:
134  return invoke_preflight_helper<PayChanFund>(ctx);
135  case ttPAYMENT:
136  return invoke_preflight_helper<Payment>(ctx);
137  case ttREGULAR_KEY_SET:
138  return invoke_preflight_helper<SetRegularKey>(ctx);
139  case ttSIGNER_LIST_SET:
140  return invoke_preflight_helper<SetSignerList>(ctx);
141  case ttTICKET_CREATE:
142  return invoke_preflight_helper<CreateTicket>(ctx);
143  case ttTRUST_SET:
144  return invoke_preflight_helper<SetTrust>(ctx);
145  case ttAMENDMENT:
146  case ttFEE:
147  case ttUNL_MODIFY:
148  return invoke_preflight_helper<Change>(ctx);
149  case ttNFTOKEN_MINT:
150  return invoke_preflight_helper<NFTokenMint>(ctx);
151  case ttNFTOKEN_BURN:
152  return invoke_preflight_helper<NFTokenBurn>(ctx);
154  return invoke_preflight_helper<NFTokenCreateOffer>(ctx);
156  return invoke_preflight_helper<NFTokenCancelOffer>(ctx);
158  return invoke_preflight_helper<NFTokenAcceptOffer>(ctx);
159  case ttCLAWBACK:
160  return invoke_preflight_helper<Clawback>(ctx);
161  case ttAMM_CREATE:
162  return invoke_preflight_helper<AMMCreate>(ctx);
163  case ttAMM_DEPOSIT:
164  return invoke_preflight_helper<AMMDeposit>(ctx);
165  case ttAMM_WITHDRAW:
166  return invoke_preflight_helper<AMMWithdraw>(ctx);
167  case ttAMM_VOTE:
168  return invoke_preflight_helper<AMMVote>(ctx);
169  case ttAMM_BID:
170  return invoke_preflight_helper<AMMBid>(ctx);
171  case ttAMM_DELETE:
172  return invoke_preflight_helper<AMMDelete>(ctx);
174  return invoke_preflight_helper<XChainCreateBridge>(ctx);
176  return invoke_preflight_helper<BridgeModify>(ctx);
178  return invoke_preflight_helper<XChainCreateClaimID>(ctx);
179  case ttXCHAIN_COMMIT:
180  return invoke_preflight_helper<XChainCommit>(ctx);
181  case ttXCHAIN_CLAIM:
182  return invoke_preflight_helper<XChainClaim>(ctx);
184  return invoke_preflight_helper<XChainAddClaimAttestation>(ctx);
186  return invoke_preflight_helper<XChainAddAccountCreateAttestation>(
187  ctx);
189  return invoke_preflight_helper<XChainCreateAccountCommit>(ctx);
190  default:
191  assert(false);
193  }
194 }
195 
196 /* invoke_preclaim<T> uses name hiding to accomplish
197  compile-time polymorphism of (presumably) static
198  class functions for Transactor and derived classes.
199 */
200 template <class T>
201 static TER
203 {
204  // If the transactor requires a valid account and the transaction doesn't
205  // list one, preflight will have already a flagged a failure.
206  auto const id = ctx.tx.getAccountID(sfAccount);
207 
208  if (id != beast::zero)
209  {
210  TER result = T::checkSeqProxy(ctx.view, ctx.tx, ctx.j);
211 
212  if (result != tesSUCCESS)
213  return result;
214 
215  result = T::checkPriorTxAndLastLedger(ctx);
216 
217  if (result != tesSUCCESS)
218  return result;
219 
220  result = T::checkFee(ctx, calculateBaseFee(ctx.view, ctx.tx));
221 
222  if (result != tesSUCCESS)
223  return result;
224 
225  result = T::checkSign(ctx);
226 
227  if (result != tesSUCCESS)
228  return result;
229  }
230 
231  return T::preclaim(ctx);
232 }
233 
234 static TER
235 invoke_preclaim(PreclaimContext const& ctx)
236 {
237  switch (ctx.tx.getTxnType())
238  {
239  case ttACCOUNT_DELETE:
240  return invoke_preclaim<DeleteAccount>(ctx);
241  case ttACCOUNT_SET:
242  return invoke_preclaim<SetAccount>(ctx);
243  case ttCHECK_CANCEL:
244  return invoke_preclaim<CancelCheck>(ctx);
245  case ttCHECK_CASH:
246  return invoke_preclaim<CashCheck>(ctx);
247  case ttCHECK_CREATE:
248  return invoke_preclaim<CreateCheck>(ctx);
249  case ttDEPOSIT_PREAUTH:
250  return invoke_preclaim<DepositPreauth>(ctx);
251  case ttOFFER_CANCEL:
252  return invoke_preclaim<CancelOffer>(ctx);
253  case ttOFFER_CREATE:
254  return invoke_preclaim<CreateOffer>(ctx);
255  case ttESCROW_CREATE:
256  return invoke_preclaim<EscrowCreate>(ctx);
257  case ttESCROW_FINISH:
258  return invoke_preclaim<EscrowFinish>(ctx);
259  case ttESCROW_CANCEL:
260  return invoke_preclaim<EscrowCancel>(ctx);
261  case ttPAYCHAN_CLAIM:
262  return invoke_preclaim<PayChanClaim>(ctx);
263  case ttPAYCHAN_CREATE:
264  return invoke_preclaim<PayChanCreate>(ctx);
265  case ttPAYCHAN_FUND:
266  return invoke_preclaim<PayChanFund>(ctx);
267  case ttPAYMENT:
268  return invoke_preclaim<Payment>(ctx);
269  case ttREGULAR_KEY_SET:
270  return invoke_preclaim<SetRegularKey>(ctx);
271  case ttSIGNER_LIST_SET:
272  return invoke_preclaim<SetSignerList>(ctx);
273  case ttTICKET_CREATE:
274  return invoke_preclaim<CreateTicket>(ctx);
275  case ttTRUST_SET:
276  return invoke_preclaim<SetTrust>(ctx);
277  case ttAMENDMENT:
278  case ttFEE:
279  case ttUNL_MODIFY:
280  return invoke_preclaim<Change>(ctx);
281  case ttNFTOKEN_MINT:
282  return invoke_preclaim<NFTokenMint>(ctx);
283  case ttNFTOKEN_BURN:
284  return invoke_preclaim<NFTokenBurn>(ctx);
286  return invoke_preclaim<NFTokenCreateOffer>(ctx);
288  return invoke_preclaim<NFTokenCancelOffer>(ctx);
290  return invoke_preclaim<NFTokenAcceptOffer>(ctx);
291  case ttCLAWBACK:
292  return invoke_preclaim<Clawback>(ctx);
293  case ttAMM_CREATE:
294  return invoke_preclaim<AMMCreate>(ctx);
295  case ttAMM_DEPOSIT:
296  return invoke_preclaim<AMMDeposit>(ctx);
297  case ttAMM_WITHDRAW:
298  return invoke_preclaim<AMMWithdraw>(ctx);
299  case ttAMM_VOTE:
300  return invoke_preclaim<AMMVote>(ctx);
301  case ttAMM_BID:
302  return invoke_preclaim<AMMBid>(ctx);
303  case ttAMM_DELETE:
304  return invoke_preclaim<AMMDelete>(ctx);
306  return invoke_preclaim<XChainCreateBridge>(ctx);
308  return invoke_preclaim<BridgeModify>(ctx);
310  return invoke_preclaim<XChainCreateClaimID>(ctx);
311  case ttXCHAIN_COMMIT:
312  return invoke_preclaim<XChainCommit>(ctx);
313  case ttXCHAIN_CLAIM:
314  return invoke_preclaim<XChainClaim>(ctx);
316  return invoke_preclaim<XChainCreateAccountCommit>(ctx);
318  return invoke_preclaim<XChainAddClaimAttestation>(ctx);
320  return invoke_preclaim<XChainAddAccountCreateAttestation>(ctx);
321  default:
322  assert(false);
323  return temUNKNOWN;
324  }
325 }
326 
327 static XRPAmount
328 invoke_calculateBaseFee(ReadView const& view, STTx const& tx)
329 {
330  switch (tx.getTxnType())
331  {
332  case ttACCOUNT_DELETE:
333  return DeleteAccount::calculateBaseFee(view, tx);
334  case ttACCOUNT_SET:
335  return SetAccount::calculateBaseFee(view, tx);
336  case ttCHECK_CANCEL:
337  return CancelCheck::calculateBaseFee(view, tx);
338  case ttCHECK_CASH:
339  return CashCheck::calculateBaseFee(view, tx);
340  case ttCHECK_CREATE:
341  return CreateCheck::calculateBaseFee(view, tx);
342  case ttDEPOSIT_PREAUTH:
343  return DepositPreauth::calculateBaseFee(view, tx);
344  case ttOFFER_CANCEL:
345  return CancelOffer::calculateBaseFee(view, tx);
346  case ttOFFER_CREATE:
347  return CreateOffer::calculateBaseFee(view, tx);
348  case ttESCROW_CREATE:
349  return EscrowCreate::calculateBaseFee(view, tx);
350  case ttESCROW_FINISH:
351  return EscrowFinish::calculateBaseFee(view, tx);
352  case ttESCROW_CANCEL:
353  return EscrowCancel::calculateBaseFee(view, tx);
354  case ttPAYCHAN_CLAIM:
355  return PayChanClaim::calculateBaseFee(view, tx);
356  case ttPAYCHAN_CREATE:
357  return PayChanCreate::calculateBaseFee(view, tx);
358  case ttPAYCHAN_FUND:
359  return PayChanFund::calculateBaseFee(view, tx);
360  case ttPAYMENT:
361  return Payment::calculateBaseFee(view, tx);
362  case ttREGULAR_KEY_SET:
363  return SetRegularKey::calculateBaseFee(view, tx);
364  case ttSIGNER_LIST_SET:
365  return SetSignerList::calculateBaseFee(view, tx);
366  case ttTICKET_CREATE:
367  return CreateTicket::calculateBaseFee(view, tx);
368  case ttTRUST_SET:
369  return SetTrust::calculateBaseFee(view, tx);
370  case ttAMENDMENT:
371  case ttFEE:
372  case ttUNL_MODIFY:
373  return Change::calculateBaseFee(view, tx);
374  case ttNFTOKEN_MINT:
375  return NFTokenMint::calculateBaseFee(view, tx);
376  case ttNFTOKEN_BURN:
377  return NFTokenBurn::calculateBaseFee(view, tx);
379  return NFTokenCreateOffer::calculateBaseFee(view, tx);
381  return NFTokenCancelOffer::calculateBaseFee(view, tx);
383  return NFTokenAcceptOffer::calculateBaseFee(view, tx);
384  case ttCLAWBACK:
385  return Clawback::calculateBaseFee(view, tx);
386  case ttAMM_CREATE:
387  return AMMCreate::calculateBaseFee(view, tx);
388  case ttAMM_DEPOSIT:
389  return AMMDeposit::calculateBaseFee(view, tx);
390  case ttAMM_WITHDRAW:
391  return AMMWithdraw::calculateBaseFee(view, tx);
392  case ttAMM_VOTE:
393  return AMMVote::calculateBaseFee(view, tx);
394  case ttAMM_BID:
395  return AMMBid::calculateBaseFee(view, tx);
396  case ttAMM_DELETE:
397  return AMMDelete::calculateBaseFee(view, tx);
399  return XChainCreateBridge::calculateBaseFee(view, tx);
401  return BridgeModify::calculateBaseFee(view, tx);
403  return XChainCreateClaimID::calculateBaseFee(view, tx);
404  case ttXCHAIN_COMMIT:
405  return XChainCommit::calculateBaseFee(view, tx);
406  case ttXCHAIN_CLAIM:
407  return XChainClaim::calculateBaseFee(view, tx);
412  view, tx);
415  default:
416  assert(false);
417  return XRPAmount{0};
418  }
419 }
420 
422  : isBlocker_(false)
423  , fee_(beast::zero)
424  , potentialSpend_(beast::zero)
425  , seqProx_(SeqProxy::sequence(0))
426  , sequencesConsumed_(0)
427 {
428  assert(!isTesSuccess(pfresult));
429 }
430 
432  : isBlocker_(false)
433  , fee_(
434  tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp()
435  : beast::zero)
436  , potentialSpend_(beast::zero)
437  , seqProx_(tx.getSeqProxy())
438  , sequencesConsumed_(tx.getSeqProxy().isSeq() ? 1 : 0)
439 {
440 }
441 
443  : TxConsequences(tx)
444 {
445  isBlocker_ = (category == blocker);
446 }
447 
449  : TxConsequences(tx)
450 {
452 }
453 
454 TxConsequences::TxConsequences(STTx const& tx, std::uint32_t sequencesConsumed)
455  : TxConsequences(tx)
456 {
458 }
459 
462 {
463  switch (ctx.tx.getTxnType())
464  {
465  case ttACCOUNT_DELETE: {
466  DeleteAccount p(ctx);
467  return p();
468  }
469  case ttACCOUNT_SET: {
470  SetAccount p(ctx);
471  return p();
472  }
473  case ttCHECK_CANCEL: {
474  CancelCheck p(ctx);
475  return p();
476  }
477  case ttCHECK_CASH: {
478  CashCheck p(ctx);
479  return p();
480  }
481  case ttCHECK_CREATE: {
482  CreateCheck p(ctx);
483  return p();
484  }
485  case ttDEPOSIT_PREAUTH: {
486  DepositPreauth p(ctx);
487  return p();
488  }
489  case ttOFFER_CANCEL: {
490  CancelOffer p(ctx);
491  return p();
492  }
493  case ttOFFER_CREATE: {
494  CreateOffer p(ctx);
495  return p();
496  }
497  case ttESCROW_CREATE: {
498  EscrowCreate p(ctx);
499  return p();
500  }
501  case ttESCROW_FINISH: {
502  EscrowFinish p(ctx);
503  return p();
504  }
505  case ttESCROW_CANCEL: {
506  EscrowCancel p(ctx);
507  return p();
508  }
509  case ttPAYCHAN_CLAIM: {
510  PayChanClaim p(ctx);
511  return p();
512  }
513  case ttPAYCHAN_CREATE: {
514  PayChanCreate p(ctx);
515  return p();
516  }
517  case ttPAYCHAN_FUND: {
518  PayChanFund p(ctx);
519  return p();
520  }
521  case ttPAYMENT: {
522  Payment p(ctx);
523  return p();
524  }
525  case ttREGULAR_KEY_SET: {
526  SetRegularKey p(ctx);
527  return p();
528  }
529  case ttSIGNER_LIST_SET: {
530  SetSignerList p(ctx);
531  return p();
532  }
533  case ttTICKET_CREATE: {
534  CreateTicket p(ctx);
535  return p();
536  }
537  case ttTRUST_SET: {
538  SetTrust p(ctx);
539  return p();
540  }
541  case ttAMENDMENT:
542  case ttFEE:
543  case ttUNL_MODIFY: {
544  Change p(ctx);
545  return p();
546  }
547  case ttNFTOKEN_MINT: {
548  NFTokenMint p(ctx);
549  return p();
550  }
551  case ttNFTOKEN_BURN: {
552  NFTokenBurn p(ctx);
553  return p();
554  }
555  case ttNFTOKEN_CREATE_OFFER: {
556  NFTokenCreateOffer p(ctx);
557  return p();
558  }
559  case ttNFTOKEN_CANCEL_OFFER: {
560  NFTokenCancelOffer p(ctx);
561  return p();
562  }
563  case ttNFTOKEN_ACCEPT_OFFER: {
564  NFTokenAcceptOffer p(ctx);
565  return p();
566  }
567  case ttCLAWBACK: {
568  Clawback p(ctx);
569  return p();
570  }
571  case ttAMM_CREATE: {
572  AMMCreate p(ctx);
573  return p();
574  }
575  case ttAMM_DEPOSIT: {
576  AMMDeposit p(ctx);
577  return p();
578  }
579  case ttAMM_WITHDRAW: {
580  AMMWithdraw p(ctx);
581  return p();
582  }
583  case ttAMM_VOTE: {
584  AMMVote p(ctx);
585  return p();
586  }
587  case ttAMM_BID: {
588  AMMBid p(ctx);
589  return p();
590  }
591  case ttAMM_DELETE: {
592  AMMDelete p(ctx);
593  return p();
594  }
595  case ttXCHAIN_CREATE_BRIDGE: {
596  XChainCreateBridge p(ctx);
597  return p();
598  }
599  case ttXCHAIN_MODIFY_BRIDGE: {
600  BridgeModify p(ctx);
601  return p();
602  }
604  XChainCreateClaimID p(ctx);
605  return p();
606  }
607  case ttXCHAIN_COMMIT: {
608  XChainCommit p(ctx);
609  return p();
610  }
611  case ttXCHAIN_CLAIM: {
612  XChainClaim p(ctx);
613  return p();
614  }
617  return p();
618  }
621  return p();
622  }
625  return p();
626  }
627  default:
628  assert(false);
629  return {temUNKNOWN, false};
630  }
631 }
632 
633 PreflightResult
635  Application& app,
636  Rules const& rules,
637  STTx const& tx,
638  ApplyFlags flags,
639  beast::Journal j)
640 {
641  PreflightContext const pfctx(app, tx, rules, flags, j);
642  try
643  {
644  return {pfctx, invoke_preflight(pfctx)};
645  }
646  catch (std::exception const& e)
647  {
648  JLOG(j.fatal()) << "apply: " << e.what();
649  return {pfctx, {tefEXCEPTION, TxConsequences{tx}}};
650  }
651 }
652 
653 PreclaimResult
655  PreflightResult const& preflightResult,
656  Application& app,
657  OpenView const& view)
658 {
660  if (preflightResult.rules != view.rules())
661  {
662  auto secondFlight = preflight(
663  app,
664  view.rules(),
665  preflightResult.tx,
666  preflightResult.flags,
667  preflightResult.j);
668  ctx.emplace(
669  app,
670  view,
671  secondFlight.ter,
672  secondFlight.tx,
673  secondFlight.flags,
674  secondFlight.j);
675  }
676  else
677  {
678  ctx.emplace(
679  app,
680  view,
681  preflightResult.ter,
682  preflightResult.tx,
683  preflightResult.flags,
684  preflightResult.j);
685  }
686  try
687  {
688  if (ctx->preflightResult != tesSUCCESS)
689  return {*ctx, ctx->preflightResult};
690  return {*ctx, invoke_preclaim(*ctx)};
691  }
692  catch (std::exception const& e)
693  {
694  JLOG(ctx->j.fatal()) << "apply: " << e.what();
695  return {*ctx, tefEXCEPTION};
696  }
697 }
698 
699 XRPAmount
700 calculateBaseFee(ReadView const& view, STTx const& tx)
701 {
702  return invoke_calculateBaseFee(view, tx);
703 }
704 
705 XRPAmount
706 calculateDefaultBaseFee(ReadView const& view, STTx const& tx)
707 {
708  return Transactor::calculateBaseFee(view, tx);
709 }
710 
712 doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view)
713 {
714  if (preclaimResult.view.seq() != view.seq())
715  {
716  // Logic error from the caller. Don't have enough
717  // info to recover.
718  return {tefEXCEPTION, false};
719  }
720  try
721  {
722  if (!preclaimResult.likelyToClaimFee)
723  return {preclaimResult.ter, false};
724  ApplyContext ctx(
725  app,
726  view,
727  preclaimResult.tx,
728  preclaimResult.ter,
729  calculateBaseFee(view, preclaimResult.tx),
730  preclaimResult.flags,
731  preclaimResult.j);
732  return invoke_apply(ctx);
733  }
734  catch (std::exception const& e)
735  {
736  JLOG(preclaimResult.j.fatal()) << "apply: " << e.what();
737  return {tefEXCEPTION, false};
738  }
739 }
740 
741 } // namespace ripple
ripple::AMMDeposit
AMMDeposit implements AMM deposit Transactor.
Definition: AMMDeposit.h:62
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:338
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:179
ripple::PayChanClaim
Definition: app/tx/impl/PayChan.h:72
ripple::ttNFTOKEN_CREATE_OFFER
@ ttNFTOKEN_CREATE_OFFER
This transaction creates a new offer to buy or sell an NFT.
Definition: TxFormats.h:134
ripple::consequences_helper
TxConsequences consequences_helper(PreflightContext const &ctx)
Definition: applySteps.cpp:67
ripple::Application
Definition: Application.h:116
ripple::PreclaimResult::view
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:197
ripple::ttACCOUNT_DELETE
@ ttACCOUNT_DELETE
This transaction type deletes an existing account.
Definition: TxFormats.h:122
ripple::ttAMM_DELETE
@ ttAMM_DELETE
This transaction type deletes AMM in the empty state.
Definition: TxFormats.h:161
ripple::PreclaimResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:203
ripple::XChainClaim
Definition: XChainBridge.h:81
ripple::NFTokenMint
Definition: NFTokenMint.h:28
ripple::TxConsequences::TxConsequences
TxConsequences(NotTEC pfresult)
Definition: applySteps.cpp:421
ripple::PreclaimContext::view
ReadView const & view
Definition: Transactor.h:56
ripple::AMMCreate::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: AMMCreate.cpp:82
std::exception
STL class.
ripple::PreclaimContext::j
const beast::Journal j
Definition: Transactor.h:60
ripple::ttREGULAR_KEY_SET
@ ttREGULAR_KEY_SET
This transaction type sets or clears an account's "regular key".
Definition: TxFormats.h:74
ripple::ttCLAWBACK
@ ttCLAWBACK
This transaction claws back issued tokens.
Definition: TxFormats.h:143
ripple::isTesSuccess
bool isTesSuccess(TER x)
Definition: TER.h:633
ripple::ttSIGNER_LIST_SET
@ ttSIGNER_LIST_SET
This transaction type modifies the signer list associated with an account.
Definition: TxFormats.h:95
ripple::ttXCHAIN_CLAIM
@ ttXCHAIN_CLAIM
This transaction completes a crosschain transaction.
Definition: TxFormats.h:170
std::pair
ripple::ttESCROW_CANCEL
@ ttESCROW_CANCEL
This transaction type cancels an existing escrow.
Definition: TxFormats.h:71
ripple::Payment
Definition: Payment.h:30
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::CreateCheck
Definition: CreateCheck.h:27
ripple::CancelOffer
Definition: CancelOffer.h:30
ripple::ttXCHAIN_CREATE_BRIDGE
@ ttXCHAIN_CREATE_BRIDGE
This transactions creates a sidechain.
Definition: TxFormats.h:185
ripple::ttFEE
@ ttFEE
This system-generated transaction type is used to update the network's fee settings.
Definition: TxFormats.h:198
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:29
ripple::ttAMM_DEPOSIT
@ ttAMM_DEPOSIT
This transaction type deposits into an AMM instance.
Definition: TxFormats.h:149
ripple::TxConsequences::Category
Category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:50
ripple::ttOFFER_CANCEL
@ ttOFFER_CANCEL
This transaction type cancels existing offers to trade one asset for another.
Definition: TxFormats.h:83
ripple::SetAccount
Definition: SetAccount.h:32
ripple::DepositPreauth
Definition: DepositPreauth.h:27
ripple::EscrowCreate
Definition: Escrow.h:27
ripple::ttPAYCHAN_CREATE
@ ttPAYCHAN_CREATE
This transaction type creates a new unidirectional XRP payment channel.
Definition: TxFormats.h:98
std::optional::emplace
T emplace(T... args)
ripple::BridgeModify
Definition: XChainBridge.h:52
ripple::invoke_calculateBaseFee
static XRPAmount invoke_calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: applySteps.cpp:328
ripple::AMMCreate
AMMCreate implements Automatic Market Maker(AMM) creation Transactor.
Definition: AMMCreate.h:57
ripple::ttXCHAIN_CREATE_CLAIM_ID
@ ttXCHAIN_CREATE_CLAIM_ID
This transactions creates a crosschain sequence number.
Definition: TxFormats.h:164
ripple::PreflightResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:154
ripple::preflight
PreflightResult preflight(Application &app, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
Definition: applySteps.cpp:634
ripple::ttNFTOKEN_ACCEPT_OFFER
@ ttNFTOKEN_ACCEPT_OFFER
This transaction accepts an existing offer to buy or sell an existing NFT.
Definition: TxFormats.h:140
ripple::Change::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Change.h:50
ripple::DeleteAccount
Definition: DeleteAccount.h:29
ripple::ttAMENDMENT
@ ttAMENDMENT
This system-generated transaction type is used to update the status of the various amendments.
Definition: TxFormats.h:192
ripple::XChainCommit
Definition: XChainBridge.h:106
ripple::PreclaimResult::likelyToClaimFee
const bool likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition: applySteps.h:209
ripple::PreclaimResult::ter
const TER ter
Intermediate transaction result.
Definition: applySteps.h:206
ripple::SetSignerList
See the README.md for an overview of the SetSignerList transaction that this class implements.
Definition: SetSignerList.h:42
ripple::ttCHECK_CANCEL
@ ttCHECK_CANCEL
This transaction type cancels an existing check.
Definition: TxFormats.h:113
ripple::ttPAYMENT
@ ttPAYMENT
This transaction type executes a payment.
Definition: TxFormats.h:59
ripple::Transactor::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:162
ripple::ttUNL_MODIFY
@ ttUNL_MODIFY
This system-generated transaction type is used to update the network's negative UNL.
Definition: TxFormats.h:204
ripple::doApply
std::pair< TER, bool > doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:712
ripple::ttCHECK_CREATE
@ ttCHECK_CREATE
This transaction type creates a new check.
Definition: TxFormats.h:107
ripple::PreflightResult
Describes the results of the preflight check.
Definition: applySteps.h:150
ripple::ttXCHAIN_COMMIT
@ ttXCHAIN_COMMIT
This transactions initiates a crosschain transaction.
Definition: TxFormats.h:167
std::enable_if_t
ripple::ttAMM_CREATE
@ ttAMM_CREATE
This transaction type creates an AMM instance.
Definition: TxFormats.h:146
ripple::TxConsequences::potentialSpend
XRPAmount const & potentialSpend() const
Potential Spend.
Definition: applySteps.h:108
ripple::PreflightResult::rules
const Rules rules
From the input - the rules.
Definition: applySteps.h:156
ripple::ttTRUST_SET
@ ttTRUST_SET
This transaction type modifies a trustline between two accounts.
Definition: TxFormats.h:119
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:589
ripple::TxConsequences::blocker
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:55
ripple::PreflightResult::ter
const NotTEC ter
Intermediate transaction result.
Definition: applySteps.h:165
ripple::TERSubset< CanCvtToTER >
ripple::Change
Definition: Change.h:32
ripple::ttNFTOKEN_MINT
@ ttNFTOKEN_MINT
This transaction mints a new NFT.
Definition: TxFormats.h:128
ripple::ttESCROW_CREATE
@ ttESCROW_CREATE
This transaction type creates an escrow object.
Definition: TxFormats.h:62
ripple::SetTrust
Definition: SetTrust.h:31
ripple::TER
TERSubset< CanCvtToTER > TER
Definition: TER.h:604
ripple::ttXCHAIN_MODIFY_BRIDGE
@ ttXCHAIN_MODIFY_BRIDGE
This transaction modifies a sidechain.
Definition: TxFormats.h:182
ripple::AMMVote
AMMVote implements AMM vote Transactor.
Definition: AMMVote.h:50
ripple::ttAMM_WITHDRAW
@ ttAMM_WITHDRAW
This transaction type withdraws from an AMM instance.
Definition: TxFormats.h:152
ripple::ttESCROW_FINISH
@ ttESCROW_FINISH
This transaction type completes an existing escrow.
Definition: TxFormats.h:65
ripple::invoke_preflight_helper
std::pair< NotTEC, TxConsequences > invoke_preflight_helper(PreflightContext const &ctx)
Definition: applySteps.cpp:94
ripple::AMMWithdraw
AMMWithdraw implements AMM withdraw Transactor.
Definition: AMMWithdraw.h:65
ripple::STTx
Definition: STTx.h:45
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::CreateOffer
Transactor specialized for creating offers in the ledger.
Definition: CreateOffer.h:34
std::uint32_t
ripple::temUNKNOWN
@ temUNKNOWN
Definition: TER.h:122
ripple::ttXCHAIN_ACCOUNT_CREATE_COMMIT
@ ttXCHAIN_ACCOUNT_CREATE_COMMIT
This transaction initiates a crosschain account create transaction.
Definition: TxFormats.h:173
ripple::NFTokenCreateOffer
Definition: NFTokenCreateOffer.h:27
ripple::TxConsequences::isBlocker_
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:61
ripple::PreclaimContext::tx
STTx const & tx
Definition: Transactor.h:58
ripple::ttNFTOKEN_CANCEL_OFFER
@ ttNFTOKEN_CANCEL_OFFER
This transaction cancels an existing offer to buy or sell an existing NFT.
Definition: TxFormats.h:137
ripple::ttOFFER_CREATE
@ ttOFFER_CREATE
This transaction type creates an offer to trade one asset for another.
Definition: TxFormats.h:80
ripple::XChainAddAccountCreateAttestation
Definition: XChainBridge.h:186
ripple::XChainCreateBridge
Definition: XChainBridge.h:33
ripple::invoke_apply
static std::pair< TER, bool > invoke_apply(ApplyContext &ctx)
Definition: applySteps.cpp:461
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:52
ripple::calculateDefaultBaseFee
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
Definition: applySteps.cpp:706
ripple::ttACCOUNT_SET
@ ttACCOUNT_SET
This transaction type adjusts various account settings.
Definition: TxFormats.h:68
ripple::preclaim
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:654
ripple::CancelCheck
Definition: CancelCheck.h:27
ripple::EscrowCancel
Definition: Escrow.h:72
ripple::TxConsequences::sequencesConsumed
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition: applySteps.h:122
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:54
ripple::NFTokenCancelOffer
Definition: NFTokenCancelOffer.h:27
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::invoke_preclaim
static TER invoke_preclaim(PreclaimContext const &ctx)
Definition: applySteps.cpp:202
ripple::SetRegularKey
Definition: SetRegularKey.h:30
ripple::PayChanFund
Definition: app/tx/impl/PayChan.h:51
ripple::ReadView::seq
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition: ReadView.h:122
ripple::ttDEPOSIT_PREAUTH
@ ttDEPOSIT_PREAUTH
This transaction type grants or revokes authorization to transfer funds.
Definition: TxFormats.h:116
ripple::XChainCreateClaimID
Definition: XChainBridge.h:138
ripple::Clawback
Definition: Clawback.h:27
ripple::ttCHECK_CASH
@ ttCHECK_CASH
This transaction type cashes an existing check.
Definition: TxFormats.h:110
ripple::PreclaimResult
Describes the results of the preclaim check.
Definition: applySteps.h:193
ripple::ttPAYCHAN_FUND
@ ttPAYCHAN_FUND
This transaction type funds an existing unidirectional XRP payment channel.
Definition: TxFormats.h:101
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::TxConsequences::potentialSpend_
XRPAmount potentialSpend_
Does NOT include the fee.
Definition: applySteps.h:65
ripple::ttAMM_VOTE
@ ttAMM_VOTE
This transaction type votes for the trading fee.
Definition: TxFormats.h:155
ripple::ttPAYCHAN_CLAIM
@ ttPAYCHAN_CLAIM
This transaction type submits a claim against an existing unidirectional payment channel.
Definition: TxFormats.h:104
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
ripple::calculateBaseFee
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:700
std::optional
ripple::ttNFTOKEN_BURN
@ ttNFTOKEN_BURN
This transaction burns (i.e.
Definition: TxFormats.h:131
ripple::PreclaimResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:201
ripple::sfFee
const SF_AMOUNT sfFee
ripple::AMMDelete
AMMDelete implements AMM delete transactor.
Definition: AMMDelete.h:33
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::PreflightResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:160
ripple::CreateTicket
Definition: CreateTicket.h:30
ripple::TxConsequences::sequencesConsumed_
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition: applySteps.h:69
ripple::EscrowFinish::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Escrow.cpp:354
ripple::XChainCreateAccountCommit
Definition: XChainBridge.h:232
ripple::tefEXCEPTION
@ tefEXCEPTION
Definition: TER.h:163
ripple::PreflightContext::tx
STTx const & tx
Definition: Transactor.h:35
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:31
ripple::AMMBid
AMMBid implements AMM bid Transactor.
Definition: AMMBid.h:65
ripple::XChainAddClaimAttestation
Definition: XChainBridge.h:166
ripple::CashCheck
Definition: CashCheck.h:27
ripple::PayChanCreate
Definition: app/tx/impl/PayChan.h:27
ripple::NFTokenBurn
Definition: NFTokenBurn.h:27
ripple::TxConsequences
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:45
ripple::SetRegularKey::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: SetRegularKey.cpp:28
ripple::EscrowFinish
Definition: Escrow.h:51
ripple::DeleteAccount::calculateBaseFee
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: DeleteAccount.cpp:56
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:233
ripple::OpenView::rules
Rules const & rules() const override
Returns the tx processing rules.
Definition: OpenView.cpp:152
ripple::invoke_preflight
static std::pair< NotTEC, TxConsequences > invoke_preflight(PreflightContext const &ctx)
Definition: applySteps.cpp:103
ripple::ttXCHAIN_ADD_ACCOUNT_CREATE_ATTESTATION
@ ttXCHAIN_ADD_ACCOUNT_CREATE_ATTESTATION
This transaction adds an attestation to a claimid.
Definition: TxFormats.h:179
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:48
ripple::ttTICKET_CREATE
@ ttTICKET_CREATE
This transaction type creates a new set of tickets.
Definition: TxFormats.h:89
std::exception::what
T what(T... args)
ripple::PreclaimResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:199
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::ttAMM_BID
@ ttAMM_BID
This transaction type bids for the auction slot.
Definition: TxFormats.h:158
ripple::NFTokenAcceptOffer
Definition: NFTokenAcceptOffer.h:27
ripple::PreflightResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:162
ripple::ttXCHAIN_ADD_CLAIM_ATTESTATION
@ ttXCHAIN_ADD_CLAIM_ATTESTATION
This transaction adds an attestation to a claimid.
Definition: TxFormats.h:176
beast
Definition: base_uint.h:641