3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/contract.h>
6#include <xrpl/basics/safe_cast.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/beast/utility/Zero.h>
9#include <xrpl/beast/utility/instrumentation.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Asset.h>
13#include <xrpl/protocol/Concepts.h>
14#include <xrpl/protocol/IOUAmount.h>
15#include <xrpl/protocol/Issue.h>
16#include <xrpl/protocol/MPTAmount.h>
17#include <xrpl/protocol/MPTIssue.h>
18#include <xrpl/protocol/Protocol.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/STBase.h>
21#include <xrpl/protocol/Serializer.h>
22#include <xrpl/protocol/XRPAmount.h>
23#include <xrpl/protocol/json_get_or_throw.h>
68 static_assert(
kMaxValue == 9'999'999'999'999'999ull);
89 template <AssetType A>
98 template <AssetType A>
107 template <AssetType A>
123 template <AssetType A>
131 template <AssetType A>
134 template <AssetType A>
137 template <AssetType A>
140 template <AssetType A>
167 [[nodiscard]] constexpr
bool
168 holds() const noexcept;
173 [[nodiscard]]
std::uint64_t
176 [[nodiscard]]
Asset const&
180 constexpr TIss const&
203 value() const noexcept;
229 operator
bool() const noexcept;
275 [[nodiscard]]
std::
string
278 [[nodiscard]]
std::
string
313 copy(
std::
size_t n,
void* buf) const override;
315 move(
std::
size_t n,
void* buf) override;
338template <AssetType A>
349template <AssetType A>
363 "xrpl::STAmount::STAmount(SField, A, std::uint64_t, int, bool) : "
364 "maximum mantissa input");
374template <AssetType A>
382template <AssetType A>
388template <AssetType A>
476template <Val
idIssueType TIss>
480 return asset_.holds<TIss>();
501template <Val
idIssueType TIss>
502[[nodiscard]]
constexpr TIss
const&
505 return asset_.get<TIss>();
508template <Val
idIssueType TIss>
512 return asset_.get<TIss>();
518 return asset_.getIssuer();
536operator bool() const noexcept
544 return asset().visit(
567template <AssetType A>
574 if (
asset.integral())
615[[nodiscard]]
inline bool
621[[nodiscard]]
inline bool
625 (!value.negative() && value.exponent() == 0 && value.mantissa() <=
kMaxMpTokenAmount);
641operator==(STAmount
const& lhs, STAmount
const& rhs);
643operator<(STAmount
const& lhs, STAmount
const& rhs);
673operator+(STAmount
const& v1, STAmount
const& v2);
675operator-(STAmount
const& v1, STAmount
const& v2);
678divide(STAmount
const& v1, STAmount
const& v2, Asset
const& asset);
681multiply(STAmount
const& v1, STAmount
const& v2, Asset
const& asset);
685mulRound(STAmount
const& v1, STAmount
const& v2, Asset
const& asset,
bool roundUp);
689mulRoundStrict(STAmount
const& v1, STAmount
const& v2, Asset
const& asset,
bool roundUp);
693divRound(STAmount
const& v1, STAmount
const& v2, Asset
const& asset,
bool roundUp);
697divRoundStrict(STAmount
const& v1, STAmount
const& v2, Asset
const& asset,
bool roundUp);
703getRate(STAmount
const& offerOut, STAmount
const& offerIn);
717[[nodiscard]] STAmount
719 STAmount
const& value,
733template <AssetType A>
752template <AssetType A>
778canAdd(STAmount
const& amt1, STAmount
const& amt2);
781canSubtract(STAmount
const& amt1, STAmount
const& amt2);
807 using namespace xrpl;
A generic endpoint for log messages.
Lightweight wrapper to tag static string.
bool isMember(char const *key) const
Return true if the object has a member named key.
Floating point representation of amounts with high dynamic range.
mantissa_type mantissa() const noexcept
A currency issued by an account.
constexpr value_type value() const
Returns the underlying value.
Number is a floating point type that can represent a wide range of values.
constexpr rep mantissa() const noexcept
Returns the mantissa of the external view of the Number.
std::pair< T, int > normalizeToRange() const
static RoundingMode getround()
static MantissaRange::MantissaScale getMantissaScale()
Returns which mantissa scale is currently in use for normalization.
json::StaticString const & getJsonName() const
constexpr bool holds() const noexcept
constexpr TIss const & get() const
void setIssue(Asset const &asset)
Set the Issue for this amount.
static constexpr std::uint64_t kIssuedCurrency
std::string getFullText() const override
static STAmount fromNumber(A const &asset, Number const &number)
void add(Serializer &s) const override
std::pair< mantissa_type, exponent_type > rep
static std::uint64_t const kURateOne
std::uint64_t mantissa() const noexcept
static constexpr std::uint64_t kPositive
int signum() const noexcept
friend class detail::STVar
bool isEquivalent(STBase const &t) const override
STBase * copy(std::size_t n, void *buf) const override
std::string getText() const override
static constexpr int kMinOffset
std::uint64_t mantissa_type
SerializedTypeID getSType() const override
bool negative() const noexcept
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
static constexpr std::uint64_t kMaxNativeN
bool isDefault() const override
bool integral() const noexcept
static constexpr std::uint64_t kValueMask
STAmount & operator=(beast::Zero)
static std::unique_ptr< STAmount > construct(SerialIter &, SField const &name)
bool native() const noexcept
Asset const & asset() const
void setJson(json::Value &) const
STAmount(A const &asset, Number const &number)
static constexpr std::uint64_t kMpToken
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
int exponent() const noexcept
AccountID const & getIssuer() const
bool isZeroAtScale(int scale) const
Checks if this amount evaluates to zero when constrained to a specific accounting scale.
static constexpr std::uint64_t kMinValue
static constexpr std::uint64_t kMaxValue
STBase * move(std::size_t n, void *buf) override
static constexpr std::uint64_t kMaxNative
static constexpr int kMaxOffset
STAmount const & value() const noexcept
STAmount(SerialIter &sit, SField const &name)
STAmount(A const &asset, std::uint64_t mantissa=0, int exponent=0, bool negative=false)
JSON (JavaScript Object Notation).
xrpl::AccountID getOrThrow(json::Value const &v, xrpl::SField const &field)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr BaseUInt< Bits, Tag > operator+(BaseUInt< Bits, Tag > const &a, BaseUInt< Bits, Tag > const &b)
STAmount divide(STAmount const &amount, Rate const &rate)
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
bool isLegalMPT(STAmount const &value)
bool operator>=(STAmount const &lhs, STAmount const &rhs)
bool isXRP(AccountID const &c)
Number operator-(Number const &x, Number const &y)
STAmount mulRoundStrict(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
int scale(Number const &number, Asset const &asset)
Get the scale of a Number for a given asset.
bool isLegalNet(STAmount const &value)
STAmount amountFromString(Asset const &asset, std::string const &amount)
STAmount divRound(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
constexpr Dest safeCast(Src s) noexcept
constexpr Dest unsafeCast(Src s) noexcept
STAmount roundToScale(STAmount const &value, std::int32_t scale, Number::RoundingMode rounding=Number::getround())
Round an arbitrary precision Amount to the precision of an STAmount that has a given exponent.
bool canAdd(STAmount const &amt1, STAmount const &amt2)
Safely checks if two STAmount values can be added without overflow, underflow, or precision loss.
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
STAmount amountFromQuality(std::uint64_t rate)
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
constexpr bool isPowerOfTen(T value)
STAmount amountFromJson(SField const &name, json::Value const &v)
bool hasInvalidAmount(STBase const &field, beast::Journal j)
void roundToAsset(A const &asset, Number &value)
Round an arbitrary precision Number IN PLACE to the precision of a given Asset.
bool operator<=(STAmount const &lhs, STAmount const &rhs)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
STAmount mulRound(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
bool canSubtract(STAmount const &amt1, STAmount const &amt2)
Determines if it is safe to subtract one STAmount from another.
STAmount divRoundStrict(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
bool operator>(STAmount const &lhs, STAmount const &rhs)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
Zero allows classes to offer efficient comparisons to zero.
Note, should be treated as flags that can be | and &.