Add units to all fee calculations:

* Uses existing XRPAmount with units for drops, and a new TaggedFee for
  fee units (LoadFeeTrack), and fee levels (TxQ).
* Resolves #2451
This commit is contained in:
Edward Hennis
2019-02-14 18:59:07 -05:00
parent 1901b981f3
commit e3b5b808c5
87 changed files with 2195 additions and 681 deletions

View File

@@ -205,6 +205,7 @@ STAmount::STAmount (SField const& name,
, mIsNative (true)
, mIsNegative (negative)
{
assert(mValue <= std::numeric_limits<std::int64_t>::max());
}
STAmount::STAmount (SField const& name, Issue const& issue,
@@ -215,6 +216,7 @@ STAmount::STAmount (SField const& name, Issue const& issue,
, mOffset (exponent)
, mIsNegative (negative)
{
assert(mValue <= std::numeric_limits<std::int64_t>::max());
canonicalize ();
}
@@ -226,6 +228,7 @@ STAmount::STAmount (std::uint64_t mantissa, bool negative)
, mIsNative (true)
, mIsNegative (mantissa != 0 && negative)
{
assert(mValue <= std::numeric_limits<std::int64_t>::max());
}
STAmount::STAmount (Issue const& issue,
@@ -235,6 +238,7 @@ STAmount::STAmount (Issue const& issue,
, mOffset (exponent)
, mIsNegative (negative)
{
assert(mValue <= std::numeric_limits<std::int64_t>::max());
canonicalize ();
}
@@ -280,9 +284,9 @@ STAmount::STAmount (XRPAmount const& amount)
, mIsNegative (amount < beast::zero)
{
if (mIsNegative)
mValue = static_cast<std::uint64_t> (-amount.drops ());
mValue = unsafe_cast<std::uint64_t> (-amount.drops ());
else
mValue = static_cast<std::uint64_t> (amount.drops ());
mValue = unsafe_cast<std::uint64_t> (amount.drops ());
canonicalize ();
}
@@ -298,20 +302,23 @@ STAmount::construct (SerialIter& sit, SField const& name)
// Conversion
//
//------------------------------------------------------------------------------
XRPAmount STAmount::xrp () const
XRPAmount
STAmount::xrp () const
{
if (!mIsNative)
Throw<std::logic_error> ("Cannot return non-native STAmount as XRPAmount");
Throw<std::logic_error> (
"Cannot return non-native STAmount as XRPAmount");
auto drops = static_cast<std::int64_t> (mValue);
auto drops = static_cast<XRPAmount::value_type> (mValue);
if (mIsNegative)
drops = -drops;
return { drops };
return XRPAmount{ drops };
}
IOUAmount STAmount::iou () const
IOUAmount
STAmount::iou () const
{
if (mIsNative)
Throw<std::logic_error> ("Cannot return native STAmount as IOUAmount");