Convert STAmount switchovers to tls (RIPD-1068)

This commit is contained in:
Miguel Portilla
2016-01-08 15:00:55 -05:00
committed by Edward Hennis
parent 4fb6bf3e67
commit 14dde47173
17 changed files with 93 additions and 142 deletions

View File

@@ -21,6 +21,7 @@
#define RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED
#include <ripple/basics/chrono.h>
#include <ripple/basics/LocalValue.h>
#include <ripple/protocol/SField.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/STBase.h>
@@ -378,32 +379,14 @@ divide (STAmount const& v1, STAmount const& v2, Issue const& issue);
STAmount
multiply (STAmount const& v1, STAmount const& v2, Issue const& issue);
/** Control when bugfixes that require switchover dates are enabled */
class STAmountCalcSwitchovers
{
bool enableUnderflowFix_ {false};
public:
STAmountCalcSwitchovers () = delete;
explicit
STAmountCalcSwitchovers (NetClock::time_point parentCloseTime);
explicit
STAmountCalcSwitchovers (bool enableAll)
: enableUnderflowFix_ (enableAll) {}
bool enableUnderflowFix () const;
// for tests
static NetClock::time_point enableUnderflowFixCloseTime ();
};
// multiply, or divide rounding result in specified direction
STAmount
mulRound (STAmount const& v1, STAmount const& v2,
Issue const& issue, bool roundUp,
STAmountCalcSwitchovers const& switchovers);
Issue const& issue, bool roundUp);
STAmount
divRound (STAmount const& v1, STAmount const& v2,
Issue const& issue, bool roundUp,
STAmountCalcSwitchovers const& switchovers);
Issue const& issue, bool roundUp);
// Someone is offering X for Y, what is the rate?
// Rate: smaller is better, the taker wants the most out: in/out
@@ -418,6 +401,30 @@ inline bool isXRP(STAmount const& amount)
return isXRP (amount.issue().currency);
}
extern LocalValue<bool> stAmountCalcSwitchover;
/** RAII class to set and restore the STAmount calc switchover.*/
class STAmountSO
{
public:
explicit STAmountSO(NetClock::time_point const closeTime)
: saved_(*stAmountCalcSwitchover)
{
*stAmountCalcSwitchover = closeTime <= soTime;
}
~STAmountSO()
{
*stAmountCalcSwitchover = saved_;
}
// Mon Dec 28, 2015 10:00:00am PST
static NetClock::time_point const soTime;
private:
bool saved_;
};
} // ripple
#endif