rippled
RippleCalc.h
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 #ifndef RIPPLE_APP_PATHS_RIPPLECALC_H_INCLUDED
21 #define RIPPLE_APP_PATHS_RIPPLECALC_H_INCLUDED
22 
23 #include <ripple/basics/Log.h>
24 #include <ripple/ledger/PaymentSandbox.h>
25 #include <ripple/protocol/STAmount.h>
26 #include <ripple/protocol/TER.h>
27 
28 #include <boost/container/flat_set.hpp>
29 
30 namespace ripple {
31 class Config;
32 namespace path {
33 
34 namespace detail {
35 struct FlowDebugInfo;
36 }
37 
44 {
45 public:
46  struct Input
47  {
48  explicit Input() = default;
49 
50  bool partialPaymentAllowed = false;
51  bool defaultPathsAllowed = true;
52  bool limitQuality = false;
53  bool isLedgerOpen = true;
54  };
55  struct Output
56  {
57  explicit Output() = default;
58 
59  // The computed input amount.
61 
62  // The computed output amount.
64 
65  // Collection of offers found expired or unfunded. When a payment
66  // succeeds, unfunded and expired offers are removed. When a payment
67  // fails, they are not removed. This vector contains the offers that
68  // could have been removed but were not because the payment fails. It is
69  // useful for offer crossing, which does remove the offers.
70  boost::container::flat_set<uint256> removableOffers;
71 
72  private:
74 
75  public:
76  TER
77  result() const
78  {
79  return calculationResult_;
80  }
81  void
82  setResult(TER const value)
83  {
84  calculationResult_ = value;
85  }
86  };
87 
88  static Output
91 
92  // Compute paths using this ledger entry set. Up to caller to actually
93  // apply to ledger.
94 
95  // Issuer:
96  // XRP: xrpAccount()
97  // non-XRP: uSrcAccountID (for any issuer) or another account with
98  // trust node.
99  STAmount const& saMaxAmountReq, // --> -1 = no limit.
100 
101  // Issuer:
102  // XRP: xrpAccount()
103  // non-XRP: uDstAccountID (for any issuer) or another account with
104  // trust node.
105  STAmount const& saDstAmountReq,
106 
107  AccountID const& uDstAccountID,
108  AccountID const& uSrcAccountID,
109 
110  // A set of paths that are included in the transaction that we'll
111  // explore for liquidity.
112  STPathSet const& spsPaths,
113  Logs& l,
114  Input const* const pInputs = nullptr);
115 
116  // The view we are currently working on
118 
119  // If the transaction fails to meet some constraint, still need to delete
120  // unfunded offers in a deterministic order (hence the ordered container).
121  //
122  // Offers that were found unfunded.
123  boost::container::flat_set<uint256> permanentlyUnfundedOffers_;
124 };
125 
126 } // namespace path
127 } // namespace ripple
128 
129 #endif
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
ripple::path::RippleCalc
RippleCalc calculates the quality of a payment path.
Definition: RippleCalc.h:43
ripple::PaymentSandbox
A wrapper which makes credits unavailable to balances.
Definition: PaymentSandbox.h:112
ripple::path::RippleCalc::Input
Definition: RippleCalc.h:46
ripple::STPathSet
Definition: STPathSet.h:176
ripple::path::RippleCalc::Output::removableOffers
boost::container::flat_set< uint256 > removableOffers
Definition: RippleCalc.h:70
ripple::base_uint< 160, detail::AccountIDTag >
ripple::path::RippleCalc::Input::isLedgerOpen
bool isLedgerOpen
Definition: RippleCalc.h:53
ripple::path::RippleCalc::Input::defaultPathsAllowed
bool defaultPathsAllowed
Definition: RippleCalc.h:51
ripple::TERSubset< CanCvtToTER >
ripple::STAmount
Definition: STAmount.h:45
ripple::path::RippleCalc::Output::actualAmountOut
STAmount actualAmountOut
Definition: RippleCalc.h:63
ripple::path::RippleCalc::Output::actualAmountIn
STAmount actualAmountIn
Definition: RippleCalc.h:60
ripple::temUNKNOWN
@ temUNKNOWN
Definition: TER.h:122
ripple::path::RippleCalc::Output
Definition: RippleCalc.h:55
ripple::path::RippleCalc::Output::result
TER result() const
Definition: RippleCalc.h:77
ripple::path::RippleCalc::view
PaymentSandbox & view
Definition: RippleCalc.h:117
ripple::path::RippleCalc::Output::Output
Output()=default
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::path::RippleCalc::rippleCalculate
static Output rippleCalculate(PaymentSandbox &view, STAmount const &saMaxAmountReq, STAmount const &saDstAmountReq, AccountID const &uDstAccountID, AccountID const &uSrcAccountID, STPathSet const &spsPaths, Logs &l, Input const *const pInputs=nullptr)
Definition: RippleCalc.cpp:31
ripple::path::RippleCalc::Input::partialPaymentAllowed
bool partialPaymentAllowed
Definition: RippleCalc.h:50
ripple::path::RippleCalc::Output::calculationResult_
TER calculationResult_
Definition: RippleCalc.h:73
ripple::path::RippleCalc::Output::setResult
void setResult(TER const value)
Definition: RippleCalc.h:82
ripple::path::RippleCalc::Input::limitQuality
bool limitQuality
Definition: RippleCalc.h:52
ripple::path::RippleCalc::permanentlyUnfundedOffers_
boost::container::flat_set< uint256 > permanentlyUnfundedOffers_
Definition: RippleCalc.h:123
ripple::path::RippleCalc::Input::Input
Input()=default