xrpld
Loading...
Searching...
No Matches
STAmount.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/LocalValue.h>
5#include <xrpl/basics/Number.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/protocol/Asset.h>
9#include <xrpl/protocol/IOUAmount.h>
10#include <xrpl/protocol/Issue.h>
11#include <xrpl/protocol/MPTAmount.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STBase.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/XRPAmount.h>
17#include <xrpl/protocol/json_get_or_throw.h>
18
19namespace xrpl {
20
21// Internal form:
22// 1: If amount is zero, then value is zero and offset is -100
23// 2: Otherwise:
24// legal offset range is -96 to +80 inclusive
25// value range is 10^15 to (10^16 - 1) inclusive
26// amount = value * [10 ^ offset]
27
28// Wire form:
29// High 8 bits are (offset+142), legal range is, 80 to 22 inclusive
30// Low 56 bits are value, legal range is 10^15 to (10^16 - 1) inclusive
31class STAmount final : public STBase, public CountedObject<STAmount>
32{
33public:
35 using exponent_type = int;
37
38private:
43
44public:
46
47 static constexpr int kMinOffset = -96;
48 static constexpr int kMaxOffset = 80;
49
50 // Maximum native value supported by the code
51 static constexpr std::uint64_t kMinValue = 1'000'000'000'000'000ull;
52 static_assert(isPowerOfTen(kMinValue));
53 static constexpr std::uint64_t kMaxValue = (kMinValue * 10) - 1;
54 static_assert(kMaxValue == 9'999'999'999'999'999ull);
55 static constexpr std::uint64_t kMaxNative = 9'000'000'000'000'000'000ull;
56
57 // Max native value on network.
58 static constexpr std::uint64_t kMaxNativeN = 100'000'000'000'000'000ull;
59 static constexpr std::uint64_t kIssuedCurrency = 0x8'000'000'000'000'000ull;
60 static constexpr std::uint64_t kPositive = 0x4'000'000'000'000'000ull;
61 static constexpr std::uint64_t kMpToken = 0x2'000'000'000'000'000ull;
62 static constexpr std::uint64_t kValueMask = ~(kPositive | kMpToken);
63
65
66 //--------------------------------------------------------------------------
67 STAmount(SerialIter& sit, SField const& name);
68
69 struct Unchecked
70 {
71 explicit Unchecked() = default;
72 };
73
74 // Do not call canonicalize
75 template <AssetType A>
77 SField const& name,
78 A const& asset,
81 bool negative,
82 Unchecked);
83
84 template <AssetType A>
86 A const& asset,
89 bool negative,
90 Unchecked);
91
92 // Call canonicalize
93 template <AssetType A>
95 SField const& name,
96 A const& asset,
99 bool negative = false);
100
101 STAmount(SField const& name, std::int64_t mantissa);
102
103 STAmount(SField const& name, std::uint64_t mantissa = 0, bool negative = false);
104
105 explicit STAmount(std::uint64_t mantissa = 0, bool negative = false);
106
107 explicit STAmount(SField const& name, STAmount const& amt);
108
109 template <AssetType A>
110 STAmount(A const& asset, std::uint64_t mantissa = 0, int exponent = 0, bool negative = false)
112 {
113 canonicalize();
114 }
115
116 // VFALCO Is this needed when we have the previous signature?
117 template <AssetType A>
118 STAmount(A const& asset, std::uint32_t mantissa, int exponent = 0, bool negative = false);
119
120 template <AssetType A>
121 STAmount(A const& asset, std::int64_t mantissa, int exponent = 0);
122
123 template <AssetType A>
124 STAmount(A const& asset, int mantissa, int exponent = 0);
125
126 template <AssetType A>
127 STAmount(A const& asset, Number const& number) : STAmount(fromNumber(asset, number))
128 {
129 }
130
131 // Legacy support for new-style amounts
132 STAmount(IOUAmount const& amount, Issue const& issue);
133 STAmount(XRPAmount const& amount);
134 STAmount(MPTAmount const& amount, MPTIssue const& mptIssue);
135 operator Number() const;
136
137 //--------------------------------------------------------------------------
138 //
139 // Observers
140 //
141 //--------------------------------------------------------------------------
142
143 [[nodiscard]] int
144 exponent() const noexcept;
145
146 [[nodiscard]] bool
147 integral() const noexcept;
148
149 [[nodiscard]] bool
150 native() const noexcept;
151
152 template <ValidIssueType TIss>
153 [[nodiscard]] constexpr bool
154 holds() const noexcept;
155
156 [[nodiscard]] bool
157 negative() const noexcept;
158
159 [[nodiscard]] std::uint64_t
160 mantissa() const noexcept;
161
162 [[nodiscard]] Asset const&
163 asset() const;
164
165 template <ValidIssueType TIss>
166 constexpr TIss const&
167 get() const;
168
169 template <ValidIssueType TIss>
170 TIss&
171 get();
172
173 [[nodiscard]] AccountID const&
174 getIssuer() const;
175
176 [[nodiscard]] int
177 signum() const noexcept;
178
180 [[nodiscard]] STAmount
181 zeroed() const;
182
183 void
184 setJson(json::Value&) const;
185
186 [[nodiscard]] STAmount const&
187 value() const noexcept;
188
203 [[nodiscard]] bool
204 isZeroAtScale(int scale) const;
205
206 //--------------------------------------------------------------------------
207 //
208 // Operators
209 //
210 //--------------------------------------------------------------------------
211
212 explicit
213 operator bool() const noexcept;
214
215 STAmount&
216 operator+=(STAmount const&);
217 STAmount&
218 operator-=(STAmount const&);
219
220 STAmount& operator=(beast::Zero);
221
222 STAmount&
223 operator=(XRPAmount const& amount);
224
225 STAmount&
226 operator=(Number const&);
227
228 //--------------------------------------------------------------------------
229 //
230 // Modification
231 //
232 //--------------------------------------------------------------------------
233
234 void
235 negate();
236
237 void
238 clear();
239
240 // Zero while copying currency and issuer.
241 void
242 clear(Asset const& asset);
243
245 void
246 setIssue(Asset const& asset);
247
248 //--------------------------------------------------------------------------
249 //
250 // STBase
251 //
252 //--------------------------------------------------------------------------
253
254 [[nodiscard]] SerializedTypeID
255 getSType() const override;
256
257 [[nodiscard]] std::string
258 getFullText() const override;
259
260 [[nodiscard]] std::string
261 getText() const override;
262
263 [[nodiscard]] json::Value getJson(JsonOptions = JsonOptions::Values::None) const override;
264
265 void
266 add(Serializer& s) const override;
267
268 [[nodiscard]] bool
269 isEquivalent(STBase const& t) const override;
270
271 [[nodiscard]] bool
272 isDefault() const override;
273
274 [[nodiscard]] XRPAmount
275 xrp() const;
276 [[nodiscard]] IOUAmount
277 iou() const;
278 [[nodiscard]] MPTAmount
279 mpt() const;
280
281private:
282 template <AssetType A>
283 static STAmount
284 fromNumber(A const& asset, Number const& number);
285
286 static std::unique_ptr<STAmount>
287 construct(SerialIter&, SField const& name);
288
289 void
290 set(std::int64_t v);
291 void
292 canonicalize();
293
294 STBase*
295 copy(std::size_t n, void* buf) const override;
296 STBase*
297 move(std::size_t n, void* buf) override;
298
299 STAmount&
300 operator=(IOUAmount const& iou);
301
302 friend class detail::STVar;
303
304 friend STAmount
305 operator+(STAmount const& v1, STAmount const& v2);
306};
307
308template <AssetType A>
310 SField const& name,
311 A const& asset,
314 bool negative,
315 Unchecked)
317{
318}
319
320template <AssetType A>
330
331template <AssetType A>
333 SField const& name,
334 A const& asset,
336 int exponent,
337 bool negative)
339{
340 // value_ is uint64, but needs to fit in the range of int64
342 {
343 XRPL_ASSERT(
345 "xrpl::STAmount::STAmount(SField, A, std::uint64_t, int, bool) : "
346 "maximum mantissa input");
347 }
348 else
349 {
351 throw std::overflow_error("STAmount mantissa is too large " + std::to_string(mantissa));
352 }
353 canonicalize();
354}
355
356template <AssetType A>
363
364template <AssetType A>
369
370template <AssetType A>
373{
374}
375
376// Legacy support for new-style amounts
377inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue)
378 : asset_(issue), offset_(amount.exponent()), isNegative_(amount < beast::kZero)
379{
380 if (isNegative_)
381 {
383 }
384 else
385 {
387 }
388
389 canonicalize();
390}
391
392inline STAmount::STAmount(MPTAmount const& amount, MPTIssue const& mptIssue)
393 : asset_(mptIssue), offset_(0), isNegative_(amount < beast::kZero)
394{
395 if (isNegative_)
396 {
398 }
399 else
400 {
402 }
403
404 canonicalize();
405}
406
407//------------------------------------------------------------------------------
408//
409// Creation
410//
411//------------------------------------------------------------------------------
412
413// VFALCO TODO The parameter type should be Quality not uint64_t
416
418amountFromString(Asset const& asset, std::string const& amount);
419
421amountFromJson(SField const& name, json::Value const& v);
422
423bool
424amountFromJsonNoThrow(STAmount& result, json::Value const& jvSource);
425
426// IOUAmount and XRPAmount define toSTAmount, defining this
427// trivial conversion here makes writing generic code easier
428inline STAmount const&
430{
431 return a; // NOLINT(bugprone-return-const-ref-from-parameter)
432}
433
434//------------------------------------------------------------------------------
435//
436// Observers
437//
438//------------------------------------------------------------------------------
439
440inline int
441STAmount::exponent() const noexcept
442{
443 return offset_;
444}
445
446inline bool
447STAmount::integral() const noexcept
448{
449 return asset_.integral();
450}
451
452inline bool
453STAmount::native() const noexcept
454{
455 return asset_.native();
456}
457
458template <ValidIssueType TIss>
459constexpr bool
460STAmount::holds() const noexcept
461{
462 return asset_.holds<TIss>();
463}
464
465inline bool
466STAmount::negative() const noexcept
467{
468 return isNegative_;
469}
470
471inline std::uint64_t
472STAmount::mantissa() const noexcept
473{
474 return value_;
475}
476
477inline Asset const&
479{
480 return asset_;
481}
482
483template <ValidIssueType TIss>
484[[nodiscard]] constexpr TIss const&
486{
487 return asset_.get<TIss>();
488}
489
490template <ValidIssueType TIss>
491TIss&
493{
494 return asset_.get<TIss>();
495}
496
497inline AccountID const&
499{
500 return asset_.getIssuer();
501}
502
503inline int
504STAmount::signum() const noexcept
505{
506 if (value_ == 0u)
507 return 0;
508 return isNegative_ ? -1 : 1;
509}
510
511inline STAmount
513{
514 return STAmount(asset_);
515}
516
517inline STAmount::
518operator bool() const noexcept
519{
520 return *this != beast::kZero;
521}
522
523inline STAmount::
524operator Number() const
525{
526 return asset().visit(
527 [&](Issue const& issue) -> Number {
528 if (issue.native())
529 return xrp();
530 return iou();
531 },
532 [&](MPTIssue const&) -> Number { return mpt(); });
533}
534
535inline STAmount&
537{
538 clear();
539 return *this;
540}
541
542inline STAmount&
544{
545 *this = STAmount(amount);
546 return *this;
547}
548
549template <AssetType A>
550inline STAmount
551STAmount::fromNumber(A const& a, Number const& number)
552{
553 bool const negative = number.mantissa() < 0;
554 Number const working{negative ? -number : number};
555 Asset const asset{a};
556 if (asset.integral())
557 {
558 std::uint64_t const intValue = static_cast<std::int64_t>(working);
559 return STAmount{asset, intValue, 0, negative};
560 }
561
562 auto const [mantissa, exponent] = working.normalizeToRange<kMinValue, kMaxValue>();
563
565}
566
567inline void
569{
570 if (*this != beast::kZero)
572}
573
574inline void
576{
577 // The -100 is used to allow 0 to sort less than a small positive values
578 // which have a negative exponent.
579 offset_ = integral() ? 0 : -100;
580 value_ = 0;
581 isNegative_ = false;
582}
583
584inline void
586{
588 clear();
589}
590
591inline STAmount const&
592STAmount::value() const noexcept
593{
594 return *this;
595}
596
597[[nodiscard]] inline bool
598isLegalNet(STAmount const& value)
599{
600 return !value.native() || (value.mantissa() <= STAmount::kMaxNativeN);
601}
602
603[[nodiscard]] inline bool
604isLegalMPT(STAmount const& value)
605{
606 return !value.holds<MPTIssue>() ||
607 (!value.negative() && value.exponent() == 0 && value.mantissa() <= kMaxMpTokenAmount);
608}
609
610/* Check recursively if an object has invalid MPTAmount or XRPAmount in STAmount field.
611 * Calls isLegalNet() and isLegalMPT().
612 */
613[[nodiscard]] bool
614hasInvalidAmount(STBase const& field, beast::Journal j);
615
616//------------------------------------------------------------------------------
617//
618// Operators
619//
620//------------------------------------------------------------------------------
621
622bool
623operator==(STAmount const& lhs, STAmount const& rhs);
624bool
625operator<(STAmount const& lhs, STAmount const& rhs);
626
627inline bool
628operator!=(STAmount const& lhs, STAmount const& rhs)
629{
630 return !(lhs == rhs);
631}
632
633inline bool
634operator>(STAmount const& lhs, STAmount const& rhs)
635{
636 return rhs < lhs;
637}
638
639inline bool
640operator<=(STAmount const& lhs, STAmount const& rhs)
641{
642 return !(rhs < lhs);
643}
644
645inline bool
646operator>=(STAmount const& lhs, STAmount const& rhs)
647{
648 return !(lhs < rhs);
649}
650
651STAmount
652operator-(STAmount const& value);
653
654//------------------------------------------------------------------------------
655//
656// Arithmetic
657//
658//------------------------------------------------------------------------------
659
660STAmount
661operator+(STAmount const& v1, STAmount const& v2);
662STAmount
663operator-(STAmount const& v1, STAmount const& v2);
664
665STAmount
666divide(STAmount const& v1, STAmount const& v2, Asset const& asset);
667
668STAmount
669multiply(STAmount const& v1, STAmount const& v2, Asset const& asset);
670
671// multiply rounding result in specified direction
672STAmount
673mulRound(STAmount const& v1, STAmount const& v2, Asset const& asset, bool roundUp);
674
675// multiply following the rounding directions more precisely.
676STAmount
677mulRoundStrict(STAmount const& v1, STAmount const& v2, Asset const& asset, bool roundUp);
678
679// divide rounding result in specified direction
680STAmount
681divRound(STAmount const& v1, STAmount const& v2, Asset const& asset, bool roundUp);
682
683// divide following the rounding directions more precisely.
684STAmount
685divRoundStrict(STAmount const& v1, STAmount const& v2, Asset const& asset, bool roundUp);
686
687// Someone is offering X for Y, what is the rate?
688// Rate: smaller is better, the taker wants the most out: in/out
689// VFALCO TODO Return a Quality object
691getRate(STAmount const& offerOut, STAmount const& offerIn);
692
705[[nodiscard]] STAmount
707 STAmount const& value,
710
720template <AssetType A>
721void
722roundToAsset(A const& asset, Number& value)
723{
724 value = STAmount{asset, value};
725}
726
738template <AssetType A>
739[[nodiscard]] Number
741 A const& asset,
742 Number const& value,
745{
746 NumberRoundModeGuard const mg(rounding);
747 STAmount const ret{asset, value};
748 if (ret.integral())
749 return ret;
750 // Note that the ctor will round integral types (XRP, MPT) via canonicalize,
751 // so no extra work is needed for those.
752 return roundToScale(ret, scale);
753}
754
755//------------------------------------------------------------------------------
756
757inline bool
758isXRP(STAmount const& amount)
759{
760 return amount.native();
761}
762
763bool
764canAdd(STAmount const& amt1, STAmount const& amt2);
765
766bool
767canSubtract(STAmount const& amt1, STAmount const& amt2);
768
778inline int
779scale(Number const& number, Asset const& asset)
780{
781 return STAmount{asset, number}.exponent();
782}
783
784} // namespace xrpl
785
786//------------------------------------------------------------------------------
787namespace json {
788template <>
789inline xrpl::STAmount
790getOrThrow(json::Value const& v, xrpl::SField const& field)
791{
792 using namespace xrpl;
793 json::StaticString const& key = field.getJsonName();
794 if (!v.isMember(key))
796 json::Value const& inner = v[key];
797 return amountFromJson(field, inner);
798}
799} // namespace json
A generic endpoint for log messages.
Definition Journal.h:38
Lightweight wrapper to tag static string.
Definition json_value.h:44
Represents a JSON value.
Definition json_value.h:130
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.
Definition IOUAmount.h:24
mantissa_type mantissa() const noexcept
Definition IOUAmount.h:165
A currency issued by an account.
Definition Issue.h:13
bool native() const
Definition Issue.cpp:54
constexpr value_type value() const
Returns the underlying value.
Definition MPTAmount.h:122
Number is a floating point type that can represent a wide range of values.
Definition Number.h:306
constexpr rep mantissa() const noexcept
Returns the mantissa of the external view of the Number.
Definition Number.h:640
std::pair< T, int > normalizeToRange() const
Definition Number.h:789
static RoundingMode getround()
Definition Number.cpp:105
static MantissaRange::MantissaScale getMantissaScale()
Returns which mantissa scale is currently in use for normalization.
Definition Number.cpp:117
Identifies fields.
Definition SField.h:130
void set(std::int64_t v)
Definition STAmount.cpp:878
constexpr bool holds() const noexcept
Definition STAmount.h:460
constexpr TIss const & get() const
void setIssue(Asset const &asset)
Set the Issue for this amount.
Definition STAmount.cpp:407
static constexpr std::uint64_t kIssuedCurrency
Definition STAmount.h:59
std::string getFullText() const override
Definition STAmount.cpp:636
exponent_type offset_
Definition STAmount.h:41
mantissa_type value_
Definition STAmount.h:40
static STAmount fromNumber(A const &asset, Number const &number)
Definition STAmount.h:551
STAmount value_type
Definition STAmount.h:45
void add(Serializer &s) const override
Definition STAmount.cpp:742
bool isNegative_
Definition STAmount.h:42
std::pair< mantissa_type, exponent_type > rep
Definition STAmount.h:36
static std::uint64_t const kURateOne
Definition STAmount.h:64
void negate()
Definition STAmount.h:568
void canonicalize()
Definition STAmount.cpp:821
std::uint64_t mantissa() const noexcept
Definition STAmount.h:472
static constexpr std::uint64_t kPositive
Definition STAmount.h:60
int signum() const noexcept
Definition STAmount.h:504
friend class detail::STVar
Definition STAmount.h:302
bool isEquivalent(STBase const &t) const override
Definition STAmount.cpp:790
STBase * copy(std::size_t n, void *buf) const override
Definition STAmount.cpp:254
std::string getText() const override
Definition STAmount.cpp:646
static constexpr int kMinOffset
Definition STAmount.h:47
std::uint64_t mantissa_type
Definition STAmount.h:34
SerializedTypeID getSType() const override
Definition STAmount.cpp:630
IOUAmount iou() const
Definition STAmount.cpp:286
bool negative() const noexcept
Definition STAmount.h:466
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
Definition STAmount.h:512
static constexpr std::uint64_t kMaxNativeN
Definition STAmount.h:58
bool isDefault() const override
Definition STAmount.cpp:797
bool integral() const noexcept
Definition STAmount.h:447
static constexpr std::uint64_t kValueMask
Definition STAmount.h:62
STAmount & operator=(beast::Zero)
Definition STAmount.h:536
static std::unique_ptr< STAmount > construct(SerialIter &, SField const &name)
Definition STAmount.cpp:248
bool native() const noexcept
Definition STAmount.h:453
Asset const & asset() const
Definition STAmount.h:478
int exponent_type
Definition STAmount.h:35
void setJson(json::Value &) const
Definition STAmount.cpp:606
STAmount(A const &asset, Number const &number)
Definition STAmount.h:127
MPTAmount mpt() const
Definition STAmount.cpp:301
static constexpr std::uint64_t kMpToken
Definition STAmount.h:61
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
Definition STAmount.cpp:734
int exponent() const noexcept
Definition STAmount.h:441
AccountID const & getIssuer() const
Definition STAmount.h:498
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
Definition STAmount.h:51
static constexpr std::uint64_t kMaxValue
Definition STAmount.h:53
STBase * move(std::size_t n, void *buf) override
Definition STAmount.cpp:260
static constexpr std::uint64_t kMaxNative
Definition STAmount.h:55
XRPAmount xrp() const
Definition STAmount.cpp:271
static constexpr int kMaxOffset
Definition STAmount.h:48
STAmount const & value() const noexcept
Definition STAmount.h:592
STAmount(SerialIter &sit, SField const &name)
Definition STAmount.cpp:112
STAmount(A const &asset, std::uint64_t mantissa=0, int exponent=0, bool negative=false)
Definition STAmount.h:110
T max(T... args)
JSON (JavaScript Object Notation).
Definition json_errors.h:5
xrpl::AccountID getOrThrow(json::Value const &v, xrpl::SField const &field)
Definition AccountID.h:111
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr BaseUInt< Bits, Tag > operator+(BaseUInt< Bits, Tag > const &a, BaseUInt< Bits, Tag > const &b)
Definition base_uint.h:625
STAmount divide(STAmount const &amount, Rate const &rate)
Definition Rate2.cpp:69
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:199
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
Definition base_uint.h:588
bool isLegalMPT(STAmount const &value)
Definition STAmount.h:604
bool operator>=(STAmount const &lhs, STAmount const &rhs)
Definition STAmount.h:646
bool isXRP(AccountID const &c)
Definition AccountID.h:70
Number operator-(Number const &x, Number const &y)
Definition Number.h:736
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.
Definition STAmount.h:779
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safeCast(Src s) noexcept
Definition safe_cast.h:21
bool isLegalNet(STAmount const &value)
Definition STAmount.h:598
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > unsafeCast(Src s) noexcept
Definition safe_cast.h:52
STAmount amountFromString(Asset const &asset, std::string const &amount)
Definition STAmount.cpp:907
STAmount divRound(STAmount const &v1, STAmount const &v2, Asset const &asset, bool roundUp)
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.
Definition STAmount.cpp:464
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
STAmount amountFromQuality(std::uint64_t rate)
Definition STAmount.cpp:895
SerializedTypeID
Definition SField.h:93
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Definition STAmount.cpp:422
constexpr bool isPowerOfTen(T value)
Definition Number.h:40
bool operator!=(Buffer const &lhs, Buffer const &rhs) noexcept
Definition Buffer.h:210
STAmount amountFromJson(SField const &name, json::Value const &v)
Definition STAmount.cpp:916
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.
Definition STAmount.h:722
bool operator<=(STAmount const &lhs, STAmount const &rhs)
Definition STAmount.h:640
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
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.
Definition STAmount.cpp:541
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.
Definition Protocol.h:238
bool operator>(STAmount const &lhs, STAmount const &rhs)
Definition STAmount.h:634
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
Zero allows classes to offer efficient comparisons to zero.
Definition Zero.h:25
Note, should be treated as flags that can be | and &.
Definition STBase.h:17
T to_string(T... args)