mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add DeliverMin transaction field (RIPD-930)
This commit is contained in:
committed by
Vinnie Falco
parent
b7f07aed00
commit
4dc573f195
@@ -26,6 +26,7 @@
|
||||
#include <ripple/test/jtx/advance.h>
|
||||
#include <ripple/test/jtx/amount.h>
|
||||
#include <ripple/test/jtx/balance.h>
|
||||
#include <ripple/test/jtx/delivermin.h>
|
||||
#include <ripple/test/jtx/Env.h>
|
||||
#include <ripple/test/jtx/fee.h>
|
||||
#include <ripple/test/jtx/flags.h>
|
||||
|
||||
@@ -172,7 +172,7 @@ struct XRP_t
|
||||
std::int64_t, std::uint64_t>{v} *
|
||||
dropsPerXRP<T>::value };
|
||||
}
|
||||
|
||||
|
||||
PrettyAmount
|
||||
operator()(double v) const
|
||||
{
|
||||
|
||||
50
src/ripple/test/jtx/delivermin.h
Normal file
50
src/ripple/test/jtx/delivermin.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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_TEST_JTX_DELIVERMIN_H_INCLUDED
|
||||
#define RIPPLE_TEST_JTX_DELIVERMIN_H_INCLUDED
|
||||
|
||||
#include <ripple/test/jtx/Env.h>
|
||||
#include <ripple/protocol/STAmount.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
/** Sets the DeliverMin on a JTx. */
|
||||
class delivermin
|
||||
{
|
||||
private:
|
||||
STAmount amount_;
|
||||
|
||||
public:
|
||||
delivermin (STAmount const& amount)
|
||||
: amount_(amount)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
operator()(Env const&, JTx& jtx) const;
|
||||
};
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
@@ -52,6 +52,24 @@ PrettyAmount::operator AnyAmount() const
|
||||
return { amount_ };
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static
|
||||
std::string
|
||||
to_places(const T d, std::uint8_t places)
|
||||
{
|
||||
assert(places <= std::numeric_limits<T>::digits10);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << std::setprecision(places) << std::fixed << d;
|
||||
|
||||
std::string out = oss.str();
|
||||
out.erase(out.find_last_not_of('0') + 1, std::string::npos);
|
||||
if (out.back() == '.')
|
||||
out.pop_back();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os,
|
||||
PrettyAmount const& amount)
|
||||
@@ -72,11 +90,10 @@ operator<< (std::ostream& os,
|
||||
}
|
||||
auto const d = double(n) /
|
||||
dropsPerXRP<int>::value;
|
||||
os.precision(6);
|
||||
if (amount.value().negative())
|
||||
os << "-" << d << " XRP";
|
||||
else
|
||||
os << d << " XRP";
|
||||
os << "-";
|
||||
|
||||
os << to_places(d, 6) << " XRP";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
36
src/ripple/test/jtx/impl/delivermin.cpp
Normal file
36
src/ripple/test/jtx/impl/delivermin.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/test/jtx/delivermin.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
void
|
||||
delivermin::operator()(Env const& env, JTx& jt) const
|
||||
{
|
||||
jt.jv[jss::DeliverMin] = amount_.getJson(0);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
Reference in New Issue
Block a user