From 0952ebfc1d7a2c1dd3aa185d3255e5ecd6c50323 Mon Sep 17 00:00:00 2001 From: Scott Schurr Date: Mon, 13 Jun 2016 11:32:48 -0700 Subject: [PATCH] Add jtx support for trust line quality (RIPD-1094) --- Builds/VisualStudio2015/RippleD.vcxproj | 6 ++ .../VisualStudio2015/RippleD.vcxproj.filters | 6 ++ src/ripple/test/jtx.h | 1 + src/ripple/test/jtx/impl/quality.cpp | 73 +++++++++++++++ src/ripple/test/jtx/quality.h | 91 +++++++++++++++++++ src/ripple/unity/test.cpp | 1 + 6 files changed, 178 insertions(+) create mode 100644 src/ripple/test/jtx/impl/quality.cpp create mode 100644 src/ripple/test/jtx/quality.h diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 34a50db41..c60aa5f23 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -3603,6 +3603,10 @@ True True + + True + True + True True @@ -3663,6 +3667,8 @@ + + diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 8c9052946..af26d08d3 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -4065,6 +4065,9 @@ ripple\test\jtx\impl + + ripple\test\jtx\impl + ripple\test\jtx\impl @@ -4125,6 +4128,9 @@ ripple\test\jtx + + ripple\test\jtx + ripple\test\jtx diff --git a/src/ripple/test/jtx.h b/src/ripple/test/jtx.h index c30f0c8fd..24766929c 100644 --- a/src/ripple/test/jtx.h +++ b/src/ripple/test/jtx.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ripple/test/jtx/impl/quality.cpp b/src/ripple/test/jtx/impl/quality.cpp new file mode 100644 index 000000000..3d0e634a2 --- /dev/null +++ b/src/ripple/test/jtx/impl/quality.cpp @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2016 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 +#include +#include +#include + +namespace ripple { +namespace test { +namespace jtx { + +qualityInPercent::qualityInPercent (double percent) +: qIn_ (static_cast((percent / 100) * QUALITY_ONE)) +{ + assert (percent <= 400 && percent >= 0); +} + +qualityOutPercent::qualityOutPercent (double percent) +: qOut_ (static_cast((percent / 100) * QUALITY_ONE)) +{ + assert (percent <= 400 && percent >= 0); +} + +static void +insertQualityIntoJtx (SField const& field, std::uint32_t value, JTx& jt) +{ + jt.jv[field.jsonName] = value; +} + +void +qualityIn::operator()(Env&, JTx& jt) const +{ + insertQualityIntoJtx (sfQualityIn, qIn_, jt); +} + +void +qualityInPercent::operator()(Env&, JTx& jt) const +{ + insertQualityIntoJtx (sfQualityIn, qIn_, jt); +} + +void +qualityOut::operator()(Env&, JTx& jt) const +{ + insertQualityIntoJtx (sfQualityOut, qOut_, jt); +} + +void +qualityOutPercent::operator()(Env&, JTx& jt) const +{ + insertQualityIntoJtx (sfQualityOut, qOut_, jt); +} + +} // jtx +} // test +} // ripple diff --git a/src/ripple/test/jtx/quality.h b/src/ripple/test/jtx/quality.h new file mode 100644 index 000000000..562e5933c --- /dev/null +++ b/src/ripple/test/jtx/quality.h @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2016 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_QUALITY_H_INCLUDED +#define RIPPLE_TEST_JTX_QUALITY_H_INCLUDED + +#include + +namespace ripple { +namespace test { +namespace jtx { + +/** Sets the literal QualityIn on a trust JTx. */ +class qualityIn +{ +private: + std::uint32_t qIn_; + +public: + explicit qualityIn (std::uint32_t qIn) + : qIn_ (qIn) + { + } + + void + operator()(Env&, JTx& jtx) const; +}; + +/** Sets the QualityIn on a trust JTx as a percentage. */ +class qualityInPercent +{ +private: + std::uint32_t qIn_; + +public: + explicit qualityInPercent (double percent); + + void + operator()(Env&, JTx& jtx) const; +}; + +/** Sets the literal QualityOut on a trust JTx. */ +class qualityOut +{ +private: + std::uint32_t qOut_; + +public: + explicit qualityOut (std::uint32_t qOut) + : qOut_ (qOut) + { + } + + void + operator()(Env&, JTx& jtx) const; +}; + +/** Sets the QualityOut on a trust JTx as a percentage. */ +class qualityOutPercent +{ +private: + std::uint32_t qOut_; + +public: + explicit qualityOutPercent (double percent); + + void + operator()(Env&, JTx& jtx) const; +}; + +} // jtx +} // test +} // ripple + +#endif diff --git a/src/ripple/unity/test.cpp b/src/ripple/unity/test.cpp index 630a51f31..9e91807bb 100644 --- a/src/ripple/unity/test.cpp +++ b/src/ripple/unity/test.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include