Files
xahaud/src/ripple/ledger/tests/PathSet.h
Edward Hennis 6464d1abc1 Clean up src/ripple/app/tx directory:
* Move InboundTransactions to app/ledger
* Move TransactionAcquire to app/ledger
* Move LocalTxs to app/ledger
* Move Transaction to app/misc
* Move TransactionMaster to app/ledger
2015-10-28 11:37:15 -04:00

137 lines
3.7 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2015 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.
*/
//==============================================================================
#include <ripple/basics/Log.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/test/jtx.h>
namespace ripple {
namespace test {
/** An offer exists
*/
inline
bool
isOffer (jtx::Env& env,
jtx::Account const& account,
STAmount const& takerPays,
STAmount const& takerGets)
{
bool exists = false;
forEachItem (*env.open(), account,
[&](std::shared_ptr<SLE const> const& sle)
{
if (sle->getType () == ltOFFER &&
sle->getFieldAmount (sfTakerPays) == takerPays &&
sle->getFieldAmount (sfTakerGets) == takerGets)
exists = true;
});
return exists;
}
class Path
{
public:
STPath path;
Path () = default;
Path (Path const&) = default;
Path& operator=(Path const&) = default;
Path (Path&&) = default;
Path& operator=(Path&&) = default;
template <class First, class... Rest>
explicit Path (First&& first, Rest&&... rest)
{
addHelper (std::forward<First> (first), std::forward<Rest> (rest)...);
}
Path& push_back (Issue const& iss);
Path& push_back (jtx::Account const& acc);
Json::Value json () const;
private:
Path& addHelper (){return *this;};
template <class First, class... Rest>
Path& addHelper (First&& first, Rest&&... rest);
};
inline Path& Path::push_back (Issue const& iss)
{
path.emplace_back (STPathElement::typeCurrency | STPathElement::typeIssuer,
zero, iss.currency, iss.account);
return *this;
}
inline
Path& Path::push_back (jtx::Account const& account)
{
path.emplace_back (account.id (), zero, zero);
return *this;
}
template <class First, class... Rest>
Path& Path::addHelper (First&& first, Rest&&... rest)
{
push_back (std::forward<First> (first));
return addHelper (std::forward<Rest> (rest)...);
}
inline
Json::Value Path::json () const
{
return path.getJson (0);
}
class PathSet
{
public:
STPathSet paths;
PathSet () = default;
PathSet (PathSet const&) = default;
PathSet& operator=(PathSet const&) = default;
PathSet (PathSet&&) = default;
PathSet& operator=(PathSet&&) = default;
template <class First, class... Rest>
explicit PathSet (First&& first, Rest&&... rest)
{
addHelper (std::forward<First> (first), std::forward<Rest> (rest)...);
}
Json::Value json () const
{
Json::Value v;
v["Paths"] = paths.getJson (0);
return v;
}
private:
PathSet& addHelper ()
{
return *this;
};
template <class First, class... Rest>
PathSet& addHelper (First first, Rest... rest)
{
paths.emplace_back (std::move (first.path));
return addHelper (std::move (rest)...);
}
};
} // test
} // ripple