mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-07 18:56:47 +00:00
This shores up the View interface support for contextual transaction processing by putting params in the View, and provides support for replacing the open ledger with the open MetaView. Transaction metadata is now part of the View interface. Stacked MetaViews correctly apply their transaction metadata to the parent. * Add lastCloseTime to View * Add insertTx to View, implement in MetaView * Add View::txExists for transaction checking * Add Fees to View, cache fees in Ledger and MetaView * Use ViewFlags in View * Use tapENABLE_TESTING flag for features * Use cached Fees in View * Rename to ViewFlags * Move FreezeHandling to View.h, remove ViewAPIBasics.h * Remove BasicView::parent hack * Remove calls to getLedger in Transactors
181 lines
5.7 KiB
C++
181 lines
5.7 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef RIPPLE_APP_PATHS_PATHSTATE_H_INCLUDED
|
|
#define RIPPLE_APP_PATHS_PATHSTATE_H_INCLUDED
|
|
|
|
#include <ripple/app/ledger/MetaView.h>
|
|
#include <ripple/app/paths/Node.h>
|
|
#include <ripple/app/paths/Types.h>
|
|
#include <ripple/app/paths/impl/PaymentView.h>
|
|
#include <boost/optional.hpp>
|
|
|
|
namespace ripple {
|
|
|
|
// Holds a single path state under incremental application.
|
|
class PathState : public CountedObject <PathState>
|
|
{
|
|
public:
|
|
using OfferIndexList = std::vector<uint256>;
|
|
using Ptr = std::shared_ptr<PathState>;
|
|
using List = std::vector<Ptr>;
|
|
|
|
PathState (PaymentView const& parent,
|
|
STAmount const& saSend,
|
|
STAmount const& saSendMax)
|
|
: mIndex (0)
|
|
, uQuality (0)
|
|
, saInReq (saSendMax)
|
|
, saOutReq (saSend)
|
|
{
|
|
view_.emplace(&parent);
|
|
}
|
|
|
|
void reset(STAmount const& in, STAmount const& out);
|
|
|
|
TER expandPath (
|
|
STPath const& spSourcePath,
|
|
AccountID const& uReceiverID,
|
|
AccountID const& uSenderID
|
|
);
|
|
|
|
path::Node::List& nodes() { return nodes_; }
|
|
|
|
STAmount const& inPass() const { return saInPass; }
|
|
STAmount const& outPass() const { return saOutPass; }
|
|
STAmount const& outReq() const { return saOutReq; }
|
|
|
|
STAmount const& inAct() const { return saInAct; }
|
|
STAmount const& outAct() const { return saOutAct; }
|
|
STAmount const& inReq() const { return saInReq; }
|
|
|
|
void setInPass(STAmount const& sa)
|
|
{
|
|
saInPass = sa;
|
|
}
|
|
|
|
void setOutPass(STAmount const& sa)
|
|
{
|
|
saOutPass = sa;
|
|
}
|
|
|
|
AccountIssueToNodeIndex const& forward() { return umForward; }
|
|
AccountIssueToNodeIndex const& reverse() { return umReverse; }
|
|
|
|
void insertReverse (AccountIssue const& ai, path::NodeIndex i)
|
|
{
|
|
umReverse.insert({ai, i});
|
|
}
|
|
|
|
static char const* getCountedObjectName () { return "PathState"; }
|
|
OfferIndexList& unfundedOffers() { return unfundedOffers_; }
|
|
|
|
void setStatus(TER status) { terStatus = status; }
|
|
TER status() const { return terStatus; }
|
|
|
|
std::uint64_t quality() const { return uQuality; }
|
|
void setQuality (std::uint64_t q) { uQuality = q; }
|
|
|
|
bool allLiquidityConsumed() const { return allLiquidityConsumed_; }
|
|
void consumeAllLiquidity () { allLiquidityConsumed_ = true; }
|
|
|
|
void setIndex (int i) { mIndex = i; }
|
|
int index() const { return mIndex; }
|
|
|
|
TER checkNoRipple (AccountID const& destinationAccountID,
|
|
AccountID const& sourceAccountID);
|
|
void checkFreeze ();
|
|
|
|
static bool lessPriority (PathState const& lhs, PathState const& rhs);
|
|
|
|
PaymentView&
|
|
view()
|
|
{
|
|
return *view_;
|
|
}
|
|
|
|
void resetView (PaymentView const& view)
|
|
{
|
|
view_.emplace(&view);
|
|
}
|
|
|
|
bool isDry() const
|
|
{
|
|
return !(saInPass && saOutPass);
|
|
}
|
|
|
|
private:
|
|
TER checkNoRipple (
|
|
AccountID const&, AccountID const&, AccountID const&, Currency const&);
|
|
|
|
/** Clear path structures, and clear each node. */
|
|
void clear();
|
|
|
|
TER pushNode (
|
|
int const iType,
|
|
AccountID const& account,
|
|
Currency const& currency,
|
|
AccountID const& issuer);
|
|
|
|
TER pushImpliedNodes (
|
|
AccountID const& account,
|
|
Currency const& currency,
|
|
AccountID const& issuer);
|
|
|
|
Json::Value getJson () const;
|
|
|
|
private:
|
|
boost::optional<PaymentView> view_;
|
|
|
|
int mIndex; // Index/rank amoung siblings.
|
|
std::uint64_t uQuality; // 0 = no quality/liquity left.
|
|
|
|
STAmount const& saInReq; // --> Max amount to spend by sender.
|
|
STAmount saInAct; // --> Amount spent by sender so far.
|
|
STAmount saInPass; // <-- Amount spent by sender.
|
|
|
|
STAmount const& saOutReq; // --> Amount to send.
|
|
STAmount saOutAct; // --> Amount actually sent so far.
|
|
STAmount saOutPass; // <-- Amount actually sent.
|
|
|
|
// If true, all liquidity on this path has been consumed.
|
|
bool allLiquidityConsumed_ = false;
|
|
|
|
TER terStatus;
|
|
|
|
path::Node::List nodes_;
|
|
|
|
// When processing, don't want to complicate directory walking with
|
|
// deletion. Offers that became unfunded or were completely consumed go
|
|
// here and are deleted at the end.
|
|
OfferIndexList unfundedOffers_;
|
|
|
|
// First time scanning foward, as part of path construction, a funding
|
|
// source was mentioned for accounts. Source may only be used there.
|
|
AccountIssueToNodeIndex umForward;
|
|
|
|
// First time working in reverse a funding source was used.
|
|
// Source may only be used there if not mentioned by an account.
|
|
AccountIssueToNodeIndex umReverse;
|
|
};
|
|
|
|
} // ripple
|
|
|
|
#endif
|