diff --git a/.clang-tidy b/.clang-tidy index 6a7005b464..33569be50a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,13 +1,11 @@ --- -# This entire group of checks was applied to all cpp files but not all header files. -# --- Checks: "-*, bugprone-argument-comment, bugprone-assert-side-effect, bugprone-bad-signal-to-kill-thread, bugprone-bool-pointer-implicit-conversion, - bugprone-casting-through-void, bugprone-capturing-this-in-member-variable, + bugprone-casting-through-void, bugprone-chained-comparison, bugprone-compare-pointer-to-member-virtual-function, bugprone-copy-constructor-init, @@ -26,10 +24,10 @@ Checks: "-*, bugprone-lambda-function-name, bugprone-macro-parentheses, bugprone-macro-repeated-side-effects, + bugprone-misleading-setter-of-reference, bugprone-misplaced-operator-in-strlen-in-alloc, bugprone-misplaced-pointer-arithmetic-in-alloc, bugprone-misplaced-widening-cast, - bugprone-misleading-setter-of-reference, bugprone-move-forwarding-reference, bugprone-multi-level-implicit-pointer-conversion, bugprone-multiple-new-in-one-expression, @@ -75,10 +73,10 @@ Checks: "-*, bugprone-unhandled-self-assignment, bugprone-unique-ptr-array-mismatch, bugprone-unsafe-functions, - bugprone-use-after-move, + bugprone-unused-local-non-trivial-variable, bugprone-unused-raii, bugprone-unused-return-value, - bugprone-unused-local-non-trivial-variable, + bugprone-use-after-move, bugprone-virtual-near-miss, cppcoreguidelines-init-variables, cppcoreguidelines-misleading-capture-default-by-value, @@ -90,6 +88,7 @@ Checks: "-*, cppcoreguidelines-use-enum-class, cppcoreguidelines-virtual-class-destructor, hicpp-ignored-remove-result, + llvm-namespace-comment, misc-const-correctness, misc-definitions-in-headers, misc-header-include-cycle, @@ -101,6 +100,7 @@ Checks: "-*, misc-unused-alias-decls, misc-unused-using-decls, modernize-concat-nested-namespaces, + modernize-deprecated-headers, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, @@ -116,8 +116,6 @@ Checks: "-*, modernize-use-starts-ends-with, modernize-use-std-numbers, modernize-use-using, - modernize-deprecated-headers, - llvm-namespace-comment, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, @@ -137,6 +135,7 @@ Checks: "-*, readability-duplicate-include, readability-else-after-return, readability-enum-initial-value, + readability-identifier-naming, readability-implicit-bool-conversion, readability-make-member-function-const, readability-math-missing-parentheses, @@ -154,52 +153,47 @@ Checks: "-*, readability-use-std-min-max " # --- -# other checks that have issues that need to be resolved: -# # readability-inconsistent-declaration-parameter-name, # in this codebase this check will break a lot of arg names # readability-static-accessed-through-instance, # this check is probably unnecessary. it makes the code less readable -# readability-identifier-naming, # https://github.com/XRPLF/rippled/pull/6571 # --- -# CheckOptions: readability-braces-around-statements.ShortStatementLines: 2 - # readability-identifier-naming.MacroDefinitionCase: UPPER_CASE - # readability-identifier-naming.ClassCase: CamelCase - # readability-identifier-naming.StructCase: CamelCase - # readability-identifier-naming.UnionCase: CamelCase - # readability-identifier-naming.EnumCase: CamelCase - # readability-identifier-naming.EnumConstantCase: CamelCase - # readability-identifier-naming.ScopedEnumConstantCase: CamelCase - # readability-identifier-naming.GlobalConstantCase: UPPER_CASE - # readability-identifier-naming.GlobalConstantPrefix: "k" - # readability-identifier-naming.GlobalVariableCase: CamelCase - # readability-identifier-naming.GlobalVariablePrefix: "g" - # readability-identifier-naming.ConstexprFunctionCase: camelBack - # readability-identifier-naming.ConstexprMethodCase: camelBack - # readability-identifier-naming.ClassMethodCase: camelBack - # readability-identifier-naming.ClassMemberCase: camelBack - # readability-identifier-naming.ClassConstantCase: UPPER_CASE - # readability-identifier-naming.ClassConstantPrefix: "k" - # readability-identifier-naming.StaticConstantCase: UPPER_CASE - # readability-identifier-naming.StaticConstantPrefix: "k" - # readability-identifier-naming.StaticVariableCase: UPPER_CASE - # readability-identifier-naming.StaticVariablePrefix: "k" - # readability-identifier-naming.ConstexprVariableCase: UPPER_CASE - # readability-identifier-naming.ConstexprVariablePrefix: "k" - # readability-identifier-naming.LocalConstantCase: camelBack - # readability-identifier-naming.LocalVariableCase: camelBack - # readability-identifier-naming.TemplateParameterCase: CamelCase - # readability-identifier-naming.ParameterCase: camelBack - # readability-identifier-naming.FunctionCase: camelBack - # readability-identifier-naming.MemberCase: camelBack - # readability-identifier-naming.PrivateMemberSuffix: _ - # readability-identifier-naming.ProtectedMemberSuffix: _ - # readability-identifier-naming.PublicMemberSuffix: "" - # readability-identifier-naming.FunctionIgnoredRegexp: ".*tag_invoke.*" + readability-identifier-naming.MacroDefinitionCase: UPPER_CASE + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.StructCase: CamelCase + readability-identifier-naming.UnionCase: CamelCase + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.EnumConstantCase: CamelCase + readability-identifier-naming.ScopedEnumConstantCase: CamelCase + readability-identifier-naming.GlobalConstantCase: UPPER_CASE + readability-identifier-naming.GlobalConstantPrefix: "k" + readability-identifier-naming.GlobalVariableCase: CamelCase + readability-identifier-naming.GlobalVariablePrefix: "g" + readability-identifier-naming.ConstexprFunctionCase: camelBack + readability-identifier-naming.ConstexprMethodCase: camelBack + readability-identifier-naming.ClassMethodCase: camelBack + readability-identifier-naming.ClassMemberCase: camelBack + readability-identifier-naming.ClassConstantCase: UPPER_CASE + readability-identifier-naming.ClassConstantPrefix: "k" + readability-identifier-naming.StaticConstantCase: UPPER_CASE + readability-identifier-naming.StaticConstantPrefix: "k" + readability-identifier-naming.StaticVariableCase: UPPER_CASE + readability-identifier-naming.StaticVariablePrefix: "k" + readability-identifier-naming.ConstexprVariableCase: UPPER_CASE + readability-identifier-naming.ConstexprVariablePrefix: "k" + readability-identifier-naming.LocalConstantCase: camelBack + readability-identifier-naming.LocalVariableCase: camelBack + readability-identifier-naming.TemplateParameterCase: CamelCase + readability-identifier-naming.ParameterCase: camelBack + readability-identifier-naming.FunctionCase: camelBack + readability-identifier-naming.MemberCase: camelBack + readability-identifier-naming.PrivateMemberSuffix: _ + readability-identifier-naming.ProtectedMemberSuffix: _ + readability-identifier-naming.PublicMemberSuffix: "" + readability-identifier-naming.GlobalFunctionIgnoredRegexp: "^(to_string|hash_append|tuple_hash)$" bugprone-unsafe-functions.ReportMoreUnsafeFunctions: true bugprone-unused-return-value.CheckedReturnTypes: ::std::error_code;::std::error_condition;::std::errc misc-include-cleaner.IgnoreHeaders: ".*/(detail|impl)/.*;.*fwd\\.h(pp)?;time.h;stdlib.h;sqlite3.h;netinet/in\\.h;sys/resource\\.h;sys/sysinfo\\.h;linux/sysinfo\\.h;__chrono/.*;bits/.*;_abort\\.h;boost/uuid/uuid_hash.hpp;boost/beast/core/flat_buffer\\.hpp;boost/beast/http/field\\.hpp;boost/beast/http/dynamic_body\\.hpp;boost/beast/http/message\\.hpp;boost/beast/http/read\\.hpp;boost/beast/http/write\\.hpp;openssl/obj_mac\\.h" -# -HeaderFilterRegex: '^.*/(test|xrpl|xrpld)/.*\.(h|hpp)$' +HeaderFilterRegex: '^.*/(test|xrpl|xrpld)/.*\.(h|hpp|ipp)$' ExcludeHeaderFilterRegex: '^.*/protocol_autogen/.*\.(h|hpp)$' WarningsAsErrors: "*" diff --git a/include/xrpl/basics/BasicConfig.h b/include/xrpl/basics/BasicConfig.h index 0639fb6c4d..7593de4e86 100644 --- a/include/xrpl/basics/BasicConfig.h +++ b/include/xrpl/basics/BasicConfig.h @@ -133,7 +133,7 @@ public: /// Returns a value if present, else another value. template [[nodiscard]] T - value_or(std::string const& name, T const& other) const + valueOr(std::string const& name, T const& other) const { auto const v = get(name); return v.has_value() ? *v : other; @@ -142,7 +142,7 @@ public: // indicates if trailing comments were seen // during the appending of any lines/values [[nodiscard]] bool - had_trailing_comments() const + hadTrailingComments() const { return had_trailing_comments_; } @@ -273,7 +273,7 @@ public: // indicates if trailing comments were seen // in any loaded Sections [[nodiscard]] bool - had_trailing_comments() const + hadTrailingComments() const { return std::ranges::any_of(map_, [](auto s) { return s.second.had_trailing_comments(); }); } @@ -294,17 +294,17 @@ template bool set(T& target, std::string const& name, Section const& section) { - bool found_and_valid = false; + bool foundAndValid = false; try { auto const val = section.get(name); - if ((found_and_valid = val.has_value())) + if ((foundAndValid = val.has_value())) target = *val; } catch (boost::bad_lexical_cast const&) // NOLINT(bugprone-empty-catch) { } - return found_and_valid; + return foundAndValid; } /** Set a value from a configuration Section @@ -316,10 +316,10 @@ template bool set(T& target, T const& defaultValue, std::string const& name, Section const& section) { - bool const found_and_valid = set(target, name, section); - if (!found_and_valid) + bool const foundAndValid = set(target, name, section); + if (!foundAndValid) target = defaultValue; - return found_and_valid; + return foundAndValid; } /** Retrieve a key/value pair from a section. diff --git a/include/xrpl/basics/CountedObject.h b/include/xrpl/basics/CountedObject.h index 379fd49837..3846ecd5d5 100644 --- a/include/xrpl/basics/CountedObject.h +++ b/include/xrpl/basics/CountedObject.h @@ -38,11 +38,11 @@ public: do { - head = instance.m_head.load(); + head = instance.m_head_.load(); next_ = head; - } while (instance.m_head.exchange(this) != head); + } while (instance.m_head_.exchange(this) != head); - ++instance.m_count; + ++instance.m_count_; } ~Counter() noexcept = default; @@ -88,8 +88,8 @@ private: ~CountedObjects() noexcept = default; private: - std::atomic m_count; - std::atomic m_head; + std::atomic m_count_; + std::atomic m_head_; }; //------------------------------------------------------------------------------ @@ -108,8 +108,8 @@ private: static auto& getCounter() noexcept { - static CountedObjects::Counter c{beast::type_name()}; - return c; + static CountedObjects::Counter kC{beast::type_name()}; + return kC; } CountedObject() noexcept diff --git a/include/xrpl/basics/Expected.h b/include/xrpl/basics/Expected.h index f4d8e5019a..14daa3639b 100644 --- a/include/xrpl/basics/Expected.h +++ b/include/xrpl/basics/Expected.h @@ -16,9 +16,9 @@ namespace xrpl { */ // Exception thrown by an invalid access to Expected. -struct bad_expected_access : public std::runtime_error +struct BadExpectedAccess : public std::runtime_error { - bad_expected_access() : runtime_error("bad expected access") + BadExpectedAccess() : runtime_error("bad expected access") { } }; @@ -26,30 +26,30 @@ struct bad_expected_access : public std::runtime_error namespace detail { // Custom policy for Expected. Always throw on an invalid access. -struct throw_policy : public boost::outcome_v2::policy::base +struct ThrowPolicy : public boost::outcome_v2::policy::base { template static constexpr void - wide_value_check(Impl&& self) + wideValueCheck(Impl&& self) { if (!base::_has_value(std::forward(self))) - Throw(); + Throw(); } template static constexpr void - wide_error_check(Impl&& self) + wideErrorCheck(Impl&& self) { if (!base::_has_error(std::forward(self))) - Throw(); + Throw(); } template static constexpr void - wide_exception_check(Impl&& self) + wideExceptionCheck(Impl&& self) { if (!base::_has_exception(std::forward(self))) - Throw(); + Throw(); } }; @@ -107,9 +107,9 @@ Unexpected(E (&)[N]) -> Unexpected; // Definition of Expected. All of the machinery comes from boost::result. template -class [[nodiscard]] Expected : private boost::outcome_v2::result +class [[nodiscard]] Expected : private boost::outcome_v2::result { - using Base = boost::outcome_v2::result; + using Base = boost::outcome_v2::result; public: template @@ -126,7 +126,7 @@ public: } [[nodiscard]] constexpr bool - has_value() const + hasValue() const { return Base::has_value(); } @@ -158,7 +158,7 @@ public: constexpr explicit operator bool() const { - return has_value(); + return hasValue(); } // Add operator* and operator-> so the Expected API looks a bit more like @@ -193,9 +193,9 @@ public: // (without a value) or the reason for the failure. template class [[nodiscard]] -Expected : private boost::outcome_v2::result +Expected : private boost::outcome_v2::result { - using Base = boost::outcome_v2::result; + using Base = boost::outcome_v2::result; public: // The default constructor makes a successful Expected. diff --git a/include/xrpl/basics/IntrusivePointer.h b/include/xrpl/basics/IntrusivePointer.h index 019e71a727..1abb92beca 100644 --- a/include/xrpl/basics/IntrusivePointer.h +++ b/include/xrpl/basics/IntrusivePointer.h @@ -164,7 +164,7 @@ public: /** Return the strong count */ [[nodiscard]] std::size_t - use_count() const; + useCount() const; template friend SharedIntrusive @@ -364,7 +364,7 @@ public: * return 0 */ [[nodiscard]] std::size_t - use_count() const; + useCount() const; /** Return true if there is a non-zero strong count. */ [[nodiscard]] bool @@ -406,8 +406,8 @@ private: // pointer. The low bit must be masked to zero when converting back to a // pointer. If the low bit is '1', this is a weak pointer. std::uintptr_t tp_{0}; - static constexpr std::uintptr_t tagMask = 1; - static constexpr std::uintptr_t ptrMask = ~tagMask; + static constexpr std::uintptr_t kTAG_MASK = 1; + static constexpr std::uintptr_t kPTR_MASK = ~kTAG_MASK; private: /** Return the raw pointer held by this object. @@ -415,7 +415,7 @@ private: [[nodiscard]] T* unsafeGetRawPtr() const; - enum class RefStrength { strong, weak }; + enum class RefStrength { Strong, Weak }; /** Set the raw pointer and tag bit directly. */ void diff --git a/include/xrpl/basics/IntrusivePointer.ipp b/include/xrpl/basics/IntrusivePointer.ipp index 59caf5a931..115fa69964 100644 --- a/include/xrpl/basics/IntrusivePointer.ipp +++ b/include/xrpl/basics/IntrusivePointer.ipp @@ -226,7 +226,7 @@ SharedIntrusive::get() const template std::size_t -SharedIntrusive::use_count() const +SharedIntrusive::useCount() const { if (auto p = unsafeGetRawPtr()) return p->use_count(); @@ -266,12 +266,12 @@ SharedIntrusive::unsafeReleaseAndStore(T* next) auto action = prev->releaseStrongRef(); switch (action) { - case noop: + case Noop: break; - case destroy: + case Destroy: delete prev; break; - case partialDestroy: + case PartialDestroy: prev->partialDestructor(); partialDestructorFinished(&prev); // prev is null and may no longer be used @@ -367,9 +367,9 @@ WeakIntrusive::unsafeReleaseNoStore() auto action = ptr_->releaseWeakRef(); switch (action) { - case noop: + case Noop: break; - case destroy: + case Destroy: delete ptr_; break; } @@ -517,7 +517,7 @@ SharedWeakUnion::get() const template std::size_t -SharedWeakUnion::use_count() const +SharedWeakUnion::useCount() const { if (auto p = get()) return p->use_count(); @@ -559,14 +559,14 @@ template bool SharedWeakUnion::isStrong() const { - return !(tp_ & tagMask); + return !(tp_ & kTAG_MASK); } template bool SharedWeakUnion::isWeak() const { - return tp_ & tagMask; + return tp_ & kTAG_MASK; } template @@ -581,7 +581,7 @@ SharedWeakUnion::convertToStrong() { [[maybe_unused]] auto action = p->releaseWeakRef(); XRPL_ASSERT( - (action == ReleaseWeakRefAction::noop), + (action == ReleaseWeakRefAction::Noop), "xrpl::SharedWeakUnion::convertToStrong : " "action is noop"); unsafeSetRawPtr(p, RefStrength::strong); @@ -605,9 +605,9 @@ SharedWeakUnion::convertToWeak() auto action = p->addWeakReleaseStrongRef(); switch (action) { - case noop: + case Noop: break; - case destroy: + case Destroy: // We just added a weak ref. How could we destroy? // LCOV_EXCL_START UNREACHABLE( @@ -617,7 +617,7 @@ SharedWeakUnion::convertToWeak() unsafeSetRawPtr(nullptr); return true; // Should never happen // LCOV_EXCL_STOP - case partialDestroy: + case PartialDestroy: // This is a weird case. We just converted the last strong // pointer to a weak pointer. p->partialDestructor(); @@ -633,7 +633,7 @@ template T* SharedWeakUnion::unsafeGetRawPtr() const { - return reinterpret_cast(tp_ & ptrMask); + return reinterpret_cast(tp_ & kPTR_MASK); } template @@ -642,7 +642,7 @@ SharedWeakUnion::unsafeSetRawPtr(T* p, RefStrength rs) { tp_ = reinterpret_cast(p); if (tp_ && rs == RefStrength::weak) - tp_ |= tagMask; + tp_ |= kTAG_MASK; } template @@ -666,12 +666,12 @@ SharedWeakUnion::unsafeReleaseNoStore() auto strongAction = p->releaseStrongRef(); switch (strongAction) { - case noop: + case Noop: break; - case destroy: + case Destroy: delete p; break; - case partialDestroy: + case PartialDestroy: p->partialDestructor(); partialDestructorFinished(&p); // p is null and may no longer be used @@ -684,9 +684,9 @@ SharedWeakUnion::unsafeReleaseNoStore() auto weakAction = p->releaseWeakRef(); switch (weakAction) { - case noop: + case Noop: break; - case destroy: + case Destroy: delete p; break; } diff --git a/include/xrpl/basics/IntrusiveRefCounts.h b/include/xrpl/basics/IntrusiveRefCounts.h index e7c31bde93..4e7498f4e8 100644 --- a/include/xrpl/basics/IntrusiveRefCounts.h +++ b/include/xrpl/basics/IntrusiveRefCounts.h @@ -18,7 +18,7 @@ namespace xrpl { destroy: Run the destructor. This action will occur when either the strong count or weak count is decremented and the other count is also zero. */ -enum class ReleaseStrongRefAction { noop, partialDestroy, destroy }; +enum class ReleaseStrongRefAction { Noop, PartialDestroy, Destroy }; /** Action to perform when releasing a weak pointer. @@ -28,7 +28,7 @@ enum class ReleaseStrongRefAction { noop, partialDestroy, destroy }; destroy: Run the destructor. This action will occur when either the strong count or weak count is decremented and the other count is also zero. */ -enum class ReleaseWeakRefAction { noop, destroy }; +enum class ReleaseWeakRefAction { Noop, Destroy }; /** Implement the strong count, weak count, and bit flags for an intrusive pointer. @@ -71,7 +71,7 @@ struct IntrusiveRefCounts expired() const noexcept; std::size_t - use_count() const noexcept; + useCount() const noexcept; // This function MUST be called after a partial destructor finishes running. // Calling this function may cause other threads to delete the object @@ -98,11 +98,11 @@ private: // enough for strong pointers and 14 bit counts are enough for weak // pointers. Use type aliases to make it easy to switch types. using CountType = std::uint16_t; - static constexpr size_t StrongCountNumBits = sizeof(CountType) * 8; - static constexpr size_t WeakCountNumBits = StrongCountNumBits - 2; + static constexpr size_t kSTRONG_COUNT_NUM_BITS = sizeof(CountType) * 8; + static constexpr size_t kWEAK_COUNT_NUM_BITS = kSTRONG_COUNT_NUM_BITS - 2; using FieldType = std::uint32_t; - static constexpr size_t FieldTypeBits = sizeof(FieldType) * 8; - static constexpr FieldType one = 1; + static constexpr size_t kFIELD_TYPE_BITS = sizeof(FieldType) * 8; + static constexpr FieldType kONE = 1; /** `refCounts` consists of four fields that are treated atomically: @@ -137,21 +137,21 @@ private: */ - mutable std::atomic refCounts{strongDelta}; + mutable std::atomic refCounts_{kSTRONG_DELTA}; /** Amount to change the strong count when adding or releasing a reference Note: The strong count is stored in the low `StrongCountNumBits` bits of refCounts */ - static constexpr FieldType strongDelta = 1; + static constexpr FieldType kSTRONG_DELTA = 1; /** Amount to change the weak count when adding or releasing a reference Note: The weak count is stored in the high `WeakCountNumBits` bits of refCounts */ - static constexpr FieldType weakDelta = (one << StrongCountNumBits); + static constexpr FieldType kWEAK_DELTA = (kONE << kSTRONG_COUNT_NUM_BITS); /** Flag that is set when the partialDestroy function has started running (or is about to start running). @@ -159,33 +159,34 @@ private: See description of the `refCounts` field for a fuller description of this field. */ - static constexpr FieldType partialDestroyStartedMask = (one << (FieldTypeBits - 1)); + static constexpr FieldType kPARTIAL_DESTROY_STARTED_MASK = (kONE << (kFIELD_TYPE_BITS - 1)); /** Flag that is set when the partialDestroy function has finished running See description of the `refCounts` field for a fuller description of this field. */ - static constexpr FieldType partialDestroyFinishedMask = (one << (FieldTypeBits - 2)); + static constexpr FieldType kPARTIAL_DESTROY_FINISHED_MASK = (kONE << (kFIELD_TYPE_BITS - 2)); /** Mask that will zero out all the `count` bits and leave the tag bits unchanged. */ - static constexpr FieldType tagMask = partialDestroyStartedMask | partialDestroyFinishedMask; + static constexpr FieldType kTAG_MASK = + kPARTIAL_DESTROY_STARTED_MASK | kPARTIAL_DESTROY_FINISHED_MASK; /** Mask that will zero out the `tag` bits and leave the count bits unchanged. */ - static constexpr FieldType valueMask = ~tagMask; + static constexpr FieldType kVALUE_MASK = ~kTAG_MASK; /** Mask that will zero out everything except the strong count. */ - static constexpr FieldType strongMask = ((one << StrongCountNumBits) - 1) & valueMask; + static constexpr FieldType kSTRONG_MASK = ((kONE << kSTRONG_COUNT_NUM_BITS) - 1) & kVALUE_MASK; /** Mask that will zero out everything except the weak count. */ - static constexpr FieldType weakMask = - (((one << WeakCountNumBits) - 1) << StrongCountNumBits) & valueMask; + static constexpr FieldType kWEAK_MASK = + (((kONE << kWEAK_COUNT_NUM_BITS) - 1) << kSTRONG_COUNT_NUM_BITS) & kVALUE_MASK; /** Unpack the count and tag fields from the packed atomic integer form. */ struct RefCountPair @@ -210,29 +211,29 @@ private: [[nodiscard]] FieldType combinedValue() const noexcept; - static constexpr CountType maxStrongValue = - static_cast((one << StrongCountNumBits) - 1); - static constexpr CountType maxWeakValue = - static_cast((one << WeakCountNumBits) - 1); + static constexpr CountType kMAX_STRONG_VALUE = + static_cast((kONE << kSTRONG_COUNT_NUM_BITS) - 1); + static constexpr CountType kMAX_WEAK_VALUE = + static_cast((kONE << kWEAK_COUNT_NUM_BITS) - 1); /** Put an extra margin to detect when running up against limits. This is only used in debug code, and is useful if we reduce the number of bits in the strong and weak counts (to 16 and 14 bits). */ - static constexpr CountType checkStrongMaxValue = maxStrongValue - 32; - static constexpr CountType checkWeakMaxValue = maxWeakValue - 32; + static constexpr CountType kCHECK_STRONG_MAX_VALUE = kMAX_STRONG_VALUE - 32; + static constexpr CountType kCHECK_WEAK_MAX_VALUE = kMAX_WEAK_VALUE - 32; }; }; inline void IntrusiveRefCounts::addStrongRef() const noexcept { - refCounts.fetch_add(strongDelta, std::memory_order_acq_rel); + refCounts_.fetch_add(kSTRONG_DELTA, std::memory_order_acq_rel); } inline void IntrusiveRefCounts::addWeakRef() const noexcept { - refCounts.fetch_add(weakDelta, std::memory_order_acq_rel); + refCounts_.fetch_add(kWEAK_DELTA, std::memory_order_acq_rel); } inline ReleaseStrongRefAction @@ -246,36 +247,36 @@ IntrusiveRefCounts::releaseStrongRef() const // conditional `fetch_or`. This loop will almost always run once. using enum ReleaseStrongRefAction; - auto prevIntVal = refCounts.load(std::memory_order_acquire); + auto prevIntVal = refCounts_.load(std::memory_order_acquire); while (true) { RefCountPair const prevVal{prevIntVal}; XRPL_ASSERT( - (prevVal.strong >= strongDelta), + (prevVal.strong >= kSTRONG_DELTA), "xrpl::IntrusiveRefCounts::releaseStrongRef : previous ref " "higher than new"); - auto nextIntVal = prevIntVal - strongDelta; - ReleaseStrongRefAction action = noop; + auto nextIntVal = prevIntVal - kSTRONG_DELTA; + ReleaseStrongRefAction action = Noop; if (prevVal.strong == 1) { if (prevVal.weak == 0) { - action = destroy; + action = Destroy; } else { - nextIntVal |= partialDestroyStartedMask; - action = partialDestroy; + nextIntVal |= kPARTIAL_DESTROY_STARTED_MASK; + action = PartialDestroy; } } - if (refCounts.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel)) + if (refCounts_.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel)) { // Can't be in partial destroy because only decrementing the strong // count to zero can start a partial destroy, and that can't happen // twice. XRPL_ASSERT( - (action == noop) || !(prevIntVal & partialDestroyStartedMask), + (action == Noop) || !(prevIntVal & kPARTIAL_DESTROY_STARTED_MASK), "xrpl::IntrusiveRefCounts::releaseStrongRef : not in partial " "destroy"); return action; @@ -288,9 +289,9 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const { using enum ReleaseStrongRefAction; - static_assert(weakDelta > strongDelta); - auto constexpr delta = weakDelta - strongDelta; - auto prevIntVal = refCounts.load(std::memory_order_acquire); + static_assert(kWEAK_DELTA > kSTRONG_DELTA); + auto constexpr kDELTA = kWEAK_DELTA - kSTRONG_DELTA; + auto prevIntVal = refCounts_.load(std::memory_order_acquire); // This loop will almost always run once. The loop is needed to atomically // change the counts and flags (the count could be atomically changed, but // the flags depend on the current value of the counts). @@ -311,24 +312,24 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not in " "partial destroy"); - auto nextIntVal = prevIntVal + delta; - ReleaseStrongRefAction action = noop; + auto nextIntVal = prevIntVal + kDELTA; + ReleaseStrongRefAction action = Noop; if (prevVal.strong == 1) { if (prevVal.weak == 0) { - action = noop; + action = Noop; } else { - nextIntVal |= partialDestroyStartedMask; - action = partialDestroy; + nextIntVal |= kPARTIAL_DESTROY_STARTED_MASK; + action = PartialDestroy; } } - if (refCounts.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel)) + if (refCounts_.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel)) { XRPL_ASSERT( - (!(prevIntVal & partialDestroyStartedMask)), + (!(prevIntVal & kPARTIAL_DESTROY_STARTED_MASK)), "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not " "started partial destroy"); return action; @@ -339,7 +340,7 @@ IntrusiveRefCounts::addWeakReleaseStrongRef() const inline ReleaseWeakRefAction IntrusiveRefCounts::releaseWeakRef() const { - auto prevIntVal = refCounts.fetch_sub(weakDelta, std::memory_order_acq_rel); + auto prevIntVal = refCounts_.fetch_sub(kWEAK_DELTA, std::memory_order_acq_rel); RefCountPair prev = prevIntVal; if (prev.weak == 1 && prev.strong == 0) { @@ -348,19 +349,19 @@ IntrusiveRefCounts::releaseWeakRef() const // This case should only be hit if the partialDestroyStartedBit is // set non-atomically (and even then very rarely). The code is kept // in case we need to set the flag non-atomically for perf reasons. - refCounts.wait(prevIntVal, std::memory_order_acquire); - prevIntVal = refCounts.load(std::memory_order_acquire); + refCounts_.wait(prevIntVal, std::memory_order_acquire); + prevIntVal = refCounts_.load(std::memory_order_acquire); prev = RefCountPair{prevIntVal}; } if (prev.partialDestroyFinishedBit == 0u) { // partial destroy MUST finish before running a full destroy (when // using weak pointers) - refCounts.wait(prevIntVal - weakDelta, std::memory_order_acquire); + refCounts_.wait(prevIntVal - kWEAK_DELTA, std::memory_order_acquire); } - return ReleaseWeakRefAction::destroy; + return ReleaseWeakRefAction::Destroy; } - return ReleaseWeakRefAction::noop; + return ReleaseWeakRefAction::Noop; } inline bool @@ -369,13 +370,13 @@ IntrusiveRefCounts::checkoutStrongRefFromWeak() const noexcept auto curValue = RefCountPair{1, 1}.combinedValue(); auto desiredValue = RefCountPair{2, 1}.combinedValue(); - while (!refCounts.compare_exchange_weak(curValue, desiredValue, std::memory_order_acq_rel)) + while (!refCounts_.compare_exchange_weak(curValue, desiredValue, std::memory_order_acq_rel)) { RefCountPair const prev{curValue}; if (prev.strong == 0u) return false; - desiredValue = curValue + strongDelta; + desiredValue = curValue + kSTRONG_DELTA; } return true; } @@ -383,38 +384,39 @@ IntrusiveRefCounts::checkoutStrongRefFromWeak() const noexcept inline bool IntrusiveRefCounts::expired() const noexcept { - RefCountPair const val = refCounts.load(std::memory_order_acquire); + RefCountPair const val = refCounts_.load(std::memory_order_acquire); return val.strong == 0; } inline std::size_t -IntrusiveRefCounts::use_count() const noexcept +IntrusiveRefCounts::useCount() const noexcept { - RefCountPair const val = refCounts.load(std::memory_order_acquire); + RefCountPair const val = refCounts_.load(std::memory_order_acquire); return val.strong; } inline IntrusiveRefCounts::~IntrusiveRefCounts() noexcept { #ifndef NDEBUG - auto v = refCounts.load(std::memory_order_acquire); + auto v = refCounts_.load(std::memory_order_acquire); XRPL_ASSERT( - (!(v & valueMask)), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : count must be zero"); - auto t = v & tagMask; - XRPL_ASSERT((!t || t == tagMask), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : valid tag"); + (!(v & kVALUE_MASK)), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : count must be zero"); + auto t = v & kTAG_MASK; + XRPL_ASSERT( + (!t || t == kTAG_MASK), "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : valid tag"); #endif } //------------------------------------------------------------------------------ inline IntrusiveRefCounts::RefCountPair::RefCountPair(IntrusiveRefCounts::FieldType v) noexcept - : strong{static_cast(v & strongMask)} - , weak{static_cast((v & weakMask) >> StrongCountNumBits)} - , partialDestroyStartedBit{v & partialDestroyStartedMask} - , partialDestroyFinishedBit{v & partialDestroyFinishedMask} + : strong{static_cast(v & kSTRONG_MASK)} + , weak{static_cast((v & kWEAK_MASK) >> kSTRONG_COUNT_NUM_BITS)} + , partialDestroyStartedBit{v & kPARTIAL_DESTROY_STARTED_MASK} + , partialDestroyFinishedBit{v & kPARTIAL_DESTROY_FINISHED_MASK} { XRPL_ASSERT( - (strong < checkStrongMaxValue && weak < checkWeakMaxValue), + (strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE), "xrpl::IntrusiveRefCounts::RefCountPair(FieldType) : inputs inside " "range"); } @@ -425,7 +427,7 @@ inline IntrusiveRefCounts::RefCountPair::RefCountPair( : strong{s}, weak{w} { XRPL_ASSERT( - (strong < checkStrongMaxValue && weak < checkWeakMaxValue), + (strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE), "xrpl::IntrusiveRefCounts::RefCountPair(CountType, CountType) : " "inputs inside range"); } @@ -434,11 +436,11 @@ inline IntrusiveRefCounts::FieldType IntrusiveRefCounts::RefCountPair::combinedValue() const noexcept { XRPL_ASSERT( - (strong < checkStrongMaxValue && weak < checkWeakMaxValue), + (strong < kCHECK_STRONG_MAX_VALUE && weak < kCHECK_WEAK_MAX_VALUE), "xrpl::IntrusiveRefCounts::RefCountPair::combinedValue : inputs " "inside range"); return (static_cast(weak) - << IntrusiveRefCounts::StrongCountNumBits) | + << IntrusiveRefCounts::kSTRONG_COUNT_NUM_BITS) | static_cast(strong) | partialDestroyStartedBit | partialDestroyFinishedBit; } @@ -449,7 +451,7 @@ partialDestructorFinished(T** o) { T& self = **o; IntrusiveRefCounts::RefCountPair const p = - self.refCounts.fetch_or(IntrusiveRefCounts::partialDestroyFinishedMask); + self.refCounts_.fetch_or(IntrusiveRefCounts::kPARTIAL_DESTROY_FINISHED_MASK); XRPL_ASSERT( (!p.partialDestroyFinishedBit && p.partialDestroyStartedBit && !p.strong), "xrpl::partialDestructorFinished : not a weak ref"); @@ -458,7 +460,7 @@ partialDestructorFinished(T** o) // There was a weak count before the partial destructor ran (or we would // have run the full destructor) and now there isn't a weak count. Some // thread is waiting to run the destructor. - self.refCounts.notify_one(); + self.refCounts_.notify_one(); } // Set the pointer to null to emphasize that the object shouldn't be used // after calling this function as it may be destroyed in another thread. diff --git a/include/xrpl/basics/LocalValue.h b/include/xrpl/basics/LocalValue.h index 421ea7af23..f39df425a6 100644 --- a/include/xrpl/basics/LocalValue.h +++ b/include/xrpl/basics/LocalValue.h @@ -26,17 +26,17 @@ struct LocalValues template struct Value : BasicValue { - T t_; + T t; Value() = default; - explicit Value(T t) : t_(std::move(t)) + explicit Value(T t) : t(std::move(t)) { } void* get() override { - return &t_; + return &t; } }; @@ -55,8 +55,8 @@ template boost::thread_specific_ptr& getLocalValues() { - static boost::thread_specific_ptr tsp(&detail::LocalValues::cleanup); - return tsp; + static boost::thread_specific_ptr kTSP(&detail::LocalValues::cleanup); + return kTSP; } } // namespace detail diff --git a/include/xrpl/basics/Log.h b/include/xrpl/basics/Log.h index 5c63166d93..afc1b5514c 100644 --- a/include/xrpl/basics/Log.h +++ b/include/xrpl/basics/Log.h @@ -17,15 +17,15 @@ namespace xrpl { // DEPRECATED use beast::severities::Severity instead // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum LogSeverity { - lsINVALID = -1, // used to indicate an invalid severity - lsTRACE = 0, // Very low-level progress information, details inside + LsInvalid = -1, // used to indicate an invalid severity + LsTrace = 0, // Very low-level progress information, details inside // an operation - lsDEBUG = 1, // Function-level progress information, operations - lsINFO = 2, // Server-level progress information, major operations - lsWARNING = 3, // Conditions that warrant human attention, may indicate + LsDebug = 1, // Function-level progress information, operations + LsInfo = 2, // Server-level progress information, major operations + LsWarning = 3, // Conditions that warrant human attention, may indicate // a problem - lsERROR = 4, // A condition that indicates a problem - lsFATAL = 5 // A severe condition that indicates a server problem + LsError = 4, // A condition that indicates a problem + LsFatal = 5 // A severe condition that indicates a server problem }; /** Manages partitions for logging. */ @@ -130,8 +130,8 @@ private: /** @} */ private: - std::unique_ptr m_stream; - boost::filesystem::path m_path; + std::unique_ptr m_stream_; + boost::filesystem::path m_path_; }; std::mutex mutable mutex_; @@ -168,7 +168,7 @@ public: threshold(beast::severities::Severity thresh); std::vector> - partition_severities() const; + partitionSeverities() const; void write( @@ -214,7 +214,7 @@ private: // Maximum line length for log messages. // If the message exceeds this length it will be truncated with // ellipses. - maximumMessageCharacters = 12 * 1024 + MaximumMessageCharacters = 12 * 1024 }; static void diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index b82cb628b9..542671c8ae 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -70,27 +70,27 @@ isPowerOfTen(T value) struct MantissaRange { using rep = std::uint64_t; - enum class mantissa_scale { small, large }; + enum class MantissaScale { Small, Large }; - explicit constexpr MantissaRange(mantissa_scale scale_) - : min(getMin(scale_)), log(logTen(min).value_or(-1)), scale(scale_) + explicit constexpr MantissaRange(MantissaScale scale) + : min(getMin(scale)), log(logTen(min).value_or(-1)), scale(scale) { } rep min; rep max{(min * 10) - 1}; int log; - mantissa_scale scale; + MantissaScale scale; private: static constexpr rep - getMin(mantissa_scale scale_) + getMin(MantissaScale scale) { - switch (scale_) + switch (scale) { - case mantissa_scale::small: + case MantissaScale::Small: return 1'000'000'000'000'000ULL; - case mantissa_scale::large: + case MantissaScale::Large: return 1'000'000'000'000'000'000ULL; default: // Since this can never be called outside a non-constexpr @@ -214,26 +214,26 @@ class Number public: // The range for the exponent when normalized - constexpr static int minExponent = -32768; - constexpr static int maxExponent = 32768; + constexpr static int kMIN_EXPONENT = -32768; + constexpr static int kMAX_EXPONENT = 32768; - constexpr static internalrep maxRep = std::numeric_limits::max(); - static_assert(maxRep == 9'223'372'036'854'775'807); - static_assert(-maxRep == std::numeric_limits::min() + 1); + constexpr static internalrep kMAX_REP = std::numeric_limits::max(); + static_assert(kMAX_REP == 9'223'372'036'854'775'807); + static_assert(-kMAX_REP == std::numeric_limits::min() + 1); // May need to make unchecked private - struct unchecked + struct Unchecked { - explicit unchecked() = default; + explicit Unchecked() = default; }; // Like unchecked, normalized is used with the ctors that take an // internalrep mantissa. Unlike unchecked, those ctors will normalize the // value. // Only unit tests are expected to use this class - struct normalized + struct Normalized { - explicit normalized() = default; + explicit Normalized() = default; }; explicit constexpr Number() = default; @@ -244,13 +244,13 @@ public: bool negative, internalrep mantissa, int exponent, - unchecked) noexcept; + Unchecked) noexcept; // Assume unsigned values are... unsigned. i.e. positive - explicit constexpr Number(internalrep mantissa, int exponent, unchecked) noexcept; + explicit constexpr Number(internalrep mantissa, int exponent, Unchecked) noexcept; // Only unit tests are expected to use this ctor - explicit Number(bool negative, internalrep mantissa, int exponent, normalized); + explicit Number(bool negative, internalrep mantissa, int exponent, Normalized); // Assume unsigned values are... unsigned. i.e. positive - explicit Number(internalrep mantissa, int exponent, normalized); + explicit Number(internalrep mantissa, int exponent, Normalized); [[nodiscard]] constexpr rep mantissa() const noexcept; @@ -384,42 +384,42 @@ public: root2(Number f); // Thread local rounding control. Default is to_nearest - enum class rounding_mode { to_nearest, towards_zero, downward, upward }; - static rounding_mode + enum class RoundingMode { ToNearest, TowardsZero, Downward, Upward }; + static RoundingMode getround(); // Returns previously set mode - static rounding_mode - setround(rounding_mode mode); + static RoundingMode + setround(RoundingMode mode); /** Returns which mantissa scale is currently in use for normalization. * * If you think you need to call this outside of unit tests, no you don't. */ - static MantissaRange::mantissa_scale + static MantissaRange::MantissaScale getMantissaScale(); /** Changes which mantissa scale is used for normalization. * * If you think you need to call this outside of unit tests, no you don't. */ static void - setMantissaScale(MantissaRange::mantissa_scale scale); + setMantissaScale(MantissaRange::MantissaScale scale); static internalrep minMantissa() { - return range_.get().min; + return range.get().min; } static internalrep maxMantissa() { - return range_.get().max; + return range.get().max; } static int mantissaLog() { - return range_.get().log; + return range.get().log; } /// oneSmall is needed because the ranges are private @@ -440,28 +440,28 @@ public: normalizeToRange(T minMantissa, T maxMantissa) const; private: - static thread_local rounding_mode mode_; + static thread_local RoundingMode mode; // The available ranges for mantissa - constexpr static MantissaRange smallRange{MantissaRange::mantissa_scale::small}; - static_assert(isPowerOfTen(smallRange.min)); - static_assert(smallRange.min == 1'000'000'000'000'000LL); - static_assert(smallRange.max == 9'999'999'999'999'999LL); - static_assert(smallRange.log == 15); - static_assert(smallRange.min < maxRep); - static_assert(smallRange.max < maxRep); - constexpr static MantissaRange largeRange{MantissaRange::mantissa_scale::large}; - static_assert(isPowerOfTen(largeRange.min)); - static_assert(largeRange.min == 1'000'000'000'000'000'000ULL); - static_assert(largeRange.max == internalrep(9'999'999'999'999'999'999ULL)); - static_assert(largeRange.log == 18); - static_assert(largeRange.min < maxRep); - static_assert(largeRange.max > maxRep); + constexpr static MantissaRange kSMALL_RANGE{MantissaRange::MantissaScale::Small}; + static_assert(isPowerOfTen(kSMALL_RANGE.min)); + static_assert(kSMALL_RANGE.min == 1'000'000'000'000'000LL); + static_assert(kSMALL_RANGE.max == 9'999'999'999'999'999LL); + static_assert(kSMALL_RANGE.log == 15); + static_assert(kSMALL_RANGE.min < kMAX_REP); + static_assert(kSMALL_RANGE.max < kMAX_REP); + constexpr static MantissaRange kLARGE_RANGE{MantissaRange::MantissaScale::Large}; + static_assert(isPowerOfTen(kLARGE_RANGE.min)); + static_assert(kLARGE_RANGE.min == 1'000'000'000'000'000'000ULL); + static_assert(kLARGE_RANGE.max == internalrep(9'999'999'999'999'999'999ULL)); + static_assert(kLARGE_RANGE.log == 18); + static_assert(kLARGE_RANGE.min < kMAX_REP); + static_assert(kLARGE_RANGE.max > kMAX_REP); // The range for the mantissa when normalized. // Use reference_wrapper to avoid making copies, and prevent accidentally // changing the values inside the range. - static thread_local std::reference_wrapper range_; + static thread_local std::reference_wrapper range; void normalize(); @@ -485,8 +485,8 @@ private: friend void doNormalize( bool& negative, - T& mantissa_, - int& exponent_, + T& mantissa, + int& exponent, MantissaRange::rep const& minMantissa, MantissaRange::rep const& maxMantissa); @@ -509,31 +509,31 @@ private: class Guard; }; -constexpr Number::Number(bool negative, internalrep mantissa, int exponent, unchecked) noexcept +constexpr Number::Number(bool negative, internalrep mantissa, int exponent, Unchecked) noexcept : negative_(negative), mantissa_{mantissa}, exponent_{exponent} { } -constexpr Number::Number(internalrep mantissa, int exponent, unchecked) noexcept - : Number(false, mantissa, exponent, unchecked{}) +constexpr Number::Number(internalrep mantissa, int exponent, Unchecked) noexcept + : Number(false, mantissa, exponent, Unchecked{}) { } -constexpr static Number numZero{}; +constexpr static Number kNUM_ZERO{}; -inline Number::Number(bool negative, internalrep mantissa, int exponent, normalized) - : Number(negative, mantissa, exponent, unchecked{}) +inline Number::Number(bool negative, internalrep mantissa, int exponent, Normalized) + : Number(negative, mantissa, exponent, Unchecked{}) { normalize(); } -inline Number::Number(internalrep mantissa, int exponent, normalized) - : Number(false, mantissa, exponent, normalized{}) +inline Number::Number(internalrep mantissa, int exponent, Normalized) + : Number(false, mantissa, exponent, Normalized{}) { } inline Number::Number(rep mantissa, int exponent) - : Number(mantissa < 0, externalToInternal(mantissa), exponent, normalized{}) + : Number(mantissa < 0, externalToInternal(mantissa), exponent, Normalized{}) { } @@ -550,10 +550,10 @@ constexpr Number::rep Number::mantissa() const noexcept { auto m = mantissa_; - if (m > maxRep) + if (m > kMAX_REP) { XRPL_ASSERT_PARTS( - !isnormal() || (m % 10 == 0 && m / 10 <= maxRep), + !isnormal() || (m % 10 == 0 && m / 10 <= kMAX_REP), "xrpl::Number::mantissa", "large normalized mantissa has no remainder"); m /= 10; @@ -571,10 +571,10 @@ constexpr int Number::exponent() const noexcept { auto e = exponent_; - if (mantissa_ > maxRep) + if (mantissa_ > kMAX_REP) { XRPL_ASSERT_PARTS( - !isnormal() || (mantissa_ % 10 == 0 && mantissa_ / 10 <= maxRep), + !isnormal() || (mantissa_ % 10 == 0 && mantissa_ / 10 <= kMAX_REP), "xrpl::Number::exponent", "large normalized mantissa has no remainder"); ++e; @@ -669,29 +669,29 @@ operator/(Number const& x, Number const& y) inline Number Number::min() noexcept { - return Number{false, range_.get().min, minExponent, unchecked{}}; + return Number{false, range.get().min, kMIN_EXPONENT, Unchecked{}}; } inline Number Number::max() noexcept { - return Number{false, std::min(range_.get().max, maxRep), maxExponent, unchecked{}}; + return Number{false, std::min(range.get().max, kMAX_REP), kMAX_EXPONENT, Unchecked{}}; } inline Number Number::lowest() noexcept { - return Number{true, std::min(range_.get().max, maxRep), maxExponent, unchecked{}}; + return Number{true, std::min(range.get().max, kMAX_REP), kMAX_EXPONENT, Unchecked{}}; } inline bool Number::isnormal() const noexcept { - MantissaRange const& range = range_; - auto const abs_m = mantissa_; + MantissaRange const& range = range; + auto const absM = mantissa_; return *this == Number{} || - (range.min <= abs_m && abs_m <= range.max && (abs_m <= maxRep || abs_m % 10 == 0) && - minExponent <= exponent_ && exponent_ <= maxExponent); + (range.min <= absM && absM <= range.max && (absM <= kMAX_REP || absM % 10 == 0) && + kMIN_EXPONENT <= exponent_ && exponent_ <= kMAX_EXPONENT); } template @@ -755,34 +755,34 @@ squelch(Number const& x, Number const& limit) noexcept } inline std::string -to_string(MantissaRange::mantissa_scale const& scale) +to_string(MantissaRange::MantissaScale const& scale) { switch (scale) { - case MantissaRange::mantissa_scale::small: + case MantissaRange::MantissaScale::Small: return "small"; - case MantissaRange::mantissa_scale::large: + case MantissaRange::MantissaScale::Large: return "large"; default: throw std::runtime_error("Bad scale"); } } -class saveNumberRoundMode +class SaveNumberRoundMode { - Number::rounding_mode mode_; + Number::RoundingMode mode_; public: - ~saveNumberRoundMode() + ~SaveNumberRoundMode() { Number::setround(mode_); } - explicit saveNumberRoundMode(Number::rounding_mode mode) noexcept : mode_{mode} + explicit SaveNumberRoundMode(Number::RoundingMode mode) noexcept : mode_{mode} { } - saveNumberRoundMode(saveNumberRoundMode const&) = delete; - saveNumberRoundMode& - operator=(saveNumberRoundMode const&) = delete; + SaveNumberRoundMode(SaveNumberRoundMode const&) = delete; + SaveNumberRoundMode& + operator=(SaveNumberRoundMode const&) = delete; }; // saveNumberRoundMode doesn't do quite enough for us. What we want is a @@ -791,10 +791,10 @@ public: // build it here. class NumberRoundModeGuard { - saveNumberRoundMode saved_; + SaveNumberRoundMode saved_; public: - explicit NumberRoundModeGuard(Number::rounding_mode mode) noexcept + explicit NumberRoundModeGuard(Number::RoundingMode mode) noexcept : saved_{Number::setround(mode)} { } @@ -812,10 +812,10 @@ public: */ class NumberMantissaScaleGuard { - MantissaRange::mantissa_scale const saved_; + MantissaRange::MantissaScale const saved_; public: - explicit NumberMantissaScaleGuard(MantissaRange::mantissa_scale scale) noexcept + explicit NumberMantissaScaleGuard(MantissaRange::MantissaScale scale) noexcept : saved_{Number::getMantissaScale()} { Number::setMantissaScale(scale); diff --git a/include/xrpl/basics/SHAMapHash.h b/include/xrpl/basics/SHAMapHash.h index bf688be7da..3b93d1f151 100644 --- a/include/xrpl/basics/SHAMapHash.h +++ b/include/xrpl/basics/SHAMapHash.h @@ -21,12 +21,12 @@ public: } [[nodiscard]] uint256 const& - as_uint256() const + asUint256() const { return hash_; } uint256& - as_uint256() + asUint256() { return hash_; } @@ -93,7 +93,7 @@ template <> inline std::size_t extract(SHAMapHash const& key) { - return *reinterpret_cast(key.as_uint256().data()); + return *reinterpret_cast(key.asUint256().data()); } } // namespace xrpl diff --git a/include/xrpl/basics/SharedWeakCachePointer.h b/include/xrpl/basics/SharedWeakCachePointer.h index 05d3891e5f..c2c3239eea 100644 --- a/include/xrpl/basics/SharedWeakCachePointer.h +++ b/include/xrpl/basics/SharedWeakCachePointer.h @@ -73,7 +73,7 @@ public: /** If this is a strong pointer, return the strong count. Otherwise return 0 */ [[nodiscard]] std::size_t - use_count() const; + useCount() const; /** Return true if there is a non-zero strong count. */ [[nodiscard]] bool diff --git a/include/xrpl/basics/SharedWeakCachePointer.ipp b/include/xrpl/basics/SharedWeakCachePointer.ipp index bb1e201ca8..2f8345e645 100644 --- a/include/xrpl/basics/SharedWeakCachePointer.ipp +++ b/include/xrpl/basics/SharedWeakCachePointer.ipp @@ -57,10 +57,10 @@ template std::shared_ptr const& SharedWeakCachePointer::getStrong() const { - static std::shared_ptr const empty; + static std::shared_ptr const kEMPTY; if (auto p = std::get_if>(&combo_)) return *p; - return empty; + return kEMPTY; } template @@ -86,7 +86,7 @@ SharedWeakCachePointer::get() const template std::size_t -SharedWeakCachePointer::use_count() const +SharedWeakCachePointer::useCount() const { if (auto p = std::get_if>(&combo_)) return p->use_count(); diff --git a/include/xrpl/basics/SlabAllocator.h b/include/xrpl/basics/SlabAllocator.h index ddcc89d2da..fa31854a2b 100644 --- a/include/xrpl/basics/SlabAllocator.h +++ b/include/xrpl/basics/SlabAllocator.h @@ -36,32 +36,32 @@ class SlabAllocator struct SlabBlock { // A mutex to protect the freelist for this block: - std::mutex m_; + std::mutex m; // A linked list of appropriately sized free buffers: - std::uint8_t* l_ = nullptr; + std::uint8_t* l = nullptr; // The next memory block - SlabBlock* next_; + SlabBlock* next; // The underlying memory block: - std::uint8_t const* const p_ = nullptr; + std::uint8_t const* const p = nullptr; // The extent of the underlying memory block: - std::size_t const size_; + std::size_t const size; SlabBlock(SlabBlock* next, std::uint8_t* data, std::size_t size, std::size_t item) - : next_(next), p_(data), size_(size) + : next(next), p(data), size(size) { // We don't need to grab the mutex here, since we're the only // ones with access at this moment. - while (data + item <= p_ + size_) + while (data + item <= p + size) { // Use memcpy to avoid unaligned UB // (will optimize to equivalent code) - std::memcpy(data, static_cast(&l_), sizeof(std::uint8_t*)); - l_ = data; + std::memcpy(data, static_cast(&l), sizeof(std::uint8_t*)); + l = data; data += item; } } @@ -83,7 +83,7 @@ class SlabAllocator bool own(std::uint8_t const* p) const noexcept { - return (p >= p_) && (p < p_ + size_); + return (p >= p) && (p < p + size); } std::uint8_t* @@ -92,15 +92,15 @@ class SlabAllocator std::uint8_t* ret = nullptr; // NOLINT(misc-const-correctness) { - std::scoped_lock const l(m_); + std::scoped_lock const l(m); - ret = l_; + ret = l; if (ret != nullptr) { // Use memcpy to avoid unaligned UB // (will optimize to equivalent code) - std::memcpy(static_cast(&l_), ret, sizeof(std::uint8_t*)); + std::memcpy(static_cast(&l), ret, sizeof(std::uint8_t*)); } } @@ -121,12 +121,12 @@ class SlabAllocator { XRPL_ASSERT(own(ptr), "xrpl::SlabAllocator::SlabBlock::deallocate : own input"); - std::scoped_lock const l(m_); + std::scoped_lock const l(m); // Use memcpy to avoid unaligned UB // (will optimize to equivalent code) - std::memcpy(ptr, static_cast(&l_), sizeof(std::uint8_t*)); - l_ = ptr; + std::memcpy(ptr, static_cast(&l), sizeof(std::uint8_t*)); + l = ptr; } }; @@ -201,7 +201,7 @@ public: if (auto ret = slab->allocate()) return ret; - slab = slab->next_; + slab = slab->next; } // No slab can satisfy our request, so we attempt to allocate a new @@ -242,7 +242,7 @@ public: // Link the new slab while (!slabs_.compare_exchange_weak( - slab->next_, slab, std::memory_order_release, std::memory_order_relaxed)) + slab->next, slab, std::memory_order_release, std::memory_order_relaxed)) { ; // Nothing to do } @@ -265,7 +265,7 @@ public: "xrpl::SlabAllocator::SlabAllocator::deallocate : non-null " "input"); - for (auto slab = slabs_.load(); slab != nullptr; slab = slab->next_) + for (auto slab = slabs_.load(); slab != nullptr; slab = slab->next) { if (slab->own(ptr)) { @@ -294,16 +294,16 @@ public: friend class SlabAllocatorSet; private: - std::size_t extra; - std::size_t alloc; - std::size_t align; + std::size_t extra_; + std::size_t alloc_; + std::size_t align_; public: constexpr SlabConfig( - std::size_t extra_, - std::size_t alloc_ = 0, - std::size_t align_ = alignof(Type)) - : extra(extra_), alloc(alloc_), align(align_) + std::size_t extra, + std::size_t alloc = 0, + std::size_t align = alignof(Type)) + : extra_(extra), alloc_(alloc), align_(align) { } }; @@ -313,13 +313,13 @@ public: // Ensure that the specified allocators are sorted from smallest to // largest by size: std::sort(std::begin(cfg), std::end(cfg), [](SlabConfig const& a, SlabConfig const& b) { - return a.extra < b.extra; + return a.extra_ < b.extra_; }); // We should never have two slabs of the same size if (std::adjacent_find( std::begin(cfg), std::end(cfg), [](SlabConfig const& a, SlabConfig const& b) { - return a.extra == b.extra; + return a.extra_ == b.extra_; }) != cfg.end()) { throw std::runtime_error( @@ -328,7 +328,7 @@ public: for (auto const& c : cfg) { - auto& a = allocators_.emplace_back(c.extra, c.alloc, c.align); + auto& a = allocators_.emplace_back(c.extra_, c.alloc_, c.align_); if (a.size() > maxSize_) maxSize_ = a.size(); diff --git a/include/xrpl/basics/Slice.h b/include/xrpl/basics/Slice.h index 4be7d9d0bb..948d012958 100644 --- a/include/xrpl/basics/Slice.h +++ b/include/xrpl/basics/Slice.h @@ -110,7 +110,7 @@ public: /** Shrinks the slice by moving its start forward by n characters. */ void - remove_prefix(std::size_t n) + removePrefix(std::size_t n) { data_ += n; size_ -= n; @@ -118,7 +118,7 @@ public: /** Shrinks the slice by moving its end backward by n characters. */ void - remove_suffix(std::size_t n) + removeSuffix(std::size_t n) { size_ -= n; } diff --git a/include/xrpl/basics/StringUtilities.h b/include/xrpl/basics/StringUtilities.h index 592eee6d53..8bce0079dc 100644 --- a/include/xrpl/basics/StringUtilities.h +++ b/include/xrpl/basics/StringUtilities.h @@ -30,7 +30,7 @@ template std::optional strUnHex(std::size_t strSize, Iterator begin, Iterator end) { - static constexpr std::array const digitLookupTable = []() { + static constexpr std::array const kDIGIT_LOOKUP_TABLE = []() { std::array t{}; for (auto& x : t) @@ -56,7 +56,7 @@ strUnHex(std::size_t strSize, Iterator begin, Iterator end) if (strSize & 1) { - int c = digitLookupTable[*iter++]; + int c = kDIGIT_LOOKUP_TABLE[*iter++]; if (c < 0) return {}; @@ -66,12 +66,12 @@ strUnHex(std::size_t strSize, Iterator begin, Iterator end) while (iter != end) { - int const cHigh = digitLookupTable[*iter++]; + int const cHigh = kDIGIT_LOOKUP_TABLE[*iter++]; if (cHigh < 0) return {}; - int const cLow = digitLookupTable[*iter++]; + int const cLow = kDIGIT_LOOKUP_TABLE[*iter++]; if (cLow < 0) return {}; @@ -94,9 +94,9 @@ strViewUnHex(std::string_view strSrc) return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend()); } -struct parsedURL +struct ParsedUrl { - explicit parsedURL() = default; + explicit ParsedUrl() = default; std::string scheme; std::string username; @@ -106,7 +106,7 @@ struct parsedURL std::string path; bool - operator==(parsedURL const& other) const + operator==(ParsedUrl const& other) const { return scheme == other.scheme && domain == other.domain && port == other.port && path == other.path; @@ -114,7 +114,7 @@ struct parsedURL }; bool -parseUrl(parsedURL& pUrl, std::string const& strUrl); +parseUrl(ParsedUrl& pUrl, std::string const& strUrl); std::string trim_whitespace(std::string str); diff --git a/include/xrpl/basics/TaggedCache.h b/include/xrpl/basics/TaggedCache.h index 95703f0633..8517462747 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -35,7 +35,7 @@ template < bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer, class SharedPointerType = std::shared_ptr, - class Hash = hardened_hash<>, + class Hash = HardenedHash<>, class KeyEqual = std::equal_to, class Mutex = std::recursive_mutex> class TaggedCache @@ -44,7 +44,7 @@ public: using mutex_type = Mutex; using key_type = Key; using mapped_type = T; - using clock_type = beast::abstract_clock; + using clock_type = beast::AbstractClock; using shared_weak_combo_pointer_type = SharedWeakUnionPointerType; using shared_pointer_type = SharedPointerType; @@ -86,7 +86,7 @@ public: */ template bool - touch_if_exists(KeyComparable const& key); + touchIfExists(KeyComparable const& key); using SweptPointersVector = std::vector; @@ -115,10 +115,10 @@ public: canonicalize(key_type const& key, SharedPointerType& data, R&& replaceCallback); bool - canonicalize_replace_cache(key_type const& key, SharedPointerType const& data); + canonicalizeReplaceCache(key_type const& key, SharedPointerType const& data); bool - canonicalize_replace_client(key_type const& key, SharedPointerType& data); + canonicalizeReplaceClient(key_type const& key, SharedPointerType& data); SharedPointerType fetch(key_type const& key); @@ -169,7 +169,7 @@ private: initialFetch(key_type const& key, std::scoped_lock const& l); void - collect_metrics(); + collectMetrics(); private: struct Stats @@ -179,9 +179,9 @@ private: std::string const& prefix, Handler const& handler, beast::insight::Collector::ptr const& collector) - : hook(collector->make_hook(handler)) - , size(collector->make_gauge(prefix, "size")) - , hit_rate(collector->make_gauge(prefix, "hit_rate")) + : hook(collector->makeHook(handler)) + , size(collector->makeGauge(prefix, "size")) + , hit_rate(collector->makeGauge(prefix, "hit_rate")) { } @@ -199,8 +199,7 @@ private: public: clock_type::time_point last_access; - explicit KeyOnlyEntry(clock_type::time_point const& last_access_) - : last_access(last_access_) + explicit KeyOnlyEntry(clock_type::time_point const& lastAccess) : last_access(lastAccess) { } @@ -217,8 +216,8 @@ private: shared_weak_combo_pointer_type ptr; clock_type::time_point last_access; - ValueEntry(clock_type::time_point const& last_access_, shared_pointer_type const& ptr_) - : ptr(ptr_), last_access(last_access_) + ValueEntry(clock_type::time_point const& lastAccess, shared_pointer_type const& ptr) + : ptr(ptr), last_access(lastAccess) { } @@ -261,7 +260,7 @@ private: [[nodiscard]] std::thread sweepHelper( - clock_type::time_point const& when_expire, + clock_type::time_point const& whenExpire, [[maybe_unused]] clock_type::time_point const& now, typename KeyValueCacheType::map_type& partition, SweptPointersVector& stuffToSweep, @@ -270,33 +269,33 @@ private: [[nodiscard]] std::thread sweepHelper( - clock_type::time_point const& when_expire, + clock_type::time_point const& whenExpire, clock_type::time_point const& now, typename KeyOnlyCacheType::map_type& partition, SweptPointersVector&, std::atomic& allRemovals, std::scoped_lock const&); - beast::Journal m_journal; - clock_type& m_clock; - Stats m_stats; + beast::Journal m_journal_; + clock_type& m_clock_; + Stats m_stats_; - mutex_type mutable m_mutex; + mutex_type mutable m_mutex_; // Used for logging - std::string m_name; + std::string m_name_; // Desired number of cache entries (0 = ignore) - int const m_target_size; + int const m_target_size_; // Desired maximum cache age - clock_type::duration const m_target_age; + clock_type::duration const m_target_age_; // Number of items cached - int m_cache_count{0}; - cache_type m_cache; // Hold strong reference to recent objects - std::uint64_t m_hits{0}; - std::uint64_t m_misses{0}; + int m_cache_count_{0}; + cache_type m_cache_; // Hold strong reference to recent objects + std::uint64_t m_hits_{0}; + std::uint64_t m_misses_{0}; }; } // namespace xrpl diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index 67c80b554e..b79538b8f4 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -30,12 +30,12 @@ inline TaggedCache< clock_type& clock, beast::Journal journal, beast::insight::Collector::ptr const& collector) - : m_journal(journal) - , m_clock(clock) - , m_stats(name, std::bind(&TaggedCache::collect_metrics, this), collector) - , m_name(name) - , m_target_size(size) - , m_target_age(expiration) + : m_journal_(journal) + , m_clock_(clock) + , m_stats_(name, std::bind(&TaggedCache::collectMetrics, this), collector) + , m_name_(name) + , m_target_size_(size) + , m_target_age_(expiration) { } @@ -53,7 +53,7 @@ inline auto TaggedCache:: clock() -> clock_type& { - return m_clock; + return m_clock_; } template < @@ -69,8 +69,8 @@ inline std::size_t TaggedCache:: size() const { - std::scoped_lock lock(m_mutex); - return m_cache.size(); + std::scoped_lock lock(m_mutex_); + return m_cache_.size(); } template < @@ -86,8 +86,8 @@ inline int TaggedCache:: getCacheSize() const { - std::scoped_lock lock(m_mutex); - return m_cache_count; + std::scoped_lock lock(m_mutex_); + return m_cache_count_; } template < @@ -103,8 +103,8 @@ inline int TaggedCache:: getTrackSize() const { - std::scoped_lock lock(m_mutex); - return m_cache.size(); + std::scoped_lock lock(m_mutex_); + return m_cache_.size(); } template < @@ -120,9 +120,9 @@ inline float TaggedCache:: getHitRate() { - std::scoped_lock lock(m_mutex); - auto const total = static_cast(m_hits + m_misses); - return m_hits * (100.0f / std::max(1.0f, total)); + std::scoped_lock lock(m_mutex_); + auto const total = static_cast(m_hits_ + m_misses_); + return m_hits_ * (100.0f / std::max(1.0f, total)); } template < @@ -138,9 +138,9 @@ inline void TaggedCache:: clear() { - std::scoped_lock lock(m_mutex); - m_cache.clear(); - m_cache_count = 0; + std::scoped_lock lock(m_mutex_); + m_cache_.clear(); + m_cache_count_ = 0; } template < @@ -156,11 +156,11 @@ inline void TaggedCache:: reset() { - std::scoped_lock lock(m_mutex); - m_cache.clear(); - m_cache_count = 0; - m_hits = 0; - m_misses = 0; + std::scoped_lock lock(m_mutex_); + m_cache_.clear(); + m_cache_count_ = 0; + m_hits_ = 0; + m_misses_ = 0; } template < @@ -175,17 +175,17 @@ template < template inline bool TaggedCache:: - touch_if_exists(KeyComparable const& key) + touchIfExists(KeyComparable const& key) { - std::scoped_lock lock(m_mutex); - auto const iter(m_cache.find(key)); - if (iter == m_cache.end()) + std::scoped_lock lock(m_mutex_); + auto const iter(m_cache_.find(key)); + if (iter == m_cache_.end()) { - ++m_stats.misses; + ++m_stats_.misses; return false; } - iter->second.touch(m_clock.now()); - ++m_stats.hits; + iter->second.touch(m_clock_.now()); + ++m_stats_.hits; return true; } @@ -205,53 +205,53 @@ TaggedCache allStuffToSweep(m_cache.partitions()); + std::vector allStuffToSweep(m_cache_.partitions()); - clock_type::time_point const now(m_clock.now()); - clock_type::time_point when_expire; + clock_type::time_point const now(m_clock_.now()); + clock_type::time_point whenExpire; auto const start = std::chrono::steady_clock::now(); { - std::scoped_lock lock(m_mutex); + std::scoped_lock lock(m_mutex_); - if (m_target_size == 0 || (static_cast(m_cache.size()) <= m_target_size)) + if (m_target_size_ == 0 || (static_cast(m_cache_.size()) <= m_target_size_)) { - when_expire = now - m_target_age; + whenExpire = now - m_target_age_; } else { - when_expire = now - m_target_age * m_target_size / m_cache.size(); + whenExpire = now - m_target_age_ * m_target_size_ / m_cache_.size(); clock_type::duration const minimumAge(std::chrono::seconds(1)); - if (when_expire > (now - minimumAge)) - when_expire = now - minimumAge; + if (whenExpire > (now - minimumAge)) + whenExpire = now - minimumAge; - JLOG(m_journal.trace()) - << m_name << " is growing fast " << m_cache.size() << " of " << m_target_size - << " aging at " << (now - when_expire).count() << " of " << m_target_age.count(); + JLOG(m_journal_.trace()) + << m_name_ << " is growing fast " << m_cache_.size() << " of " << m_target_size_ + << " aging at " << (now - whenExpire).count() << " of " << m_target_age_.count(); } std::vector workers; - workers.reserve(m_cache.partitions()); + workers.reserve(m_cache_.partitions()); std::atomic allRemovals = 0; - for (std::size_t p = 0; p < m_cache.partitions(); ++p) + for (std::size_t p = 0; p < m_cache_.partitions(); ++p) { workers.push_back(sweepHelper( - when_expire, now, m_cache.map()[p], allStuffToSweep[p], allRemovals, lock)); + whenExpire, now, m_cache_.map()[p], allStuffToSweep[p], allRemovals, lock)); } for (std::thread& worker : workers) worker.join(); - m_cache_count -= allRemovals; + m_cache_count_ -= allRemovals; } // At this point allStuffToSweep will go out of scope outside the lock // and decrement the reference count on each strong pointer. - JLOG(m_journal.debug()) << m_name << " TaggedCache sweep lock duration " - << std::chrono::duration_cast( - std::chrono::steady_clock::now() - start) - .count() - << "ms"; + JLOG(m_journal_.debug()) << m_name_ << " TaggedCache sweep lock duration " + << std::chrono::duration_cast( + std::chrono::steady_clock::now() - start) + .count() + << "ms"; } template < @@ -269,11 +269,11 @@ TaggedCachesecond; @@ -282,13 +282,13 @@ TaggedCachesecond; - entry.touch(m_clock.now()); + entry.touch(m_clock_.now()); auto shouldReplace = [&] { if constexpr (std::is_invocable_r_v) @@ -368,12 +368,12 @@ TaggedCache inline bool TaggedCache:: - canonicalize_replace_cache(key_type const& key, SharedPointerType const& data) + canonicalizeReplaceCache(key_type const& key, SharedPointerType const& data) { return canonicalize(key, const_cast(data), []() { return true; }); } @@ -405,7 +405,7 @@ template < class Mutex> inline bool TaggedCache:: - canonicalize_replace_client(key_type const& key, SharedPointerType& data) + canonicalizeReplaceClient(key_type const& key, SharedPointerType& data) { return canonicalize(key, data, []() { return false; }); } @@ -423,10 +423,10 @@ inline SharedPointerType TaggedCache:: fetch(key_type const& key) { - std::scoped_lock l(m_mutex); + std::scoped_lock l(m_mutex_); auto ret = initialFetch(key, l); if (!ret) - ++m_misses; + ++m_misses_; return ret; } @@ -451,12 +451,12 @@ TaggedCache, SharedPointerType>) { auto p = std::make_shared(std::cref(value)); - return canonicalize_replace_client(key, p); + return canonicalizeReplaceClient(key, p); } if constexpr (std::is_same_v, SharedPointerType>) { auto p = intr_ptr::make_shared(std::cref(value)); - return canonicalize_replace_client(key, p); + return canonicalizeReplaceClient(key, p); } } @@ -474,9 +474,9 @@ inline auto TaggedCache:: insert(key_type const& key) -> std::enable_if_t { - std::scoped_lock lock(m_mutex); - clock_type::time_point const now(m_clock.now()); - auto [it, inserted] = m_cache.emplace( + std::scoped_lock lock(m_mutex_); + clock_type::time_point const now(m_clock_.now()); + auto [it, inserted] = m_cache_.emplace( std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(now)); if (!inserted) it->second.last_access = now; @@ -519,7 +519,7 @@ inline auto TaggedCache:: peekMutex() -> mutex_type& { - return m_mutex; + return m_mutex_; } template < @@ -538,9 +538,9 @@ TaggedCache v; { - std::scoped_lock lock(m_mutex); - v.reserve(m_cache.size()); - for (auto const& _ : m_cache) + std::scoped_lock lock(m_mutex_); + v.reserve(m_cache_.size()); + for (auto const& _ : m_cache_) v.push_back(_.first); } @@ -560,11 +560,11 @@ inline double TaggedCache:: rate() const { - std::scoped_lock lock(m_mutex); - auto const tot = m_hits + m_misses; + std::scoped_lock lock(m_mutex_); + auto const tot = m_hits_ + m_misses_; if (tot == 0) return 0; - return double(m_hits) / tot; + return double(m_hits_) / tot; } template < @@ -582,7 +582,7 @@ TaggedCachesecond.touch(m_clock.now()); + it->second.touch(m_clock_.now()); return it->second.ptr.getStrong(); } // End CachedSLEs functions. @@ -613,27 +613,27 @@ inline SharedPointerType TaggedCache:: initialFetch(key_type const& key, std::scoped_lock const& l) { - auto cit = m_cache.find(key); - if (cit == m_cache.end()) + auto cit = m_cache_.find(key); + if (cit == m_cache_.end()) return {}; Entry& entry = cit->second; if (entry.isCached()) { - ++m_hits; - entry.touch(m_clock.now()); + ++m_hits_; + entry.touch(m_clock_.now()); return entry.ptr.getStrong(); } entry.ptr = entry.lock(); if (entry.isCached()) { // independent of cache size, so not counted as a hit - ++m_cache_count; - entry.touch(m_clock.now()); + ++m_cache_count_; + entry.touch(m_clock_.now()); return entry.ptr.getStrong(); } - m_cache.erase(cit); + m_cache_.erase(cit); return {}; } @@ -648,19 +648,19 @@ template < class Mutex> inline void TaggedCache:: - collect_metrics() + collectMetrics() { - m_stats.size.set(getCacheSize()); + m_stats_.size.set(getCacheSize()); { - beast::insight::Gauge::value_type hit_rate(0); + beast::insight::Gauge::value_type hitRate(0); { - std::scoped_lock lock(m_mutex); - auto const total(m_hits + m_misses); + std::scoped_lock lock(m_mutex_); + auto const total(m_hits_ + m_misses_); if (total != 0) - hit_rate = (m_hits * 100) / total; + hitRate = (m_hits_ * 100) / total; } - m_stats.hit_rate.set(hit_rate); + m_stats_.hit_rate.set(hitRate); } } @@ -676,7 +676,7 @@ template < inline std::thread TaggedCache:: sweepHelper( - clock_type::time_point const& when_expire, + clock_type::time_point const& whenExpire, [[maybe_unused]] clock_type::time_point const& now, typename KeyValueCacheType::map_type& partition, SweptPointersVector& stuffToSweep, @@ -708,7 +708,7 @@ TaggedCachesecond.last_access <= when_expire) + else if (cit->second.last_access <= whenExpire) { // strong, expired ++cacheRemovals; @@ -735,8 +735,8 @@ TaggedCache= 64, "The length of a base_uint in bits must be at least 64."); - static constexpr std::size_t WIDTH = Bits / 32; + static constexpr std::size_t kWIDTH = Bits / 32; // This is really big-endian in byte order. // We sometimes use std::uint32_t for speed. - std::array data_; + std::array data_; public: //-------------------------------------------------------------------------- @@ -81,8 +81,8 @@ public: // STL Container Interface // - static std::size_t constexpr bytes = Bits / 8; - static_assert(sizeof(data_) == bytes, ""); + static std::size_t constexpr kBYTES = Bits / 8; + static_assert(sizeof(data_) == kBYTES, ""); using size_type = std::size_t; using difference_type = std::ptrdiff_t; @@ -116,7 +116,7 @@ public: iterator end() { - return data() + bytes; + return data() + kBYTES; } [[nodiscard]] const_iterator begin() const @@ -126,7 +126,7 @@ public: [[nodiscard]] const_iterator end() const { - return data() + bytes; + return data() + kBYTES; } [[nodiscard]] const_iterator cbegin() const @@ -136,14 +136,14 @@ public: [[nodiscard]] const_iterator cend() const { - return data() + bytes; + return data() + kBYTES; } /** Value hashing function. The seed prevents crafted inputs from causing degenerate parent containers. */ - using hasher = hardened_hash<>; + using hasher = HardenedHash<>; //-------------------------------------------------------------------------- @@ -160,16 +160,16 @@ private: explicit VoidHelper() = default; }; - explicit base_uint(void const* data, VoidHelper) + explicit BaseUint(void const* data, VoidHelper) { - memcpy(data_.data(), data, bytes); + memcpy(data_.data(), data, kBYTES); } // Helper function to initialize a base_uint from a std::string_view. enum class ParseResult { - okay, - badLength, - badChar, + Okay, + BadLength, + BadChar, }; constexpr Expected @@ -180,7 +180,7 @@ private: auto hexCharToUInt = [](char c, std::uint32_t shift, std::uint32_t& accum) -> ParseResult { std::uint32_t nibble = 0xFFu; if (c < '0' || c > 'f') - return ParseResult::badChar; + return ParseResult::BadChar; if (c >= 'a') { @@ -196,11 +196,11 @@ private: } if (nibble > 0xFu) - return ParseResult::badChar; + return ParseResult::BadChar; accum |= (nibble << shift); - return ParseResult::okay; + return ParseResult::Okay; }; decltype(data_) ret{}; @@ -211,7 +211,7 @@ private: } if (sv.size() != size() * 2) - return Unexpected(ParseResult::badLength); + return Unexpected(ParseResult::BadLength); std::size_t i = 0u; auto in = sv.begin(); @@ -221,7 +221,7 @@ private: for (std::uint32_t const shift : {4u, 0u, 12u, 8u, 20u, 16u, 28u, 24u}) { if (auto const result = hexCharToUInt(*in++, shift, accum); - result != ParseResult::okay) + result != ParseResult::Okay) return Unexpected(result); } ret[i++] = accum; @@ -244,15 +244,15 @@ private: } public: - constexpr base_uint() : data_{} + constexpr BaseUint() : data_{} { } - constexpr base_uint(beast::Zero) : data_{} + constexpr BaseUint(beast::Zero) : data_{} { } - explicit base_uint(std::uint64_t b) + explicit BaseUint(std::uint64_t b) { *this = b; } @@ -260,7 +260,7 @@ public: // This constructor is intended to be used at compile time since it might // throw at runtime. Consider declaring this constructor consteval once // we get to C++23. - explicit constexpr base_uint(std::string_view sv) noexcept(false) + explicit constexpr BaseUint(std::string_view sv) noexcept(false) : data_(parseFromStringViewThrows(sv)) { } @@ -268,9 +268,9 @@ public: template < class Container, class = std::enable_if_t< - detail::is_contiguous_container::value && + detail::IsContiguousContainer::value && std::is_trivially_copyable_v>> - explicit base_uint(Container const& c) + explicit BaseUint(Container const& c) { XRPL_ASSERT( c.size() * sizeof(typename Container::value_type) == size(), @@ -280,9 +280,9 @@ public: template std::enable_if_t< - detail::is_contiguous_container::value && + detail::IsContiguousContainer::value && std::is_trivially_copyable_v, - base_uint&> + BaseUint&> operator=(Container const& c) { XRPL_ASSERT( @@ -295,14 +295,14 @@ public: /* Construct from a raw pointer. The buffer pointed to by `data` must be at least Bits/8 bytes. */ - static base_uint + static BaseUint fromVoid(void const* data) { - return base_uint(data, VoidHelper()); + return BaseUint(data, VoidHelper()); } template - static std::optional + static std::optional fromVoidChecked(T const& from) { if (from.size() != size()) @@ -313,7 +313,7 @@ public: [[nodiscard]] constexpr int signum() const { - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < kWIDTH; i++) { if (data_[i] != 0) return 1; @@ -325,24 +325,24 @@ public: bool operator!() const { - return *this == beast::zero; + return *this == beast::kZERO; } - constexpr base_uint + constexpr BaseUint operator~() const { - base_uint ret; + BaseUint ret; - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < kWIDTH; i++) ret.data_[i] = ~data_[i]; return ret; } - base_uint& + BaseUint& operator=(std::uint64_t uHost) { - *this = beast::zero; + *this = beast::kZERO; // NOLINTBEGIN(cppcoreguidelines-pro-type-member-init) union { @@ -352,43 +352,43 @@ public: // NOLINTEND(cppcoreguidelines-pro-type-member-init) // Put in least significant bits. ul = boost::endian::native_to_big(uHost); - data_[WIDTH - 2] = u[0]; - data_[WIDTH - 1] = u[1]; + data_[kWIDTH - 2] = u[0]; + data_[kWIDTH - 1] = u[1]; return *this; } - base_uint& - operator^=(base_uint const& b) + BaseUint& + operator^=(BaseUint const& b) { - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < kWIDTH; i++) data_[i] ^= b.data_[i]; return *this; } - base_uint& - operator&=(base_uint const& b) + BaseUint& + operator&=(BaseUint const& b) { - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < kWIDTH; i++) data_[i] &= b.data_[i]; return *this; } - base_uint& - operator|=(base_uint const& b) + BaseUint& + operator|=(BaseUint const& b) { - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < kWIDTH; i++) data_[i] |= b.data_[i]; return *this; } - base_uint& + BaseUint& operator++() { // prefix operator - for (int i = WIDTH - 1; i >= 0; --i) + for (int i = kWIDTH - 1; i >= 0; --i) { data_[i] = boost::endian::native_to_big(boost::endian::big_to_native(data_[i]) + 1); if (data_[i] != 0) @@ -398,20 +398,20 @@ public: return *this; } - base_uint + BaseUint operator++(int) { // postfix operator - base_uint const ret = *this; + BaseUint const ret = *this; ++(*this); return ret; } - base_uint& + BaseUint& operator--() { - for (int i = WIDTH - 1; i >= 0; --i) + for (int i = kWIDTH - 1; i >= 0; --i) { auto prev = data_[i]; data_[i] = boost::endian::native_to_big(boost::endian::big_to_native(data_[i]) - 1); @@ -423,36 +423,36 @@ public: return *this; } - base_uint + BaseUint operator--(int) { // postfix operator - base_uint const ret = *this; + BaseUint const ret = *this; --(*this); return ret; } - [[nodiscard]] base_uint + [[nodiscard]] BaseUint next() const { auto ret = *this; return ++ret; } - [[nodiscard]] base_uint + [[nodiscard]] BaseUint prev() const { auto ret = *this; return --ret; } - base_uint& - operator+=(base_uint const& b) + BaseUint& + operator+=(BaseUint const& b) { std::uint64_t carry = 0; - for (int i = WIDTH - 1; i >= 0; i--) + for (int i = kWIDTH - 1; i >= 0; i--) { std::uint64_t const n = carry + boost::endian::big_to_native(data_[i]) + boost::endian::big_to_native(b.data_[i]); @@ -466,7 +466,7 @@ public: template friend void - hash_append(Hasher& h, base_uint const& a) noexcept + hash_append(Hasher& h, BaseUint const& a) noexcept { // Do not allow any endian transformations on this memory h(a.data_.data(), sizeof(a.data_)); @@ -506,10 +506,10 @@ public: constexpr static std::size_t size() { - return bytes; + return kBYTES; } - base_uint& + BaseUint& operator=(beast::Zero) { data_.fill(0); @@ -520,28 +520,28 @@ public: [[nodiscard]] bool isZero() const { - return *this == beast::zero; + return *this == beast::kZERO; } [[nodiscard]] bool isNonZero() const { - return *this != beast::zero; + return *this != beast::kZERO; } void zero() { - *this = beast::zero; + *this = beast::kZERO; } }; -using uint128 = base_uint<128>; -using uint160 = base_uint<160>; -using uint256 = base_uint<256>; -using uint192 = base_uint<192>; +using uint128 = BaseUint<128>; +using uint160 = BaseUint<160>; +using uint256 = BaseUint<256>; +using uint192 = BaseUint<192>; template [[nodiscard]] constexpr std::strong_ordering -operator<=>(base_uint const& lhs, base_uint const& rhs) +operator<=>(BaseUint const& lhs, BaseUint const& rhs) { // This comparison might seem wrong on a casual inspection because it // compares data internally stored as std::uint32_t byte-by-byte. But @@ -562,7 +562,7 @@ operator<=>(base_uint const& lhs, base_uint const& rhs) template [[nodiscard]] constexpr bool -operator==(base_uint const& lhs, base_uint const& rhs) +operator==(BaseUint const& lhs, BaseUint const& rhs) { return (lhs <=> rhs) == 0; } @@ -570,59 +570,59 @@ operator==(base_uint const& lhs, base_uint const& rhs) //------------------------------------------------------------------------------ template constexpr bool -operator==(base_uint const& a, std::uint64_t b) +operator==(BaseUint const& a, std::uint64_t b) { - return a == base_uint(b); + return a == BaseUint(b); } //------------------------------------------------------------------------------ template -constexpr base_uint -operator^(base_uint const& a, base_uint const& b) +constexpr BaseUint +operator^(BaseUint const& a, BaseUint const& b) { - return base_uint(a) ^= b; + return BaseUint(a) ^= b; } template -constexpr base_uint -operator&(base_uint const& a, base_uint const& b) +constexpr BaseUint +operator&(BaseUint const& a, BaseUint const& b) { - return base_uint(a) &= b; + return BaseUint(a) &= b; } template -constexpr base_uint -operator|(base_uint const& a, base_uint const& b) +constexpr BaseUint +operator|(BaseUint const& a, BaseUint const& b) { - return base_uint(a) |= b; + return BaseUint(a) |= b; } template -constexpr base_uint -operator+(base_uint const& a, base_uint const& b) +constexpr BaseUint +operator+(BaseUint const& a, BaseUint const& b) { - return base_uint(a) += b; + return BaseUint(a) += b; } //------------------------------------------------------------------------------ template inline std::string -to_string(base_uint const& a) +to_string(BaseUint const& a) { return strHex(a.cbegin(), a.cend()); } template inline std::string -to_short_string(base_uint const& a) +to_short_string(BaseUint const& a) { - static_assert(base_uint::bytes > 4, "For 4 bytes or less, use a native type"); + static_assert(BaseUint::kBYTES > 4, "For 4 bytes or less, use a native type"); return strHex(a.cbegin(), a.cbegin() + 4) + "..."; } template inline std::ostream& -operator<<(std::ostream& out, base_uint const& u) +operator<<(std::ostream& out, BaseUint const& u) { return out << to_string(u); } @@ -650,7 +650,7 @@ static_assert(sizeof(uint256) == 256 / 8, "There should be no padding bytes"); namespace beast { template -struct is_uniquely_represented> : public std::true_type +struct is_uniquely_represented> : public std::true_type { explicit is_uniquely_represented() = default; }; diff --git a/include/xrpl/basics/chrono.h b/include/xrpl/basics/chrono.h index a9f12b041c..6d3f99e461 100644 --- a/include/xrpl/basics/chrono.h +++ b/include/xrpl/basics/chrono.h @@ -30,10 +30,10 @@ using weeks = std::chrono::duration; using time_point = std::chrono::time_point; - static bool const is_steady = false; + static bool const kIS_STEADY = false; }; template @@ -60,7 +60,7 @@ to_string(NetClock::time_point tp) { // 2000-01-01 00:00:00 UTC is 946684800s from 1970-01-01 00:00:00 UTC using namespace std::chrono; - return to_string(system_clock::time_point{tp.time_since_epoch() + epoch_offset}); + return to_string(system_clock::time_point{tp.time_since_epoch() + kEPOCH_OFFSET}); } template @@ -77,23 +77,23 @@ to_string_iso(NetClock::time_point tp) // 2000-01-01 00:00:00 UTC is 946684800s from 1970-01-01 00:00:00 UTC // Note, NetClock::duration is seconds, as checked by static_assert static_assert(std::is_same_v>); - return to_string_iso(date::sys_time{tp.time_since_epoch() + epoch_offset}); + return to_string_iso(date::sys_time{tp.time_since_epoch() + kEPOCH_OFFSET}); } /** A clock for measuring elapsed time. The epoch is unspecified. */ -using Stopwatch = beast::abstract_clock; +using Stopwatch = beast::AbstractClock; /** A manual Stopwatch for unit tests. */ -using TestStopwatch = beast::manual_clock; +using TestStopwatch = beast::ManualClock; /** Returns an instance of a wall clock. */ inline Stopwatch& stopwatch() { - using Clock = beast::basic_seconds_clock; + using Clock = beast::BasicSecondsClock; using Facade = Clock::Clock; return beast::get_abstract_clock(); } diff --git a/include/xrpl/basics/hardened_hash.h b/include/xrpl/basics/hardened_hash.h index 2722a5a4a7..38865ce5fc 100644 --- a/include/xrpl/basics/hardened_hash.h +++ b/include/xrpl/basics/hardened_hash.h @@ -18,22 +18,22 @@ template seed_pair make_seed_pair() noexcept { - struct state_t + struct StateT { std::mutex mutex; std::random_device rng; std::mt19937_64 gen; std::uniform_int_distribution dist; - state_t() : gen(rng()) + StateT() : gen(rng()) { } // state_t(state_t const&) = delete; // state_t& operator=(state_t const&) = delete; }; - static state_t state; - std::scoped_lock const lock(state.mutex); - return {state.dist(state.gen), state.dist(state.gen)}; + static StateT kSTATE; + std::scoped_lock const lock(kSTATE.mutex); + return {kSTATE.dist(kSTATE.gen), kSTATE.dist(kSTATE.gen)}; } } // namespace detail @@ -68,22 +68,22 @@ make_seed_pair() noexcept see https://131002.net/siphash/#at */ -template -class hardened_hash +template +class HardenedHash { private: - detail::seed_pair m_seeds{detail::make_seed_pair<>()}; + detail::seed_pair m_seeds_{detail::make_seed_pair<>()}; public: using result_type = typename HashAlgorithm::result_type; - hardened_hash() = default; + HardenedHash() = default; template result_type operator()(T const& t) const noexcept { - HashAlgorithm h(m_seeds.first, m_seeds.second); + HashAlgorithm h(m_seeds_.first, m_seeds_.second); hash_append(h, t); return static_cast(h); } diff --git a/include/xrpl/basics/mulDiv.h b/include/xrpl/basics/mulDiv.h index 2495f07728..8a9bc4f5dc 100644 --- a/include/xrpl/basics/mulDiv.h +++ b/include/xrpl/basics/mulDiv.h @@ -5,7 +5,7 @@ #include namespace xrpl { -auto constexpr muldiv_max = std::numeric_limits::max(); +auto constexpr kMULDIV_MAX = std::numeric_limits::max(); /** Return value*mul/div accurately. Computes the result of the multiplication and division in diff --git a/include/xrpl/basics/partitioned_unordered_map.h b/include/xrpl/basics/partitioned_unordered_map.h index 33fe63e91b..a223acb383 100644 --- a/include/xrpl/basics/partitioned_unordered_map.h +++ b/include/xrpl/basics/partitioned_unordered_map.h @@ -24,7 +24,7 @@ template <> inline std::size_t extract(std::string const& key) { - return ::beast::uhash<>{}(key); + return ::beast::Uhash<>{}(key); } template < @@ -33,7 +33,7 @@ template < typename Hash, typename Pred = std::equal_to, typename Alloc = std::allocator>> -class partitioned_unordered_map +class PartitionedUnorderedMap { std::size_t partitions_; @@ -53,46 +53,46 @@ public: using map_type = std::unordered_map; using partition_map_type = std::vector; - struct iterator + struct Iterator { using iterator_category = std::forward_iterator_tag; - partition_map_type* map_{nullptr}; - typename partition_map_type::iterator ait_{}; - typename map_type::iterator mit_; + partition_map_type* map{nullptr}; + typename partition_map_type::iterator ait{}; + typename map_type::iterator mit; - iterator() = default; + Iterator() = default; - iterator(partition_map_type* map) : map_(map) + Iterator(partition_map_type* map) : map(map) { } reference operator*() const { - return *mit_; + return *mit; } pointer operator->() const { - return &(*mit_); + return &(*mit); } void inc() { - ++mit_; - while (mit_ == ait_->end()) + ++mit; + while (mit == ait->end()) { - ++ait_; - if (ait_ == map_->end()) + ++ait; + if (ait == map->end()) return; - mit_ = ait_->begin(); + mit = ait->begin(); } } // ++it - iterator& + Iterator& operator++() { inc(); @@ -100,75 +100,75 @@ public: } // it++ - iterator + Iterator operator++(int) { - iterator tmp(*this); + Iterator tmp(*this); inc(); return tmp; } friend bool - operator==(iterator const& lhs, iterator const& rhs) + operator==(Iterator const& lhs, Iterator const& rhs) { - return lhs.map_ == rhs.map_ && lhs.ait_ == rhs.ait_ && lhs.mit_ == rhs.mit_; + return lhs.map == rhs.map && lhs.ait == rhs.ait && lhs.mit == rhs.mit; } friend bool - operator!=(iterator const& lhs, iterator const& rhs) + operator!=(Iterator const& lhs, Iterator const& rhs) { return !(lhs == rhs); } }; - struct const_iterator + struct ConstIterator { using iterator_category = std::forward_iterator_tag; - partition_map_type* map_{nullptr}; - typename partition_map_type::iterator ait_{}; - typename map_type::iterator mit_; + partition_map_type* map{nullptr}; + typename partition_map_type::iterator ait{}; + typename map_type::iterator mit; - const_iterator() = default; + ConstIterator() = default; - const_iterator(partition_map_type* map) : map_(map) + ConstIterator(partition_map_type* map) : map(map) { } - const_iterator(iterator const& orig) + ConstIterator(Iterator const& orig) { - map_ = orig.map_; - ait_ = orig.ait_; - mit_ = orig.mit_; + map = orig.map; + ait = orig.ait; + mit = orig.mit; } const_reference operator*() const { - return *mit_; + return *mit; } const_pointer operator->() const { - return &(*mit_); + return &(*mit); } void inc() { - ++mit_; - while (mit_ == ait_->end()) + ++mit; + while (mit == ait->end()) { - ++ait_; - if (ait_ == map_->end()) + ++ait; + if (ait == map->end()) return; - mit_ = ait_->begin(); + mit = ait->begin(); } } // ++it - const_iterator& + ConstIterator& operator++() { inc(); @@ -176,22 +176,22 @@ public: } // it++ - const_iterator + ConstIterator operator++(int) { - const_iterator tmp(*this); + ConstIterator tmp(*this); inc(); return tmp; } friend bool - operator==(const_iterator const& lhs, const_iterator const& rhs) + operator==(ConstIterator const& lhs, ConstIterator const& rhs) { - return lhs.map_ == rhs.map_ && lhs.ait_ == rhs.ait_ && lhs.mit_ == rhs.mit_; + return lhs.map == rhs.map && lhs.ait == rhs.ait && lhs.mit == rhs.mit; } friend bool - operator!=(const_iterator const& lhs, const_iterator const& rhs) + operator!=(ConstIterator const& lhs, ConstIterator const& rhs) { return !(lhs == rhs); } @@ -208,8 +208,8 @@ private: static void end(T& it) { - it.ait_ = it.map_->end(); - it.mit_ = it.map_->back().end(); + it.ait = it.map->end(); + it.mit = it.map->back().end(); } template @@ -227,7 +227,7 @@ private: } public: - partitioned_unordered_map(std::optional partitions = std::nullopt) + PartitionedUnorderedMap(std::optional partitions = std::nullopt) { // Set partitions to the number of hardware threads if the parameter // is either empty or set to 0. @@ -252,45 +252,45 @@ public: return map_; } - iterator + Iterator begin() { - iterator it(&map_); + Iterator it(&map_); begin(it); return it; } - const_iterator + ConstIterator cbegin() const { - const_iterator it(&map_); + ConstIterator it(&map_); begin(it); return it; } - const_iterator + ConstIterator begin() const { return cbegin(); } - iterator + Iterator end() { - iterator it(&map_); + Iterator it(&map_); end(it); return it; } - const_iterator + ConstIterator cend() const { - const_iterator it(&map_); + ConstIterator it(&map_); end(it); return it; } - const_iterator + ConstIterator end() const { return cend(); @@ -301,50 +301,50 @@ private: void find(key_type const& key, T& it) const { - it.ait_ = it.map_->begin() + partitioner(key); - it.mit_ = it.ait_->find(key); - if (it.mit_ == it.ait_->end()) + it.ait = it.map->begin() + partitioner(key); + it.mit = it.ait->find(key); + if (it.mit == it.ait->end()) end(it); } public: - iterator + Iterator find(key_type const& key) { - iterator it(&map_); + Iterator it(&map_); find(key, it); return it; } - const_iterator + ConstIterator find(key_type const& key) const { - const_iterator it(&map_); + ConstIterator it(&map_); find(key, it); return it; } template - std::pair + std::pair emplace(std::piecewise_construct_t const&, T&& keyTuple, U&& valueTuple) { auto const& key = std::get<0>(keyTuple); - iterator it(&map_); - it.ait_ = it.map_->begin() + partitioner(key); - auto [eit, inserted] = it.ait_->emplace( + Iterator it(&map_); + it.ait = it.map->begin() + partitioner(key); + auto [eit, inserted] = it.ait->emplace( std::piecewise_construct, std::forward(keyTuple), std::forward(valueTuple)); - it.mit_ = eit; + it.mit = eit; return {it, inserted}; } template - std::pair + std::pair emplace(T&& key, U&& val) { - iterator it(&map_); - it.ait_ = it.map_->begin() + partitioner(key); - auto [eit, inserted] = it.ait_->emplace(std::forward(key), std::forward(val)); - it.mit_ = eit; + Iterator it(&map_); + it.ait = it.map->begin() + partitioner(key); + auto [eit, inserted] = it.ait->emplace(std::forward(key), std::forward(val)); + it.mit = eit; return {it, inserted}; } @@ -355,19 +355,19 @@ public: p.clear(); } - iterator - erase(const_iterator position) + Iterator + erase(ConstIterator position) { - iterator it(&map_); - it.ait_ = position.ait_; - it.mit_ = position.ait_->erase(position.mit_); + Iterator it(&map_); + it.ait = position.ait; + it.mit = position.ait->erase(position.mit); - while (it.mit_ == it.ait_->end()) + while (it.mit == it.ait->end()) { - ++it.ait_; - if (it.ait_ == it.map_->end()) + ++it.ait; + if (it.ait == it.map->end()) break; - it.mit_ = it.ait_->begin(); + it.mit = it.ait->begin(); } return it; diff --git a/include/xrpl/basics/random.h b/include/xrpl/basics/random.h index a4018b7e5f..d27ddd675d 100644 --- a/include/xrpl/basics/random.h +++ b/include/xrpl/basics/random.h @@ -47,27 +47,27 @@ inline beast::xor_shift_engine& default_prng() { // This is used to seed the thread-specific PRNGs on demand - static beast::xor_shift_engine seeder = [] { + static beast::xor_shift_engine kSEEDER = [] { std::random_device rng; std::uniform_int_distribution distribution{1}; return beast::xor_shift_engine(distribution(rng)); }(); // This protects the seeder - static std::mutex m; + static std::mutex kM; // The thread-specific PRNGs: - thread_local beast::xor_shift_engine engine = [] { + thread_local beast::xor_shift_engine kENGINE = [] { std::uint64_t seed = 0; { - std::scoped_lock const lk(m); + std::scoped_lock const lk(kM); std::uniform_int_distribution distribution{1}; - seed = distribution(seeder); + seed = distribution(kSEEDER); } return beast::xor_shift_engine{seed}; }(); - return engine; + return kENGINE; } /** Return a uniformly distributed random integer. diff --git a/include/xrpl/basics/safe_cast.h b/include/xrpl/basics/safe_cast.h index c167e660ce..c4a200373a 100644 --- a/include/xrpl/basics/safe_cast.h +++ b/include/xrpl/basics/safe_cast.h @@ -18,29 +18,29 @@ concept SafeToCast = (std::is_integral_v && std::is_integral_v) && template constexpr std::enable_if_t && std::is_integral_v, Dest> -safe_cast(Src s) noexcept +safeCast(Src s) noexcept { static_assert( std::is_signed_v || std::is_unsigned_v, "Cannot cast signed to unsigned"); - constexpr unsigned not_same = std::is_signed_v != std::is_signed_v; + constexpr unsigned kNOT_SAME = std::is_signed_v != std::is_signed_v; static_assert( - sizeof(Dest) >= sizeof(Src) + not_same, + sizeof(Dest) >= sizeof(Src) + kNOT_SAME, "Destination is too small to hold all values of source"); return static_cast(s); } template constexpr std::enable_if_t && std::is_integral_v, Dest> -safe_cast(Src s) noexcept +safeCast(Src s) noexcept { - return static_cast(safe_cast>(s)); + return static_cast(safeCast>(s)); } template constexpr std::enable_if_t && std::is_enum_v, Dest> -safe_cast(Src s) noexcept +safeCast(Src s) noexcept { - return safe_cast(static_cast>(s)); + return safeCast(static_cast>(s)); } // unsafe_cast explicitly flags a static_cast as not necessarily able to hold @@ -49,7 +49,7 @@ safe_cast(Src s) noexcept template constexpr std::enable_if_t && std::is_integral_v, Dest> -unsafe_cast(Src s) noexcept +unsafeCast(Src s) noexcept { static_assert( !SafeToCast, @@ -60,14 +60,14 @@ unsafe_cast(Src s) noexcept template constexpr std::enable_if_t && std::is_integral_v, Dest> -unsafe_cast(Src s) noexcept +unsafeCast(Src s) noexcept { return static_cast(unsafe_cast>(s)); } template constexpr std::enable_if_t && std::is_enum_v, Dest> -unsafe_cast(Src s) noexcept +unsafeCast(Src s) noexcept { return unsafe_cast(static_cast>(s)); } diff --git a/include/xrpl/basics/tagged_integer.h b/include/xrpl/basics/tagged_integer.h index 129c586126..0cf592fb0e 100644 --- a/include/xrpl/basics/tagged_integer.h +++ b/include/xrpl/basics/tagged_integer.h @@ -23,171 +23,171 @@ namespace xrpl { allowed arithmetic operations. */ template -class tagged_integer : boost::totally_ordered< - tagged_integer, - boost::integer_arithmetic< - tagged_integer, - boost::bitwise< - tagged_integer, - boost::unit_steppable< - tagged_integer, - boost::shiftable>>>>> +class TaggedInteger : boost::totally_ordered< + TaggedInteger, + boost::integer_arithmetic< + TaggedInteger, + boost::bitwise< + TaggedInteger, + boost::unit_steppable< + TaggedInteger, + boost::shiftable>>>>> { private: - Int m_value; + Int m_value_; public: using value_type = Int; using tag_type = Tag; - tagged_integer() = default; + TaggedInteger() = default; template < class OtherInt, class = std::enable_if_t && sizeof(OtherInt) <= sizeof(Int)>> - explicit constexpr tagged_integer(OtherInt value) noexcept : m_value(value) + explicit constexpr TaggedInteger(OtherInt value) noexcept : m_value_(value) { - static_assert(sizeof(tagged_integer) == sizeof(Int), "tagged_integer is adding padding"); + static_assert(sizeof(TaggedInteger) == sizeof(Int), "tagged_integer is adding padding"); } bool - operator<(tagged_integer const& rhs) const noexcept + operator<(TaggedInteger const& rhs) const noexcept { - return m_value < rhs.m_value; + return m_value_ < rhs.m_value_; } bool - operator==(tagged_integer const& rhs) const noexcept + operator==(TaggedInteger const& rhs) const noexcept { - return m_value == rhs.m_value; + return m_value_ == rhs.m_value_; } - tagged_integer& - operator+=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator+=(TaggedInteger const& rhs) noexcept { - m_value += rhs.m_value; + m_value_ += rhs.m_value_; return *this; } - tagged_integer& - operator-=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator-=(TaggedInteger const& rhs) noexcept { - m_value -= rhs.m_value; + m_value_ -= rhs.m_value_; return *this; } - tagged_integer& - operator*=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator*=(TaggedInteger const& rhs) noexcept { - m_value *= rhs.m_value; + m_value_ *= rhs.m_value_; return *this; } - tagged_integer& - operator/=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator/=(TaggedInteger const& rhs) noexcept { - m_value /= rhs.m_value; + m_value_ /= rhs.m_value_; return *this; } - tagged_integer& - operator%=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator%=(TaggedInteger const& rhs) noexcept { - m_value %= rhs.m_value; + m_value_ %= rhs.m_value_; return *this; } - tagged_integer& - operator|=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator|=(TaggedInteger const& rhs) noexcept { - m_value |= rhs.m_value; + m_value_ |= rhs.m_value_; return *this; } - tagged_integer& - operator&=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator&=(TaggedInteger const& rhs) noexcept { - m_value &= rhs.m_value; + m_value_ &= rhs.m_value_; return *this; } - tagged_integer& - operator^=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator^=(TaggedInteger const& rhs) noexcept { - m_value ^= rhs.m_value; + m_value_ ^= rhs.m_value_; return *this; } - tagged_integer& - operator<<=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator<<=(TaggedInteger const& rhs) noexcept { - m_value <<= rhs.m_value; + m_value_ <<= rhs.m_value_; return *this; } - tagged_integer& - operator>>=(tagged_integer const& rhs) noexcept + TaggedInteger& + operator>>=(TaggedInteger const& rhs) noexcept { - m_value >>= rhs.m_value; + m_value_ >>= rhs.m_value_; return *this; } - tagged_integer + TaggedInteger operator~() const noexcept { - return tagged_integer{~m_value}; + return TaggedInteger{~m_value_}; } - tagged_integer + TaggedInteger operator+() const noexcept { return *this; } - tagged_integer + TaggedInteger operator-() const noexcept { - return tagged_integer{-m_value}; + return TaggedInteger{-m_value_}; } - tagged_integer& + TaggedInteger& operator++() noexcept { - ++m_value; + ++m_value_; return *this; } - tagged_integer& + TaggedInteger& operator--() noexcept { - --m_value; + --m_value_; return *this; } explicit operator Int() const noexcept { - return m_value; + return m_value_; } friend std::ostream& - operator<<(std::ostream& s, tagged_integer const& t) + operator<<(std::ostream& s, TaggedInteger const& t) { - s << t.m_value; + s << t.m_value_; return s; } friend std::istream& - operator>>(std::istream& s, tagged_integer& t) + operator>>(std::istream& s, TaggedInteger& t) { - s >> t.m_value; + s >> t.m_value_; return s; } friend std::string - to_string(tagged_integer const& t) + to_string(TaggedInteger const& t) { - return std::to_string(t.m_value); + return std::to_string(t.m_value_); } }; @@ -195,8 +195,8 @@ public: namespace beast { template -struct is_contiguously_hashable, HashAlgorithm> - : public is_contiguously_hashable +struct is_contiguously_hashable, HashAlgorithm> + : public IsContiguouslyHashable { explicit is_contiguously_hashable() = default; }; diff --git a/include/xrpl/beast/clock/abstract_clock.h b/include/xrpl/beast/clock/abstract_clock.h index 09de3f891d..80a718f4e9 100644 --- a/include/xrpl/beast/clock/abstract_clock.h +++ b/include/xrpl/beast/clock/abstract_clock.h @@ -31,7 +31,7 @@ namespace beast { http://en.cppreference.com/w/cpp/concept/Clock */ template -class abstract_clock +class AbstractClock { public: using rep = typename Clock::rep; @@ -40,11 +40,11 @@ public: using time_point = typename Clock::time_point; using clock_type = Clock; - static bool const is_steady = Clock::is_steady; + static bool const kIS_STEADY = Clock::kIS_STEADY; - virtual ~abstract_clock() = default; - abstract_clock() = default; - abstract_clock(abstract_clock const&) = default; + virtual ~AbstractClock() = default; + AbstractClock() = default; + AbstractClock(AbstractClock const&) = default; /** Returns the current time. */ [[nodiscard]] virtual time_point @@ -56,12 +56,12 @@ public: namespace detail { template -struct abstract_clock_wrapper : public abstract_clock +struct AbstractClockWrapper : public AbstractClock { - explicit abstract_clock_wrapper() = default; + explicit AbstractClockWrapper() = default; - using typename abstract_clock::duration; - using typename abstract_clock::time_point; + using typename AbstractClock::duration; + using typename AbstractClock::time_point; [[nodiscard]] time_point now() const override @@ -80,11 +80,11 @@ struct abstract_clock_wrapper : public abstract_clock @tparam Clock The actual concrete clock to use. */ template -abstract_clock& +AbstractClock& get_abstract_clock() { - static detail::abstract_clock_wrapper clock; - return clock; + static detail::AbstractClockWrapper kCLOCK; + return kCLOCK; } } // namespace beast diff --git a/include/xrpl/beast/clock/basic_seconds_clock.h b/include/xrpl/beast/clock/basic_seconds_clock.h index 5205d92fef..cbd0137f40 100644 --- a/include/xrpl/beast/clock/basic_seconds_clock.h +++ b/include/xrpl/beast/clock/basic_seconds_clock.h @@ -13,19 +13,19 @@ namespace beast { @tparam Clock A type meeting these requirements: http://en.cppreference.com/w/cpp/concept/Clock */ -class basic_seconds_clock +class BasicSecondsClock { public: using Clock = std::chrono::steady_clock; - explicit basic_seconds_clock() = default; + explicit BasicSecondsClock() = default; using rep = typename Clock::rep; using period = typename Clock::period; using duration = typename Clock::duration; using time_point = typename Clock::time_point; - static bool const is_steady = Clock::is_steady; + static bool const kIS_STEADY = Clock::is_steady; static time_point now(); diff --git a/include/xrpl/beast/clock/manual_clock.h b/include/xrpl/beast/clock/manual_clock.h index 3cabdc0ea8..9d8f307c5f 100644 --- a/include/xrpl/beast/clock/manual_clock.h +++ b/include/xrpl/beast/clock/manual_clock.h @@ -17,18 +17,18 @@ namespace beast { http://en.cppreference.com/w/cpp/concept/Clock */ template -class manual_clock : public abstract_clock +class ManualClock : public AbstractClock { public: - using typename abstract_clock::rep; - using typename abstract_clock::duration; - using typename abstract_clock::time_point; + using typename AbstractClock::rep; + using typename AbstractClock::duration; + using typename AbstractClock::time_point; private: time_point now_; public: - explicit manual_clock(time_point const& now = time_point(duration(0))) : now_(now) + explicit ManualClock(time_point const& now = time_point(duration(0))) : now_(now) { } @@ -51,9 +51,9 @@ public: /** Convenience for setting the time in seconds from epoch. */ template void - set(Integer seconds_from_epoch) + set(Integer secondsFromEpoch) { - set(time_point(duration(std::chrono::seconds(seconds_from_epoch)))); + set(time_point(duration(std::chrono::seconds(secondsFromEpoch)))); } /** Advance the clock by a duration. */ @@ -68,7 +68,7 @@ public: } /** Convenience for advancing the clock by one second. */ - manual_clock& + ManualClock& operator++() { advance(std::chrono::seconds(1)); diff --git a/include/xrpl/beast/container/aged_container.h b/include/xrpl/beast/container/aged_container.h index dd622fcd9a..4b486440c9 100644 --- a/include/xrpl/beast/container/aged_container.h +++ b/include/xrpl/beast/container/aged_container.h @@ -5,9 +5,9 @@ namespace beast { template -struct is_aged_container : std::false_type +struct IsAgedContainer : std::false_type { - explicit is_aged_container() = default; + explicit IsAgedContainer() = default; }; } // namespace beast diff --git a/include/xrpl/beast/container/aged_unordered_map.h b/include/xrpl/beast/container/aged_unordered_map.h index ea53320e91..ea694ea09f 100644 --- a/include/xrpl/beast/container/aged_unordered_map.h +++ b/include/xrpl/beast/container/aged_unordered_map.h @@ -16,5 +16,5 @@ template < class KeyEqual = std::equal_to, class Allocator = std::allocator>> using aged_unordered_map = - detail::aged_unordered_container; + detail::AgedUnorderedContainer; } // namespace beast diff --git a/include/xrpl/beast/container/detail/aged_associative_container.h b/include/xrpl/beast/container/detail/aged_associative_container.h index 5d3534004c..6b2eab18bc 100644 --- a/include/xrpl/beast/container/detail/aged_associative_container.h +++ b/include/xrpl/beast/container/detail/aged_associative_container.h @@ -3,10 +3,10 @@ namespace beast::detail { // Extracts the key portion of value -template -struct aged_associative_container_extract_t +template +struct AgedAssociativeContainerExtractT { - explicit aged_associative_container_extract_t() = default; + explicit AgedAssociativeContainerExtractT() = default; template decltype(Value::first) const& diff --git a/include/xrpl/beast/container/detail/aged_container_iterator.h b/include/xrpl/beast/container/detail/aged_container_iterator.h index ffa251b7a6..fa7e72e86e 100644 --- a/include/xrpl/beast/container/detail/aged_container_iterator.h +++ b/include/xrpl/beast/container/detail/aged_container_iterator.h @@ -12,13 +12,13 @@ class aged_ordered_container; namespace detail { // If Iterator is SCARY then this iterator will be as well. -template -class aged_container_iterator +template +class AgedContainerIterator { public: using iterator_category = typename std::iterator_traits::iterator_category; using value_type = std::conditional_t< - is_const, + IsConst, typename Iterator::value_type::stashed::value_type const, typename Iterator::value_type::stashed::value_type>; using difference_type = typename std::iterator_traits::difference_type; @@ -26,99 +26,98 @@ public: using reference = value_type&; using time_point = typename Iterator::value_type::stashed::time_point; - aged_container_iterator() = default; + AgedContainerIterator() = default; // Disable constructing a const_iterator from a non-const_iterator. // Converting between reverse and non-reverse iterators should be explicit. template < - bool other_is_const, + bool OtherIsConst, class OtherIterator, class = std::enable_if_t< - (!other_is_const || is_const) && + (!OtherIsConst || IsConst) && !static_cast(std::is_same_v)>> - explicit aged_container_iterator( - aged_container_iterator const& other) - : m_iter(other.m_iter) + explicit AgedContainerIterator(AgedContainerIterator const& other) + : m_iter_(other.m_iter) { } // Disable constructing a const_iterator from a non-const_iterator. - template > - aged_container_iterator(aged_container_iterator const& other) - : m_iter(other.m_iter) + template > + AgedContainerIterator(AgedContainerIterator const& other) + : m_iter_(other.m_iter) { } // Disable assigning a const_iterator to a non-const iterator - template + template auto - operator=(aged_container_iterator const& other) - -> std::enable_if_t + operator=(AgedContainerIterator const& other) + -> std::enable_if_t { - m_iter = other.m_iter; + m_iter_ = other.m_iter; return *this; } - template + template bool - operator==(aged_container_iterator const& other) const + operator==(AgedContainerIterator const& other) const { - return m_iter == other.m_iter; + return m_iter_ == other.m_iter; } - template + template bool - operator!=(aged_container_iterator const& other) const + operator!=(AgedContainerIterator const& other) const { - return m_iter != other.m_iter; + return m_iter_ != other.m_iter; } - aged_container_iterator& + AgedContainerIterator& operator++() { - ++m_iter; + ++m_iter_; return *this; } - aged_container_iterator + AgedContainerIterator operator++(int) { - aged_container_iterator const prev(*this); - ++m_iter; + AgedContainerIterator const prev(*this); + ++m_iter_; return prev; } - aged_container_iterator& + AgedContainerIterator& operator--() { - --m_iter; + --m_iter_; return *this; } - aged_container_iterator + AgedContainerIterator operator--(int) { - aged_container_iterator const prev(*this); - --m_iter; + AgedContainerIterator const prev(*this); + --m_iter_; return prev; } reference operator*() const { - return m_iter->value; + return m_iter_->value; } pointer operator->() const { - return &m_iter->value; + return &m_iter_->value; } [[nodiscard]] time_point const& when() const { - return m_iter->when; + return m_iter_->when; } private: @@ -132,17 +131,17 @@ private: friend class aged_container_iterator; template - aged_container_iterator(OtherIterator iter) : m_iter(std::move(iter)) + AgedContainerIterator(OtherIterator iter) : m_iter_(std::move(iter)) { } [[nodiscard]] Iterator const& iterator() const { - return m_iter; + return m_iter_; } - Iterator m_iter; + Iterator m_iter_; }; } // namespace detail diff --git a/include/xrpl/beast/container/detail/aged_unordered_container.h b/include/xrpl/beast/container/detail/aged_unordered_container.h index 7fe3a8b38a..db30e2e93d 100644 --- a/include/xrpl/beast/container/detail/aged_unordered_container.h +++ b/include/xrpl/beast/container/detail/aged_unordered_container.h @@ -63,10 +63,10 @@ template < class Hash = std::hash, class KeyEqual = std::equal_to, class Allocator = std::allocator, Key>>> -class aged_unordered_container +class AgedUnorderedContainer { public: - using clock_type = abstract_clock; + using clock_type = AbstractClock; using time_point = typename clock_type::time_point; using duration = typename clock_type::duration; using key_type = Key; @@ -84,39 +84,38 @@ private: static Key const& extract(value_type const& value) { - return aged_associative_container_extract_t()(value); + return AgedAssociativeContainerExtractT()(value); } // VFALCO TODO hoist to remove template argument dependencies - struct element : boost::intrusive::unordered_set_base_hook< + struct Element : boost::intrusive::unordered_set_base_hook< boost::intrusive::link_mode>, boost::intrusive::list_base_hook< boost::intrusive::link_mode> { // Stash types here so the iterator doesn't // need to see the container declaration. - struct stashed + struct Stashed { - explicit stashed() = default; + explicit Stashed() = default; - using value_type = typename aged_unordered_container::value_type; - using time_point = typename aged_unordered_container::time_point; + using value_type = typename AgedUnorderedContainer::value_type; + using time_point = typename AgedUnorderedContainer::time_point; }; - element(time_point const& when_, value_type const& value_) : value(value_), when(when_) + Element(time_point const& when, value_type const& value) : value(value), when(when) { } - element(time_point const& when_, value_type&& value_) - : value(std::move(value_)), when(when_) + Element(time_point const& when, value_type&& value) : value(std::move(value)), when(when) { } template < class... Args, class = std::enable_if_t>> - element(time_point const& when_, Args&&... args) - : value(std::forward(args)...), when(when_) + Element(time_point const& when, Args&&... args) + : value(std::forward(args)...), when(when) { } @@ -128,7 +127,7 @@ private: class ValueHash : public Hash { public: - using argument_type = element; + using argument_type = Element; using result_type = size_t; ValueHash() = default; @@ -138,19 +137,19 @@ private: } std::size_t - operator()(element const& e) const + operator()(Element const& e) const { return Hash::operator()(extract(e.value)); } Hash& - hash_function() + hashFunction() { return *this; } [[nodiscard]] Hash const& - hash_function() const + hashFunction() const { return *this; } @@ -162,7 +161,7 @@ private: { public: using first_argument_type = Key; - using second_argument_type = element; + using second_argument_type = Element; using result_type = bool; KeyValueEqual() = default; @@ -172,49 +171,49 @@ private: } bool - operator()(Key const& k, element const& e) const + operator()(Key const& k, Element const& e) const { return KeyEqual::operator()(k, extract(e.value)); } bool - operator()(element const& e, Key const& k) const + operator()(Element const& e, Key const& k) const { return KeyEqual::operator()(extract(e.value), k); } bool - operator()(element const& lhs, element const& rhs) const + operator()(Element const& lhs, Element const& rhs) const { return KeyEqual::operator()(extract(lhs.value), extract(rhs.value)); } KeyEqual& - key_eq() + keyEq() { return *this; } [[nodiscard]] KeyEqual const& - key_eq() const + keyEq() const { return *this; } }; using list_type = typename boost::intrusive:: - make_list>::type; + make_list>::type; using cont_type = std::conditional_t< IsMulti, typename boost::intrusive::make_unordered_multiset< - element, + Element, boost::intrusive::constant_time_size, boost::intrusive::hash, boost::intrusive::equal, boost::intrusive::cache_begin>::type, typename boost::intrusive::make_unordered_set< - element, + Element, boost::intrusive::constant_time_size, boost::intrusive::hash, boost::intrusive::equal, @@ -224,106 +223,105 @@ private: using bucket_traits = typename cont_type::bucket_traits; using ElementAllocator = - typename std::allocator_traits::template rebind_alloc; + typename std::allocator_traits::template rebind_alloc; using ElementAllocatorTraits = std::allocator_traits; using BucketAllocator = - typename std::allocator_traits::template rebind_alloc; + typename std::allocator_traits::template rebind_alloc; using BucketAllocatorTraits = std::allocator_traits; - class config_t : private ValueHash, - private KeyValueEqual, - private beast::detail::empty_base_optimization + class ConfigT : private ValueHash, + private KeyValueEqual, + private beast::detail::EmptyBaseOptimization { public: - explicit config_t(clock_type& clock_) : clock(clock_) + explicit ConfigT(clock_type& clock) : clock(clock) { } - config_t(clock_type& clock_, Hash const& hash) : ValueHash(hash), clock(clock_) + ConfigT(clock_type& clock, Hash const& hash) : ValueHash(hash), clock(clock) { } - config_t(clock_type& clock_, KeyEqual const& keyEqual) - : KeyValueEqual(keyEqual), clock(clock_) + ConfigT(clock_type& clock, KeyEqual const& keyEqual) : KeyValueEqual(keyEqual), clock(clock) { } - config_t(clock_type& clock_, Allocator const& alloc_) - : beast::detail::empty_base_optimization(alloc_), clock(clock_) + ConfigT(clock_type& clock, Allocator const& alloc) + : beast::detail::EmptyBaseOptimization(alloc), clock(clock) { } - config_t(clock_type& clock_, Hash const& hash, KeyEqual const& keyEqual) - : ValueHash(hash), KeyValueEqual(keyEqual), clock(clock_) + ConfigT(clock_type& clock, Hash const& hash, KeyEqual const& keyEqual) + : ValueHash(hash), KeyValueEqual(keyEqual), clock(clock) { } - config_t(clock_type& clock_, Hash const& hash, Allocator const& alloc_) + ConfigT(clock_type& clock, Hash const& hash, Allocator const& alloc) : ValueHash(hash) - , beast::detail::empty_base_optimization(alloc_) - , clock(clock_) + , beast::detail::EmptyBaseOptimization(alloc) + , clock(clock) { } - config_t(clock_type& clock_, KeyEqual const& keyEqual, Allocator const& alloc_) + ConfigT(clock_type& clock, KeyEqual const& keyEqual, Allocator const& alloc) : KeyValueEqual(keyEqual) - , beast::detail::empty_base_optimization(alloc_) - , clock(clock_) + , beast::detail::EmptyBaseOptimization(alloc) + , clock(clock) { } - config_t( - clock_type& clock_, + ConfigT( + clock_type& clock, Hash const& hash, KeyEqual const& keyEqual, - Allocator const& alloc_) + Allocator const& alloc) : ValueHash(hash) , KeyValueEqual(keyEqual) - , beast::detail::empty_base_optimization(alloc_) - , clock(clock_) + , beast::detail::EmptyBaseOptimization(alloc) + , clock(clock) { } - config_t(config_t const& other) + ConfigT(ConfigT const& other) : ValueHash(other.hash_function()) , KeyValueEqual(other.key_eq()) - , beast::detail::empty_base_optimization( + , beast::detail::EmptyBaseOptimization( ElementAllocatorTraits::select_on_container_copy_construction(other.alloc())) , clock(other.clock) { } - config_t(config_t const& other, Allocator const& alloc) + ConfigT(ConfigT const& other, Allocator const& alloc) : ValueHash(other.hash_function()) , KeyValueEqual(other.key_eq()) - , beast::detail::empty_base_optimization(alloc) + , beast::detail::EmptyBaseOptimization(alloc) , clock(other.clock) { } - config_t(config_t&& other) + ConfigT(ConfigT&& other) : ValueHash(std::move(other.hash_function())) , KeyValueEqual(std::move(other.key_eq())) - , beast::detail::empty_base_optimization(std::move(other.alloc())) + , beast::detail::EmptyBaseOptimization(std::move(other.alloc())) , clock(other.clock) { } - config_t( - config_t&& other, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved) + ConfigT( + ConfigT&& other, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved) Allocator const& alloc) : ValueHash(std::move(other.hash_function())) , KeyValueEqual(std::move(other.key_eq())) - , beast::detail::empty_base_optimization(alloc) + , beast::detail::EmptyBaseOptimization(alloc) , clock(other.clock) { } - config_t& - operator=(config_t const& other) + ConfigT& + operator=(ConfigT const& other) { hash_function() = other.hash_function(); key_eq() = other.key_eq(); @@ -332,8 +330,8 @@ private: return *this; } - config_t& - operator=(config_t&& other) + ConfigT& + operator=(ConfigT&& other) { hash_function() = std::move(other.hash_function()); key_eq() = std::move(other.key_eq()); @@ -343,13 +341,13 @@ private: } ValueHash& - value_hash() + valueHash() { return *this; } [[nodiscard]] ValueHash const& - value_hash() const + valueHash() const { return *this; } @@ -367,13 +365,13 @@ private: } KeyValueEqual& - key_value_equal() + keyValueEqual() { return *this; } [[nodiscard]] KeyValueEqual const& - key_value_equal() const + keyValueEqual() const { return *this; } @@ -393,13 +391,13 @@ private: ElementAllocator& alloc() { - return beast::detail::empty_base_optimization::member(); + return beast::detail::EmptyBaseOptimization::member(); } [[nodiscard]] ElementAllocator const& alloc() const { - return beast::detail::empty_base_optimization::member(); + return beast::detail::EmptyBaseOptimization::member(); } std::reference_wrapper clock; @@ -412,43 +410,43 @@ private: bucket_type, typename std::allocator_traits::template rebind_alloc>; - Buckets() : m_max_load_factor(1.f), m_vec() + Buckets() : m_max_load_factor_(1.f), m_vec_() { - m_vec.resize(cont_type::suggested_upper_bucket_count(0)); + m_vec_.resize(cont_type::suggested_upper_bucket_count(0)); } - Buckets(Allocator const& alloc) : m_max_load_factor(1.f), m_vec(alloc) + Buckets(Allocator const& alloc) : m_max_load_factor_(1.f), m_vec_(alloc) { - m_vec.resize(cont_type::suggested_upper_bucket_count(0)); + m_vec_.resize(cont_type::suggested_upper_bucket_count(0)); } operator bucket_traits() { - return bucket_traits(&m_vec[0], m_vec.size()); + return bucket_traits(&m_vec_[0], m_vec_.size()); } void clear() { - m_vec.clear(); + m_vec_.clear(); } [[nodiscard]] size_type - max_bucket_count() const + maxBucketCount() const { - return m_vec.max_size(); + return m_vec_.max_size(); } float& - max_load_factor() + maxLoadFactor() { - return m_max_load_factor; + return m_max_load_factor_; } [[nodiscard]] float const& - max_load_factor() const + maxLoadFactor() const { - return m_max_load_factor; + return m_max_load_factor_; } // count is the number of buckets @@ -456,17 +454,17 @@ private: void rehash(size_type count, Container& c) { - size_type const size(m_vec.size()); + size_type const size(m_vec_.size()); if (count == size) return; - if (count > m_vec.capacity()) + if (count > m_vec_.capacity()) { // Need two vectors otherwise we // will destroy non-empty buckets. - vec_type vec(m_vec.get_allocator()); - std::swap(m_vec, vec); - m_vec.resize(count); - c.rehash(bucket_traits(&m_vec[0], m_vec.size())); + vec_type vec(m_vec_.get_allocator()); + std::swap(m_vec_, vec); + m_vec_.resize(count); + c.rehash(bucket_traits(&m_vec_[0], m_vec_.size())); return; } // Rehash in place. @@ -474,14 +472,14 @@ private: { // This should not reallocate since // we checked capacity earlier. - m_vec.resize(count); - c.rehash(bucket_traits(&m_vec[0], count)); + m_vec_.resize(count); + c.rehash(bucket_traits(&m_vec_[0], count)); return; } // Resize must happen after rehash otherwise // we might destroy non-empty buckets. - c.rehash(bucket_traits(&m_vec[0], count)); - m_vec.resize(count); + c.rehash(bucket_traits(&m_vec_[0], count)); + m_vec_.resize(count); } // Resize the buckets to accommodate at least n items. @@ -494,48 +492,48 @@ private: } private: - float m_max_load_factor; - vec_type m_vec; + float m_max_load_factor_; + vec_type m_vec_; }; template - element* - new_element(Args&&... args) + Element* + newElement(Args&&... args) { struct Deleter { - std::reference_wrapper a_; - Deleter(ElementAllocator& a) : a_(a) + std::reference_wrapper a; + Deleter(ElementAllocator& a) : a(a) { } void - operator()(element* p) + operator()(Element* p) { - ElementAllocatorTraits::deallocate(a_.get(), p, 1); + ElementAllocatorTraits::deallocate(a.get(), p, 1); } }; - std::unique_ptr p( - ElementAllocatorTraits::allocate(m_config.alloc(), 1), Deleter(m_config.alloc())); + std::unique_ptr p( + ElementAllocatorTraits::allocate(m_config_.alloc(), 1), Deleter(m_config_.alloc())); ElementAllocatorTraits::construct( - m_config.alloc(), p.get(), clock().now(), std::forward(args)...); + m_config_.alloc(), p.get(), clock().now(), std::forward(args)...); return p.release(); } void - delete_element(element const* p) + deleteElement(Element const* p) { - ElementAllocatorTraits::destroy(m_config.alloc(), p); - ElementAllocatorTraits::deallocate(m_config.alloc(), const_cast(p), 1); + ElementAllocatorTraits::destroy(m_config_.alloc(), p); + ElementAllocatorTraits::deallocate(m_config_.alloc(), const_cast(p), 1); } void - unlink_and_delete_element(element const* p) + unlinkAndDeleteElement(Element const* p) { - chronological.list.erase(chronological.list.iterator_to(*p)); - m_cont.erase(m_cont.iterator_to(*p)); - delete_element(p); + chronological.list_.erase(chronological.list_.iterator_to(*p)); + m_cont_.erase(m_cont_.iterator_to(*p)); + deleteElement(p); } public: @@ -549,14 +547,13 @@ public: // A set iterator (IsMap==false) is always const // because the elements of a set are immutable. - using iterator = beast::detail::aged_container_iterator; - using const_iterator = - beast::detail::aged_container_iterator; + using iterator = beast::detail::AgedContainerIterator; + using const_iterator = beast::detail::AgedContainerIterator; using local_iterator = - beast::detail::aged_container_iterator; + beast::detail::AgedContainerIterator; using const_local_iterator = - beast::detail::aged_container_iterator; + beast::detail::AgedContainerIterator; //-------------------------------------------------------------------------- // @@ -567,117 +564,116 @@ public: // //-------------------------------------------------------------------------- - class chronological_t + class ChronologicalT { public: // A set iterator (IsMap==false) is always const // because the elements of a set are immutable. - using iterator = - beast::detail::aged_container_iterator; + using iterator = beast::detail::AgedContainerIterator; using const_iterator = - beast::detail::aged_container_iterator; + beast::detail::AgedContainerIterator; using reverse_iterator = - beast::detail::aged_container_iterator; + beast::detail::AgedContainerIterator; using const_reverse_iterator = - beast::detail::aged_container_iterator; + beast::detail::AgedContainerIterator; iterator begin() { - return iterator(list.begin()); + return iterator(list_.begin()); } const_iterator begin() const { - return const_iterator(list.begin()); + return const_iterator(list_.begin()); } const_iterator cbegin() const { - return const_iterator(list.begin()); + return const_iterator(list_.begin()); } iterator end() { - return iterator(list.end()); + return iterator(list_.end()); } const_iterator end() const { - return const_iterator(list.end()); + return const_iterator(list_.end()); } const_iterator cend() const { - return const_iterator(list.end()); + return const_iterator(list_.end()); } reverse_iterator rbegin() { - return reverse_iterator(list.rbegin()); + return reverse_iterator(list_.rbegin()); } const_reverse_iterator rbegin() const { - return const_reverse_iterator(list.rbegin()); + return const_reverse_iterator(list_.rbegin()); } const_reverse_iterator crbegin() const { - return const_reverse_iterator(list.rbegin()); + return const_reverse_iterator(list_.rbegin()); } reverse_iterator rend() { - return reverse_iterator(list.rend()); + return reverse_iterator(list_.rend()); } const_reverse_iterator rend() const { - return const_reverse_iterator(list.rend()); + return const_reverse_iterator(list_.rend()); } const_reverse_iterator crend() const { - return const_reverse_iterator(list.rend()); + return const_reverse_iterator(list_.rend()); } iterator - iterator_to(value_type& value) + iteratorTo(value_type& value) { - static_assert(std::is_standard_layout_v, "must be standard layout"); - return list.iterator_to(*reinterpret_cast( + static_assert(std::is_standard_layout_v, "must be standard layout"); + return list_.iterator_to(*reinterpret_cast( reinterpret_cast(&value) - - ((std::size_t)std::addressof(((element*)0)->member)))); + ((std::size_t)std::addressof(((Element*)0)->member)))); } const_iterator - iterator_to(value_type const& value) const + iteratorTo(value_type const& value) const { - static_assert(std::is_standard_layout_v, "must be standard layout"); - return list.iterator_to(*reinterpret_cast( + static_assert(std::is_standard_layout_v, "must be standard layout"); + return list_.iterator_to(*reinterpret_cast( reinterpret_cast(&value) - - ((std::size_t)std::addressof(((element*)0)->member)))); + ((std::size_t)std::addressof(((Element*)0)->member)))); } - chronological_t(chronological_t const&) = delete; - chronological_t(chronological_t&&) = delete; - chronological_t() = default; + ChronologicalT(ChronologicalT const&) = delete; + ChronologicalT(ChronologicalT&&) = delete; + ChronologicalT() = default; private: - friend class aged_unordered_container; - list_type mutable list; + friend AgedUnorderedContainer aged_unordered_container; + list_type mutable list_; } chronological; //-------------------------------------------------------------------------- @@ -686,58 +682,50 @@ public: // //-------------------------------------------------------------------------- - aged_unordered_container() = delete; + AgedUnorderedContainer() = delete; - explicit aged_unordered_container(clock_type& clock); + explicit AgedUnorderedContainer(clock_type& clock); - aged_unordered_container(clock_type& clock, Hash const& hash); + AgedUnorderedContainer(clock_type& clock, Hash const& hash); - aged_unordered_container(clock_type& clock, KeyEqual const& key_eq); + AgedUnorderedContainer(clock_type& clock, KeyEqual const& keyEq); - aged_unordered_container(clock_type& clock, Allocator const& alloc); + AgedUnorderedContainer(clock_type& clock, Allocator const& alloc); - aged_unordered_container(clock_type& clock, Hash const& hash, KeyEqual const& key_eq); + AgedUnorderedContainer(clock_type& clock, Hash const& hash, KeyEqual const& keyEq); - aged_unordered_container(clock_type& clock, Hash const& hash, Allocator const& alloc); + AgedUnorderedContainer(clock_type& clock, Hash const& hash, Allocator const& alloc); - aged_unordered_container(clock_type& clock, KeyEqual const& key_eq, Allocator const& alloc); + AgedUnorderedContainer(clock_type& clock, KeyEqual const& keyEq, Allocator const& alloc); - aged_unordered_container( + AgedUnorderedContainer( clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc); template - aged_unordered_container(InputIt first, InputIt last, clock_type& clock); + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock); template - aged_unordered_container(InputIt first, InputIt last, clock_type& clock, Hash const& hash); + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, Hash const& hash); template - aged_unordered_container( - InputIt first, - InputIt last, - clock_type& clock, - KeyEqual const& key_eq); + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, KeyEqual const& keyEq); template - aged_unordered_container( - InputIt first, - InputIt last, - clock_type& clock, - Allocator const& alloc); + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, Allocator const& alloc); template - aged_unordered_container( + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq); + KeyEqual const& keyEq); template - aged_unordered_container( + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, @@ -745,102 +733,102 @@ public: Allocator const& alloc); template - aged_unordered_container( + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc); template - aged_unordered_container( + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc); - aged_unordered_container(aged_unordered_container const& other); + AgedUnorderedContainer(AgedUnorderedContainer const& other); - aged_unordered_container(aged_unordered_container const& other, Allocator const& alloc); + AgedUnorderedContainer(AgedUnorderedContainer const& other, Allocator const& alloc); - aged_unordered_container(aged_unordered_container&& other); + AgedUnorderedContainer(AgedUnorderedContainer&& other); - aged_unordered_container( + AgedUnorderedContainer( // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) - aged_unordered_container&& other, + AgedUnorderedContainer&& other, Allocator const& alloc); - aged_unordered_container(std::initializer_list init, clock_type& clock); + AgedUnorderedContainer(std::initializer_list init, clock_type& clock); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, - KeyEqual const& key_eq); + KeyEqual const& keyEq); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Allocator const& alloc); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq); + KeyEqual const& keyEq); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, Allocator const& alloc); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc); - aged_unordered_container( + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc); - ~aged_unordered_container(); + ~AgedUnorderedContainer(); - aged_unordered_container& - operator=(aged_unordered_container const& other); + AgedUnorderedContainer& + operator=(AgedUnorderedContainer const& other); - aged_unordered_container& - operator=(aged_unordered_container&& other); + AgedUnorderedContainer& + operator=(AgedUnorderedContainer&& other); - aged_unordered_container& + AgedUnorderedContainer& operator=(std::initializer_list init); allocator_type - get_allocator() const + getAllocator() const { - return m_config.alloc(); + return m_config_.alloc(); } clock_type& clock() { - return m_config.clock; + return m_config_.clock; } clock_type const& clock() const { - return m_config.clock; + return m_config_.clock; } //-------------------------------------------------------------------------- @@ -851,31 +839,31 @@ public: template < class K, - bool maybe_multi = IsMulti, - bool maybe_map = IsMap, - class = std::enable_if_t> + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& at(K const& k); template < class K, - bool maybe_multi = IsMulti, - bool maybe_map = IsMap, - class = std::enable_if_t> + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> typename std::conditional::type const& at(K const& k) const; template < - bool maybe_multi = IsMulti, - bool maybe_map = IsMap, - class = std::enable_if_t> + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& operator[](Key const& key); template < - bool maybe_multi = IsMulti, - bool maybe_map = IsMap, - class = std::enable_if_t> + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& operator[](Key&& key); @@ -888,55 +876,55 @@ public: iterator begin() { - return iterator(m_cont.begin()); + return iterator(m_cont_.begin()); } const_iterator begin() const { - return const_iterator(m_cont.begin()); + return const_iterator(m_cont_.begin()); } const_iterator cbegin() const { - return const_iterator(m_cont.begin()); + return const_iterator(m_cont_.begin()); } iterator end() { - return iterator(m_cont.end()); + return iterator(m_cont_.end()); } const_iterator end() const { - return const_iterator(m_cont.end()); + return const_iterator(m_cont_.end()); } const_iterator cend() const { - return const_iterator(m_cont.end()); + return const_iterator(m_cont_.end()); } iterator - iterator_to(value_type& value) + iteratorTo(value_type& value) { - static_assert(std::is_standard_layout_v, "must be standard layout"); - return m_cont.iterator_to(*reinterpret_cast( + static_assert(std::is_standard_layout_v, "must be standard layout"); + return m_cont_.iterator_to(*reinterpret_cast( reinterpret_cast(&value) - - ((std::size_t)std::addressof(((element*)0)->member)))); + ((std::size_t)std::addressof(((Element*)0)->member)))); } const_iterator - iterator_to(value_type const& value) const + iteratorTo(value_type const& value) const { - static_assert(std::is_standard_layout_v, "must be standard layout"); - return m_cont.iterator_to(*reinterpret_cast( + static_assert(std::is_standard_layout_v, "must be standard layout"); + return m_cont_.iterator_to(*reinterpret_cast( reinterpret_cast(&value) - - ((std::size_t)std::addressof(((element*)0)->member)))); + ((std::size_t)std::addressof(((Element*)0)->member)))); } //-------------------------------------------------------------------------- @@ -948,19 +936,19 @@ public: bool empty() const noexcept { - return m_cont.empty(); + return m_cont_.empty(); } size_type size() const noexcept { - return m_cont.size(); + return m_cont_.size(); } size_type - max_size() const noexcept + maxSize() const noexcept { - return m_config.max_size(); + return m_config_.max_size(); } //-------------------------------------------------------------------------- @@ -973,29 +961,29 @@ public: clear(); // map, set - template + template auto - insert(value_type const& value) -> std::enable_if_t>; + insert(value_type const& value) -> std::enable_if_t>; // multimap, multiset - template + template auto - insert(value_type const& value) -> std::enable_if_t; + insert(value_type const& value) -> std::enable_if_t; // map, set - template + template auto insert(value_type&& value) - -> std::enable_if_t>; + -> std::enable_if_t>; // multimap, multiset - template + template auto - insert(value_type&& value) -> std::enable_if_t; + insert(value_type&& value) -> std::enable_if_t; // map, set - template - std::enable_if_t + template + std::enable_if_t insert(const_iterator /*hint*/, value_type const& value) { // Hint is ignored but we provide the interface so @@ -1004,8 +992,8 @@ public: } // multimap, multiset - template - std::enable_if_t + template + std::enable_if_t insert(const_iterator /*hint*/, value_type const& value) { // VFALCO TODO The hint could be used to let @@ -1014,8 +1002,8 @@ public: } // map, set - template - std::enable_if_t + template + std::enable_if_t insert(const_iterator /*hint*/, value_type&& value) { // Hint is ignored but we provide the interface so @@ -1024,8 +1012,8 @@ public: } // multimap, multiset - template - std::enable_if_t + template + std::enable_if_t insert(const_iterator /*hint*/, value_type&& value) { // VFALCO TODO The hint could be used to let @@ -1034,9 +1022,9 @@ public: } // map, multimap - template + template std::enable_if_t< - maybe_map && std::is_constructible_v, + MaybeMap && std::is_constructible_v, std::conditional_t>> insert(P&& value) { @@ -1044,9 +1032,9 @@ public: } // map, multimap - template + template std::enable_if_t< - maybe_map && std::is_constructible_v, + MaybeMap && std::is_constructible_v, std::conditional_t>> insert(const_iterator hint, P&& value) { @@ -1067,51 +1055,51 @@ public: } // set, map - template + template auto - emplace(Args&&... args) -> std::enable_if_t>; + emplace(Args&&... args) -> std::enable_if_t>; // multiset, multimap - template + template auto - emplace(Args&&... args) -> std::enable_if_t; + emplace(Args&&... args) -> std::enable_if_t; // set, map - template + template auto - emplace_hint(const_iterator /*hint*/, Args&&... args) - -> std::enable_if_t>; + emplaceHint(const_iterator /*hint*/, Args&&... args) + -> std::enable_if_t>; // multiset, multimap - template - std::enable_if_t - emplace_hint(const_iterator /*hint*/, Args&&... args) + template + std::enable_if_t + emplaceHint(const_iterator /*hint*/, Args&&... args) { // VFALCO TODO The hint could be used for multi, to let // the client order equal ranges - return emplace(std::forward(args)...); + return emplace(std::forward(args)...); } - template - beast::detail::aged_container_iterator - erase(beast::detail::aged_container_iterator pos); + template + beast::detail::AgedContainerIterator + erase(beast::detail::AgedContainerIterator pos); - template - beast::detail::aged_container_iterator + template + beast::detail::AgedContainerIterator erase( - beast::detail::aged_container_iterator first, - beast::detail::aged_container_iterator last); + beast::detail::AgedContainerIterator first, + beast::detail::AgedContainerIterator last); template auto erase(K const& k) -> size_type; void - swap(aged_unordered_container& other) noexcept; + swap(AgedUnorderedContainer& other) noexcept; - template + template void - touch(beast::detail::aged_container_iterator pos) + touch(beast::detail::AgedContainerIterator pos) { touch(pos, clock().now()); } @@ -1131,8 +1119,8 @@ public: size_type count(K const& k) const { - return m_cont.count( - k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal())); + return m_cont_.count( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual())); } // VFALCO TODO Respect is_transparent (c++14) @@ -1140,8 +1128,8 @@ public: iterator find(K const& k) { - return iterator(m_cont.find( - k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); + return iterator(m_cont_.find( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); } // VFALCO TODO Respect is_transparent (c++14) @@ -1149,27 +1137,27 @@ public: const_iterator find(K const& k) const { - return const_iterator(m_cont.find( - k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); + return const_iterator(m_cont_.find( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); } // VFALCO TODO Respect is_transparent (c++14) template std::pair - equal_range(K const& k) + equalRange(K const& k) { - auto const r(m_cont.equal_range( - k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); + auto const r(m_cont_.equal_range( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); return std::make_pair(iterator(r.first), iterator(r.second)); } // VFALCO TODO Respect is_transparent (c++14) template std::pair - equal_range(K const& k) const + equalRange(K const& k) const { - auto const r(m_cont.equal_range( - k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); + auto const r(m_cont_.equal_range( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); return std::make_pair(const_iterator(r.first), const_iterator(r.second)); } @@ -1182,65 +1170,65 @@ public: local_iterator begin(size_type n) { - return local_iterator(m_cont.begin(n)); + return local_iterator(m_cont_.begin(n)); } const_local_iterator begin(size_type n) const { - return const_local_iterator(m_cont.begin(n)); + return const_local_iterator(m_cont_.begin(n)); } const_local_iterator cbegin(size_type n) const { - return const_local_iterator(m_cont.begin(n)); + return const_local_iterator(m_cont_.begin(n)); } local_iterator end(size_type n) { - return local_iterator(m_cont.end(n)); + return local_iterator(m_cont_.end(n)); } const_local_iterator end(size_type n) const { - return const_local_iterator(m_cont.end(n)); + return const_local_iterator(m_cont_.end(n)); } const_local_iterator cend(size_type n) const { - return const_local_iterator(m_cont.end(n)); + return const_local_iterator(m_cont_.end(n)); } size_type - bucket_count() const + bucketCount() const { - return m_cont.bucket_count(); + return m_cont_.bucket_count(); } size_type - max_bucket_count() const + maxBucketCount() const { - return m_buck.max_bucket_count(); + return m_buck_.maxBucketCount(); } size_type - bucket_size(size_type n) const + bucketSize(size_type n) const { - return m_cont.bucket_size(n); + return m_cont_.bucket_size(n); } size_type bucket(Key const& k) const { XRPL_ASSERT( - bucket_count() != 0, + bucketCount() != 0, "beast::detail::aged_unordered_container::bucket : nonzero bucket " "count"); - return m_cont.bucket(k, std::cref(m_config.hash_function())); + return m_cont_.bucket(k, std::cref(m_config_.hash_function())); } //-------------------------------------------------------------------------- @@ -1250,28 +1238,28 @@ public: //-------------------------------------------------------------------------- float - load_factor() const + loadFactor() const { - return size() / static_cast(m_cont.bucket_count()); + return size() / static_cast(m_cont_.bucket_count()); } float - max_load_factor() const + maxLoadFactor() const { - return m_buck.max_load_factor(); + return m_buck_.maxLoadFactor(); } void - max_load_factor(float ml) + maxLoadFactor(float ml) { - m_buck.max_load_factor() = std::max(ml, m_buck.max_load_factor()); + m_buck_.maxLoadFactor() = std::max(ml, m_buck_.maxLoadFactor()); } void rehash(size_type count) { count = std::max(count, size_type(size() / max_load_factor())); - m_buck.rehash(count, m_cont); + m_buck_.rehash(count, m_cont_); } void @@ -1287,15 +1275,15 @@ public: //-------------------------------------------------------------------------- hasher const& - hash_function() const + hashFunction() const { - return m_config.hash_function(); + return m_config_.hash_function(); } key_equal const& - key_eq() const + keyEq() const { - return m_config.key_eq(); + return m_config_.key_eq(); } //-------------------------------------------------------------------------- @@ -1315,9 +1303,9 @@ public: class OtherDuration, class OtherHash, class OtherAllocator, - bool maybe_multi = IsMulti> - std::enable_if_t - operator==(aged_unordered_container< + bool MaybeMulti = IsMulti> + std::enable_if_t + operator==(AgedUnorderedContainer< false, OtherIsMap, OtherKey, @@ -1334,9 +1322,9 @@ public: class OtherDuration, class OtherHash, class OtherAllocator, - bool maybe_multi = IsMulti> - std::enable_if_t - operator==(aged_unordered_container< + bool MaybeMulti = IsMulti> + std::enable_if_t + operator==(AgedUnorderedContainer< true, OtherIsMap, OtherKey, @@ -1355,7 +1343,7 @@ public: class OtherHash, class OtherAllocator> bool - operator!=(aged_unordered_container< + operator!=(AgedUnorderedContainer< OtherIsMulti, OtherIsMap, OtherKey, @@ -1370,36 +1358,36 @@ public: private: bool - would_exceed(size_type additional) const + wouldExceed(size_type additional) const { - return size() + additional > bucket_count() * max_load_factor(); + return size() + additional > bucketCount() * max_load_factor(); } void - maybe_rehash(size_type additional) + maybeRehash(size_type additional) { - if (would_exceed(additional)) - m_buck.resize(size() + additional, m_cont); + if (wouldExceed(additional)) + m_buck_.resize(size() + additional, m_cont_); XRPL_ASSERT( - load_factor() <= max_load_factor(), + loadFactor() <= max_load_factor(), "beast::detail::aged_unordered_container::maybe_rehash : maximum " "load factor"); } // map, set - template + template auto - insert_unchecked(value_type const& value) - -> std::enable_if_t>; + insertUnchecked(value_type const& value) + -> std::enable_if_t>; // multimap, multiset - template + template auto - insert_unchecked(value_type const& value) -> std::enable_if_t; + insertUnchecked(value_type const& value) -> std::enable_if_t; template void - insert_unchecked(InputIt first, InputIt last) + insertUnchecked(InputIt first, InputIt last) { for (; first != last; ++first) insert_unchecked(*first); @@ -1418,45 +1406,45 @@ private: insert(InputIt first, InputIt last, std::random_access_iterator_tag) { auto const n(std::distance(first, last)); - maybe_rehash(n); + maybeRehash(n); insert_unchecked(first, last); } - template + template void touch( - beast::detail::aged_container_iterator pos, + beast::detail::AgedContainerIterator pos, typename clock_type::time_point const& now) { auto& e(*pos.iterator()); e.when = now; - chronological.list.erase(chronological.list.iterator_to(e)); - chronological.list.push_back(e); + chronological.list_.erase(chronological.list_.iterator_to(e)); + chronological.list_.push_back(e); } template < - bool maybe_propagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t - swap_data(aged_unordered_container& other) noexcept + bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> + std::enable_if_t + swapData(AgedUnorderedContainer& other) noexcept { - std::swap(m_config.key_compare(), other.m_config.key_compare()); - std::swap(m_config.alloc(), other.m_config.alloc()); - std::swap(m_config.clock, other.m_config.clock); + std::swap(m_config_.key_compare(), other.m_config_.key_compare()); + std::swap(m_config_.alloc(), other.m_config_.alloc()); + std::swap(m_config_.clock, other.m_config_.clock); } template < - bool maybe_propagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t - swap_data(aged_unordered_container& other) noexcept + bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> + std::enable_if_t + swapData(AgedUnorderedContainer& other) noexcept { - std::swap(m_config.key_compare(), other.m_config.key_compare()); - std::swap(m_config.clock, other.m_config.clock); + std::swap(m_config_.key_compare(), other.m_config_.key_compare()); + std::swap(m_config_.clock, other.m_config_.clock); } private: - config_t m_config; - Buckets m_buck; - cont_type mutable m_cont; + ConfigT m_config_; + Buckets m_buck_; + cont_type mutable m_cont_; }; //------------------------------------------------------------------------------ @@ -1470,10 +1458,10 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock) - : m_config(clock) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock) + : m_config_(clock) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1486,10 +1474,10 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, Hash const& hash) - : m_config(clock, hash) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, Hash const& hash) + : m_config_(clock, hash) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1502,10 +1490,10 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, KeyEqual const& key_eq) - : m_config(clock, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, KeyEqual const& keyEq) + : m_config_(clock, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1518,11 +1506,11 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, Allocator const& alloc) - : m_config(clock, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, Allocator const& alloc) + : m_config_(clock, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1535,10 +1523,10 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, Hash const& hash, KeyEqual const& key_eq) - : m_config(clock, hash, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, Hash const& hash, KeyEqual const& keyEq) + : m_config_(clock, hash, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1551,11 +1539,11 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, Hash const& hash, Allocator const& alloc) - : m_config(clock, hash, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, Hash const& hash, Allocator const& alloc) + : m_config_(clock, hash, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1568,11 +1556,11 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(clock_type& clock, KeyEqual const& key_eq, Allocator const& alloc) - : m_config(clock, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(clock_type& clock, KeyEqual const& keyEq, Allocator const& alloc) + : m_config_(clock, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1585,15 +1573,15 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc) - : m_config(clock, hash, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { } @@ -1607,10 +1595,10 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container(InputIt first, InputIt last, clock_type& clock) - : m_config(clock) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock) + : m_config_(clock) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1625,10 +1613,10 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container(InputIt first, InputIt last, clock_type& clock, Hash const& hash) - : m_config(clock, hash) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, Hash const& hash) + : m_config_(clock, hash) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1643,10 +1631,10 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container(InputIt first, InputIt last, clock_type& clock, KeyEqual const& key_eq) - : m_config(clock, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, KeyEqual const& keyEq) + : m_config_(clock, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1661,11 +1649,11 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container(InputIt first, InputIt last, clock_type& clock, Allocator const& alloc) - : m_config(clock, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(InputIt first, InputIt last, clock_type& clock, Allocator const& alloc) + : m_config_(clock, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1680,15 +1668,15 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq) - : m_config(clock, hash, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + KeyEqual const& keyEq) + : m_config_(clock, hash, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1703,16 +1691,16 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, Hash const& hash, Allocator const& alloc) - : m_config(clock, hash, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1727,16 +1715,16 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc) - : m_config(clock, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1751,17 +1739,17 @@ template < class KeyEqual, class Allocator> template -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( InputIt first, InputIt last, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc) - : m_config(clock, hash, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(first, last); } @@ -1775,11 +1763,11 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(aged_unordered_container const& other) - : m_config(other.m_config) - , m_buck(m_config.alloc()) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(AgedUnorderedContainer const& other) + : m_config_(other.m_config_) + , m_buck_(m_config_.alloc()) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(other.cbegin(), other.cend()); } @@ -1793,11 +1781,11 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(aged_unordered_container const& other, Allocator const& alloc) - : m_config(other.m_config, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(AgedUnorderedContainer const& other, Allocator const& alloc) + : m_config_(other.m_config_, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(other.cbegin(), other.cend()); } @@ -1811,13 +1799,13 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(aged_unordered_container&& other) - : m_config(std::move(other.m_config)) - , m_buck(std::move(other.m_buck)) - , m_cont(std::move(other.m_cont)) +AgedUnorderedContainer:: + AgedUnorderedContainer(AgedUnorderedContainer&& other) + : m_config_(std::move(other.m_config_)) + , m_buck_(std::move(other.m_buck_)) + , m_cont_(std::move(other.m_cont_)) { - chronological.list = std::move(other.chronological.list); + chronological.list_ = std::move(other.chronological.list_); } template < @@ -1829,14 +1817,14 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) - aged_unordered_container&& other, + AgedUnorderedContainer&& other, Allocator const& alloc) - : m_config(std::move(other.m_config), alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(std::move(other.m_config_), alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(other.cbegin(), other.cend()); other.clear(); @@ -1851,10 +1839,10 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container(std::initializer_list init, clock_type& clock) - : m_config(clock) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) +AgedUnorderedContainer:: + AgedUnorderedContainer(std::initializer_list init, clock_type& clock) + : m_config_(clock) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1868,13 +1856,13 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash) - : m_config(clock, hash) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1888,13 +1876,13 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, - KeyEqual const& key_eq) - : m_config(clock, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + KeyEqual const& keyEq) + : m_config_(clock, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1908,14 +1896,14 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Allocator const& alloc) - : m_config(clock, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1929,14 +1917,14 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq) - : m_config(clock, hash, key_eq) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + KeyEqual const& keyEq) + : m_config_(clock, hash, keyEq) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1950,15 +1938,15 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, Allocator const& alloc) - : m_config(clock, hash, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1972,15 +1960,15 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc) - : m_config(clock, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -1994,16 +1982,16 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - aged_unordered_container( +AgedUnorderedContainer:: + AgedUnorderedContainer( std::initializer_list init, clock_type& clock, Hash const& hash, - KeyEqual const& key_eq, + KeyEqual const& keyEq, Allocator const& alloc) - : m_config(clock, hash, key_eq, alloc) - , m_buck(alloc) - , m_cont(m_buck, std::cref(m_config.value_hash()), std::cref(m_config.key_value_equal())) + : m_config_(clock, hash, keyEq, alloc) + , m_buck_(alloc) + , m_cont_(m_buck_, std::cref(m_config_.valueHash()), std::cref(m_config_.keyValueEqual())) { insert(init.begin(), init.end()); } @@ -2017,8 +2005,8 @@ template < class Hash, class KeyEqual, class Allocator> -aged_unordered_container:: - ~aged_unordered_container() +AgedUnorderedContainer:: + ~AgedUnorderedContainer() { clear(); } @@ -2033,16 +2021,16 @@ template < class KeyEqual, class Allocator> auto -aged_unordered_container::operator=( - aged_unordered_container const& other) -> aged_unordered_container& +AgedUnorderedContainer::operator=( + AgedUnorderedContainer const& other) -> AgedUnorderedContainer& { if (this != &other) { size_type const n(other.size()); clear(); - m_config = other.m_config; - m_buck = Buckets(m_config.alloc()); - maybe_rehash(n); + m_config_ = other.m_config_; + m_buck_ = Buckets(m_config_.alloc()); + maybeRehash(n); insert_unchecked(other.begin(), other.end()); } return *this; @@ -2058,14 +2046,14 @@ template < class KeyEqual, class Allocator> auto -aged_unordered_container::operator=( - aged_unordered_container&& other) -> aged_unordered_container& +AgedUnorderedContainer::operator=( + AgedUnorderedContainer&& other) -> AgedUnorderedContainer& { size_type const n(other.size()); clear(); - m_config = std::move(other.m_config); - m_buck = Buckets(m_config.alloc()); - maybe_rehash(n); + m_config_ = std::move(other.m_config_); + m_buck_ = Buckets(m_config_.alloc()); + maybeRehash(n); insert_unchecked(other.begin(), other.end()); other.clear(); return *this; @@ -2081,8 +2069,8 @@ template < class KeyEqual, class Allocator> auto -aged_unordered_container::operator=( - std::initializer_list init) -> aged_unordered_container& +AgedUnorderedContainer::operator=( + std::initializer_list init) -> AgedUnorderedContainer& { clear(); insert(init); @@ -2100,13 +2088,13 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& -aged_unordered_container::at(K const& k) +AgedUnorderedContainer::at(K const& k) { - auto const iter( - m_cont.find(k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); - if (iter == m_cont.end()) + auto const iter(m_cont_.find( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); + if (iter == m_cont_.end()) throw std::out_of_range("key not found"); return iter->value.second; } @@ -2120,14 +2108,14 @@ template < class Hash, class KeyEqual, class Allocator> -template +template typename std::conditional::type const& -aged_unordered_container::at( +AgedUnorderedContainer::at( K const& k) const { - auto const iter( - m_cont.find(k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); - if (iter == m_cont.end()) + auto const iter(m_cont_.find( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); + if (iter == m_cont_.end()) throw std::out_of_range("key not found"); return iter->value.second; } @@ -2141,21 +2129,21 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& -aged_unordered_container::operator[]( +AgedUnorderedContainer::operator[]( Key const& key) { - maybe_rehash(1); + maybeRehash(1); typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( - key, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()), d)); + auto const result(m_cont_.insert_check( + key, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - element* const p(new_element( + Element* const p(new_element( std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple())); - m_cont.insert_commit(*p, d); - chronological.list.push_back(*p); + m_cont_.insert_commit(*p, d); + chronological.list_.push_back(*p); return p->value.second; } return result.first->value.second; @@ -2170,23 +2158,23 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& -aged_unordered_container::operator[]( +AgedUnorderedContainer::operator[]( Key&& key) { - maybe_rehash(1); + maybeRehash(1); typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( - key, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()), d)); + auto const result(m_cont_.insert_check( + key, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - element* const p(new_element( + Element* const p(new_element( std::piecewise_construct, std::forward_as_tuple(std::move(key)), std::forward_as_tuple())); - m_cont.insert_commit(*p, d); - chronological.list.push_back(*p); + m_cont_.insert_commit(*p, d); + chronological.list_.push_back(*p); return p->value.second; } return result.first->value.second; @@ -2204,13 +2192,13 @@ template < class KeyEqual, class Allocator> void -aged_unordered_container::clear() +AgedUnorderedContainer::clear() { - for (auto iter(chronological.list.begin()); iter != chronological.list.end();) - unlink_and_delete_element(&*iter++); - chronological.list.clear(); - m_cont.clear(); - m_buck.clear(); + for (auto iter(chronological.list_.begin()); iter != chronological.list_.end();) + unlinkAndDeleteElement(&*iter++); + chronological.list_.clear(); + m_cont_.clear(); + m_buck_.clear(); } // map, set @@ -2223,23 +2211,23 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::insert( - value_type const& value) -> std::enable_if_t> +AgedUnorderedContainer::insert( + value_type const& value) -> std::enable_if_t> { - maybe_rehash(1); + maybeRehash(1); typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( + auto const result(m_cont_.insert_check( extract(value), - std::cref(m_config.hash_function()), - std::cref(m_config.key_value_equal()), + std::cref(m_config_.hash_function()), + std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - element* const p(new_element(value)); - auto const iter(m_cont.insert_commit(*p, d)); - chronological.list.push_back(*p); + Element* const p(new_element(value)); + auto const iter(m_cont_.insert_commit(*p, d)); + chronological.list_.push_back(*p); return std::make_pair(iterator(iter), true); } return std::make_pair(iterator(result.first), false); @@ -2255,15 +2243,15 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::insert( - value_type const& value) -> std::enable_if_t +AgedUnorderedContainer::insert( + value_type const& value) -> std::enable_if_t { - maybe_rehash(1); - element* const p(new_element(value)); - chronological.list.push_back(*p); - auto const iter(m_cont.insert(*p)); + maybeRehash(1); + Element* const p(new_element(value)); + chronological.list_.push_back(*p); + auto const iter(m_cont_.insert(*p)); return iterator(iter); } @@ -2277,23 +2265,23 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::insert( - value_type&& value) -> std::enable_if_t> +AgedUnorderedContainer::insert( + value_type&& value) -> std::enable_if_t> { - maybe_rehash(1); + maybeRehash(1); typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( + auto const result(m_cont_.insert_check( extract(value), - std::cref(m_config.hash_function()), - std::cref(m_config.key_value_equal()), + std::cref(m_config_.hash_function()), + std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - element* const p(new_element(std::move(value))); - auto const iter(m_cont.insert_commit(*p, d)); - chronological.list.push_back(*p); + Element* const p(new_element(std::move(value))); + auto const iter(m_cont_.insert_commit(*p, d)); + chronological.list_.push_back(*p); return std::make_pair(iterator(iter), true); } return std::make_pair(iterator(result.first), false); @@ -2309,15 +2297,15 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::insert( - value_type&& value) -> std::enable_if_t +AgedUnorderedContainer::insert( + value_type&& value) -> std::enable_if_t { - maybe_rehash(1); - element* const p(new_element(std::move(value))); - chronological.list.push_back(*p); - auto const iter(m_cont.insert(*p)); + maybeRehash(1); + Element* const p(new_element(std::move(value))); + chronological.list_.push_back(*p); + auto const iter(m_cont_.insert(*p)); return iterator(iter); } @@ -2332,22 +2320,22 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::emplace( - Args&&... args) -> std::enable_if_t> +AgedUnorderedContainer::emplace( + Args&&... args) -> std::enable_if_t> { - maybe_rehash(1); + maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to // construct element here - element* const p(new_element(std::forward(args)...)); - auto const result(m_cont.insert(*p)); + Element* const p(new_element(std::forward(args)...)); + auto const result(m_cont_.insert(*p)); if (result.second) { - chronological.list.push_back(*p); + chronological.list_.push_back(*p); return std::make_pair(iterator(result.first), true); } - delete_element(p); + deleteElement(p); return std::make_pair(iterator(result.first), false); } #else // As original, use insert_check() / insert_commit () pair. @@ -2397,15 +2385,15 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::emplace( - Args&&... args) -> std::enable_if_t +AgedUnorderedContainer::emplace( + Args&&... args) -> std::enable_if_t { - maybe_rehash(1); - element* const p(new_element(std::forward(args)...)); - chronological.list.push_back(*p); - auto const iter(m_cont.insert(*p)); + maybeRehash(1); + Element* const p(new_element(std::forward(args)...)); + chronological.list_.push_back(*p); + auto const iter(m_cont_.insert(*p)); return iterator(iter); } @@ -2419,29 +2407,29 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container::emplace_hint( +AgedUnorderedContainer::emplaceHint( const_iterator /*hint*/, - Args&&... args) -> std::enable_if_t> + Args&&... args) -> std::enable_if_t> { - maybe_rehash(1); + maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to // construct element here - element* const p(new_element(std::forward(args)...)); + Element* const p(new_element(std::forward(args)...)); typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( + auto const result(m_cont_.insert_check( extract(p->value), - std::cref(m_config.hash_function()), - std::cref(m_config.key_value_equal()), + std::cref(m_config_.hash_function()), + std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - auto const iter(m_cont.insert_commit(*p, d)); - chronological.list.push_back(*p); + auto const iter(m_cont_.insert_commit(*p, d)); + chronological.list_.push_back(*p); return std::make_pair(iterator(iter), true); } - delete_element(p); + deleteElement(p); return std::make_pair(iterator(result.first), false); } @@ -2454,13 +2442,13 @@ template < class Hash, class KeyEqual, class Allocator> -template -beast::detail::aged_container_iterator -aged_unordered_container::erase( - beast::detail::aged_container_iterator pos) +template +beast::detail::AgedContainerIterator +AgedUnorderedContainer::erase( + beast::detail::AgedContainerIterator pos) { - unlink_and_delete_element(&*((pos++).iterator())); - return beast::detail::aged_container_iterator(pos.iterator()); + unlinkAndDeleteElement(&*((pos++).iterator())); + return beast::detail::AgedContainerIterator(pos.iterator()); } template < @@ -2472,16 +2460,16 @@ template < class Hash, class KeyEqual, class Allocator> -template -beast::detail::aged_container_iterator -aged_unordered_container::erase( - beast::detail::aged_container_iterator first, - beast::detail::aged_container_iterator last) +template +beast::detail::AgedContainerIterator +AgedUnorderedContainer::erase( + beast::detail::AgedContainerIterator first, + beast::detail::AgedContainerIterator last) { for (; first != last;) - unlink_and_delete_element(&*((first++).iterator())); + unlinkAndDeleteElement(&*((first++).iterator())); - return beast::detail::aged_container_iterator(first.iterator()); + return beast::detail::AgedContainerIterator(first.iterator()); } template < @@ -2495,19 +2483,19 @@ template < class Allocator> template auto -aged_unordered_container::erase( - K const& k) -> size_type +AgedUnorderedContainer::erase(K const& k) + -> size_type { - auto iter( - m_cont.find(k, std::cref(m_config.hash_function()), std::cref(m_config.key_value_equal()))); - if (iter == m_cont.end()) + auto iter(m_cont_.find( + k, std::cref(m_config_.hash_function()), std::cref(m_config_.keyValueEqual()))); + if (iter == m_cont_.end()) return 0; size_type n(0); for (;;) { auto p(&*iter++); - bool const done(m_config(*p, extract(iter->value))); - unlink_and_delete_element(p); + bool const done(m_config_(*p, extract(iter->value))); + unlinkAndDeleteElement(p); ++n; if (done) break; @@ -2525,12 +2513,12 @@ template < class KeyEqual, class Allocator> void -aged_unordered_container::swap( - aged_unordered_container& other) noexcept +AgedUnorderedContainer::swap( + AgedUnorderedContainer& other) noexcept { swap_data(other); std::swap(chronological, other.chronological); - std::swap(m_cont, other.m_cont); + std::swap(m_cont_, other.m_cont_); } template < @@ -2544,8 +2532,8 @@ template < class Allocator> template auto -aged_unordered_container::touch( - K const& k) -> size_type +AgedUnorderedContainer::touch(K const& k) + -> size_type { auto const now(clock().now()); size_type n(0); @@ -2574,10 +2562,10 @@ template < class OtherDuration, class OtherHash, class OtherAllocator, - bool maybe_multi> -std::enable_if_t -aged_unordered_container::operator==( - aged_unordered_container< + bool MaybeMulti> +std::enable_if_t +AgedUnorderedContainer::operator==( + AgedUnorderedContainer< false, OtherIsMap, OtherKey, @@ -2614,10 +2602,10 @@ template < class OtherDuration, class OtherHash, class OtherAllocator, - bool maybe_multi> -std::enable_if_t -aged_unordered_container::operator==( - aged_unordered_container< + bool MaybeMulti> +std::enable_if_t +AgedUnorderedContainer::operator==( + AgedUnorderedContainer< true, OtherIsMap, OtherKey, @@ -2659,23 +2647,22 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container:: - insert_unchecked(value_type const& value) - -> std::enable_if_t> +AgedUnorderedContainer::insertUnchecked( + value_type const& value) -> std::enable_if_t> { typename cont_type::insert_commit_data d; - auto const result(m_cont.insert_check( + auto const result(m_cont_.insert_check( extract(value), - std::cref(m_config.hash_function()), - std::cref(m_config.key_value_equal()), + std::cref(m_config_.hash_function()), + std::cref(m_config_.keyValueEqual()), d)); if (result.second) { - element* const p(new_element(value)); - auto const iter(m_cont.insert_commit(*p, d)); - chronological.list.push_back(*p); + Element* const p(new_element(value)); + auto const iter(m_cont_.insert_commit(*p, d)); + chronological.list_.push_back(*p); return std::make_pair(iterator(iter), true); } return std::make_pair(iterator(result.first), false); @@ -2691,14 +2678,14 @@ template < class Hash, class KeyEqual, class Allocator> -template +template auto -aged_unordered_container:: - insert_unchecked(value_type const& value) -> std::enable_if_t +AgedUnorderedContainer::insertUnchecked( + value_type const& value) -> std::enable_if_t { - element* const p(new_element(value)); - chronological.list.push_back(*p); - auto const iter(m_cont.insert(*p)); + Element* const p(new_element(value)); + chronological.list_.push_back(*p); + auto const iter(m_cont_.insert(*p)); return iterator(iter); } @@ -2718,8 +2705,7 @@ template < class KeyEqual, class Allocator> struct is_aged_container< - beast::detail:: - aged_unordered_container> + beast::detail::AgedUnorderedContainer> : std::true_type { explicit is_aged_container() = default; @@ -2738,11 +2724,10 @@ template < class Allocator> void swap( - beast::detail:: - aged_unordered_container& lhs, - beast::detail:: - aged_unordered_container& - rhs) noexcept + beast::detail::AgedUnorderedContainer& + lhs, + beast::detail::AgedUnorderedContainer& + rhs) noexcept { lhs.swap(rhs); } @@ -2761,8 +2746,8 @@ template < class Period> std::size_t expire( - beast::detail:: - aged_unordered_container& c, + beast::detail::AgedUnorderedContainer& + c, std::chrono::duration const& age) noexcept { std::size_t n(0); diff --git a/include/xrpl/beast/container/detail/empty_base_optimization.h b/include/xrpl/beast/container/detail/empty_base_optimization.h index 230845102d..acdb917acb 100644 --- a/include/xrpl/beast/container/detail/empty_base_optimization.h +++ b/include/xrpl/beast/container/detail/empty_base_optimization.h @@ -14,25 +14,25 @@ namespace beast::detail { template -struct is_empty_base_optimization_derived +struct IsEmptyBaseOptimizationDerived : std::integral_constant && !boost::is_final::value> { }; -template ::value> -class empty_base_optimization : private T +template ::value> +class EmptyBaseOptimization : private T { public: - empty_base_optimization() = default; - empty_base_optimization(empty_base_optimization&&) = default; - empty_base_optimization(empty_base_optimization const&) = default; - empty_base_optimization& - operator=(empty_base_optimization&&) = default; - empty_base_optimization& - operator=(empty_base_optimization const&) = default; + EmptyBaseOptimization() = default; + EmptyBaseOptimization(EmptyBaseOptimization&&) = default; + EmptyBaseOptimization(EmptyBaseOptimization const&) = default; + EmptyBaseOptimization& + operator=(EmptyBaseOptimization&&) = default; + EmptyBaseOptimization& + operator=(EmptyBaseOptimization const&) = default; template - explicit empty_base_optimization(Arg1&& arg1, ArgN&&... argn) + explicit EmptyBaseOptimization(Arg1&& arg1, ArgN&&... argn) : T(std::forward(arg1), std::forward(argn)...) { } diff --git a/include/xrpl/beast/core/List.h b/include/xrpl/beast/core/List.h index 30a5166c62..3ae1233f83 100644 --- a/include/xrpl/beast/core/List.h +++ b/include/xrpl/beast/core/List.h @@ -45,8 +45,8 @@ class ListNode template friend class ListIterator; - ListNode* m_next = nullptr; - ListNode* m_prev = nullptr; + ListNode* m_next_ = nullptr; + ListNode* m_prev_ = nullptr; }; //------------------------------------------------------------------------------ @@ -62,12 +62,12 @@ public: using reference = value_type&; using size_type = std::size_t; - ListIterator(N* node = nullptr) noexcept : m_node(node) + ListIterator(N* node = nullptr) noexcept : m_node_(node) { } template - ListIterator(ListIterator const& other) noexcept : m_node(other.m_node) + ListIterator(ListIterator const& other) noexcept : m_node_(other.m_node) { } @@ -75,7 +75,7 @@ public: bool operator==(ListIterator const& other) const noexcept { - return m_node == other.m_node; + return m_node_ == other.m_node; } template @@ -131,22 +131,22 @@ private: [[nodiscard]] reference dereference() const noexcept { - return static_cast(*m_node); + return static_cast(*m_node_); } void increment() noexcept { - m_node = m_node->m_next; + m_node_ = m_node_->m_next; } void decrement() noexcept { - m_node = m_node->m_prev; + m_node_ = m_node_->m_prev; } - N* m_node; + N* m_node_; }; } // namespace detail @@ -275,8 +275,8 @@ public: /** Create an empty list. */ List() { - m_head.m_prev = nullptr; // identifies the head - m_tail.m_next = nullptr; // identifies the tail + m_head_.m_prev = nullptr; // identifies the head + m_tail_.m_next = nullptr; // identifies the tail clear(); } @@ -297,7 +297,7 @@ public: [[nodiscard]] size_type size() const noexcept { - return m_size; + return m_size_; } /** Obtain a reference to the first element. @@ -307,7 +307,7 @@ public: reference front() noexcept { - return element_from(m_head.m_next); + return element_from(m_head_.m_next); } /** Obtain a const reference to the first element. @@ -317,7 +317,7 @@ public: [[nodiscard]] const_reference front() const noexcept { - return element_from(m_head.m_next); + return element_from(m_head_.m_next); } /** Obtain a reference to the last element. @@ -327,7 +327,7 @@ public: reference back() noexcept { - return element_from(m_tail.m_prev); + return element_from(m_tail_.m_prev); } /** Obtain a const reference to the last element. @@ -337,7 +337,7 @@ public: [[nodiscard]] const_reference back() const noexcept { - return element_from(m_tail.m_prev); + return element_from(m_tail_.m_prev); } /** Obtain an iterator to the beginning of the list. @@ -346,7 +346,7 @@ public: iterator begin() noexcept { - return iterator(m_head.m_next); + return iterator(m_head_.m_next); } /** Obtain a const iterator to the beginning of the list. @@ -355,7 +355,7 @@ public: [[nodiscard]] const_iterator begin() const noexcept { - return const_iterator(m_head.m_next); + return const_iterator(m_head_.m_next); } /** Obtain a const iterator to the beginning of the list. @@ -364,7 +364,7 @@ public: [[nodiscard]] const_iterator cbegin() const noexcept { - return const_iterator(m_head.m_next); + return const_iterator(m_head_.m_next); } /** Obtain a iterator to the end of the list. @@ -373,7 +373,7 @@ public: iterator end() noexcept { - return iterator(&m_tail); + return iterator(&m_tail_); } /** Obtain a const iterator to the end of the list. @@ -382,7 +382,7 @@ public: [[nodiscard]] const_iterator end() const noexcept { - return const_iterator(&m_tail); + return const_iterator(&m_tail_); } /** Obtain a const iterator to the end of the list @@ -391,7 +391,7 @@ public: [[nodiscard]] const_iterator cend() const noexcept { - return const_iterator(&m_tail); + return const_iterator(&m_tail_); } /** Clear the list. @@ -400,9 +400,9 @@ public: void clear() noexcept { - m_head.m_next = &m_tail; - m_tail.m_prev = &m_head; - m_size = 0; + m_head_.m_next = &m_tail_; + m_tail_.m_prev = &m_head_; + m_size_ = 0; } /** Insert an element. @@ -419,7 +419,7 @@ public: node->m_prev = node->m_next->m_prev; node->m_next->m_prev = node; node->m_prev->m_next = node; - ++m_size; + ++m_size_; return iterator(node); } @@ -434,11 +434,11 @@ public: if (!other.empty()) { Node* before = &*pos; - other.m_head.m_next->m_prev = before->m_prev; - before->m_prev->m_next = other.m_head.m_next; - other.m_tail.m_prev->m_next = before; - before->m_prev = other.m_tail.m_prev; - m_size += other.m_size; + other.m_head_.m_next->m_prev = before->m_prev; + before->m_prev->m_next = other.m_head_.m_next; + other.m_tail_.m_prev->m_next = before; + before->m_prev = other.m_tail_.m_prev; + m_size_ += other.m_size_; other.clear(); } } @@ -455,7 +455,7 @@ public: ++pos; node->m_next->m_prev = node->m_prev; node->m_prev->m_next = node->m_next; - --m_size; + --m_size_; return pos; } @@ -464,7 +464,7 @@ public: @param element The element to insert. */ iterator - push_front(T& element) noexcept + pushFront(T& element) noexcept { return insert(begin(), element); } @@ -474,7 +474,7 @@ public: @return A reference to the popped element. */ T& - pop_front() noexcept + popFront() noexcept { T& element(front()); erase(begin()); @@ -486,7 +486,7 @@ public: @param element The element to append. */ iterator - push_back(T& element) noexcept + pushBack(T& element) noexcept { return insert(end(), element); } @@ -496,7 +496,7 @@ public: @return A reference to the popped element. */ T& - pop_back() noexcept + popBack() noexcept { T& element(back()); erase(--end()); @@ -539,7 +539,7 @@ public: @return An iterator to the element. */ iterator - iterator_to(T& element) const noexcept + iteratorTo(T& element) const noexcept { return iterator(static_cast(&element)); } @@ -550,28 +550,28 @@ public: @return A const iterator to the element. */ [[nodiscard]] const_iterator - const_iterator_to(T const& element) const noexcept + constIteratorTo(T const& element) const noexcept { return const_iterator(static_cast(&element)); } private: reference - element_from(Node* node) noexcept + elementFrom(Node* node) noexcept { return *(static_cast(node)); } const_reference - element_from(Node const* node) const noexcept + elementFrom(Node const* node) const noexcept { return *(static_cast(node)); } private: - size_type m_size = 0u; - Node m_head; - Node m_tail; + size_type m_size_ = 0u; + Node m_head_; + Node m_tail_; }; } // namespace beast diff --git a/include/xrpl/beast/core/LockFreeStack.h b/include/xrpl/beast/core/LockFreeStack.h index 03598915df..683006ac75 100644 --- a/include/xrpl/beast/core/LockFreeStack.h +++ b/include/xrpl/beast/core/LockFreeStack.h @@ -26,27 +26,27 @@ public: LockFreeStackIterator() = default; - LockFreeStackIterator(NodePtr node) : m_node(node) + LockFreeStackIterator(NodePtr node) : m_node_(node) { } template explicit LockFreeStackIterator(LockFreeStackIterator const& other) - : m_node(other.m_node) + : m_node_(other.m_node) { } LockFreeStackIterator& operator=(NodePtr node) { - m_node = node; + m_node_ = node; return static_cast(*this); } LockFreeStackIterator& operator++() { - m_node = m_node->m_next.load(); + m_node_ = m_node_->m_next.load(); return static_cast(*this); } @@ -54,14 +54,14 @@ public: operator++(int) { LockFreeStackIterator result(*this); - m_node = m_node->m_next; + m_node_ = m_node_->m_next; return result; } NodePtr node() const { - return m_node; + return m_node_; } reference @@ -73,11 +73,11 @@ public: pointer operator->() const { - return static_cast(m_node); + return static_cast(m_node_); } private: - NodePtr m_node{}; + NodePtr m_node_{}; }; //------------------------------------------------------------------------------ @@ -121,11 +121,11 @@ public: class Node { public: - Node() : m_next(nullptr) + Node() : m_next_(nullptr) { } - explicit Node(Node* next) : m_next(next) + explicit Node(Node* next) : m_next_(next) { } @@ -139,7 +139,7 @@ public: template friend class LockFreeStackIterator; - std::atomic m_next; + std::atomic m_next_; }; public: @@ -153,7 +153,7 @@ public: using iterator = LockFreeStackIterator, false>; using const_iterator = LockFreeStackIterator, true>; - LockFreeStack() : m_end(nullptr), m_head(&m_end) + LockFreeStack() : m_end_(nullptr), m_head_(&m_end_) { } @@ -165,7 +165,7 @@ public: [[nodiscard]] bool empty() const { - return m_head.load() == &m_end; + return m_head_.load() == &m_end_; } /** Push a node onto the stack. @@ -181,16 +181,16 @@ public: */ // VFALCO NOTE Fix this, shouldn't it be a reference like intrusive list? bool - push_front(Node* node) + pushFront(Node* node) { bool first = false; - Node* old_head = m_head.load(std::memory_order_relaxed); + Node* oldHead = m_head_.load(std::memory_order_relaxed); do { - first = (old_head == &m_end); - node->m_next = old_head; - } while (!m_head.compare_exchange_strong( - old_head, node, std::memory_order_release, std::memory_order_relaxed)); + first = (oldHead == &m_end_); + node->m_next_ = oldHead; + } while (!m_head_.compare_exchange_strong( + oldHead, node, std::memory_order_release, std::memory_order_relaxed)); return first; } @@ -204,17 +204,17 @@ public: was empty. */ Element* - pop_front() + popFront() { - Node* node = m_head.load(); - Node* new_head = nullptr; + Node* node = m_head_.load(); + Node* newHead = nullptr; do { - if (node == &m_end) + if (node == &m_end_) return nullptr; - new_head = node->m_next.load(); - } while (!m_head.compare_exchange_strong( - node, new_head, std::memory_order_release, std::memory_order_relaxed)); + newHead = node->m_next_.load(); + } while (!m_head_.compare_exchange_strong( + node, newHead, std::memory_order_release, std::memory_order_relaxed)); return static_cast(node); } @@ -228,43 +228,43 @@ public: iterator begin() { - return iterator(m_head.load()); + return iterator(m_head_.load()); } iterator end() { - return iterator(&m_end); + return iterator(&m_end_); } [[nodiscard]] const_iterator begin() const { - return const_iterator(m_head.load()); + return const_iterator(m_head_.load()); } [[nodiscard]] const_iterator end() const { - return const_iterator(&m_end); + return const_iterator(&m_end_); } [[nodiscard]] const_iterator cbegin() const { - return const_iterator(m_head.load()); + return const_iterator(m_head_.load()); } [[nodiscard]] const_iterator cend() const { - return const_iterator(&m_end); + return const_iterator(&m_end_); } /** @} */ private: - Node m_end; - std::atomic m_head; + Node m_end_; + std::atomic m_head_; }; } // namespace beast diff --git a/include/xrpl/beast/hash/hash_append.h b/include/xrpl/beast/hash/hash_append.h index 3161ab3ce2..734039ae2b 100644 --- a/include/xrpl/beast/hash/hash_append.h +++ b/include/xrpl/beast/hash/hash_append.h @@ -66,28 +66,28 @@ maybe_reverse_bytes(T& t, Hasher&) // then x and y have the same bit pattern representation. template -struct is_uniquely_represented +struct IsUniquelyRepresented : public std::integral_constant< bool, std::is_integral_v || std::is_enum_v || std::is_pointer_v> { - explicit is_uniquely_represented() = default; + explicit IsUniquelyRepresented() = default; }; template -struct is_uniquely_represented : public is_uniquely_represented +struct is_uniquely_represented : public IsUniquelyRepresented { explicit is_uniquely_represented() = default; }; template -struct is_uniquely_represented : public is_uniquely_represented +struct is_uniquely_represented : public IsUniquelyRepresented { explicit is_uniquely_represented() = default; }; template -struct is_uniquely_represented : public is_uniquely_represented +struct is_uniquely_represented : public IsUniquelyRepresented { explicit is_uniquely_represented() = default; }; @@ -98,7 +98,7 @@ template struct is_uniquely_represented> : public std::integral_constant< bool, - is_uniquely_represented::value && is_uniquely_represented::value && + IsUniquelyRepresented::value && IsUniquelyRepresented::value && sizeof(T) + sizeof(U) == sizeof(std::pair)> { explicit is_uniquely_represented() = default; @@ -110,7 +110,7 @@ template struct is_uniquely_represented> : public std::integral_constant< bool, - std::conjunction_v...> && + std::conjunction_v...> && sizeof(std::tuple) == (sizeof(T) + ...)> { explicit is_uniquely_represented() = default; @@ -119,7 +119,7 @@ struct is_uniquely_represented> // is_uniquely_represented template -struct is_uniquely_represented : public is_uniquely_represented +struct is_uniquely_represented : public IsUniquelyRepresented { explicit is_uniquely_represented() = default; }; @@ -130,7 +130,7 @@ template struct is_uniquely_represented> : public std::integral_constant< bool, - is_uniquely_represented::value && sizeof(T) * N == sizeof(std::array)> + IsUniquelyRepresented::value && sizeof(T) * N == sizeof(std::array)> { explicit is_uniquely_represented() = default; }; @@ -150,20 +150,20 @@ struct is_uniquely_represented> */ /** @{ */ template -struct is_contiguously_hashable +struct IsContiguouslyHashable : public std::integral_constant< bool, - is_uniquely_represented::value && - (sizeof(T) == 1 || HashAlgorithm::endian == boost::endian::order::native)> + IsUniquelyRepresented::value && + (sizeof(T) == 1 || HashAlgorithm::kENDIAN == boost::endian::order::native)> { - explicit is_contiguously_hashable() = default; + explicit IsContiguouslyHashable() = default; }; template struct is_contiguously_hashable : public std::integral_constant< bool, - is_uniquely_represented::value && + IsUniquelyRepresented::value && (sizeof(T) == 1 || HashAlgorithm::endian == boost::endian::order::native)> { explicit is_contiguously_hashable() = default; @@ -200,7 +200,7 @@ struct is_contiguously_hashable // scalars template -inline std::enable_if_t::value> +inline std::enable_if_t::value> hash_append(Hasher& h, T const& t) noexcept { // NOLINTNEXTLINE(bugprone-sizeof-expression) @@ -209,7 +209,7 @@ hash_append(Hasher& h, T const& t) noexcept template inline std::enable_if_t< - !is_contiguously_hashable::value && + !IsContiguouslyHashable::value && (std::is_integral_v || std::is_pointer_v || std::is_enum_v)> hash_append(Hasher& h, T t) noexcept { @@ -239,35 +239,35 @@ hash_append(Hasher& h, std::nullptr_t) noexcept // Forward declarations for ADL purposes template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, T (&a)[N]) noexcept; template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept; template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept; template -std::enable_if_t, Hasher>::value> +std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::pair const& p) noexcept; template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept; template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept; template -std::enable_if_t, Hasher>::value> +std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::array const& a) noexcept; template -std::enable_if_t, Hasher>::value> +std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::tuple const& t) noexcept; template @@ -279,10 +279,10 @@ void hash_append(Hasher& h, std::unordered_set const& s); template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; template void @@ -291,7 +291,7 @@ hash_append(Hasher& h, T0 const& t0, T1 const& t1, T const&... t) noexcept; // c-array template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, T (&a)[N]) noexcept { for (auto const& t : a) @@ -301,7 +301,7 @@ hash_append(Hasher& h, T (&a)[N]) noexcept // basic_string template -inline std::enable_if_t::value> +inline std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept { for (auto c : s) @@ -310,7 +310,7 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep } template -inline std::enable_if_t::value> +inline std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept { h(s.data(), s.size() * sizeof(CharT)); @@ -320,7 +320,7 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep // pair template -inline std::enable_if_t, Hasher>::value> +inline std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::pair const& p) noexcept { hash_append(h, p.first, p.second); @@ -329,7 +329,7 @@ hash_append(Hasher& h, std::pair const& p) noexcept // vector template -inline std::enable_if_t::value> +inline std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept { for (auto const& t : v) @@ -338,7 +338,7 @@ hash_append(Hasher& h, std::vector const& v) noexcept } template -inline std::enable_if_t::value> +inline std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept { h(v.data(), v.size() * sizeof(T)); @@ -348,7 +348,7 @@ hash_append(Hasher& h, std::vector const& v) noexcept // array template -std::enable_if_t, Hasher>::value> +std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::array const& a) noexcept { for (auto const& t : a) @@ -356,14 +356,14 @@ hash_append(Hasher& h, std::array const& a) noexcept } template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept { for (auto const& t : v) hash_append(h, t); } template -std::enable_if_t::value> +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept { h(&(v.begin()), v.size() * sizeof(Key)); @@ -395,7 +395,7 @@ tuple_hash(Hasher& h, std::tuple const& t, std::index_sequence) noex } // namespace detail template -inline std::enable_if_t, Hasher>::value> +inline std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::tuple const& t) noexcept { detail::tuple_hash(h, t, std::index_sequence_for{}); diff --git a/include/xrpl/beast/hash/uhash.h b/include/xrpl/beast/hash/uhash.h index 4f66f058a8..97461f67c7 100644 --- a/include/xrpl/beast/hash/uhash.h +++ b/include/xrpl/beast/hash/uhash.h @@ -6,10 +6,10 @@ namespace beast { // Universal hash function -template -struct uhash +template +struct Uhash { - uhash() = default; + Uhash() = default; using result_type = typename Hasher::result_type; diff --git a/include/xrpl/beast/hash/xxhasher.h b/include/xrpl/beast/hash/xxhasher.h index 5cd060e465..01485e1e85 100644 --- a/include/xrpl/beast/hash/xxhasher.h +++ b/include/xrpl/beast/hash/xxhasher.h @@ -12,7 +12,7 @@ namespace beast { -class xxhasher +class Xxhasher { public: using result_type = std::size_t; @@ -21,9 +21,9 @@ private: static_assert(sizeof(std::size_t) == 8, "requires 64-bit std::size_t"); // Have an internal buffer to avoid the streaming API // A 64-byte buffer should to be big enough for us - static constexpr std::size_t INTERNAL_BUFFER_SIZE = 64; + static constexpr std::size_t kINTERNAL_BUFFER_SIZE = 64; - alignas(64) std::array buffer_{}; + alignas(64) std::array buffer_{}; std::span readBuffer_; std::span writeBuffer_; @@ -102,18 +102,18 @@ private: } public: - static constexpr auto const endian = boost::endian::order::native; + static constexpr auto const kENDIAN = boost::endian::order::native; - xxhasher(xxhasher const&) = delete; - xxhasher& - operator=(xxhasher const&) = delete; + Xxhasher(Xxhasher const&) = delete; + Xxhasher& + operator=(Xxhasher const&) = delete; - xxhasher() + Xxhasher() { resetBuffers(); } - ~xxhasher() noexcept + ~Xxhasher() noexcept { if (state_ != nullptr) { @@ -122,13 +122,13 @@ public: } template >* = nullptr> - explicit xxhasher(Seed seed) : seed_(seed) + explicit Xxhasher(Seed seed) : seed_(seed) { resetBuffers(); } template >* = nullptr> - xxhasher(Seed seed, Seed) : seed_(seed) + Xxhasher(Seed seed, Seed) : seed_(seed) { resetBuffers(); } diff --git a/include/xrpl/beast/insight/Collector.h b/include/xrpl/beast/insight/Collector.h index 1d18c7e15c..2e73d60400 100644 --- a/include/xrpl/beast/insight/Collector.h +++ b/include/xrpl/beast/insight/Collector.h @@ -42,13 +42,13 @@ public: /** @{ */ template Hook - make_hook(Handler handler) + makeHook(Handler handler) { - return make_hook(HookImpl::HandlerType(handler)); + return makeHook(HookImpl::HandlerType(handler)); } virtual Hook - make_hook(HookImpl::HandlerType const& handler) = 0; + makeHook(HookImpl::HandlerType const& handler) = 0; /** @} */ /** Create a counter with the specified name. @@ -56,14 +56,14 @@ public: */ /** @{ */ virtual Counter - make_counter(std::string const& name) = 0; + makeCounter(std::string const& name) = 0; Counter - make_counter(std::string const& prefix, std::string const& name) + makeCounter(std::string const& prefix, std::string const& name) { if (prefix.empty()) - return make_counter(name); - return make_counter(prefix + "." + name); + return makeCounter(name); + return makeCounter(prefix + "." + name); } /** @} */ @@ -72,14 +72,14 @@ public: */ /** @{ */ virtual Event - make_event(std::string const& name) = 0; + makeEvent(std::string const& name) = 0; Event - make_event(std::string const& prefix, std::string const& name) + makeEvent(std::string const& prefix, std::string const& name) { if (prefix.empty()) - return make_event(name); - return make_event(prefix + "." + name); + return makeEvent(name); + return makeEvent(prefix + "." + name); } /** @} */ @@ -88,14 +88,14 @@ public: */ /** @{ */ virtual Gauge - make_gauge(std::string const& name) = 0; + makeGauge(std::string const& name) = 0; Gauge - make_gauge(std::string const& prefix, std::string const& name) + makeGauge(std::string const& prefix, std::string const& name) { if (prefix.empty()) - return make_gauge(name); - return make_gauge(prefix + "." + name); + return makeGauge(name); + return makeGauge(prefix + "." + name); } /** @} */ @@ -104,14 +104,14 @@ public: */ /** @{ */ virtual Meter - make_meter(std::string const& name) = 0; + makeMeter(std::string const& name) = 0; Meter - make_meter(std::string const& prefix, std::string const& name) + makeMeter(std::string const& prefix, std::string const& name) { if (prefix.empty()) - return make_meter(name); - return make_meter(prefix + "." + name); + return makeMeter(name); + return makeMeter(prefix + "." + name); } /** @} */ }; diff --git a/include/xrpl/beast/insight/Counter.h b/include/xrpl/beast/insight/Counter.h index c5b8178c2d..fff88d5c23 100644 --- a/include/xrpl/beast/insight/Counter.h +++ b/include/xrpl/beast/insight/Counter.h @@ -29,7 +29,7 @@ public: factory function in the Collector interface. @see Collector. */ - explicit Counter(std::shared_ptr const& impl) : m_impl(impl) + explicit Counter(std::shared_ptr const& impl) : m_impl_(impl) { } @@ -38,8 +38,8 @@ public: void increment(value_type amount) const { - if (m_impl) - m_impl->increment(amount); + if (m_impl_) + m_impl_->increment(amount); } Counter const& @@ -85,7 +85,7 @@ public: } private: - std::shared_ptr m_impl; + std::shared_ptr m_impl_; }; } // namespace beast::insight diff --git a/include/xrpl/beast/insight/Event.h b/include/xrpl/beast/insight/Event.h index 28994db956..0336e9da3d 100644 --- a/include/xrpl/beast/insight/Event.h +++ b/include/xrpl/beast/insight/Event.h @@ -31,7 +31,7 @@ public: factory function in the Collector interface. @see Collector. */ - explicit Event(std::shared_ptr const& impl) : m_impl(impl) + explicit Event(std::shared_ptr const& impl) : m_impl_(impl) { } @@ -41,18 +41,18 @@ public: notify(std::chrono::duration const& value) const { using namespace std::chrono; - if (m_impl) - m_impl->notify(ceil(value)); + if (m_impl_) + m_impl_->notify(ceil(value)); } [[nodiscard]] std::shared_ptr const& impl() const { - return m_impl; + return m_impl_; } private: - std::shared_ptr m_impl; + std::shared_ptr m_impl_; }; } // namespace beast::insight diff --git a/include/xrpl/beast/insight/Gauge.h b/include/xrpl/beast/insight/Gauge.h index 8a7de33e2e..335c049398 100644 --- a/include/xrpl/beast/insight/Gauge.h +++ b/include/xrpl/beast/insight/Gauge.h @@ -31,7 +31,7 @@ public: factory function in the Collector interface. @see Collector. */ - explicit Gauge(std::shared_ptr const& impl) : m_impl(impl) + explicit Gauge(std::shared_ptr const& impl) : m_impl_(impl) { } @@ -44,8 +44,8 @@ public: void set(value_type value) const { - if (m_impl) - m_impl->set(value); + if (m_impl_) + m_impl_->set(value); } Gauge const& @@ -61,8 +61,8 @@ public: void increment(difference_type amount) const { - if (m_impl) - m_impl->increment(amount); + if (m_impl_) + m_impl_->increment(amount); } Gauge const& @@ -111,11 +111,11 @@ public: [[nodiscard]] std::shared_ptr const& impl() const { - return m_impl; + return m_impl_; } private: - std::shared_ptr m_impl; + std::shared_ptr m_impl_; }; } // namespace beast::insight diff --git a/include/xrpl/beast/insight/Hook.h b/include/xrpl/beast/insight/Hook.h index d873411390..dd12eeea81 100644 --- a/include/xrpl/beast/insight/Hook.h +++ b/include/xrpl/beast/insight/Hook.h @@ -20,18 +20,18 @@ public: factory function in the Collector interface. @see Collector. */ - explicit Hook(std::shared_ptr const& impl) : m_impl(impl) + explicit Hook(std::shared_ptr const& impl) : m_impl_(impl) { } [[nodiscard]] std::shared_ptr const& impl() const { - return m_impl; + return m_impl_; } private: - std::shared_ptr m_impl; + std::shared_ptr m_impl_; }; } // namespace beast::insight diff --git a/include/xrpl/beast/insight/Meter.h b/include/xrpl/beast/insight/Meter.h index 93ae237956..5f6bb0453f 100644 --- a/include/xrpl/beast/insight/Meter.h +++ b/include/xrpl/beast/insight/Meter.h @@ -28,7 +28,7 @@ public: factory function in the Collector interface. @see Collector. */ - explicit Meter(std::shared_ptr const& impl) : m_impl(impl) + explicit Meter(std::shared_ptr const& impl) : m_impl_(impl) { } @@ -37,8 +37,8 @@ public: void increment(value_type amount) const { - if (m_impl) - m_impl->increment(amount); + if (m_impl_) + m_impl_->increment(amount); } Meter const& @@ -66,11 +66,11 @@ public: [[nodiscard]] std::shared_ptr const& impl() const { - return m_impl; + return m_impl_; } private: - std::shared_ptr m_impl; + std::shared_ptr m_impl_; }; } // namespace beast::insight diff --git a/include/xrpl/beast/net/IPAddress.h b/include/xrpl/beast/net/IPAddress.h index 277a43e5d8..78acfd7772 100644 --- a/include/xrpl/beast/net/IPAddress.h +++ b/include/xrpl/beast/net/IPAddress.h @@ -95,7 +95,7 @@ struct hash<::beast::IP::Address> std::size_t operator()(::beast::IP::Address const& addr) const { - return ::beast::uhash<>{}(addr); + return ::beast::Uhash<>{}(addr); } }; } // namespace boost diff --git a/include/xrpl/beast/net/IPEndpoint.h b/include/xrpl/beast/net/IPEndpoint.h index 15d86d75fe..e71286205a 100644 --- a/include/xrpl/beast/net/IPEndpoint.h +++ b/include/xrpl/beast/net/IPEndpoint.h @@ -27,56 +27,56 @@ public: @return An optional endpoint; will be `std::nullopt` on failure */ static std::optional - from_string_checked(std::string const& s); + fromStringChecked(std::string const& s); static Endpoint - from_string(std::string const& s); + fromString(std::string const& s); /** Returns a string representing the endpoint. */ [[nodiscard]] std::string - to_string() const; + toString() const; /** Returns the port number on the endpoint. */ [[nodiscard]] Port port() const { - return m_port; + return m_port_; } /** Returns a new Endpoint with a different port. */ [[nodiscard]] Endpoint - at_port(Port port) const + atPort(Port port) const { - return Endpoint(m_addr, port); + return Endpoint(m_addr_, port); } /** Returns the address portion of this endpoint. */ [[nodiscard]] Address const& address() const { - return m_addr; + return m_addr_; } /** Convenience accessors for the address part. */ /** @{ */ [[nodiscard]] bool - is_v4() const + isV4() const { - return m_addr.is_v4(); + return m_addr_.is_v4(); } [[nodiscard]] bool - is_v6() const + isV6() const { - return m_addr.is_v6(); + return m_addr_.is_v6(); } [[nodiscard]] AddressV4 - to_v4() const + toV4() const { - return m_addr.to_v4(); + return m_addr_.to_v4(); } [[nodiscard]] AddressV6 - to_v6() const + toV6() const { - return m_addr.to_v6(); + return m_addr_.to_v6(); } /** @} */ @@ -114,12 +114,12 @@ public: hash_append(Hasher& h, Endpoint const& endpoint) { using ::beast::hash_append; - hash_append(h, endpoint.m_addr, endpoint.m_port); + hash_append(h, endpoint.m_addr_, endpoint.m_port_); } private: - Address m_addr; - Port m_port; + Address m_addr_; + Port m_port_; }; //------------------------------------------------------------------------------ @@ -167,7 +167,7 @@ is_public(Endpoint const& endpoint) inline std::string to_string(Endpoint const& endpoint) { - return endpoint.to_string(); + return endpoint.toString(); } /** Output stream conversion. */ @@ -197,7 +197,7 @@ struct hash<::beast::IP::Endpoint> std::size_t operator()(::beast::IP::Endpoint const& endpoint) const { - return ::beast::uhash<>{}(endpoint); + return ::beast::Uhash<>{}(endpoint); } }; } // namespace std @@ -212,7 +212,7 @@ struct hash<::beast::IP::Endpoint> std::size_t operator()(::beast::IP::Endpoint const& endpoint) const { - return ::beast::uhash<>{}(endpoint); + return ::beast::Uhash<>{}(endpoint); } }; } // namespace boost diff --git a/include/xrpl/beast/unit_test/amount.h b/include/xrpl/beast/unit_test/amount.h index ae1dd8fe31..3a392f393f 100644 --- a/include/xrpl/beast/unit_test/amount.h +++ b/include/xrpl/beast/unit_test/amount.h @@ -11,31 +11,31 @@ namespace beast::unit_test { /** Utility for producing nicely composed output of amounts with units. */ -class amount +class Amount { private: std::size_t n_; std::string const& what_; public: - amount(amount const&) = default; - amount& - operator=(amount const&) = delete; + Amount(Amount const&) = default; + Amount& + operator=(Amount const&) = delete; template - amount(std::size_t n, std::string const& what); + Amount(std::size_t n, std::string const& what); friend std::ostream& - operator<<(std::ostream& s, amount const& t); + operator<<(std::ostream& s, Amount const& t); }; template -amount::amount(std::size_t n, std::string const& what) : n_(n), what_(what) +Amount::Amount(std::size_t n, std::string const& what) : n_(n), what_(what) { } inline std::ostream& -operator<<(std::ostream& s, amount const& t) +operator<<(std::ostream& s, Amount const& t) { s << t.n_ << " " << t.what_ << ((t.n_ != 1) ? "s" : ""); return s; diff --git a/include/xrpl/beast/unit_test/detail/const_container.h b/include/xrpl/beast/unit_test/detail/const_container.h index a36423f0ef..074d907b5f 100644 --- a/include/xrpl/beast/unit_test/detail/const_container.h +++ b/include/xrpl/beast/unit_test/detail/const_container.h @@ -11,24 +11,24 @@ namespace beast::unit_test::detail { provide additional behavior. */ template -class const_container +class ConstContainer { private: using cont_type = Container; - cont_type m_cont; + cont_type m_cont_; protected: cont_type& cont() { - return m_cont; + return m_cont_; } [[nodiscard]] cont_type const& cont() const { - return m_cont; + return m_cont_; } public: @@ -42,14 +42,14 @@ public: [[nodiscard]] bool empty() const { - return m_cont.empty(); + return m_cont_.empty(); } /** Returns the number of items in the container. */ [[nodiscard]] size_type size() const { - return m_cont.size(); + return m_cont_.size(); } /** Returns forward iterators for traversal. */ @@ -57,25 +57,25 @@ public: [[nodiscard]] const_iterator begin() const { - return m_cont.cbegin(); + return m_cont_.cbegin(); } [[nodiscard]] const_iterator cbegin() const { - return m_cont.cbegin(); + return m_cont_.cbegin(); } [[nodiscard]] const_iterator end() const { - return m_cont.cend(); + return m_cont_.cend(); } [[nodiscard]] const_iterator cend() const { - return m_cont.cend(); + return m_cont_.cend(); } /** @} */ }; diff --git a/include/xrpl/beast/unit_test/global_suites.h b/include/xrpl/beast/unit_test/global_suites.h index ca33ddb11c..43c8f8c6bc 100644 --- a/include/xrpl/beast/unit_test/global_suites.h +++ b/include/xrpl/beast/unit_test/global_suites.h @@ -11,11 +11,11 @@ namespace beast::unit_test { namespace detail { /// Holds test suites registered during static initialization. -inline suite_list& +inline SuiteList& global_suites() { - static suite_list s; - return s; + static SuiteList kS; + return kS; } template @@ -35,7 +35,7 @@ struct insert_suite } // namespace detail /// Holds test suites registered during static initialization. -inline suite_list const& +inline SuiteList const& global_suites() { return detail::global_suites(); diff --git a/include/xrpl/beast/unit_test/match.h b/include/xrpl/beast/unit_test/match.h index dbafd67da5..de4a0822bb 100644 --- a/include/xrpl/beast/unit_test/match.h +++ b/include/xrpl/beast/unit_test/match.h @@ -11,70 +11,70 @@ namespace beast::unit_test { // Predicate for implementing matches -class selector +class Selector { public: - enum class mode_t { + enum class ModeT { // Run all tests except manual ones - all, + All, // Run tests that match in any field - automatch, + Automatch, // Match on suite - suite, + Suite, // Match on library - library, + Library, // Match on module (used internally) - module, + Module, // Match nothing (used internally) - none + None }; private: - mode_t mode_; + ModeT mode_; std::string pat_; std::string library_; public: template - explicit selector(mode_t mode, std::string const& pattern = ""); + explicit Selector(ModeT mode, std::string const& pattern = ""); template bool - operator()(suite_info const& s); + operator()(SuiteInfo const& s); }; //------------------------------------------------------------------------------ template -selector::selector(mode_t mode, std::string const& pattern) : mode_(mode), pat_(pattern) +Selector::Selector(ModeT mode, std::string const& pattern) : mode_(mode), pat_(pattern) { - if (mode_ == mode_t::automatch && pattern.empty()) - mode_ = mode_t::all; + if (mode_ == ModeT::Automatch && pattern.empty()) + mode_ = ModeT::All; } template bool -selector::operator()(suite_info const& s) +Selector::operator()(SuiteInfo const& s) { switch (mode_) { - case mode_t::automatch: + case ModeT::Automatch: // suite or full name - if (s.name() == pat_ || s.full_name() == pat_) + if (s.name() == pat_ || s.fullName() == pat_) { - mode_ = mode_t::none; + mode_ = ModeT::None; return true; } // check module if (pat_ == s.module()) { - mode_ = mode_t::module; + mode_ = ModeT::Module; library_ = s.library(); return !s.manual(); } @@ -82,12 +82,12 @@ selector::operator()(suite_info const& s) // check library if (pat_ == s.library()) { - mode_ = mode_t::library; + mode_ = ModeT::Library; return !s.manual(); } // check start of name - if (s.name().starts_with(pat_) || s.full_name().starts_with(pat_)) + if (s.name().starts_with(pat_) || s.fullName().starts_with(pat_)) { // Don't change the mode so that the partial pattern can match // more than once @@ -96,19 +96,19 @@ selector::operator()(suite_info const& s) return false; - case mode_t::suite: + case ModeT::Suite: return pat_ == s.name(); - case mode_t::module: + case ModeT::Module: return pat_ == s.module() && !s.manual(); - case mode_t::library: + case ModeT::Library: return pat_ == s.library() && !s.manual(); - case mode_t::none: + case ModeT::None: return false; - case mode_t::all: + case ModeT::All: default: break; }; @@ -135,31 +135,31 @@ selector::operator()(suite_info const& s) not marked manual are selected from then on. */ -inline selector +inline Selector match_auto(std::string const& name) { - return selector(selector::mode_t::automatch, name); + return Selector(Selector::ModeT::Automatch, name); } /** Return a predicate that matches all suites not marked manual. */ -inline selector +inline Selector match_all() { - return selector(selector::mode_t::all); + return Selector(Selector::ModeT::All); } /** Returns a predicate that matches a specific suite. */ -inline selector +inline Selector match_suite(std::string const& name) { - return selector(selector::mode_t::suite, name); + return Selector(Selector::ModeT::Suite, name); } /** Returns a predicate that matches all suites in a library. */ -inline selector +inline Selector match_library(std::string const& name) { - return selector(selector::mode_t::library, name); + return Selector(Selector::ModeT::Library, name); } } // namespace beast::unit_test diff --git a/include/xrpl/beast/unit_test/recorder.h b/include/xrpl/beast/unit_test/recorder.h index 55305a4b70..276b55d9af 100644 --- a/include/xrpl/beast/unit_test/recorder.h +++ b/include/xrpl/beast/unit_test/recorder.h @@ -10,65 +10,65 @@ namespace beast::unit_test { /** A test runner that stores the results. */ -class recorder : public runner +class Recorder : public Runner { private: - results m_results; - suite_results m_suite; - case_results m_case; + Results m_results_; + SuiteResults m_suite_; + CaseResults m_case_; public: - recorder() = default; + Recorder() = default; /** Returns a report with the results of all completed suites. */ - [[nodiscard]] results const& + [[nodiscard]] Results const& report() const { - return m_results; + return m_results_; } private: void - on_suite_begin(suite_info const& info) override + onSuiteBegin(SuiteInfo const& info) override { - m_suite = suite_results(info.full_name()); + m_suite_ = SuiteResults(info.fullName()); } void - on_suite_end() override + onSuiteEnd() override { - m_results.insert(std::move(m_suite)); + m_results_.insert(std::move(m_suite_)); } void - on_case_begin(std::string const& name) override + onCaseBegin(std::string const& name) override { - m_case = case_results(name); + m_case_ = CaseResults(name); } void - on_case_end() override + onCaseEnd() override { - if (!m_case.tests.empty()) - m_suite.insert(std::move(m_case)); + if (!m_case_.tests.empty()) + m_suite_.insert(std::move(m_case_)); } void - on_pass() override + onPass() override { - m_case.tests.pass(); + m_case_.tests.pass(); } void - on_fail(std::string const& reason) override + onFail(std::string const& reason) override { - m_case.tests.fail(reason); + m_case_.tests.fail(reason); } void - on_log(std::string const& s) override + onLog(std::string const& s) override { - m_case.log.insert(s); + m_case_.log.insert(s); } }; diff --git a/include/xrpl/beast/unit_test/reporter.h b/include/xrpl/beast/unit_test/reporter.h index 58bea93b2f..b0ce2212e1 100644 --- a/include/xrpl/beast/unit_test/reporter.h +++ b/include/xrpl/beast/unit_test/reporter.h @@ -26,23 +26,23 @@ namespace detail { The totals are output when the object is destroyed. */ template -class reporter : public runner +class Reporter : public Runner { private: using clock_type = std::chrono::steady_clock; - struct case_results + struct CaseResults { std::string name; std::size_t total = 0; std::size_t failed = 0; - explicit case_results(std::string name_ = "") : name(std::move(name_)) + explicit CaseResults(std::string name = "") : name(std::move(name)) { } }; - struct suite_results + struct SuiteResults { std::string name; std::size_t cases = 0; @@ -50,21 +50,21 @@ private: std::size_t failed = 0; typename clock_type::time_point start = clock_type::now(); - explicit suite_results(std::string name_ = "") : name(std::move(name_)) + explicit SuiteResults(std::string name = "") : name(std::move(name)) { } void - add(case_results const& r); + add(CaseResults const& r); }; - struct results + struct Results { using run_time = std::pair; // Need to be named before converting // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) - enum { max_top = 10 }; + enum { MaxTop = 10 }; std::size_t suites = 0; std::size_t cases = 0; @@ -74,54 +74,54 @@ private: typename clock_type::time_point start = clock_type::now(); void - add(suite_results const& r); + add(SuiteResults const& r); }; std::ostream& os_; - results results_; - suite_results suite_results_; - case_results case_results_; + Results results_; + SuiteResults suite_results_; + CaseResults case_results_; public: - reporter(reporter const&) = delete; - reporter& - operator=(reporter const&) = delete; + Reporter(Reporter const&) = delete; + Reporter& + operator=(Reporter const&) = delete; - ~reporter() override; + ~Reporter() override; - explicit reporter(std::ostream& os = std::cout); + explicit Reporter(std::ostream& os = std::cout); private: static std::string fmtdur(typename clock_type::duration const& d); void - on_suite_begin(suite_info const& info) override; + onSuiteBegin(SuiteInfo const& info) override; void - on_suite_end() override; + onSuiteEnd() override; void - on_case_begin(std::string const& name) override; + onCaseBegin(std::string const& name) override; void - on_case_end() override; + onCaseEnd() override; void - on_pass() override; + onPass() override; void - on_fail(std::string const& reason) override; + onFail(std::string const& reason) override; void - on_log(std::string const& s) override; + onLog(std::string const& s) override; }; //------------------------------------------------------------------------------ template void -reporter::suite_results::add(case_results const& r) +Reporter::SuiteResults::add(CaseResults const& r) { ++cases; total += r.total; @@ -130,7 +130,7 @@ reporter::suite_results::add(case_results const& r) template void -reporter::results::add(suite_results const& r) +Reporter::Results::add(SuiteResults const& r) { ++suites; total += r.total; @@ -148,11 +148,11 @@ reporter::results::add(suite_results const& r) }); if (iter != top.end()) { - if (top.size() == max_top) + if (top.size() == MaxTop) top.resize(top.size() - 1); top.emplace(iter, r.name, elapsed); } - else if (top.size() < max_top) + else if (top.size() < MaxTop) { top.emplace_back(r.name, elapsed); } @@ -162,12 +162,12 @@ reporter::results::add(suite_results const& r) //------------------------------------------------------------------------------ template -reporter::reporter(std::ostream& os) : os_(os) +Reporter::Reporter(std::ostream& os) : os_(os) { } template -reporter::~reporter() +Reporter::~Reporter() { if (results_.top.size() > 0) { @@ -176,14 +176,14 @@ reporter::~reporter() os_ << std::setw(8) << fmtdur(i.second) << " " << i.first << '\n'; } auto const elapsed = clock_type::now() - results_.start; - os_ << fmtdur(elapsed) << ", " << amount{results_.suites, "suite"} << ", " - << amount{results_.cases, "case"} << ", " << amount{results_.total, "test"} << " total, " - << amount{results_.failed, "failure"} << std::endl; + os_ << fmtdur(elapsed) << ", " << Amount{results_.suites, "suite"} << ", " + << Amount{results_.cases, "case"} << ", " << Amount{results_.total, "test"} << " total, " + << Amount{results_.failed, "failure"} << std::endl; } template std::string -reporter::fmtdur(typename clock_type::duration const& d) +Reporter::fmtdur(typename clock_type::duration const& d) { using namespace std::chrono; auto const ms = duration_cast(d); @@ -196,44 +196,44 @@ reporter::fmtdur(typename clock_type::duration const& d) template void -reporter::on_suite_begin(suite_info const& info) +Reporter::on_suite_begin(SuiteInfo const& info) { - suite_results_ = suite_results{info.full_name()}; + suite_results_ = SuiteResults{info.fullName()}; } template void -reporter::on_suite_end() +Reporter::on_suite_end() { results_.add(suite_results_); } template void -reporter::on_case_begin(std::string const& name) +Reporter::on_case_begin(std::string const& name) { - case_results_ = case_results(name); + case_results_ = CaseResults(name); os_ << suite_results_.name << (case_results_.name.empty() ? "" : (" " + case_results_.name)) << std::endl; } template void -reporter::on_case_end() +Reporter::on_case_end() { suite_results_.add(case_results_); } template void -reporter::on_pass() +Reporter::on_pass() { ++case_results_.total; } template void -reporter::on_fail(std::string const& reason) +Reporter::on_fail(std::string const& reason) { ++case_results_.failed; ++case_results_.total; @@ -243,13 +243,13 @@ reporter::on_fail(std::string const& reason) template void -reporter::on_log(std::string const& s) +Reporter::on_log(std::string const& s) { os_ << s; } } // namespace detail -using reporter = detail::reporter<>; +using reporter = detail::Reporter<>; } // namespace beast::unit_test diff --git a/include/xrpl/beast/unit_test/results.h b/include/xrpl/beast/unit_test/results.h index 71c9aff47f..f14e54c95f 100644 --- a/include/xrpl/beast/unit_test/results.h +++ b/include/xrpl/beast/unit_test/results.h @@ -13,17 +13,17 @@ namespace beast::unit_test { /** Holds a set of test condition outcomes in a testcase. */ -class case_results +class CaseResults { public: /** Holds the result of evaluating one test condition. */ - struct test + struct Test { - explicit test(bool pass_) : pass(pass_) + explicit Test(bool pass) : pass(pass) { } - test(bool pass_, std::string reason_) : pass(pass_), reason(std::move(reason_)) + Test(bool pass, std::string reason) : pass(pass), reason(std::move(reason)) { } @@ -32,13 +32,13 @@ public: }; private: - class tests_t : public detail::const_container> + class TestsT : public detail::ConstContainer> { private: std::size_t failed_{0}; public: - tests_t() = default; + TestsT() = default; /** Returns the total number of test conditions. */ [[nodiscard]] std::size_t @@ -70,7 +70,7 @@ private: } }; - class log_t : public detail::const_container> + class LogT : public detail::ConstContainer> { public: /** Insert a string into the log. */ @@ -84,7 +84,7 @@ private: std::string name_; public: - explicit case_results(std::string name = "") : name_(std::move(name)) + explicit CaseResults(std::string name = "") : name_(std::move(name)) { } @@ -96,16 +96,16 @@ public: } /** Memberspace for a container of test condition outcomes. */ - tests_t tests; + TestsT tests; /** Memberspace for a container of testcase log messages. */ - log_t log; + LogT log; }; //-------------------------------------------------------------------------- /** Holds the set of testcase results in a suite. */ -class suite_results : public detail::const_container> +class SuiteResults : public detail::ConstContainer> { private: std::string name_; @@ -113,7 +113,7 @@ private: std::size_t failed_ = 0; public: - explicit suite_results(std::string name = "") : name_(std::move(name)) + explicit SuiteResults(std::string name = "") : name_(std::move(name)) { } @@ -141,7 +141,7 @@ public: /** Insert a set of testcase results. */ /** @{ */ void - insert(case_results&& r) + insert(CaseResults&& r) { total_ += r.tests.total(); failed_ += r.tests.failed(); @@ -149,7 +149,7 @@ public: } void - insert(case_results const& r) + insert(CaseResults const& r) { cont().push_back(r); total_ += r.tests.total(); @@ -162,21 +162,21 @@ public: // VFALCO TODO Make this a template class using scoped allocators /** Holds the results of running a set of testsuites. */ -class results : public detail::const_container> +class Results : public detail::ConstContainer> { private: - std::size_t m_cases{0}; + std::size_t m_cases_{0}; std::size_t total_{0}; std::size_t failed_{0}; public: - results() = default; + Results() = default; /** Returns the total number of test cases. */ [[nodiscard]] std::size_t cases() const { - return m_cases; + return m_cases_; } /** Returns the total number of test conditions. */ @@ -196,18 +196,18 @@ public: /** Insert a set of suite results. */ /** @{ */ void - insert(suite_results&& r) + insert(SuiteResults&& r) { - m_cases += r.size(); + m_cases_ += r.size(); total_ += r.total(); failed_ += r.failed(); cont().emplace_back(std::move(r)); } void - insert(suite_results const& r) + insert(SuiteResults const& r) { - m_cases += r.size(); + m_cases_ += r.size(); total_ += r.total(); failed_ += r.failed(); cont().push_back(r); diff --git a/include/xrpl/beast/unit_test/runner.h b/include/xrpl/beast/unit_test/runner.h index 5601a8725f..33fb36a4db 100644 --- a/include/xrpl/beast/unit_test/runner.h +++ b/include/xrpl/beast/unit_test/runner.h @@ -18,7 +18,7 @@ namespace beast::unit_test { Derived classes can customize the reporting behavior. This interface is injected into the unit_test class to receive the results of the tests. */ -class runner +class Runner { std::string arg_; bool default_ = false; @@ -27,11 +27,11 @@ class runner std::recursive_mutex mutex_; public: - runner() = default; - virtual ~runner() = default; - runner(runner const&) = delete; - runner& - operator=(runner const&) = delete; + Runner() = default; + virtual ~Runner() = default; + Runner(Runner const&) = delete; + Runner& + operator=(Runner const&) = delete; /** Set the argument string. @@ -58,7 +58,7 @@ public: */ template bool - run(suite_info const& s); + run(SuiteInfo const& s); /** Run a sequence of suites. The expression @@ -79,14 +79,14 @@ public: */ template bool - run_if(FwdIter first, FwdIter last, Pred pred = Pred{}); + runIf(FwdIter first, FwdIter last, Pred pred = Pred{}); /** Run all suites in a container. @return `true` if any conditions failed. */ template bool - run_each(SequenceContainer const& c); + runEach(SequenceContainer const& c); /** Conditionally run suites in a container. pred will be called as: @@ -97,53 +97,53 @@ public: */ template bool - run_each_if(SequenceContainer const& c, Pred pred = Pred{}); + runEachIf(SequenceContainer const& c, Pred pred = Pred{}); protected: /// Called when a new suite starts. virtual void - on_suite_begin(suite_info const&) + onSuiteBegin(SuiteInfo const&) { } /// Called when a suite ends. virtual void - on_suite_end() + onSuiteEnd() { } /// Called when a new case starts. virtual void - on_case_begin(std::string const&) + onCaseBegin(std::string const&) { } /// Called when a new case ends. virtual void - on_case_end() + onCaseEnd() { } /// Called for each passing condition. virtual void - on_pass() + onPass() { } /// Called for each failing condition. virtual void - on_fail(std::string const&) + onFail(std::string const&) { } /// Called when a test logs output. virtual void - on_log(std::string const&) + onLog(std::string const&) { } private: - friend class suite; + friend class Suite; // Start a new testcase. template @@ -167,23 +167,23 @@ private: template bool -runner::run(suite_info const& s) +Runner::run(SuiteInfo const& s) { // Enable 'default' testcase default_ = true; failed_ = false; - on_suite_begin(s); + onSuiteBegin(s); s.run(*this); // Forgot to call pass or fail. BOOST_ASSERT(cond_); - on_case_end(); - on_suite_end(); + onCaseEnd(); + onSuiteEnd(); return failed_; } template bool -runner::run(FwdIter first, FwdIter last) +Runner::run(FwdIter first, FwdIter last) { bool failed(false); for (; first != last; ++first) @@ -193,7 +193,7 @@ runner::run(FwdIter first, FwdIter last) template bool -runner::run_if(FwdIter first, FwdIter last, Pred pred) +Runner::runIf(FwdIter first, FwdIter last, Pred pred) { bool failed(false); for (; first != last; ++first) @@ -206,7 +206,7 @@ runner::run_if(FwdIter first, FwdIter last, Pred pred) template bool -runner::run_each(SequenceContainer const& c) +Runner::runEach(SequenceContainer const& c) { bool failed(false); for (auto const& s : c) @@ -216,7 +216,7 @@ runner::run_each(SequenceContainer const& c) template bool -runner::run_each_if(SequenceContainer const& c, Pred pred) +Runner::runEachIf(SequenceContainer const& c, Pred pred) { bool failed(false); for (auto const& s : c) @@ -229,7 +229,7 @@ runner::run_each_if(SequenceContainer const& c, Pred pred) template void -runner::testcase(std::string const& name) +Runner::testcase(std::string const& name) { std::scoped_lock const lock(mutex_); // Name may not be empty @@ -237,43 +237,43 @@ runner::testcase(std::string const& name) // Forgot to call pass or fail BOOST_ASSERT(default_ || cond_); if (!default_) - on_case_end(); + onCaseEnd(); default_ = false; cond_ = false; - on_case_begin(name); + onCaseBegin(name); } template void -runner::pass() +Runner::pass() { std::scoped_lock const lock(mutex_); if (default_) testcase(""); - on_pass(); + onPass(); cond_ = true; } template void -runner::fail(std::string const& reason) +Runner::fail(std::string const& reason) { std::scoped_lock const lock(mutex_); if (default_) testcase(""); - on_fail(reason); + onFail(reason); failed_ = true; cond_ = true; } template void -runner::log(std::string const& s) +Runner::log(std::string const& s) { std::scoped_lock const lock(mutex_); if (default_) testcase(""); - on_log(s); + onLog(s); } } // namespace beast::unit_test diff --git a/include/xrpl/beast/unit_test/suite.h b/include/xrpl/beast/unit_test/suite.h index c6967ecfe3..c2b5c044a0 100644 --- a/include/xrpl/beast/unit_test/suite.h +++ b/include/xrpl/beast/unit_test/suite.h @@ -20,7 +20,7 @@ namespace detail { template static std::string -make_reason(String const& reason, char const* file, int line) +makeReason(String const& reason, char const* file, int line) { std::string s(reason); if (!s.empty()) @@ -37,7 +37,7 @@ make_reason(String const& reason, char const* file, int line) class Thread; -enum class abort_t { no_abort_on_fail, abort_on_fail }; +enum class AbortT { NoAbortOnFail, AbortOnFail }; /** A testsuite class. @@ -46,16 +46,16 @@ enum class abort_t { no_abort_on_fail, abort_on_fail }; derive from it and use the BEAST_DEFINE_UNIT_TEST macro in a translation unit. */ -class suite +class Suite { private: bool abort_ = false; bool aborted_ = false; - runner* runner_ = nullptr; + Runner* runner_ = nullptr; // This exception is thrown internally to stop the current suite // in the event of a failure, if the option to stop is set. - struct abort_exception : public std::exception + struct AbortException : public std::exception { [[nodiscard]] char const* what() const noexcept override @@ -65,16 +65,16 @@ private: }; template - class log_buf : public std::basic_stringbuf + class LogBuf : public std::basic_stringbuf { - suite& suite_; + Suite& suite_; public: - explicit log_buf(suite& self) : suite_(self) + explicit LogBuf(Suite& self) : suite_(self) { } - ~log_buf() override + ~LogBuf() override { sync(); } @@ -94,25 +94,25 @@ private: class CharT, class Traits = std::char_traits, class Allocator = std::allocator> - class log_os : public std::basic_ostream + class LogOs : public std::basic_ostream { - log_buf buf_; + LogBuf buf_; public: - explicit log_os(suite& self) : std::basic_ostream(&buf_), buf_(self) + explicit LogOs(Suite& self) : std::basic_ostream(&buf_), buf_(self) { } }; - class scoped_testcase; + class ScopedTestcase; - class testcase_t + class TestcaseT { - suite& suite_; + Suite& suite_; std::stringstream ss_; public: - explicit testcase_t(suite& self) : suite_(self) + explicit TestcaseT(Suite& self) : suite_(self) { } @@ -127,13 +127,13 @@ private: @param abort Determines if suite continues running after a failure. */ void - operator()(std::string const& name, abort_t abort = abort_t::no_abort_on_fail); + operator()(std::string const& name, AbortT abort = AbortT::NoAbortOnFail); - scoped_testcase - operator()(abort_t abort); + ScopedTestcase + operator()(AbortT abort); template - scoped_testcase + ScopedTestcase operator<<(T const& t); }; @@ -143,28 +143,28 @@ public: Text sent to the log output stream will be forwarded to the output stream associated with the runner. */ - log_os log; + LogOs log; /** Memberspace for declaring test cases. */ - testcase_t testcase; + TestcaseT testcase; /** Returns the "current" running suite. If no suite is running, nullptr is returned. */ - static suite* - this_suite() + static Suite* + thisSuite() { - return *p_this_suite(); + return *pThisSuite(); } - suite() : log(*this), testcase(*this) + Suite() : log(*this), testcase(*this) { } - virtual ~suite() = default; - suite(suite const&) = delete; - suite& - operator=(suite const&) = delete; + virtual ~Suite() = default; + Suite(Suite const&) = delete; + Suite& + operator=(Suite const&) = delete; /** Invokes the test using the specified runner. @@ -175,7 +175,7 @@ public: */ template void - operator()(runner& r); + operator()(Runner& r); /** Record a successful test condition. */ template @@ -296,11 +296,11 @@ public: private: friend class Thread; - static suite** - p_this_suite() + static Suite** + pThisSuite() { - static suite* pts = nullptr; // NOLINT(misc-const-correctness) - return &pts; + static Suite* kPTS = nullptr; // NOLINT(misc-const-correctness) + return &kPTS; } /** Runs the suite. */ @@ -308,41 +308,41 @@ private: run() = 0; void - propagate_abort() const; + propagateAbort() const; template void - run(runner& r); + run(Runner& r); }; //------------------------------------------------------------------------------ // Helper for streaming testcase names -class suite::scoped_testcase +class Suite::ScopedTestcase { private: - suite& suite_; + Suite& suite_; std::stringstream& ss_; public: - scoped_testcase& - operator=(scoped_testcase const&) = delete; + ScopedTestcase& + operator=(ScopedTestcase const&) = delete; - ~scoped_testcase() + ~ScopedTestcase() { auto const& name = ss_.str(); if (!name.empty()) suite_.runner_->testcase(name); } - scoped_testcase(suite& self, std::stringstream& ss) : suite_(self), ss_(ss) + ScopedTestcase(Suite& self, std::stringstream& ss) : suite_(self), ss_(ss) { ss_.clear(); ss_.str({}); } template - scoped_testcase(suite& self, std::stringstream& ss, T const& t) : suite_(self), ss_(ss) + ScopedTestcase(Suite& self, std::stringstream& ss, T const& t) : suite_(self), ss_(ss) { ss_.clear(); ss_.str({}); @@ -350,7 +350,7 @@ public: } template - scoped_testcase& + ScopedTestcase& operator<<(T const& t) { ss_ << t; @@ -361,22 +361,22 @@ public: //------------------------------------------------------------------------------ inline void -suite::testcase_t::operator()(std::string const& name, abort_t abort) +Suite::TestcaseT::operator()(std::string const& name, AbortT abort) { - suite_.abort_ = abort == abort_t::abort_on_fail; + suite_.abort_ = abort == AbortT::AbortOnFail; suite_.runner_->testcase(name); } -inline suite::scoped_testcase -suite::testcase_t::operator()(abort_t abort) +inline Suite::ScopedTestcase +Suite::TestcaseT::operator()(AbortT abort) { - suite_.abort_ = abort == abort_t::abort_on_fail; + suite_.abort_ = abort == AbortT::AbortOnFail; return {suite_, ss_}; } template -inline suite::scoped_testcase -suite::testcase_t::operator<<(T const& t) +inline Suite::ScopedTestcase +Suite::TestcaseT::operator<<(T const& t) { return {suite_, ss_, t}; } @@ -385,24 +385,24 @@ suite::testcase_t::operator<<(T const& t) template void -suite::operator()(runner& r) +Suite::operator()(Runner& r) { - *p_this_suite() = this; + *pThisSuite() = this; try { run(r); - *p_this_suite() = nullptr; + *pThisSuite() = nullptr; } catch (...) { - *p_this_suite() = nullptr; + *pThisSuite() = nullptr; throw; } } template bool -suite::expect(Condition const& shouldBeTrue, String const& reason) +Suite::expect(Condition const& shouldBeTrue, String const& reason) { if (shouldBeTrue) { @@ -415,14 +415,14 @@ suite::expect(Condition const& shouldBeTrue, String const& reason) template bool -suite::expect(Condition const& shouldBeTrue, String const& reason, char const* file, int line) +Suite::expect(Condition const& shouldBeTrue, String const& reason, char const* file, int line) { if (shouldBeTrue) { pass(); return true; } - fail(detail::make_reason(reason, file, line)); + fail(detail::makeReason(reason, file, line)); return false; } @@ -430,7 +430,7 @@ suite::expect(Condition const& shouldBeTrue, String const& reason, char const* f template bool -suite::except(F&& f, String const& reason) +Suite::except(F&& f, String const& reason) { try { @@ -447,7 +447,7 @@ suite::except(F&& f, String const& reason) template bool -suite::except(F&& f, String const& reason) +Suite::except(F&& f, String const& reason) { try { @@ -464,7 +464,7 @@ suite::except(F&& f, String const& reason) template bool -suite::unexcept(F&& f, String const& reason) +Suite::unexcept(F&& f, String const& reason) { try { @@ -481,7 +481,7 @@ suite::unexcept(F&& f, String const& reason) template bool -suite::unexpected(Condition shouldBeFalse, String const& reason) +Suite::unexpected(Condition shouldBeFalse, String const& reason) { bool const b = static_cast(shouldBeFalse); if (!b) @@ -497,43 +497,43 @@ suite::unexpected(Condition shouldBeFalse, String const& reason) template void -suite::pass() +Suite::pass() { - propagate_abort(); + propagateAbort(); runner_->pass(); } // ::fail template void -suite::fail(std::string const& reason) +Suite::fail(std::string const& reason) { - propagate_abort(); + propagateAbort(); runner_->fail(reason); if (abort_) { aborted_ = true; - BOOST_THROW_EXCEPTION(abort_exception()); + BOOST_THROW_EXCEPTION(AbortException()); } } template void -suite::fail(String const& reason, char const* file, int line) +Suite::fail(String const& reason, char const* file, int line) { - fail(detail::make_reason(reason, file, line)); + fail(detail::makeReason(reason, file, line)); } inline void -suite::propagate_abort() const +Suite::propagateAbort() const { if (abort_ && aborted_) - BOOST_THROW_EXCEPTION(abort_exception()); + BOOST_THROW_EXCEPTION(AbortException()); } template void -suite::run(runner& r) +Suite::run(Runner& r) { runner_ = &r; @@ -541,7 +541,7 @@ suite::run(runner& r) { run(); } - catch (abort_exception const&) // NOLINT(bugprone-empty-catch) + catch (AbortException const&) // NOLINT(bugprone-empty-catch) { // ends the suite } diff --git a/include/xrpl/beast/unit_test/suite_info.h b/include/xrpl/beast/unit_test/suite_info.h index e814d518cb..ef3f1ac717 100644 --- a/include/xrpl/beast/unit_test/suite_info.h +++ b/include/xrpl/beast/unit_test/suite_info.h @@ -11,12 +11,12 @@ namespace beast::unit_test { -class runner; +class Runner; /** Associates a unit test type with metadata. */ -class suite_info +class SuiteInfo { - using run_type = std::function; + using run_type = std::function; std::string name_; std::string module_; @@ -26,7 +26,7 @@ class suite_info run_type run_; public: - suite_info( + SuiteInfo( std::string name, std::string module, std::string library, @@ -69,20 +69,20 @@ public: /// Return the canonical suite name as a string. [[nodiscard]] std::string - full_name() const + fullName() const { return library_ + "." + module_ + "." + name_; } /// Run a new instance of the associated test suite. void - run(runner& r) const + run(Runner& r) const { run_(r); } friend bool - operator<(suite_info const& lhs, suite_info const& rhs) + operator<(SuiteInfo const& lhs, SuiteInfo const& rhs) { // we want higher priority suites sorted first, thus the negation // of priority value here @@ -95,7 +95,7 @@ public: /// Convenience for producing suite_info for a given test type. template -suite_info +SuiteInfo make_suite_info( std::string name, std::string module, @@ -103,8 +103,8 @@ make_suite_info( bool manual, int priority) { - return suite_info( - std::move(name), std::move(module), std::move(library), manual, priority, [](runner& r) { + return SuiteInfo( + std::move(name), std::move(module), std::move(library), manual, priority, [](Runner& r) { Suite{}(r); }); } diff --git a/include/xrpl/beast/unit_test/suite_list.h b/include/xrpl/beast/unit_test/suite_list.h index deffbdfe84..dc9441f89a 100644 --- a/include/xrpl/beast/unit_test/suite_list.h +++ b/include/xrpl/beast/unit_test/suite_list.h @@ -16,7 +16,7 @@ namespace beast::unit_test { /// A container of test suites. -class suite_list : public detail::const_container> +class SuiteList : public detail::ConstContainer> { private: #ifndef NDEBUG @@ -38,7 +38,7 @@ public: template void -suite_list::insert( +SuiteList::insert( char const* name, char const* module, char const* library, diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index 45b7b671cb..27af2f6a17 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -12,17 +12,17 @@ namespace severities { // Hundreds of usages via logging macros // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum Severity { - kAll = 0, + KAll = 0, - kTrace = kAll, - kDebug = 1, - kInfo = 2, - kWarning = 3, - kError = 4, - kFatal = 5, + KTrace = KAll, + KDebug = 1, + KInfo = 2, + KWarning = 3, + KError = 4, + KFatal = 5, - kDisabled = 6, - kNone = kDisabled + KDisabled = 6, + KNone = KDisabled }; } // namespace severities @@ -48,7 +48,7 @@ private: using Severity = severities::Severity; // Invariant: m_sink always points to a valid Sink - Sink* m_sink; + Sink* m_sink_; public: //-------------------------------------------------------------------------- @@ -108,7 +108,7 @@ public: private: Severity thresh_; - bool m_console; + bool m_console_; }; #ifndef __INTELLISENSE__ @@ -132,7 +132,7 @@ public: class ScopedStream { public: - ScopedStream(ScopedStream const& other) : ScopedStream(other.m_sink, other.m_level) + ScopedStream(ScopedStream const& other) : ScopedStream(other.m_sink_, other.m_level_) { } @@ -151,7 +151,7 @@ public: std::ostringstream& ostream() const { - return m_ostream; + return m_ostream_; } std::ostream& @@ -162,9 +162,9 @@ public: operator<<(T const& t) const; private: - Sink& m_sink; - Severity const m_level; - std::ostringstream mutable m_ostream; + Sink& m_sink_; + Severity const m_level_; + std::ostringstream mutable m_ostream_; }; #ifndef __INTELLISENSE__ @@ -183,7 +183,7 @@ public: { public: /** Create a stream which produces no output. */ - explicit Stream() : m_sink(getNullSink()), m_level(severities::kDisabled) + explicit Stream() : m_sink_(getNullSink()), m_level_(severities::KDisabled) { } @@ -191,14 +191,14 @@ public: Constructor is inlined so checking active() very inexpensive. */ - Stream(Sink& sink, Severity level) : m_sink(sink), m_level(level) + Stream(Sink& sink, Severity level) : m_sink_(sink), m_level_(level) { XRPL_ASSERT( - m_level < severities::kDisabled, "beast::Journal::Stream::Stream : maximum level"); + m_level_ < severities::KDisabled, "beast::Journal::Stream::Stream : maximum level"); } /** Construct or copy another Stream. */ - Stream(Stream const& other) : Stream(other.m_sink, other.m_level) + Stream(Stream const& other) : Stream(other.m_sink_, other.m_level_) { } @@ -209,14 +209,14 @@ public: [[nodiscard]] Sink& sink() const { - return m_sink; + return m_sink_; } /** Returns the Severity level of messages this Stream reports. */ [[nodiscard]] Severity level() const { - return m_level; + return m_level_; } /** Returns `true` if sink logs anything at this stream's level. */ @@ -224,7 +224,7 @@ public: [[nodiscard]] bool active() const { - return m_sink.active(m_level); + return m_sink_.active(m_level_); } explicit @@ -245,8 +245,8 @@ public: /** @} */ private: - Sink& m_sink; - Severity m_level; + Sink& m_sink_; + Severity m_level_; }; #ifndef __INTELLISENSE__ @@ -264,7 +264,7 @@ public: Journal() = delete; /** Create a journal that writes to the specified sink. */ - explicit Journal(Sink& sink) : m_sink(&sink) + explicit Journal(Sink& sink) : m_sink_(&sink) { } @@ -272,14 +272,14 @@ public: [[nodiscard]] Sink& sink() const { - return *m_sink; + return *m_sink_; } /** Returns a stream for this sink, with the specified severity level. */ [[nodiscard]] Stream stream(Severity level) const { - return Stream(*m_sink, level); + return Stream(*m_sink_, level); } /** Returns `true` if any message would be logged at this severity level. @@ -289,7 +289,7 @@ public: [[nodiscard]] bool active(Severity level) const { - return m_sink->active(level); + return m_sink_->active(level); } /** Severity stream access functions. */ @@ -297,37 +297,37 @@ public: [[nodiscard]] Stream trace() const { - return {*m_sink, severities::kTrace}; + return {*m_sink_, severities::KTrace}; } [[nodiscard]] Stream debug() const { - return {*m_sink, severities::kDebug}; + return {*m_sink_, severities::KDebug}; } [[nodiscard]] Stream info() const { - return {*m_sink, severities::kInfo}; + return {*m_sink_, severities::KInfo}; } [[nodiscard]] Stream warn() const { - return {*m_sink, severities::kWarning}; + return {*m_sink_, severities::KWarning}; } [[nodiscard]] Stream error() const { - return {*m_sink, severities::kError}; + return {*m_sink_, severities::KError}; } [[nodiscard]] Stream fatal() const { - return {*m_sink, severities::kFatal}; + return {*m_sink_, severities::KFatal}; } /** @} */ }; @@ -347,15 +347,15 @@ template Journal::ScopedStream::ScopedStream(Journal::Stream const& stream, T const& t) : ScopedStream(stream.sink(), stream.level()) { - m_ostream << t; + m_ostream_ << t; } template std::ostream& Journal::ScopedStream::operator<<(T const& t) const { - m_ostream << t; - return m_ostream; + m_ostream_ << t; + return m_ostream_; } //------------------------------------------------------------------------------ @@ -370,7 +370,7 @@ Journal::Stream::operator<<(T const& t) const namespace detail { template > -class logstream_buf : public std::basic_stringbuf +class LogstreamBuf : public std::basic_stringbuf { beast::Journal::Stream strm_; @@ -389,11 +389,11 @@ class logstream_buf : public std::basic_stringbuf } public: - explicit logstream_buf(beast::Journal::Stream const& strm) : strm_(strm) + explicit LogstreamBuf(beast::Journal::Stream const& strm) : strm_(strm) { } - ~logstream_buf() override + ~LogstreamBuf() override { sync(); } @@ -414,7 +414,7 @@ public: } // namespace detail template > -class basic_logstream : public std::basic_ostream +class BasicLogstream : public std::basic_ostream { using char_type = CharT; using traits_type = Traits; @@ -422,16 +422,16 @@ class basic_logstream : public std::basic_ostream using pos_type = typename traits_type::pos_type; using off_type = typename traits_type::off_type; - detail::logstream_buf buf_; + detail::LogstreamBuf buf_; public: - explicit basic_logstream(beast::Journal::Stream const& strm) + explicit BasicLogstream(beast::Journal::Stream const& strm) : std::basic_ostream(&buf_), buf_(strm) { } }; -using logstream = basic_logstream; -using logwstream = basic_logstream; +using logstream = BasicLogstream; +using logwstream = BasicLogstream; } // namespace beast diff --git a/include/xrpl/beast/utility/PropertyStream.h b/include/xrpl/beast/utility/PropertyStream.h index 39e354cc31..43ed920e20 100644 --- a/include/xrpl/beast/utility/PropertyStream.h +++ b/include/xrpl/beast/utility/PropertyStream.h @@ -23,11 +23,11 @@ public: protected: virtual void - map_begin() = 0; + mapBegin() = 0; virtual void - map_begin(std::string const& key) = 0; + mapBegin(std::string const& key) = 0; virtual void - map_end() = 0; + mapEnd() = 0; virtual void add(std::string const& key, std::string const& value) = 0; @@ -40,7 +40,7 @@ protected: template void - lexical_add(std::string const& key, Value value) + lexicalAdd(std::string const& key, Value value) { std::stringstream ss; ss << value; @@ -79,11 +79,11 @@ protected: add(std::string const& key, long double value); virtual void - array_begin() = 0; + arrayBegin() = 0; virtual void - array_begin(std::string const& key) = 0; + arrayBegin(std::string const& key) = 0; virtual void - array_end() = 0; + arrayEnd() = 0; virtual void add(std::string const& value) = 0; @@ -96,7 +96,7 @@ protected: template void - lexical_add(Value value) + lexicalAdd(Value value) { std::stringstream ss; ss << value; @@ -157,7 +157,7 @@ public: operator*() const; private: - Source* m_source; + Source* m_source_; }; //------------------------------------------------------------------------------ @@ -169,9 +169,9 @@ private: class PropertyStream::Proxy { private: - Map const* m_map; - std::string m_key; - std::ostringstream mutable m_ostream; + Map const* m_map_; + std::string m_key_; + std::ostringstream mutable m_ostream_; public: Proxy(Map const& map, std::string key); @@ -189,7 +189,7 @@ public: std::ostream& operator<<(T const& t) const { - return m_ostream << t; + return m_ostream_ << t; } }; @@ -202,7 +202,7 @@ public: class PropertyStream::Map { private: - PropertyStream& m_stream; + PropertyStream& m_stream_; public: explicit Map(PropertyStream& stream); @@ -224,7 +224,7 @@ public: void add(std::string const& key, Value value) const { - m_stream.add(key, value); + m_stream_.add(key, value); } template @@ -261,7 +261,7 @@ template PropertyStream::Proxy& PropertyStream::Proxy::operator=(Value value) { - m_map->add(m_key, value); + m_map_->add(m_key_, value); return *this; } @@ -274,7 +274,7 @@ PropertyStream::Proxy::operator=(Value value) class PropertyStream::Set { private: - PropertyStream& m_stream; + PropertyStream& m_stream_; public: Set(std::string const& key, Map& map); @@ -294,7 +294,7 @@ public: void add(Value value) const { - m_stream.add(value); + m_stream_.add(value); } }; @@ -308,7 +308,7 @@ public: class PropertyStream::Source { private: - std::string const m_name; + std::string const m_name_; std::recursive_mutex lock_; Item item_; Source* parent_{nullptr}; @@ -351,7 +351,7 @@ public: /** Write only this Source to the stream. */ void - write_one(PropertyStream& stream); + writeOne(PropertyStream& stream); /** write this source and all its children recursively to the stream. */ void @@ -384,18 +384,18 @@ public: find(std::string path); Source* - find_one_deep(std::string const& name); + findOneDeep(std::string const& name); PropertyStream::Source* - find_path(std::string path); + findPath(std::string path); PropertyStream::Source* - find_one(std::string const& name); + findOne(std::string const& name); static bool - peel_leading_slash(std::string* path); + peelLeadingSlash(std::string* path); static bool - peel_trailing_slashstar(std::string* path); + peelTrailingSlashstar(std::string* path); static std::string - peel_name(std::string* path); + peelName(std::string* path); //-------------------------------------------------------------------------- diff --git a/include/xrpl/beast/utility/Zero.h b/include/xrpl/beast/utility/Zero.h index ff212b9c98..20a18d3d3a 100644 --- a/include/xrpl/beast/utility/Zero.h +++ b/include/xrpl/beast/utility/Zero.h @@ -27,7 +27,7 @@ struct Zero }; namespace { -constexpr Zero zero{}; +constexpr Zero kZERO{}; } // namespace /** Default implementation of signum calls the method on the class. */ @@ -102,42 +102,42 @@ template bool operator==(Zero, T const& t) { - return t == zero; + return t == kZERO; } template bool operator!=(Zero, T const& t) { - return t != zero; + return t != kZERO; } template bool operator<(Zero, T const& t) { - return t > zero; + return t > kZERO; } template bool operator>(Zero, T const& t) { - return t < zero; + return t < kZERO; } template bool operator>=(Zero, T const& t) { - return t <= zero; + return t <= kZERO; } template bool operator<=(Zero, T const& t) { - return t >= zero; + return t >= kZERO; } } // namespace beast diff --git a/include/xrpl/beast/xor_shift_engine.h b/include/xrpl/beast/xor_shift_engine.h index 85504f51aa..3a5345934e 100644 --- a/include/xrpl/beast/xor_shift_engine.h +++ b/include/xrpl/beast/xor_shift_engine.h @@ -9,16 +9,16 @@ namespace beast { namespace detail { template -class xor_shift_engine +class XorShiftEngine { public: using result_type = std::uint64_t; - xor_shift_engine(xor_shift_engine const&) = default; - xor_shift_engine& - operator=(xor_shift_engine const&) = default; + XorShiftEngine(XorShiftEngine const&) = default; + XorShiftEngine& + operator=(XorShiftEngine const&) = default; - explicit xor_shift_engine(result_type val = 1977u); + explicit XorShiftEngine(result_type val = 1977u); void seed(result_type seed); @@ -44,14 +44,14 @@ private: }; template -xor_shift_engine::xor_shift_engine(result_type val) +XorShiftEngine::XorShiftEngine(result_type val) { seed(val); } template void -xor_shift_engine::seed(result_type seed) +XorShiftEngine::seed(result_type seed) { if (seed == 0) throw std::domain_error("invalid seed"); @@ -61,7 +61,7 @@ xor_shift_engine::seed(result_type seed) template auto -xor_shift_engine::operator()() -> result_type +XorShiftEngine::operator()() -> result_type { result_type s1 = s_[0]; result_type const s0 = s_[1]; @@ -72,7 +72,7 @@ xor_shift_engine::operator()() -> result_type template auto -xor_shift_engine::murmurhash3(result_type x) -> result_type +XorShiftEngine::murmurhash3(result_type x) -> result_type { x ^= x >> 33; x *= 0xff51afd7ed558ccdULL; @@ -91,6 +91,6 @@ xor_shift_engine::murmurhash3(result_type x) -> result_type http://xorshift.di.unimi.it/xorshift128plus.c does not accept seed==0 */ -using xor_shift_engine = detail::xor_shift_engine<>; +using xor_shift_engine = detail::XorShiftEngine<>; } // namespace beast diff --git a/include/xrpl/core/ClosureCounter.h b/include/xrpl/core/ClosureCounter.h index 76e52cb3cd..d1c5ef2e58 100644 --- a/include/xrpl/core/ClosureCounter.h +++ b/include/xrpl/core/ClosureCounter.h @@ -30,7 +30,7 @@ namespace xrpl { * \tparam Ret_t The return type of the closure. * \tparam Args_t The argument types of the closure. */ -template +template class ClosureCounter { private: @@ -75,7 +75,7 @@ private: std::remove_reference_t closure_{}; static_assert( - std::is_same_v()...)), Ret_t>, + std::is_same_v()...)), RetT>, "Closure arguments don't match ClosureCounter Ret_t or Args_t"); public: @@ -113,10 +113,10 @@ private: // Note that Args_t is not deduced, it is explicit. So Args_t&& // would be an rvalue reference, not a forwarding reference. We // want to forward exactly what the user declared. - Ret_t - operator()(Args_t... args) + RetT + operator()(ArgsT... args) { - return closure_(std::forward(args)...); + return closure_(std::forward(args)...); } }; diff --git a/include/xrpl/core/Coro.ipp b/include/xrpl/core/Coro.ipp index e7461b1b85..6d742e97c5 100644 --- a/include/xrpl/core/Coro.ipp +++ b/include/xrpl/core/Coro.ipp @@ -4,18 +4,17 @@ namespace xrpl { /// Coroutine stack size (1.5 MB). Increased from 1 MB because /// ASAN-instrumented deep call stacks exceeded the original limit. -constexpr std::size_t coroStackSize = 1536 * 1024; +constexpr std::size_t kCORO_STACK_SIZE = 1536 * 1024; template -JobQueue::Coro::Coro(Coro_create_t, JobQueue& jq, JobType type, std::string const& name, F&& f) +JobQueue::Coro::Coro(CoroCreateT, JobQueue& jq, JobType type, std::string const& name, F&& f) : jq_(jq) , type_(type) , name_(name) , coro_( - boost::context::protected_fixedsize_stack(coroStackSize), - [this, - fn = std::forward(f)](boost::coroutines2::coroutine::push_type& do_yield) { - yield_ = &do_yield; + boost::context::protected_fixedsize_stack(kCORO_STACK_SIZE), + [this, fn = std::forward(f)](boost::coroutines2::coroutine::push_type& doYield) { + yield_ = &doYield; yield(); fn(shared_from_this()); #ifndef NDEBUG @@ -36,7 +35,7 @@ inline void JobQueue::Coro::yield() const { { - std::scoped_lock lock(jq_.m_mutex); + std::scoped_lock lock(jq_.m_mutex_); ++jq_.nSuspend_; } (*yield_)(); @@ -71,7 +70,7 @@ JobQueue::Coro::resume() running_ = true; } { - std::scoped_lock lk(jq_.m_mutex); + std::scoped_lock lk(jq_.m_mutex_); --jq_.nSuspend_; } auto saved = detail::getLocalValues().release(); @@ -115,7 +114,7 @@ JobQueue::Coro::expectEarlyExit() // // That said, since we're outside the Coro's stack, we need to // decrement the nSuspend that the Coro's call to yield caused. - std::scoped_lock lock(jq_.m_mutex); + std::scoped_lock lock(jq_.m_mutex_); --jq_.nSuspend_; #ifndef NDEBUG finished_ = true; diff --git a/include/xrpl/core/HashRouter.h b/include/xrpl/core/HashRouter.h index 230fc06dbc..d36b8aee6e 100644 --- a/include/xrpl/core/HashRouter.h +++ b/include/xrpl/core/HashRouter.h @@ -212,7 +212,7 @@ public: uint256 const& key, PeerShortID peer, HashRouterFlags& flags, - std::chrono::seconds tx_interval); + std::chrono::seconds txInterval); /** Set the flags on a hash. @@ -250,7 +250,7 @@ private: Setup const setup_; // Stores all suppressed hashes and their expiration time - beast::aged_unordered_map> + beast::aged_unordered_map> suppressionMap_; }; diff --git a/include/xrpl/core/Job.h b/include/xrpl/core/Job.h index 2fe5ab263c..692cd3a107 100644 --- a/include/xrpl/core/Job.h +++ b/include/xrpl/core/Job.h @@ -15,62 +15,62 @@ namespace xrpl { // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum JobType { // Special type indicating an invalid job - will go away soon. - jtINVALID = -1, + JtInvalid = -1, // Job types - the position in this enum indicates the job priority with // earlier jobs having lower priority than later jobs. If you wish to // insert a job at a specific priority, simply add it at the right location. - jtPACK, // Make a fetch pack for a peer - jtPUBOLDLEDGER, // An old ledger has been accepted - jtCLIENT, // A placeholder for the priority of all jtCLIENT jobs - jtCLIENT_SUBSCRIBE, // A websocket subscription by a client - jtCLIENT_FEE_CHANGE, // Subscription for fee change by a client - jtCLIENT_CONSENSUS, // Subscription for consensus state change by a client - jtCLIENT_ACCT_HIST, // Subscription for account history by a client - jtCLIENT_RPC, // Client RPC request - jtCLIENT_WEBSOCKET, // Client websocket request - jtRPC, // A websocket command from the client - jtSWEEP, // Sweep for stale structures - jtVALIDATION_ut, // A validation from an untrusted source - jtMANIFEST, // A validator's manifest - jtUPDATE_PF, // Update pathfinding requests - jtTRANSACTION_l, // A local transaction - jtREPLAY_REQ, // Peer request a ledger delta or a skip list - jtLEDGER_REQ, // Peer request ledger/txnset data - jtPROPOSAL_ut, // A proposal from an untrusted source - jtREPLAY_TASK, // A Ledger replay task/subtask - jtTRANSACTION, // A transaction received from the network - jtMISSING_TXN, // Request missing transactions - jtREQUESTED_TXN, // Reply with requested transactions - jtBATCH, // Apply batched transactions - jtLEDGER_DATA, // Received data for a ledger we're acquiring - jtADVANCE, // Advance validated/acquired ledgers - jtPUBLEDGER, // Publish a fully-accepted ledger - jtTXN_DATA, // Fetch a proposed set - jtWAL, // Write-ahead logging - jtVALIDATION_t, // A validation from a trusted source - jtWRITE, // Write out hashed objects - jtACCEPT, // Accept a consensus ledger - jtPROPOSAL_t, // A proposal from a trusted source - jtNETOP_CLUSTER, // NetworkOPs cluster peer report - jtNETOP_TIMER, // NetworkOPs net timer processing - jtADMIN, // An administrative operation + JtPack, // Make a fetch pack for a peer + JtPuboldledger, // An old ledger has been accepted + JtClient, // A placeholder for the priority of all jtCLIENT jobs + JtClientSubscribe, // A websocket subscription by a client + JtClientFeeChange, // Subscription for fee change by a client + JtClientConsensus, // Subscription for consensus state change by a client + JtClientAcctHist, // Subscription for account history by a client + JtClientRpc, // Client RPC request + JtClientWebsocket, // Client websocket request + JtRpc, // A websocket command from the client + JtSweep, // Sweep for stale structures + JtValidationUt, // A validation from an untrusted source + JtManifest, // A validator's manifest + JtUpdatePf, // Update pathfinding requests + JtTransactionL, // A local transaction + JtReplayReq, // Peer request a ledger delta or a skip list + JtLedgerReq, // Peer request ledger/txnset data + JtProposalUt, // A proposal from an untrusted source + JtReplayTask, // A Ledger replay task/subtask + JtTransaction, // A transaction received from the network + JtMissingTxn, // Request missing transactions + JtRequestedTxn, // Reply with requested transactions + JtBatch, // Apply batched transactions + JtLedgerData, // Received data for a ledger we're acquiring + JtAdvance, // Advance validated/acquired ledgers + JtPubledger, // Publish a fully-accepted ledger + JtTxnData, // Fetch a proposed set + JtWal, // Write-ahead logging + JtValidationT, // A validation from a trusted source + JtWrite, // Write out hashed objects + JtAccept, // Accept a consensus ledger + JtProposalT, // A proposal from a trusted source + JtNetopCluster, // NetworkOPs cluster peer report + JtNetopTimer, // NetworkOPs net timer processing + JtAdmin, // An administrative operation // Special job types which are not dispatched by the job pool - jtPEER, - jtDISK, - jtTXN_PROC, - jtOB_SETUP, - jtPATH_FIND, - jtHO_READ, - jtHO_WRITE, - jtGENERIC, // Used just to measure time + JtPeer, + JtDisk, + JtTxnProc, + JtObSetup, + JtPathFind, + JtHoRead, + JtHoWrite, + JtGeneric, // Used just to measure time // Node store monitoring - jtNS_SYNC_READ, - jtNS_ASYNC_READ, - jtNS_WRITE, + JtNsSyncRead, + JtNsAsyncRead, + JtNsWrite, }; class Job : public CountedObject @@ -105,7 +105,7 @@ public: /** Returns the time when the job was queued. */ [[nodiscard]] clock_type::time_point const& - queue_time() const; + queueTime() const; void doJob(); @@ -122,12 +122,12 @@ public: operator>=(Job const& j) const; private: - JobType mType; - std::uint64_t mJobIndex; - std::function mJob; - std::shared_ptr m_loadEvent; - std::string mName; - clock_type::time_point m_queue_time; + JobType mType_; + std::uint64_t mJobIndex_; + std::function mJob_; + std::shared_ptr m_loadEvent_; + std::string mName_; + clock_type::time_point m_queue_time_; }; using JobCounter = ClosureCounter; diff --git a/include/xrpl/core/JobQueue.h b/include/xrpl/core/JobQueue.h index bac616470a..69a22ede29 100644 --- a/include/xrpl/core/JobQueue.h +++ b/include/xrpl/core/JobQueue.h @@ -24,9 +24,9 @@ class PerfLog; } // namespace perf class Logs; -struct Coro_create_t +struct CoroCreateT { - explicit Coro_create_t() = default; + explicit CoroCreateT() = default; }; /** A pool of threads to perform work. @@ -63,7 +63,7 @@ public: public: // Private: Used in the implementation template - Coro(Coro_create_t, JobQueue&, JobType, std::string const&, F&&); + Coro(CoroCreateT, JobQueue&, JobType, std::string const&, F&&); // Not copy-constructible or assignable Coro(Coro const&) = delete; @@ -226,29 +226,29 @@ private: using JobDataMap = std::map; - beast::Journal m_journal; - mutable std::mutex m_mutex; - std::uint64_t m_lastJob{0}; - std::set m_jobSet; + beast::Journal m_journal_; + mutable std::mutex m_mutex_; + std::uint64_t m_lastJob_{0}; + std::set m_jobSet_; JobCounter jobCounter_; std::atomic_bool stopping_{false}; std::atomic_bool stopped_{false}; - JobDataMap m_jobData; - JobTypeData m_invalidJobData; + JobDataMap m_jobData_; + JobTypeData m_invalidJobData_; // The number of jobs currently in processTask() - int m_processCount{0}; + int m_processCount_{0}; // The number of suspended coroutines int nSuspend_ = 0; - Workers m_workers; + Workers m_workers_; // Statistics tracking perf::PerfLog& perfLog_; - beast::insight::Collector::ptr m_collector; - beast::insight::Gauge job_count; - beast::insight::Hook hook; + beast::insight::Collector::ptr m_collector_; + beast::insight::Gauge job_count_; + beast::insight::Hook hook_; std::condition_variable cv_; @@ -397,7 +397,7 @@ JobQueue::postCoro(JobType t, std::string const& name, F&& f) Last param is the function the coroutine runs. Signature of void(std::shared_ptr). */ - auto coro = std::make_shared(Coro_create_t{}, *this, t, name, std::forward(f)); + auto coro = std::make_shared(CoroCreateT{}, *this, t, name, std::forward(f)); if (!coro->post()) { // The Coro was not successfully posted. Disable it so it's destructor diff --git a/include/xrpl/core/JobTypeData.h b/include/xrpl/core/JobTypeData.h index 20a85e04c1..7f6e6d1a2c 100644 --- a/include/xrpl/core/JobTypeData.h +++ b/include/xrpl/core/JobTypeData.h @@ -11,10 +11,10 @@ namespace xrpl { struct JobTypeData { private: - LoadMonitor m_load; + LoadMonitor m_load_; /* Support for insight */ - beast::insight::Collector::ptr m_collector; + beast::insight::Collector::ptr m_collector_; public: /* The job category which we represent */ @@ -34,18 +34,18 @@ public: beast::insight::Event execute; JobTypeData( - JobTypeInfo const& info_, + JobTypeInfo const& info, beast::insight::Collector::ptr collector, Logs& logs) noexcept - : m_load(logs.journal("LoadMonitor")), m_collector(std::move(collector)), info(info_) + : m_load_(logs.journal("LoadMonitor")), m_collector_(std::move(collector)), info(info) { - m_load.setTargetLatency(info.getAverageLatency(), info.getPeakLatency()); + m_load_.setTargetLatency(info.getAverageLatency(), info.getPeakLatency()); if (!info.special()) { - dequeue = m_collector->make_event(info.name() + "_q"); - execute = m_collector->make_event(info.name()); + dequeue = m_collector_->makeEvent(info.name() + "_q"); + execute = m_collector_->makeEvent(info.name()); } } @@ -69,13 +69,13 @@ public: LoadMonitor& load() { - return m_load; + return m_load_; } LoadMonitor::Stats stats() { - return m_load.getStats(); + return m_load_.getStats(); } }; diff --git a/include/xrpl/core/JobTypeInfo.h b/include/xrpl/core/JobTypeInfo.h index 81c4557be2..03f3c0dd07 100644 --- a/include/xrpl/core/JobTypeInfo.h +++ b/include/xrpl/core/JobTypeInfo.h @@ -8,19 +8,19 @@ namespace xrpl { class JobTypeInfo { private: - JobType const m_type; - std::string const m_name; + JobType const m_type_; + std::string const m_name_; /** The limit on the number of running jobs for this job type. A limit of 0 marks this as a "special job" which is not dispatched via the job queue. */ - int const m_limit; + int const m_limit_; /** Average and peak latencies for this job type. 0 is none specified */ - std::chrono::milliseconds const m_avgLatency; - std::chrono::milliseconds const m_peakLatency; + std::chrono::milliseconds const m_avgLatency_; + std::chrono::milliseconds const m_peakLatency_; public: // Not default constructible @@ -32,48 +32,48 @@ public: int limit, std::chrono::milliseconds avgLatency, std::chrono::milliseconds peakLatency) - : m_type(type) - , m_name(std::move(name)) - , m_limit(limit) - , m_avgLatency(avgLatency) - , m_peakLatency(peakLatency) + : m_type_(type) + , m_name_(std::move(name)) + , m_limit_(limit) + , m_avgLatency_(avgLatency) + , m_peakLatency_(peakLatency) { } [[nodiscard]] JobType type() const { - return m_type; + return m_type_; } [[nodiscard]] std::string const& name() const { - return m_name; + return m_name_; } [[nodiscard]] int limit() const { - return m_limit; + return m_limit_; } [[nodiscard]] bool special() const { - return m_limit == 0; + return m_limit_ == 0; } [[nodiscard]] std::chrono::milliseconds getAverageLatency() const { - return m_avgLatency; + return m_avgLatency_; } [[nodiscard]] std::chrono::milliseconds getPeakLatency() const { - return m_peakLatency; + return m_peakLatency_; } }; diff --git a/include/xrpl/core/JobTypes.h b/include/xrpl/core/JobTypes.h index cc5b54fea7..6e42485e6e 100644 --- a/include/xrpl/core/JobTypes.h +++ b/include/xrpl/core/JobTypes.h @@ -17,7 +17,7 @@ public: private: JobTypes() : m_unknown( - jtINVALID, + JtInvalid, "invalid", 0, std::chrono::milliseconds{0}, @@ -49,53 +49,53 @@ private: // clang-format off // avg peak // JobType name limit latency latency - add(jtPACK, "makeFetchPack", 1, 0ms, 0ms); - add(jtPUBOLDLEDGER, "publishAcqLedger", 2, 10000ms, 15000ms); - add(jtVALIDATION_ut, "untrustedValidation", maxLimit, 2000ms, 5000ms); - add(jtMANIFEST, "manifest", maxLimit, 2000ms, 5000ms); - add(jtTRANSACTION_l, "localTransaction", maxLimit, 100ms, 500ms); - add(jtREPLAY_REQ, "ledgerReplayRequest", 10, 250ms, 1000ms); - add(jtLEDGER_REQ, "ledgerRequest", 3, 0ms, 0ms); - add(jtPROPOSAL_ut, "untrustedProposal", maxLimit, 500ms, 1250ms); - add(jtREPLAY_TASK, "ledgerReplayTask", maxLimit, 0ms, 0ms); - add(jtLEDGER_DATA, "ledgerData", 3, 0ms, 0ms); - add(jtCLIENT, "clientCommand", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_SUBSCRIBE, "clientSubscribe", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_FEE_CHANGE, "clientFeeChange", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_CONSENSUS, "clientConsensus", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_ACCT_HIST, "clientAccountHistory", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_RPC, "clientRPC", maxLimit, 2000ms, 5000ms); - add(jtCLIENT_WEBSOCKET, "clientWebsocket", maxLimit, 2000ms, 5000ms); - add(jtRPC, "RPC", maxLimit, 0ms, 0ms); - add(jtUPDATE_PF, "updatePaths", 1, 0ms, 0ms); - add(jtTRANSACTION, "transaction", maxLimit, 250ms, 1000ms); - add(jtBATCH, "batch", maxLimit, 250ms, 1000ms); - add(jtADVANCE, "advanceLedger", maxLimit, 0ms, 0ms); - add(jtPUBLEDGER, "publishNewLedger", maxLimit, 3000ms, 4500ms); - add(jtTXN_DATA, "fetchTxnData", 5, 0ms, 0ms); - add(jtWAL, "writeAhead", maxLimit, 1000ms, 2500ms); - add(jtVALIDATION_t, "trustedValidation", maxLimit, 500ms, 1500ms); - add(jtWRITE, "writeObjects", maxLimit, 1750ms, 2500ms); - add(jtACCEPT, "acceptLedger", maxLimit, 0ms, 0ms); - add(jtPROPOSAL_t, "trustedProposal", maxLimit, 100ms, 500ms); - add(jtSWEEP, "sweep", 1, 0ms, 0ms); - add(jtNETOP_CLUSTER, "clusterReport", 1, 9999ms, 9999ms); - add(jtNETOP_TIMER, "heartbeat", 1, 999ms, 999ms); - add(jtADMIN, "administration", maxLimit, 0ms, 0ms); - add(jtMISSING_TXN, "handleHaveTransactions", 1200, 0ms, 0ms); - add(jtREQUESTED_TXN, "doTransactions", 1200, 0ms, 0ms); + add(JtPack, "makeFetchPack", 1, 0ms, 0ms); + add(JtPuboldledger, "publishAcqLedger", 2, 10000ms, 15000ms); + add(JtValidationUt, "untrustedValidation", maxLimit, 2000ms, 5000ms); + add(JtManifest, "manifest", maxLimit, 2000ms, 5000ms); + add(JtTransactionL, "localTransaction", maxLimit, 100ms, 500ms); + add(JtReplayReq, "ledgerReplayRequest", 10, 250ms, 1000ms); + add(JtLedgerReq, "ledgerRequest", 3, 0ms, 0ms); + add(JtProposalUt, "untrustedProposal", maxLimit, 500ms, 1250ms); + add(JtReplayTask, "ledgerReplayTask", maxLimit, 0ms, 0ms); + add(JtLedgerData, "ledgerData", 3, 0ms, 0ms); + add(JtClient, "clientCommand", maxLimit, 2000ms, 5000ms); + add(JtClientSubscribe, "clientSubscribe", maxLimit, 2000ms, 5000ms); + add(JtClientFeeChange, "clientFeeChange", maxLimit, 2000ms, 5000ms); + add(JtClientConsensus, "clientConsensus", maxLimit, 2000ms, 5000ms); + add(JtClientAcctHist, "clientAccountHistory", maxLimit, 2000ms, 5000ms); + add(JtClientRpc, "clientRPC", maxLimit, 2000ms, 5000ms); + add(JtClientWebsocket, "clientWebsocket", maxLimit, 2000ms, 5000ms); + add(JtRpc, "RPC", maxLimit, 0ms, 0ms); + add(JtUpdatePf, "updatePaths", 1, 0ms, 0ms); + add(JtTransaction, "transaction", maxLimit, 250ms, 1000ms); + add(JtBatch, "batch", maxLimit, 250ms, 1000ms); + add(JtAdvance, "advanceLedger", maxLimit, 0ms, 0ms); + add(JtPubledger, "publishNewLedger", maxLimit, 3000ms, 4500ms); + add(JtTxnData, "fetchTxnData", 5, 0ms, 0ms); + add(JtWal, "writeAhead", maxLimit, 1000ms, 2500ms); + add(JtValidationT, "trustedValidation", maxLimit, 500ms, 1500ms); + add(JtWrite, "writeObjects", maxLimit, 1750ms, 2500ms); + add(JtAccept, "acceptLedger", maxLimit, 0ms, 0ms); + add(JtProposalT, "trustedProposal", maxLimit, 100ms, 500ms); + add(JtSweep, "sweep", 1, 0ms, 0ms); + add(JtNetopCluster, "clusterReport", 1, 9999ms, 9999ms); + add(JtNetopTimer, "heartbeat", 1, 999ms, 999ms); + add(JtAdmin, "administration", maxLimit, 0ms, 0ms); + add(JtMissingTxn, "handleHaveTransactions", 1200, 0ms, 0ms); + add(JtRequestedTxn, "doTransactions", 1200, 0ms, 0ms); - add(jtPEER, "peerCommand", 0, 200ms, 2500ms); - add(jtDISK, "diskAccess", 0, 500ms, 1000ms); - add(jtTXN_PROC, "processTransaction", 0, 0ms, 0ms); - add(jtOB_SETUP, "orderBookSetup", 0, 0ms, 0ms); - add(jtPATH_FIND, "pathFind", 0, 0ms, 0ms); - add(jtHO_READ, "nodeRead", 0, 0ms, 0ms); - add(jtHO_WRITE, "nodeWrite", 0, 0ms, 0ms); - add(jtGENERIC, "generic", 0, 0ms, 0ms); - add(jtNS_SYNC_READ, "SyncReadNode", 0, 0ms, 0ms); - add(jtNS_ASYNC_READ, "AsyncReadNode", 0, 0ms, 0ms); - add(jtNS_WRITE, "WriteNode", 0, 0ms, 0ms); + add(JtPeer, "peerCommand", 0, 200ms, 2500ms); + add(JtDisk, "diskAccess", 0, 500ms, 1000ms); + add(JtTxnProc, "processTransaction", 0, 0ms, 0ms); + add(JtObSetup, "orderBookSetup", 0, 0ms, 0ms); + add(JtPathFind, "pathFind", 0, 0ms, 0ms); + add(JtHoRead, "nodeRead", 0, 0ms, 0ms); + add(JtHoWrite, "nodeWrite", 0, 0ms, 0ms); + add(JtGeneric, "generic", 0, 0ms, 0ms); + add(JtNsSyncRead, "SyncReadNode", 0, 0ms, 0ms); + add(JtNsAsyncRead, "AsyncReadNode", 0, 0ms, 0ms); + add(JtNsWrite, "WriteNode", 0, 0ms, 0ms); // clang-format on } @@ -103,8 +103,8 @@ public: static JobTypes const& instance() { - static JobTypes const types; - return types; + static JobTypes const kTYPES; + return kTYPES; } static std::string const& diff --git a/include/xrpl/core/LoadMonitor.h b/include/xrpl/core/LoadMonitor.h index b8777a7056..03c699a6a8 100644 --- a/include/xrpl/core/LoadMonitor.h +++ b/include/xrpl/core/LoadMonitor.h @@ -54,13 +54,13 @@ private: std::mutex mutex_; - std::uint64_t mCounts{0}; - int mLatencyEvents{0}; - std::chrono::milliseconds mLatencyMSAvg; - std::chrono::milliseconds mLatencyMSPeak; - std::chrono::milliseconds mTargetLatencyAvg; - std::chrono::milliseconds mTargetLatencyPk; - UptimeClock::time_point mLastUpdate; + std::uint64_t mCounts_{0}; + int mLatencyEvents_{0}; + std::chrono::milliseconds mLatencyMSAvg_; + std::chrono::milliseconds mLatencyMSPeak_; + std::chrono::milliseconds mTargetLatencyAvg_; + std::chrono::milliseconds mTargetLatencyPk_; + UptimeClock::time_point mLastUpdate_; beast::Journal const j_; }; diff --git a/include/xrpl/core/PeerReservationTable.h b/include/xrpl/core/PeerReservationTable.h index 80ad7196c3..c587a7f104 100644 --- a/include/xrpl/core/PeerReservationTable.h +++ b/include/xrpl/core/PeerReservationTable.h @@ -81,7 +81,7 @@ public: * @throw soci::soci_error */ std::optional - insert_or_assign(PeerReservation const& reservation); + insertOrAssign(PeerReservation const& reservation); /** * @return the erased reservation if it existed @@ -93,7 +93,7 @@ private: beast::Journal mutable journal_; std::mutex mutable mutex_; DatabaseCon* connection_{}; - std::unordered_set, KeyEqual> table_; + std::unordered_set, KeyEqual> table_; }; } // namespace xrpl diff --git a/include/xrpl/core/PerfLog.h b/include/xrpl/core/PerfLog.h index 7151d09b08..75e2bd9517 100644 --- a/include/xrpl/core/PerfLog.h +++ b/include/xrpl/core/PerfLog.h @@ -165,12 +165,12 @@ measureDurationAndLog( std::chrono::duration maxDelay, beast::Journal const& journal) { - auto start_time = std::chrono::high_resolution_clock::now(); + auto startTime = std::chrono::high_resolution_clock::now(); auto result = func(); - auto end_time = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(end_time - start_time); + auto endTime = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(endTime - startTime); if (duration > maxDelay) { JLOG(journal.warn()) << actionDescription << " took " << duration.count() << " ms"; diff --git a/include/xrpl/core/detail/Workers.h b/include/xrpl/core/detail/Workers.h index fb9004a9b6..c2eff0e9a6 100644 --- a/include/xrpl/core/detail/Workers.h +++ b/include/xrpl/core/detail/Workers.h @@ -176,7 +176,7 @@ private: run(); private: - Workers& m_workers; + Workers& m_workers_; std::string const threadName_; int const instance_; @@ -192,19 +192,19 @@ private: deleteWorkers(beast::LockFreeStack& stack); private: - Callback& m_callback; + Callback& m_callback_; perf::PerfLog* perfLog_; - std::string m_threadNames; // The name to give each thread - std::condition_variable m_cv; // signaled when all threads paused - std::mutex m_mut; - bool m_allPaused{true}; - semaphore m_semaphore; // each pending task is 1 resource - int m_numberOfThreads{0}; // how many we want active now - std::atomic m_activeCount; // to know when all are paused - std::atomic m_pauseCount; // how many threads need to pause now - std::atomic m_runningTaskCount; // how many calls to processTask() active - beast::LockFreeStack m_everyone; // holds all created workers - beast::LockFreeStack m_paused; // holds just paused workers + std::string m_threadNames_; // The name to give each thread + std::condition_variable m_cv_; // signaled when all threads paused + std::mutex m_mut_; + bool m_allPaused_{true}; + semaphore m_semaphore_; // each pending task is 1 resource + int m_numberOfThreads_{0}; // how many we want active now + std::atomic m_activeCount_; // to know when all are paused + std::atomic m_pauseCount_; // how many threads need to pause now + std::atomic m_runningTaskCount_; // how many calls to processTask() active + beast::LockFreeStack m_everyone_; // holds all created workers + beast::LockFreeStack m_paused_; // holds just paused workers }; } // namespace xrpl diff --git a/include/xrpl/core/detail/semaphore.h b/include/xrpl/core/detail/semaphore.h index 38b7329ab1..968e389491 100644 --- a/include/xrpl/core/detail/semaphore.h +++ b/include/xrpl/core/detail/semaphore.h @@ -34,12 +34,12 @@ namespace xrpl { template -class basic_semaphore +class BasicSemaphore { private: - Mutex m_mutex; - CondVar m_cond; - std::size_t m_count; + Mutex m_mutex_; + CondVar m_cond_; + std::size_t m_count_; public: using size_type = std::size_t; @@ -47,7 +47,7 @@ public: /** Create the semaphore, with an optional initial count. If unspecified, the initial count is zero. */ - explicit basic_semaphore(size_type count = 0) : m_count(count) + explicit BasicSemaphore(size_type count = 0) : m_count_(count) { } @@ -55,35 +55,35 @@ public: void notify() { - std::scoped_lock const lock{m_mutex}; - ++m_count; - m_cond.notify_one(); + std::scoped_lock const lock{m_mutex_}; + ++m_count_; + m_cond_.notify_one(); } /** Block until notify is called. */ void wait() { - std::unique_lock lock{m_mutex}; - while (m_count == 0) - m_cond.wait(lock); - --m_count; + std::unique_lock lock{m_mutex_}; + while (m_count_ == 0) + m_cond_.wait(lock); + --m_count_; } /** Perform a non-blocking wait. @return `true` If the wait would be satisfied. */ bool - try_wait() + tryWait() { - std::scoped_lock lock{m_mutex}; - if (m_count == 0) + std::scoped_lock lock{m_mutex_}; + if (m_count_ == 0) return false; - --m_count; + --m_count_; return true; } }; -using semaphore = basic_semaphore; +using semaphore = BasicSemaphore; } // namespace xrpl diff --git a/include/xrpl/json/json_value.h b/include/xrpl/json/json_value.h index def2696c5c..ba17ce799c 100644 --- a/include/xrpl/json/json_value.h +++ b/include/xrpl/json/json_value.h @@ -18,14 +18,14 @@ namespace Json { // Used throughout JSON layer // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum ValueType { - nullValue = 0, ///< 'null' value - intValue, ///< signed integer value - uintValue, ///< unsigned integer value - realValue, ///< double value - stringValue, ///< UTF-8 string value - booleanValue, ///< bool value - arrayValue, ///< array value (ordered list) - objectValue ///< object value (collection of name/value pairs). + NullValue = 0, ///< 'null' value + IntValue, ///< signed integer value + UintValue, ///< unsigned integer value + RealValue, ///< double value + StringValue, ///< UTF-8 string value + BooleanValue, ///< bool value + ArrayValue, ///< array value (ordered list) + ObjectValue ///< object value (collection of name/value pairs). }; /** \brief Lightweight wrapper to tag static string. @@ -56,7 +56,7 @@ public: } [[nodiscard]] constexpr char const* - c_str() const + cStr() const { return str_; } @@ -68,7 +68,7 @@ private: inline bool operator==(StaticString x, StaticString y) { - return strcmp(x.c_str(), y.c_str()) == 0; + return strcmp(x.cStr(), y.cStr()) == 0; } inline bool @@ -80,7 +80,7 @@ operator!=(StaticString x, StaticString y) inline bool operator==(std::string const& x, StaticString y) { - return strcmp(x.c_str(), y.c_str()) == 0; + return strcmp(x.c_str(), y.cStr()) == 0; } inline bool @@ -140,10 +140,10 @@ public: using Int = Json::Int; using ArrayIndex = UInt; - static Value const null; - static constexpr Int minInt = std::numeric_limits::min(); - static constexpr Int maxInt = std::numeric_limits::max(); - static constexpr UInt maxUInt = std::numeric_limits::max(); + static Value const kNULL; + static constexpr Int kMIN_INT = std::numeric_limits::min(); + static constexpr Int kMAX_INT = std::numeric_limits::max(); + static constexpr UInt kMAX_U_INT = std::numeric_limits::max(); private: class CZString @@ -151,7 +151,7 @@ private: public: // Stored as int field, implicit conversion // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) - enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy }; + enum DuplicationPolicy { NoDuplication = 0, Duplicate, DuplicateOnCopy }; CZString(int index); CZString(char const* cstr, DuplicationPolicy allocate); CZString(CZString const& other); @@ -165,7 +165,7 @@ private: [[nodiscard]] int index() const; [[nodiscard]] char const* - c_str() const; + cStr() const; [[nodiscard]] bool isStaticString() const; @@ -193,7 +193,7 @@ public: Json::Value obj_value(Json::objectValue); // {} \endcode */ - Value(ValueType type = nullValue); + Value(ValueType type = NullValue); Value(Int value); Value(UInt value); Value(double value); @@ -418,11 +418,11 @@ private: union ValueHolder { Int int_; - UInt uint_; - double real_; + UInt uint; + double real; bool bool_; - char* string_; - ObjectValues* map_{nullptr}; + char* string; + ObjectValues* map{nullptr}; } value_; ValueType type_ : 8; int allocated_ : 1 {}; // Notes: if declared as bool, bitfield is useless. @@ -477,7 +477,7 @@ class ValueAllocator public: // Need to be named before converting // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) - enum { unknown = (unsigned)-1 }; + enum { Unknown = (unsigned)-1 }; virtual ~ValueAllocator() = default; @@ -486,7 +486,7 @@ public: virtual void releaseMemberName(char* memberName) = 0; virtual char* - duplicateStringValue(char const* value, unsigned int length = unknown) = 0; + duplicateStringValue(char const* value, unsigned int length = Unknown) = 0; virtual void releaseStringValue(char* value) = 0; }; diff --git a/include/xrpl/json/json_writer.h b/include/xrpl/json/json_writer.h index 45961fe030..a4fec11d63 100644 --- a/include/xrpl/json/json_writer.h +++ b/include/xrpl/json/json_writer.h @@ -204,31 +204,31 @@ write_value(Write const& write, Value const& value) { switch (value.type()) { - case nullValue: + case NullValue: write("null", 4); break; - case intValue: + case IntValue: write_string(write, valueToString(value.asInt())); break; - case uintValue: + case UintValue: write_string(write, valueToString(value.asUInt())); break; - case realValue: + case RealValue: write_string(write, valueToString(value.asDouble())); break; - case stringValue: + case StringValue: write_string(write, valueToQuotedString(value.asCString())); break; - case booleanValue: + case BooleanValue: write_string(write, valueToString(value.asBool())); break; - case arrayValue: { + case ArrayValue: { write("[", 1); int const size = value.size(); for (int index = 0; index < size; ++index) @@ -241,7 +241,7 @@ write_value(Write const& write, Value const& value) break; } - case objectValue: { + case ObjectValue: { Value::Members const members = value.getMemberNames(); write("{", 1); for (auto it = members.begin(); it != members.end(); ++it) diff --git a/include/xrpl/ledger/ApplyView.h b/include/xrpl/ledger/ApplyView.h index 0aea9813b9..f825311e1d 100644 --- a/include/xrpl/ledger/ApplyView.h +++ b/include/xrpl/ledger/ApplyView.h @@ -10,56 +10,56 @@ namespace xrpl { // Bitwise flag enum with existing operator overloads // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum ApplyFlags : std::uint32_t { - tapNONE = 0x00, + TapNone = 0x00, // This is a local transaction with the // fail_hard flag set. - tapFAIL_HARD = 0x10, + TapFailHard = 0x10, // This is not the transaction's last pass // Transaction can be retried, soft failures allowed - tapRETRY = 0x20, + TapRetry = 0x20, // Transaction came from a privileged source - tapUNLIMITED = 0x400, + TapUnlimited = 0x400, // Transaction is executing as part of a batch - tapBATCH = 0x800, + TapBatch = 0x800, // Transaction shouldn't be applied // Signatures shouldn't be checked - tapDRY_RUN = 0x1000 + TapDryRun = 0x1000 }; constexpr ApplyFlags operator|(ApplyFlags const& lhs, ApplyFlags const& rhs) { - return safe_cast( - safe_cast>(lhs) | - safe_cast>(rhs)); + return safeCast( + safeCast>(lhs) | + safeCast>(rhs)); } -static_assert((tapFAIL_HARD | tapRETRY) == safe_cast(0x30u), "ApplyFlags operator |"); -static_assert((tapRETRY | tapFAIL_HARD) == safe_cast(0x30u), "ApplyFlags operator |"); +static_assert((TapFailHard | TapRetry) == safeCast(0x30u), "ApplyFlags operator |"); +static_assert((TapRetry | TapFailHard) == safeCast(0x30u), "ApplyFlags operator |"); constexpr ApplyFlags operator&(ApplyFlags const& lhs, ApplyFlags const& rhs) { - return safe_cast( - safe_cast>(lhs) & - safe_cast>(rhs)); + return safeCast( + safeCast>(lhs) & + safeCast>(rhs)); } -static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &"); -static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &"); +static_assert((TapFailHard & TapRetry) == TapNone, "ApplyFlags operator &"); +static_assert((TapRetry & TapFailHard) == TapNone, "ApplyFlags operator &"); constexpr ApplyFlags operator~(ApplyFlags const& flags) { - return safe_cast(~safe_cast>(flags)); + return safeCast(~safeCast>(flags)); } -static_assert(~tapRETRY == safe_cast(0xFFFFFFDFu), "ApplyFlags operator ~"); +static_assert(~TapRetry == safeCast(0xFFFFFFDFu), "ApplyFlags operator ~"); inline ApplyFlags operator|=(ApplyFlags& lhs, ApplyFlags const& rhs) diff --git a/include/xrpl/ledger/CachedView.h b/include/xrpl/ledger/CachedView.h index 5dad2598f4..34a75e4c07 100644 --- a/include/xrpl/ledger/CachedView.h +++ b/include/xrpl/ledger/CachedView.h @@ -17,7 +17,7 @@ private: DigestAwareReadView const& base_; CachedSLEs& cache_; std::mutex mutable mutex_; - std::unordered_map> mutable map_; + std::unordered_map> mutable map_; public: CachedViewImpl() = delete; @@ -69,31 +69,31 @@ public: return base_.succ(key, last); } - std::unique_ptr + std::unique_ptr slesBegin() const override { return base_.slesBegin(); } - std::unique_ptr + std::unique_ptr slesEnd() const override { return base_.slesEnd(); } - std::unique_ptr + std::unique_ptr slesUpperBound(uint256 const& key) const override { return base_.slesUpperBound(key); } - std::unique_ptr + std::unique_ptr txsBegin() const override { return base_.txsBegin(); } - std::unique_ptr + std::unique_ptr txsEnd() const override { return base_.txsEnd(); diff --git a/include/xrpl/ledger/Ledger.h b/include/xrpl/ledger/Ledger.h index 62303ba3d2..332d39dddd 100644 --- a/include/xrpl/ledger/Ledger.h +++ b/include/xrpl/ledger/Ledger.h @@ -20,11 +20,11 @@ class TransactionMaster; class SqliteStatement; -struct create_genesis_t +struct CreateGenesisT { - explicit create_genesis_t() = default; + explicit CreateGenesisT() = default; }; -extern create_genesis_t const create_genesis; +extern CreateGenesisT const kCREATE_GENESIS; /** Holds a ledger. @@ -81,7 +81,7 @@ public: Amendments specified are enabled in the genesis ledger */ Ledger( - create_genesis_t, + CreateGenesisT, Rules rules, Fees const& fees, std::vector const& amendments, @@ -169,19 +169,19 @@ public: std::shared_ptr read(Keylet const& k) const override; - std::unique_ptr + std::unique_ptr slesBegin() const override; - std::unique_ptr + std::unique_ptr slesEnd() const override; - std::unique_ptr + std::unique_ptr slesUpperBound(uint256 const& key) const override; - std::unique_ptr + std::unique_ptr txsBegin() const override; - std::unique_ptr + std::unique_ptr txsEnd() const override; bool @@ -249,7 +249,7 @@ public: bool isImmutable() const { - return mImmutable; + return mImmutable_; } /* Mark this ledger as "should be full". @@ -392,7 +392,7 @@ private: static std::pair, std::shared_ptr> deserializeTxPlusMeta(SHAMapItem const& item); - bool mImmutable; + bool mImmutable_; // A SHAMap containing the transactions associated with this ledger. SHAMap mutable txMap_; diff --git a/include/xrpl/ledger/OpenView.h b/include/xrpl/ledger/OpenView.h index 3420aa1df0..eae548e7b5 100644 --- a/include/xrpl/ledger/OpenView.h +++ b/include/xrpl/ledger/OpenView.h @@ -20,20 +20,20 @@ namespace xrpl { rules of open ledgers applied during transaction processing. */ -inline constexpr struct open_ledger_t +inline constexpr struct OpenLedgerT { - explicit constexpr open_ledger_t() = default; -} open_ledger{}; + explicit constexpr OpenLedgerT() = default; +} kOPEN_LEDGER{}; /** Batch view construction tag. Views constructed with this tag are part of a stack of views used during batch transaction applied. */ -inline constexpr struct batch_view_t +inline constexpr struct BatchViewT { - explicit constexpr batch_view_t() = default; -} batch_view{}; + explicit constexpr BatchViewT() = default; +} kBATCH_VIEW{}; //------------------------------------------------------------------------------ @@ -47,20 +47,20 @@ private: // Initial size for the monotonic_buffer_resource used for allocations // The size was chosen from the old `qalloc` code (which this replaces). // It is unclear how the size initially chosen in qalloc. - static constexpr size_t initialBufferSize = kilobytes(256); + static constexpr size_t kINITIAL_BUFFER_SIZE = kilobytes(256); class txs_iter_impl; - struct txData + struct TxData { std::shared_ptr txn; std::shared_ptr meta; // Constructor needed for emplacement in std::map - txData( - std::shared_ptr const& txn_, - std::shared_ptr const& meta_) - : txn(txn_), meta(meta_) + TxData( + std::shared_ptr const& txn, + std::shared_ptr const& meta) + : txn(txn), meta(meta) { } }; @@ -70,9 +70,9 @@ private: // functions b/c clang does not support pmr yet (as-of 9/2020) using txs_map = std::map< key_type, - txData, + TxData, std::less, - boost::container::pmr::polymorphic_allocator>>; + boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be // easily moved. @@ -133,17 +133,17 @@ public: all newly inserted tx. */ OpenView( - open_ledger_t, + OpenLedgerT, ReadView const* base, Rules rules, std::shared_ptr hold = nullptr); - OpenView(open_ledger_t, Rules const& rules, std::shared_ptr const& base) - : OpenView(open_ledger, &*base, rules, base) + OpenView(OpenLedgerT, Rules const& rules, std::shared_ptr const& base) + : OpenView(kOPEN_LEDGER, &*base, rules, base) { } - OpenView(batch_view_t, OpenView& base) : OpenView(std::addressof(base)) + OpenView(BatchViewT, OpenView& base) : OpenView(std::addressof(base)) { baseTxCount_ = base.txCount(); } @@ -200,19 +200,19 @@ public: std::shared_ptr read(Keylet const& k) const override; - std::unique_ptr + std::unique_ptr slesBegin() const override; - std::unique_ptr + std::unique_ptr slesEnd() const override; - std::unique_ptr + std::unique_ptr slesUpperBound(uint256 const& key) const override; - std::unique_ptr + std::unique_ptr txsBegin() const override; - std::unique_ptr + std::unique_ptr txsEnd() const override; bool diff --git a/include/xrpl/ledger/ReadView.h b/include/xrpl/ledger/ReadView.h index bb0aa56507..4f9bf9c31d 100644 --- a/include/xrpl/ledger/ReadView.h +++ b/include/xrpl/ledger/ReadView.h @@ -36,25 +36,25 @@ public: using mapped_type = std::shared_ptr; - struct sles_type : detail::ReadViewFwdRange> + struct SlesType : detail::ReadViewFwdRange> { - explicit sles_type(ReadView const& view); - [[nodiscard]] iterator + explicit SlesType(ReadView const& view); + [[nodiscard]] Iterator begin() const; - [[nodiscard]] iterator + [[nodiscard]] Iterator end() const; - [[nodiscard]] iterator - upper_bound(key_type const& key) const; + [[nodiscard]] Iterator + upperBound(key_type const& key) const; }; - struct txs_type : detail::ReadViewFwdRange + struct TxsType : detail::ReadViewFwdRange { - explicit txs_type(ReadView const& view); + explicit TxsType(ReadView const& view); [[nodiscard]] bool empty() const; - [[nodiscard]] iterator + [[nodiscard]] Iterator begin() const; - [[nodiscard]] iterator + [[nodiscard]] Iterator end() const; }; @@ -189,23 +189,23 @@ public: } // used by the implementation - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesBegin() const = 0; // used by the implementation - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesEnd() const = 0; // used by the implementation - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr slesUpperBound(key_type const& key) const = 0; // used by the implementation - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr txsBegin() const = 0; // used by the implementation - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr txsEnd() const = 0; /** Returns `true` if a tx exists in the tx map. @@ -236,10 +236,10 @@ public: @note Visiting each state entry in the ledger can become quite expensive as the ledger grows. */ - sles_type sles; + SlesType sles; // The range of transactions - txs_type txs; + TxsType txs; }; //------------------------------------------------------------------------------ @@ -269,7 +269,7 @@ makeRulesGivenLedger(DigestAwareReadView const& ledger, Rules const& current); Rules makeRulesGivenLedger( DigestAwareReadView const& ledger, - std::unordered_set> const& presets); + std::unordered_set> const& presets); } // namespace xrpl diff --git a/include/xrpl/ledger/detail/ApplyStateTable.h b/include/xrpl/ledger/detail/ApplyStateTable.h index 93b639f54b..7b18f742b4 100644 --- a/include/xrpl/ledger/detail/ApplyStateTable.h +++ b/include/xrpl/ledger/detail/ApplyStateTable.h @@ -20,10 +20,10 @@ public: private: enum class Action { - cache, - erase, - insert, - modify, + Cache, + Erase, + Insert, + Modify, }; using items_t = std::map>>; diff --git a/include/xrpl/ledger/detail/ApplyViewBase.h b/include/xrpl/ledger/detail/ApplyViewBase.h index d6a293610a..558c9e5d4d 100644 --- a/include/xrpl/ledger/detail/ApplyViewBase.h +++ b/include/xrpl/ledger/detail/ApplyViewBase.h @@ -43,19 +43,19 @@ public: [[nodiscard]] std::shared_ptr read(Keylet const& k) const override; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesBegin() const override; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesEnd() const override; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesUpperBound(uint256 const& key) const override; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr txsBegin() const override; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr txsEnd() const override; [[nodiscard]] bool diff --git a/include/xrpl/ledger/detail/RawStateTable.h b/include/xrpl/ledger/detail/RawStateTable.h index ec5cb05981..cf5ea3dcd8 100644 --- a/include/xrpl/ledger/detail/RawStateTable.h +++ b/include/xrpl/ledger/detail/RawStateTable.h @@ -19,16 +19,16 @@ public: // Initial size for the monotonic_buffer_resource used for allocations // The size was chosen from the old `qalloc` code (which this replaces). // It is unclear how the size initially chosen in qalloc. - static constexpr size_t initialBufferSize = kilobytes(256); + static constexpr size_t kINITIAL_BUFFER_SIZE = kilobytes(256); RawStateTable() - : monotonic_resource_{ - std::make_unique(initialBufferSize)} + : monotonic_resource_{std::make_unique( + kINITIAL_BUFFER_SIZE)} , items_{monotonic_resource_.get()} {}; RawStateTable(RawStateTable const& rhs) - : monotonic_resource_{ - std::make_unique(initialBufferSize)} + : monotonic_resource_{std::make_unique( + kINITIAL_BUFFER_SIZE)} , items_{rhs.items_, monotonic_resource_.get()} , dropsDestroyed_{rhs.dropsDestroyed_} {}; @@ -63,31 +63,31 @@ public: void destroyXRP(XRPAmount const& fee); - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesBegin(ReadView const& base) const; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesEnd(ReadView const& base) const; - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr slesUpperBound(ReadView const& base, uint256 const& key) const; private: enum class Action { - erase, - insert, - replace, + Erase, + Insert, + Replace, }; class sles_iter_impl; - struct sleAction + struct SleAction { Action action; std::shared_ptr sle; // Constructor needed for emplacement in std::map - sleAction(Action action_, std::shared_ptr const& sle_) : action(action_), sle(sle_) + SleAction(Action action, std::shared_ptr const& sle) : action(action), sle(sle) { } }; @@ -96,9 +96,9 @@ private: // functions b/c clang does not support pmr yet (as-of 9/2020) using items_t = std::map< key_type, - sleAction, + SleAction, std::less, - boost::container::pmr::polymorphic_allocator>>; + boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be // easily moved. std::unique_ptr monotonic_resource_; diff --git a/include/xrpl/ledger/detail/ReadViewFwdRange.h b/include/xrpl/ledger/detail/ReadViewFwdRange.h index 74fe0447dc..c548ccb101 100644 --- a/include/xrpl/ledger/detail/ReadViewFwdRange.h +++ b/include/xrpl/ledger/detail/ReadViewFwdRange.h @@ -53,7 +53,7 @@ public: "ReadViewFwdRange move and move assign constructors should be " "noexcept"); - class iterator + class Iterator { public: using value_type = ValueType; @@ -66,25 +66,25 @@ public: using iterator_category = std::forward_iterator_tag; - iterator() = default; + Iterator() = default; - iterator(iterator const& other); - iterator(iterator&& other) noexcept; + Iterator(Iterator const& other); + Iterator(Iterator&& other) noexcept; // Used by the implementation - explicit iterator(ReadView const* view, std::unique_ptr impl); + explicit Iterator(ReadView const* view, std::unique_ptr impl); - iterator& - operator=(iterator const& other); + Iterator& + operator=(Iterator const& other); - iterator& - operator=(iterator&& other) noexcept; + Iterator& + operator=(Iterator&& other) noexcept; bool - operator==(iterator const& other) const; + operator==(Iterator const& other) const; bool - operator!=(iterator const& other) const; + operator!=(Iterator const& other) const; // Can throw reference @@ -94,10 +94,10 @@ public: pointer operator->() const; - iterator& + Iterator& operator++(); - iterator + Iterator operator++(int); private: @@ -106,10 +106,10 @@ public: std::optional mutable cache_; }; - static_assert(std::is_nothrow_move_constructible{}, ""); - static_assert(std::is_nothrow_move_assignable{}, ""); + static_assert(std::is_nothrow_move_constructible{}, ""); + static_assert(std::is_nothrow_move_assignable{}, ""); - using const_iterator = iterator; + using const_iterator = Iterator; using value_type = ValueType; diff --git a/include/xrpl/ledger/detail/ReadViewFwdRange.ipp b/include/xrpl/ledger/detail/ReadViewFwdRange.ipp index ce6754b39c..c1b9ace0c5 100644 --- a/include/xrpl/ledger/detail/ReadViewFwdRange.ipp +++ b/include/xrpl/ledger/detail/ReadViewFwdRange.ipp @@ -4,19 +4,19 @@ namespace xrpl { namespace detail { template -ReadViewFwdRange::iterator::iterator(iterator const& other) +ReadViewFwdRange::Iterator::Iterator(Iterator const& other) : view_(other.view_), impl_(other.impl_ ? other.impl_->copy() : nullptr), cache_(other.cache_) { } template -ReadViewFwdRange::iterator::iterator(iterator&& other) noexcept +ReadViewFwdRange::Iterator::Iterator(Iterator&& other) noexcept : view_(other.view_), impl_(std::move(other.impl_)), cache_(std::move(other.cache_)) { } template -ReadViewFwdRange::iterator::iterator( +ReadViewFwdRange::Iterator::Iterator( ReadView const* view, std::unique_ptr impl) : view_(view), impl_(std::move(impl)) @@ -25,7 +25,7 @@ ReadViewFwdRange::iterator::iterator( template auto -ReadViewFwdRange::iterator::operator=(iterator const& other) -> iterator& +ReadViewFwdRange::Iterator::operator=(Iterator const& other) -> Iterator& { if (this != &other) { @@ -38,7 +38,7 @@ ReadViewFwdRange::iterator::operator=(iterator const& other) -> itera template auto -ReadViewFwdRange::iterator::operator=(iterator&& other) noexcept -> iterator& +ReadViewFwdRange::Iterator::operator=(Iterator&& other) noexcept -> Iterator& { if (this != &other) { @@ -52,7 +52,7 @@ ReadViewFwdRange::iterator::operator=(iterator&& other) noexcept -> i template bool -ReadViewFwdRange::iterator::operator==(iterator const& other) const +ReadViewFwdRange::Iterator::operator==(Iterator const& other) const { XRPL_ASSERT( view_ == other.view_, @@ -67,14 +67,14 @@ ReadViewFwdRange::iterator::operator==(iterator const& other) const template bool -ReadViewFwdRange::iterator::operator!=(iterator const& other) const +ReadViewFwdRange::Iterator::operator!=(Iterator const& other) const { return !(*this == other); } template auto -ReadViewFwdRange::iterator::operator*() const -> reference +ReadViewFwdRange::Iterator::operator*() const -> reference { if (!cache_) cache_ = impl_->dereference(); @@ -83,14 +83,14 @@ ReadViewFwdRange::iterator::operator*() const -> reference template auto -ReadViewFwdRange::iterator::operator->() const -> pointer +ReadViewFwdRange::Iterator::operator->() const -> pointer { return &**this; } template auto -ReadViewFwdRange::iterator::operator++() -> iterator& +ReadViewFwdRange::Iterator::operator++() -> Iterator& { impl_->increment(); cache_.reset(); @@ -99,9 +99,9 @@ ReadViewFwdRange::iterator::operator++() -> iterator& template auto -ReadViewFwdRange::iterator::operator++(int) -> iterator +ReadViewFwdRange::Iterator::operator++(int) -> Iterator { - iterator prev(view_, impl_->copy()); + Iterator prev(view_, impl_->copy()); prev.cache_ = std::move(cache_); ++(*this); return prev; diff --git a/include/xrpl/ledger/helpers/AMMHelpers.h b/include/xrpl/ledger/helpers/AMMHelpers.h index 9258d58fb6..c62437bf75 100644 --- a/include/xrpl/ledger/helpers/AMMHelpers.h +++ b/include/xrpl/ledger/helpers/AMMHelpers.h @@ -25,11 +25,11 @@ namespace detail { Number reduceOffer(auto const& amount) { - static Number const reducedOfferPct(9999, -4); + static Number const kREDUCED_OFFER_PCT(9999, -4); // Make sure the result is always less than amount or zero. - NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero); - return amount * reducedOfferPct; + NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero); + return amount * kREDUCED_OFFER_PCT; } } // namespace detail @@ -177,10 +177,10 @@ getAMMOfferStartWithTakerGets( Quality const& targetQuality, std::uint16_t const& tfee) { - if (targetQuality.rate() == beast::zero) + if (targetQuality.rate() == beast::kZERO) return std::nullopt; - NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest); + NumberRoundModeGuard const mg(Number::RoundingMode::ToNearest); auto const f = feeMult(tfee); auto const a = 1; auto const b = pool.in * (1 - 1 / f) / targetQuality.rate() - 2 * pool.out; @@ -202,7 +202,7 @@ getAMMOfferStartWithTakerGets( // Round downward to minimize the offer and to maximize the quality. // This has the most impact when takerGets is XRP. auto const takerGets = - toAmount(getAsset(pool.out), nTakerGetsProposed, Number::rounding_mode::downward); + toAmount(getAsset(pool.out), nTakerGetsProposed, Number::RoundingMode::Downward); return TAmounts{swapAssetOut(pool, takerGets, tfee), takerGets}; }; @@ -244,10 +244,10 @@ getAMMOfferStartWithTakerPays( Quality const& targetQuality, std::uint16_t tfee) { - if (targetQuality.rate() == beast::zero) + if (targetQuality.rate() == beast::kZERO) return std::nullopt; - NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest); + NumberRoundModeGuard const mg(Number::RoundingMode::ToNearest); auto const f = feeMult(tfee); auto const& a = f; auto const b = pool.in * (1 + f); @@ -269,7 +269,7 @@ getAMMOfferStartWithTakerPays( // Round downward to minimize the offer and to maximize the quality. // This has the most impact when takerPays is XRP. auto const takerPays = - toAmount(getAsset(pool.in), nTakerPaysProposed, Number::rounding_mode::downward); + toAmount(getAsset(pool.in), nTakerPaysProposed, Number::RoundingMode::Downward); return TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; }; @@ -342,7 +342,7 @@ changeSpotPriceQuality( return std::nullopt; } auto const takerPays = - toAmount(getAsset(pool.in), nTakerPays, Number::rounding_mode::upward); + toAmount(getAsset(pool.in), nTakerPays, Number::RoundingMode::Upward); // should not fail if (auto amounts = TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; Quality{amounts} < quality && @@ -446,34 +446,34 @@ swapAssetIn(TAmounts const& pool, TIn const& assetIn, std::uint16_t t // 1-fee // maximize: // fee - saveNumberRoundMode const _{Number::getround()}; + SaveNumberRoundMode const _{Number::getround()}; - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); auto const numerator = pool.in * pool.out; auto const fee = getFee(tfee); - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); auto const denom = pool.in + assetIn * (1 - fee); if (denom.signum() <= 0) return toAmount(getAsset(pool.out), 0); - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); auto const ratio = numerator / denom; - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); auto const swapOut = pool.out - ratio; if (swapOut.signum() < 0) return toAmount(getAsset(pool.out), 0); - return toAmount(getAsset(pool.out), swapOut, Number::rounding_mode::downward); + return toAmount(getAsset(pool.out), swapOut, Number::RoundingMode::Downward); } return toAmount( getAsset(pool.out), pool.out - (pool.in * pool.out) / (pool.in + assetIn * feeMult(tfee)), - Number::rounding_mode::downward); + Number::RoundingMode::Downward); } /** Swap assetOut out of the pool and swap in a proportional amount @@ -508,38 +508,38 @@ swapAssetOut(TAmounts const& pool, TOut const& assetOut, std::uint16_ // maximize: // tfee/100000 - saveNumberRoundMode const _{Number::getround()}; + SaveNumberRoundMode const _{Number::getround()}; - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); auto const numerator = pool.in * pool.out; - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); auto const denom = pool.out - assetOut; if (denom.signum() <= 0) { return toMaxAmount(getAsset(pool.in)); } - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); auto const ratio = numerator / denom; auto const numerator2 = ratio - pool.in; auto const fee = getFee(tfee); - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); auto const feeMult = 1 - fee; - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); auto const swapIn = numerator2 / feeMult; if (swapIn.signum() < 0) return toAmount(getAsset(pool.in), 0); - return toAmount(getAsset(pool.in), swapIn, Number::rounding_mode::upward); + return toAmount(getAsset(pool.in), swapIn, Number::RoundingMode::Upward); } return toAmount( getAsset(pool.in), ((pool.in * pool.out) / (pool.out - assetOut) - pool.in) / feeMult(tfee), - Number::rounding_mode::upward); + Number::RoundingMode::Upward); } /** Return square of n. @@ -589,26 +589,26 @@ Number solveQuadraticEq(Number const& a, Number const& b, Number const& c); STAmount -multiply(STAmount const& amount, Number const& frac, Number::rounding_mode rm); +multiply(STAmount const& amount, Number const& frac, Number::RoundingMode rm); namespace detail { -inline Number::rounding_mode +inline Number::RoundingMode getLPTokenRounding(IsDeposit isDeposit) { // Minimize on deposit, maximize on withdraw to ensure // AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance - return isDeposit == IsDeposit::Yes ? Number::rounding_mode::downward - : Number::rounding_mode::upward; + return isDeposit == IsDeposit::Yes ? Number::RoundingMode::Downward + : Number::RoundingMode::Upward; } -inline Number::rounding_mode +inline Number::RoundingMode getAssetRounding(IsDeposit isDeposit) { // Maximize on deposit, minimize on withdraw to ensure // AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance - return isDeposit == IsDeposit::Yes ? Number::rounding_mode::upward - : Number::rounding_mode::downward; + return isDeposit == IsDeposit::Yes ? Number::RoundingMode::Upward + : Number::RoundingMode::Downward; } } // namespace detail diff --git a/include/xrpl/ledger/helpers/LendingHelpers.h b/include/xrpl/ledger/helpers/LendingHelpers.h index e1d8626b7c..83ce8e5efa 100644 --- a/include/xrpl/ledger/helpers/LendingHelpers.h +++ b/include/xrpl/ledger/helpers/LendingHelpers.h @@ -10,7 +10,7 @@ namespace xrpl { bool checkLendingProtocolDependencies(Rules const& rules, STTx const& tx); -static constexpr std::uint32_t secondsInYear = 365 * 24 * 60 * 60; +static constexpr std::uint32_t kSECONDS_IN_YEAR = 365 * 24 * 60 * 60; Number loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval); @@ -19,7 +19,7 @@ loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval); inline Number roundPeriodicPayment(Asset const& asset, Number const& periodicPayment, std::int32_t scale) { - return roundToAsset(asset, periodicPayment, scale, Number::rounding_mode::upward); + return roundToAsset(asset, periodicPayment, scale, Number::RoundingMode::Upward); } /* Represents the breakdown of amounts to be paid and changes applied to the @@ -42,14 +42,14 @@ struct LoanPaymentParts // The amount of principal paid that reduces the loan balance. // This amount is subtracted from sfPrincipalOutstanding in the Loan object // and paid to the Vault - Number principalPaid = numZero; + Number principalPaid = kNUM_ZERO; // The total amount of interest paid to the Vault. // This includes: // - Tracked interest from the amortization schedule // - Untracked interest (e.g., late payment penalty interest) // This value is always non-negative. - Number interestPaid = numZero; + Number interestPaid = kNUM_ZERO; // The change in the loan's total value outstanding. // - If valueChange < 0: Loan value decreased @@ -62,7 +62,7 @@ struct LoanPaymentParts // - Late payments add penalty interest to the loan value // - Early full payment may increase or decrease the loan value based on // terms - Number valueChange = numZero; + Number valueChange = kNUM_ZERO; /* The total amount of fees paid to the Broker. * This includes: @@ -70,7 +70,7 @@ struct LoanPaymentParts * - Untracked fees (e.g., late payment fees, service fees, origination * fees) This value is always non-negative. */ - Number feePaid = numZero; + Number feePaid = kNUM_ZERO; LoanPaymentParts& operator+=(LoanPaymentParts const& other); @@ -161,7 +161,7 @@ adjustImpreciseNumber( { value = roundToAsset(asset, value + adjustment, vaultScale); - if (*value < beast::zero) + if (*value < beast::kZERO) value = 0; } @@ -169,7 +169,7 @@ inline int getAssetsTotalScale(SLE::const_ref vaultSle) { if (!vaultSle) - return Number::minExponent - 1; // LCOV_EXCL_LINE + return Number::kMIN_EXPONENT - 1; // LCOV_EXCL_LINE return scale(vaultSle->at(sfAssetsTotal), vaultSle->at(sfAsset)); } @@ -222,7 +222,7 @@ namespace detail { // These classes and functions should only be accessed by LendingHelper // functions and unit tests -enum class PaymentSpecialCase { none, final, extra }; +enum class PaymentSpecialCase { None, Final, Extra }; /* Represents a single loan payment component parts. @@ -258,7 +258,7 @@ struct PaymentComponents // - none: Regular scheduled payment // - final: The last payment that closes out the loan // - extra: An additional payment beyond the regular schedule (overpayment) - PaymentSpecialCase specialCase = PaymentSpecialCase::none; + PaymentSpecialCase specialCase = PaymentSpecialCase::None; // Calculates the tracked interest portion of this payment. // This is derived from the other components as: @@ -310,7 +310,7 @@ struct ExtendedPaymentComponents : public PaymentComponents // borrower is sufficient to cover all components of the payment. Number totalDue; - ExtendedPaymentComponents(PaymentComponents const& p, Number fee, Number interest = numZero) + ExtendedPaymentComponents(PaymentComponents const& p, Number fee, Number interest = kNUM_ZERO) : PaymentComponents(p) , untrackedManagementFee(fee) , untrackedInterest(interest) @@ -462,7 +462,7 @@ isRounded(Asset const& asset, Number const& value, std::int32_t scale); // regular, late, and full are mutually exclusive. // overpayment is an "add on" to a regular payment, and follows that path with // potential extra work at the end. -enum class LoanPaymentType { regular = 0, late, full, overpayment }; +enum class LoanPaymentType { Regular = 0, Late, Full, Overpayment }; Expected loanMakePayment( diff --git a/include/xrpl/ledger/helpers/NFTokenHelpers.h b/include/xrpl/ledger/helpers/NFTokenHelpers.h index 49fd520d51..7c94eeb234 100644 --- a/include/xrpl/ledger/helpers/NFTokenHelpers.h +++ b/include/xrpl/ledger/helpers/NFTokenHelpers.h @@ -30,8 +30,8 @@ struct TokenAndPage STObject token; std::shared_ptr page; - TokenAndPage(STObject token_, std::shared_ptr page_) - : token(std::move(token_)), page(std::move(page_)) + TokenAndPage(STObject token, std::shared_ptr page) + : token(std::move(token)), page(std::move(page)) { } }; @@ -92,7 +92,7 @@ tokenOfferCreatePreflight( std::uint16_t nftFlags, Rules const& rules, std::optional const& owner = std::nullopt, - std::uint32_t txFlags = tfSellNFToken); + std::uint32_t txFlags = kTF_SELL_NF_TOKEN); /** Preclaim checks shared by NFTokenCreateOffer and NFTokenMint */ TER @@ -106,7 +106,7 @@ tokenOfferCreatePreclaim( std::uint16_t xferFee, beast::Journal j, std::optional const& owner = std::nullopt, - std::uint32_t txFlags = tfSellNFToken); + std::uint32_t txFlags = kTF_SELL_NF_TOKEN); /** doApply implementation shared by NFTokenCreateOffer and NFTokenMint */ TER @@ -120,7 +120,7 @@ tokenOfferCreateApply( uint256 const& nftokenID, XRPAmount const& priorBalance, beast::Journal j, - std::uint32_t txFlags = tfSellNFToken); + std::uint32_t txFlags = kTF_SELL_NF_TOKEN); TER checkTrustlineAuthorized( diff --git a/include/xrpl/ledger/helpers/RippleStateHelpers.h b/include/xrpl/ledger/helpers/RippleStateHelpers.h index 17b0f7673e..28210999f5 100644 --- a/include/xrpl/ledger/helpers/RippleStateHelpers.h +++ b/include/xrpl/ledger/helpers/RippleStateHelpers.h @@ -118,7 +118,7 @@ isDeepFrozen( [[nodiscard]] inline TER checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue) { - return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS; + return isDeepFrozen(view, account, issue) ? (TER)TecFrozen : (TER)TesSuccess; } //------------------------------------------------------------------------------ diff --git a/include/xrpl/ledger/helpers/TokenHelpers.h b/include/xrpl/ledger/helpers/TokenHelpers.h index 8f83465da3..9ccef3e4bf 100644 --- a/include/xrpl/ledger/helpers/TokenHelpers.h +++ b/include/xrpl/ledger/helpers/TokenHelpers.h @@ -21,13 +21,13 @@ namespace xrpl { //------------------------------------------------------------------------------ /** Controls the treatment of frozen account balances */ -enum class FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN }; +enum class FreezeHandling { FhIgnoreFreeze, FhZeroIfFrozen }; /** Controls the treatment of unauthorized MPT balances */ -enum class AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED }; +enum class AuthHandling { AhIgnoreAuth, AhZeroIfUnauthorized }; /** Controls whether to include the account's full spendable balance */ -enum class SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE }; +enum class SpendableHandling { ShSimpleBalance, ShFullBalance }; enum class WaiveTransferFee : bool { No = false, Yes }; @@ -135,7 +135,7 @@ accountHolds( AccountID const& issuer, FreezeHandling zeroIfFrozen, beast::Journal j, - SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE); + SpendableHandling includeFullBalance = SpendableHandling::ShSimpleBalance); [[nodiscard]] STAmount accountHolds( @@ -144,7 +144,7 @@ accountHolds( Issue const& issue, FreezeHandling zeroIfFrozen, beast::Journal j, - SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE); + SpendableHandling includeFullBalance = SpendableHandling::ShSimpleBalance); [[nodiscard]] STAmount accountHolds( @@ -154,7 +154,7 @@ accountHolds( FreezeHandling zeroIfFrozen, AuthHandling zeroIfUnauthorized, beast::Journal j, - SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE); + SpendableHandling includeFullBalance = SpendableHandling::ShSimpleBalance); [[nodiscard]] STAmount accountHolds( @@ -164,7 +164,7 @@ accountHolds( FreezeHandling zeroIfFrozen, AuthHandling zeroIfUnauthorized, beast::Journal j, - SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE); + SpendableHandling includeFullBalance = SpendableHandling::ShSimpleBalance); // Returns the amount an account can spend of the currency type saDefault, or // returns saDefault if this account is the issuer of the currency in diff --git a/include/xrpl/nodestore/Backend.h b/include/xrpl/nodestore/Backend.h index 7f9dd172cc..124cd99db5 100644 --- a/include/xrpl/nodestore/Backend.h +++ b/include/xrpl/nodestore/Backend.h @@ -113,7 +113,7 @@ public: @see import */ virtual void - for_each(std::function)> f) = 0; + forEach(std::function)> f) = 0; /** Estimate the number of write operations pending. */ virtual int diff --git a/include/xrpl/nodestore/Database.h b/include/xrpl/nodestore/Database.h index c21c1e27dd..d3be679a18 100644 --- a/include/xrpl/nodestore/Database.h +++ b/include/xrpl/nodestore/Database.h @@ -110,7 +110,7 @@ public: fetchNodeObject( uint256 const& hash, std::uint32_t ledgerSeq = 0, - FetchType fetchType = FetchType::synchronous, + FetchType fetchType = FetchType::Synchronous, bool duplicate = false); /** Fetch an object without waiting. @@ -266,7 +266,7 @@ private: @see import */ virtual void - for_each(std::function)> f) = 0; + forEach(std::function)> f) = 0; void threadEntry(); diff --git a/include/xrpl/nodestore/NodeObject.h b/include/xrpl/nodestore/NodeObject.h index 8759f244d2..d65cdb2fe0 100644 --- a/include/xrpl/nodestore/NodeObject.h +++ b/include/xrpl/nodestore/NodeObject.h @@ -10,11 +10,11 @@ namespace xrpl { /** The types of node objects. */ enum class NodeObjectType : std::uint32_t { - hotUNKNOWN = 0, - hotLEDGER = 1, - hotACCOUNT_NODE = 3, - hotTRANSACTION_NODE = 4, - hotDUMMY = 512 // an invalid or missing object + HotUnknown = 0, + HotLedger = 1, + HotAccountNode = 3, + HotTransactionNode = 4, + HotDummy = 512 // an invalid or missing object }; /** A simple object that the Ledger uses to store entries. @@ -29,7 +29,7 @@ enum class NodeObjectType : std::uint32_t { class NodeObject : public CountedObject { public: - static constexpr std::size_t keyBytes = 32; + static constexpr std::size_t kEY_BYTES = 32; private: // This hack is used to make the constructor effectively private @@ -71,9 +71,9 @@ public: getData() const; private: - NodeObjectType const mType; - uint256 const mHash; - Blob const mData; + NodeObjectType const mType_; + uint256 const mHash_; + Blob const mData_; }; } // namespace xrpl diff --git a/include/xrpl/nodestore/Scheduler.h b/include/xrpl/nodestore/Scheduler.h index bf256648aa..588ff19bdc 100644 --- a/include/xrpl/nodestore/Scheduler.h +++ b/include/xrpl/nodestore/Scheduler.h @@ -6,12 +6,12 @@ namespace xrpl::NodeStore { -enum class FetchType { synchronous, async }; +enum class FetchType { Synchronous, Async }; /** Contains information about a fetch operation. */ struct FetchReport { - explicit FetchReport(FetchType fetchType_) : fetchType(fetchType_) + explicit FetchReport(FetchType fetchType) : fetchType(fetchType) { } diff --git a/include/xrpl/nodestore/Types.h b/include/xrpl/nodestore/Types.h index cc7d345067..2b5d9ac770 100644 --- a/include/xrpl/nodestore/Types.h +++ b/include/xrpl/nodestore/Types.h @@ -12,24 +12,24 @@ enum { // This is only used to pre-allocate the array for // batch objects and does not affect the amount written. // - batchWritePreallocationSize = 256, + BatchWritePreallocationSize = 256, // This sets a limit on the maximum number of writes // in a batch. Actual usage can be twice this since // we have a new batch growing as we write the old. // - batchWriteLimitSize = 65536 + BatchWriteLimitSize = 65536 }; /** Return codes from Backend operations. */ enum class Status { - ok = 0, - notFound = 1, - dataCorrupt = 2, - unknown = 3, - backendError = 4, + Ok = 0, + NotFound = 1, + DataCorrupt = 2, + Unknown = 3, + BackendError = 4, - customCode = 100 + CustomCode = 100 }; /** A batch of NodeObjects to write at once. */ diff --git a/include/xrpl/protocol/AMMCore.h b/include/xrpl/protocol/AMMCore.h index 9132e98a9c..eb6bae9b37 100644 --- a/include/xrpl/protocol/AMMCore.h +++ b/include/xrpl/protocol/AMMCore.h @@ -8,21 +8,21 @@ namespace xrpl { -std::uint16_t constexpr TRADING_FEE_THRESHOLD = 1000; // 1% +std::uint16_t constexpr kTRADING_FEE_THRESHOLD = 1000; // 1% // Auction slot -std::uint32_t constexpr TOTAL_TIME_SLOT_SECS = 24 * 3600; -std::uint16_t constexpr AUCTION_SLOT_TIME_INTERVALS = 20; -std::uint16_t constexpr AUCTION_SLOT_MAX_AUTH_ACCOUNTS = 4; -std::uint32_t constexpr AUCTION_SLOT_FEE_SCALE_FACTOR = 100000; -std::uint32_t constexpr AUCTION_SLOT_DISCOUNTED_FEE_FRACTION = 10; -std::uint32_t constexpr AUCTION_SLOT_MIN_FEE_FRACTION = 25; -std::uint32_t constexpr AUCTION_SLOT_INTERVAL_DURATION = - TOTAL_TIME_SLOT_SECS / AUCTION_SLOT_TIME_INTERVALS; +std::uint32_t constexpr kTOTAL_TIME_SLOT_SECS = 24 * 3600; +std::uint16_t constexpr kAUCTION_SLOT_TIME_INTERVALS = 20; +std::uint16_t constexpr kAUCTION_SLOT_MAX_AUTH_ACCOUNTS = 4; +std::uint32_t constexpr kAUCTION_SLOT_FEE_SCALE_FACTOR = 100000; +std::uint32_t constexpr kAUCTION_SLOT_DISCOUNTED_FEE_FRACTION = 10; +std::uint32_t constexpr kAUCTION_SLOT_MIN_FEE_FRACTION = 25; +std::uint32_t constexpr kAUCTION_SLOT_INTERVAL_DURATION = + kTOTAL_TIME_SLOT_SECS / kAUCTION_SLOT_TIME_INTERVALS; // Votes -std::uint16_t constexpr VOTE_MAX_SLOTS = 8; -std::uint32_t constexpr VOTE_WEIGHT_SCALE_FACTOR = 100000; +std::uint16_t constexpr kVOTE_MAX_SLOTS = 8; +std::uint32_t constexpr kVOTE_WEIGHT_SCALE_FACTOR = 100000; class STObject; class STAmount; @@ -77,7 +77,7 @@ ammEnabled(Rules const&); inline Number getFee(std::uint16_t tfee) { - return Number{tfee} / AUCTION_SLOT_FEE_SCALE_FACTOR; + return Number{tfee} / kAUCTION_SLOT_FEE_SCALE_FACTOR; } /** Get fee multiplier (1 - tfee) diff --git a/include/xrpl/protocol/AccountID.h b/include/xrpl/protocol/AccountID.h index 641f2f15c1..bd50341b41 100644 --- a/include/xrpl/protocol/AccountID.h +++ b/include/xrpl/protocol/AccountID.h @@ -25,7 +25,7 @@ public: } // namespace detail /** A 160-bit unsigned that uniquely identifies an account. */ -using AccountID = base_uint<160, detail::AccountIDTag>; +using AccountID = BaseUint<160, detail::AccountIDTag>; /** Convert AccountID to base58 checked string */ std::string @@ -69,7 +69,7 @@ to_issuer(AccountID&, std::string const&); inline bool isXRP(AccountID const& c) { - return c == beast::zero; + return c == beast::kZERO; } // DEPRECATED diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index 9fb45e7bf8..72bdeb6a9b 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -15,7 +15,7 @@ toSTAmount(IOUAmount const& iou, Asset const& asset) XRPL_ASSERT(asset.holds(), "xrpl::toSTAmount : is Issue"); bool const isNeg = iou.signum() < 0; std::uint64_t const umant = isNeg ? -iou.mantissa() : iou.mantissa(); - return STAmount(asset, umant, iou.exponent(), isNeg, STAmount::unchecked()); + return STAmount(asset, umant, iou.exponent(), isNeg, STAmount::Unchecked()); } inline STAmount @@ -96,9 +96,9 @@ inline MPTAmount toAmount(STAmount const& amt) { XRPL_ASSERT( - amt.holds() && amt.mantissa() <= maxMPTokenAmount && amt.exponent() == 0, + amt.holds() && amt.mantissa() <= kMAX_MP_TOKEN_AMOUNT && amt.exponent() == 0, "xrpl::toAmount : maximum mantissa"); - if (amt.mantissa() > maxMPTokenAmount || amt.exponent() != 0) + if (amt.mantissa() > kMAX_MP_TOKEN_AMOUNT || amt.exponent() != 0) Throw("toAmount: invalid mantissa or exponent"); bool const isNeg = amt.negative(); std::int64_t const sMant = isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa(); @@ -141,9 +141,9 @@ toAmount(MPTAmount const& amt) template T -toAmount(Asset const& asset, Number const& n, Number::rounding_mode mode = Number::getround()) +toAmount(Asset const& asset, Number const& n, Number::RoundingMode mode = Number::getround()) { - saveNumberRoundMode const rm(Number::getround()); + SaveNumberRoundMode const rm(Number::getround()); if (isXRP(asset)) Number::setround(mode); @@ -167,8 +167,8 @@ toAmount(Asset const& asset, Number const& n, Number::rounding_mode mode = Numbe } else { - constexpr bool alwaysFalse = !std::is_same_v; - static_assert(alwaysFalse, "Unsupported type for toAmount"); + constexpr bool kALWAYS_FALSE = !std::is_same_v; + static_assert(kALWAYS_FALSE, "Unsupported type for toAmount"); } } @@ -178,35 +178,35 @@ toMaxAmount(Asset const& asset) { if constexpr (std::is_same_v) { - return IOUAmount(STAmount::cMaxValue, STAmount::cMaxOffset); + return IOUAmount(STAmount::kC_MAX_VALUE, STAmount::kC_MAX_OFFSET); } else if constexpr (std::is_same_v) { - return XRPAmount(static_cast(STAmount::cMaxNativeN)); + return XRPAmount(static_cast(STAmount::kC_MAX_NATIVE_N)); } else if constexpr (std::is_same_v) { - return MPTAmount(maxMPTokenAmount); + return MPTAmount(kMAX_MP_TOKEN_AMOUNT); } else if constexpr (std::is_same_v) { return asset.visit( [](Issue const& issue) { if (isXRP(issue)) - return STAmount(issue, static_cast(STAmount::cMaxNativeN)); - return STAmount(issue, STAmount::cMaxValue, STAmount::cMaxOffset); + return STAmount(issue, static_cast(STAmount::kC_MAX_NATIVE_N)); + return STAmount(issue, STAmount::kC_MAX_VALUE, STAmount::kC_MAX_OFFSET); }, - [](MPTIssue const& issue) { return STAmount(issue, maxMPTokenAmount); }); + [](MPTIssue const& issue) { return STAmount(issue, kMAX_MP_TOKEN_AMOUNT); }); } else { - constexpr bool alwaysFalse = !std::is_same_v; - static_assert(alwaysFalse, "Unsupported type for toMaxAmount"); + constexpr bool kALWAYS_FALSE = !std::is_same_v; + static_assert(kALWAYS_FALSE, "Unsupported type for toMaxAmount"); } } inline STAmount -toSTAmount(Asset const& asset, Number const& n, Number::rounding_mode mode = Number::getround()) +toSTAmount(Asset const& asset, Number const& n, Number::RoundingMode mode = Number::getround()) { return toAmount(asset, n, mode); } @@ -233,8 +233,8 @@ getAsset(T const& amt) } else { - constexpr bool alwaysFalse = !std::is_same_v; - static_assert(alwaysFalse, "Unsupported type for getIssue"); + constexpr bool kALWAYS_FALSE = !std::is_same_v; + static_assert(kALWAYS_FALSE, "Unsupported type for getIssue"); } } @@ -260,8 +260,8 @@ get(STAmount const& a) } else { - constexpr bool alwaysFalse = !std::is_same_v; - static_assert(alwaysFalse, "Unsupported type for get"); + constexpr bool kALWAYS_FALSE = !std::is_same_v; + static_assert(kALWAYS_FALSE, "Unsupported type for get"); } } diff --git a/include/xrpl/protocol/ApiVersion.h b/include/xrpl/protocol/ApiVersion.h index 653b4830bf..41bffd5f85 100644 --- a/include/xrpl/protocol/ApiVersion.h +++ b/include/xrpl/protocol/ApiVersion.h @@ -35,49 +35,49 @@ namespace xrpl { namespace RPC { template -constexpr static std::integral_constant apiVersion = {}; +constexpr static std::integral_constant kAPI_VERSION = {}; -constexpr static auto apiInvalidVersion = apiVersion<0>; -constexpr static auto apiMinimumSupportedVersion = apiVersion<1>; -constexpr static auto apiMaximumSupportedVersion = apiVersion<2>; -constexpr static auto apiVersionIfUnspecified = apiVersion<1>; -constexpr static auto apiCommandLineVersion = apiVersion<1>; // TODO Bump to 2 later -constexpr static auto apiBetaVersion = apiVersion<3>; -constexpr static auto apiMaximumValidVersion = apiBetaVersion; +constexpr static auto kAPI_INVALID_VERSION = kAPI_VERSION<0>; +constexpr static auto kAPI_MINIMUM_SUPPORTED_VERSION = kAPI_VERSION<1>; +constexpr static auto kAPI_MAXIMUM_SUPPORTED_VERSION = kAPI_VERSION<2>; +constexpr static auto kAPI_VERSION_IF_UNSPECIFIED = kAPI_VERSION<1>; +constexpr static auto kAPI_COMMAND_LINE_VERSION = kAPI_VERSION<1>; // TODO Bump to 2 later +constexpr static auto kAPI_BETA_VERSION = kAPI_VERSION<3>; +constexpr static auto kAPI_MAXIMUM_VALID_VERSION = kAPI_BETA_VERSION; -static_assert(apiInvalidVersion < apiMinimumSupportedVersion); +static_assert(kAPI_INVALID_VERSION < kAPI_MINIMUM_SUPPORTED_VERSION); static_assert( - apiVersionIfUnspecified >= apiMinimumSupportedVersion && - apiVersionIfUnspecified <= apiMaximumSupportedVersion); + kAPI_VERSION_IF_UNSPECIFIED >= kAPI_MINIMUM_SUPPORTED_VERSION && + kAPI_VERSION_IF_UNSPECIFIED <= kAPI_MAXIMUM_SUPPORTED_VERSION); static_assert( - apiCommandLineVersion >= apiMinimumSupportedVersion && - apiCommandLineVersion <= apiMaximumSupportedVersion); -static_assert(apiMaximumSupportedVersion >= apiMinimumSupportedVersion); -static_assert(apiBetaVersion >= apiMaximumSupportedVersion); -static_assert(apiMaximumValidVersion >= apiMaximumSupportedVersion); + kAPI_COMMAND_LINE_VERSION >= kAPI_MINIMUM_SUPPORTED_VERSION && + kAPI_COMMAND_LINE_VERSION <= kAPI_MAXIMUM_SUPPORTED_VERSION); +static_assert(kAPI_MAXIMUM_SUPPORTED_VERSION >= kAPI_MINIMUM_SUPPORTED_VERSION); +static_assert(kAPI_BETA_VERSION >= kAPI_MAXIMUM_SUPPORTED_VERSION); +static_assert(kAPI_MAXIMUM_VALID_VERSION >= kAPI_MAXIMUM_SUPPORTED_VERSION); inline void setVersion(Json::Value& parent, unsigned int apiVersion, bool betaEnabled) { - XRPL_ASSERT(apiVersion != apiInvalidVersion, "xrpl::RPC::setVersion : input is valid"); + XRPL_ASSERT(apiVersion != kAPI_INVALID_VERSION, "xrpl::RPC::setVersion : input is valid"); - auto& retObj = parent[jss::version] = Json::objectValue; + auto& retObj = parent[jss::kVERSION] = Json::ObjectValue; - if (apiVersion == apiVersionIfUnspecified) + if (apiVersion == kAPI_VERSION_IF_UNSPECIFIED) { // API version numbers used in API version 1 - static beast::SemanticVersion const firstVersion{"1.0.0"}; - static beast::SemanticVersion const goodVersion{"1.0.0"}; - static beast::SemanticVersion const lastVersion{"1.0.0"}; + static beast::SemanticVersion const kFIRST_VERSION{"1.0.0"}; + static beast::SemanticVersion const kGOOD_VERSION{"1.0.0"}; + static beast::SemanticVersion const kLAST_VERSION{"1.0.0"}; - retObj[jss::first] = firstVersion.print(); - retObj[jss::good] = goodVersion.print(); - retObj[jss::last] = lastVersion.print(); + retObj[jss::kFIRST] = kFIRST_VERSION.print(); + retObj[jss::kGOOD] = kGOOD_VERSION.print(); + retObj[jss::kLAST] = kLAST_VERSION.print(); } else { - retObj[jss::first] = apiMinimumSupportedVersion.value; - retObj[jss::last] = betaEnabled ? apiBetaVersion : apiMaximumSupportedVersion; + retObj[jss::kFIRST] = kAPI_MINIMUM_SUPPORTED_VERSION.value; + retObj[jss::kLAST] = betaEnabled ? kAPI_BETA_VERSION : kAPI_MAXIMUM_SUPPORTED_VERSION; } } @@ -98,63 +98,63 @@ setVersion(Json::Value& parent, unsigned int apiVersion, bool betaEnabled) inline unsigned int getAPIVersionNumber(Json::Value const& jv, bool betaEnabled) { - static Json::Value const minVersion(RPC::apiMinimumSupportedVersion); + static Json::Value const kMIN_VERSION(RPC::kAPI_MINIMUM_SUPPORTED_VERSION); Json::Value const maxVersion( - betaEnabled ? RPC::apiBetaVersion : RPC::apiMaximumSupportedVersion); + betaEnabled ? RPC::kAPI_BETA_VERSION : RPC::kAPI_MAXIMUM_SUPPORTED_VERSION); if (jv.isObject()) { - if (jv.isMember(jss::api_version)) + if (jv.isMember(jss::kAPI_VERSION)) { - auto const specifiedVersion = jv[jss::api_version]; + auto const specifiedVersion = jv[jss::kAPI_VERSION]; if (!specifiedVersion.isInt() && !specifiedVersion.isUInt()) { - return RPC::apiInvalidVersion; + return RPC::kAPI_INVALID_VERSION; } auto const specifiedVersionInt = specifiedVersion.asInt(); - if (specifiedVersionInt < minVersion || specifiedVersionInt > maxVersion) + if (specifiedVersionInt < kMIN_VERSION || specifiedVersionInt > maxVersion) { - return RPC::apiInvalidVersion; + return RPC::kAPI_INVALID_VERSION; } return specifiedVersionInt; } } - return RPC::apiVersionIfUnspecified; + return RPC::kAPI_VERSION_IF_UNSPECIFIED; } } // namespace RPC -template +template void forApiVersions(Fn const& fn, Args&&... args) - requires // - (maxVer >= minVer) && // - (minVer >= RPC::apiMinimumSupportedVersion) && // - (RPC::apiMaximumValidVersion >= maxVer) && requires { - fn(std::integral_constant{}, std::forward(args)...); - fn(std::integral_constant{}, std::forward(args)...); + requires // + (MaxVer >= MinVer) && // + (MinVer >= RPC::kAPI_MINIMUM_SUPPORTED_VERSION) && // + (RPC::kAPI_MAXIMUM_VALID_VERSION >= MaxVer) && requires { + fn(std::integral_constant{}, std::forward(args)...); + fn(std::integral_constant{}, std::forward(args)...); } { - constexpr auto size = maxVer + 1 - minVer; - [&](std::index_sequence) { + constexpr auto kSIZE = MaxVer + 1 - MinVer; + [&](std::index_sequence) { // NOLINTBEGIN(bugprone-use-after-move) (((void)fn( - std::integral_constant{}, std::forward(args)...)), + std::integral_constant{}, std::forward(args)...)), ...); // NOLINTEND(bugprone-use-after-move) - }(std::make_index_sequence{}); + }(std::make_index_sequence{}); } template void forAllApiVersions(Fn const& fn, Args&&... args) requires requires { - forApiVersions( + forApiVersions( fn, std::forward(args)...); } { - forApiVersions( + forApiVersions( fn, std::forward(args)...); } diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h index 920e62f2c4..801ea6f5bc 100644 --- a/include/xrpl/protocol/Asset.h +++ b/include/xrpl/protocol/Asset.h @@ -30,8 +30,8 @@ struct BadAsset inline BadAsset const& badAsset() { - static BadAsset const a; - return a; + static BadAsset const kA; + return kA; } /* Asset is an abstraction of three different issue types: XRP, IOU, MPT. @@ -148,10 +148,10 @@ public: }; template -constexpr bool is_issue_v = std::is_same_v; +constexpr bool kIS_ISSUE_V = std::is_same_v; template -constexpr bool is_mptissue_v = std::is_same_v; +constexpr bool kIS_MPTISSUE_V = std::is_same_v; inline Json::Value to_json(Asset const& asset) @@ -205,13 +205,13 @@ Asset::getAmountType() const { return visit( [&](Issue const& issue) -> Asset::AmtType { - constexpr AmountType xrp; - constexpr AmountType iou; - return native() ? AmtType(xrp) : AmtType(iou); + constexpr AmountType kXRP; + constexpr AmountType kIOU; + return native() ? AmtType(kXRP) : AmtType(kIOU); }, [&](MPTIssue const& issue) -> Asset::AmtType { - constexpr AmountType mpt; - return AmtType(mpt); + constexpr AmountType kMPT; + return AmtType(kMPT); }); } @@ -237,10 +237,10 @@ constexpr std::weak_ordering operator<=>(Asset const& lhs, Asset const& rhs) { return std::visit( - [](TLhs const& lhs_, TRhs const& rhs_) { + [](TLhs const& lhs, TRhs const& rhs) { if constexpr (std::is_same_v) { - return std::weak_ordering(lhs_ <=> rhs_); + return std::weak_ordering(lhs <=> rhs); } else if constexpr (is_issue_v && is_mptissue_v) { diff --git a/include/xrpl/protocol/Book.h b/include/xrpl/protocol/Book.h index cda4daf603..ebef29fddf 100644 --- a/include/xrpl/protocol/Book.h +++ b/include/xrpl/protocol/Book.h @@ -21,8 +21,8 @@ public: Book() = default; - Book(Asset const& in_, Asset const& out_, std::optional const& domain_) - : in(in_), out(out_), domain(domain_) + Book(Asset const& in, Asset const& out, std::optional const& domain) + : in(in), out(out), domain(domain) { } }; @@ -140,8 +140,8 @@ private: using issue_hasher = std::hash; using mptissue_hasher = std::hash; - issue_hasher m_issue_hasher; - mptissue_hasher m_mptissue_hasher; + issue_hasher m_issue_hasher_; + mptissue_hasher m_mptissue_hasher_; public: explicit hash() = default; @@ -151,11 +151,11 @@ public: { return asset.visit( [&](xrpl::Issue const& issue) { - value_type const result(m_issue_hasher(issue)); + value_type const result(m_issue_hasher_(issue)); return result; }, [&](xrpl::MPTIssue const& issue) { - value_type const result(m_mptissue_hasher(issue)); + value_type const result(m_mptissue_hasher_(issue)); return result; }); } @@ -170,8 +170,8 @@ private: using asset_hasher = std::hash; using uint256_hasher = xrpl::uint256::hasher; - asset_hasher m_asset_hasher; - uint256_hasher m_uint256_hasher; + asset_hasher m_asset_hasher_; + uint256_hasher m_uint256_hasher_; public: hash() = default; @@ -182,11 +182,11 @@ public: value_type operator()(argument_type const& value) const { - value_type result(m_asset_hasher(value.in)); - boost::hash_combine(result, m_asset_hasher(value.out)); + value_type result(m_asset_hasher_(value.in)); + boost::hash_combine(result, m_asset_hasher_(value.out)); if (value.domain) - boost::hash_combine(result, m_uint256_hasher(*value.domain)); + boost::hash_combine(result, m_uint256_hasher_(*value.domain)); return result; } diff --git a/include/xrpl/protocol/Concepts.h b/include/xrpl/protocol/Concepts.h index 5f2eb3c7c8..e909aff805 100644 --- a/include/xrpl/protocol/Concepts.h +++ b/include/xrpl/protocol/Concepts.h @@ -59,7 +59,7 @@ struct CombineVisitors : Ts... // robust than class template argument deduction (CTAD) via the deduction guide. template constexpr CombineVisitors...> -make_combine_visitors(Ts&&... ts) +makeCombineVisitors(Ts&&... ts) { // std::decay_t is used to remove references/constness from the lambda // types before they are passed as template arguments to the CombineVisitors @@ -74,11 +74,11 @@ constexpr auto visit(Variant&& v, Visitors&&... visitors) -> decltype(auto) { // Use the function template helper instead of raw CTAD. - auto visitor_set = make_combine_visitors(std::forward(visitors)...); + auto visitorSet = makeCombineVisitors(std::forward(visitors)...); // Delegate to std::visit, perfectly forwarding the variant and the visitor // set. - return std::visit(visitor_set, std::forward(v)); + return std::visit(visitorSet, std::forward(v)); } } // namespace detail diff --git a/include/xrpl/protocol/ErrorCodes.h b/include/xrpl/protocol/ErrorCodes.h index ed7f898312..e36a0dbdbe 100644 --- a/include/xrpl/protocol/ErrorCodes.h +++ b/include/xrpl/protocol/ErrorCodes.h @@ -19,131 +19,131 @@ namespace xrpl { // or repurpose error code values. // Protocol-wide, 50+ files // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) -enum error_code_i { +enum ErrorCodeI { // -1 represents codes not listed in this enumeration - rpcUNKNOWN = -1, + RpcUnknown = -1, - rpcSUCCESS = 0, + RpcSuccess = 0, - rpcBAD_SYNTAX = 1, - rpcJSON_RPC = 2, - rpcFORBIDDEN = 3, + RpcBadSyntax = 1, + RpcJsonRpc = 2, + RpcForbidden = 3, - rpcWRONG_NETWORK = 4, + RpcWrongNetwork = 4, // Misc failure // unused 5, - rpcNO_PERMISSION = 6, - rpcNO_EVENTS = 7, + RpcNoPermission = 6, + RpcNoEvents = 7, // unused 8, - rpcTOO_BUSY = 9, - rpcSLOW_DOWN = 10, - rpcHIGH_FEE = 11, - rpcNOT_ENABLED = 12, - rpcNOT_READY = 13, - rpcAMENDMENT_BLOCKED = 14, + RpcTooBusy = 9, + RpcSlowDown = 10, + RpcHighFee = 11, + RpcNotEnabled = 12, + RpcNotReady = 13, + RpcAmendmentBlocked = 14, // Networking - rpcNO_CLOSED = 15, - rpcNO_CURRENT = 16, - rpcNO_NETWORK = 17, - rpcNOT_SYNCED = 18, + RpcNoClosed = 15, + RpcNoCurrent = 16, + RpcNoNetwork = 17, + RpcNotSynced = 18, // Ledger state - rpcACT_NOT_FOUND = 19, + RpcActNotFound = 19, // unused 20, - rpcLGR_NOT_FOUND = 21, - rpcLGR_NOT_VALIDATED = 22, - rpcMASTER_DISABLED = 23, + RpcLgrNotFound = 21, + RpcLgrNotValidated = 22, + RpcMasterDisabled = 23, // unused 24, // unused 25, // unused 26, // unused 27, // unused 28, - rpcTXN_NOT_FOUND = 29, - rpcINVALID_HOTWALLET = 30, + RpcTxnNotFound = 29, + RpcInvalidHotwallet = 30, // Malformed command - rpcINVALID_PARAMS = 31, - rpcUNKNOWN_COMMAND = 32, - rpcNO_PF_REQUEST = 33, + RpcInvalidParams = 31, + RpcUnknownCommand = 32, + RpcNoPfRequest = 33, // Bad parameter // NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34, - rpcACT_MALFORMED = 35, - rpcALREADY_MULTISIG = 36, - rpcALREADY_SINGLE_SIG = 37, + RpcActMalformed = 35, + RpcAlreadyMultisig = 36, + RpcAlreadySingleSig = 37, // unused 38, // unused 39, - rpcBAD_FEATURE = 40, - rpcBAD_ISSUER = 41, - rpcBAD_MARKET = 42, - rpcBAD_SECRET = 43, - rpcBAD_SEED = 44, - rpcCHANNEL_MALFORMED = 45, - rpcCHANNEL_AMT_MALFORMED = 46, - rpcCOMMAND_MISSING = 47, - rpcDST_ACT_MALFORMED = 48, - rpcDST_ACT_MISSING = 49, - rpcDST_ACT_NOT_FOUND = 50, - rpcDST_AMT_MALFORMED = 51, - rpcDST_AMT_MISSING = 52, - rpcDST_ISR_MALFORMED = 53, + RpcBadFeature = 40, + RpcBadIssuer = 41, + RpcBadMarket = 42, + RpcBadSecret = 43, + RpcBadSeed = 44, + RpcChannelMalformed = 45, + RpcChannelAmtMalformed = 46, + RpcCommandMissing = 47, + RpcDstActMalformed = 48, + RpcDstActMissing = 49, + RpcDstActNotFound = 50, + RpcDstAmtMalformed = 51, + RpcDstAmtMissing = 52, + RpcDstIsrMalformed = 53, // unused 54, // unused 55, // unused 56, - rpcLGR_IDXS_INVALID = 57, - rpcLGR_IDX_MALFORMED = 58, + RpcLgrIdxsInvalid = 57, + RpcLgrIdxMalformed = 58, // unused 59, // unused 60, // unused 61, - rpcPUBLIC_MALFORMED = 62, - rpcSIGNING_MALFORMED = 63, - rpcSENDMAX_MALFORMED = 64, - rpcSRC_ACT_MALFORMED = 65, - rpcSRC_ACT_MISSING = 66, - rpcSRC_ACT_NOT_FOUND = 67, - rpcDELEGATE_ACT_NOT_FOUND = 68, - rpcSRC_CUR_MALFORMED = 69, - rpcSRC_ISR_MALFORMED = 70, - rpcSTREAM_MALFORMED = 71, - rpcATX_DEPRECATED = 72, + RpcPublicMalformed = 62, + RpcSigningMalformed = 63, + RpcSendmaxMalformed = 64, + RpcSrcActMalformed = 65, + RpcSrcActMissing = 66, + RpcSrcActNotFound = 67, + RpcDelegateActNotFound = 68, + RpcSrcCurMalformed = 69, + RpcSrcIsrMalformed = 70, + RpcStreamMalformed = 71, + RpcAtxDeprecated = 72, // Internal error (should never happen) - rpcINTERNAL = 73, // Generic internal error. - rpcNOT_IMPL = 74, - rpcNOT_SUPPORTED = 75, - rpcBAD_KEY_TYPE = 76, - rpcDB_DESERIALIZATION = 77, - rpcEXCESSIVE_LGR_RANGE = 78, - rpcINVALID_LGR_RANGE = 79, - rpcEXPIRED_VALIDATOR_LIST = 80, + RpcInternal = 73, // Generic internal error. + RpcNotImpl = 74, + RpcNotSupported = 75, + RpcBadKeyType = 76, + RpcDbDeserialization = 77, + RpcExcessiveLgrRange = 78, + RpcInvalidLgrRange = 79, + RpcExpiredValidatorList = 80, // unused = 90, // DEPRECATED. New code must not use this value. - rpcREPORTING_UNSUPPORTED = 91, + RpcReportingUnsupported = 91, - rpcOBJECT_NOT_FOUND = 92, + RpcObjectNotFound = 92, // AMM - rpcISSUE_MALFORMED = 93, + RpcIssueMalformed = 93, // Oracle - rpcORACLE_MALFORMED = 94, + RpcOracleMalformed = 94, // deposit_authorized + credentials - rpcBAD_CREDENTIALS = 95, + RpcBadCredentials = 95, // Simulate - rpcTX_SIGNED = 96, + RpcTxSigned = 96, // Pathfinding - rpcDOMAIN_MALFORMED = 97, + RpcDomainMalformed = 97, // ledger_entry - rpcENTRY_NOT_FOUND = 98, - rpcUNEXPECTED_LEDGER_TYPE = 99, + RpcEntryNotFound = 98, + RpcUnexpectedLedgerType = 99, - rpcLAST = rpcUNEXPECTED_LEDGER_TYPE // rpcLAST should always equal the last code. + RpcLast = RpcUnexpectedLedgerType // rpcLAST should always equal the last code. }; /** Codes returned in the `warnings` array of certain RPC commands. @@ -152,13 +152,13 @@ enum error_code_i { */ // Protocol-wide, 50+ files // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) -enum warning_code_i { - warnRPC_UNSUPPORTED_MAJORITY = 1001, - warnRPC_AMENDMENT_BLOCKED = 1002, - warnRPC_EXPIRED_VALIDATOR_LIST = 1003, +enum WarningCodeI { + WarnRpcUnsupportedMajority = 1001, + WarnRpcAmendmentBlocked = 1002, + WarnRpcExpiredValidatorList = 1003, // unused = 1004 - warnRPC_FIELDS_DEPRECATED = 2004, // xrpld needs to maintain - // compatibility with Clio on this code. + WarnRpcFieldsDeprecated = 2004, // xrpld needs to maintain + // compatibility with Clio on this code. }; //------------------------------------------------------------------------------ @@ -172,25 +172,21 @@ struct ErrorInfo { // Default ctor needed to produce an empty std::array during constexpr eval. constexpr ErrorInfo() - : code(rpcUNKNOWN), token("unknown"), message("An unknown error code."), http_status(200) + : code(RpcUnknown), token("unknown"), message("An unknown error code."), http_status(200) { } - constexpr ErrorInfo(error_code_i code_, char const* token_, char const* message_) - : code(code_), token(token_), message(message_), http_status(200) + constexpr ErrorInfo(ErrorCodeI code, char const* token, char const* message) + : code(code), token(token), message(message), http_status(200) { } - constexpr ErrorInfo( - error_code_i code_, - char const* token_, - char const* message_, - int http_status_) - : code(code_), token(token_), message(message_), http_status(http_status_) + constexpr ErrorInfo(ErrorCodeI code, char const* token, char const* message, int httpStatus) + : code(code), token(token), message(message), http_status(httpStatus) { } - error_code_i code; + ErrorCodeI code; Json::StaticString token; Json::StaticString message; int http_status; @@ -198,23 +194,23 @@ struct ErrorInfo /** Returns an ErrorInfo that reflects the error code. */ ErrorInfo const& -get_error_info(error_code_i code); +get_error_info(ErrorCodeI code); /** Add or update the json update to reflect the error code. */ /** @{ */ void -inject_error(error_code_i code, Json::Value& json); +inject_error(ErrorCodeI code, Json::Value& json); void -inject_error(error_code_i code, std::string const& message, Json::Value& json); +inject_error(ErrorCodeI code, std::string const& message, Json::Value& json); /** @} */ /** Returns a new json object that reflects the error code. */ /** @{ */ Json::Value -make_error(error_code_i code); +make_error(ErrorCodeI code); Json::Value -make_error(error_code_i code, std::string const& message); +make_error(ErrorCodeI code, std::string const& message); /** @} */ /** Returns a new json object that indicates invalid parameters. */ @@ -222,7 +218,7 @@ make_error(error_code_i code, std::string const& message); inline Json::Value make_param_error(std::string const& message) { - return make_error(rpcINVALID_PARAMS, message); + return make_error(RpcInvalidParams, message); } inline std::string @@ -323,7 +319,7 @@ contains_error(Json::Value const& json); /** Returns http status that corresponds to the error code. */ int -error_code_http_status(error_code_i code); +error_code_http_status(ErrorCodeI code); } // namespace RPC diff --git a/include/xrpl/protocol/Feature.h b/include/xrpl/protocol/Feature.h index 8f96935ca1..f2cc5d08b8 100644 --- a/include/xrpl/protocol/Feature.h +++ b/include/xrpl/protocol/Feature.h @@ -65,11 +65,11 @@ namespace xrpl { // Feature names must not exceed this length (in characters, excluding the null terminator). -static constexpr std::size_t maxFeatureNameSize = 63; +static constexpr std::size_t kMAX_FEATURE_NAME_SIZE = 63; // Reserve this exact feature-name length (in characters/bytes, excluding the null terminator) // so that a 32-byte uint256 (for example, in WASM or other interop contexts) can be used // as a compact, fixed-size feature selector without conflicting with human-readable names. -static constexpr std::size_t reservedFeatureNameSize = 32; +static constexpr std::size_t kRESERVED_FEATURE_NAME_SIZE = 32; // Both validFeatureNameSize and validFeatureName are consteval functions that can be used in // static_asserts to validate feature names at compile time. They are only used inside @@ -79,27 +79,27 @@ static constexpr std::size_t reservedFeatureNameSize = 32; consteval auto validFeatureNameSize(auto fn) -> bool { - constexpr char const* n = fn(); + constexpr char const* kN = fn(); // Note, std::strlen is not constexpr, we need to implement our own here. - constexpr std::size_t N = [](auto n) { + constexpr std::size_t kN = [](auto n) { std::size_t ret = 0; for (auto ptr = n; *ptr != '\0'; ret++, ++ptr) ; return ret; - }(n); - return N != reservedFeatureNameSize && // - N <= maxFeatureNameSize; + }(kN); + return kN != kRESERVED_FEATURE_NAME_SIZE && // + kN <= kMAX_FEATURE_NAME_SIZE; } consteval auto validFeatureName(auto fn) -> bool { - constexpr char const* n = fn(); + constexpr char const* kN = fn(); // Prevent the use of visually confusable characters and enforce that feature names // are always valid ASCII. This is needed because C++ allows Unicode identifiers. // Characters below 0x20 are nonprintable control characters, and characters with the 0x80 bit // set are non-ASCII (e.g. UTF-8 encoding of Unicode), so both are disallowed. - for (auto ptr = n; *ptr != '\0'; ++ptr) + for (auto ptr = kN; *ptr != '\0'; ++ptr) { if (*ptr & 0x80 || *ptr < 0x20) return false; @@ -136,7 +136,7 @@ namespace detail { // Feature.cpp. Because it's only used to reserve storage, and determine how // large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than // the actual number of amendments. A LogicError on startup will verify this. -static constexpr std::size_t numFeatures = +static constexpr std::size_t kNUM_FEATURES = (0 + #include ); @@ -184,9 +184,9 @@ bitsetIndexToFeature(size_t i); std::string featureToName(uint256 const& f); -class FeatureBitset : private std::bitset +class FeatureBitset : private std::bitset { - using base = std::bitset; + using base = std::bitset; template void diff --git a/include/xrpl/protocol/Fees.h b/include/xrpl/protocol/Fees.h index 6c398735ad..c94ba31b8a 100644 --- a/include/xrpl/protocol/Fees.h +++ b/include/xrpl/protocol/Fees.h @@ -6,7 +6,7 @@ namespace xrpl { // Deprecated constant for backwards compatibility with pre-XRPFees amendment. // This was the reference fee units used in the old fee calculation. -inline constexpr std::uint32_t FEE_UNITS_DEPRECATED = 10; +inline constexpr std::uint32_t kFEE_UNITS_DEPRECATED = 10; /** Reflects the fee settings for a particular ledger. @@ -29,8 +29,8 @@ struct Fees Fees& operator=(Fees const&) = default; - Fees(XRPAmount base_, XRPAmount reserve_, XRPAmount increment_) - : base(base_), reserve(reserve_), increment(increment_) + Fees(XRPAmount base, XRPAmount reserve, XRPAmount increment) + : base(base), reserve(reserve), increment(increment) { } diff --git a/include/xrpl/protocol/HashPrefix.h b/include/xrpl/protocol/HashPrefix.h index 305b4bfd49..1b05d450a1 100644 --- a/include/xrpl/protocol/HashPrefix.h +++ b/include/xrpl/protocol/HashPrefix.h @@ -9,7 +9,7 @@ namespace xrpl { namespace detail { constexpr std::uint32_t -make_hash_prefix(char a, char b, char c) +makeHashPrefix(char a, char b, char c) { return (static_cast(a) << 24) + (static_cast(b) << 16) + (static_cast(c) << 8); @@ -33,40 +33,40 @@ make_hash_prefix(char a, char b, char c) */ enum class HashPrefix : std::uint32_t { /** transaction plus signature to give transaction ID */ - transactionID = detail::make_hash_prefix('T', 'X', 'N'), + TransactionId = detail::makeHashPrefix('T', 'X', 'N'), /** transaction plus metadata */ - txNode = detail::make_hash_prefix('S', 'N', 'D'), + TxNode = detail::makeHashPrefix('S', 'N', 'D'), /** account state */ - leafNode = detail::make_hash_prefix('M', 'L', 'N'), + LeafNode = detail::makeHashPrefix('M', 'L', 'N'), /** inner node in V1 tree */ - innerNode = detail::make_hash_prefix('M', 'I', 'N'), + InnerNode = detail::makeHashPrefix('M', 'I', 'N'), /** ledger master data for signing */ - ledgerMaster = detail::make_hash_prefix('L', 'W', 'R'), + LedgerMaster = detail::makeHashPrefix('L', 'W', 'R'), /** inner transaction to sign */ - txSign = detail::make_hash_prefix('S', 'T', 'X'), + TxSign = detail::makeHashPrefix('S', 'T', 'X'), /** inner transaction to multi-sign */ - txMultiSign = detail::make_hash_prefix('S', 'M', 'T'), + TxMultiSign = detail::makeHashPrefix('S', 'M', 'T'), /** validation for signing */ - validation = detail::make_hash_prefix('V', 'A', 'L'), + Validation = detail::makeHashPrefix('V', 'A', 'L'), /** proposal for signing */ - proposal = detail::make_hash_prefix('P', 'R', 'P'), + Proposal = detail::makeHashPrefix('P', 'R', 'P'), /** Manifest */ - manifest = detail::make_hash_prefix('M', 'A', 'N'), + Manifest = detail::makeHashPrefix('M', 'A', 'N'), /** Payment Channel Claim */ - paymentChannelClaim = detail::make_hash_prefix('C', 'L', 'M'), + PaymentChannelClaim = detail::makeHashPrefix('C', 'L', 'M'), /** Batch */ - batch = detail::make_hash_prefix('B', 'C', 'H'), + Batch = detail::makeHashPrefix('B', 'C', 'H'), }; template diff --git a/include/xrpl/protocol/IOUAmount.h b/include/xrpl/protocol/IOUAmount.h index 5a03de6650..fd6e432de5 100644 --- a/include/xrpl/protocol/IOUAmount.h +++ b/include/xrpl/protocol/IOUAmount.h @@ -92,7 +92,7 @@ public: inline IOUAmount::IOUAmount(beast::Zero) { - *this = beast::zero; + *this = beast::kZERO; } inline IOUAmount::IOUAmount(mantissa_type mantissa, exponent_type exponent) diff --git a/include/xrpl/protocol/Indexes.h b/include/xrpl/protocol/Indexes.h index f4dd5e6816..817eeed5a0 100644 --- a/include/xrpl/protocol/Indexes.h +++ b/include/xrpl/protocol/Indexes.h @@ -75,14 +75,14 @@ Keylet const& negativeUNL() noexcept; /** The beginning of an order book */ -struct book_t +struct BookT { - explicit book_t() = default; + explicit BookT() = default; Keylet operator()(Book const& b) const; }; -static book_t const book{}; +static BookT const kBOOK{}; /** The index of a trust line for a given currency @@ -119,19 +119,19 @@ Keylet quality(Keylet const& k, std::uint64_t q) noexcept; /** The directory for the next lower quality */ -struct next_t +struct NextT { - explicit next_t() = default; + explicit NextT() = default; Keylet operator()(Keylet const& k) const; }; -static next_t const next{}; +static NextT const kNEXT{}; /** A ticket belonging to an account */ -struct ticket_t +struct TicketT { - explicit ticket_t() = default; + explicit TicketT() = default; Keylet operator()(AccountID const& id, std::uint32_t ticketSeq) const; @@ -145,7 +145,7 @@ struct ticket_t return {ltTICKET, key}; } }; -static ticket_t const ticket{}; +static TicketT const kTICKET{}; /** A SignerList */ Keylet @@ -362,18 +362,18 @@ getTicketIndex(AccountID const& account, std::uint32_t uSequence); uint256 getTicketIndex(AccountID const& account, SeqProxy ticketSeq); -template +template // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) -struct keyletDesc +struct KeyletDesc { - std::function function; + std::function function; Json::StaticString expectedLEName; bool includeInTests{}; }; // This list should include all of the keylet functions that take a single // AccountID parameter. -std::array, 6> const directAccountKeylets{ +std::array, 6> const kDIRECT_ACCOUNT_KEYLETS{ {{.function = &keylet::account, .expectedLEName = jss::AccountRoot, .includeInTests = false}, {.function = &keylet::ownerDir, .expectedLEName = jss::DirectoryNode, .includeInTests = true}, {.function = &keylet::signers, .expectedLEName = jss::SignerList, .includeInTests = true}, diff --git a/include/xrpl/protocol/Issue.h b/include/xrpl/protocol/Issue.h index fa9c4ebd1f..39213b8528 100644 --- a/include/xrpl/protocol/Issue.h +++ b/include/xrpl/protocol/Issue.h @@ -96,16 +96,16 @@ operator<=>(Issue const& lhs, Issue const& rhs) inline Issue const& xrpIssue() { - static Issue const issue{xrpCurrency(), xrpAccount()}; - return issue; + static Issue const kISSUE{xrpCurrency(), xrpAccount()}; + return kISSUE; } /** Returns an asset specifier that represents no account and currency. */ inline Issue const& noIssue() { - static Issue const issue{noCurrency(), noAccount()}; - return issue; + static Issue const kISSUE{noCurrency(), noAccount()}; + return kISSUE; } inline bool diff --git a/include/xrpl/protocol/KeyType.h b/include/xrpl/protocol/KeyType.h index d05e421e4b..c709eb897a 100644 --- a/include/xrpl/protocol/KeyType.h +++ b/include/xrpl/protocol/KeyType.h @@ -6,18 +6,18 @@ namespace xrpl { enum class KeyType { - secp256k1 = 0, - ed25519 = 1, + Secp256k1 = 0, + Ed25519 = 1, }; inline std::optional keyTypeFromString(std::string const& s) { if (s == "secp256k1") - return KeyType::secp256k1; + return KeyType::Secp256k1; if (s == "ed25519") - return KeyType::ed25519; + return KeyType::Ed25519; return {}; } @@ -25,10 +25,10 @@ keyTypeFromString(std::string const& s) inline char const* to_string(KeyType type) { - if (type == KeyType::secp256k1) + if (type == KeyType::Secp256k1) return "secp256k1"; - if (type == KeyType::ed25519) + if (type == KeyType::Ed25519) return "ed25519"; return "INVALID"; diff --git a/include/xrpl/protocol/Keylet.h b/include/xrpl/protocol/Keylet.h index 6795516795..19704e2a11 100644 --- a/include/xrpl/protocol/Keylet.h +++ b/include/xrpl/protocol/Keylet.h @@ -20,7 +20,7 @@ struct Keylet uint256 key; LedgerEntryType type; - Keylet(LedgerEntryType type_, uint256 const& key_) : key(key_), type(type_) + Keylet(LedgerEntryType type, uint256 const& key) : key(key), type(type) { } diff --git a/include/xrpl/protocol/LedgerFormats.h b/include/xrpl/protocol/LedgerFormats.h index 77ef9fcf1d..7fec4cdf33 100644 --- a/include/xrpl/protocol/LedgerFormats.h +++ b/include/xrpl/protocol/LedgerFormats.h @@ -53,7 +53,7 @@ enum LedgerEntryType : std::uint16_t { \sa keylet::unchecked */ - ltANY = 0, + LtAny = 0, /** A special type, matching any ledger type except directory nodes. @@ -65,7 +65,7 @@ enum LedgerEntryType : std::uint16_t { \sa keylet::child */ - ltCHILD = 0x1CD2, + LtChild = 0x1CD2, //--------------------------------------------------------------------------- /** A legacy, deprecated type. @@ -74,7 +74,7 @@ enum LedgerEntryType : std::uint16_t { Support for this type of object was never implemented. No objects of this type were ever created. */ - ltNICKNAME [[deprecated("This object type is not supported and should not be used.")]] = 0x006e, + LtNickname [[deprecated("This object type is not supported and should not be used.")]] = 0x006e, /** A legacy, deprecated type. @@ -82,7 +82,7 @@ enum LedgerEntryType : std::uint16_t { Support for this type of object was never implemented. No objects of this type were ever created. */ - ltCONTRACT [[deprecated("This object type is not supported and should not be used.")]] = 0x0063, + LtContract [[deprecated("This object type is not supported and should not be used.")]] = 0x0063, /** A legacy, deprecated type. @@ -90,7 +90,7 @@ enum LedgerEntryType : std::uint16_t { Support for this type of object was never implemented. No objects of this type were ever created. */ - ltGENERATOR_MAP [[deprecated("This object type is not supported and should not be used.")]] = + LtGeneratorMap [[deprecated("This object type is not supported and should not be used.")]] = 0x0067, }; @@ -123,85 +123,85 @@ enum LedgerEntryType : std::uint16_t { #define XMACRO(LEDGER_OBJECT, LSF_FLAG, LSF_FLAG2) \ LEDGER_OBJECT(AccountRoot, \ - LSF_FLAG(lsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \ - LSF_FLAG(lsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \ - LSF_FLAG(lsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \ - LSF_FLAG(lsfDisallowXRP, 0x00080000) /* True, to disallow sending XRP. */ \ - LSF_FLAG(lsfDisableMaster, 0x00100000) /* True, force regular key */ \ - LSF_FLAG(lsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \ - LSF_FLAG(lsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \ - LSF_FLAG(lsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \ - LSF_FLAG(lsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \ - LSF_FLAG(lsfDisallowIncomingNFTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \ - LSF_FLAG(lsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \ - LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \ - LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \ - LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \ - LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \ + LSF_FLAG(LsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \ + LSF_FLAG(LsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \ + LSF_FLAG(LsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \ + LSF_FLAG(LsfDisallowXrp, 0x00080000) /* True, to disallow sending XRP. */ \ + LSF_FLAG(LsfDisableMaster, 0x00100000) /* True, force regular key */ \ + LSF_FLAG(LsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \ + LSF_FLAG(LsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \ + LSF_FLAG(LsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \ + LSF_FLAG(LsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \ + LSF_FLAG(LsfDisallowIncomingNfTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \ + LSF_FLAG(LsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \ + LSF_FLAG(LsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \ + LSF_FLAG(LsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \ + LSF_FLAG(LsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \ + LSF_FLAG(LsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \ \ LEDGER_OBJECT(Offer, \ - LSF_FLAG(lsfPassive, 0x00010000) \ - LSF_FLAG(lsfSell, 0x00020000) /* True, offer was placed as a sell. */ \ - LSF_FLAG(lsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \ + LSF_FLAG(LsfPassive, 0x00010000) \ + LSF_FLAG(LsfSell, 0x00020000) /* True, offer was placed as a sell. */ \ + LSF_FLAG(LsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \ \ LEDGER_OBJECT(RippleState, \ - LSF_FLAG(lsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \ - LSF_FLAG(lsfHighReserve, 0x00020000) \ - LSF_FLAG(lsfLowAuth, 0x00040000) \ - LSF_FLAG(lsfHighAuth, 0x00080000) \ - LSF_FLAG(lsfLowNoRipple, 0x00100000) \ - LSF_FLAG(lsfHighNoRipple, 0x00200000) \ - LSF_FLAG(lsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \ - LSF_FLAG(lsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \ - LSF_FLAG(lsfAMMNode, 0x01000000) /* True, trust line to AMM. */ \ + LSF_FLAG(LsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \ + LSF_FLAG(LsfHighReserve, 0x00020000) \ + LSF_FLAG(LsfLowAuth, 0x00040000) \ + LSF_FLAG(LsfHighAuth, 0x00080000) \ + LSF_FLAG(LsfLowNoRipple, 0x00100000) \ + LSF_FLAG(LsfHighNoRipple, 0x00200000) \ + LSF_FLAG(LsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \ + LSF_FLAG(LsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \ + LSF_FLAG(LsfAmmNode, 0x01000000) /* True, trust line to AMM. */ \ /* Used by client apps to identify payments via AMM. */ \ - LSF_FLAG(lsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \ - LSF_FLAG(lsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \ + LSF_FLAG(LsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \ + LSF_FLAG(LsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \ \ LEDGER_OBJECT(SignerList, \ - LSF_FLAG(lsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \ + LSF_FLAG(LsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \ \ LEDGER_OBJECT(DirNode, \ - LSF_FLAG(lsfNFTokenBuyOffers, 0x00000001) \ - LSF_FLAG(lsfNFTokenSellOffers, 0x00000002)) \ + LSF_FLAG(LsfNfTokenBuyOffers, 0x00000001) \ + LSF_FLAG(LsfNfTokenSellOffers, 0x00000002)) \ \ LEDGER_OBJECT(NFTokenOffer, \ - LSF_FLAG(lsfSellNFToken, 0x00000001)) \ + LSF_FLAG(LsfSellNfToken, 0x00000001)) \ \ LEDGER_OBJECT(MPTokenIssuance, \ - LSF_FLAG(lsfMPTLocked, 0x00000001) /* Also used in ltMPTOKEN */ \ - LSF_FLAG(lsfMPTCanLock, 0x00000002) \ - LSF_FLAG(lsfMPTRequireAuth, 0x00000004) \ - LSF_FLAG(lsfMPTCanEscrow, 0x00000008) \ - LSF_FLAG(lsfMPTCanTrade, 0x00000010) \ - LSF_FLAG(lsfMPTCanTransfer, 0x00000020) \ - LSF_FLAG(lsfMPTCanClawback, 0x00000040)) \ + LSF_FLAG(LsfMptLocked, 0x00000001) /* Also used in ltMPTOKEN */ \ + LSF_FLAG(LsfMptCanLock, 0x00000002) \ + LSF_FLAG(LsfMptRequireAuth, 0x00000004) \ + LSF_FLAG(LsfMptCanEscrow, 0x00000008) \ + LSF_FLAG(LsfMptCanTrade, 0x00000010) \ + LSF_FLAG(LsfMptCanTransfer, 0x00000020) \ + LSF_FLAG(LsfMptCanClawback, 0x00000040)) \ \ LEDGER_OBJECT(MPTokenIssuanceMutable, \ - LSF_FLAG(lsmfMPTCanMutateCanLock, 0x00000002) \ - LSF_FLAG(lsmfMPTCanMutateRequireAuth, 0x00000004) \ - LSF_FLAG(lsmfMPTCanMutateCanEscrow, 0x00000008) \ - LSF_FLAG(lsmfMPTCanMutateCanTrade, 0x00000010) \ - LSF_FLAG(lsmfMPTCanMutateCanTransfer, 0x00000020) \ - LSF_FLAG(lsmfMPTCanMutateCanClawback, 0x00000040) \ - LSF_FLAG(lsmfMPTCanMutateMetadata, 0x00010000) \ - LSF_FLAG(lsmfMPTCanMutateTransferFee, 0x00020000)) \ + LSF_FLAG(LsmfMptCanMutateCanLock, 0x00000002) \ + LSF_FLAG(LsmfMptCanMutateRequireAuth, 0x00000004) \ + LSF_FLAG(LsmfMptCanMutateCanEscrow, 0x00000008) \ + LSF_FLAG(LsmfMptCanMutateCanTrade, 0x00000010) \ + LSF_FLAG(LsmfMptCanMutateCanTransfer, 0x00000020) \ + LSF_FLAG(LsmfMptCanMutateCanClawback, 0x00000040) \ + LSF_FLAG(LsmfMptCanMutateMetadata, 0x00010000) \ + LSF_FLAG(LsmfMptCanMutateTransferFee, 0x00020000)) \ \ LEDGER_OBJECT(MPToken, \ LSF_FLAG2(lsfMPTLocked, 0x00000001) \ - LSF_FLAG(lsfMPTAuthorized, 0x00000002) \ - LSF_FLAG(lsfMPTAMM, 0x00000004)) \ + LSF_FLAG(LsfMptAuthorized, 0x00000002) \ + LSF_FLAG(LsfMptamm, 0x00000004)) \ \ LEDGER_OBJECT(Credential, \ - LSF_FLAG(lsfAccepted, 0x00010000)) \ + LSF_FLAG(LsfAccepted, 0x00010000)) \ \ LEDGER_OBJECT(Vault, \ - LSF_FLAG(lsfVaultPrivate, 0x00010000)) \ + LSF_FLAG(LsfVaultPrivate, 0x00010000)) \ \ LEDGER_OBJECT(Loan, \ - LSF_FLAG(lsfLoanDefault, 0x00010000) \ - LSF_FLAG(lsfLoanImpaired, 0x00020000) \ - LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */ + LSF_FLAG(LsfLoanDefault, 0x00010000) \ + LSF_FLAG(LsfLoanImpaired, 0x00020000) \ + LSF_FLAG(LsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */ // clang-format on @@ -256,9 +256,9 @@ XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP) inline std::vector> const& getAllLedgerFlags() { - static std::vector> const flags = { + static std::vector> const kFLAGS = { XMACRO(ALL_LEDGER_FLAGS, NULL_OUTPUT, NULL_OUTPUT)}; - return flags; + return kFLAGS; } #undef XMACRO diff --git a/include/xrpl/protocol/LedgerHeader.h b/include/xrpl/protocol/LedgerHeader.h index 1035e5e892..68dd5e24b9 100644 --- a/include/xrpl/protocol/LedgerHeader.h +++ b/include/xrpl/protocol/LedgerHeader.h @@ -26,12 +26,12 @@ struct LedgerHeader // // Closed means "tx set already determined" - uint256 hash = beast::zero; - uint256 txHash = beast::zero; - uint256 accountHash = beast::zero; - uint256 parentHash = beast::zero; + uint256 hash = beast::kZERO; + uint256 txHash = beast::kZERO; + uint256 accountHash = beast::kZERO; + uint256 parentHash = beast::kZERO; - XRPAmount drops = beast::zero; + XRPAmount drops = beast::kZERO; // If validated is false, it means "not yet validated." // Once validated is true, it will never be set false at a later time. @@ -53,12 +53,12 @@ struct LedgerHeader }; // ledger close flags -static std::uint32_t const sLCF_NoConsensusTime = 0x01; +static std::uint32_t const kS_LCF_NO_CONSENSUS_TIME = 0x01; inline bool getCloseAgree(LedgerHeader const& info) { - return (info.closeFlags & sLCF_NoConsensusTime) == 0; + return (info.closeFlags & kS_LCF_NO_CONSENSUS_TIME) == 0; } void diff --git a/include/xrpl/protocol/MPTAmount.h b/include/xrpl/protocol/MPTAmount.h index 9d0e0901bf..b4907774d2 100644 --- a/include/xrpl/protocol/MPTAmount.h +++ b/include/xrpl/protocol/MPTAmount.h @@ -88,7 +88,7 @@ constexpr MPTAmount::MPTAmount(value_type value) : value_(value) constexpr MPTAmount::MPTAmount(beast::Zero) { - *this = beast::zero; + *this = beast::kZERO; } constexpr MPTAmount& diff --git a/include/xrpl/protocol/MPTIssue.h b/include/xrpl/protocol/MPTIssue.h index c467382f07..e841a9cd4f 100644 --- a/include/xrpl/protocol/MPTIssue.h +++ b/include/xrpl/protocol/MPTIssue.h @@ -102,15 +102,15 @@ getMPTIssuer(MPTID&&) = delete; inline MPTID noMPT() { - static MPTIssue const mpt{0, noAccount()}; - return mpt.getMptID(); + static MPTIssue const kMPT{0, noAccount()}; + return kMPT.getMptID(); } inline MPTID badMPT() { - static MPTIssue const mpt{0, xrpAccount()}; - return mpt.getMptID(); + static MPTIssue const kMPT{0, xrpAccount()}; + return kMPT.getMptID(); } template diff --git a/include/xrpl/protocol/PathAsset.h b/include/xrpl/protocol/PathAsset.h index 67b78f2191..9927a66293 100644 --- a/include/xrpl/protocol/PathAsset.h +++ b/include/xrpl/protocol/PathAsset.h @@ -52,10 +52,10 @@ public: }; template -constexpr bool is_currency_v = std::is_same_v; +constexpr bool kIS_CURRENCY_V = std::is_same_v; template -constexpr bool is_mptid_v = std::is_same_v; +constexpr bool kIS_MPTID_V = std::is_same_v; inline PathAsset::PathAsset(Asset const& asset) { @@ -98,10 +98,10 @@ constexpr bool operator==(PathAsset const& lhs, PathAsset const& rhs) { return std::visit( - [](TLhs const& lhs_, TRhs const& rhs_) { + [](TLhs const& lhs, TRhs const& rhs) { if constexpr (std::is_same_v) { - return lhs_ == rhs_; + return lhs == rhs; } else { diff --git a/include/xrpl/protocol/Permissions.h b/include/xrpl/protocol/Permissions.h index 3ce8918a16..5d56fa4461 100644 --- a/include/xrpl/protocol/Permissions.h +++ b/include/xrpl/protocol/Permissions.h @@ -33,7 +33,7 @@ enum GranularPermissionType : std::uint32_t { // Injected bare enumerators (xrpl::delegable / xrpl::notDelegable) are required by preprocessor // tricks in tests and macro-generated code; enum class would break that. // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) -enum Delegation { delegable, notDelegable }; +enum Delegation { Delegable, NotDelegable }; class Permission { diff --git a/include/xrpl/protocol/Protocol.h b/include/xrpl/protocol/Protocol.h index 0db7b217f0..50b2425016 100644 --- a/include/xrpl/protocol/Protocol.h +++ b/include/xrpl/protocol/Protocol.h @@ -19,40 +19,40 @@ namespace xrpl { @ingroup protocol */ /** Smallest legal byte size of a transaction. */ -std::size_t constexpr txMinSizeBytes = 32; +std::size_t constexpr kTX_MIN_SIZE_BYTES = 32; /** Largest legal byte size of a transaction. */ -std::size_t constexpr txMaxSizeBytes = megabytes(1); +std::size_t constexpr kTX_MAX_SIZE_BYTES = megabytes(1); /** The maximum number of unfunded offers to delete at once */ -std::size_t constexpr unfundedOfferRemoveLimit = 1000; +std::size_t constexpr kUNFUNDED_OFFER_REMOVE_LIMIT = 1000; /** The maximum number of expired offers to delete at once */ -std::size_t constexpr expiredOfferRemoveLimit = 256; +std::size_t constexpr kEXPIRED_OFFER_REMOVE_LIMIT = 256; /** The maximum number of metadata entries allowed in one transaction */ -std::size_t constexpr oversizeMetaDataCap = 5200; +std::size_t constexpr kOVERSIZE_META_DATA_CAP = 5200; /** The maximum number of entries per directory page */ -std::size_t constexpr dirNodeMaxEntries = 32; +std::size_t constexpr kDIR_NODE_MAX_ENTRIES = 32; /** The maximum number of pages allowed in a directory Made obsolete by fixDirectoryLimit amendment. */ -std::uint64_t constexpr dirNodeMaxPages = 262144; +std::uint64_t constexpr kDIR_NODE_MAX_PAGES = 262144; /** The maximum number of items in an NFT page */ -std::size_t constexpr dirMaxTokensPerPage = 32; +std::size_t constexpr kDIR_MAX_TOKENS_PER_PAGE = 32; /** The maximum number of owner directory entries for account to be deletable */ -std::size_t constexpr maxDeletableDirEntries = 1000; +std::size_t constexpr kMAX_DELETABLE_DIR_ENTRIES = 1000; /** The maximum number of token offers that can be canceled at once */ -std::size_t constexpr maxTokenOfferCancelCount = 500; +std::size_t constexpr kMAX_TOKEN_OFFER_CANCEL_COUNT = 500; /** The maximum number of offers in an offer directory for NFT to be burnable */ -std::size_t constexpr maxDeletableTokenOfferEntries = 500; +std::size_t constexpr kMAX_DELETABLE_TOKEN_OFFER_ENTRIES = 500; /** The maximum token transfer fee allowed. @@ -63,7 +63,7 @@ std::size_t constexpr maxDeletableTokenOfferEntries = 500; Note that for extremely low transfer fees values, it is possible that the calculated fee will be 0. */ -std::uint16_t constexpr maxTransferFee = 50000; +std::uint16_t constexpr kMAX_TRANSFER_FEE = 50000; /** There are 10,000 basis points (bips) in 100%. * @@ -81,32 +81,32 @@ std::uint16_t constexpr maxTransferFee = 50000; * * Example: 50% is 0.50 * bipsPerUnity = 5,000 bps. */ -Bips32 constexpr bipsPerUnity(100 * 100); -static_assert(bipsPerUnity == Bips32{10'000}); -TenthBips32 constexpr tenthBipsPerUnity(bipsPerUnity.value() * 10); -static_assert(tenthBipsPerUnity == TenthBips32(100'000)); +Bips32 constexpr kBIPS_PER_UNITY(100 * 100); +static_assert(kBIPS_PER_UNITY == Bips32{10'000}); +TenthBips32 constexpr kTENTH_BIPS_PER_UNITY(kBIPS_PER_UNITY.value() * 10); +static_assert(kTENTH_BIPS_PER_UNITY == TenthBips32(100'000)); constexpr Bips32 percentageToBips(std::uint32_t percentage) { - return Bips32(percentage * bipsPerUnity.value() / 100); + return Bips32(percentage * kBIPS_PER_UNITY.value() / 100); } constexpr TenthBips32 percentageToTenthBips(std::uint32_t percentage) { - return TenthBips32(percentage * tenthBipsPerUnity.value() / 100); + return TenthBips32(percentage * kTENTH_BIPS_PER_UNITY.value() / 100); } template constexpr T bipsOfValue(T value, Bips bips) { - return value * bips.value() / bipsPerUnity.value(); + return value * bips.value() / kBIPS_PER_UNITY.value(); } template constexpr T tenthBipsOfValue(T value, TenthBips bips) { - return value * bips.value() / tenthBipsPerUnity.value(); + return value * bips.value() / kTENTH_BIPS_PER_UNITY.value(); } namespace Lending { @@ -114,54 +114,54 @@ namespace Lending { Valid values are between 0 and 10% inclusive. */ -TenthBips16 constexpr maxManagementFeeRate( - unsafe_cast(percentageToTenthBips(10).value())); -static_assert(maxManagementFeeRate == TenthBips16(std::uint16_t(10'000u))); +TenthBips16 constexpr kMAX_MANAGEMENT_FEE_RATE( + unsafeCast(percentageToTenthBips(10).value())); +static_assert(kMAX_MANAGEMENT_FEE_RATE == TenthBips16(std::uint16_t(10'000u))); /** The maximum coverage rate required of a loan broker in 1/10 bips. Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxCoverRate = percentageToTenthBips(100); -static_assert(maxCoverRate == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_COVER_RATE = percentageToTenthBips(100); +static_assert(kMAX_COVER_RATE == TenthBips32(100'000u)); /** The maximum overpayment fee on a loan in 1/10 bips. * Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxOverpaymentFee = percentageToTenthBips(100); -static_assert(maxOverpaymentFee == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_OVERPAYMENT_FEE = percentageToTenthBips(100); +static_assert(kMAX_OVERPAYMENT_FEE == TenthBips32(100'000u)); /** Annualized interest rate of the Loan in 1/10 bips. * * Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxInterestRate = percentageToTenthBips(100); -static_assert(maxInterestRate == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_INTEREST_RATE = percentageToTenthBips(100); +static_assert(kMAX_INTEREST_RATE == TenthBips32(100'000u)); /** The maximum premium added to the interest rate for late payments on a loan * in 1/10 bips. * * Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxLateInterestRate = percentageToTenthBips(100); -static_assert(maxLateInterestRate == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_LATE_INTEREST_RATE = percentageToTenthBips(100); +static_assert(kMAX_LATE_INTEREST_RATE == TenthBips32(100'000u)); /** The maximum close interest rate charged for repaying a loan early in 1/10 * bips. * * Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxCloseInterestRate = percentageToTenthBips(100); -static_assert(maxCloseInterestRate == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_CLOSE_INTEREST_RATE = percentageToTenthBips(100); +static_assert(kMAX_CLOSE_INTEREST_RATE == TenthBips32(100'000u)); /** The maximum overpayment interest rate charged on loan overpayments in 1/10 * bips. * * Valid values are between 0 and 100% inclusive. */ -TenthBips32 constexpr maxOverpaymentInterestRate = percentageToTenthBips(100); -static_assert(maxOverpaymentInterestRate == TenthBips32(100'000u)); +TenthBips32 constexpr kMAX_OVERPAYMENT_INTEREST_RATE = percentageToTenthBips(100); +static_assert(kMAX_OVERPAYMENT_INTEREST_RATE == TenthBips32(100'000u)); /** LoanPay transaction cost will be one base fee per X combined payments * @@ -172,7 +172,7 @@ static_assert(maxOverpaymentInterestRate == TenthBips32(100'000u)); * This number was chosen arbitrarily, but should not be changed once released * without an amendment */ -static constexpr int loanPaymentsPerFeeIncrement = 5; +static constexpr int kLOAN_PAYMENTS_PER_FEE_INCREMENT = 5; /** Maximum number of combined payments that a LoanPay transaction will process * @@ -196,65 +196,65 @@ static constexpr int loanPaymentsPerFeeIncrement = 5; * This number was chosen arbitrarily, but should not be changed once released * without an amendment */ -static constexpr int loanMaximumPaymentsPerTransaction = 100; +static constexpr int kLOAN_MAXIMUM_PAYMENTS_PER_TRANSACTION = 100; } // namespace Lending /** The maximum length of a URI inside an NFT */ -std::size_t constexpr maxTokenURILength = 256; +std::size_t constexpr kMAX_TOKEN_URI_LENGTH = 256; /** The maximum length of a Data element inside a DID */ -std::size_t constexpr maxDIDDocumentLength = 256; +std::size_t constexpr kMAX_DID_DOCUMENT_LENGTH = 256; /** The maximum length of a URI inside a DID */ -std::size_t constexpr maxDIDURILength = 256; +std::size_t constexpr kMAX_DIDURI_LENGTH = 256; /** The maximum length of an Attestation inside a DID */ -std::size_t constexpr maxDIDDataLength = 256; +std::size_t constexpr kMAX_DID_DATA_LENGTH = 256; /** The maximum length of a domain */ -std::size_t constexpr maxDomainLength = 256; +std::size_t constexpr kMAX_DOMAIN_LENGTH = 256; /** The maximum length of a URI inside a Credential */ -std::size_t constexpr maxCredentialURILength = 256; +std::size_t constexpr kMAX_CREDENTIAL_URI_LENGTH = 256; /** The maximum length of a CredentialType inside a Credential */ -std::size_t constexpr maxCredentialTypeLength = 64; +std::size_t constexpr kMAX_CREDENTIAL_TYPE_LENGTH = 64; /** The maximum number of credentials can be passed in array */ -std::size_t constexpr maxCredentialsArraySize = 8; +std::size_t constexpr kMAX_CREDENTIALS_ARRAY_SIZE = 8; /** The maximum number of credentials can be passed in array for permissioned * domain */ -std::size_t constexpr maxPermissionedDomainCredentialsArraySize = 10; +std::size_t constexpr kMAX_PERMISSIONED_DOMAIN_CREDENTIALS_ARRAY_SIZE = 10; /** The maximum length of MPTokenMetadata */ -std::size_t constexpr maxMPTokenMetadataLength = 1024; +std::size_t constexpr kMAX_MP_TOKEN_METADATA_LENGTH = 1024; /** The maximum amount of MPTokenIssuance */ -std::uint64_t constexpr maxMPTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull; -static_assert(Number::maxRep >= maxMPTokenAmount); +std::uint64_t constexpr kMAX_MP_TOKEN_AMOUNT = 0x7FFF'FFFF'FFFF'FFFFull; +static_assert(Number::kMAX_REP >= kMAX_MP_TOKEN_AMOUNT); /** The maximum length of Data payload */ -std::size_t constexpr maxDataPayloadLength = 256; +std::size_t constexpr kMAX_DATA_PAYLOAD_LENGTH = 256; /** Vault withdrawal policies */ -std::uint8_t constexpr vaultStrategyFirstComeFirstServe = 1; +std::uint8_t constexpr kVAULT_STRATEGY_FIRST_COME_FIRST_SERVE = 1; /** Default IOU scale factor for a Vault */ -std::uint8_t constexpr vaultDefaultIOUScale = 6; +std::uint8_t constexpr kVAULT_DEFAULT_IOU_SCALE = 6; /** Maximum scale factor for a Vault. The number is chosen to ensure that 1 IOU can be always converted to shares. 10^19 > maxMPTokenAmount (2^64-1) > 10^18 */ -std::uint8_t constexpr vaultMaximumIOUScale = 18; +std::uint8_t constexpr kVAULT_MAXIMUM_IOU_SCALE = 18; /** Maximum recursion depth for vault shares being put as an asset inside * another vault; counted from 0 */ -std::uint8_t constexpr maxAssetCheckDepth = 5; +std::uint8_t constexpr kMAX_ASSET_CHECK_DEPTH = 5; /** A ledger index. */ using LedgerIndex = std::uint32_t; -std::uint32_t constexpr FLAG_LEDGER_INTERVAL = 256; +std::uint32_t constexpr kFLAG_LEDGER_INTERVAL = 256; /** Returns true if the given ledgerIndex is a voting ledgerIndex */ bool @@ -273,38 +273,38 @@ using TxID = uint256; /** The maximum number of trustlines to delete as part of AMM account * deletion cleanup. */ -std::uint16_t constexpr maxDeletableAMMTrustLines = 512; +std::uint16_t constexpr kMAX_DELETABLE_AMM_TRUST_LINES = 512; /** The maximum length of a URI inside an Oracle */ -std::size_t constexpr maxOracleURI = 256; +std::size_t constexpr kMAX_ORACLE_URI = 256; /** The maximum length of a Provider inside an Oracle */ -std::size_t constexpr maxOracleProvider = 256; +std::size_t constexpr kMAX_ORACLE_PROVIDER = 256; /** The maximum size of a data series array inside an Oracle */ -std::size_t constexpr maxOracleDataSeries = 10; +std::size_t constexpr kMAX_ORACLE_DATA_SERIES = 10; /** The maximum length of a SymbolClass inside an Oracle */ -std::size_t constexpr maxOracleSymbolClass = 16; +std::size_t constexpr kMAX_ORACLE_SYMBOL_CLASS = 16; /** The maximum allowed time difference between lastUpdateTime and the time of the last closed ledger */ -std::size_t constexpr maxLastUpdateTimeDelta = 300; +std::size_t constexpr kMAX_LAST_UPDATE_TIME_DELTA = 300; /** The maximum price scaling factor */ -std::size_t constexpr maxPriceScale = 20; +std::size_t constexpr kMAX_PRICE_SCALE = 20; /** The maximum percentage of outliers to trim */ -std::size_t constexpr maxTrim = 25; +std::size_t constexpr kMAX_TRIM = 25; /** The maximum number of delegate permissions an account can grant */ -std::size_t constexpr permissionMaxSize = 10; +std::size_t constexpr kPERMISSION_MAX_SIZE = 10; /** The maximum number of transactions that can be in a batch. */ -std::size_t constexpr maxBatchTxCount = 8; +std::size_t constexpr kMAX_BATCH_TX_COUNT = 8; } // namespace xrpl diff --git a/include/xrpl/protocol/PublicKey.h b/include/xrpl/protocol/PublicKey.h index 9ec82dde97..85133e5952 100644 --- a/include/xrpl/protocol/PublicKey.h +++ b/include/xrpl/protocol/PublicKey.h @@ -43,8 +43,8 @@ class PublicKey protected: // All the constructed public keys are valid, non-empty and contain 33 // bytes of data. - static constexpr std::size_t size_ = 33; - std::uint8_t buf_[size_]{}; // should be large enough + static constexpr std::size_t kSIZE = 33; + std::uint8_t buf_[kSIZE]{}; // should be large enough public: using const_iterator = std::uint8_t const*; @@ -72,7 +72,7 @@ public: static std::size_t size() noexcept { - return size_; + return kSIZE; } [[nodiscard]] const_iterator @@ -90,19 +90,19 @@ public: [[nodiscard]] const_iterator end() const noexcept { - return buf_ + size_; + return buf_ + kSIZE; } [[nodiscard]] const_iterator cend() const noexcept { - return buf_ + size_; + return buf_ + kSIZE; } [[nodiscard]] Slice slice() const noexcept { - return {buf_, size_}; + return {buf_, kSIZE}; } operator Slice() const noexcept @@ -168,7 +168,7 @@ template <> std::optional parseBase58(TokenType type, std::string const& s); -enum class ECDSACanonicality { canonical, fullyCanonical }; +enum class ECDSACanonicality { Canonical, FullyCanonical }; /** Determines the canonicality of a signature. diff --git a/include/xrpl/protocol/Quality.h b/include/xrpl/protocol/Quality.h index 2d4ea2f652..d7258eddd3 100644 --- a/include/xrpl/protocol/Quality.h +++ b/include/xrpl/protocol/Quality.h @@ -26,11 +26,11 @@ struct TAmounts { TAmounts() = default; - TAmounts(beast::Zero, beast::Zero) : in(beast::zero), out(beast::zero) + TAmounts(beast::Zero, beast::Zero) : in(beast::kZERO), out(beast::kZERO) { } - TAmounts(In in_, Out out_) : in(std::move(in_)), out(std::move(out_)) + TAmounts(In in, Out out) : in(std::move(in)), out(std::move(out)) { } @@ -38,7 +38,7 @@ struct TAmounts [[nodiscard]] bool empty() const noexcept { - return in <= beast::zero || out <= beast::zero; + return in <= beast::kZERO || out <= beast::kZERO; } TAmounts& @@ -94,15 +94,15 @@ public: // have lower unsigned integer representations. using value_type = std::uint64_t; - static int const minTickSize = 3; - static int const maxTickSize = 16; + static int const kMIN_TICK_SIZE = 3; + static int const kMAX_TICK_SIZE = 16; private: // This has the same representation as STAmount, see the comment on the // STAmount. However, this class does not always use the canonical // representation. In particular, the increment and decrement operators may // cause a non-canonical representation. - value_type m_value; + value_type m_value_; public: Quality() = default; @@ -148,7 +148,7 @@ public: [[nodiscard]] STAmount rate() const { - return amountFromQuality(m_value); + return amountFromQuality(m_value_); } /** Returns the quality rounded up to the specified number @@ -162,42 +162,42 @@ public: to prevent money creation. */ [[nodiscard]] Amounts - ceil_in(Amounts const& amount, STAmount const& limit) const; + ceilIn(Amounts const& amount, STAmount const& limit) const; template [[nodiscard]] TAmounts - ceil_in(TAmounts const& amount, In const& limit) const; + ceilIn(TAmounts const& amount, In const& limit) const; // Some of the underlying rounding functions called by ceil_in() ignored // low order bits that could influence rounding decisions. This "strict" // method uses underlying functions that pay attention to all the bits. [[nodiscard]] Amounts - ceil_in_strict(Amounts const& amount, STAmount const& limit, bool roundUp) const; + ceilInStrict(Amounts const& amount, STAmount const& limit, bool roundUp) const; template [[nodiscard]] TAmounts - ceil_in_strict(TAmounts const& amount, In const& limit, bool roundUp) const; + ceilInStrict(TAmounts const& amount, In const& limit, bool roundUp) const; /** Returns the scaled amount with out capped. Math is avoided if the result is exact. The input is clamped to prevent money creation. */ [[nodiscard]] Amounts - ceil_out(Amounts const& amount, STAmount const& limit) const; + ceilOut(Amounts const& amount, STAmount const& limit) const; template [[nodiscard]] TAmounts - ceil_out(TAmounts const& amount, Out const& limit) const; + ceilOut(TAmounts const& amount, Out const& limit) const; // Some of the underlying rounding functions called by ceil_out() ignored // low order bits that could influence rounding decisions. This "strict" // method uses underlying functions that pay attention to all the bits. [[nodiscard]] Amounts - ceil_out_strict(Amounts const& amount, STAmount const& limit, bool roundUp) const; + ceilOutStrict(Amounts const& amount, STAmount const& limit, bool roundUp) const; template [[nodiscard]] TAmounts - ceil_out_strict(TAmounts const& amount, Out const& limit, bool roundUp) const; + ceilOutStrict(TAmounts const& amount, Out const& limit, bool roundUp) const; private: // The ceil_in and ceil_out methods that deal in TAmount all convert @@ -205,11 +205,11 @@ private: // This helper function takes care of all the conversion operations. template ... Round> [[nodiscard]] TAmounts - ceil_TAmounts_helper( + ceilTAmountsHelper( TAmounts const& amount, Lim const& limit, - Lim const& limit_cmp, - FnPtr ceil_function, + Lim const& limitCmp, + FnPtr ceilFunction, Round... round) const; public: @@ -220,13 +220,13 @@ public: friend bool operator<(Quality const& lhs, Quality const& rhs) noexcept { - return lhs.m_value > rhs.m_value; + return lhs.m_value_ > rhs.m_value_; } friend bool operator>(Quality const& lhs, Quality const& rhs) noexcept { - return lhs.m_value < rhs.m_value; + return lhs.m_value_ < rhs.m_value_; } friend bool @@ -244,7 +244,7 @@ public: friend bool operator==(Quality const& lhs, Quality const& rhs) noexcept { - return lhs.m_value == rhs.m_value; + return lhs.m_value_ == rhs.m_value_; } friend bool @@ -256,7 +256,7 @@ public: friend std::ostream& operator<<(std::ostream& os, Quality const& quality) { - os << quality.m_value; + os << quality.m_value_; return os; } @@ -266,12 +266,12 @@ public: relativeDistance(Quality const& q1, Quality const& q2) { XRPL_ASSERT( - q1.m_value > 0 && q2.m_value > 0, "xrpl::Quality::relativeDistance : minimum inputs"); + q1.m_value_ > 0 && q2.m_value_ > 0, "xrpl::Quality::relativeDistance : minimum inputs"); - if (q1.m_value == q2.m_value) // make expected common case fast + if (q1.m_value_ == q2.m_value_) // make expected common case fast return 0; - auto const [minV, maxV] = std::minmax(q1.m_value, q2.m_value); + auto const [minV, maxV] = std::minmax(q1.m_value_, q2.m_value_); auto mantissa = [](std::uint64_t rate) { return rate & ~(255ull << (64 - 8)); }; auto exponent = [](std::uint64_t rate) { return static_cast(rate >> (64 - 8)) - 100; }; @@ -293,66 +293,66 @@ public: template ... Round> TAmounts -Quality::ceil_TAmounts_helper( +Quality::ceilTAmountsHelper( TAmounts const& amount, Lim const& limit, - Lim const& limit_cmp, - FnPtr ceil_function, + Lim const& limitCmp, + FnPtr ceilFunction, Round... roundUp) const { - if (limit_cmp <= limit) + if (limitCmp <= limit) return amount; // Use the existing STAmount implementation for now, but consider // replacing with code specific to IOUAMount and XRPAmount Amounts const stAmt(toSTAmount(amount.in), toSTAmount(amount.out)); STAmount const stLim(toSTAmount(limit)); - Amounts const stRes = ((*this).*ceil_function)(stAmt, stLim, roundUp...); + Amounts const stRes = ((*this).*ceilFunction)(stAmt, stLim, roundUp...); return TAmounts(toAmount(stRes.in), toAmount(stRes.out)); } template TAmounts -Quality::ceil_in(TAmounts const& amount, In const& limit) const +Quality::ceilIn(TAmounts const& amount, In const& limit) const { // Construct a function pointer to the function we want to call. - static constexpr Amounts (Quality::*ceil_in_fn_ptr)(Amounts const&, STAmount const&) const = - &Quality::ceil_in; + static constexpr Amounts (Quality::*kCEIL_IN_FN_PTR)(Amounts const&, STAmount const&) const = + &Quality::ceilIn; - return ceil_TAmounts_helper(amount, limit, amount.in, ceil_in_fn_ptr); + return ceil_TAmounts_helper(amount, limit, amount.in, kCEIL_IN_FN_PTR); } template TAmounts -Quality::ceil_in_strict(TAmounts const& amount, In const& limit, bool roundUp) const +Quality::ceilInStrict(TAmounts const& amount, In const& limit, bool roundUp) const { // Construct a function pointer to the function we want to call. - static constexpr Amounts (Quality::*ceil_in_fn_ptr)(Amounts const&, STAmount const&, bool) - const = &Quality::ceil_in_strict; + static constexpr Amounts (Quality::*kCEIL_IN_FN_PTR)(Amounts const&, STAmount const&, bool) + const = &Quality::ceilInStrict; - return ceil_TAmounts_helper(amount, limit, amount.in, ceil_in_fn_ptr, roundUp); + return ceil_TAmounts_helper(amount, limit, amount.in, kCEIL_IN_FN_PTR, roundUp); } template TAmounts -Quality::ceil_out(TAmounts const& amount, Out const& limit) const +Quality::ceilOut(TAmounts const& amount, Out const& limit) const { // Construct a function pointer to the function we want to call. - static constexpr Amounts (Quality::*ceil_out_fn_ptr)(Amounts const&, STAmount const&) const = - &Quality::ceil_out; + static constexpr Amounts (Quality::*kCEIL_OUT_FN_PTR)(Amounts const&, STAmount const&) const = + &Quality::ceilOut; - return ceil_TAmounts_helper(amount, limit, amount.out, ceil_out_fn_ptr); + return ceil_TAmounts_helper(amount, limit, amount.out, kCEIL_OUT_FN_PTR); } template TAmounts -Quality::ceil_out_strict(TAmounts const& amount, Out const& limit, bool roundUp) const +Quality::ceilOutStrict(TAmounts const& amount, Out const& limit, bool roundUp) const { // Construct a function pointer to the function we want to call. - static constexpr Amounts (Quality::*ceil_out_fn_ptr)(Amounts const&, STAmount const&, bool) - const = &Quality::ceil_out_strict; + static constexpr Amounts (Quality::*kCEIL_OUT_FN_PTR)(Amounts const&, STAmount const&, bool) + const = &Quality::ceilOutStrict; - return ceil_TAmounts_helper(amount, limit, amount.out, ceil_out_fn_ptr, roundUp); + return ceil_TAmounts_helper(amount, limit, amount.out, kCEIL_OUT_FN_PTR, roundUp); } /** Calculate the quality of a two-hop path given the two hops. diff --git a/include/xrpl/protocol/QualityFunction.h b/include/xrpl/protocol/QualityFunction.h index 672c529c38..f7f92e50da 100644 --- a/include/xrpl/protocol/QualityFunction.h +++ b/include/xrpl/protocol/QualityFunction.h @@ -72,7 +72,7 @@ QualityFunction::QualityFunction( std::uint32_t tfee, QualityFunction::AMMTag) { - if (amounts.in <= beast::zero || amounts.out <= beast::zero) + if (amounts.in <= beast::kZERO || amounts.out <= beast::kZERO) Throw("QualityFunction amounts are 0."); Number const cfee = feeMult(tfee); m_ = -cfee / amounts.in; diff --git a/include/xrpl/protocol/Rate.h b/include/xrpl/protocol/Rate.h index e57d7e3a99..5dcd62a295 100644 --- a/include/xrpl/protocol/Rate.h +++ b/include/xrpl/protocol/Rate.h @@ -72,6 +72,6 @@ transferFeeAsRate(std::uint16_t fee); } // namespace nft /** A transfer rate signifying a 1:1 exchange */ -extern Rate const parityRate; +extern Rate const kPARITY_RATE; } // namespace xrpl diff --git a/include/xrpl/protocol/Rules.h b/include/xrpl/protocol/Rules.h index 604bb24700..fbbd3d8805 100644 --- a/include/xrpl/protocol/Rules.h +++ b/include/xrpl/protocol/Rules.h @@ -56,7 +56,7 @@ public: These are the rules reflected by the genesis ledger. */ - explicit Rules(std::unordered_set> const& presets); + explicit Rules(std::unordered_set> const& presets); private: // Allow a friend function to construct Rules. @@ -66,14 +66,14 @@ private: friend Rules makeRulesGivenLedger( DigestAwareReadView const& ledger, - std::unordered_set> const& presets); + std::unordered_set> const& presets); Rules( - std::unordered_set> const& presets, + std::unordered_set> const& presets, std::optional const& digest, STVector256 const& amendments); - [[nodiscard]] std::unordered_set> const& + [[nodiscard]] std::unordered_set> const& presets() const; public: diff --git a/include/xrpl/protocol/SField.h b/include/xrpl/protocol/SField.h index 784de5511e..e6de4bd4fe 100644 --- a/include/xrpl/protocol/SField.h +++ b/include/xrpl/protocol/SField.h @@ -39,45 +39,45 @@ class STCurrency; #define XMACRO(STYPE) \ /* special types */ \ - STYPE(STI_UNKNOWN, -2) \ - STYPE(STI_NOTPRESENT, 0) \ - STYPE(STI_UINT16, 1) \ + STYPE(StiUnknown, -2) \ + STYPE(StiNotpresent, 0) \ + STYPE(StiUinT16, 1) \ \ /* types (common) */ \ - STYPE(STI_UINT32, 2) \ - STYPE(STI_UINT64, 3) \ - STYPE(STI_UINT128, 4) \ - STYPE(STI_UINT256, 5) \ - STYPE(STI_AMOUNT, 6) \ - STYPE(STI_VL, 7) \ - STYPE(STI_ACCOUNT, 8) \ - STYPE(STI_NUMBER, 9) \ - STYPE(STI_INT32, 10) \ - STYPE(STI_INT64, 11) \ + STYPE(StiUinT32, 2) \ + STYPE(StiUinT64, 3) \ + STYPE(StiUinT128, 4) \ + STYPE(StiUinT256, 5) \ + STYPE(StiAmount, 6) \ + STYPE(StiVl, 7) \ + STYPE(StiAccount, 8) \ + STYPE(StiNumber, 9) \ + STYPE(StiInT32, 10) \ + STYPE(StiInT64, 11) \ \ /* 12-13 are reserved */ \ - STYPE(STI_OBJECT, 14) \ - STYPE(STI_ARRAY, 15) \ + STYPE(StiObject, 14) \ + STYPE(StiArray, 15) \ \ /* types (uncommon) */ \ - STYPE(STI_UINT8, 16) \ - STYPE(STI_UINT160, 17) \ - STYPE(STI_PATHSET, 18) \ - STYPE(STI_VECTOR256, 19) \ - STYPE(STI_UINT96, 20) \ - STYPE(STI_UINT192, 21) \ - STYPE(STI_UINT384, 22) \ - STYPE(STI_UINT512, 23) \ - STYPE(STI_ISSUE, 24) \ - STYPE(STI_XCHAIN_BRIDGE, 25) \ - STYPE(STI_CURRENCY, 26) \ + STYPE(StiUinT8, 16) \ + STYPE(StiUinT160, 17) \ + STYPE(StiPathset, 18) \ + STYPE(StiVectoR256, 19) \ + STYPE(StiUinT96, 20) \ + STYPE(StiUinT192, 21) \ + STYPE(StiUinT384, 22) \ + STYPE(StiUinT512, 23) \ + STYPE(StiIssue, 24) \ + STYPE(StiXchainBridge, 25) \ + STYPE(StiCurrency, 26) \ \ /* high-level types */ \ /* cannot be serialized inside other types */ \ - STYPE(STI_TRANSACTION, 10001) \ - STYPE(STI_LEDGERENTRY, 10002) \ - STYPE(STI_VALIDATION, 10003) \ - STYPE(STI_METADATA, 10004) + STYPE(StiTransaction, 10001) \ + STYPE(StiLedgerentry, 10002) \ + STYPE(StiValidation, 10003) \ + STYPE(StiMetadata, 10004) #pragma push_macro("TO_ENUM") #undef TO_ENUM @@ -91,7 +91,7 @@ class STCurrency; // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum SerializedTypeID { XMACRO(TO_ENUM) }; -static std::map const sTypeMap = {XMACRO(TO_MAP)}; +static std::map const kS_TYPE_MAP = {XMACRO(TO_MAP)}; #undef XMACRO #undef TO_ENUM @@ -104,7 +104,7 @@ static std::map const sTypeMap = {XMACRO(TO_MAP)}; inline int field_code(SerializedTypeID id, int index) { - return (safe_cast(id) << 16) | index; + return (safeCast(id) << 16) | index; } // constexpr @@ -130,23 +130,23 @@ public: // Need to be named before converting // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum { - sMD_Never = 0x00, - sMD_ChangeOrig = 0x01, // original value when it changes - sMD_ChangeNew = 0x02, // new value when it changes - sMD_DeleteFinal = 0x04, // final value when it is deleted - sMD_Create = 0x08, // value when it's created - sMD_Always = 0x10, // value when node containing it is affected at all - sMD_BaseTen = 0x20, // value is treated as base 10, overriding behavior - sMD_PseudoAccount = 0x40, // if this field is set in an ACCOUNT_ROOT - // _only_, then it is a pseudo-account - sMD_NeedsAsset = 0x80, // This field needs to be associated with an - // asset before it is serialized as a ledger - // object. Intended for STNumber. - sMD_Default = sMD_ChangeOrig | sMD_ChangeNew | sMD_DeleteFinal | sMD_Create + SMdNever = 0x00, + SMdChangeOrig = 0x01, // original value when it changes + SMdChangeNew = 0x02, // new value when it changes + SMdDeleteFinal = 0x04, // final value when it is deleted + SMdCreate = 0x08, // value when it's created + SMdAlways = 0x10, // value when node containing it is affected at all + SMdBaseTen = 0x20, // value is treated as base 10, overriding behavior + SMdPseudoAccount = 0x40, // if this field is set in an ACCOUNT_ROOT + // _only_, then it is a pseudo-account + SMdNeedsAsset = 0x80, // This field needs to be associated with an + // asset before it is serialized as a ledger + // object. Intended for STNumber. + SMdDefault = SMdChangeOrig | SMdChangeNew | SMdDeleteFinal | SMdCreate }; - enum class IsSigning : unsigned char { no, yes }; - static IsSigning const notSigning = IsSigning::no; + enum class IsSigning : unsigned char { No, Yes }; + static IsSigning const kNOT_SIGNING = IsSigning::No; int const fieldCode; // (type<<16)|index SerializedTypeID const fieldType; // STI_* @@ -173,8 +173,8 @@ public: SerializedTypeID tid, int fv, char const* fn, - int meta = sMD_Default, - IsSigning signing = IsSigning::yes); + int meta = SMdDefault, + IsSigning signing = IsSigning::Yes); explicit SField(private_access_tag_t, int fc, char const* fn); static SField const& @@ -269,7 +269,7 @@ public: [[nodiscard]] bool shouldInclude(bool withSigningField) const { - return (fieldValue < 256) && (withSigningField || (signingField == IsSigning::yes)); + return (fieldValue < 256) && (withSigningField || (signingField == IsSigning::Yes)); } bool @@ -315,7 +315,7 @@ struct OptionaledField { TypedField const* f; - explicit OptionaledField(TypedField const& f_) : f(&f_) + explicit OptionaledField(TypedField const& f) : f(&f) { } }; @@ -366,8 +366,8 @@ using SF_XCHAIN_BRIDGE = TypedField; #define UNTYPED_SFIELD(sfName, stiSuffix, fieldValue, ...) extern SField const sfName; #define TYPED_SFIELD(sfName, stiSuffix, fieldValue, ...) extern SF_##stiSuffix const sfName; -extern SField const sfInvalid; -extern SField const sfGeneric; +extern SField const kSF_INVALID; +extern SField const kSF_GENERIC; #include diff --git a/include/xrpl/protocol/SOTemplate.h b/include/xrpl/protocol/SOTemplate.h index 3bfe07d049..624f1974a5 100644 --- a/include/xrpl/protocol/SOTemplate.h +++ b/include/xrpl/protocol/SOTemplate.h @@ -14,17 +14,17 @@ namespace xrpl { // 2026 usages, 129 files // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum SOEStyle { - soeINVALID = -1, - soeREQUIRED = 0, // required - soeOPTIONAL = 1, // optional, may be present with default value - soeDEFAULT = 2, // optional, if present, must not have default value + SoeInvalid = -1, + SoeRequired = 0, // required + SoeOptional = 1, // optional, may be present with default value + SoeDefault = 2, // optional, if present, must not have default value // inner object with the default fields has to be // constructed with STObject::makeInnerObject() }; // Part of a Python-parsed DSL (transactions.macro); bare enumerator names required by the parser // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) -enum SOETxMPTIssue { soeMPTNone, soeMPTSupported, soeMPTNotSupported }; +enum SOETxMPTIssue { SoeMptNone, SoeMptSupported, SoeMptNotSupported }; //------------------------------------------------------------------------------ @@ -34,7 +34,7 @@ class SOElement // Use std::reference_wrapper so SOElement can be stored in a std::vector. std::reference_wrapper sField_; SOEStyle style_; - SOETxMPTIssue supportMpt_ = soeMPTNone; + SOETxMPTIssue supportMpt_ = SoeMptNone; private: void @@ -60,7 +60,7 @@ public: SOElement( TypedField const& fieldName, SOEStyle style, - SOETxMPTIssue supportMpt = soeMPTNotSupported) + SOETxMPTIssue supportMpt = SoeMptNotSupported) : sField_(fieldName), style_(style), supportMpt_(supportMpt) { init(fieldName); diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index f681f811b7..aa68bf7690 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -34,39 +34,39 @@ public: using rep = std::pair; private: - Asset mAsset; - mantissa_type mValue{}; - exponent_type mOffset; - bool mIsNegative{}; + Asset mAsset_; + mantissa_type mValue_{}; + exponent_type mOffset_; + bool mIsNegative_{}; public: using value_type = STAmount; - constexpr static int cMinOffset = -96; - constexpr static int cMaxOffset = 80; + constexpr static int kC_MIN_OFFSET = -96; + constexpr static int kC_MAX_OFFSET = 80; // Maximum native value supported by the code - constexpr static std::uint64_t cMinValue = 1'000'000'000'000'000ull; - static_assert(isPowerOfTen(cMinValue)); - constexpr static std::uint64_t cMaxValue = (cMinValue * 10) - 1; - static_assert(cMaxValue == 9'999'999'999'999'999ull); - constexpr static std::uint64_t cMaxNative = 9'000'000'000'000'000'000ull; + constexpr static std::uint64_t kC_MIN_VALUE = 1'000'000'000'000'000ull; + static_assert(isPowerOfTen(kC_MIN_VALUE)); + constexpr static std::uint64_t kC_MAX_VALUE = (kC_MIN_VALUE * 10) - 1; + static_assert(kC_MAX_VALUE == 9'999'999'999'999'999ull); + constexpr static std::uint64_t kC_MAX_NATIVE = 9'000'000'000'000'000'000ull; // Max native value on network. - constexpr static std::uint64_t cMaxNativeN = 100'000'000'000'000'000ull; - constexpr static std::uint64_t cIssuedCurrency = 0x8'000'000'000'000'000ull; - constexpr static std::uint64_t cPositive = 0x4'000'000'000'000'000ull; - constexpr static std::uint64_t cMPToken = 0x2'000'000'000'000'000ull; - constexpr static std::uint64_t cValueMask = ~(cPositive | cMPToken); + constexpr static std::uint64_t kC_MAX_NATIVE_N = 100'000'000'000'000'000ull; + constexpr static std::uint64_t kC_ISSUED_CURRENCY = 0x8'000'000'000'000'000ull; + constexpr static std::uint64_t kC_POSITIVE = 0x4'000'000'000'000'000ull; + constexpr static std::uint64_t kC_MP_TOKEN = 0x2'000'000'000'000'000ull; + constexpr static std::uint64_t kC_VALUE_MASK = ~(kC_POSITIVE | kC_MP_TOKEN); - static std::uint64_t const uRateOne; + static std::uint64_t const kU_RATE_ONE; //-------------------------------------------------------------------------- STAmount(SerialIter& sit, SField const& name); - struct unchecked + struct Unchecked { - explicit unchecked() = default; + explicit Unchecked() = default; }; // Do not call canonicalize @@ -77,7 +77,7 @@ public: mantissa_type mantissa, exponent_type exponent, bool negative, - unchecked); + Unchecked); template STAmount( @@ -85,7 +85,7 @@ public: mantissa_type mantissa, exponent_type exponent, bool negative, - unchecked); + Unchecked); // Call canonicalize template @@ -106,7 +106,7 @@ public: template STAmount(A const& asset, std::uint64_t mantissa = 0, int exponent = 0, bool negative = false) - : mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) + : mAsset_(asset), mValue_(mantissa), mOffset_(exponent), mIsNegative_(negative) { canonicalize(); } @@ -241,7 +241,7 @@ public: [[nodiscard]] std::string getText() const override; - [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::none) const override; + [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::None) const override; void add(Serializer& s) const override; @@ -293,8 +293,8 @@ STAmount::STAmount( mantissa_type mantissa, exponent_type exponent, bool negative, - unchecked) - : STBase(name), mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) + Unchecked) + : STBase(name), mAsset_(asset), mValue_(mantissa), mOffset_(exponent), mIsNegative_(negative) { } @@ -304,8 +304,8 @@ STAmount::STAmount( mantissa_type mantissa, exponent_type exponent, bool negative, - unchecked) - : mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) + Unchecked) + : mAsset_(asset), mValue_(mantissa), mOffset_(exponent), mIsNegative_(negative) { } @@ -316,19 +316,19 @@ STAmount::STAmount( std::uint64_t mantissa, int exponent, bool negative) - : STBase(name), mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) + : STBase(name), mAsset_(asset), mValue_(mantissa), mOffset_(exponent), mIsNegative_(negative) { // mValue is uint64, but needs to fit in the range of int64 - if (Number::getMantissaScale() == MantissaRange::mantissa_scale::small) + if (Number::getMantissaScale() == MantissaRange::MantissaScale::Small) { XRPL_ASSERT( - mValue <= std::numeric_limits::max(), + mValue_ <= std::numeric_limits::max(), "xrpl::STAmount::STAmount(SField, A, std::uint64_t, int, bool) : " "maximum mantissa input"); } else { - if (integral() && mValue > std::numeric_limits::max()) + if (integral() && mValue_ > std::numeric_limits::max()) throw std::overflow_error("STAmount mantissa is too large " + std::to_string(mantissa)); } canonicalize(); @@ -336,7 +336,7 @@ STAmount::STAmount( template STAmount::STAmount(A const& asset, std::int64_t mantissa, int exponent) - : mAsset(asset), mOffset(exponent) + : mAsset_(asset), mOffset_(exponent) { set(mantissa); canonicalize(); @@ -344,42 +344,42 @@ STAmount::STAmount(A const& asset, std::int64_t mantissa, int exponent) template STAmount::STAmount(A const& asset, std::uint32_t mantissa, int exponent, bool negative) - : STAmount(asset, safe_cast(mantissa), exponent, negative) + : STAmount(asset, safeCast(mantissa), exponent, negative) { } template STAmount::STAmount(A const& asset, int mantissa, int exponent) - : STAmount(asset, safe_cast(mantissa), exponent) + : STAmount(asset, safeCast(mantissa), exponent) { } // Legacy support for new-style amounts inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue) - : mAsset(issue), mOffset(amount.exponent()), mIsNegative(amount < beast::zero) + : mAsset_(issue), mOffset_(amount.exponent()), mIsNegative_(amount < beast::kZERO) { - if (mIsNegative) + if (mIsNegative_) { - mValue = unsafe_cast(-amount.mantissa()); + mValue_ = unsafeCast(-amount.mantissa()); } else { - mValue = unsafe_cast(amount.mantissa()); + mValue_ = unsafeCast(amount.mantissa()); } canonicalize(); } inline STAmount::STAmount(MPTAmount const& amount, MPTIssue const& mptIssue) - : mAsset(mptIssue), mOffset(0), mIsNegative(amount < beast::zero) + : mAsset_(mptIssue), mOffset_(0), mIsNegative_(amount < beast::kZERO) { - if (mIsNegative) + if (mIsNegative_) { - mValue = unsafe_cast(-amount.value()); + mValue_ = unsafeCast(-amount.value()); } else { - mValue = unsafe_cast(amount.value()); + mValue_ = unsafeCast(amount.value()); } canonicalize(); @@ -421,84 +421,84 @@ toSTAmount(STAmount const& a) inline int STAmount::exponent() const noexcept { - return mOffset; + return mOffset_; } inline bool STAmount::integral() const noexcept { - return mAsset.integral(); + return mAsset_.integral(); } inline bool STAmount::native() const noexcept { - return mAsset.native(); + return mAsset_.native(); } template constexpr bool STAmount::holds() const noexcept { - return mAsset.holds(); + return mAsset_.holds(); } inline bool STAmount::negative() const noexcept { - return mIsNegative; + return mIsNegative_; } inline std::uint64_t STAmount::mantissa() const noexcept { - return mValue; + return mValue_; } inline Asset const& STAmount::asset() const { - return mAsset; + return mAsset_; } template [[nodiscard]] constexpr TIss const& STAmount::get() const { - return mAsset.get(); + return mAsset_.get(); } template TIss& STAmount::get() { - return mAsset.get(); + return mAsset_.get(); } inline AccountID const& STAmount::getIssuer() const { - return mAsset.getIssuer(); + return mAsset_.getIssuer(); } inline int STAmount::signum() const noexcept { - if (mValue == 0u) + if (mValue_ == 0u) return 0; - return mIsNegative ? -1 : 1; + return mIsNegative_ ? -1 : 1; } inline STAmount STAmount::zeroed() const { - return STAmount(mAsset); + return STAmount(mAsset_); } inline STAmount:: operator bool() const noexcept { - return *this != beast::zero; + return *this != beast::kZERO; } inline STAmount:: @@ -540,7 +540,7 @@ STAmount::fromNumber(A const& a, Number const& number) return STAmount{asset, intValue, 0, negative}; } - auto const [mantissa, exponent] = working.normalizeToRange(cMinValue, cMaxValue); + auto const [mantissa, exponent] = working.normalizeToRange(kC_MIN_VALUE, kC_MAX_VALUE); return STAmount{asset, mantissa, exponent, negative}; } @@ -548,8 +548,8 @@ STAmount::fromNumber(A const& a, Number const& number) inline void STAmount::negate() { - if (*this != beast::zero) - mIsNegative = !mIsNegative; + if (*this != beast::kZERO) + mIsNegative_ = !mIsNegative_; } inline void @@ -557,9 +557,9 @@ STAmount::clear() { // The -100 is used to allow 0 to sort less than a small positive values // which have a negative exponent. - mOffset = integral() ? 0 : -100; - mValue = 0; - mIsNegative = false; + mOffset_ = integral() ? 0 : -100; + mValue_ = 0; + mIsNegative_ = false; } inline void @@ -578,7 +578,7 @@ STAmount::value() const noexcept inline bool isLegalNet(STAmount const& value) { - return !value.native() || (value.mantissa() <= STAmount::cMaxNativeN); + return !value.native() || (value.mantissa() <= STAmount::kC_MAX_NATIVE_N); } //------------------------------------------------------------------------------ @@ -674,7 +674,7 @@ getRate(STAmount const& offerOut, STAmount const& offerIn); roundToScale( STAmount const& value, std::int32_t scale, - Number::rounding_mode rounding = Number::getround()); + Number::RoundingMode rounding = Number::getround()); /** Round an arbitrary precision Number IN PLACE to the precision of a given * Asset. @@ -709,7 +709,7 @@ roundToAsset( A const& asset, Number const& value, std::int32_t scale, - Number::rounding_mode rounding = Number::getround()) + Number::RoundingMode rounding = Number::getround()) { NumberRoundModeGuard const mg(rounding); STAmount const ret{asset, value}; diff --git a/include/xrpl/protocol/STArray.h b/include/xrpl/protocol/STArray.h index f1ac58075b..ba9eae6a28 100644 --- a/include/xrpl/protocol/STArray.h +++ b/include/xrpl/protocol/STArray.h @@ -58,13 +58,13 @@ public: template void - emplace_back(Args&&... args); + emplaceBack(Args&&... args); void - push_back(STObject const& object); + pushBack(STObject const& object); void - push_back(STObject&& object); + pushBack(STObject&& object); iterator begin(); @@ -180,19 +180,19 @@ STArray::back() const template inline void -STArray::emplace_back(Args&&... args) +STArray::emplaceBack(Args&&... args) { v_.emplace_back(std::forward(args)...); } inline void -STArray::push_back(STObject const& object) +STArray::pushBack(STObject const& object) { v_.push_back(object); } inline void -STArray::push_back(STObject&& object) +STArray::pushBack(STObject&& object) { v_.push_back(std::move(object)); } diff --git a/include/xrpl/protocol/STBase.h b/include/xrpl/protocol/STBase.h index 7ebf22fe8f..27ae4ee28f 100644 --- a/include/xrpl/protocol/STBase.h +++ b/include/xrpl/protocol/STBase.h @@ -20,14 +20,14 @@ struct JsonOptions // Bitwise flags with operator~ // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) - enum values : underlying_t { + enum Values : underlying_t { // clang-format off - none = 0b0000'0000, - include_date = 0b0000'0001, - disable_API_prior_V2 = 0b0000'0010, + None = 0b0000'0000, + IncludeDate = 0b0000'0001, + DisableApiPriorV2 = 0b0000'0010, // IMPORTANT `_all` must be union of all of the above; see also operator~ - _all = 0b0000'0011 + All = 0b0000'0011 // clang-format on }; @@ -69,18 +69,18 @@ struct JsonOptions [[nodiscard]] constexpr JsonOptions friend operator~(JsonOptions v) noexcept { - return {~v.value & static_cast(_all)}; + return {~v.value & static_cast(All)}; } }; template requires requires(T const& t) { - { t.getJson(JsonOptions::none) } -> std::convertible_to; + { t.getJson(JsonOptions::None) } -> std::convertible_to; } Json::Value to_json(T const& t) { - return t.getJson(JsonOptions::none); + return t.getJson(JsonOptions::None); } namespace detail { @@ -115,7 +115,7 @@ class STVar; */ class STBase { - SField const* fName; + SField const* fName_; public: virtual ~STBase() = default; @@ -148,7 +148,7 @@ public: [[nodiscard]] virtual std::string getText() const; - [[nodiscard]] virtual Json::Value getJson(JsonOptions = JsonOptions::none) const; + [[nodiscard]] virtual Json::Value getJson(JsonOptions = JsonOptions::None) const; virtual void add(Serializer& s) const; diff --git a/include/xrpl/protocol/STBitString.h b/include/xrpl/protocol/STBitString.h index 6f2e08e401..292ef867f1 100644 --- a/include/xrpl/protocol/STBitString.h +++ b/include/xrpl/protocol/STBitString.h @@ -16,7 +16,7 @@ class STBitString final : public STBase, public CountedObject> static_assert(Bits > 0, "Number of bits must be positive"); public: - using value_type = base_uint; + using value_type = BaseUint; private: value_type value_{}; @@ -46,7 +46,7 @@ public: template void - setValue(base_uint const& v); + setValue(BaseUint const& v); [[nodiscard]] value_type const& value() const; @@ -106,28 +106,28 @@ template <> inline SerializedTypeID STUInt128::getSType() const { - return STI_UINT128; + return StiUinT128; } template <> inline SerializedTypeID STUInt160::getSType() const { - return STI_UINT160; + return StiUinT160; } template <> inline SerializedTypeID STUInt192::getSType() const { - return STI_UINT192; + return StiUinT192; } template <> inline SerializedTypeID STUInt256::getSType() const { - return STI_UINT256; + return StiUinT256; } template @@ -157,7 +157,7 @@ STBitString::add(Serializer& s) const template template void -STBitString::setValue(base_uint const& v) +STBitString::setValue(BaseUint const& v) { value_ = v; } @@ -180,7 +180,7 @@ template bool STBitString::isDefault() const { - return value_ == beast::zero; + return value_ == beast::kZERO; } } // namespace xrpl diff --git a/include/xrpl/protocol/STBlob.h b/include/xrpl/protocol/STBlob.h index 0667c54e30..84f44f1b78 100644 --- a/include/xrpl/protocol/STBlob.h +++ b/include/xrpl/protocol/STBlob.h @@ -24,7 +24,7 @@ public: STBlob(SField const& f, void const* data, std::size_t size); STBlob(SField const& f, Buffer&& b); STBlob(SField const& n); - STBlob(SerialIter&, SField const& name = sfGeneric); + STBlob(SerialIter&, SField const& name = kSF_GENERIC); [[nodiscard]] std::size_t size() const; diff --git a/include/xrpl/protocol/STExchange.h b/include/xrpl/protocol/STExchange.h index c733df37cf..e109119835 100644 --- a/include/xrpl/protocol/STExchange.h +++ b/include/xrpl/protocol/STExchange.h @@ -100,7 +100,7 @@ get(STObject const& st, TypedField const& f) if (!b) return t; auto const id = b->getSType(); - if (id == STI_NOTPRESENT) + if (id == StiNotpresent) return t; auto const u = dynamic_cast(b); // This should never happen diff --git a/include/xrpl/protocol/STLedgerEntry.h b/include/xrpl/protocol/STLedgerEntry.h index 2e884bc2bf..3f4156690c 100644 --- a/include/xrpl/protocol/STLedgerEntry.h +++ b/include/xrpl/protocol/STLedgerEntry.h @@ -38,7 +38,7 @@ public: getText() const override; [[nodiscard]] Json::Value - getJson(JsonOptions options = JsonOptions::none) const override; + getJson(JsonOptions options = JsonOptions::None) const override; /** Returns the 'key' (or 'index') of this item. The key identifies this entry's position in diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index 187bde6dae..3917db615a 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -57,7 +57,7 @@ class STObject : public STBase, public CountedObject using list_type = std::vector; list_type v_; - SOTemplate const* mType{}; + SOTemplate const* mType_{}; public: using iterator = boost::transform_iterator; @@ -132,7 +132,7 @@ public: getText() const override; // TODO(tom): options should be an enum. - [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::none) const override; + [[nodiscard]] Json::Value getJson(JsonOptions = JsonOptions::None) const override; void addWithoutSigningFields(Serializer& s) const; @@ -142,7 +142,7 @@ public: template std::size_t - emplace_back(Args&&... args); + emplaceBack(Args&&... args); [[nodiscard]] int getCount() const; @@ -381,7 +381,7 @@ public: template void - setFieldH160(SField const& field, base_uint<160, Tag> const& v); + setFieldH160(SField const& field, BaseUint<160, Tag> const& v); STObject& peekFieldObject(SField const& field); @@ -416,8 +416,8 @@ private: enum class WhichFields : bool { // These values are carefully chosen to do the right thing if passed // to SField::shouldInclude (bool) via static_cast - omitSigningFields = false, - withAllFields = true + OmitSigningFields = false, + WithAllFields = true }; void @@ -667,7 +667,7 @@ public: // Emulate std::optional::value_or [[nodiscard]] value_type - value_or(value_type val) const; + valueOr(value_type val) const; OptionalProxy& operator=(std::nullopt_t const&); @@ -692,7 +692,7 @@ private: disengage(); [[nodiscard]] optional_type - optional_value() const; + optionalValue() const; }; class STObject::FieldErr : public std::runtime_error @@ -703,16 +703,16 @@ class STObject::FieldErr : public std::runtime_error template STObject::Proxy::Proxy(STObject* st, TypedField const* f) : st_(st), f_(f) { - if (st_->mType != nullptr) + if (st_->mType_ != nullptr) { // STObject has associated template if (!st_->peekAtPField(*f_)) Throw("Template field error '" + this->f_->getName() + "'"); - style_ = st_->mType->style(*f_); + style_ = st_->mType_->style(*f_); } else { - style_ = soeINVALID; + style_ = SoeInvalid; } } @@ -723,11 +723,11 @@ STObject::Proxy::value() const -> value_type auto const t = find(); if (t) return t->value(); - if (style_ == soeINVALID) + if (style_ == SoeInvalid) { Throw("Value requested from invalid STObject."); } - if (style_ != soeDEFAULT) + if (style_ != SoeDefault) { Throw("Missing field '" + this->f_->getName() + "'"); } @@ -762,13 +762,13 @@ template void STObject::Proxy::assign(U&& u) { - if (style_ == soeDEFAULT && u == value_type{}) + if (style_ == SoeDefault && u == value_type{}) { st_->makeFieldAbsent(*f_); return; } T* t = nullptr; - if (style_ == soeINVALID) + if (style_ == SoeInvalid) { t = dynamic_cast(st_->getPField(*f_, true)); } @@ -836,14 +836,14 @@ template STObject::OptionalProxy:: operator typename STObject::OptionalProxy::optional_type() const { - return optional_value(); + return optionalValue(); } template typename STObject::OptionalProxy::optional_type STObject::OptionalProxy::operator~() const { - return optional_value(); + return optionalValue(); } template @@ -904,16 +904,16 @@ template bool STObject::OptionalProxy::engaged() const noexcept { - return this->style_ == soeDEFAULT || this->find() != nullptr; + return this->style_ == SoeDefault || this->find() != nullptr; } template void STObject::OptionalProxy::disengage() { - if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT) + if (this->style_ == SoeRequired || this->style_ == SoeDefault) Throw("Template field error '" + this->f_->getName() + "'"); - if (this->style_ == soeINVALID) + if (this->style_ == SoeInvalid) { this->st_->delField(*this->f_); } @@ -925,7 +925,7 @@ STObject::OptionalProxy::disengage() template auto -STObject::OptionalProxy::optional_value() const -> optional_type +STObject::OptionalProxy::optionalValue() const -> optional_type { if (!engaged()) return std::nullopt; @@ -934,7 +934,7 @@ STObject::OptionalProxy::optional_value() const -> optional_type template typename STObject::OptionalProxy::value_type -STObject::OptionalProxy::value_or(value_type val) const +STObject::OptionalProxy::valueOr(value_type val) const { return engaged() ? this->value() : val; } @@ -981,13 +981,13 @@ STObject::reserve(std::size_t n) inline bool STObject::isFree() const { - return mType == nullptr; + return mType_ == nullptr; } inline void STObject::addWithoutSigningFields(Serializer& s) const { - add(s, WhichFields::omitSigningFields); + add(s, WhichFields::OmitSigningFields); } // VFALCO NOTE does this return an expensive copy of an object with a @@ -997,13 +997,13 @@ inline Serializer STObject::getSerializer() const { Serializer s; - add(s, WhichFields::withAllFields); + add(s, WhichFields::WithAllFields); return s; } template inline std::size_t -STObject::emplace_back(Args&&... args) +STObject::emplaceBack(Args&&... args) { v_.emplace_back(std::forward(args)...); return v_.size() - 1; @@ -1082,21 +1082,21 @@ STObject::at(TypedField const& f) const if (auto const u = dynamic_cast(b)) return u->value(); - XRPL_ASSERT(mType, "xrpl::STObject::at(TypedField auto) : field template non-null"); + XRPL_ASSERT(mType_, "xrpl::STObject::at(TypedField auto) : field template non-null"); XRPL_ASSERT( - b->getSType() == STI_NOTPRESENT, "xrpl::STObject::at(TypedField auto) : type not present"); + b->getSType() == StiNotpresent, "xrpl::STObject::at(TypedField auto) : type not present"); - if (mType->style(f) == soeOPTIONAL) + if (mType_->style(f) == SoeOptional) Throw("Missing optional field: " + f.getName()); XRPL_ASSERT( - mType->style(f) == soeDEFAULT, + mType_->style(f) == SoeDefault, "xrpl::STObject::at(TypedField auto) : template style is default"); // Used to help handle the case where value_type is a const reference, // otherwise we would return the address of a temporary. - static std::decay_t const dv{}; - return dv; + static std::decay_t const kDV{}; + return kDV; } template @@ -1110,16 +1110,16 @@ STObject::at(OptionaledField const& of) const if (!u) { XRPL_ASSERT( - mType, + mType_, "xrpl::STObject::at(OptionaledField auto) : field template " "non-null"); XRPL_ASSERT( - b->getSType() == STI_NOTPRESENT, + b->getSType() == StiNotpresent, "xrpl::STObject::at(OptionaledField auto) : type not present"); - if (mType->style(*of.f) == soeOPTIONAL) + if (mType_->style(*of.f) == SoeOptional) return std::nullopt; XRPL_ASSERT( - mType->style(*of.f) == soeDEFAULT, + mType_->style(*of.f) == SoeDefault, "xrpl::STObject::at(OptionaledField auto) : template style is " "default"); return typename T::value_type{}; @@ -1143,14 +1143,14 @@ STObject::at(OptionaledField const& of) -> OptionalProxy template void -STObject::setFieldH160(SField const& field, base_uint<160, Tag> const& v) +STObject::setFieldH160(SField const& field, BaseUint<160, Tag> const& v) { STBase* rf = getPField(field, true); if (!rf) throwFieldNotFound(field); - if (rf->getSType() == STI_NOTPRESENT) + if (rf->getSType() == StiNotpresent) rf = makeFieldPresent(field); using Bits = STBitString<160>; @@ -1181,7 +1181,7 @@ STObject::getFieldByValue(SField const& field) const SerializedTypeID const id = rf->getSType(); - if (id == STI_NOTPRESENT) + if (id == StiNotpresent) return V(); // optional field not present T const* cf = dynamic_cast(rf); @@ -1208,7 +1208,7 @@ STObject::getFieldByConstRef(SField const& field, V const& empty) const SerializedTypeID const id = rf->getSType(); - if (id == STI_NOTPRESENT) + if (id == StiNotpresent) { // NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter) return empty; // optional field not present @@ -1234,7 +1234,7 @@ STObject::setFieldUsingSetValue(SField const& field, V value) if (!rf) throwFieldNotFound(field); - if (rf->getSType() == STI_NOTPRESENT) + if (rf->getSType() == StiNotpresent) rf = makeFieldPresent(field); T* cf = dynamic_cast(rf); @@ -1255,7 +1255,7 @@ STObject::setFieldUsingAssignment(SField const& field, T const& value) if (!rf) throwFieldNotFound(field); - if (rf->getSType() == STI_NOTPRESENT) + if (rf->getSType() == StiNotpresent) rf = makeFieldPresent(field); T* cf = dynamic_cast(rf); @@ -1276,7 +1276,7 @@ STObject::peekField(SField const& field) if (!rf) throwFieldNotFound(field); - if (rf->getSType() == STI_NOTPRESENT) + if (rf->getSType() == StiNotpresent) rf = makeFieldPresent(field); T* cf = dynamic_cast(rf); diff --git a/include/xrpl/protocol/STPathSet.h b/include/xrpl/protocol/STPathSet.h index ce9a73523c..002e7268e6 100644 --- a/include/xrpl/protocol/STPathSet.h +++ b/include/xrpl/protocol/STPathSet.h @@ -16,10 +16,10 @@ namespace xrpl { class STPathElement final : public CountedObject { - unsigned int mType; - AccountID mAccountID; - PathAsset mAssetID; - AccountID mIssuerID; + unsigned int mType_; + AccountID mAccountID_; + PathAsset mAssetID_; + AccountID mIssuerID_; bool is_offer_; std::size_t hash_value_; @@ -28,14 +28,14 @@ public: // Bitwise values (typeCurrency | typeMPT) // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) enum Type { - typeNone = 0x00, - typeAccount = 0x01, // Rippling through an account (vs taking an offer). - typeCurrency = 0x10, // Currency follows. - typeIssuer = 0x20, // Issuer follows. - typeMPT = 0x40, // MPT follows. - typeBoundary = 0xFF, // Boundary between alternate paths. - typeAsset = typeCurrency | typeMPT, - typeAll = typeAccount | typeCurrency | typeIssuer | typeMPT, + TypeNone = 0x00, + TypeAccount = 0x01, // Rippling through an account (vs taking an offer). + TypeCurrency = 0x10, // Currency follows. + TypeIssuer = 0x20, // Issuer follows. + TypeMpt = 0x40, // MPT follows. + TypeBoundary = 0xFF, // Boundary between alternate paths. + TypeAsset = TypeCurrency | TypeMpt, + TypeAll = TypeAccount | TypeCurrency | TypeIssuer | TypeMpt, // Combination of all types. }; @@ -113,12 +113,12 @@ public: private: static std::size_t - get_hash(STPathElement const& element); + getHash(STPathElement const& element); }; class STPath final : public CountedObject { - std::vector mPath; + std::vector mPath_; public: STPath() = default; @@ -132,11 +132,11 @@ public: empty() const; void - push_back(STPathElement const& e); + pushBack(STPathElement const& e); template void - emplace_back(Args&&... args); + emplaceBack(Args&&... args); [[nodiscard]] bool hasSeen(AccountID const& account, PathAsset const& asset, AccountID const& issuer) const; @@ -173,7 +173,7 @@ public: // A set of zero or more payment paths class STPathSet final : public STBase, public CountedObject { - std::vector value; + std::vector value_; public: STPathSet() = default; @@ -218,11 +218,11 @@ public: empty() const; void - push_back(STPath const& e); + pushBack(STPath const& e); template void - emplace_back(Args&&... args); + emplaceBack(Args&&... args); private: STBase* @@ -235,16 +235,16 @@ private: // ------------ STPathElement ------------ -inline STPathElement::STPathElement() : mType(typeNone), is_offer_(true) +inline STPathElement::STPathElement() : mType_(TypeNone), is_offer_(true) { - hash_value_ = get_hash(*this); + hash_value_ = getHash(*this); } inline STPathElement::STPathElement( std::optional const& account, std::optional const& asset, std::optional const& issuer) - : mType(typeNone) + : mType_(TypeNone) { if (!account) { @@ -253,26 +253,27 @@ inline STPathElement::STPathElement( else { is_offer_ = false; - mAccountID = *account; - mType |= typeAccount; + mAccountID_ = *account; + mType_ |= TypeAccount; XRPL_ASSERT( - mAccountID != noAccount(), "xrpl::STPathElement::STPathElement : account is set"); + mAccountID_ != noAccount(), "xrpl::STPathElement::STPathElement : account is set"); } if (asset) { - mAssetID = *asset; - mType |= mAssetID.holds() ? typeCurrency : typeMPT; + mAssetID_ = *asset; + mType_ |= mAssetID_.holds() ? TypeCurrency : TypeMpt; } if (issuer) { - mIssuerID = *issuer; - mType |= typeIssuer; - XRPL_ASSERT(mIssuerID != noAccount(), "xrpl::STPathElement::STPathElement : issuer is set"); + mIssuerID_ = *issuer; + mType_ |= TypeIssuer; + XRPL_ASSERT( + mIssuerID_ != noAccount(), "xrpl::STPathElement::STPathElement : issuer is set"); } - hash_value_ = get_hash(*this); + hash_value_ = getHash(*this); } inline STPathElement::STPathElement( @@ -280,22 +281,22 @@ inline STPathElement::STPathElement( PathAsset const& asset, AccountID const& issuer, bool forceAsset) - : mType(typeNone) - , mAccountID(account) - , mAssetID(asset) - , mIssuerID(issuer) - , is_offer_(isXRP(mAccountID)) + : mType_(TypeNone) + , mAccountID_(account) + , mAssetID_(asset) + , mIssuerID_(issuer) + , is_offer_(isXRP(mAccountID_)) { if (!is_offer_) - mType |= typeAccount; + mType_ |= TypeAccount; - if (forceAsset || !isXRP(mAssetID)) - mType |= asset.holds() ? typeCurrency : typeMPT; + if (forceAsset || !isXRP(mAssetID_)) + mType_ |= asset.holds() ? TypeCurrency : TypeMpt; if (!isXRP(issuer)) - mType |= typeIssuer; + mType_ |= TypeIssuer; - hash_value_ = get_hash(*this); + hash_value_ = getHash(*this); } inline STPathElement::STPathElement( @@ -303,24 +304,24 @@ inline STPathElement::STPathElement( AccountID const& account, PathAsset const& asset, AccountID const& issuer) - : mType(uType) - , mAccountID(account) - , mAssetID(asset) - , mIssuerID(issuer) - , is_offer_(isXRP(mAccountID)) + : mType_(uType) + , mAccountID_(account) + , mAssetID_(asset) + , mIssuerID_(issuer) + , is_offer_(isXRP(mAccountID_)) { // uType could be assetType; i.e. either Currency or MPTID. // Get the actual type. - mAssetID.visit( - [&](Currency const&) { mType = mType & (~Type::typeMPT); }, - [&](MPTID const&) { mType = mType & (~Type::typeCurrency); }); - hash_value_ = get_hash(*this); + mAssetID_.visit( + [&](Currency const&) { mType_ = mType_ & (~Type::TypeMpt); }, + [&](MPTID const&) { mType_ = mType_ & (~Type::TypeCurrency); }); + hash_value_ = getHash(*this); } inline auto STPathElement::getNodeType() const { - return mType; + return mType_; } inline bool @@ -338,37 +339,37 @@ STPathElement::isAccount() const inline bool STPathElement::isType(Type const& pe) const { - return (mType & pe) != 0u; + return (mType_ & pe) != 0u; } inline bool STPathElement::hasIssuer() const { - return isType(STPathElement::typeIssuer); + return isType(STPathElement::TypeIssuer); } inline bool STPathElement::hasCurrency() const { - return isType(STPathElement::typeCurrency); + return isType(STPathElement::TypeCurrency); } inline bool STPathElement::hasMPT() const { - return isType(STPathElement::typeMPT); + return isType(STPathElement::TypeMpt); } inline bool STPathElement::hasAsset() const { - return isType(STPathElement::typeAsset); + return isType(STPathElement::TypeAsset); } inline bool STPathElement::isNone() const { - return getNodeType() == STPathElement::typeNone; + return getNodeType() == STPathElement::TypeNone; } // Nodes are either an account ID or a offer prefix. Offer prefixs denote a @@ -376,38 +377,38 @@ STPathElement::isNone() const inline AccountID const& STPathElement::getAccountID() const { - return mAccountID; + return mAccountID_; } inline PathAsset const& STPathElement::getPathAsset() const { - return mAssetID; + return mAssetID_; } inline Currency const& STPathElement::getCurrency() const { - return mAssetID.get(); + return mAssetID_.get(); } inline MPTID const& STPathElement::getMPTID() const { - return mAssetID.get(); + return mAssetID_.get(); } inline AccountID const& STPathElement::getIssuerID() const { - return mIssuerID; + return mIssuerID_; } inline bool STPathElement::operator==(STPathElement const& t) const { - return (mType & typeAccount) == (t.mType & typeAccount) && hash_value_ == t.hash_value_ && - mAccountID == t.mAccountID && mAssetID == t.mAssetID && mIssuerID == t.mIssuerID; + return (mType_ & TypeAccount) == (t.mType_ & TypeAccount) && hash_value_ == t.hash_value_ && + mAccountID_ == t.mAccountID_ && mAssetID_ == t.mAssetID_ && mIssuerID_ == t.mIssuerID_; } inline bool @@ -418,81 +419,81 @@ STPathElement::operator!=(STPathElement const& t) const // ------------ STPath ------------ -inline STPath::STPath(std::vector p) : mPath(std::move(p)) +inline STPath::STPath(std::vector p) : mPath_(std::move(p)) { } inline std::vector::size_type STPath::size() const { - return mPath.size(); + return mPath_.size(); } inline bool STPath::empty() const { - return mPath.empty(); + return mPath_.empty(); } inline void -STPath::push_back(STPathElement const& e) +STPath::pushBack(STPathElement const& e) { - mPath.push_back(e); + mPath_.push_back(e); } template inline void -STPath::emplace_back(Args&&... args) +STPath::emplaceBack(Args&&... args) { - mPath.emplace_back(std::forward(args)...); + mPath_.emplace_back(std::forward(args)...); } inline std::vector::const_iterator STPath::begin() const { - return mPath.begin(); + return mPath_.begin(); } inline std::vector::const_iterator STPath::end() const { - return mPath.end(); + return mPath_.end(); } inline bool STPath::operator==(STPath const& t) const { - return mPath == t.mPath; + return mPath_ == t.mPath_; } inline std::vector::const_reference STPath::back() const { - return mPath.back(); + return mPath_.back(); } inline std::vector::const_reference STPath::front() const { - return mPath.front(); + return mPath_.front(); } inline STPathElement& STPath::operator[](int i) { - return mPath[i]; + return mPath_[i]; } inline STPathElement const& STPath::operator[](int i) const { - return mPath[i]; + return mPath_[i]; } inline void STPath::reserve(size_t s) { - mPath.reserve(s); + mPath_.reserve(s); } // ------------ STPathSet ------------ @@ -505,50 +506,50 @@ inline STPathSet::STPathSet(SField const& n) : STBase(n) inline std::vector::const_reference STPathSet::operator[](std::vector::size_type n) const { - return value[n]; + return value_[n]; } inline std::vector::reference STPathSet::operator[](std::vector::size_type n) { - return value[n]; + return value_[n]; } inline std::vector::const_iterator STPathSet::begin() const { - return value.begin(); + return value_.begin(); } inline std::vector::const_iterator STPathSet::end() const { - return value.end(); + return value_.end(); } inline std::vector::size_type STPathSet::size() const { - return value.size(); + return value_.size(); } inline bool STPathSet::empty() const { - return value.empty(); + return value_.empty(); } inline void -STPathSet::push_back(STPath const& e) +STPathSet::pushBack(STPath const& e) { - value.push_back(e); + value_.push_back(e); } template inline void -STPathSet::emplace_back(Args&&... args) +STPathSet::emplaceBack(Args&&... args) { - value.emplace_back(std::forward(args)...); + value_.emplace_back(std::forward(args)...); } } // namespace xrpl diff --git a/include/xrpl/protocol/STTx.h b/include/xrpl/protocol/STTx.h index b27d9e0637..e8308bb9fe 100644 --- a/include/xrpl/protocol/STTx.h +++ b/include/xrpl/protocol/STTx.h @@ -16,12 +16,12 @@ namespace xrpl { enum class TxnSql : char { - txnSqlNew = 'N', - txnSqlConflict = 'C', - txnSqlHeld = 'H', - txnSqlValidated = 'V', - txnSqlIncluded = 'I', - txnSqlUnknown = 'U' + TxnSqlNew = 'N', + TxnSqlConflict = 'C', + TxnSqlHeld = 'H', + TxnSqlValidated = 'V', + TxnSqlIncluded = 'I', + TxnSqlUnknown = 'U' }; class STTx final : public STObject, public CountedObject @@ -30,8 +30,8 @@ class STTx final : public STObject, public CountedObject TxType tx_type_; public: - static constexpr std::size_t minMultiSigners = 1; - static constexpr std::size_t maxMultiSigners = 32; + static constexpr std::size_t kMIN_MULTI_SIGNERS = 1; + static constexpr std::size_t kMAX_MULTI_SIGNERS = 32; STTx() = delete; STTx(STTx const& other) = default; diff --git a/include/xrpl/protocol/STValidation.h b/include/xrpl/protocol/STValidation.h index c645336b59..11f2c67b6b 100644 --- a/include/xrpl/protocol/STValidation.h +++ b/include/xrpl/protocol/STValidation.h @@ -16,14 +16,14 @@ namespace xrpl { // Validation flags // This is a full (as opposed to a partial) validation -constexpr std::uint32_t vfFullValidation = 0x00000001; +constexpr std::uint32_t kVF_FULL_VALIDATION = 0x00000001; // The signature is fully canonical -constexpr std::uint32_t vfFullyCanonicalSig = 0x80000000; +constexpr std::uint32_t kVF_FULLY_CANONICAL_SIG = 0x80000000; class STValidation final : public STObject, public CountedObject { - bool mTrusted = false; + bool mTrusted_ = false; // Determines the validity of the signature in this validation; unseated // optional if we haven't yet checked it, a boolean otherwise. @@ -151,7 +151,7 @@ STValidation::STValidation(SerialIter& sit, LookupNodeID&& lookupNodeID, bool ch , signingPubKey_([this]() { auto const spk = getFieldVL(sfSigningPubKey); - if (publicKeyType(makeSlice(spk)) != KeyType::secp256k1) + if (publicKeyType(makeSlice(spk)) != KeyType::Secp256k1) Throw("Invalid public key in validation"); return PublicKey{makeSlice(spk)}; @@ -161,7 +161,7 @@ STValidation::STValidation(SerialIter& sit, LookupNodeID&& lookupNodeID, bool ch if (checkSignature && !isValid()) { JLOG(debugLog().error()) << "Invalid signature in validation: " - << getJson(JsonOptions::none); + << getJson(JsonOptions::None); Throw("Invalid signature in validation"); } @@ -194,7 +194,7 @@ STValidation::STValidation( "node"); // First, set our own public key: - if (publicKeyType(pk) != KeyType::secp256k1) + if (publicKeyType(pk) != KeyType::Secp256k1) LogicError("We can only use secp256k1 keys for signing validations"); setFieldVL(sfSigningPubKey, pk.slice()); @@ -204,14 +204,14 @@ STValidation::STValidation( f(*this); // Finally, sign the validation and mark it as trusted: - setFlag(vfFullyCanonicalSig); + setFlag(kVF_FULLY_CANONICAL_SIG); setFieldVL(sfSignature, signDigest(pk, sk, getSigningHash())); setTrusted(); // Check to ensure that all required fields are present. for (auto const& e : validationFormat()) { - if (e.style() == soeREQUIRED && !isFieldPresent(e.sField())) + if (e.style() == SoeRequired && !isFieldPresent(e.sField())) LogicError("Required field '" + e.sField().getName() + "' missing from validation."); } @@ -234,19 +234,19 @@ STValidation::getNodeID() const noexcept inline bool STValidation::isTrusted() const noexcept { - return mTrusted; + return mTrusted_; } inline void STValidation::setTrusted() { - mTrusted = true; + mTrusted_ = true; } inline void STValidation::setUntrusted() { - mTrusted = false; + mTrusted_ = false; } inline void diff --git a/include/xrpl/protocol/STVector256.h b/include/xrpl/protocol/STVector256.h index c650c565ce..ab2a23f7f9 100644 --- a/include/xrpl/protocol/STVector256.h +++ b/include/xrpl/protocol/STVector256.h @@ -9,7 +9,7 @@ namespace xrpl { class STVector256 : public STBase, public CountedObject { - std::vector mValue; + std::vector mValue_; public: using value_type = std::vector const&; @@ -70,7 +70,7 @@ public: insert(std::vector::const_iterator pos, uint256 const& value); void - push_back(uint256 const& v); + pushBack(uint256 const& v); std::vector::iterator begin(); @@ -103,124 +103,124 @@ inline STVector256::STVector256(SField const& n) : STBase(n) { } -inline STVector256::STVector256(std::vector const& vector) : mValue(vector) +inline STVector256::STVector256(std::vector const& vector) : mValue_(vector) { } inline STVector256::STVector256(SField const& n, std::vector const& vector) - : STBase(n), mValue(vector) + : STBase(n), mValue_(vector) { } inline STVector256& STVector256::operator=(std::vector const& v) { - mValue = v; + mValue_ = v; return *this; } inline STVector256& STVector256::operator=(std::vector&& v) { - mValue = std::move(v); + mValue_ = std::move(v); return *this; } inline void STVector256::setValue(STVector256 const& v) { - mValue = v.mValue; + mValue_ = v.mValue_; } /** Retrieve a copy of the vector we contain */ inline STVector256:: operator std::vector() const { - return mValue; + return mValue_; } inline std::size_t STVector256::size() const { - return mValue.size(); + return mValue_.size(); } inline void STVector256::resize(std::size_t n) { - mValue.resize(n); + mValue_.resize(n); } inline bool STVector256::empty() const { - return mValue.empty(); + return mValue_.empty(); } inline std::vector::reference STVector256::operator[](std::vector::size_type n) { - return mValue[n]; + return mValue_[n]; } inline std::vector::const_reference STVector256::operator[](std::vector::size_type n) const { - return mValue[n]; + return mValue_[n]; } inline std::vector const& STVector256::value() const { - return mValue; + return mValue_; } inline std::vector::iterator STVector256::insert(std::vector::const_iterator pos, uint256 const& value) { - return mValue.insert(pos, value); + return mValue_.insert(pos, value); } inline void -STVector256::push_back(uint256 const& v) +STVector256::pushBack(uint256 const& v) { - mValue.push_back(v); + mValue_.push_back(v); } inline std::vector::iterator STVector256::begin() { - return mValue.begin(); + return mValue_.begin(); } inline std::vector::const_iterator STVector256::begin() const { - return mValue.begin(); + return mValue_.begin(); } inline std::vector::iterator STVector256::end() { - return mValue.end(); + return mValue_.end(); } inline std::vector::const_iterator STVector256::end() const { - return mValue.end(); + return mValue_.end(); } inline std::vector::iterator STVector256::erase(std::vector::iterator position) { - return mValue.erase(position); + return mValue_.erase(position); } inline void STVector256::clear() noexcept { - mValue.clear(); + mValue_.clear(); } } // namespace xrpl diff --git a/include/xrpl/protocol/STXChainBridge.h b/include/xrpl/protocol/STXChainBridge.h index 2dc2fbce48..a2333cb7f4 100644 --- a/include/xrpl/protocol/STXChainBridge.h +++ b/include/xrpl/protocol/STXChainBridge.h @@ -20,7 +20,7 @@ class STXChainBridge final : public STBase, public CountedObject public: using value_type = STXChainBridge; - enum class ChainType { locking, issuing }; + enum class ChainType { Locking, Issuing }; static ChainType otherChain(ChainType ct); @@ -174,7 +174,7 @@ STXChainBridge::value() const noexcept inline AccountID const& STXChainBridge::door(ChainType ct) const { - if (ct == ChainType::locking) + if (ct == ChainType::Locking) return lockingChainDoor(); return issuingChainDoor(); } @@ -182,7 +182,7 @@ STXChainBridge::door(ChainType ct) const inline Issue const& STXChainBridge::issue(ChainType ct) const { - if (ct == ChainType::locking) + if (ct == ChainType::Locking) return lockingChainIssue(); return issuingChainIssue(); } @@ -190,25 +190,25 @@ STXChainBridge::issue(ChainType ct) const inline STXChainBridge::ChainType STXChainBridge::otherChain(ChainType ct) { - if (ct == ChainType::locking) - return ChainType::issuing; - return ChainType::locking; + if (ct == ChainType::Locking) + return ChainType::Issuing; + return ChainType::Locking; } inline STXChainBridge::ChainType STXChainBridge::srcChain(bool wasLockingChainSend) { if (wasLockingChainSend) - return ChainType::locking; - return ChainType::issuing; + return ChainType::Locking; + return ChainType::Issuing; } inline STXChainBridge::ChainType STXChainBridge::dstChain(bool wasLockingChainSend) { if (wasLockingChainSend) - return ChainType::issuing; - return ChainType::locking; + return ChainType::Issuing; + return ChainType::Locking; } } // namespace xrpl diff --git a/include/xrpl/protocol/SecretKey.h b/include/xrpl/protocol/SecretKey.h index 462a48f4bd..9af27e9709 100644 --- a/include/xrpl/protocol/SecretKey.h +++ b/include/xrpl/protocol/SecretKey.h @@ -17,10 +17,10 @@ namespace xrpl { class SecretKey { public: - static constexpr std::size_t size_ = 32; + static constexpr std::size_t kSIZE = 32; private: - std::uint8_t buf_[size_]{}; + std::uint8_t buf_[kSIZE]{}; public: using const_iterator = std::uint8_t const*; @@ -37,7 +37,7 @@ public: ~SecretKey(); - SecretKey(std::array const& data); + SecretKey(std::array const& data); SecretKey(Slice const& slice); [[nodiscard]] std::uint8_t const* @@ -58,7 +58,7 @@ public: to avoid accidental exposure of secret key material. */ [[nodiscard]] std::string - to_string() const; + toString() const; [[nodiscard]] const_iterator begin() const noexcept diff --git a/include/xrpl/protocol/SeqProxy.h b/include/xrpl/protocol/SeqProxy.h index 820004681d..be040cceec 100644 --- a/include/xrpl/protocol/SeqProxy.h +++ b/include/xrpl/protocol/SeqProxy.h @@ -35,7 +35,7 @@ namespace xrpl { class SeqProxy { public: - enum class Type : std::uint8_t { seq = 0, ticket }; + enum class Type : std::uint8_t { Seq = 0, Ticket }; private: std::uint32_t value_; @@ -55,7 +55,7 @@ public: static constexpr SeqProxy sequence(std::uint32_t v) { - return SeqProxy{Type::seq, v}; + return SeqProxy{Type::Seq, v}; } [[nodiscard]] constexpr std::uint32_t @@ -67,13 +67,13 @@ public: [[nodiscard]] constexpr bool isSeq() const { - return type_ == Type::seq; + return type_ == Type::Seq; } [[nodiscard]] constexpr bool isTicket() const { - return type_ == Type::ticket; + return type_ == Type::Ticket; } // Occasionally it is convenient to be able to increase the value_ diff --git a/include/xrpl/protocol/Serializer.h b/include/xrpl/protocol/Serializer.h index e14d008cd1..f701f64b6d 100644 --- a/include/xrpl/protocol/Serializer.h +++ b/include/xrpl/protocol/Serializer.h @@ -21,41 +21,41 @@ class Serializer { private: // DEPRECATED - Blob mData; + Blob mData_; public: explicit Serializer(int n = 256) { - mData.reserve(n); + mData_.reserve(n); } Serializer(void const* data, std::size_t size) { - mData.resize(size); + mData_.resize(size); if (size != 0u) { XRPL_ASSERT(data, "xrpl::Serializer::Serializer(void const*) : non-null input"); - std::memcpy(mData.data(), data, size); + std::memcpy(mData_.data(), data, size); } } [[nodiscard]] Slice slice() const noexcept { - return Slice(mData.data(), mData.size()); + return Slice(mData_.data(), mData_.size()); } [[nodiscard]] std::size_t size() const noexcept { - return mData.size(); + return mData_.size(); } [[nodiscard]] void const* data() const noexcept { - return mData.data(); + return mData_.data(); } // assemble functions @@ -69,11 +69,11 @@ public: int add32(T i) { - int const ret = mData.size(); - mData.push_back(static_cast((i >> 24) & 0xff)); - mData.push_back(static_cast((i >> 16) & 0xff)); - mData.push_back(static_cast((i >> 8) & 0xff)); - mData.push_back(static_cast(i & 0xff)); + int const ret = mData_.size(); + mData_.push_back(static_cast((i >> 24) & 0xff)); + mData_.push_back(static_cast((i >> 16) & 0xff)); + mData_.push_back(static_cast((i >> 8) & 0xff)); + mData_.push_back(static_cast(i & 0xff)); return ret; } @@ -85,15 +85,15 @@ public: int add64(T i) { - int const ret = mData.size(); - mData.push_back(static_cast((i >> 56) & 0xff)); - mData.push_back(static_cast((i >> 48) & 0xff)); - mData.push_back(static_cast((i >> 40) & 0xff)); - mData.push_back(static_cast((i >> 32) & 0xff)); - mData.push_back(static_cast((i >> 24) & 0xff)); - mData.push_back(static_cast((i >> 16) & 0xff)); - mData.push_back(static_cast((i >> 8) & 0xff)); - mData.push_back(static_cast(i & 0xff)); + int const ret = mData_.size(); + mData_.push_back(static_cast((i >> 56) & 0xff)); + mData_.push_back(static_cast((i >> 48) & 0xff)); + mData_.push_back(static_cast((i >> 40) & 0xff)); + mData_.push_back(static_cast((i >> 32) & 0xff)); + mData_.push_back(static_cast((i >> 24) & 0xff)); + mData_.push_back(static_cast((i >> 16) & 0xff)); + mData_.push_back(static_cast((i >> 8) & 0xff)); + mData_.push_back(static_cast(i & 0xff)); return ret; } @@ -102,7 +102,7 @@ public: template int - addBitString(base_uint const& v) + addBitString(BaseUint const& v) { return addRaw(v.data(), v.size()); } @@ -134,13 +134,13 @@ public: bool getInteger(Integer& number, int offset) { - static auto const bytes = sizeof(Integer); - if ((offset + bytes) > mData.size()) + static auto const kBYTES = sizeof(Integer); + if ((offset + kBYTES) > mData_.size()) return false; number = 0; - auto ptr = &mData[offset]; - for (auto i = 0; i < bytes; ++i) + auto ptr = &mData_[offset]; + for (auto i = 0; i < kBYTES; ++i) { if (i) number <<= 8; @@ -151,11 +151,11 @@ public: template bool - getBitString(base_uint& data, int offset) const + getBitString(BaseUint& data, int offset) const { - auto success = (offset + (Bits / 8)) <= mData.size(); + auto success = (offset + (Bits / 8)) <= mData_.size(); if (success) - memcpy(data.begin(), &(mData.front()) + offset, (Bits / 8)); + memcpy(data.begin(), &(mData_.front()) + offset, (Bits / 8)); return success; } @@ -164,7 +164,7 @@ public: int addFieldID(SerializedTypeID type, int name) { - return addFieldID(safe_cast(type), name); + return addFieldID(safeCast(type), name); } // DEPRECATED @@ -175,38 +175,38 @@ public: [[nodiscard]] Blob const& peekData() const { - return mData; + return mData_; } [[nodiscard]] Blob getData() const { - return mData; + return mData_; } Blob& modData() { - return mData; + return mData_; } [[nodiscard]] int getDataLength() const { - return mData.size(); + return mData_.size(); } [[nodiscard]] void const* getDataPtr() const { - return mData.data(); + return mData_.data(); } void* getDataPtr() { - return mData.data(); + return mData_.data(); } [[nodiscard]] int getLength() const { - return mData.size(); + return mData_.size(); } [[nodiscard]] std::string getString() const @@ -216,7 +216,7 @@ public: void erase() { - mData.clear(); + mData_.clear(); } bool chop(int num); @@ -225,58 +225,58 @@ public: Blob ::iterator begin() { - return mData.begin(); + return mData_.begin(); } Blob ::iterator end() { - return mData.end(); + return mData_.end(); } [[nodiscard]] Blob ::const_iterator begin() const { - return mData.begin(); + return mData_.begin(); } [[nodiscard]] Blob ::const_iterator end() const { - return mData.end(); + return mData_.end(); } void reserve(size_t n) { - mData.reserve(n); + mData_.reserve(n); } void resize(size_t n) { - mData.resize(n); + mData_.resize(n); } [[nodiscard]] size_t capacity() const { - return mData.capacity(); + return mData_.capacity(); } bool operator==(Blob const& v) const { - return v == mData; + return v == mData_; } bool operator!=(Blob const& v) const { - return v != mData; + return v != mData_; } bool operator==(Serializer const& v) const { - return v.mData == mData; + return v.mData_ == mData_; } bool operator!=(Serializer const& v) const { - return v.mData != mData; + return v.mData_ != mData_; } static int @@ -369,7 +369,7 @@ public: geti64(); template - base_uint + BaseUint getBitString(); uint128 @@ -428,7 +428,7 @@ public: }; template -base_uint +BaseUint SerialIter::getBitString() { auto const n = Bits / 8; @@ -442,7 +442,7 @@ SerialIter::getBitString() used_ += n; remain_ -= n; - return base_uint::fromVoid(x); + return BaseUint::fromVoid(x); } } // namespace xrpl diff --git a/include/xrpl/protocol/SystemParameters.h b/include/xrpl/protocol/SystemParameters.h index b51e011533..029c0418b5 100644 --- a/include/xrpl/protocol/SystemParameters.h +++ b/include/xrpl/protocol/SystemParameters.h @@ -14,22 +14,22 @@ namespace xrpl { static inline std::string const& systemName() { - static std::string const name = "xrpld"; - return name; + static std::string const kNAME = "xrpld"; + return kNAME; } /** Configure the native currency. */ /** Number of drops in the genesis account. */ -constexpr XRPAmount INITIAL_XRP{100'000'000'000 * DROPS_PER_XRP}; -static_assert(INITIAL_XRP.drops() == 100'000'000'000'000'000); -static_assert(Number::maxRep >= INITIAL_XRP.drops()); +constexpr XRPAmount kINITIAL_XRP{100'000'000'000 * kDROPS_PER_XRP}; +static_assert(kINITIAL_XRP.drops() == 100'000'000'000'000'000); +static_assert(Number::kMAX_REP >= kINITIAL_XRP.drops()); /** Returns true if the amount does not exceed the initial XRP in existence. */ inline bool isLegalAmount(XRPAmount const& amount) { - return amount <= INITIAL_XRP; + return amount <= kINITIAL_XRP; } /** Returns true if the absolute value of the amount does not exceed the initial @@ -37,31 +37,31 @@ isLegalAmount(XRPAmount const& amount) inline bool isLegalAmountSigned(XRPAmount const& amount) { - return amount >= -INITIAL_XRP && amount <= INITIAL_XRP; + return amount >= -kINITIAL_XRP && amount <= kINITIAL_XRP; } /* The currency code for the native currency. */ static inline std::string const& systemCurrencyCode() { - static std::string const code = "XRP"; - return code; + static std::string const kCODE = "XRP"; + return kCODE; } /** The XRP ledger network's earliest allowed sequence */ -static constexpr std::uint32_t XRP_LEDGER_EARLIEST_SEQ{32570u}; +static constexpr std::uint32_t kXRP_LEDGER_EARLIEST_SEQ{32570u}; /** The XRP Ledger mainnet's earliest ledger with a FeeSettings object. Only * used in asserts and tests. */ -static constexpr std::uint32_t XRP_LEDGER_EARLIEST_FEES{562177u}; +static constexpr std::uint32_t kXRP_LEDGER_EARLIEST_FEES{562177u}; /** The minimum amount of support an amendment should have. */ -constexpr std::ratio<80, 100> amendmentMajorityCalcThreshold; +constexpr std::ratio<80, 100> kAMENDMENT_MAJORITY_CALC_THRESHOLD; /** The minimum amount of time an amendment must hold a majority */ -constexpr std::chrono::seconds const defaultAmendmentMajorityTime = weeks{2}; +constexpr std::chrono::seconds const kDEFAULT_AMENDMENT_MAJORITY_TIME = weeks{2}; } // namespace xrpl /** Default peer port (IANA registered) */ -inline std::uint16_t constexpr DEFAULT_PEER_PORT{2459}; +inline std::uint16_t constexpr kDEFAULT_PEER_PORT{2459}; diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index 6494453b91..b60588d185 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -31,23 +31,23 @@ enum TELcodes : TERUnderlyingType { // limit) Only valid during non-consensus processing. Implications: // - Not forwarded // - No fee check - telLOCAL_ERROR = -399, - telBAD_DOMAIN, - telBAD_PATH_COUNT, - telBAD_PUBLIC_KEY, - telFAILED_PROCESSING, - telINSUF_FEE_P, - telNO_DST_PARTIAL, - telCAN_NOT_QUEUE, - telCAN_NOT_QUEUE_BALANCE, - telCAN_NOT_QUEUE_BLOCKS, - telCAN_NOT_QUEUE_BLOCKED, - telCAN_NOT_QUEUE_FEE, - telCAN_NOT_QUEUE_FULL, - telWRONG_NETWORK, - telREQUIRES_NETWORK_ID, - telNETWORK_ID_MAKES_TX_NON_CANONICAL, - telENV_RPC_FAILED + TelLocalError = -399, + TelBadDomain, + TelBadPathCount, + TelBadPublicKey, + TelFailedProcessing, + TelInsufFeeP, + TelNoDstPartial, + TelCanNotQueue, + TelCanNotQueueBalance, + TelCanNotQueueBlocks, + TelCanNotQueueBlocked, + TelCanNotQueueFee, + TelCanNotQueueFull, + TelWrongNetwork, + TelRequiresNetworkId, + TelNetworkIdMakesTxNonCanonical, + TelEnvRpcFailed }; //------------------------------------------------------------------------------ @@ -68,64 +68,64 @@ enum TEMcodes : TERUnderlyingType { // - Not forwarded // - Reject // - Cannot succeed in any imagined ledger. - temMALFORMED = -299, + TemMalformed = -299, - temBAD_AMOUNT, - temBAD_CURRENCY, - temBAD_EXPIRATION, - temBAD_FEE, - temBAD_ISSUER, - temBAD_LIMIT, - temBAD_OFFER, - temBAD_PATH, - temBAD_PATH_LOOP, - temBAD_REGKEY, - temBAD_SEND_XRP_LIMIT, - temBAD_SEND_XRP_MAX, - temBAD_SEND_XRP_NO_DIRECT, - temBAD_SEND_XRP_PARTIAL, - temBAD_SEND_XRP_PATHS, - temBAD_SEQUENCE, - temBAD_SIGNATURE, - temBAD_SRC_ACCOUNT, - temBAD_TRANSFER_RATE, - temDST_IS_SRC, - temDST_NEEDED, - temINVALID, - temINVALID_FLAG, - temREDUNDANT, - temRIPPLE_EMPTY, - temDISABLED, - temBAD_SIGNER, - temBAD_QUORUM, - temBAD_WEIGHT, - temBAD_TICK_SIZE, - temINVALID_ACCOUNT_ID, - temCANNOT_PREAUTH_SELF, - temINVALID_COUNT, + TemBadAmount, + TemBadCurrency, + TemBadExpiration, + TemBadFee, + TemBadIssuer, + TemBadLimit, + TemBadOffer, + TemBadPath, + TemBadPathLoop, + TemBadRegkey, + TemBadSendXrpLimit, + TemBadSendXrpMax, + TemBadSendXrpNoDirect, + TemBadSendXrpPartial, + TemBadSendXrpPaths, + TemBadSequence, + TemBadSignature, + TemBadSrcAccount, + TemBadTransferRate, + TemDstIsSrc, + TemDstNeeded, + TemInvalid, + TemInvalidFlag, + TemRedundant, + TemRippleEmpty, + TemDisabled, + TemBadSigner, + TemBadQuorum, + TemBadWeight, + TemBadTickSize, + TemInvalidAccountId, + TemCannotPreauthSelf, + TemInvalidCount, - temUNCERTAIN, // An internal intermediate result; should never be returned. - temUNKNOWN, // An internal intermediate result; should never be returned. + TemUncertain, // An internal intermediate result; should never be returned. + TemUnknown, // An internal intermediate result; should never be returned. - temSEQ_AND_TICKET, - temBAD_NFTOKEN_TRANSFER_FEE, + TemSeqAndTicket, + TemBadNftokenTransferFee, - temBAD_AMM_TOKENS, + TemBadAmmTokens, - temXCHAIN_EQUAL_DOOR_ACCOUNTS, - temXCHAIN_BAD_PROOF, - temXCHAIN_BRIDGE_BAD_ISSUES, - temXCHAIN_BRIDGE_NONDOOR_OWNER, - temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT, - temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT, + TemXchainEqualDoorAccounts, + TemXchainBadProof, + TemXchainBridgeBadIssues, + TemXchainBridgeNondoorOwner, + TemXchainBridgeBadMinAccountCreateAmount, + TemXchainBridgeBadRewardAmount, - temEMPTY_DID, + TemEmptyDid, - temARRAY_EMPTY, - temARRAY_TOO_LARGE, - temBAD_TRANSFER_FEE, - temINVALID_INNER_BATCH, - temBAD_MPT, + TemArrayEmpty, + TemArrayTooLarge, + TemBadTransferFee, + TemInvalidInnerBatch, + TemBadMpt, }; //------------------------------------------------------------------------------ @@ -150,28 +150,28 @@ enum TEFcodes : TERUnderlyingType { // - Not applied // - Not forwarded // - Could succeed in an imagined ledger. - tefFAILURE = -199, - tefALREADY, - tefBAD_ADD_AUTH, - tefBAD_AUTH, - tefBAD_LEDGER, - tefCREATED, - tefEXCEPTION, - tefINTERNAL, - tefNO_AUTH_REQUIRED, // Can't set auth if auth is not required. - tefPAST_SEQ, - tefWRONG_PRIOR, - tefMASTER_DISABLED, - tefMAX_LEDGER, - tefBAD_SIGNATURE, - tefBAD_QUORUM, - tefNOT_MULTI_SIGNING, - tefBAD_AUTH_MASTER, - tefINVARIANT_FAILED, - tefTOO_BIG, - tefNO_TICKET, - tefNFTOKEN_IS_NOT_TRANSFERABLE, - tefINVALID_LEDGER_FIX_TYPE, + TefFailure = -199, + TefAlready, + TefBadAddAuth, + TefBadAuth, + TefBadLedger, + TefCreated, + TefException, + TefInternal, + TefNoAuthRequired, // Can't set auth if auth is not required. + TefPastSeq, + TefWrongPrior, + TefMasterDisabled, + TefMaxLedger, + TefBadSignature, + TefBadQuorum, + TefNotMultiSigning, + TefBadAuthMaster, + TefInvariantFailed, + TefTooBig, + TefNoTicket, + TefNftokenIsNotTransferable, + TefInvalidLedgerFixType, }; //------------------------------------------------------------------------------ @@ -200,24 +200,24 @@ enum TERcodes : TERUnderlyingType { // - Might succeed later // - Hold // - Makes hole in sequence which jams transactions. - terRETRY = -99, - terFUNDS_SPENT, // DEPRECATED. - terINSUF_FEE_B, // Can't pay fee, therefore don't burden network. - terNO_ACCOUNT, // Can't pay fee, therefore don't burden network. - terNO_AUTH, // Not authorized to hold IOUs. - terNO_LINE, // Internal flag. - terOWNERS, // Can't succeed with non-zero owner count. - terPRE_SEQ, // Can't pay fee, no point in forwarding, so don't - // burden network. - terLAST, // DEPRECATED. - terNO_RIPPLE, // Rippling not allowed - terQUEUED, // Transaction is being held in TxQ until fee drops - terPRE_TICKET, // Ticket is not yet in ledger but might be on its way - terNO_AMM, // AMM doesn't exist for the asset pair - terADDRESS_COLLISION, // Failed to allocate AccountID when trying to - // create a pseudo-account - terNO_DELEGATE_PERMISSION, // Delegate does not have permission - terLOCKED, // MPT is locked + TerRetry = -99, + TerFundsSpent, // DEPRECATED. + TerInsufFeeB, // Can't pay fee, therefore don't burden network. + TerNoAccount, // Can't pay fee, therefore don't burden network. + TerNoAuth, // Not authorized to hold IOUs. + TerNoLine, // Internal flag. + TerOwners, // Can't succeed with non-zero owner count. + TerPreSeq, // Can't pay fee, no point in forwarding, so don't + // burden network. + TerLast, // DEPRECATED. + TerNoRipple, // Rippling not allowed + TerQueued, // Transaction is being held in TxQ until fee drops + TerPreTicket, // Ticket is not yet in ledger but might be on its way + TerNoAmm, // AMM doesn't exist for the asset pair + TerAddressCollision, // Failed to allocate AccountID when trying to + // create a pseudo-account + TerNoDelegatePermission, // Delegate does not have permission + TerLocked, // MPT is locked }; //------------------------------------------------------------------------------ @@ -234,7 +234,7 @@ enum TEScodes : TERUnderlyingType { // Implications: // - Applied // - Forwarded - tesSUCCESS = 0 + TesSuccess = 0 }; //------------------------------------------------------------------------------ @@ -273,89 +273,89 @@ enum TECcodes : TERUnderlyingType { // - tecOBJECT_NOT_FOUND : cannot find the additional object(s) needed to // complete the transaction - tecCLAIM = 100, - tecPATH_PARTIAL = 101, - tecUNFUNDED_ADD = 102, // Unused legacy code - tecUNFUNDED_OFFER = 103, - tecUNFUNDED_PAYMENT = 104, - tecFAILED_PROCESSING = 105, - tecDIR_FULL = 121, - tecINSUF_RESERVE_LINE = 122, - tecINSUF_RESERVE_OFFER = 123, - tecNO_DST = 124, - tecNO_DST_INSUF_XRP = 125, - tecNO_LINE_INSUF_RESERVE = 126, - tecNO_LINE_REDUNDANT = 127, - tecPATH_DRY = 128, - tecUNFUNDED = 129, - tecNO_ALTERNATIVE_KEY = 130, - tecNO_REGULAR_KEY = 131, - tecOWNERS = 132, - tecNO_ISSUER = 133, - tecNO_AUTH = 134, - tecNO_LINE = 135, - tecINSUFF_FEE = 136, - tecFROZEN = 137, - tecNO_TARGET = 138, - tecNO_PERMISSION = 139, - tecNO_ENTRY = 140, - tecINSUFFICIENT_RESERVE = 141, - tecNEED_MASTER_KEY = 142, - tecDST_TAG_NEEDED = 143, - tecINTERNAL = 144, - tecOVERSIZE = 145, - tecCRYPTOCONDITION_ERROR = 146, - tecINVARIANT_FAILED = 147, - tecEXPIRED = 148, - tecDUPLICATE = 149, - tecKILLED = 150, - tecHAS_OBLIGATIONS = 151, - tecTOO_SOON = 152, - tecHOOK_REJECTED [[maybe_unused]] = 153, - tecMAX_SEQUENCE_REACHED = 154, - tecNO_SUITABLE_NFTOKEN_PAGE = 155, - tecNFTOKEN_BUY_SELL_MISMATCH = 156, - tecNFTOKEN_OFFER_TYPE_MISMATCH = 157, - tecCANT_ACCEPT_OWN_NFTOKEN_OFFER = 158, - tecINSUFFICIENT_FUNDS = 159, - tecOBJECT_NOT_FOUND = 160, - tecINSUFFICIENT_PAYMENT = 161, - tecUNFUNDED_AMM = 162, - tecAMM_BALANCE = 163, - tecAMM_FAILED = 164, - tecAMM_INVALID_TOKENS = 165, - tecAMM_EMPTY = 166, - tecAMM_NOT_EMPTY = 167, - tecAMM_ACCOUNT = 168, - tecINCOMPLETE = 169, - tecXCHAIN_BAD_TRANSFER_ISSUE = 170, - tecXCHAIN_NO_CLAIM_ID = 171, - tecXCHAIN_BAD_CLAIM_ID = 172, - tecXCHAIN_CLAIM_NO_QUORUM = 173, - tecXCHAIN_PROOF_UNKNOWN_KEY = 174, - tecXCHAIN_CREATE_ACCOUNT_NONXRP_ISSUE = 175, - tecXCHAIN_WRONG_CHAIN = 176, - tecXCHAIN_REWARD_MISMATCH = 177, - tecXCHAIN_NO_SIGNERS_LIST = 178, - tecXCHAIN_SENDING_ACCOUNT_MISMATCH = 179, - tecXCHAIN_INSUFF_CREATE_AMOUNT = 180, - tecXCHAIN_ACCOUNT_CREATE_PAST = 181, - tecXCHAIN_ACCOUNT_CREATE_TOO_MANY = 182, - tecXCHAIN_PAYMENT_FAILED = 183, - tecXCHAIN_SELF_COMMIT = 184, - tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR = 185, - tecXCHAIN_CREATE_ACCOUNT_DISABLED = 186, - tecEMPTY_DID = 187, - tecINVALID_UPDATE_TIME = 188, - tecTOKEN_PAIR_NOT_FOUND = 189, - tecARRAY_EMPTY = 190, - tecARRAY_TOO_LARGE = 191, - tecLOCKED = 192, - tecBAD_CREDENTIALS = 193, - tecWRONG_ASSET = 194, - tecLIMIT_EXCEEDED = 195, - tecPSEUDO_ACCOUNT = 196, - tecPRECISION_LOSS = 197, + TecClaim = 100, + TecPathPartial = 101, + TecUnfundedAdd = 102, // Unused legacy code + TecUnfundedOffer = 103, + TecUnfundedPayment = 104, + TecFailedProcessing = 105, + TecDirFull = 121, + TecInsufReserveLine = 122, + TecInsufReserveOffer = 123, + TecNoDst = 124, + TecNoDstInsufXrp = 125, + TecNoLineInsufReserve = 126, + TecNoLineRedundant = 127, + TecPathDry = 128, + TecUnfunded = 129, + TecNoAlternativeKey = 130, + TecNoRegularKey = 131, + TecOwners = 132, + TecNoIssuer = 133, + TecNoAuth = 134, + TecNoLine = 135, + TecInsuffFee = 136, + TecFrozen = 137, + TecNoTarget = 138, + TecNoPermission = 139, + TecNoEntry = 140, + TecInsufficientReserve = 141, + TecNeedMasterKey = 142, + TecDstTagNeeded = 143, + TecInternal = 144, + TecOversize = 145, + TecCryptoconditionError = 146, + TecInvariantFailed = 147, + TecExpired = 148, + TecDuplicate = 149, + TecKilled = 150, + TecHasObligations = 151, + TecTooSoon = 152, + TecHookRejected [[maybe_unused]] = 153, + TecMaxSequenceReached = 154, + TecNoSuitableNftokenPage = 155, + TecNftokenBuySellMismatch = 156, + TecNftokenOfferTypeMismatch = 157, + TecCantAcceptOwnNftokenOffer = 158, + TecInsufficientFunds = 159, + TecObjectNotFound = 160, + TecInsufficientPayment = 161, + TecUnfundedAmm = 162, + TecAmmBalance = 163, + TecAmmFailed = 164, + TecAmmInvalidTokens = 165, + TecAmmEmpty = 166, + TecAmmNotEmpty = 167, + TecAmmAccount = 168, + TecIncomplete = 169, + TecXchainBadTransferIssue = 170, + TecXchainNoClaimId = 171, + TecXchainBadClaimId = 172, + TecXchainClaimNoQuorum = 173, + TecXchainProofUnknownKey = 174, + TecXchainCreateAccountNonxrpIssue = 175, + TecXchainWrongChain = 176, + TecXchainRewardMismatch = 177, + TecXchainNoSignersList = 178, + TecXchainSendingAccountMismatch = 179, + TecXchainInsuffCreateAmount = 180, + TecXchainAccountCreatePast = 181, + TecXchainAccountCreateTooMany = 182, + TecXchainPaymentFailed = 183, + TecXchainSelfCommit = 184, + TecXchainBadPublicKeyAccountPair = 185, + TecXchainCreateAccountDisabled = 186, + TecEmptyDid = 187, + TecInvalidUpdateTime = 188, + TecTokenPairNotFound = 189, + TecArrayEmpty = 190, + TecArrayTooLarge = 191, + TecLocked = 192, + TecBadCredentials = 193, + TecWrongAsset = 194, + TecLimitExceeded = 195, + TecPseudoAccount = 196, + TecPrecisionLoss = 197, }; //------------------------------------------------------------------------------ @@ -364,37 +364,37 @@ enum TECcodes : TERUnderlyingType { constexpr TERUnderlyingType TERtoInt(TELcodes v) { - return safe_cast(v); + return safeCast(v); } constexpr TERUnderlyingType -TERtoInt(TEMcodes v) +teRtoInt(TEMcodes v) { - return safe_cast(v); + return safeCast(v); } constexpr TERUnderlyingType TERtoInt(TEFcodes v) { - return safe_cast(v); + return safeCast(v); } constexpr TERUnderlyingType TERtoInt(TERcodes v) { - return safe_cast(v); + return safeCast(v); } constexpr TERUnderlyingType TERtoInt(TEScodes v) { - return safe_cast(v); + return safeCast(v); } constexpr TERUnderlyingType TERtoInt(TECcodes v) { - return safe_cast(v); + return safeCast(v); } //------------------------------------------------------------------------------ @@ -407,7 +407,7 @@ class TERSubset public: // Constructors - constexpr TERSubset() : code_(tesSUCCESS) + constexpr TERSubset() : code_(TesSuccess) { } constexpr TERSubset(TERSubset const& rhs) = default; @@ -429,7 +429,7 @@ public: template < typename T, typename = std::enable_if_t>>::value>> - constexpr TERSubset(T rhs) : code_(TERtoInt(rhs)) + constexpr TERSubset(T rhs) : code_(teRtoInt(rhs)) { } @@ -452,7 +452,7 @@ public: explicit operator bool() const { - return code_ != tesSUCCESS; + return code_ != TesSuccess; } // Conversion to Json::Value allows assignment to Json::Objects @@ -486,7 +486,7 @@ public: // (unnamed) conversion to int. To avoid silent conversions like these // we provide (only) a named conversion. friend constexpr TERUnderlyingType - TERtoInt(TERSubset v) + teRtoInt(TERSubset v) { return v.code_; } @@ -497,28 +497,28 @@ public: template constexpr auto operator==(L const& lhs, R const& rhs) -> std::enable_if_t< - std::is_same_v && std::is_same_v, + std::is_same_v && std::is_same_v, bool> { - return TERtoInt(lhs) == TERtoInt(rhs); + return teRtoInt(lhs) == TERtoInt(rhs); } template constexpr auto operator!=(L const& lhs, R const& rhs) -> std::enable_if_t< - std::is_same_v && std::is_same_v, + std::is_same_v && std::is_same_v, bool> { - return TERtoInt(lhs) != TERtoInt(rhs); + return teRtoInt(lhs) != TERtoInt(rhs); } template constexpr auto operator<(L const& lhs, R const& rhs) -> std::enable_if_t< - std::is_same_v && std::is_same_v, + std::is_same_v && std::is_same_v, bool> { - return TERtoInt(lhs) < TERtoInt(rhs); + return teRtoInt(lhs) < teRtoInt(rhs); } template @@ -542,10 +542,10 @@ operator>(L const& lhs, R const& rhs) -> std::enable_if_t< template constexpr auto operator>=(L const& lhs, R const& rhs) -> std::enable_if_t< - std::is_same_v && std::is_same_v, + std::is_same_v && std::is_same_v, bool> { - return TERtoInt(lhs) >= TERtoInt(rhs); + return teRtoInt(lhs) >= teRtoInt(rhs); } //------------------------------------------------------------------------------ @@ -630,25 +630,25 @@ using TER = TERSubset; inline bool isTelLocal(TER x) noexcept { - return (x >= telLOCAL_ERROR && x < temMALFORMED); + return (x >= TelLocalError && x < TemMalformed); } inline bool isTemMalformed(TER x) noexcept { - return (x >= temMALFORMED && x < tefFAILURE); + return (x >= TemMalformed && x < TefFailure); } inline bool isTefFailure(TER x) noexcept { - return (x >= tefFAILURE && x < terRETRY); + return (x >= TefFailure && x < TerRetry); } inline bool isTerRetry(TER x) noexcept { - return (x >= terRETRY && x < tesSUCCESS); + return (x >= TerRetry && x < TesSuccess); } inline bool @@ -661,7 +661,7 @@ isTesSuccess(TER x) noexcept inline bool isTecClaim(TER x) noexcept { - return ((x) >= tecCLAIM); + return ((x) >= TecClaim); } std::unordered_map> const& diff --git a/include/xrpl/protocol/TxFlags.h b/include/xrpl/protocol/TxFlags.h index 7bbbd12707..e635036efa 100644 --- a/include/xrpl/protocol/TxFlags.h +++ b/include/xrpl/protocol/TxFlags.h @@ -37,10 +37,10 @@ namespace xrpl { using FlagValue = std::uint32_t; // Universal Transaction flags: -inline constexpr FlagValue tfFullyCanonicalSig = 0x80000000; -inline constexpr FlagValue tfInnerBatchTxn = 0x40000000; -inline constexpr FlagValue tfUniversal = tfFullyCanonicalSig | tfInnerBatchTxn; -inline constexpr FlagValue tfUniversalMask = ~tfUniversal; +inline constexpr FlagValue kTF_FULLY_CANONICAL_SIG = 0x80000000; +inline constexpr FlagValue kTF_INNER_BATCH_TXN = 0x40000000; +inline constexpr FlagValue tfUniversal = kTF_FULLY_CANONICAL_SIG | kTF_INNER_BATCH_TXN; +inline constexpr FlagValue kTF_UNIVERSAL_MASK = ~tfUniversal; #pragma push_macro("XMACRO") #pragma push_macro("TO_VALUE") @@ -81,137 +81,137 @@ inline constexpr FlagValue tfUniversalMask = ~tfUniversal; // TODO: Consider rewriting this using reflection in C++26 or later. Alternatively this could be a DSL processed by a script at build time. #define XMACRO(TRANSACTION, TF_FLAG, TF_FLAG2, MASK_ADJ) \ TRANSACTION(AccountSet, \ - TF_FLAG(tfRequireDestTag, 0x00010000) \ - TF_FLAG(tfOptionalDestTag, 0x00020000) \ - TF_FLAG(tfRequireAuth, 0x00040000) \ - TF_FLAG(tfOptionalAuth, 0x00080000) \ - TF_FLAG(tfDisallowXRP, 0x00100000) \ - TF_FLAG(tfAllowXRP, 0x00200000), \ + TF_FLAG(kTF_REQUIRE_DEST_TAG, 0x00010000) \ + TF_FLAG(kTF_OPTIONAL_DEST_TAG, 0x00020000) \ + TF_FLAG(kTF_REQUIRE_AUTH, 0x00040000) \ + TF_FLAG(kTF_OPTIONAL_AUTH, 0x00080000) \ + TF_FLAG(kTF_DISALLOW_XRP, 0x00100000) \ + TF_FLAG(kTF_ALLOW_XRP, 0x00200000), \ MASK_ADJ(0)) \ \ TRANSACTION(OfferCreate, \ - TF_FLAG(tfPassive, 0x00010000) \ - TF_FLAG(tfImmediateOrCancel, 0x00020000) \ - TF_FLAG(tfFillOrKill, 0x00040000) \ - TF_FLAG(tfSell, 0x00080000) \ - TF_FLAG(tfHybrid, 0x00100000), \ + TF_FLAG(kTF_PASSIVE, 0x00010000) \ + TF_FLAG(kTF_IMMEDIATE_OR_CANCEL, 0x00020000) \ + TF_FLAG(kTF_FILL_OR_KILL, 0x00040000) \ + TF_FLAG(kTF_SELL, 0x00080000) \ + TF_FLAG(kTF_HYBRID, 0x00100000), \ MASK_ADJ(0)) \ \ TRANSACTION(Payment, \ - TF_FLAG(tfNoRippleDirect, 0x00010000) \ - TF_FLAG(tfPartialPayment, 0x00020000) \ - TF_FLAG(tfLimitQuality, 0x00040000), \ + TF_FLAG(kTF_NO_RIPPLE_DIRECT, 0x00010000) \ + TF_FLAG(kTF_PARTIAL_PAYMENT, 0x00020000) \ + TF_FLAG(kTF_LIMIT_QUALITY, 0x00040000), \ MASK_ADJ(0)) \ \ TRANSACTION(TrustSet, \ - TF_FLAG(tfSetfAuth, 0x00010000) \ - TF_FLAG(tfSetNoRipple, 0x00020000) \ - TF_FLAG(tfClearNoRipple, 0x00040000) \ - TF_FLAG(tfSetFreeze, 0x00100000) \ - TF_FLAG(tfClearFreeze, 0x00200000) \ - TF_FLAG(tfSetDeepFreeze, 0x00400000) \ - TF_FLAG(tfClearDeepFreeze, 0x00800000), \ + TF_FLAG(kTF_SETF_AUTH, 0x00010000) \ + TF_FLAG(kTF_SET_NO_RIPPLE, 0x00020000) \ + TF_FLAG(kTF_CLEAR_NO_RIPPLE, 0x00040000) \ + TF_FLAG(kTF_SET_FREEZE, 0x00100000) \ + TF_FLAG(kTF_CLEAR_FREEZE, 0x00200000) \ + TF_FLAG(kTF_SET_DEEP_FREEZE, 0x00400000) \ + TF_FLAG(kTF_CLEAR_DEEP_FREEZE, 0x00800000), \ MASK_ADJ(0)) \ \ TRANSACTION(EnableAmendment, \ - TF_FLAG(tfGotMajority, 0x00010000) \ - TF_FLAG(tfLostMajority, 0x00020000), \ + TF_FLAG(kTF_GOT_MAJORITY, 0x00010000) \ + TF_FLAG(kTF_LOST_MAJORITY, 0x00020000), \ MASK_ADJ(0)) \ \ TRANSACTION(PaymentChannelClaim, \ - TF_FLAG(tfRenew, 0x00010000) \ - TF_FLAG(tfClose, 0x00020000), \ + TF_FLAG(kTF_RENEW, 0x00010000) \ + TF_FLAG(kTF_CLOSE, 0x00020000), \ MASK_ADJ(0)) \ \ TRANSACTION(NFTokenMint, \ - TF_FLAG(tfBurnable, 0x00000001) \ - TF_FLAG(tfOnlyXRP, 0x00000002) \ + TF_FLAG(kTF_BURNABLE, 0x00000001) \ + TF_FLAG(kTF_ONLY_XRP, 0x00000002) \ /* deprecated TF_FLAG(tfTrustLine, 0x00000004) */ \ - TF_FLAG(tfTransferable, 0x00000008) \ - TF_FLAG(tfMutable, 0x00000010), \ + TF_FLAG(kTF_TRANSFERABLE, 0x00000008) \ + TF_FLAG(kTF_MUTABLE, 0x00000010), \ MASK_ADJ(0)) \ \ TRANSACTION(MPTokenIssuanceCreate, \ /* Note: tf/lsfMPTLocked is intentionally omitted since this transaction is not allowed to modify it. */ \ - TF_FLAG(tfMPTCanLock, lsfMPTCanLock) \ - TF_FLAG(tfMPTRequireAuth, lsfMPTRequireAuth) \ - TF_FLAG(tfMPTCanEscrow, lsfMPTCanEscrow) \ - TF_FLAG(tfMPTCanTrade, lsfMPTCanTrade) \ - TF_FLAG(tfMPTCanTransfer, lsfMPTCanTransfer) \ - TF_FLAG(tfMPTCanClawback, lsfMPTCanClawback), \ + TF_FLAG(kTF_MPT_CAN_LOCK, LsfMptCanLock) \ + TF_FLAG(kTF_MPT_REQUIRE_AUTH, LsfMptRequireAuth) \ + TF_FLAG(kTF_MPT_CAN_ESCROW, LsfMptCanEscrow) \ + TF_FLAG(kTF_MPT_CAN_TRADE, LsfMptCanTrade) \ + TF_FLAG(kTF_MPT_CAN_TRANSFER, LsfMptCanTransfer) \ + TF_FLAG(kTF_MPT_CAN_CLAWBACK, LsfMptCanClawback), \ MASK_ADJ(0)) \ \ TRANSACTION(MPTokenAuthorize, \ - TF_FLAG(tfMPTUnauthorize, 0x00000001), \ + TF_FLAG(kTF_MPT_UNAUTHORIZE, 0x00000001), \ MASK_ADJ(0)) \ \ TRANSACTION(MPTokenIssuanceSet, \ - TF_FLAG(tfMPTLock, 0x00000001) \ - TF_FLAG(tfMPTUnlock, 0x00000002), \ + TF_FLAG(kTF_MPT_LOCK, 0x00000001) \ + TF_FLAG(kTF_MPT_UNLOCK, 0x00000002), \ MASK_ADJ(0)) \ \ TRANSACTION(NFTokenCreateOffer, \ - TF_FLAG(tfSellNFToken, 0x00000001), \ + TF_FLAG(kTF_SELL_NF_TOKEN, 0x00000001), \ MASK_ADJ(0)) \ \ TRANSACTION(AMMDeposit, \ - TF_FLAG(tfLPToken, 0x00010000) \ - TF_FLAG(tfSingleAsset, 0x00080000) \ - TF_FLAG(tfTwoAsset, 0x00100000) \ - TF_FLAG(tfOneAssetLPToken, 0x00200000) \ - TF_FLAG(tfLimitLPToken, 0x00400000) \ - TF_FLAG(tfTwoAssetIfEmpty, 0x00800000), \ + TF_FLAG(kTF_LP_TOKEN, 0x00010000) \ + TF_FLAG(kTF_SINGLE_ASSET, 0x00080000) \ + TF_FLAG(kTF_TWO_ASSET, 0x00100000) \ + TF_FLAG(kTF_ONE_ASSET_LP_TOKEN, 0x00200000) \ + TF_FLAG(kTF_LIMIT_LP_TOKEN, 0x00400000) \ + TF_FLAG(kTF_TWO_ASSET_IF_EMPTY, 0x00800000), \ MASK_ADJ(0)) \ \ TRANSACTION(AMMWithdraw, \ - TF_FLAG2(tfLPToken, 0x00010000) \ - TF_FLAG(tfWithdrawAll, 0x00020000) \ - TF_FLAG(tfOneAssetWithdrawAll, 0x00040000) \ - TF_FLAG2(tfSingleAsset, 0x00080000) \ - TF_FLAG2(tfTwoAsset, 0x00100000) \ - TF_FLAG2(tfOneAssetLPToken, 0x00200000) \ - TF_FLAG2(tfLimitLPToken, 0x00400000), \ + TF_FLAG2(kTF_LP_TOKEN, 0x00010000) \ + TF_FLAG(kTF_WITHDRAW_ALL, 0x00020000) \ + TF_FLAG(kTF_ONE_ASSET_WITHDRAW_ALL, 0x00040000) \ + TF_FLAG2(kTF_SINGLE_ASSET, 0x00080000) \ + TF_FLAG2(kTF_TWO_ASSET, 0x00100000) \ + TF_FLAG2(kTF_ONE_ASSET_LP_TOKEN, 0x00200000) \ + TF_FLAG2(kTF_LIMIT_LP_TOKEN, 0x00400000), \ MASK_ADJ(0)) \ \ TRANSACTION(AMMClawback, \ - TF_FLAG(tfClawTwoAssets, 0x00000001), \ + TF_FLAG(kTF_CLAW_TWO_ASSETS, 0x00000001), \ MASK_ADJ(0)) \ \ TRANSACTION(XChainModifyBridge, \ - TF_FLAG(tfClearAccountCreateAmount, 0x00010000), \ + TF_FLAG(kTF_CLEAR_ACCOUNT_CREATE_AMOUNT, 0x00010000), \ MASK_ADJ(0)) \ \ TRANSACTION(VaultCreate, \ - TF_FLAG(tfVaultPrivate, lsfVaultPrivate) \ - TF_FLAG(tfVaultShareNonTransferable, 0x00020000), \ + TF_FLAG(kTF_VAULT_PRIVATE, LsfVaultPrivate) \ + TF_FLAG(kTF_VAULT_SHARE_NON_TRANSFERABLE, 0x00020000), \ MASK_ADJ(0)) \ \ TRANSACTION(Batch, \ - TF_FLAG(tfAllOrNothing, 0x00010000) \ - TF_FLAG(tfOnlyOne, 0x00020000) \ - TF_FLAG(tfUntilFailure, 0x00040000) \ - TF_FLAG(tfIndependent, 0x00080000), \ - MASK_ADJ(tfInnerBatchTxn)) /* Batch must reject tfInnerBatchTxn - only inner transactions should have this flag */ \ + TF_FLAG(kTF_ALL_OR_NOTHING, 0x00010000) \ + TF_FLAG(kTF_ONLY_ONE, 0x00020000) \ + TF_FLAG(kTF_UNTIL_FAILURE, 0x00040000) \ + TF_FLAG(kTF_INDEPENDENT, 0x00080000), \ + MASK_ADJ(kTF_INNER_BATCH_TXN)) /* Batch must reject tfInnerBatchTxn - only inner transactions should have this flag */ \ \ TRANSACTION(LoanSet, /* True indicates the loan supports overpayments */ \ - TF_FLAG(tfLoanOverpayment, 0x00010000), \ + TF_FLAG(kTF_LOAN_OVERPAYMENT, 0x00010000), \ MASK_ADJ(0)) \ \ TRANSACTION(LoanPay, /* True indicates any excess in this payment can be used as an overpayment. */ \ /* False: no overpayments will be taken. */ \ - TF_FLAG2(tfLoanOverpayment, 0x00010000) \ - TF_FLAG(tfLoanFullPayment, 0x00020000) /* True indicates that the payment is an early full payment. */ \ + TF_FLAG2(kTF_LOAN_OVERPAYMENT, 0x00010000) \ + TF_FLAG(kTF_LOAN_FULL_PAYMENT, 0x00020000) /* True indicates that the payment is an early full payment. */ \ /* It must pay the entire loan including close interest and fees, or it will fail. */ \ /* False: Not a full payment. */ \ - TF_FLAG(tfLoanLatePayment, 0x00040000), /* True indicates that the payment is late, and includes late interest and fees. */ \ + TF_FLAG(kTF_LOAN_LATE_PAYMENT, 0x00040000), /* True indicates that the payment is late, and includes late interest and fees. */ \ /* If the loan is not late, it will fail. */ \ /* False: not a late payment. If the current payment is overdue, the transaction will fail.*/ \ MASK_ADJ(0)) \ \ TRANSACTION(LoanManage, \ - TF_FLAG(tfLoanDefault, 0x00010000) \ - TF_FLAG(tfLoanImpair, 0x00020000) \ - TF_FLAG(tfLoanUnimpair, 0x00040000), \ + TF_FLAG(kTF_LOAN_DEFAULT, 0x00010000) \ + TF_FLAG(kTF_LOAN_IMPAIR, 0x00020000) \ + TF_FLAG(kTF_LOAN_UNIMPAIR, 0x00040000), \ MASK_ADJ(0)) // clang-format on @@ -244,16 +244,16 @@ XMACRO(TO_MASK, VALUE_TO_MASK, VALUE_TO_MASK, MASK_ADJ_TO_MASK) // The outer Batch transaction must NOT have tfInnerBatchTxn set; only inner transactions should // have it. static_assert( - (tfBatchMask & tfInnerBatchTxn) == tfInnerBatchTxn, + (tfBatchMask & kTF_INNER_BATCH_TXN) == kTF_INNER_BATCH_TXN, "tfBatchMask must include tfInnerBatchTxn to reject it on outer Batch"); // Verify that other transaction masks correctly allow tfInnerBatchTxn. // Inner transactions need tfInnerBatchTxn to be valid, so these masks must not reject it. static_assert( - (tfPaymentMask & tfInnerBatchTxn) == 0, + (tfPaymentMask & kTF_INNER_BATCH_TXN) == 0, "tfPaymentMask must not reject tfInnerBatchTxn"); static_assert( - (tfAccountSetMask & tfInnerBatchTxn) == 0, + (tfAccountSetMask & kTF_INNER_BATCH_TXN) == 0, "tfAccountSetMask must not reject tfInnerBatchTxn"); // Create getter functions for each set of flags using Meyer's singleton pattern. @@ -282,9 +282,9 @@ XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP, NULL_MASK_ADJ) inline FlagMap const& getUniversalFlags() { - static FlagMap const flags = { - {"tfFullyCanonicalSig", tfFullyCanonicalSig}, {"tfInnerBatchTxn", tfInnerBatchTxn}}; - return flags; + static FlagMap const kFLAGS = { + {"tfFullyCanonicalSig", kTF_FULLY_CANONICAL_SIG}, {"tfInnerBatchTxn", kTF_INNER_BATCH_TXN}}; + return kFLAGS; } // Create a getter function for all transaction flag maps using Meyer's singleton pattern. @@ -302,10 +302,10 @@ using FlagMapPairList = std::vector>; inline FlagMapPairList const& getAllTxFlags() { - static FlagMapPairList const flags = { + static FlagMapPairList const kFLAGS = { {"universal", getUniversalFlags()}, XMACRO(ALL_TX_FLAGS, NULL_OUTPUT, NULL_OUTPUT, NULL_MASK_ADJ)}; - return flags; + return kFLAGS; } #undef XMACRO @@ -333,44 +333,46 @@ getAllTxFlags() #pragma pop_macro("MASK_ADJ_TO_MASK") // Additional transaction masks and combos -inline constexpr FlagValue tfMPTPaymentMask = ~(tfUniversal | tfPartialPayment); -inline constexpr FlagValue tfTrustSetPermissionMask = - ~(tfUniversal | tfSetfAuth | tfSetFreeze | tfClearFreeze); +inline constexpr FlagValue kTF_MPT_PAYMENT_MASK = ~(tfUniversal | kTF_PARTIAL_PAYMENT); +inline constexpr FlagValue kTF_TRUST_SET_PERMISSION_MASK = + ~(tfUniversal | kTF_SETF_AUTH | kTF_SET_FREEZE | kTF_CLEAR_FREEZE); // MPTokenIssuanceCreate MutableFlags: // Indicating specific fields or flags may be changed after issuance. -inline constexpr FlagValue tmfMPTCanMutateCanLock = lsmfMPTCanMutateCanLock; -inline constexpr FlagValue tmfMPTCanMutateRequireAuth = lsmfMPTCanMutateRequireAuth; -inline constexpr FlagValue tmfMPTCanMutateCanEscrow = lsmfMPTCanMutateCanEscrow; -inline constexpr FlagValue tmfMPTCanMutateCanTrade = lsmfMPTCanMutateCanTrade; -inline constexpr FlagValue tmfMPTCanMutateCanTransfer = lsmfMPTCanMutateCanTransfer; -inline constexpr FlagValue tmfMPTCanMutateCanClawback = lsmfMPTCanMutateCanClawback; -inline constexpr FlagValue tmfMPTCanMutateMetadata = lsmfMPTCanMutateMetadata; -inline constexpr FlagValue tmfMPTCanMutateTransferFee = lsmfMPTCanMutateTransferFee; -inline constexpr FlagValue tmfMPTokenIssuanceCreateMutableMask = - ~(tmfMPTCanMutateCanLock | tmfMPTCanMutateRequireAuth | tmfMPTCanMutateCanEscrow | - tmfMPTCanMutateCanTrade | tmfMPTCanMutateCanTransfer | tmfMPTCanMutateCanClawback | - tmfMPTCanMutateMetadata | tmfMPTCanMutateTransferFee); +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_CAN_LOCK = LsmfMptCanMutateCanLock; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_REQUIRE_AUTH = LsmfMptCanMutateRequireAuth; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_CAN_ESCROW = LsmfMptCanMutateCanEscrow; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_CAN_TRADE = LsmfMptCanMutateCanTrade; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_CAN_TRANSFER = LsmfMptCanMutateCanTransfer; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_CAN_CLAWBACK = LsmfMptCanMutateCanClawback; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_METADATA = LsmfMptCanMutateMetadata; +inline constexpr FlagValue kTMF_MPT_CAN_MUTATE_TRANSFER_FEE = LsmfMptCanMutateTransferFee; +inline constexpr FlagValue kTMF_MP_TOKEN_ISSUANCE_CREATE_MUTABLE_MASK = + ~(kTMF_MPT_CAN_MUTATE_CAN_LOCK | kTMF_MPT_CAN_MUTATE_REQUIRE_AUTH | + kTMF_MPT_CAN_MUTATE_CAN_ESCROW | kTMF_MPT_CAN_MUTATE_CAN_TRADE | + kTMF_MPT_CAN_MUTATE_CAN_TRANSFER | kTMF_MPT_CAN_MUTATE_CAN_CLAWBACK | + kTMF_MPT_CAN_MUTATE_METADATA | kTMF_MPT_CAN_MUTATE_TRANSFER_FEE); // MPTokenIssuanceSet MutableFlags: // Set or Clear flags. -inline constexpr FlagValue tmfMPTSetCanLock = 0x00000001; -inline constexpr FlagValue tmfMPTClearCanLock = 0x00000002; -inline constexpr FlagValue tmfMPTSetRequireAuth = 0x00000004; -inline constexpr FlagValue tmfMPTClearRequireAuth = 0x00000008; -inline constexpr FlagValue tmfMPTSetCanEscrow = 0x00000010; -inline constexpr FlagValue tmfMPTClearCanEscrow = 0x00000020; -inline constexpr FlagValue tmfMPTSetCanTrade = 0x00000040; -inline constexpr FlagValue tmfMPTClearCanTrade = 0x00000080; -inline constexpr FlagValue tmfMPTSetCanTransfer = 0x00000100; -inline constexpr FlagValue tmfMPTClearCanTransfer = 0x00000200; -inline constexpr FlagValue tmfMPTSetCanClawback = 0x00000400; -inline constexpr FlagValue tmfMPTClearCanClawback = 0x00000800; -inline constexpr FlagValue tmfMPTokenIssuanceSetMutableMask = ~( - tmfMPTSetCanLock | tmfMPTClearCanLock | tmfMPTSetRequireAuth | tmfMPTClearRequireAuth | - tmfMPTSetCanEscrow | tmfMPTClearCanEscrow | tmfMPTSetCanTrade | tmfMPTClearCanTrade | - tmfMPTSetCanTransfer | tmfMPTClearCanTransfer | tmfMPTSetCanClawback | tmfMPTClearCanClawback); +inline constexpr FlagValue kTMF_MPT_SET_CAN_LOCK = 0x00000001; +inline constexpr FlagValue kTMF_MPT_CLEAR_CAN_LOCK = 0x00000002; +inline constexpr FlagValue kTMF_MPT_SET_REQUIRE_AUTH = 0x00000004; +inline constexpr FlagValue kTMF_MPT_CLEAR_REQUIRE_AUTH = 0x00000008; +inline constexpr FlagValue kTMF_MPT_SET_CAN_ESCROW = 0x00000010; +inline constexpr FlagValue kTMF_MPT_CLEAR_CAN_ESCROW = 0x00000020; +inline constexpr FlagValue kTMF_MPT_SET_CAN_TRADE = 0x00000040; +inline constexpr FlagValue kTMF_MPT_CLEAR_CAN_TRADE = 0x00000080; +inline constexpr FlagValue kTMF_MPT_SET_CAN_TRANSFER = 0x00000100; +inline constexpr FlagValue kTMF_MPT_CLEAR_CAN_TRANSFER = 0x00000200; +inline constexpr FlagValue kTMF_MPT_SET_CAN_CLAWBACK = 0x00000400; +inline constexpr FlagValue kTMF_MPT_CLEAR_CAN_CLAWBACK = 0x00000800; +inline constexpr FlagValue kTMF_MP_TOKEN_ISSUANCE_SET_MUTABLE_MASK = + ~(kTMF_MPT_SET_CAN_LOCK | kTMF_MPT_CLEAR_CAN_LOCK | kTMF_MPT_SET_REQUIRE_AUTH | + kTMF_MPT_CLEAR_REQUIRE_AUTH | kTMF_MPT_SET_CAN_ESCROW | kTMF_MPT_CLEAR_CAN_ESCROW | + kTMF_MPT_SET_CAN_TRADE | kTMF_MPT_CLEAR_CAN_TRADE | kTMF_MPT_SET_CAN_TRANSFER | + kTMF_MPT_CLEAR_CAN_TRANSFER | kTMF_MPT_SET_CAN_CLAWBACK | kTMF_MPT_CLEAR_CAN_CLAWBACK); // Prior to fixRemoveNFTokenAutoTrustLine, transfer of an NFToken between accounts allowed a // TrustLine to be added to the issuer of that token without explicit permission from that issuer. @@ -383,44 +385,46 @@ inline constexpr FlagValue tmfMPTokenIssuanceSetMutableMask = ~( // The fixRemoveNFTokenAutoTrustLine amendment disables minting with the tfTrustLine flag as a way // to prevent the attack. But until the amendment passes we still need to keep the old behavior // available. -inline constexpr FlagValue tfTrustLine = 0x00000004; // needed for backwards compatibility -inline constexpr FlagValue tfNFTokenMintMaskWithoutMutable = - ~(tfUniversal | tfBurnable | tfOnlyXRP | tfTransferable); +inline constexpr FlagValue kTF_TRUST_LINE = 0x00000004; // needed for backwards compatibility +inline constexpr FlagValue kTF_NF_TOKEN_MINT_MASK_WITHOUT_MUTABLE = + ~(tfUniversal | kTF_BURNABLE | kTF_ONLY_XRP | kTF_TRANSFERABLE); -inline constexpr FlagValue tfNFTokenMintOldMask = ~(~tfNFTokenMintMaskWithoutMutable | tfTrustLine); +inline constexpr FlagValue kTF_NF_TOKEN_MINT_OLD_MASK = + ~(~kTF_NF_TOKEN_MINT_MASK_WITHOUT_MUTABLE | kTF_TRUST_LINE); // if featureDynamicNFT enabled then new flag allowing mutable URI available. -inline constexpr FlagValue tfNFTokenMintOldMaskWithMutable = ~(~tfNFTokenMintOldMask | tfMutable); +inline constexpr FlagValue kTF_NF_TOKEN_MINT_OLD_MASK_WITH_MUTABLE = + ~(~kTF_NF_TOKEN_MINT_OLD_MASK | kTF_MUTABLE); -inline constexpr FlagValue tfWithdrawSubTx = tfLPToken | tfSingleAsset | tfTwoAsset | - tfOneAssetLPToken | tfLimitLPToken | tfWithdrawAll | tfOneAssetWithdrawAll; -inline constexpr FlagValue tfDepositSubTx = - tfLPToken | tfSingleAsset | tfTwoAsset | tfOneAssetLPToken | tfLimitLPToken | tfTwoAssetIfEmpty; +inline constexpr FlagValue kTF_WITHDRAW_SUB_TX = kTF_LP_TOKEN | kTF_SINGLE_ASSET | kTF_TWO_ASSET | + kTF_ONE_ASSET_LP_TOKEN | kTF_LIMIT_LP_TOKEN | kTF_WITHDRAW_ALL | kTF_ONE_ASSET_WITHDRAW_ALL; +inline constexpr FlagValue kTF_DEPOSIT_SUB_TX = kTF_LP_TOKEN | kTF_SINGLE_ASSET | kTF_TWO_ASSET | + kTF_ONE_ASSET_LP_TOKEN | kTF_LIMIT_LP_TOKEN | kTF_TWO_ASSET_IF_EMPTY; #pragma push_macro("ACCOUNTSET_FLAGS") #pragma push_macro("ACCOUNTSET_FLAG_TO_VALUE") #pragma push_macro("ACCOUNTSET_FLAG_TO_MAP") // AccountSet SetFlag/ClearFlag values -#define ACCOUNTSET_FLAGS(ASF_FLAG) \ - ASF_FLAG(asfRequireDest, 1) \ - ASF_FLAG(asfRequireAuth, 2) \ - ASF_FLAG(asfDisallowXRP, 3) \ - ASF_FLAG(asfDisableMaster, 4) \ - ASF_FLAG(asfAccountTxnID, 5) \ - ASF_FLAG(asfNoFreeze, 6) \ - ASF_FLAG(asfGlobalFreeze, 7) \ - ASF_FLAG(asfDefaultRipple, 8) \ - ASF_FLAG(asfDepositAuth, 9) \ - ASF_FLAG(asfAuthorizedNFTokenMinter, 10) \ - /* 11 is reserved for Hooks amendment */ \ - /* ASF_FLAG(asfTshCollect, 11) */ \ - ASF_FLAG(asfDisallowIncomingNFTokenOffer, 12) \ - ASF_FLAG(asfDisallowIncomingCheck, 13) \ - ASF_FLAG(asfDisallowIncomingPayChan, 14) \ - ASF_FLAG(asfDisallowIncomingTrustline, 15) \ - ASF_FLAG(asfAllowTrustLineClawback, 16) \ - ASF_FLAG(asfAllowTrustLineLocking, 17) +#define ACCOUNTSET_FLAGS(ASF_FLAG) \ + ASF_FLAG(kASF_REQUIRE_DEST, 1) \ + ASF_FLAG(kASF_REQUIRE_AUTH, 2) \ + ASF_FLAG(kASF_DISALLOW_XRP, 3) \ + ASF_FLAG(kASF_DISABLE_MASTER, 4) \ + ASF_FLAG(kASF_ACCOUNT_TXN_ID, 5) \ + ASF_FLAG(kASF_NO_FREEZE, 6) \ + ASF_FLAG(kASF_GLOBAL_FREEZE, 7) \ + ASF_FLAG(kASF_DEFAULT_RIPPLE, 8) \ + ASF_FLAG(kASF_DEPOSIT_AUTH, 9) \ + ASF_FLAG(kASF_AUTHORIZED_NF_TOKEN_MINTER, 10) \ + /* 11 is reserved for Hooks amendment */ \ + /* ASF_FLAG(asfTshCollect, 11) */ \ + ASF_FLAG(kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER, 12) \ + ASF_FLAG(kASF_DISALLOW_INCOMING_CHECK, 13) \ + ASF_FLAG(kASF_DISALLOW_INCOMING_PAY_CHAN, 14) \ + ASF_FLAG(kASF_DISALLOW_INCOMING_TRUSTLINE, 15) \ + ASF_FLAG(kASF_ALLOW_TRUST_LINE_CLAWBACK, 16) \ + ASF_FLAG(kASF_ALLOW_TRUST_LINE_LOCKING, 17) #define ACCOUNTSET_FLAG_TO_VALUE(name, value) inline constexpr FlagValue name = value; #define ACCOUNTSET_FLAG_TO_MAP(name, value) {#name, value}, @@ -430,9 +434,9 @@ ACCOUNTSET_FLAGS(ACCOUNTSET_FLAG_TO_VALUE) inline std::map const& getAsfFlagMap() { - static std::map const flags = { + static std::map const kFLAGS = { ACCOUNTSET_FLAGS(ACCOUNTSET_FLAG_TO_MAP)}; - return flags; + return kFLAGS; } #undef ACCOUNTSET_FLAG_TO_VALUE diff --git a/include/xrpl/protocol/TxFormats.h b/include/xrpl/protocol/TxFormats.h index 235fb7b16e..77ab069feb 100644 --- a/include/xrpl/protocol/TxFormats.h +++ b/include/xrpl/protocol/TxFormats.h @@ -51,16 +51,16 @@ enum TxType : std::uint16_t #pragma pop_macro("TRANSACTION") /** This transaction type is deprecated; it is retained for historical purposes. */ - ttNICKNAME_SET [[deprecated("This transaction type is not supported and should not be used.")]] = 6, + TtNicknameSet [[deprecated("This transaction type is not supported and should not be used.")]] = 6, /** This transaction type is deprecated; it is retained for historical purposes. */ - ttCONTRACT [[deprecated("This transaction type is not supported and should not be used.")]] = 9, + TtContract [[deprecated("This transaction type is not supported and should not be used.")]] = 9, /** This identifier was never used, but the slot is reserved for historical purposes. */ - ttSPINAL_TAP [[deprecated("This transaction type is not supported and should not be used.")]] = 11, + TtSpinalTap [[deprecated("This transaction type is not supported and should not be used.")]] = 11, /** This transaction type installs a hook. */ - ttHOOK_SET [[maybe_unused]] = 22, + TtHookSet [[maybe_unused]] = 22, }; // clang-format on diff --git a/include/xrpl/protocol/UintTypes.h b/include/xrpl/protocol/UintTypes.h index fd48244d89..9e033344f0 100644 --- a/include/xrpl/protocol/UintTypes.h +++ b/include/xrpl/protocol/UintTypes.h @@ -30,21 +30,21 @@ public: /** Directory is an index into the directory of offer books. The last 64 bits of this are the quality. */ -using Directory = base_uint<256, detail::DirectoryTag>; +using Directory = BaseUint<256, detail::DirectoryTag>; /** Currency is a hash representing a specific currency. */ -using Currency = base_uint<160, detail::CurrencyTag>; +using Currency = BaseUint<160, detail::CurrencyTag>; /** NodeID is a 160-bit hash representing one node. */ -using NodeID = base_uint<160, detail::NodeIDTag>; +using NodeID = BaseUint<160, detail::NodeIDTag>; /** MPTID is a 192-bit value representing MPT Issuance ID, * which is a concatenation of a 32-bit sequence (big endian) * and a 160-bit account */ -using MPTID = base_uint<192>; +using MPTID = BaseUint<192>; /** Domain is a 256-bit hash representing a specific domain. */ -using Domain = base_uint<256>; +using Domain = BaseUint<256>; /** XRP currency. */ Currency const& @@ -62,7 +62,7 @@ badCurrency(); inline bool isXRP(Currency const& c) { - return c == beast::zero; + return c == beast::kZERO; } /** Returns "", "XRP", or three letter ISO code. */ diff --git a/include/xrpl/protocol/Units.h b/include/xrpl/protocol/Units.h index 8faabd7138..d5b3a24c31 100644 --- a/include/xrpl/protocol/Units.h +++ b/include/xrpl/protocol/Units.h @@ -209,7 +209,7 @@ public: return *this; } - template + template ValueUnit& operator%=(value_type const& rhs) { @@ -300,13 +300,13 @@ public: using jsontype = std::conditional_t, Json::Int, Json::UInt>; - constexpr auto min = std::numeric_limits::min(); - constexpr auto max = std::numeric_limits::max(); + constexpr auto kMIN = std::numeric_limits::min(); + constexpr auto kMAX = std::numeric_limits::max(); - if (value_ < min) - return min; - if (value_ > max) - return max; + if (value_ < kMIN) + return kMIN; + if (value_ > kMAX) + return kMAX; return static_cast(value_); } else @@ -392,14 +392,14 @@ mulDivU(Source1 value, Dest mul, Source2 div) } using desttype = typename Dest::value_type; - constexpr auto max = std::numeric_limits::max(); + constexpr auto kMAX = std::numeric_limits::max(); // Shortcuts, since these happen a lot in the real world if (value == div) return mul; if (mul.value() == div.value()) { - if (value.value() > max) + if (value.value() > kMAX) return std::nullopt; return Dest{static_cast(value.value())}; } @@ -414,7 +414,7 @@ mulDivU(Source1 value, Dest mul, Source2 div) auto quotient = product / div.value(); - if (quotient > max) + if (quotient > kMAX) return std::nullopt; return Dest{static_cast(quotient)}; @@ -494,7 +494,7 @@ mulDiv(std::uint64_t value, Source1 mul, Source2 div) template Src> constexpr Dest -safe_cast(Src s) noexcept +safeCast(Src s) noexcept { // Dest may not have an explicit value constructor return Dest{safe_cast(s.value())}; @@ -502,7 +502,7 @@ safe_cast(Src s) noexcept template constexpr Dest -safe_cast(Src s) noexcept +safeCast(Src s) noexcept { // Dest may not have an explicit value constructor return Dest{safe_cast(s)}; @@ -510,7 +510,7 @@ safe_cast(Src s) noexcept template Src> constexpr Dest -unsafe_cast(Src s) noexcept +unsafeCast(Src s) noexcept { // Dest may not have an explicit value constructor return Dest{unsafe_cast(s.value())}; @@ -518,7 +518,7 @@ unsafe_cast(Src s) noexcept template constexpr Dest -unsafe_cast(Src s) noexcept +unsafeCast(Src s) noexcept { // Dest may not have an explicit value constructor return Dest{unsafe_cast(s)}; diff --git a/include/xrpl/protocol/XChainAttestations.h b/include/xrpl/protocol/XChainAttestations.h index 83bb6267a2..7b0f05cdc8 100644 --- a/include/xrpl/protocol/XChainAttestations.h +++ b/include/xrpl/protocol/XChainAttestations.h @@ -42,13 +42,13 @@ struct AttestationBase bool wasLockingChainSend; explicit AttestationBase( - AccountID attestationSignerAccount_, - PublicKey const& publicKey_, - Buffer signature_, - AccountID const& sendingAccount_, - STAmount sendingAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_); + AccountID attestationSignerAccount, + PublicKey const& publicKey, + Buffer signature, + AccountID const& sendingAccount, + STAmount sendingAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend); AttestationBase(AttestationBase const&) = default; @@ -86,27 +86,27 @@ struct AttestationClaim : AttestationBase std::optional dst; explicit AttestationClaim( - AccountID attestationSignerAccount_, - PublicKey const& publicKey_, - Buffer signature_, - AccountID const& sendingAccount_, - STAmount const& sendingAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, - std::uint64_t claimID_, - std::optional const& dst_); + AccountID attestationSignerAccount, + PublicKey const& publicKey, + Buffer signature, + AccountID const& sendingAccount, + STAmount const& sendingAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend, + std::uint64_t claimId, + std::optional const& dst); explicit AttestationClaim( STXChainBridge const& bridge, - AccountID attestationSignerAccount_, - PublicKey const& publicKey_, - SecretKey const& secretKey_, - AccountID const& sendingAccount_, - STAmount const& sendingAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, - std::uint64_t claimID_, - std::optional const& dst_); + AccountID attestationSignerAccount, + PublicKey const& publicKey, + SecretKey const& secretKey, + AccountID const& sendingAccount, + STAmount const& sendingAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend, + std::uint64_t claimId, + std::optional const& dst); explicit AttestationClaim(STObject const& o); explicit AttestationClaim(Json::Value const& v); @@ -165,29 +165,29 @@ struct AttestationCreateAccount : AttestationBase explicit AttestationCreateAccount(Json::Value const& v); explicit AttestationCreateAccount( - AccountID attestationSignerAccount_, - PublicKey const& publicKey_, - Buffer signature_, - AccountID const& sendingAccount_, - STAmount const& sendingAmount_, - STAmount rewardAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, - std::uint64_t createCount_, - AccountID const& toCreate_); + AccountID attestationSignerAccount, + PublicKey const& publicKey, + Buffer signature, + AccountID const& sendingAccount, + STAmount const& sendingAmount, + STAmount rewardAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend, + std::uint64_t createCount, + AccountID const& toCreate); explicit AttestationCreateAccount( STXChainBridge const& bridge, - AccountID attestationSignerAccount_, - PublicKey const& publicKey_, - SecretKey const& secretKey_, - AccountID const& sendingAccount_, - STAmount const& sendingAmount_, - STAmount const& rewardAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, - std::uint64_t createCount_, - AccountID const& toCreate_); + AccountID attestationSignerAccount, + PublicKey const& publicKey, + SecretKey const& secretKey, + AccountID const& sendingAccount, + STAmount const& sendingAmount, + STAmount const& rewardAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend, + std::uint64_t createCount, + AccountID const& toCreate); [[nodiscard]] STObject toSTObject() const; @@ -232,17 +232,17 @@ struct CmpByCreateCount // Result when checking when two attestation match. enum class AttestationMatch { // One of the fields doesn't match, and it isn't the dst field - nonDstMismatch, + NonDstMismatch, // all of the fields match, except the dst field - matchExceptDst, + MatchExceptDst, // all of the fields match - match + Match }; struct XChainClaimAttestation { using TSignedAttestation = Attestations::AttestationClaim; - static SField const& ArrayFieldName; + static SField const& arrayFieldName; AccountID keyAccount; PublicKey publicKey; @@ -264,19 +264,19 @@ struct XChainClaimAttestation }; explicit XChainClaimAttestation( - AccountID const& keyAccount_, - PublicKey const& publicKey_, - STAmount const& amount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, + AccountID const& keyAccount, + PublicKey const& publicKey, + STAmount const& amount, + AccountID const& rewardAccount, + bool wasLockingChainSend, std::optional const& dst); explicit XChainClaimAttestation( - STAccount const& keyAccount_, - PublicKey const& publicKey_, - STAmount const& amount_, - STAccount const& rewardAccount_, - bool wasLockingChainSend_, + STAccount const& keyAccount, + PublicKey const& publicKey, + STAmount const& amount, + STAccount const& rewardAccount, + bool wasLockingChainSend, std::optional const& dst); explicit XChainClaimAttestation(TSignedAttestation const& claimAtt); @@ -298,7 +298,7 @@ struct XChainClaimAttestation struct XChainCreateAccountAttestation { using TSignedAttestation = Attestations::AttestationCreateAccount; - static SField const& ArrayFieldName; + static SField const& arrayFieldName; AccountID keyAccount; PublicKey publicKey; @@ -319,13 +319,13 @@ struct XChainCreateAccountAttestation }; explicit XChainCreateAccountAttestation( - AccountID const& keyAccount_, - PublicKey const& publicKey_, - STAmount const& amount_, - STAmount const& rewardAmount_, - AccountID const& rewardAccount_, - bool wasLockingChainSend_, - AccountID const& dst_); + AccountID const& keyAccount, + PublicKey const& publicKey, + STAmount const& amount, + STAmount const& rewardAmount, + AccountID const& rewardAccount, + bool wasLockingChainSend, + AccountID const& dst); explicit XChainCreateAccountAttestation(TSignedAttestation const& claimAtt); @@ -357,7 +357,7 @@ private: // Set a max number of allowed attestations to limit the amount of memory // allocated and processing time. This number is much larger than the actual // number of attestation a server would ever expect. - static constexpr std::uint32_t maxAttestations = 256; + static constexpr std::uint32_t kMAX_ATTESTATIONS = 256; AttCollection attestations_; protected: @@ -393,7 +393,7 @@ public: template std::size_t - erase_if(F&& f); + eraseIf(F&& f); [[nodiscard]] std::size_t size() const; @@ -406,7 +406,7 @@ public: template void - emplace_back(T&& att); + emplaceBack(T&& att); }; template @@ -428,7 +428,7 @@ XChainAttestationsBase::attestations() const template template inline void -XChainAttestationsBase::emplace_back(T&& att) +XChainAttestationsBase::emplaceBack(T&& att) { attestations_.emplace_back(std::forward(att)); }; @@ -436,7 +436,7 @@ XChainAttestationsBase::emplace_back(T&& att) template template inline std::size_t -XChainAttestationsBase::erase_if(F&& f) +XChainAttestationsBase::eraseIf(F&& f) { return std::erase_if(attestations_, std::forward(f)); } diff --git a/include/xrpl/protocol/XRPAmount.h b/include/xrpl/protocol/XRPAmount.h index bc7ef891dc..0211b232ee 100644 --- a/include/xrpl/protocol/XRPAmount.h +++ b/include/xrpl/protocol/XRPAmount.h @@ -202,13 +202,13 @@ public: std::is_signed_v && std::is_integral_v, "Expected XRPAmount to be a signed integral type"); - constexpr auto min = std::numeric_limits::min(); - constexpr auto max = std::numeric_limits::max(); + constexpr auto kMIN = std::numeric_limits::min(); + constexpr auto kMAX = std::numeric_limits::max(); - if (drops_ < min) - return min; - if (drops_ > max) - return max; + if (drops_ < kMIN) + return kMIN; + if (drops_ > kMAX) + return kMAX; return static_cast(drops_); } @@ -237,12 +237,12 @@ public: }; /** Number of drops per 1 XRP */ -constexpr XRPAmount DROPS_PER_XRP{1'000'000}; +constexpr XRPAmount kDROPS_PER_XRP{1'000'000}; constexpr double XRPAmount::decimalXRP() const { - return static_cast(drops_) / DROPS_PER_XRP.drops(); + return static_cast(drops_) / kDROPS_PER_XRP.drops(); } // Output XRPAmount as just the drops value. diff --git a/include/xrpl/protocol/detail/STVar.h b/include/xrpl/protocol/detail/STVar.h index c819740a90..a361308c71 100644 --- a/include/xrpl/protocol/detail/STVar.h +++ b/include/xrpl/protocol/detail/STVar.h @@ -9,18 +9,18 @@ namespace xrpl::detail { -struct defaultObject_t +struct DefaultObjectT { - explicit defaultObject_t() = default; + explicit DefaultObjectT() = default; }; -struct nonPresentObject_t +struct NonPresentObjectT { - explicit nonPresentObject_t() = default; + explicit NonPresentObjectT() = default; }; -extern defaultObject_t defaultObject; -extern nonPresentObject_t nonPresentObject; +extern DefaultObjectT gDefaultObject; +extern NonPresentObjectT gNonPresentObject; // Concept to constrain STVar constructors, which // instantiate ST* types from SerializedTypeID @@ -35,9 +35,9 @@ class STVar { private: // The largest "small object" we can accommodate - static std::size_t constexpr max_size = 72; + static std::size_t constexpr kMAX_SIZE = 72; - std::aligned_storage::type d_ = {}; + std::aligned_storage::type d_ = {}; STBase* p_ = nullptr; public: @@ -51,16 +51,16 @@ public: STVar(STBase&& t) // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved) { - p_ = t.move(max_size, &d_); + p_ = t.move(kMAX_SIZE, &d_); } STVar(STBase const& t) { - p_ = t.copy(max_size, &d_); + p_ = t.copy(kMAX_SIZE, &d_); } - STVar(defaultObject_t, SField const& name); - STVar(nonPresentObject_t, SField const& name); + STVar(DefaultObjectT, SField const& name); + STVar(NonPresentObjectT, SField const& name); STVar(SerialIter& sit, SField const& name, int depth = 0); STBase& @@ -110,7 +110,7 @@ private: void construct(Args&&... args) { - if constexpr (sizeof(T) > max_size) + if constexpr (sizeof(T) > kMAX_SIZE) { p_ = new T(std::forward(args)...); } @@ -130,7 +130,7 @@ private: constructST(SerializedTypeID id, int depth, Args&&... arg); [[nodiscard]] bool - on_heap() const + onHeap() const { return static_cast(p_) != static_cast(&d_); } diff --git a/include/xrpl/protocol/detail/token_errors.h b/include/xrpl/protocol/detail/token_errors.h index a663d145b1..cd5fcf9768 100644 --- a/include/xrpl/protocol/detail/token_errors.h +++ b/include/xrpl/protocol/detail/token_errors.h @@ -4,16 +4,16 @@ namespace xrpl { enum class TokenCodecErrc { - success = 0, - inputTooLarge, - inputTooSmall, - badB58Character, - outputTooSmall, - mismatchedTokenType, - mismatchedChecksum, - invalidEncodingChar, - overflowAdd, - unknown, + Success = 0, + InputTooLarge, + InputTooSmall, + BadB58Character, + OutputTooSmall, + MismatchedTokenType, + MismatchedChecksum, + InvalidEncodingChar, + OverflowAdd, + Unknown, }; } // namespace xrpl @@ -41,23 +41,23 @@ public: { switch (static_cast(c)) { - case TokenCodecErrc::success: + case TokenCodecErrc::Success: return "conversion successful"; - case TokenCodecErrc::inputTooLarge: + case TokenCodecErrc::InputTooLarge: return "input too large"; - case TokenCodecErrc::inputTooSmall: + case TokenCodecErrc::InputTooSmall: return "input too small"; - case TokenCodecErrc::badB58Character: + case TokenCodecErrc::BadB58Character: return "bad base 58 character"; - case TokenCodecErrc::outputTooSmall: + case TokenCodecErrc::OutputTooSmall: return "output too small"; - case TokenCodecErrc::mismatchedTokenType: + case TokenCodecErrc::MismatchedTokenType: return "mismatched token type"; - case TokenCodecErrc::mismatchedChecksum: + case TokenCodecErrc::MismatchedChecksum: return "mismatched checksum"; - case TokenCodecErrc::invalidEncodingChar: + case TokenCodecErrc::InvalidEncodingChar: return "invalid encoding char"; - case TokenCodecErrc::unknown: + case TokenCodecErrc::Unknown: return "unknown"; default: return "unknown"; @@ -69,8 +69,8 @@ public: inline xrpl::detail::TokenCodecErrcCategory const& TokenCodecErrcCategory() { - static xrpl::detail::TokenCodecErrcCategory const c; - return c; + static xrpl::detail::TokenCodecErrcCategory const kC; + return kC; } inline std::error_code diff --git a/include/xrpl/protocol/digest.h b/include/xrpl/protocol/digest.h index bbb38fa543..e93a277da0 100644 --- a/include/xrpl/protocol/digest.h +++ b/include/xrpl/protocol/digest.h @@ -24,14 +24,14 @@ namespace xrpl { @note This uses the OpenSSL implementation */ -struct openssl_ripemd160_hasher +struct OpensslRipemd160Hasher { public: - static constexpr auto const endian = boost::endian::order::native; + static constexpr auto const kENDIAN = boost::endian::order::native; using result_type = std::array; - openssl_ripemd160_hasher(); + OpensslRipemd160Hasher(); void operator()(void const* data, std::size_t size) noexcept; @@ -47,14 +47,14 @@ private: @note This uses the OpenSSL implementation */ -struct openssl_sha512_hasher +struct OpensslSha512Hasher { public: - static constexpr auto const endian = boost::endian::order::native; + static constexpr auto const kENDIAN = boost::endian::order::native; using result_type = std::array; - openssl_sha512_hasher(); + OpensslSha512Hasher(); void operator()(void const* data, std::size_t size) noexcept; @@ -70,14 +70,14 @@ private: @note This uses the OpenSSL implementation */ -struct openssl_sha256_hasher +struct OpensslSha256Hasher { public: - static constexpr auto const endian = boost::endian::order::native; + static constexpr auto const kENDIAN = boost::endian::order::native; using result_type = std::array; - openssl_sha256_hasher(); + OpensslSha256Hasher(); void operator()(void const* data, std::size_t size) noexcept; @@ -91,9 +91,9 @@ private: //------------------------------------------------------------------------------ -using ripemd160_hasher = openssl_ripemd160_hasher; -using sha256_hasher = openssl_sha256_hasher; -using sha512_hasher = openssl_sha512_hasher; +using ripemd160_hasher = OpensslRipemd160Hasher; +using sha256_hasher = OpensslSha256Hasher; +using sha512_hasher = OpensslSha512Hasher; //------------------------------------------------------------------------------ @@ -112,13 +112,13 @@ using sha512_hasher = openssl_sha512_hasher; Meets the requirements of Hasher (in hash_append) */ -struct ripesha_hasher +struct RipeshaHasher { private: sha256_hasher h_; public: - static constexpr auto const endian = boost::endian::order::native; + static constexpr auto const kENDIAN = boost::endian::order::native; using result_type = std::array; @@ -148,7 +148,7 @@ namespace detail { SHA-512 digest of the message. */ template -struct basic_sha512_half_hasher +struct BasicSha512HalfHasher { private: sha512_hasher h_; @@ -158,7 +158,7 @@ public: using result_type = uint256; - ~basic_sha512_half_hasher() + ~BasicSha512HalfHasher() { erase(std::integral_constant{}); } @@ -191,10 +191,10 @@ private: } // namespace detail -using sha512_half_hasher = detail::basic_sha512_half_hasher; +using sha512_half_hasher = detail::BasicSha512HalfHasher; // secure version -using sha512_half_hasher_s = detail::basic_sha512_half_hasher; +using sha512_half_hasher_s = detail::BasicSha512HalfHasher; //------------------------------------------------------------------------------ diff --git a/include/xrpl/protocol/json_get_or_throw.h b/include/xrpl/protocol/json_get_or_throw.h index 949fb64cf2..fe5e3f3dbb 100644 --- a/include/xrpl/protocol/json_get_or_throw.h +++ b/include/xrpl/protocol/json_get_or_throw.h @@ -15,7 +15,7 @@ struct JsonMissingKeyError : std::exception { char const* const key; mutable std::string msg; - JsonMissingKeyError(Json::StaticString const& k) : key{k.c_str()} + JsonMissingKeyError(Json::StaticString const& k) : key{k.cStr()} { } char const* @@ -35,7 +35,7 @@ struct JsonTypeMismatchError : std::exception std::string const expectedType; mutable std::string msg; JsonTypeMismatchError(Json::StaticString const& k, std::string et) - : key{k.c_str()}, expectedType{std::move(et)} + : key{k.cStr()}, expectedType{std::move(et)} { } char const* diff --git a/include/xrpl/protocol/jss.h b/include/xrpl/protocol/jss.h index 0e94285be9..2a6ef77b0f 100644 --- a/include/xrpl/protocol/jss.h +++ b/include/xrpl/protocol/jss.h @@ -20,662 +20,662 @@ namespace xrpl::jss { error: Common properties of RPC error responses. */ -JSS(AL_size); // out: GetCounts -JSS(AL_hit_rate); // out: GetCounts -JSS(AcceptedCredentials); // out: AccountObjects -JSS(ACCOUNT_SET_FLAGS); // out: RPC server_definitions -JSS(Account); // in: TransactionSign; field. -JSS(AMMID); // field -JSS(Amount); // in: TransactionSign; field. -JSS(Amount2); // in/out: AMM IOU/XRP pool, deposit, withdraw amount -JSS(Asset); // in: AMM Asset1 -JSS(Asset2); // in: AMM Asset2 -JSS(AssetClass); // in: Oracle -JSS(AssetPrice); // in: Oracle -JSS(AuthAccount); // in: AMM Auction Slot -JSS(AuthAccounts); // in: AMM Auction Slot -JSS(BaseAsset); // in: Oracle -JSS(BidMax); // in: AMM Bid -JSS(BidMin); // in: AMM Bid -JSS(ClearFlag); // field. -JSS(Counterparty); // field. -JSS(CounterpartySignature); // field. -JSS(DeliverMax); // out: alias to Amount -JSS(DeliverMin); // in: TransactionSign -JSS(Destination); // in: TransactionSign; field. -JSS(EPrice); // in: AMM Deposit option -JSS(Fee); // in/out: TransactionSign; field. -JSS(Flags); // in/out: TransactionSign; field. -JSS(Holder); // field. -JSS(Invalid); // -JSS(Issuer); // in: Credential transactions -JSS(IssuingChainDoor); // field. -JSS(IssuingChainIssue); // field. -JSS(LastLedgerSequence); // in: TransactionSign; field -JSS(LastUpdateTime); // field. -JSS(LimitAmount); // field. -JSS(LockingChainDoor); // field. -JSS(LockingChainIssue); // field. -JSS(NetworkID); // field. -JSS(LPTokenOut); // in: AMM Liquidity Provider deposit tokens -JSS(LPTokenIn); // in: AMM Liquidity Provider withdraw tokens -JSS(LPToken); // out: AMM Liquidity Provider tokens info -JSS(OfferSequence); // field. -JSS(OracleDocumentID); // field -JSS(Owner); // field -JSS(Paths); // in/out: TransactionSign -JSS(PriceDataSeries); // field. -JSS(PriceData); // field. -JSS(Provider); // field. -JSS(QuoteAsset); // in: Oracle. -JSS(RawTransaction); // in: Batch -JSS(RawTransactions); // in: Batch -JSS(SLE_hit_rate); // out: GetCounts. -JSS(Scale); // field. -JSS(SettleDelay); // in: TransactionSign -JSS(SendMax); // in: TransactionSign -JSS(Sequence); // in/out: TransactionSign; field. -JSS(SetFlag); // field. -JSS(Signer); // field. -JSS(Signers); // field. -JSS(SigningPubKey); // field. -JSS(Subject); // in: Credential transactions -JSS(TakerGets); // field. -JSS(TakerPays); // field. -JSS(TradingFee); // in/out: AMM trading fee -JSS(TransactionType); // in: TransactionSign. -JSS(TransferRate); // in: TransferRate. -JSS(TxnSignature); // field. -JSS(URI); // field. -JSS(VoteSlots); // out: AMM Vote -JSS(aborted); // out: InboundLedger -JSS(accepted); // out: LedgerToJson, OwnerInfo, SubmitTransaction -JSS(accountState); // out: LedgerToJson -JSS(accountTreeHash); // out: ledger/Ledger.cpp -JSS(account_data); // out: AccountInfo -JSS(account_flags); // out: AccountInfo -JSS(account_hash); // out: LedgerToJson -JSS(account_id); // out: WalletPropose -JSS(account_nfts); // out: AccountNFTs -JSS(account_objects); // out: AccountObjects -JSS(account_root); // in: LedgerEntry -JSS(account_sequence_next); // out: SubmitTransaction -JSS(account_sequence_available); // out: SubmitTransaction -JSS(account_history_tx_stream); // in: Subscribe, Unsubscribe -JSS(account_history_tx_index); // out: Account txn history subscribe -JSS(account_history_tx_first); // out: Account txn history subscribe -JSS(account_history_boundary); // out: Account txn history subscribe -JSS(accounts); // in: LedgerEntry, Subscribe, handlers/Ledger, Unsubscribe -JSS(accounts_proposed); // in: Subscribe, Unsubscribe -JSS(action); // -JSS(active); // out: OverlayImpl -JSS(acquiring); // out: LedgerRequest -JSS(address); // out: PeerImp -JSS(affected); // out: AcceptedLedgerTx -JSS(age); // out: NetworkOPs, Peers -JSS(alternatives); // out: PathRequest, RipplePathFind -JSS(amendment_blocked); // out: NetworkOPs -JSS(amm_account); // in: amm_info -JSS(amount); // out: AccountChannels, amm_info -JSS(amount2); // out: amm_info -JSS(api_version); // in: many, out: Version -JSS(api_version_low); // out: Version -JSS(applied); // out: SubmitTransaction -JSS(asks); // out: Subscribe -JSS(asset); // in: amm_info -JSS(asset2); // in: amm_info -JSS(assets); // out: GatewayBalances -JSS(asset_frozen); // out: amm_info -JSS(asset2_frozen); // out: amm_info -JSS(attestations); // -JSS(attestation_reward_account); // -JSS(auction_slot); // out: amm_info -JSS(authorized); // out: AccountLines -JSS(authorize); // out: delegate -JSS(authorized_credentials); // in: ledger_entry DepositPreauth -JSS(auth_accounts); // out: amm_info -JSS(auth_change); // out: AccountInfo -JSS(auth_change_queued); // out: AccountInfo -JSS(available); // out: ValidatorList -JSS(avg_bps_recv); // out: Peers -JSS(avg_bps_sent); // out: Peers -JSS(balance); // out: AccountLines -JSS(balances); // out: GatewayBalances -JSS(base); // out: LogLevel -JSS(base_asset); // in: get_aggregate_price -JSS(base_fee); // out: NetworkOPs -JSS(base_fee_xrp); // out: NetworkOPs -JSS(bids); // out: Subscribe -JSS(binary); // in: AccountTX, LedgerEntry, AccountTxOld, Tx LedgerData -JSS(blob); // out: ValidatorList -JSS(blobs_v2); // out: ValidatorList - // in: UNL -JSS(books); // in: Subscribe, Unsubscribe -JSS(both); // in: Subscribe, Unsubscribe -JSS(both_sides); // in: Subscribe, Unsubscribe -JSS(branch); // out: server_info -JSS(broadcast); // out: SubmitTransaction -JSS(bridge_account); // in: LedgerEntry -JSS(build_path); // in: TransactionSign -JSS(build_version); // out: NetworkOPs -JSS(cancel_after); // out: AccountChannels -JSS(can_delete); // out: CanDelete -JSS(mpt_amount); // out: mpt_holders -JSS(mpt_issuance_id); // in: Payment, mpt_holders -JSS(mptoken_index); // out: mpt_holders -JSS(changes); // out: BookChanges -JSS(channel_id); // out: AccountChannels -JSS(channels); // out: AccountChannels -JSS(check_nodes); // in: LedgerCleaner -JSS(clear); // in/out: FetchInfo -JSS(close); // out: BookChanges -JSS(close_flags); // out: LedgerToJson -JSS(close_time); // in: Application, out: NetworkOPs, RCLCxPeerPos, LedgerToJson -JSS(close_time_iso); // out: Tx, NetworkOPs, TransactionEntry AccountTx, LedgerToJson -JSS(close_time_estimated); // in: Application, out: LedgerToJson -JSS(close_time_human); // out: LedgerToJson -JSS(close_time_offset); // out: NetworkOPs -JSS(close_time_resolution); // in: Application; out: LedgerToJson -JSS(closed); // out: NetworkOPs, LedgerToJson, handlers/Ledger -JSS(closed_ledger); // out: NetworkOPs -JSS(cluster); // out: PeerImp -JSS(code); // out: errors -JSS(command); // in: RPCHandler -JSS(common); // out: RPC server_definitions -JSS(complete); // out: NetworkOPs, InboundLedger -JSS(complete_ledgers); // out: NetworkOPs, PeerImp -JSS(consensus); // out: NetworkOPs, LedgerConsensus -JSS(converge_time); // out: NetworkOPs -JSS(converge_time_s); // out: NetworkOPs -JSS(cookie); // out: NetworkOPs -JSS(count); // in: AccountTx*, ValidatorList -JSS(counters); // in/out: retrieve counters -JSS(credentials); // in: deposit_authorized -JSS(credential_type); // in: LedgerEntry DepositPreauth -JSS(ctid); // in/out: Tx RPC -JSS(currency_a); // out: BookChanges -JSS(currency_b); // out: BookChanges -JSS(currency); // in: paths/PathRequest, STAmount - // out: STPathSet, STAmount, AccountLines -JSS(current); // out: OwnerInfo -JSS(current_activities); // -JSS(current_ledger_size); // out: TxQ -JSS(current_queue_size); // out: TxQ -JSS(data); // out: LedgerData -JSS(date); // out: tx/Transaction, NetworkOPs -JSS(dbKBLedger); // out: getCounts -JSS(dbKBTotal); // out: getCounts -JSS(dbKBTransaction); // out: getCounts -JSS(debug_signing); // in: TransactionSign -JSS(deletion_blockers_only); // in: AccountObjects -JSS(delivered_amount); // out: insertDeliveredAmount -JSS(deposit_authorized); // out: deposit_authorized -JSS(deprecated); // -JSS(descending); // in: AccountTx* -JSS(description); // in/out: Reservations -JSS(destination); // in: nft_buy_offers, nft_sell_offers -JSS(destination_account); // in: PathRequest, RipplePathFind, account_lines - // out: AccountChannels -JSS(destination_amount); // in: PathRequest, RipplePathFind -JSS(destination_currencies); // in: PathRequest, RipplePathFind -JSS(destination_tag); // in: PathRequest - // out: AccountChannels -JSS(details); // out: Manifest, server_info -JSS(dir_entry); // out: DirectoryEntryIterator -JSS(dir_index); // out: DirectoryEntryIterator -JSS(dir_root); // out: DirectoryEntryIterator -JSS(discounted_fee); // out: amm_info -JSS(domain); // out: ValidatorInfo, Manifest -JSS(drops); // out: TxQ -JSS(duration_us); // out: NetworkOPs -JSS(effective); // out: ValidatorList - // in: UNL -JSS(enabled); // out: AmendmentTable -JSS(engine_result); // out: NetworkOPs, TransactionSign, Submit -JSS(engine_result_code); // out: NetworkOPs, TransactionSign, Submit -JSS(engine_result_message); // out: NetworkOPs, TransactionSign, Submit -JSS(entire_set); // out: get_aggregate_price -JSS(ephemeral_key); // out: ValidatorInfo - // in/out: Manifest -JSS(error); // out: error -JSS(errored); // -JSS(error_code); // out: error -JSS(error_exception); // out: Submit -JSS(error_message); // out: error -JSS(expand); // in: handler/Ledger -JSS(expected_date); // out: any (warnings) -JSS(expected_date_UTC); // out: any (warnings) -JSS(expected_ledger_size); // out: TxQ -JSS(expiration); // out: AccountOffers, AccountChannels, ValidatorList, amm_info -JSS(fail_hard); // in: Sign, Submit -JSS(failed); // out: InboundLedger -JSS(feature); // in: Feature -JSS(features); // out: Feature -JSS(fee_base); // out: NetworkOPs -JSS(fee_div_max); // in: TransactionSign -JSS(fee_level); // out: AccountInfo -JSS(fee_mult_max); // in: TransactionSign -JSS(fee_ref); // out: NetworkOPs, DEPRECATED -JSS(fetch_pack); // out: NetworkOPs -JSS(FIELDS); // out: RPC server_definitions - // matches definitions.json format -JSS(first); // out: rpc/Version -JSS(finished); // -JSS(fix_txns); // in: LedgerCleaner -JSS(flags); // out: AccountOffers, NetworkOPs -JSS(forward); // in: AccountTx -JSS(freeze); // out: AccountLines -JSS(freeze_peer); // out: AccountLines -JSS(deep_freeze); // out: AccountLines -JSS(deep_freeze_peer); // out: AccountLines -JSS(frozen_balances); // out: GatewayBalances -JSS(full); // in: LedgerClearer, handlers/Ledger -JSS(full_reply); // out: PathFind -JSS(fullbelow_size); // out: GetCounts -JSS(git); // out: server_info -JSS(good); // out: RPCVersion -JSS(hash); // out: NetworkOPs, InboundLedger, LedgerToJson, STTx; field -JSS(have_header); // out: InboundLedger -JSS(have_state); // out: InboundLedger -JSS(have_transactions); // out: InboundLedger -JSS(high); // out: BookChanges -JSS(highest_sequence); // out: AccountInfo -JSS(highest_ticket); // out: AccountInfo -JSS(historical_perminute); // historical_perminute. -JSS(holders); // out: MPTHolders -JSS(hostid); // out: NetworkOPs -JSS(hotwallet); // in: GatewayBalances -JSS(id); // websocket. -JSS(ident); // in: AccountCurrencies, AccountInfo, OwnerInfo -JSS(ignore_default); // in: AccountLines -JSS(in); // out: OverlayImpl -JSS(inLedger); // out: tx/Transaction -JSS(inbound); // out: PeerImp -JSS(index); // in: LedgerEntry - // out: STLedgerEntry, LedgerEntry, TxHistory, LedgerData -JSS(info); // out: ServerInfo, ConsensusInfo, FetchInfo -JSS(initial_sync_duration_us); // -JSS(internal_command); // in: Internal -JSS(invalid_API_version); // out: Many, when a request has an invalid version -JSS(io_latency_ms); // out: NetworkOPs -JSS(ip); // in: Connect, out: OverlayImpl -JSS(is_burned); // out: nft_info (clio) -JSS(isSerialized); // out: RPC server_definitions - // matches definitions.json format -JSS(isSigningField); // out: RPC server_definitions - // matches definitions.json format -JSS(isVLEncoded); // out: RPC server_definitions - // matches definitions.json format -JSS(issuer); // in: RipplePathFind, Subscribe, Unsubscribe, BookOffers - // out: STPathSet, STAmount -JSS(job); // -JSS(job_queue); // -JSS(jobs); // -JSS(jsonrpc); // json version -JSS(jq_trans_overflow); // JobQueue transaction limit overflow. -JSS(kept); // out: SubmitTransaction -JSS(key); // out -JSS(key_type); // in/out: WalletPropose, TransactionSign -JSS(latency); // out: PeerImp -JSS(last); // out: RPCVersion -JSS(last_close); // out: NetworkOPs -JSS(last_refresh_time); // out: ValidatorSite -JSS(last_refresh_status); // out: ValidatorSite -JSS(last_refresh_message); // out: ValidatorSite -JSS(ledger); // in: NetworkOPs, LedgerCleaner, RPCHelpers - // out: NetworkOPs, PeerImp -JSS(ledger_current_index); // out: NetworkOPs, RPCHelpers, LedgerCurrent, LedgerAccept, - // AccountLines -JSS(ledger_data); // out: LedgerHeader -JSS(ledger_hash); // in: RPCHelpers, LedgerRequest, RipplePathFind, - // TransactionEntry, handlers/Ledger - // out: NetworkOPs, RPCHelpers, LedgerClosed, LedgerData, - // AccountLines -JSS(ledger_hit_rate); // out: GetCounts -JSS(ledger_index); // in/out: many -JSS(ledger_index_max); // in, out: AccountTx* -JSS(ledger_index_min); // in, out: AccountTx* -JSS(ledger_max); // in, out: AccountTx* -JSS(ledger_min); // in, out: AccountTx* -JSS(ledger_time); // out: NetworkOPs -JSS(LEDGER_ENTRY_TYPES); // out: RPC server_definitions - // matches definitions.json format -JSS(LEDGER_ENTRY_FLAGS); // out: RPC server_definitions -JSS(LEDGER_ENTRY_FORMATS); // out: RPC server_definitions -JSS(levels); // LogLevels -JSS(limit); // in/out: AccountTx*, AccountOffers, AccountLines, AccountObjects - // in: LedgerData, BookOffers -JSS(limit_peer); // out: AccountLines -JSS(lines); // out: AccountLines -JSS(list); // out: ValidatorList -JSS(load); // out: NetworkOPs, PeerImp -JSS(load_base); // out: NetworkOPs -JSS(load_factor); // out: NetworkOPs -JSS(load_factor_cluster); // out: NetworkOPs -JSS(load_factor_fee_escalation); // out: NetworkOPs -JSS(load_factor_fee_queue); // out: NetworkOPs -JSS(load_factor_fee_reference); // out: NetworkOPs -JSS(load_factor_local); // out: NetworkOPs -JSS(load_factor_net); // out: NetworkOPs -JSS(load_factor_server); // out: NetworkOPs -JSS(load_fee); // out: LoadFeeTrackImp, NetworkOPs -JSS(loan_broker_id); // in: LedgerEntry -JSS(loan_seq); // in: LedgerEntry -JSS(local); // out: resource/Logic.h -JSS(local_txs); // out: GetCounts -JSS(local_static_keys); // out: ValidatorList -JSS(locked); // out: GatewayBalances -JSS(low); // out: BookChanges -JSS(lowest_sequence); // out: AccountInfo -JSS(lowest_ticket); // out: AccountInfo -JSS(lp_token); // out: amm_info -JSS(majority); // out: RPC feature -JSS(manifest); // out: ValidatorInfo, Manifest -JSS(marker); // in/out: AccountTx, AccountOffers, AccountLines, AccountObjects, +JSS(kAL_SIZE); // out: GetCounts +JSS(kAL_HIT_RATE); // out: GetCounts +JSS(kACCEPTED_CREDENTIALS); // out: AccountObjects +JSS(kACCOUNT_SET_FLAGS); // out: RPC server_definitions +JSS(kACCOUNT); // in: TransactionSign; field. +JSS(kAMMID); // field +JSS(kAMOUNT); // in: TransactionSign; field. +JSS(kAMOUNT2); // in/out: AMM IOU/XRP pool, deposit, withdraw amount +JSS(kASSET); // in: AMM Asset1 +JSS(kASSET2); // in: AMM Asset2 +JSS(kASSET_CLASS); // in: Oracle +JSS(kASSET_PRICE); // in: Oracle +JSS(kAUTH_ACCOUNT); // in: AMM Auction Slot +JSS(kAUTH_ACCOUNTS); // in: AMM Auction Slot +JSS(kBASE_ASSET); // in: Oracle +JSS(kBID_MAX); // in: AMM Bid +JSS(kBID_MIN); // in: AMM Bid +JSS(kCLEAR_FLAG); // field. +JSS(kCOUNTERPARTY); // field. +JSS(kCOUNTERPARTY_SIGNATURE); // field. +JSS(kDELIVER_MAX); // out: alias to Amount +JSS(kDELIVER_MIN); // in: TransactionSign +JSS(kDESTINATION); // in: TransactionSign; field. +JSS(kE_PRICE); // in: AMM Deposit option +JSS(kFEE); // in/out: TransactionSign; field. +JSS(kFLAGS); // in/out: TransactionSign; field. +JSS(kHOLDER); // field. +JSS(kINVALID); // +JSS(kISSUER); // in: Credential transactions +JSS(kISSUING_CHAIN_DOOR); // field. +JSS(kISSUING_CHAIN_ISSUE); // field. +JSS(kLAST_LEDGER_SEQUENCE); // in: TransactionSign; field +JSS(kLAST_UPDATE_TIME); // field. +JSS(kLIMIT_AMOUNT); // field. +JSS(kLOCKING_CHAIN_DOOR); // field. +JSS(kLOCKING_CHAIN_ISSUE); // field. +JSS(kNETWORK_ID); // field. +JSS(kLP_TOKEN_OUT); // in: AMM Liquidity Provider deposit tokens +JSS(kLP_TOKEN_IN); // in: AMM Liquidity Provider withdraw tokens +JSS(kLP_TOKEN); // out: AMM Liquidity Provider tokens info +JSS(kOFFER_SEQUENCE); // field. +JSS(kORACLE_DOCUMENT_ID); // field +JSS(kOWNER); // field +JSS(kPATHS); // in/out: TransactionSign +JSS(kPRICE_DATA_SERIES); // field. +JSS(kPRICE_DATA); // field. +JSS(kPROVIDER); // field. +JSS(kQUOTE_ASSET); // in: Oracle. +JSS(kRAW_TRANSACTION); // in: Batch +JSS(kRAW_TRANSACTIONS); // in: Batch +JSS(kSLE_HIT_RATE); // out: GetCounts. +JSS(kSCALE); // field. +JSS(kSETTLE_DELAY); // in: TransactionSign +JSS(kSEND_MAX); // in: TransactionSign +JSS(kSEQUENCE); // in/out: TransactionSign; field. +JSS(kSET_FLAG); // field. +JSS(kSIGNER); // field. +JSS(kSIGNERS); // field. +JSS(kSIGNING_PUB_KEY); // field. +JSS(kSUBJECT); // in: Credential transactions +JSS(kTAKER_GETS); // field. +JSS(kTAKER_PAYS); // field. +JSS(kTRADING_FEE); // in/out: AMM trading fee +JSS(kTRANSACTION_TYPE); // in: TransactionSign. +JSS(kTRANSFER_RATE); // in: TransferRate. +JSS(kTXN_SIGNATURE); // field. +JSS(kURI); // field. +JSS(kVOTE_SLOTS); // out: AMM Vote +JSS(kABORTED); // out: InboundLedger +JSS(kACCEPTED); // out: LedgerToJson, OwnerInfo, SubmitTransaction +JSS(kACCOUNT_STATE); // out: LedgerToJson +JSS(kACCOUNT_TREE_HASH); // out: ledger/Ledger.cpp +JSS(kACCOUNT_DATA); // out: AccountInfo +JSS(kACCOUNT_FLAGS); // out: AccountInfo +JSS(kACCOUNT_HASH); // out: LedgerToJson +JSS(kACCOUNT_ID); // out: WalletPropose +JSS(kACCOUNT_NFTS); // out: AccountNFTs +JSS(kACCOUNT_OBJECTS); // out: AccountObjects +JSS(kACCOUNT_ROOT); // in: LedgerEntry +JSS(kACCOUNT_SEQUENCE_NEXT); // out: SubmitTransaction +JSS(kACCOUNT_SEQUENCE_AVAILABLE); // out: SubmitTransaction +JSS(kACCOUNT_HISTORY_TX_STREAM); // in: Subscribe, Unsubscribe +JSS(kACCOUNT_HISTORY_TX_INDEX); // out: Account txn history subscribe +JSS(kACCOUNT_HISTORY_TX_FIRST); // out: Account txn history subscribe +JSS(kACCOUNT_HISTORY_BOUNDARY); // out: Account txn history subscribe +JSS(kACCOUNTS); // in: LedgerEntry, Subscribe, handlers/Ledger, Unsubscribe +JSS(kACCOUNTS_PROPOSED); // in: Subscribe, Unsubscribe +JSS(kACTION); // +JSS(kACTIVE); // out: OverlayImpl +JSS(kACQUIRING); // out: LedgerRequest +JSS(kADDRESS); // out: PeerImp +JSS(kAFFECTED); // out: AcceptedLedgerTx +JSS(kAGE); // out: NetworkOPs, Peers +JSS(kALTERNATIVES); // out: PathRequest, RipplePathFind +JSS(kAMENDMENT_BLOCKED); // out: NetworkOPs +JSS(kAMM_ACCOUNT); // in: amm_info +JSS(kAMOUNT); // out: AccountChannels, amm_info +JSS(kAMOUNT2); // out: amm_info +JSS(kAPI_VERSION); // in: many, out: Version +JSS(kAPI_VERSION_LOW); // out: Version +JSS(kAPPLIED); // out: SubmitTransaction +JSS(kASKS); // out: Subscribe +JSS(kASSET); // in: amm_info +JSS(kASSET2); // in: amm_info +JSS(kASSETS); // out: GatewayBalances +JSS(kASSET_FROZEN); // out: amm_info +JSS(kASSET2_FROZEN); // out: amm_info +JSS(kATTESTATIONS); // +JSS(kATTESTATION_REWARD_ACCOUNT); // +JSS(kAUCTION_SLOT); // out: amm_info +JSS(kAUTHORIZED); // out: AccountLines +JSS(kAUTHORIZE); // out: delegate +JSS(kAUTHORIZED_CREDENTIALS); // in: ledger_entry DepositPreauth +JSS(kAUTH_ACCOUNTS); // out: amm_info +JSS(kAUTH_CHANGE); // out: AccountInfo +JSS(kAUTH_CHANGE_QUEUED); // out: AccountInfo +JSS(kAVAILABLE); // out: ValidatorList +JSS(kAVG_BPS_RECV); // out: Peers +JSS(kAVG_BPS_SENT); // out: Peers +JSS(kBALANCE); // out: AccountLines +JSS(kBALANCES); // out: GatewayBalances +JSS(kBASE); // out: LogLevel +JSS(kBASE_ASSET); // in: get_aggregate_price +JSS(kBASE_FEE); // out: NetworkOPs +JSS(kBASE_FEE_XRP); // out: NetworkOPs +JSS(kBIDS); // out: Subscribe +JSS(kBINARY); // in: AccountTX, LedgerEntry, AccountTxOld, Tx LedgerData +JSS(kBLOB); // out: ValidatorList +JSS(kBLOBS_V2); // out: ValidatorList + // in: UNL +JSS(kBOOKS); // in: Subscribe, Unsubscribe +JSS(kBOTH); // in: Subscribe, Unsubscribe +JSS(kBOTH_SIDES); // in: Subscribe, Unsubscribe +JSS(kBRANCH); // out: server_info +JSS(kBROADCAST); // out: SubmitTransaction +JSS(kBRIDGE_ACCOUNT); // in: LedgerEntry +JSS(kBUILD_PATH); // in: TransactionSign +JSS(kBUILD_VERSION); // out: NetworkOPs +JSS(kCANCEL_AFTER); // out: AccountChannels +JSS(kCAN_DELETE); // out: CanDelete +JSS(kMPT_AMOUNT); // out: mpt_holders +JSS(kMPT_ISSUANCE_ID); // in: Payment, mpt_holders +JSS(kMPTOKEN_INDEX); // out: mpt_holders +JSS(kCHANGES); // out: BookChanges +JSS(kCHANNEL_ID); // out: AccountChannels +JSS(kCHANNELS); // out: AccountChannels +JSS(kCHECK_NODES); // in: LedgerCleaner +JSS(kCLEAR); // in/out: FetchInfo +JSS(kCLOSE); // out: BookChanges +JSS(kCLOSE_FLAGS); // out: LedgerToJson +JSS(kCLOSE_TIME); // in: Application, out: NetworkOPs, RCLCxPeerPos, LedgerToJson +JSS(kCLOSE_TIME_ISO); // out: Tx, NetworkOPs, TransactionEntry AccountTx, LedgerToJson +JSS(kCLOSE_TIME_ESTIMATED); // in: Application, out: LedgerToJson +JSS(kCLOSE_TIME_HUMAN); // out: LedgerToJson +JSS(kCLOSE_TIME_OFFSET); // out: NetworkOPs +JSS(kCLOSE_TIME_RESOLUTION); // in: Application; out: LedgerToJson +JSS(kCLOSED); // out: NetworkOPs, LedgerToJson, handlers/Ledger +JSS(kCLOSED_LEDGER); // out: NetworkOPs +JSS(kCLUSTER); // out: PeerImp +JSS(kCODE); // out: errors +JSS(kCOMMAND); // in: RPCHandler +JSS(kCOMMON); // out: RPC server_definitions +JSS(kCOMPLETE); // out: NetworkOPs, InboundLedger +JSS(kCOMPLETE_LEDGERS); // out: NetworkOPs, PeerImp +JSS(kCONSENSUS); // out: NetworkOPs, LedgerConsensus +JSS(kCONVERGE_TIME); // out: NetworkOPs +JSS(kCONVERGE_TIME_S); // out: NetworkOPs +JSS(kCOOKIE); // out: NetworkOPs +JSS(kCOUNT); // in: AccountTx*, ValidatorList +JSS(kCOUNTERS); // in/out: retrieve counters +JSS(kCREDENTIALS); // in: deposit_authorized +JSS(kCREDENTIAL_TYPE); // in: LedgerEntry DepositPreauth +JSS(kCTID); // in/out: Tx RPC +JSS(kCURRENCY_A); // out: BookChanges +JSS(kCURRENCY_B); // out: BookChanges +JSS(kCURRENCY); // in: paths/PathRequest, STAmount + // out: STPathSet, STAmount, AccountLines +JSS(kCURRENT); // out: OwnerInfo +JSS(kCURRENT_ACTIVITIES); // +JSS(kCURRENT_LEDGER_SIZE); // out: TxQ +JSS(kCURRENT_QUEUE_SIZE); // out: TxQ +JSS(kDATA); // out: LedgerData +JSS(kDATE); // out: tx/Transaction, NetworkOPs +JSS(kDB_KB_LEDGER); // out: getCounts +JSS(kDB_KB_TOTAL); // out: getCounts +JSS(kDB_KB_TRANSACTION); // out: getCounts +JSS(kDEBUG_SIGNING); // in: TransactionSign +JSS(kDELETION_BLOCKERS_ONLY); // in: AccountObjects +JSS(kDELIVERED_AMOUNT); // out: insertDeliveredAmount +JSS(kDEPOSIT_AUTHORIZED); // out: deposit_authorized +JSS(kDEPRECATED); // +JSS(kDESCENDING); // in: AccountTx* +JSS(kDESCRIPTION); // in/out: Reservations +JSS(kDESTINATION); // in: nft_buy_offers, nft_sell_offers +JSS(kDESTINATION_ACCOUNT); // in: PathRequest, RipplePathFind, account_lines + // out: AccountChannels +JSS(kDESTINATION_AMOUNT); // in: PathRequest, RipplePathFind +JSS(kDESTINATION_CURRENCIES); // in: PathRequest, RipplePathFind +JSS(kDESTINATION_TAG); // in: PathRequest + // out: AccountChannels +JSS(kDETAILS); // out: Manifest, server_info +JSS(kDIR_ENTRY); // out: DirectoryEntryIterator +JSS(kDIR_INDEX); // out: DirectoryEntryIterator +JSS(kDIR_ROOT); // out: DirectoryEntryIterator +JSS(kDISCOUNTED_FEE); // out: amm_info +JSS(kDOMAIN); // out: ValidatorInfo, Manifest +JSS(kDROPS); // out: TxQ +JSS(kDURATION_US); // out: NetworkOPs +JSS(kEFFECTIVE); // out: ValidatorList + // in: UNL +JSS(kENABLED); // out: AmendmentTable +JSS(kENGINE_RESULT); // out: NetworkOPs, TransactionSign, Submit +JSS(kENGINE_RESULT_CODE); // out: NetworkOPs, TransactionSign, Submit +JSS(kENGINE_RESULT_MESSAGE); // out: NetworkOPs, TransactionSign, Submit +JSS(kENTIRE_SET); // out: get_aggregate_price +JSS(kEPHEMERAL_KEY); // out: ValidatorInfo + // in/out: Manifest +JSS(kERROR); // out: error +JSS(kERRORED); // +JSS(kERROR_CODE); // out: error +JSS(kERROR_EXCEPTION); // out: Submit +JSS(kERROR_MESSAGE); // out: error +JSS(kEXPAND); // in: handler/Ledger +JSS(kEXPECTED_DATE); // out: any (warnings) +JSS(kEXPECTED_DATE_UTC); // out: any (warnings) +JSS(kEXPECTED_LEDGER_SIZE); // out: TxQ +JSS(kEXPIRATION); // out: AccountOffers, AccountChannels, ValidatorList, amm_info +JSS(kFAIL_HARD); // in: Sign, Submit +JSS(kFAILED); // out: InboundLedger +JSS(kFEATURE); // in: Feature +JSS(kFEATURES); // out: Feature +JSS(kFEE_BASE); // out: NetworkOPs +JSS(kFEE_DIV_MAX); // in: TransactionSign +JSS(kFEE_LEVEL); // out: AccountInfo +JSS(kFEE_MULT_MAX); // in: TransactionSign +JSS(kFEE_REF); // out: NetworkOPs, DEPRECATED +JSS(kFETCH_PACK); // out: NetworkOPs +JSS(kFIELDS); // out: RPC server_definitions + // matches definitions.json format +JSS(kFIRST); // out: rpc/Version +JSS(kFINISHED); // +JSS(kFIX_TXNS); // in: LedgerCleaner +JSS(kFLAGS); // out: AccountOffers, NetworkOPs +JSS(kFORWARD); // in: AccountTx +JSS(kFREEZE); // out: AccountLines +JSS(kFREEZE_PEER); // out: AccountLines +JSS(kDEEP_FREEZE); // out: AccountLines +JSS(kDEEP_FREEZE_PEER); // out: AccountLines +JSS(kFROZEN_BALANCES); // out: GatewayBalances +JSS(kFULL); // in: LedgerClearer, handlers/Ledger +JSS(kFULL_REPLY); // out: PathFind +JSS(kFULLBELOW_SIZE); // out: GetCounts +JSS(kGIT); // out: server_info +JSS(kGOOD); // out: RPCVersion +JSS(kHASH); // out: NetworkOPs, InboundLedger, LedgerToJson, STTx; field +JSS(kHAVE_HEADER); // out: InboundLedger +JSS(kHAVE_STATE); // out: InboundLedger +JSS(kHAVE_TRANSACTIONS); // out: InboundLedger +JSS(kHIGH); // out: BookChanges +JSS(kHIGHEST_SEQUENCE); // out: AccountInfo +JSS(kHIGHEST_TICKET); // out: AccountInfo +JSS(kHISTORICAL_PERMINUTE); // historical_perminute. +JSS(kHOLDERS); // out: MPTHolders +JSS(kHOSTID); // out: NetworkOPs +JSS(kHOTWALLET); // in: GatewayBalances +JSS(kID); // websocket. +JSS(kIDENT); // in: AccountCurrencies, AccountInfo, OwnerInfo +JSS(kIGNORE_DEFAULT); // in: AccountLines +JSS(kIN); // out: OverlayImpl +JSS(kIN_LEDGER); // out: tx/Transaction +JSS(kINBOUND); // out: PeerImp +JSS(kINDEX); // in: LedgerEntry + // out: STLedgerEntry, LedgerEntry, TxHistory, LedgerData +JSS(kINFO); // out: ServerInfo, ConsensusInfo, FetchInfo +JSS(kINITIAL_SYNC_DURATION_US); // +JSS(kINTERNAL_COMMAND); // in: Internal +JSS(kINVALID_API_VERSION); // out: Many, when a request has an invalid version +JSS(kIO_LATENCY_MS); // out: NetworkOPs +JSS(kIP); // in: Connect, out: OverlayImpl +JSS(kIS_BURNED); // out: nft_info (clio) +JSS(kIS_SERIALIZED); // out: RPC server_definitions + // matches definitions.json format +JSS(kIS_SIGNING_FIELD); // out: RPC server_definitions + // matches definitions.json format +JSS(kIS_VL_ENCODED); // out: RPC server_definitions + // matches definitions.json format +JSS(kISSUER); // in: RipplePathFind, Subscribe, Unsubscribe, BookOffers + // out: STPathSet, STAmount +JSS(kJOB); // +JSS(kJOB_QUEUE); // +JSS(kJOBS); // +JSS(kJSONRPC); // json version +JSS(kJQ_TRANS_OVERFLOW); // JobQueue transaction limit overflow. +JSS(kEPT); // out: SubmitTransaction +JSS(kEY); // out +JSS(kEY_TYPE); // in/out: WalletPropose, TransactionSign +JSS(kLATENCY); // out: PeerImp +JSS(kLAST); // out: RPCVersion +JSS(kLAST_CLOSE); // out: NetworkOPs +JSS(kLAST_REFRESH_TIME); // out: ValidatorSite +JSS(kLAST_REFRESH_STATUS); // out: ValidatorSite +JSS(kLAST_REFRESH_MESSAGE); // out: ValidatorSite +JSS(kLEDGER); // in: NetworkOPs, LedgerCleaner, RPCHelpers + // out: NetworkOPs, PeerImp +JSS(kLEDGER_CURRENT_INDEX); // out: NetworkOPs, RPCHelpers, LedgerCurrent, LedgerAccept, + // AccountLines +JSS(kLEDGER_DATA); // out: LedgerHeader +JSS(kLEDGER_HASH); // in: RPCHelpers, LedgerRequest, RipplePathFind, + // TransactionEntry, handlers/Ledger + // out: NetworkOPs, RPCHelpers, LedgerClosed, LedgerData, + // AccountLines +JSS(kLEDGER_HIT_RATE); // out: GetCounts +JSS(kLEDGER_INDEX); // in/out: many +JSS(kLEDGER_INDEX_MAX); // in, out: AccountTx* +JSS(kLEDGER_INDEX_MIN); // in, out: AccountTx* +JSS(kLEDGER_MAX); // in, out: AccountTx* +JSS(kLEDGER_MIN); // in, out: AccountTx* +JSS(kLEDGER_TIME); // out: NetworkOPs +JSS(kLEDGER_ENTRY_TYPES); // out: RPC server_definitions + // matches definitions.json format +JSS(kLEDGER_ENTRY_FLAGS); // out: RPC server_definitions +JSS(kLEDGER_ENTRY_FORMATS); // out: RPC server_definitions +JSS(kLEVELS); // LogLevels +JSS(kLIMIT); // in/out: AccountTx*, AccountOffers, AccountLines, AccountObjects + // in: LedgerData, BookOffers +JSS(kLIMIT_PEER); // out: AccountLines +JSS(kLINES); // out: AccountLines +JSS(kLIST); // out: ValidatorList +JSS(kLOAD); // out: NetworkOPs, PeerImp +JSS(kLOAD_BASE); // out: NetworkOPs +JSS(kLOAD_FACTOR); // out: NetworkOPs +JSS(kLOAD_FACTOR_CLUSTER); // out: NetworkOPs +JSS(kLOAD_FACTOR_FEE_ESCALATION); // out: NetworkOPs +JSS(kLOAD_FACTOR_FEE_QUEUE); // out: NetworkOPs +JSS(kLOAD_FACTOR_FEE_REFERENCE); // out: NetworkOPs +JSS(kLOAD_FACTOR_LOCAL); // out: NetworkOPs +JSS(kLOAD_FACTOR_NET); // out: NetworkOPs +JSS(kLOAD_FACTOR_SERVER); // out: NetworkOPs +JSS(kLOAD_FEE); // out: LoadFeeTrackImp, NetworkOPs +JSS(kLOAN_BROKER_ID); // in: LedgerEntry +JSS(kLOAN_SEQ); // in: LedgerEntry +JSS(kLOCAL); // out: resource/Logic.h +JSS(kLOCAL_TXS); // out: GetCounts +JSS(kLOCAL_STATIC_KEYS); // out: ValidatorList +JSS(kLOCKED); // out: GatewayBalances +JSS(kLOW); // out: BookChanges +JSS(kLOWEST_SEQUENCE); // out: AccountInfo +JSS(kLOWEST_TICKET); // out: AccountInfo +JSS(kLP_TOKEN); // out: amm_info +JSS(kMAJORITY); // out: RPC feature +JSS(kMANIFEST); // out: ValidatorInfo, Manifest +JSS(kMARKER); // in/out: AccountTx, AccountOffers, AccountLines, AccountObjects, // LedgerData // in: BookOffers -JSS(master_key); // out: WalletPropose, NetworkOPs, ValidatorInfo +JSS(kMASTER_KEY); // out: WalletPropose, NetworkOPs, ValidatorInfo // in/out: Manifest -JSS(master_seed); // out: WalletPropose -JSS(master_seed_hex); // out: WalletPropose -JSS(master_signature); // out: pubManifest -JSS(max_ledger); // in/out: LedgerCleaner -JSS(max_queue_size); // out: TxQ -JSS(max_spend_drops); // out: AccountInfo -JSS(max_spend_drops_total); // out: AccountInfo -JSS(mean); // out: get_aggregate_price -JSS(median); // out: get_aggregate_price -JSS(median_fee); // out: TxQ -JSS(median_level); // out: TxQ -JSS(message); // error. -JSS(meta); // out: NetworkOPs, AccountTx*, Tx -JSS(meta_blob); // out: NetworkOPs, AccountTx*, Tx -JSS(metaData); // -JSS(metadata); // out: TransactionEntry -JSS(method); // RPC -JSS(methods); // -JSS(metrics); // out: Peers -JSS(min_count); // in: GetCounts -JSS(min_ledger); // in: LedgerCleaner -JSS(minimum_fee); // out: TxQ -JSS(minimum_level); // out: TxQ -JSS(missingCommand); // error -JSS(mpt_issuance_id_a); // out: BookChanges -JSS(mpt_issuance_id_b); // out: BookChanges -JSS(name); // out: AmendmentTableImpl, PeerImp -JSS(needed_state_hashes); // out: InboundLedger -JSS(needed_transaction_hashes); // out: InboundLedger -JSS(network_id); // out: NetworkOPs -JSS(network_ledger); // out: NetworkOPs -JSS(next_refresh_time); // out: ValidatorSite -JSS(nft_id); // in: nft_sell_offers, nft_buy_offers -JSS(nft_offer_index); // out nft_buy_offers, nft_sell_offers -JSS(nft_serial); // out: account_nfts -JSS(nft_taxon); // out: nft_info (clio) -JSS(nftoken_id); // out: insertNFTokenID -JSS(nftoken_ids); // out: insertNFTokenID -JSS(no_ripple); // out: AccountLines -JSS(no_ripple_peer); // out: AccountLines -JSS(node); // out: LedgerEntry -JSS(node_binary); // out: LedgerEntry -JSS(node_read_bytes); // out: GetCounts -JSS(node_read_errors); // out: GetCounts -JSS(node_read_retries); // out: GetCounts -JSS(node_reads_hit); // out: GetCounts -JSS(node_reads_total); // out: GetCounts -JSS(node_reads_duration_us); // out: GetCounts -JSS(node_size); // out: server_info -JSS(nodes); // out: VaultInfo -JSS(nodestore); // out: GetCounts -JSS(node_writes); // out: GetCounts -JSS(node_written_bytes); // out: GetCounts -JSS(node_writes_duration_us); // out: GetCounts -JSS(node_write_retries); // out: GetCounts -JSS(node_writes_delayed); // out::GetCounts -JSS(nth); // out: RPC server_definitions -JSS(obligations); // out: GatewayBalances -JSS(offers); // out: NetworkOPs, AccountOffers, Subscribe -JSS(offer_id); // out: insertNFTokenOfferID -JSS(offline); // in: TransactionSign -JSS(offset); // in/out: AccountTxOld -JSS(open); // out: handlers/Ledger -JSS(open_ledger_cost); // out: SubmitTransaction -JSS(open_ledger_fee); // out: TxQ -JSS(open_ledger_level); // out: TxQ -JSS(optionality); // out: server_definitions -JSS(oracles); // in: get_aggregate_price -JSS(oracle_document_id); // in: get_aggregate_price -JSS(out); // out: OverlayImpl -JSS(owner); // in: LedgerEntry, out: NetworkOPs -JSS(owner_funds); // in/out: Ledger, NetworkOPs, AcceptedLedgerTx -JSS(page_index); // -JSS(params); // RPC -JSS(parent_close_time); // out: LedgerToJson -JSS(parent_hash); // out: LedgerToJson -JSS(partition); // in: LogLevel -JSS(passphrase); // in: WalletPropose -JSS(password); // in: Subscribe -JSS(paths); // in: RipplePathFind -JSS(paths_canonical); // out: RipplePathFind -JSS(paths_computed); // out: PathRequest, RipplePathFind -JSS(peer); // in: AccountLines -JSS(peer_authorized); // out: AccountLines -JSS(peer_id); // out: RCLCxPeerPos -JSS(peers); // out: InboundLedger, handlers/Peers, Overlay -JSS(peer_disconnects); // Severed peer connection counter. -JSS(peer_disconnects_resources); // Severed peer connections because of - // excess resource consumption. -JSS(port); // in: Connect, out: NetworkOPs -JSS(ports); // out: NetworkOPs -JSS(previous); // out: Reservations -JSS(previous_ledger); // out: LedgerPropose -JSS(price); // out: amm_info, AuctionSlot -JSS(proof); // in: BookOffers -JSS(propose_seq); // out: LedgerPropose -JSS(proposers); // out: NetworkOPs, LedgerConsensus -JSS(protocol); // out: NetworkOPs, PeerImp -JSS(proxied); // out: RPC ping -JSS(pseudo_account); // out: AccountInfo -JSS(pubkey_node); // out: NetworkOPs -JSS(pubkey_publisher); // out: ValidatorList -JSS(pubkey_validator); // out: NetworkOPs, ValidatorList -JSS(public_key); // out: OverlayImpl, PeerImp, WalletPropose, ValidatorInfo - // in/out: Manifest -JSS(public_key_hex); // out: WalletPropose -JSS(published_ledger); // out: NetworkOPs -JSS(publisher_lists); // out: ValidatorList -JSS(quality); // out: NetworkOPs -JSS(quality_in); // out: AccountLines -JSS(quality_out); // out: AccountLines -JSS(queue); // in: AccountInfo -JSS(queue_data); // out: AccountInfo -JSS(queued); // out: SubmitTransaction -JSS(queued_duration_us); // -JSS(quote_asset); // in: get_aggregate_price -JSS(random); // out: Random -JSS(raw_meta); // out: AcceptedLedgerTx -JSS(receive_currencies); // out: AccountCurrencies -JSS(reference_level); // out: TxQ -JSS(refresh_interval); // in: UNL -JSS(refresh_interval_min); // out: ValidatorSites -JSS(regular_seed); // in/out: LedgerEntry -JSS(remaining); // out: ValidatorList -JSS(remote); // out: Logic.h -JSS(request); // RPC -JSS(requested); // out: Manifest -JSS(reservations); // out: Reservations -JSS(reserve_base); // out: NetworkOPs -JSS(reserve_base_xrp); // out: NetworkOPs -JSS(reserve_inc); // out: NetworkOPs -JSS(reserve_inc_xrp); // out: NetworkOPs -JSS(response); // websocket -JSS(result); // RPC -JSS(ripple_lines); // out: NetworkOPs -JSS(ripple_state); // in: LedgerEntr -JSS(ripplerpc); // XRPL RPC version -JSS(role); // out: Ping.cpp -JSS(rpc); // -JSS(rt_accounts); // in: Subscribe, Unsubscribe -JSS(running_duration_us); // -JSS(search_depth); // in: RipplePathFind -JSS(searched_all); // out: Tx -JSS(secret); // in: TransactionSign, ValidationCreate, ValidationSeed, - // channel_authorize -JSS(seed); // -JSS(seed_hex); // in: WalletPropose, TransactionSign -JSS(send_currencies); // out: AccountCurrencies -JSS(send_max); // in: PathRequest, RipplePathFind -JSS(seq); // in: LedgerEntry - // out: NetworkOPs, RPCSub, AccountOffers, ValidatorList, - // ValidatorInfo, Manifest -JSS(sequence); // in: UNL -JSS(sequence_count); // out: AccountInfo -JSS(server_domain); // out: NetworkOPs -JSS(server_state); // out: NetworkOPs -JSS(server_state_duration_us); // out: NetworkOPs -JSS(server_status); // out: NetworkOPs -JSS(server_version); // out: NetworkOPs -JSS(settle_delay); // out: AccountChannels -JSS(severity); // in: LogLevel -JSS(shares); // out: VaultInfo -JSS(signature); // out: NetworkOPs, ChannelAuthorize -JSS(signature_target); // in: TransactionSign -JSS(signature_verified); // out: ChannelVerify -JSS(signing_key); // out: NetworkOPs -JSS(signing_keys); // out: ValidatorList -JSS(signing_time); // out: NetworkOPs -JSS(signer_lists); // in/out: AccountInfo -JSS(size); // out: get_aggregate_price -JSS(snapshot); // in: Subscribe -JSS(source_account); // in: PathRequest, RipplePathFind -JSS(source_amount); // in: PathRequest, RipplePathFind -JSS(source_currencies); // in: PathRequest, RipplePathFind -JSS(source_tag); // out: AccountChannels -JSS(stand_alone); // out: NetworkOPs -JSS(standard_deviation); // out: get_aggregate_price -JSS(start); // in: TxHistory -JSS(started); // -JSS(state_accounting); // out: NetworkOPs -JSS(state_now); // in: Subscribe -JSS(status); // error -JSS(stop); // in: LedgerCleaner -JSS(stop_history_tx_only); // in: Unsubscribe, stop history tx stream -JSS(streams); // in: Subscribe, Unsubscribe -JSS(strict); // in: AccountCurrencies, AccountInfo -JSS(sub_index); // in: LedgerEntry -JSS(subcommand); // in: PathFind -JSS(subject); // in: LedgerEntry Credential -JSS(success); // rpc -JSS(supported); // out: AmendmentTableImpl -JSS(sync_mode); // in: Submit -JSS(system_time_offset); // out: NetworkOPs -JSS(tag); // out: Peers -JSS(taker); // in: Subscribe, BookOffers -JSS(taker_gets); // in: Subscribe, Unsubscribe, BookOffers -JSS(taker_gets_funded); // out: NetworkOPs -JSS(taker_pays); // in: Subscribe, Unsubscribe, BookOffers -JSS(taker_pays_funded); // out: NetworkOPs -JSS(threshold); // in: Blacklist -JSS(ticket_count); // out: AccountInfo -JSS(ticket_seq); // in: LedgerEntry -JSS(time); // -JSS(timeouts); // out: InboundLedger -JSS(time_threshold); // in/out: Oracle aggregate -JSS(time_interval); // out: AMM Auction Slot -JSS(track); // out: PeerImp -JSS(traffic); // out: Overlay -JSS(trim); // in: get_aggregate_price -JSS(trimmed_set); // out: get_aggregate_price -JSS(total); // out: counters -JSS(total_bytes_recv); // out: Peers -JSS(total_bytes_sent); // out: Peers -JSS(total_coins); // out: LedgerToJson -JSS(trading_fee); // out: amm_info -JSS(transTreeHash); // out: ledger/Ledger.cpp -JSS(transaction); // in: Tx - // out: NetworkOPs, AcceptedLedgerTx, -JSS(transaction_hash); // out: RCLCxPeerPos, LedgerToJson -JSS(transactions); // out: LedgerToJson, - // in: AccountTx*, Unsubscribe -JSS(TRANSACTION_RESULTS); // out: RPC server_definitions - // matches definitions.json format -JSS(TRANSACTION_TYPES); // out: RPC server_definitions - // matches definitions.json format -JSS(TRANSACTION_FLAGS); // out: RPC server_definitions -JSS(TRANSACTION_FORMATS); // out: RPC server_definitions -JSS(TYPES); // out: RPC server_definitions - // matches definitions.json format -JSS(transfer_rate); // out: nft_info (clio) -JSS(transitions); // out: NetworkOPs -JSS(treenode_cache_size); // out: GetCounts -JSS(treenode_track_size); // out: GetCounts -JSS(trusted); // out: UnlList -JSS(trusted_validator_keys); // out: ValidatorList -JSS(tx); // out: STTx, AccountTx* -JSS(tx_blob); // in/out: Submit, - // in: TransactionSign, AccountTx* -JSS(tx_hash); // in: TransactionEntry -JSS(tx_json); // in/out: TransactionSign - // out: TransactionEntry -JSS(tx_signing_hash); // out: TransactionSign -JSS(tx_unsigned); // out: TransactionSign -JSS(txn_count); // out: NetworkOPs -JSS(txr_tx_cnt); // out: protocol message tx's count -JSS(txr_tx_sz); // out: protocol message tx's size -JSS(txr_have_txs_cnt); // out: protocol message have tx count -JSS(txr_have_txs_sz); // out: protocol message have tx size -JSS(txr_get_ledger_cnt); // out: protocol message get ledger count -JSS(txr_get_ledger_sz); // out: protocol message get ledger size -JSS(txr_ledger_data_cnt); // out: protocol message ledger data count -JSS(txr_ledger_data_sz); // out: protocol message ledger data size -JSS(txr_transactions_cnt); // out: protocol message get object count -JSS(txr_transactions_sz); // out: protocol message get object size -JSS(txr_selected_cnt); // out: selected peers count -JSS(txr_suppressed_cnt); // out: suppressed peers count -JSS(txr_not_enabled_cnt); // out: peers with tx reduce-relay disabled count -JSS(txr_missing_tx_freq); // out: missing tx frequency average -JSS(txs); // out: TxHistory -JSS(type); // in: AccountObjects - // out: NetworkOPs, RPC server_definitions OverlayImpl, Logic -JSS(type_hex); // out: STPathSet -JSS(unl); // out: UnlList -JSS(unlimited); // out: Connection.h -JSS(uptime); // out: GetCounts -JSS(uri); // out: ValidatorSites -JSS(url); // in/out: Subscribe, Unsubscribe -JSS(url_password); // in: Subscribe -JSS(url_username); // in: Subscribe -JSS(urlgravatar); // -JSS(username); // in: Subscribe -JSS(validated); // out: NetworkOPs, RPCHelpers, AccountTx*, Tx -JSS(validator_list_expires); // out: NetworkOps, ValidatorList -JSS(validator_list); // out: NetworkOps, ValidatorList -JSS(validators); // -JSS(validated_hash); // out: NetworkOPs -JSS(validated_ledger); // out: NetworkOPs -JSS(validated_ledger_index); // out: SubmitTransaction -JSS(validated_ledgers); // out: NetworkOPs -JSS(validation_key); // out: ValidationCreate, ValidationSeed -JSS(validation_private_key); // out: ValidationCreate -JSS(validation_public_key); // out: ValidationCreate, ValidationSeed -JSS(validation_quorum); // out: NetworkOPs -JSS(validation_seed); // out: ValidationCreate, ValidationSeed -JSS(validations); // out: AmendmentTableImpl -JSS(validator_list_threshold); // out: ValidatorList -JSS(validator_sites); // out: ValidatorSites -JSS(value); // out: STAmount -JSS(vault_id); // in: VaultInfo -JSS(version); // out: RPCVersion -JSS(vetoed); // out: AmendmentTableImpl -JSS(volume_a); // out: BookChanges -JSS(volume_b); // out: BookChanges -JSS(vote); // in: Feature -JSS(vote_slots); // out: amm_info -JSS(vote_weight); // out: amm_info -JSS(warning); // rpc: -JSS(warnings); // out: server_info, server_state -JSS(workers); // -JSS(write_load); // out: GetCounts +JSS(kMASTER_SEED); // out: WalletPropose +JSS(kMASTER_SEED_HEX); // out: WalletPropose +JSS(kMASTER_SIGNATURE); // out: pubManifest +JSS(kMAX_LEDGER); // in/out: LedgerCleaner +JSS(kMAX_QUEUE_SIZE); // out: TxQ +JSS(kMAX_SPEND_DROPS); // out: AccountInfo +JSS(kMAX_SPEND_DROPS_TOTAL); // out: AccountInfo +JSS(kMEAN); // out: get_aggregate_price +JSS(kMEDIAN); // out: get_aggregate_price +JSS(kMEDIAN_FEE); // out: TxQ +JSS(kMEDIAN_LEVEL); // out: TxQ +JSS(kMESSAGE); // error. +JSS(kMETA); // out: NetworkOPs, AccountTx*, Tx +JSS(kMETA_BLOB); // out: NetworkOPs, AccountTx*, Tx +JSS(kMETA_DATA); // +JSS(kMETADATA); // out: TransactionEntry +JSS(kMETHOD); // RPC +JSS(kMETHODS); // +JSS(kMETRICS); // out: Peers +JSS(kMIN_COUNT); // in: GetCounts +JSS(kMIN_LEDGER); // in: LedgerCleaner +JSS(kMINIMUM_FEE); // out: TxQ +JSS(kMINIMUM_LEVEL); // out: TxQ +JSS(kMISSING_COMMAND); // error +JSS(kMPT_ISSUANCE_ID_A); // out: BookChanges +JSS(kMPT_ISSUANCE_ID_B); // out: BookChanges +JSS(kNAME); // out: AmendmentTableImpl, PeerImp +JSS(kNEEDED_STATE_HASHES); // out: InboundLedger +JSS(kNEEDED_TRANSACTION_HASHES); // out: InboundLedger +JSS(kNETWORK_ID); // out: NetworkOPs +JSS(kNETWORK_LEDGER); // out: NetworkOPs +JSS(kNEXT_REFRESH_TIME); // out: ValidatorSite +JSS(kNFT_ID); // in: nft_sell_offers, nft_buy_offers +JSS(kNFT_OFFER_INDEX); // out nft_buy_offers, nft_sell_offers +JSS(kNFT_SERIAL); // out: account_nfts +JSS(kNFT_TAXON); // out: nft_info (clio) +JSS(kNFTOKEN_ID); // out: insertNFTokenID +JSS(kNFTOKEN_IDS); // out: insertNFTokenID +JSS(kNO_RIPPLE); // out: AccountLines +JSS(kNO_RIPPLE_PEER); // out: AccountLines +JSS(kNODE); // out: LedgerEntry +JSS(kNODE_BINARY); // out: LedgerEntry +JSS(kNODE_READ_BYTES); // out: GetCounts +JSS(kNODE_READ_ERRORS); // out: GetCounts +JSS(kNODE_READ_RETRIES); // out: GetCounts +JSS(kNODE_READS_HIT); // out: GetCounts +JSS(kNODE_READS_TOTAL); // out: GetCounts +JSS(kNODE_READS_DURATION_US); // out: GetCounts +JSS(kNODE_SIZE); // out: server_info +JSS(kNODES); // out: VaultInfo +JSS(kNODESTORE); // out: GetCounts +JSS(kNODE_WRITES); // out: GetCounts +JSS(kNODE_WRITTEN_BYTES); // out: GetCounts +JSS(kNODE_WRITES_DURATION_US); // out: GetCounts +JSS(kNODE_WRITE_RETRIES); // out: GetCounts +JSS(kNODE_WRITES_DELAYED); // out::GetCounts +JSS(kNTH); // out: RPC server_definitions +JSS(kOBLIGATIONS); // out: GatewayBalances +JSS(kOFFERS); // out: NetworkOPs, AccountOffers, Subscribe +JSS(kOFFER_ID); // out: insertNFTokenOfferID +JSS(kOFFLINE); // in: TransactionSign +JSS(kOFFSET); // in/out: AccountTxOld +JSS(kOPEN); // out: handlers/Ledger +JSS(kOPEN_LEDGER_COST); // out: SubmitTransaction +JSS(kOPEN_LEDGER_FEE); // out: TxQ +JSS(kOPEN_LEDGER_LEVEL); // out: TxQ +JSS(kOPTIONALITY); // out: server_definitions +JSS(kORACLES); // in: get_aggregate_price +JSS(kORACLE_DOCUMENT_ID); // in: get_aggregate_price +JSS(kOUT); // out: OverlayImpl +JSS(kOWNER); // in: LedgerEntry, out: NetworkOPs +JSS(kOWNER_FUNDS); // in/out: Ledger, NetworkOPs, AcceptedLedgerTx +JSS(kPAGE_INDEX); // +JSS(kPARAMS); // RPC +JSS(kPARENT_CLOSE_TIME); // out: LedgerToJson +JSS(kPARENT_HASH); // out: LedgerToJson +JSS(kPARTITION); // in: LogLevel +JSS(kPASSPHRASE); // in: WalletPropose +JSS(kPASSWORD); // in: Subscribe +JSS(kPATHS); // in: RipplePathFind +JSS(kPATHS_CANONICAL); // out: RipplePathFind +JSS(kPATHS_COMPUTED); // out: PathRequest, RipplePathFind +JSS(kPEER); // in: AccountLines +JSS(kPEER_AUTHORIZED); // out: AccountLines +JSS(kPEER_ID); // out: RCLCxPeerPos +JSS(kPEERS); // out: InboundLedger, handlers/Peers, Overlay +JSS(kPEER_DISCONNECTS); // Severed peer connection counter. +JSS(kPEER_DISCONNECTS_RESOURCES); // Severed peer connections because of + // excess resource consumption. +JSS(kPORT); // in: Connect, out: NetworkOPs +JSS(kPORTS); // out: NetworkOPs +JSS(kPREVIOUS); // out: Reservations +JSS(kPREVIOUS_LEDGER); // out: LedgerPropose +JSS(kPRICE); // out: amm_info, AuctionSlot +JSS(kPROOF); // in: BookOffers +JSS(kPROPOSE_SEQ); // out: LedgerPropose +JSS(kPROPOSERS); // out: NetworkOPs, LedgerConsensus +JSS(kPROTOCOL); // out: NetworkOPs, PeerImp +JSS(kPROXIED); // out: RPC ping +JSS(kPSEUDO_ACCOUNT); // out: AccountInfo +JSS(kPUBKEY_NODE); // out: NetworkOPs +JSS(kPUBKEY_PUBLISHER); // out: ValidatorList +JSS(kPUBKEY_VALIDATOR); // out: NetworkOPs, ValidatorList +JSS(kPUBLIC_KEY); // out: OverlayImpl, PeerImp, WalletPropose, ValidatorInfo + // in/out: Manifest +JSS(kPUBLIC_KEY_HEX); // out: WalletPropose +JSS(kPUBLISHED_LEDGER); // out: NetworkOPs +JSS(kPUBLISHER_LISTS); // out: ValidatorList +JSS(kQUALITY); // out: NetworkOPs +JSS(kQUALITY_IN); // out: AccountLines +JSS(kQUALITY_OUT); // out: AccountLines +JSS(kQUEUE); // in: AccountInfo +JSS(kQUEUE_DATA); // out: AccountInfo +JSS(kQUEUED); // out: SubmitTransaction +JSS(kQUEUED_DURATION_US); // +JSS(kQUOTE_ASSET); // in: get_aggregate_price +JSS(kRANDOM); // out: Random +JSS(kRAW_META); // out: AcceptedLedgerTx +JSS(kRECEIVE_CURRENCIES); // out: AccountCurrencies +JSS(kREFERENCE_LEVEL); // out: TxQ +JSS(kREFRESH_INTERVAL); // in: UNL +JSS(kREFRESH_INTERVAL_MIN); // out: ValidatorSites +JSS(kREGULAR_SEED); // in/out: LedgerEntry +JSS(kREMAINING); // out: ValidatorList +JSS(kREMOTE); // out: Logic.h +JSS(kREQUEST); // RPC +JSS(kREQUESTED); // out: Manifest +JSS(kRESERVATIONS); // out: Reservations +JSS(kRESERVE_BASE); // out: NetworkOPs +JSS(kRESERVE_BASE_XRP); // out: NetworkOPs +JSS(kRESERVE_INC); // out: NetworkOPs +JSS(kRESERVE_INC_XRP); // out: NetworkOPs +JSS(kRESPONSE); // websocket +JSS(kRESULT); // RPC +JSS(kRIPPLE_LINES); // out: NetworkOPs +JSS(kRIPPLE_STATE); // in: LedgerEntr +JSS(kRIPPLERPC); // XRPL RPC version +JSS(kROLE); // out: Ping.cpp +JSS(kRPC); // +JSS(kRT_ACCOUNTS); // in: Subscribe, Unsubscribe +JSS(kRUNNING_DURATION_US); // +JSS(kSEARCH_DEPTH); // in: RipplePathFind +JSS(kSEARCHED_ALL); // out: Tx +JSS(kSECRET); // in: TransactionSign, ValidationCreate, ValidationSeed, + // channel_authorize +JSS(kSEED); // +JSS(kSEED_HEX); // in: WalletPropose, TransactionSign +JSS(kSEND_CURRENCIES); // out: AccountCurrencies +JSS(kSEND_MAX); // in: PathRequest, RipplePathFind +JSS(kSEQ); // in: LedgerEntry + // out: NetworkOPs, RPCSub, AccountOffers, ValidatorList, + // ValidatorInfo, Manifest +JSS(kSEQUENCE); // in: UNL +JSS(kSEQUENCE_COUNT); // out: AccountInfo +JSS(kSERVER_DOMAIN); // out: NetworkOPs +JSS(kSERVER_STATE); // out: NetworkOPs +JSS(kSERVER_STATE_DURATION_US); // out: NetworkOPs +JSS(kSERVER_STATUS); // out: NetworkOPs +JSS(kSERVER_VERSION); // out: NetworkOPs +JSS(kSETTLE_DELAY); // out: AccountChannels +JSS(kSEVERITY); // in: LogLevel +JSS(kSHARES); // out: VaultInfo +JSS(kSIGNATURE); // out: NetworkOPs, ChannelAuthorize +JSS(kSIGNATURE_TARGET); // in: TransactionSign +JSS(kSIGNATURE_VERIFIED); // out: ChannelVerify +JSS(kSIGNING_KEY); // out: NetworkOPs +JSS(kSIGNING_KEYS); // out: ValidatorList +JSS(kSIGNING_TIME); // out: NetworkOPs +JSS(kSIGNER_LISTS); // in/out: AccountInfo +JSS(kSIZE); // out: get_aggregate_price +JSS(kSNAPSHOT); // in: Subscribe +JSS(kSOURCE_ACCOUNT); // in: PathRequest, RipplePathFind +JSS(kSOURCE_AMOUNT); // in: PathRequest, RipplePathFind +JSS(kSOURCE_CURRENCIES); // in: PathRequest, RipplePathFind +JSS(kSOURCE_TAG); // out: AccountChannels +JSS(kSTAND_ALONE); // out: NetworkOPs +JSS(kSTANDARD_DEVIATION); // out: get_aggregate_price +JSS(kSTART); // in: TxHistory +JSS(kSTARTED); // +JSS(kSTATE_ACCOUNTING); // out: NetworkOPs +JSS(kSTATE_NOW); // in: Subscribe +JSS(kSTATUS); // error +JSS(kSTOP); // in: LedgerCleaner +JSS(kSTOP_HISTORY_TX_ONLY); // in: Unsubscribe, stop history tx stream +JSS(kSTREAMS); // in: Subscribe, Unsubscribe +JSS(kSTRICT); // in: AccountCurrencies, AccountInfo +JSS(kSUB_INDEX); // in: LedgerEntry +JSS(kSUBCOMMAND); // in: PathFind +JSS(kSUBJECT); // in: LedgerEntry Credential +JSS(kSUCCESS); // rpc +JSS(kSUPPORTED); // out: AmendmentTableImpl +JSS(kSYNC_MODE); // in: Submit +JSS(kSYSTEM_TIME_OFFSET); // out: NetworkOPs +JSS(kTAG); // out: Peers +JSS(kTAKER); // in: Subscribe, BookOffers +JSS(kTAKER_GETS); // in: Subscribe, Unsubscribe, BookOffers +JSS(kTAKER_GETS_FUNDED); // out: NetworkOPs +JSS(kTAKER_PAYS); // in: Subscribe, Unsubscribe, BookOffers +JSS(kTAKER_PAYS_FUNDED); // out: NetworkOPs +JSS(kTHRESHOLD); // in: Blacklist +JSS(kTICKET_COUNT); // out: AccountInfo +JSS(kTICKET_SEQ); // in: LedgerEntry +JSS(kTIME); // +JSS(kTIMEOUTS); // out: InboundLedger +JSS(kTIME_THRESHOLD); // in/out: Oracle aggregate +JSS(kTIME_INTERVAL); // out: AMM Auction Slot +JSS(kTRACK); // out: PeerImp +JSS(kTRAFFIC); // out: Overlay +JSS(kTRIM); // in: get_aggregate_price +JSS(kTRIMMED_SET); // out: get_aggregate_price +JSS(kTOTAL); // out: counters +JSS(kTOTAL_BYTES_RECV); // out: Peers +JSS(kTOTAL_BYTES_SENT); // out: Peers +JSS(kTOTAL_COINS); // out: LedgerToJson +JSS(kTRADING_FEE); // out: amm_info +JSS(kTRANS_TREE_HASH); // out: ledger/Ledger.cpp +JSS(kTRANSACTION); // in: Tx + // out: NetworkOPs, AcceptedLedgerTx, +JSS(kTRANSACTION_HASH); // out: RCLCxPeerPos, LedgerToJson +JSS(kTRANSACTIONS); // out: LedgerToJson, + // in: AccountTx*, Unsubscribe +JSS(kTRANSACTION_RESULTS); // out: RPC server_definitions + // matches definitions.json format +JSS(kTRANSACTION_TYPES); // out: RPC server_definitions + // matches definitions.json format +JSS(kTRANSACTION_FLAGS); // out: RPC server_definitions +JSS(kTRANSACTION_FORMATS); // out: RPC server_definitions +JSS(kTYPES); // out: RPC server_definitions + // matches definitions.json format +JSS(kTRANSFER_RATE); // out: nft_info (clio) +JSS(kTRANSITIONS); // out: NetworkOPs +JSS(kTREENODE_CACHE_SIZE); // out: GetCounts +JSS(kTREENODE_TRACK_SIZE); // out: GetCounts +JSS(kTRUSTED); // out: UnlList +JSS(kTRUSTED_VALIDATOR_KEYS); // out: ValidatorList +JSS(kTX); // out: STTx, AccountTx* +JSS(kTX_BLOB); // in/out: Submit, + // in: TransactionSign, AccountTx* +JSS(kTX_HASH); // in: TransactionEntry +JSS(kTX_JSON); // in/out: TransactionSign + // out: TransactionEntry +JSS(kTX_SIGNING_HASH); // out: TransactionSign +JSS(kTX_UNSIGNED); // out: TransactionSign +JSS(kTXN_COUNT); // out: NetworkOPs +JSS(kTXR_TX_CNT); // out: protocol message tx's count +JSS(kTXR_TX_SZ); // out: protocol message tx's size +JSS(kTXR_HAVE_TXS_CNT); // out: protocol message have tx count +JSS(kTXR_HAVE_TXS_SZ); // out: protocol message have tx size +JSS(kTXR_GET_LEDGER_CNT); // out: protocol message get ledger count +JSS(kTXR_GET_LEDGER_SZ); // out: protocol message get ledger size +JSS(kTXR_LEDGER_DATA_CNT); // out: protocol message ledger data count +JSS(kTXR_LEDGER_DATA_SZ); // out: protocol message ledger data size +JSS(kTXR_TRANSACTIONS_CNT); // out: protocol message get object count +JSS(kTXR_TRANSACTIONS_SZ); // out: protocol message get object size +JSS(kTXR_SELECTED_CNT); // out: selected peers count +JSS(kTXR_SUPPRESSED_CNT); // out: suppressed peers count +JSS(kTXR_NOT_ENABLED_CNT); // out: peers with tx reduce-relay disabled count +JSS(kTXR_MISSING_TX_FREQ); // out: missing tx frequency average +JSS(kTXS); // out: TxHistory +JSS(kTYPE); // in: AccountObjects + // out: NetworkOPs, RPC server_definitions OverlayImpl, Logic +JSS(kTYPE_HEX); // out: STPathSet +JSS(kUNL); // out: UnlList +JSS(kUNLIMITED); // out: Connection.h +JSS(kUPTIME); // out: GetCounts +JSS(kURI); // out: ValidatorSites +JSS(kURL); // in/out: Subscribe, Unsubscribe +JSS(kURL_PASSWORD); // in: Subscribe +JSS(kURL_USERNAME); // in: Subscribe +JSS(kURLGRAVATAR); // +JSS(kUSERNAME); // in: Subscribe +JSS(kVALIDATED); // out: NetworkOPs, RPCHelpers, AccountTx*, Tx +JSS(kVALIDATOR_LIST_EXPIRES); // out: NetworkOps, ValidatorList +JSS(kVALIDATOR_LIST); // out: NetworkOps, ValidatorList +JSS(kVALIDATORS); // +JSS(kVALIDATED_HASH); // out: NetworkOPs +JSS(kVALIDATED_LEDGER); // out: NetworkOPs +JSS(kVALIDATED_LEDGER_INDEX); // out: SubmitTransaction +JSS(kVALIDATED_LEDGERS); // out: NetworkOPs +JSS(kVALIDATION_KEY); // out: ValidationCreate, ValidationSeed +JSS(kVALIDATION_PRIVATE_KEY); // out: ValidationCreate +JSS(kVALIDATION_PUBLIC_KEY); // out: ValidationCreate, ValidationSeed +JSS(kVALIDATION_QUORUM); // out: NetworkOPs +JSS(kVALIDATION_SEED); // out: ValidationCreate, ValidationSeed +JSS(kVALIDATIONS); // out: AmendmentTableImpl +JSS(kVALIDATOR_LIST_THRESHOLD); // out: ValidatorList +JSS(kVALIDATOR_SITES); // out: ValidatorSites +JSS(kVALUE); // out: STAmount +JSS(kVAULT_ID); // in: VaultInfo +JSS(kVERSION); // out: RPCVersion +JSS(kVETOED); // out: AmendmentTableImpl +JSS(kVOLUME_A); // out: BookChanges +JSS(kVOLUME_B); // out: BookChanges +JSS(kVOTE); // in: Feature +JSS(kVOTE_SLOTS); // out: amm_info +JSS(kVOTE_WEIGHT); // out: amm_info +JSS(kWARNING); // rpc: +JSS(kWARNINGS); // out: server_info, server_state +JSS(kWORKERS); // +JSS(kWRITE_LOAD); // out: GetCounts #pragma push_macro("TRANSACTION") #undef TRANSACTION diff --git a/include/xrpl/protocol/nft.h b/include/xrpl/protocol/nft.h index 6dce8d1045..ce73e244c1 100644 --- a/include/xrpl/protocol/nft.h +++ b/include/xrpl/protocol/nft.h @@ -15,7 +15,7 @@ namespace xrpl::nft { struct TaxonTag { }; -using Taxon = tagged_integer; +using Taxon = TaggedInteger; inline Taxon toTaxon(std::uint32_t i) @@ -29,11 +29,11 @@ toUInt32(Taxon t) return static_cast(t); } -constexpr std::uint16_t const flagBurnable = 0x0001; -constexpr std::uint16_t const flagOnlyXRP = 0x0002; -constexpr std::uint16_t const flagCreateTrustLines = 0x0004; -constexpr std::uint16_t const flagTransferable = 0x0008; -constexpr std::uint16_t const flagMutable = 0x0010; +constexpr std::uint16_t const kFLAG_BURNABLE = 0x0001; +constexpr std::uint16_t const kFLAG_ONLY_XRP = 0x0002; +constexpr std::uint16_t const kFLAG_CREATE_TRUST_LINES = 0x0004; +constexpr std::uint16_t const kFLAG_TRANSFERABLE = 0x0008; +constexpr std::uint16_t const kFLAG_MUTABLE = 0x0010; inline std::uint16_t getFlags(uint256 const& id) diff --git a/include/xrpl/protocol/tokens.h b/include/xrpl/protocol/tokens.h index 043db02825..e2b1549188 100644 --- a/include/xrpl/protocol/tokens.h +++ b/include/xrpl/protocol/tokens.h @@ -62,7 +62,7 @@ decodeBase58Token(std::string const& s, TokenType type); namespace detail { // Expose detail functions for unit tests only std::string -encodeBase58(void const* message, std::size_t size, void* temp, std::size_t temp_size); +encodeBase58(void const* message, std::size_t size, void* temp, std::size_t tempSize); std::string decodeBase58(std::string const& s); @@ -75,7 +75,7 @@ namespace b58_fast { // particular) [[nodiscard]] B58Result> encodeBase58Token( - TokenType token_type, + TokenType tokenType, std::span input, std::span out); diff --git a/include/xrpl/rdb/DBInit.h b/include/xrpl/rdb/DBInit.h index 56bc752343..59806b2e85 100644 --- a/include/xrpl/rdb/DBInit.h +++ b/include/xrpl/rdb/DBInit.h @@ -9,20 +9,20 @@ namespace xrpl { // These pragmas are built at startup and applied to all database // connections, unless otherwise noted. -inline constexpr char const* CommonDBPragmaJournal{"PRAGMA journal_mode=%s;"}; -inline constexpr char const* CommonDBPragmaSync{"PRAGMA synchronous=%s;"}; -inline constexpr char const* CommonDBPragmaTemp{"PRAGMA temp_store=%s;"}; +inline constexpr char const* kCOMMON_DB_PRAGMA_JOURNAL{"PRAGMA journal_mode=%s;"}; +inline constexpr char const* kCOMMON_DB_PRAGMA_SYNC{"PRAGMA synchronous=%s;"}; +inline constexpr char const* kCOMMON_DB_PRAGMA_TEMP{"PRAGMA temp_store=%s;"}; // A warning will be logged if any lower-safety sqlite tuning settings // are used and at least this much ledger history is configured. This // includes full history nodes. This is because such a large amount of // data will be more difficult to recover if a rare failure occurs, // which are more likely with some of the other available tuning settings. -inline constexpr std::uint32_t SQLITE_TUNING_CUTOFF = 10'000'000; +inline constexpr std::uint32_t kSQLITE_TUNING_CUTOFF = 10'000'000; // Ledger database holds ledgers and ledger confirmations -inline constexpr auto LgrDBName{"ledger.db"}; +inline constexpr auto kLGR_DB_NAME{"ledger.db"}; -inline constexpr std::array LgrDBInit{ +inline constexpr std::array kLGR_DB_INIT{ {"BEGIN TRANSACTION;", "CREATE TABLE IF NOT EXISTS Ledgers ( \ @@ -47,9 +47,9 @@ inline constexpr std::array LgrDBInit{ //////////////////////////////////////////////////////////////////////////////// // Transaction database holds transactions and public keys -inline constexpr auto TxDBName{"transaction.db"}; +inline constexpr auto kTX_DB_NAME{"transaction.db"}; -inline constexpr std::array TxDBInit{ +inline constexpr std::array kTX_DB_INIT{ {"BEGIN TRANSACTION;", "CREATE TABLE IF NOT EXISTS Transactions ( \ @@ -82,9 +82,9 @@ inline constexpr std::array TxDBInit{ //////////////////////////////////////////////////////////////////////////////// -inline constexpr auto WalletDBName{"wallet.db"}; +inline constexpr auto kWALLET_DB_NAME{"wallet.db"}; -inline constexpr std::array WalletDBInit{ +inline constexpr std::array kWALLET_DB_INIT{ {"BEGIN TRANSACTION;", // A node's identity must be persisted, including diff --git a/include/xrpl/resource/Charge.h b/include/xrpl/resource/Charge.h index 582688260e..ca252c1943 100644 --- a/include/xrpl/resource/Charge.h +++ b/include/xrpl/resource/Charge.h @@ -27,7 +27,7 @@ public: /** Converts this charge into a human readable string. */ [[nodiscard]] std::string - to_string() const; + toString() const; bool operator==(Charge const&) const; @@ -39,8 +39,8 @@ public: operator*(value_type m) const; private: - value_type m_cost; - std::string m_label; + value_type m_cost_; + std::string m_label_; }; std::ostream& diff --git a/include/xrpl/resource/Consumer.h b/include/xrpl/resource/Consumer.h index ebb214d129..e8e465029f 100644 --- a/include/xrpl/resource/Consumer.h +++ b/include/xrpl/resource/Consumer.h @@ -26,7 +26,7 @@ public: /** Return a human readable string uniquely identifying this consumer. */ [[nodiscard]] std::string - to_string() const; + toString() const; /** Returns `true` if this is a privileged endpoint. */ [[nodiscard]] bool @@ -71,8 +71,8 @@ public: setPublicKey(PublicKey const& publicKey); private: - Logic* m_logic; - Entry* m_entry; + Logic* m_logic_; + Entry* m_entry_; }; std::ostream& diff --git a/include/xrpl/resource/Disposition.h b/include/xrpl/resource/Disposition.h index 59a1c3840a..6dad8db19a 100644 --- a/include/xrpl/resource/Disposition.h +++ b/include/xrpl/resource/Disposition.h @@ -5,15 +5,15 @@ namespace xrpl::Resource { /** The disposition of a consumer after applying a load charge. */ enum class Disposition { /** No action required. */ - ok + Ok /** Consumer should be warned that consumption is high. */ , - warn + Warn /** Consumer should be disconnected for excess consumption. */ , - drop + Drop }; } // namespace xrpl::Resource diff --git a/include/xrpl/server/InfoSub.h b/include/xrpl/server/InfoSub.h index b6dff5983d..619b5404eb 100644 --- a/include/xrpl/server/InfoSub.h +++ b/include/xrpl/server/InfoSub.h @@ -72,7 +72,7 @@ public: * historical transactions * @return rpcSUCCESS if successful, otherwise an error code */ - virtual error_code_i + virtual ErrorCodeI subAccountHistory(ref ispListener, AccountID const& account) = 0; /** @@ -207,23 +207,23 @@ public: getApiVersion() const noexcept; protected: - std::mutex mLock; + std::mutex mLock_; private: - Consumer m_consumer; - Source& m_source; + Consumer m_consumer_; + Source& m_source_; hash_set realTimeSubscriptions_; hash_set normalSubscriptions_; std::shared_ptr request_; - std::uint64_t mSeq; + std::uint64_t mSeq_; hash_set accountHistorySubscriptions_; unsigned int apiVersion_ = 0; static int - assign_id() + assignId() { - static std::atomic id(0); - return ++id; + static std::atomic kID(0); + return ++kID; } }; diff --git a/include/xrpl/server/LoadFeeTrack.h b/include/xrpl/server/LoadFeeTrack.h index e54ea4d280..5ad3972836 100644 --- a/include/xrpl/server/LoadFeeTrack.h +++ b/include/xrpl/server/LoadFeeTrack.h @@ -63,7 +63,7 @@ public: static std::uint32_t getLoadBase() { - return lftNormalFee; + return kLFT_NORMAL_FEE; } std::uint32_t @@ -100,29 +100,29 @@ public: isLoadedLocal() const { std::scoped_lock const sl(lock_); - return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee); + return (raiseCount_ != 0) || (localTxnLoadFee_ != kLFT_NORMAL_FEE); } bool isLoadedCluster() const { std::scoped_lock const sl(lock_); - return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) || - (clusterTxnLoadFee_ != lftNormalFee); + return (raiseCount_ != 0) || (localTxnLoadFee_ != kLFT_NORMAL_FEE) || + (clusterTxnLoadFee_ != kLFT_NORMAL_FEE); } private: - static std::uint32_t constexpr lftNormalFee = 256; // 256 is the minimum/normal load factor - static std::uint32_t constexpr lftFeeIncFraction = 4; // increase fee by 1/4 - static std::uint32_t constexpr lftFeeDecFraction = 4; // decrease fee by 1/4 - static std::uint32_t constexpr lftFeeMax = lftNormalFee * 1000000; + static std::uint32_t constexpr kLFT_NORMAL_FEE = 256; // 256 is the minimum/normal load factor + static std::uint32_t constexpr kLFT_FEE_INC_FRACTION = 4; // increase fee by 1/4 + static std::uint32_t constexpr kLFT_FEE_DEC_FRACTION = 4; // decrease fee by 1/4 + static std::uint32_t constexpr kLFT_FEE_MAX = kLFT_NORMAL_FEE * 1000000; beast::Journal const j_; std::mutex mutable lock_; - std::uint32_t localTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee - std::uint32_t remoteTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee - std::uint32_t clusterTxnLoadFee_{lftNormalFee}; // Scale factor, lftNormalFee = normal fee + std::uint32_t localTxnLoadFee_{kLFT_NORMAL_FEE}; // Scale factor, lftNormalFee = normal fee + std::uint32_t remoteTxnLoadFee_{kLFT_NORMAL_FEE}; // Scale factor, lftNormalFee = normal fee + std::uint32_t clusterTxnLoadFee_{kLFT_NORMAL_FEE}; // Scale factor, lftNormalFee = normal fee std::uint32_t raiseCount_{0}; }; diff --git a/include/xrpl/server/Manifest.h b/include/xrpl/server/Manifest.h index e11d5dc0da..eed1c14dae 100644 --- a/include/xrpl/server/Manifest.h +++ b/include/xrpl/server/Manifest.h @@ -81,16 +81,16 @@ struct Manifest Manifest() = delete; Manifest( - std::string serialized_, - PublicKey const& masterKey_, - std::optional const& signingKey_, + std::string serialized, + PublicKey const& masterKey, + std::optional const& signingKey, std::uint32_t seq, - std::string domain_) - : serialized(std::move(serialized_)) - , masterKey(masterKey_) - , signingKey(signingKey_) + std::string domain) + : serialized(std::move(serialized)) + , masterKey(masterKey) + , signingKey(signingKey) , sequence(seq) - , domain(std::move(domain_)) + , domain(std::move(domain)) { } @@ -194,19 +194,19 @@ loadValidatorToken( enum class ManifestDisposition { /// Manifest is valid - accepted = 0, + Accepted = 0, /// Sequence is too old - stale, + Stale, /// The master key is not acceptable to us - badMasterKey, + BadMasterKey, /// The ephemeral key is not acceptable to us - badEphemeralKey, + BadEphemeralKey, /// Timely, but invalid signature - invalid + Invalid }; inline std::string @@ -214,15 +214,15 @@ to_string(ManifestDisposition m) { switch (m) { - case ManifestDisposition::accepted: + case ManifestDisposition::Accepted: return "accepted"; - case ManifestDisposition::stale: + case ManifestDisposition::Stale: return "stale"; - case ManifestDisposition::badMasterKey: + case ManifestDisposition::BadMasterKey: return "badMasterKey"; - case ManifestDisposition::badEphemeralKey: + case ManifestDisposition::BadEphemeralKey: return "badEphemeralKey"; - case ManifestDisposition::invalid: + case ManifestDisposition::Invalid: return "invalid"; default: return "unknown"; @@ -400,7 +400,7 @@ public: */ template void - for_each_manifest(Function&& f) const + forEachManifest(Function&& f) const { std::shared_lock const lock{mutex_}; for (auto const& [_, manifest] : map_) @@ -428,7 +428,7 @@ public: */ template void - for_each_manifest(PreFun&& pf, EachFun&& f) const + forEachManifest(PreFun&& pf, EachFun&& f) const { std::shared_lock const lock{mutex_}; pf(map_.size()); diff --git a/include/xrpl/shamap/FullBelowCache.h b/include/xrpl/shamap/FullBelowCache.h index e17a640672..e5aeba8e73 100644 --- a/include/xrpl/shamap/FullBelowCache.h +++ b/include/xrpl/shamap/FullBelowCache.h @@ -24,7 +24,7 @@ private: public: // Need to be named before converting // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) - enum { defaultCacheTargetSize = 0 }; + enum { DefaultCacheTargetSize = 0 }; using key_type = uint256; using clock_type = typename CacheType::clock_type; @@ -41,9 +41,9 @@ public: clock_type& clock, beast::Journal j, beast::insight::Collector::ptr const& collector = beast::insight::NullCollector::New(), - std::size_t target_size = defaultCacheTargetSize, + std::size_t targetSize = DefaultCacheTargetSize, std::chrono::seconds expiration = std::chrono::minutes{2}) - : m_cache(name, target_size, expiration, clock, j, collector), m_gen(1) + : m_cache_(name, targetSize, expiration, clock, j, collector), m_gen_(1) { } @@ -51,7 +51,7 @@ public: clock_type& clock() { - return m_cache.clock(); + return m_cache_.clock(); } /** Return the number of elements in the cache. @@ -61,7 +61,7 @@ public: std::size_t size() const { - return m_cache.size(); + return m_cache_.size(); } /** Remove expired cache items. @@ -71,7 +71,7 @@ public: void sweep() { - m_cache.sweep(); + m_cache_.sweep(); } /** Refresh the last access time of an item, if it exists. @@ -81,9 +81,9 @@ public: @return `true` If the key exists. */ bool - touch_if_exists(key_type const& key) + touchIfExists(key_type const& key) { - return m_cache.touch_if_exists(key); + return m_cache_.touchIfExists(key); } /** Insert a key into the cache. @@ -96,33 +96,33 @@ public: void insert(key_type const& key) { - m_cache.insert(key); + m_cache_.insert(key); } /** generation determines whether cached entry is valid */ std::uint32_t getGeneration(void) const { - return m_gen; + return m_gen_; } void clear() { - m_cache.clear(); - ++m_gen; + m_cache_.clear(); + ++m_gen_; } void reset() { - m_cache.clear(); - m_gen = 1; + m_cache_.clear(); + m_gen_ = 1; } private: - CacheType m_cache; - std::atomic m_gen; + CacheType m_cache_; + std::atomic m_gen_; }; } // namespace detail diff --git a/include/xrpl/shamap/SHAMap.h b/include/xrpl/shamap/SHAMap.h index 43b2734d65..ba48e1927b 100644 --- a/include/xrpl/shamap/SHAMap.h +++ b/include/xrpl/shamap/SHAMap.h @@ -94,10 +94,10 @@ private: public: /** Number of children each non-leaf node has (the 'radix tree' part of the * map) */ - static constexpr unsigned int branchFactor = SHAMapInnerNode::branchFactor; + static constexpr unsigned int kBRANCH_FACTOR = SHAMapInnerNode::kBRANCH_FACTOR; /** The depth of the hash map: data is only present in the leaves */ - static constexpr unsigned int leafDepth = 64; + static constexpr unsigned int kLEAF_DEPTH = 64; using DeltaItem = std::pair, boost::intrusive_ptr>; @@ -136,11 +136,11 @@ public: This is always a const iterator. Meets the requirements of ForwardRange. */ - class const_iterator; + class ConstIterator; - const_iterator + ConstIterator begin() const; - const_iterator + ConstIterator end() const; //-------------------------------------------------------------------------- @@ -199,8 +199,8 @@ public: @note The item does not need to exist. */ - const_iterator - upper_bound(uint256 const& id) const; + ConstIterator + upperBound(uint256 const& id) const; /** Find the object with the greatest object id smaller than the input id. @@ -208,8 +208,8 @@ public: @note The item does not need to exist. */ - const_iterator - lower_bound(uint256 const& id) const; + ConstIterator + lowerBound(uint256 const& id) const; /** Visit every node in this SHAMap @@ -390,7 +390,7 @@ private: lastBelow( intr_ptr::SharedPtr node, SharedPtrNodeStack& stack, - int branch = branchFactor) const; + int branch = kBRANCH_FACTOR) const; // helper function for firstBelow and lastBelow SHAMapLeafNode* @@ -469,14 +469,14 @@ private: operator=(MissingNodes const&) = delete; // basic parameters - int max_; - SHAMapSyncFilter* filter_; - int const maxDefer_; - std::uint32_t generation_; + int max; + SHAMapSyncFilter* filter; + int const maxDefer; + std::uint32_t generation; // nodes we have discovered to be missing - std::vector> missingNodes_; - std::set missingHashes_; + std::vector> missingNodes; + std::set missingHashes; // nodes we are in the process of traversing using StackEntry = std::tuple< @@ -491,7 +491,7 @@ private: // elements will not be invalidated during the course of element // insertion and removal. Containers that do not offer this guarantee, // such as std::vector, can't be used here. - std::stack> stack_; + std::stack> stack; // nodes we may have acquired from deferred reads using DeferredNode = std::tuple< @@ -500,28 +500,28 @@ private: int, // branch intr_ptr::SharedPtr>; // node - int deferred_; - std::mutex deferLock_; - std::condition_variable deferCondVar_; - std::vector finishedReads_; + int deferred; + std::mutex deferLock; + std::condition_variable deferCondVar; + std::vector finishedReads; // nodes we need to resume after we get their children from deferred // reads - std::map resumes_; + std::map resumes; MissingNodes(int max, SHAMapSyncFilter* filter, int maxDefer, std::uint32_t generation) - : max_(max), filter_(filter), maxDefer_(maxDefer), generation_(generation), deferred_(0) + : max(max), filter(filter), maxDefer(maxDefer), generation(generation), deferred(0) { - missingNodes_.reserve(max); - finishedReads_.reserve(maxDefer); + missingNodes.reserve(max); + finishedReads.reserve(maxDefer); } }; // getMissingNodes helper functions void - gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node); + gmnProcessNodes(MissingNodes&, MissingNodes::StackEntry& node); static void - gmn_ProcessDeferredReads(MissingNodes&); + gmnProcessDeferredReads(MissingNodes&); // fetch from DB helper function intr_ptr::SharedPtr @@ -579,7 +579,7 @@ SHAMap::setUnbacked() //------------------------------------------------------------------------------ -class SHAMap::const_iterator +class SHAMap::ConstIterator { public: using iterator_category = std::forward_iterator_tag; @@ -594,35 +594,35 @@ private: pointer item_ = nullptr; public: - const_iterator() = delete; + ConstIterator() = delete; - const_iterator(const_iterator const& other) = default; - const_iterator& - operator=(const_iterator const& other) = default; + ConstIterator(ConstIterator const& other) = default; + ConstIterator& + operator=(ConstIterator const& other) = default; - ~const_iterator() = default; + ~ConstIterator() = default; reference operator*() const; pointer operator->() const; - const_iterator& + ConstIterator& operator++(); - const_iterator + ConstIterator operator++(int); private: - explicit const_iterator(SHAMap const* map); - const_iterator(SHAMap const* map, std::nullptr_t); - const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack); + explicit ConstIterator(SHAMap const* map); + ConstIterator(SHAMap const* map, std::nullptr_t); + ConstIterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack); friend bool - operator==(const_iterator const& x, const_iterator const& y); + operator==(ConstIterator const& x, ConstIterator const& y); friend class SHAMap; }; -inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map) +inline SHAMap::ConstIterator::ConstIterator(SHAMap const* map) : map_(map) { XRPL_ASSERT(map_, "xrpl::SHAMap::const_iterator::const_iterator : non-null input"); @@ -630,11 +630,11 @@ inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map) item_ = temp->peekItem().get(); } -inline SHAMap::const_iterator::const_iterator(SHAMap const* map, std::nullptr_t) : map_(map) +inline SHAMap::ConstIterator::ConstIterator(SHAMap const* map, std::nullptr_t) : map_(map) { } -inline SHAMap::const_iterator::const_iterator( +inline SHAMap::ConstIterator::ConstIterator( SHAMap const* map, pointer item, SharedPtrNodeStack&& stack) @@ -642,20 +642,20 @@ inline SHAMap::const_iterator::const_iterator( { } -inline SHAMap::const_iterator::reference -SHAMap::const_iterator::operator*() const +inline SHAMap::ConstIterator::reference +SHAMap::ConstIterator::operator*() const { return *item_; } -inline SHAMap::const_iterator::pointer -SHAMap::const_iterator::operator->() const +inline SHAMap::ConstIterator::pointer +SHAMap::ConstIterator::operator->() const { return item_; } -inline SHAMap::const_iterator& -SHAMap::const_iterator::operator++() +inline SHAMap::ConstIterator& +SHAMap::ConstIterator::operator++() { if (auto temp = map_->peekNextItem(item_->key(), stack_)) { @@ -668,8 +668,8 @@ SHAMap::const_iterator::operator++() return *this; } -inline SHAMap::const_iterator -SHAMap::const_iterator::operator++(int) +inline SHAMap::ConstIterator +SHAMap::ConstIterator::operator++(int) { auto tmp = *this; ++(*this); @@ -677,7 +677,7 @@ SHAMap::const_iterator::operator++(int) } inline bool -operator==(SHAMap::const_iterator const& x, SHAMap::const_iterator const& y) +operator==(SHAMap::ConstIterator const& x, SHAMap::ConstIterator const& y) { XRPL_ASSERT( x.map_ == y.map_, @@ -687,21 +687,21 @@ operator==(SHAMap::const_iterator const& x, SHAMap::const_iterator const& y) } inline bool -operator!=(SHAMap::const_iterator const& x, SHAMap::const_iterator const& y) +operator!=(SHAMap::ConstIterator const& x, SHAMap::ConstIterator const& y) { return !(x == y); } -inline SHAMap::const_iterator +inline SHAMap::ConstIterator SHAMap::begin() const { - return const_iterator(this); + return ConstIterator(this); } -inline SHAMap::const_iterator +inline SHAMap::ConstIterator SHAMap::end() const { - return const_iterator(this, nullptr); + return ConstIterator(this, nullptr); } } // namespace xrpl diff --git a/include/xrpl/shamap/SHAMapAddNode.h b/include/xrpl/shamap/SHAMapAddNode.h index a560568126..94e5c8f6cb 100644 --- a/include/xrpl/shamap/SHAMapAddNode.h +++ b/include/xrpl/shamap/SHAMapAddNode.h @@ -8,9 +8,9 @@ namespace xrpl { class SHAMapAddNode { private: - int mGood; - int mBad; - int mDuplicate; + int mGood_; + int mBad_; + int mDuplicate_; public: SHAMapAddNode(); @@ -47,63 +47,63 @@ private: SHAMapAddNode(int good, int bad, int duplicate); }; -inline SHAMapAddNode::SHAMapAddNode() : mGood(0), mBad(0), mDuplicate(0) +inline SHAMapAddNode::SHAMapAddNode() : mGood_(0), mBad_(0), mDuplicate_(0) { } inline SHAMapAddNode::SHAMapAddNode(int good, int bad, int duplicate) - : mGood(good), mBad(bad), mDuplicate(duplicate) + : mGood_(good), mBad_(bad), mDuplicate_(duplicate) { } inline void SHAMapAddNode::incInvalid() { - ++mBad; + ++mBad_; } inline void SHAMapAddNode::incUseful() { - ++mGood; + ++mGood_; } inline void SHAMapAddNode::incDuplicate() { - ++mDuplicate; + ++mDuplicate_; } inline void SHAMapAddNode::reset() { - mGood = mBad = mDuplicate = 0; + mGood_ = mBad_ = mDuplicate_ = 0; } inline int SHAMapAddNode::getGood() const { - return mGood; + return mGood_; } inline bool SHAMapAddNode::isInvalid() const { - return mBad > 0; + return mBad_ > 0; } inline bool SHAMapAddNode::isUseful() const { - return mGood > 0; + return mGood_ > 0; } inline SHAMapAddNode& SHAMapAddNode::operator+=(SHAMapAddNode const& n) { - mGood += n.mGood; - mBad += n.mBad; - mDuplicate += n.mDuplicate; + mGood_ += n.mGood_; + mBad_ += n.mBad_; + mDuplicate_ += n.mDuplicate_; return *this; } @@ -111,7 +111,7 @@ SHAMapAddNode::operator+=(SHAMapAddNode const& n) inline bool SHAMapAddNode::isGood() const { - return (mGood + mDuplicate) > mBad; + return (mGood_ + mDuplicate_) > mBad_; } inline SHAMapAddNode @@ -136,24 +136,24 @@ inline std::string SHAMapAddNode::get() const { std::string ret; - if (mGood > 0) + if (mGood_ > 0) { ret.append("good:"); - ret.append(std::to_string(mGood)); + ret.append(std::to_string(mGood_)); } - if (mBad > 0) + if (mBad_ > 0) { if (!ret.empty()) ret.append(" "); ret.append("bad:"); - ret.append(std::to_string(mBad)); + ret.append(std::to_string(mBad_)); } - if (mDuplicate > 0) + if (mDuplicate_ > 0) { if (!ret.empty()) ret.append(" "); ret.append("dupe:"); - ret.append(std::to_string(mDuplicate)); + ret.append(std::to_string(mDuplicate_)); } if (ret.empty()) ret = "no nodes processed"; diff --git a/include/xrpl/shamap/SHAMapInnerNode.h b/include/xrpl/shamap/SHAMapInnerNode.h index f2c34cbc1a..ee2a18bf03 100644 --- a/include/xrpl/shamap/SHAMapInnerNode.h +++ b/include/xrpl/shamap/SHAMapInnerNode.h @@ -15,7 +15,7 @@ class SHAMapInnerNode final : public SHAMapTreeNode, public CountedObject makeFullInner(Slice data, SHAMapHash const& hash, bool hashValid); diff --git a/include/xrpl/shamap/SHAMapItem.h b/include/xrpl/shamap/SHAMapItem.h index da70e16db3..5791cf93f3 100644 --- a/include/xrpl/shamap/SHAMapItem.h +++ b/include/xrpl/shamap/SHAMapItem.h @@ -93,7 +93,7 @@ namespace detail { // The slab cutoffs and the number of megabytes per allocation are customized // based on the number of objects of each size we expect to need at any point // in time and with an eye to minimize the number of slack bytes in a block. -inline SlabAllocatorSet slabber({ +inline SlabAllocatorSet gSlabber({ { 128, megabytes(std::size_t(60)) }, { 192, megabytes(std::size_t(46)) }, { 272, megabytes(std::size_t(60)) }, @@ -130,7 +130,7 @@ intrusive_ptr_release(SHAMapItem const* x) // If the slabber doesn't claim this pointer, it was allocated // manually, so we free it manually. - if (!detail::slabber.deallocate(const_cast(p))) + if (!detail::gSlabber.deallocate(const_cast(p))) delete[] p; } } @@ -142,7 +142,7 @@ make_shamapitem(uint256 const& tag, Slice data) data.size() <= megabytes(16), "xrpl::make_shamapitem : maximum input size"); // NOLINTNEXTLINE(misc-const-correctness) - std::uint8_t* raw = detail::slabber.allocate(data.size()); + std::uint8_t* raw = detail::gSlabber.allocate(data.size()); // If we can't grab memory from the slab allocators, we fall back to // the standard library and try to grab a precisely-sized memory block: diff --git a/include/xrpl/shamap/SHAMapLeafNode.h b/include/xrpl/shamap/SHAMapLeafNode.h index a63041c31c..af5ed29702 100644 --- a/include/xrpl/shamap/SHAMapLeafNode.h +++ b/include/xrpl/shamap/SHAMapLeafNode.h @@ -37,7 +37,7 @@ public: } void - invariants(bool is_root = false) const final; + invariants(bool isRoot = false) const final; public: boost::intrusive_ptr const& diff --git a/include/xrpl/shamap/SHAMapMissingNode.h b/include/xrpl/shamap/SHAMapMissingNode.h index f1670587eb..0bc072463e 100644 --- a/include/xrpl/shamap/SHAMapMissingNode.h +++ b/include/xrpl/shamap/SHAMapMissingNode.h @@ -28,7 +28,7 @@ to_string(SHAMapType t) case SHAMapType::FREE: return "Free Tree"; default: - return std::to_string(safe_cast>(t)); + return std::to_string(safeCast>(t)); } } diff --git a/include/xrpl/shamap/SHAMapTreeNode.h b/include/xrpl/shamap/SHAMapTreeNode.h index 55b18a2d12..d50fc65ccb 100644 --- a/include/xrpl/shamap/SHAMapTreeNode.h +++ b/include/xrpl/shamap/SHAMapTreeNode.h @@ -14,17 +14,17 @@ namespace xrpl { // These are wire-protocol identifiers used during serialization to encode the // type of a node. They should not be arbitrarily be changed. -static constexpr unsigned char const wireTypeTransaction = 0; -static constexpr unsigned char const wireTypeAccountState = 1; -static constexpr unsigned char const wireTypeInner = 2; -static constexpr unsigned char const wireTypeCompressedInner = 3; -static constexpr unsigned char const wireTypeTransactionWithMeta = 4; +static constexpr unsigned char const kWIRE_TYPE_TRANSACTION = 0; +static constexpr unsigned char const kWIRE_TYPE_ACCOUNT_STATE = 1; +static constexpr unsigned char const kWIRE_TYPE_INNER = 2; +static constexpr unsigned char const kWIRE_TYPE_COMPRESSED_INNER = 3; +static constexpr unsigned char const kWIRE_TYPE_TRANSACTION_WITH_META = 4; enum class SHAMapNodeType { - tnINNER = 1, - tnTRANSACTION_NM = 2, // transaction, no metadata - tnTRANSACTION_MD = 3, // transaction, with metadata - tnACCOUNT_STATE = 4 + TnInner = 1, + TnTransactionNm = 2, // transaction, no metadata + TnTransactionMd = 3, // transaction, with metadata + TnAccountState = 4 }; class SHAMapTreeNode : public IntrusiveRefCounts @@ -147,7 +147,7 @@ public: getString(SHAMapNodeID const&) const; virtual void - invariants(bool is_root = false) const = 0; + invariants(bool isRoot = false) const = 0; static intr_ptr::SharedPtr makeFromPrefix(Slice rawNode, SHAMapHash const& hash); diff --git a/include/xrpl/shamap/detail/TaggedPointer.h b/include/xrpl/shamap/detail/TaggedPointer.h index 31d5f2ba65..d3c0a6542f 100644 --- a/include/xrpl/shamap/detail/TaggedPointer.h +++ b/include/xrpl/shamap/detail/TaggedPointer.h @@ -47,9 +47,9 @@ private: */ std::uintptr_t tp_ = 0; /** bit-and with this mask to get the tag bits (lowest two bits) */ - static constexpr std::uintptr_t tagMask = 3; + static constexpr std::uintptr_t kTAG_MASK = 3; /** bit-and with this mask to get the pointer bits (mask out the tag) */ - static constexpr std::uintptr_t ptrMask = ~tagMask; + static constexpr std::uintptr_t kPTR_MASK = ~kTAG_MASK; /** Deallocate memory and run destructors */ void diff --git a/include/xrpl/tx/ApplyContext.h b/include/xrpl/tx/ApplyContext.h index ea936017e0..910ec6be42 100644 --- a/include/xrpl/tx/ApplyContext.h +++ b/include/xrpl/tx/ApplyContext.h @@ -34,7 +34,7 @@ public: beast::Journal journal = beast::Journal{beast::Journal::getNullSink()}) : ApplyContext(registry, base, std::nullopt, tx, preclaimResult, baseFee, flags, journal) { - XRPL_ASSERT((flags & tapBATCH) == 0, "Batch apply flag should not be set"); + XRPL_ASSERT((flags & TapBatch) == 0, "Batch apply flag should not be set"); } std::reference_wrapper registry; diff --git a/include/xrpl/tx/Transactor.h b/include/xrpl/tx/Transactor.h index 918bbe5da6..98a26e7570 100644 --- a/include/xrpl/tx/Transactor.h +++ b/include/xrpl/tx/Transactor.h @@ -23,31 +23,31 @@ public: beast::Journal const j; PreflightContext( - ServiceRegistry& registry_, - STTx const& tx_, - uint256 parentBatchId_, - Rules rules_, - ApplyFlags flags_, - beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : registry(registry_) - , tx(tx_) - , rules(std::move(rules_)) - , flags(flags_) - , parentBatchId(parentBatchId_) - , j(j_) + ServiceRegistry& registry, + STTx const& tx, + uint256 parentBatchId, + Rules rules, + ApplyFlags flags, + beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) + : registry(registry) + , tx(tx) + , rules(std::move(rules)) + , flags(flags) + , parentBatchId(parentBatchId) + , j(j) { - XRPL_ASSERT((flags_ & tapBATCH) == tapBATCH, "Batch apply flag should be set"); + XRPL_ASSERT((flags & TapBatch) == TapBatch, "Batch apply flag should be set"); } PreflightContext( - ServiceRegistry& registry_, - STTx const& tx_, - Rules rules_, - ApplyFlags flags_, - beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : registry(registry_), tx(tx_), rules(std::move(rules_)), flags(flags_), j(j_) + ServiceRegistry& registry, + STTx const& tx, + Rules rules, + ApplyFlags flags, + beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) + : registry(registry), tx(tx), rules(std::move(rules)), flags(flags), j(j) { - XRPL_ASSERT((flags_ & tapBATCH) == 0, "Batch apply flag should not be set"); + XRPL_ASSERT((flags & TapBatch) == 0, "Batch apply flag should not be set"); } PreflightContext& @@ -67,36 +67,36 @@ public: beast::Journal const j; PreclaimContext( - ServiceRegistry& registry_, - ReadView const& view_, - TER preflightResult_, - STTx const& tx_, - ApplyFlags flags_, - std::optional parentBatchId_, - beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : registry(registry_) - , view(view_) - , preflightResult(preflightResult_) - , flags(flags_) - , tx(tx_) - , parentBatchId(parentBatchId_) - , j(j_) + ServiceRegistry& registry, + ReadView const& view, + TER preflightResult, + STTx const& tx, + ApplyFlags flags, + std::optional parentBatchId, + beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) + : registry(registry) + , view(view) + , preflightResult(preflightResult) + , flags(flags) + , tx(tx) + , parentBatchId(parentBatchId) + , j(j) { XRPL_ASSERT( - parentBatchId.has_value() == ((flags_ & tapBATCH) == tapBATCH), + parentBatchId.has_value() == ((flags & TapBatch) == TapBatch), "Parent Batch ID should be set if batch apply flag is set"); } PreclaimContext( - ServiceRegistry& registry_, - ReadView const& view_, - TER preflightResult_, - STTx const& tx_, - ApplyFlags flags_, - beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : PreclaimContext(registry_, view_, preflightResult_, tx_, flags_, std::nullopt, j_) + ServiceRegistry& registry, + ReadView const& view, + TER preflightResult, + STTx const& tx, + ApplyFlags flags, + beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) + : PreclaimContext(registry, view, preflightResult, tx, flags, std::nullopt, j) { - XRPL_ASSERT((flags_ & tapBATCH) == 0, "Batch apply flag should not be set"); + XRPL_ASSERT((flags & TapBatch) == 0, "Batch apply flag should not be set"); } PreclaimContext& @@ -220,7 +220,7 @@ public: { // Most transactors do nothing // after checkSeq/Fee/Sign. - return tesSUCCESS; + return TesSuccess; } static NotTEC @@ -456,10 +456,10 @@ Transactor::invokePreflight(PreflightContext const& ctx) auto const feature = Permission::getInstance().getTxFeature(ctx.tx.getTxnType()); if (feature && !ctx.rules.enabled(*feature)) - return temDISABLED; + return TemDisabled; if (!T::checkExtraFeatures(ctx)) - return temDISABLED; + return TemDisabled; if (auto const ret = preflight1(ctx, T::getFlagsMask(ctx))) return ret; diff --git a/include/xrpl/tx/applySteps.h b/include/xrpl/tx/applySteps.h index dc4140956c..897cf500d6 100644 --- a/include/xrpl/tx/applySteps.h +++ b/include/xrpl/tx/applySteps.h @@ -27,7 +27,7 @@ struct ApplyResult inline bool isTecClaimHardFail(TER ter, ApplyFlags flags) { - return isTecClaim(ter) && ((flags & tapRETRY) == 0u); + return isTecClaim(ter) && ((flags & TapRetry) == 0u); } /** Class describing the consequences to the account @@ -41,10 +41,10 @@ public: /// transactions enum class Category { /// Moves currency around, creates offers, etc. - normal = 0, + Normal = 0, /// Affects the ability of subsequent transactions /// to claim a fee. Eg. `SetRegularKey` - blocker + Blocker }; private: @@ -160,13 +160,13 @@ public: /// Constructor template - PreflightResult(Context const& ctx_, std::pair const& result) - : tx(ctx_.tx) - , parentBatchId(ctx_.parentBatchId) - , rules(ctx_.rules) + PreflightResult(Context const& ctx, std::pair const& result) + : tx(ctx.tx) + , parentBatchId(ctx.parentBatchId) + , rules(ctx.rules) , consequences(result.second) - , flags(ctx_.flags) - , j(ctx_.j) + , flags(ctx.flags) + , j(ctx.j) , ter(result.first) { } @@ -206,13 +206,13 @@ public: /// Constructor template - PreclaimResult(Context const& ctx_, TER ter_) - : view(ctx_.view) - , tx(ctx_.tx) - , parentBatchId(ctx_.parentBatchId) - , flags(ctx_.flags) - , j(ctx_.j) - , ter(ter_) + PreclaimResult(Context const& ctx, TER ter) + : view(ctx.view) + , tx(ctx.tx) + , parentBatchId(ctx.parentBatchId) + , flags(ctx.flags) + , j(ctx.j) + , ter(ter) , likelyToClaimFee(isTesSuccess(ter) || isTecClaimHardFail(ter, flags)) { } diff --git a/include/xrpl/tx/paths/detail/Steps.h b/include/xrpl/tx/paths/detail/Steps.h index 9b37f06ca9..48fafe0eb6 100644 --- a/include/xrpl/tx/paths/detail/Steps.h +++ b/include/xrpl/tx/paths/detail/Steps.h @@ -18,21 +18,21 @@ class ReadView; class ApplyView; class AMMContext; -enum class DebtDirection { issues, redeems }; -enum class QualityDirection { in, out }; -enum class StrandDirection { forward, reverse }; -enum class OfferCrossing { no = 0, yes = 1, sell = 2 }; +enum class DebtDirection { Issues, Redeems }; +enum class QualityDirection { In, Out }; +enum class StrandDirection { Forward, Reverse }; +enum class OfferCrossing { No = 0, Yes = 1, Sell = 2 }; inline bool redeems(DebtDirection dir) { - return dir == DebtDirection::redeems; + return dir == DebtDirection::Redeems; } inline bool issues(DebtDirection dir) { - return dir == DebtDirection::issues; + return dir == DebtDirection::Issues; } /** @@ -460,7 +460,7 @@ public: [[nodiscard]] bool isZero(EitherAmount const& out) const override { - return get(out) == beast::zero; + return get(out) == beast::kZERO; } [[nodiscard]] bool @@ -547,24 +547,24 @@ struct StrandContext /** StrandContext constructor. */ StrandContext( - ReadView const& view_, - std::vector> const& strand_, + ReadView const& view, + std::vector> const& strand, // A strand may not include an inner node that // replicates the source or destination. - AccountID const& strandSrc_, - AccountID const& strandDst_, - Asset const& strandDeliver_, - std::optional const& limitQuality_, - bool isLast_, - bool ownerPaysTransferFee_, - OfferCrossing offerCrossing_, - bool isDefaultPath_, + AccountID const& strandSrc, + AccountID const& strandDst, + Asset const& strandDeliver, + std::optional const& limitQuality, + bool isLast, + bool ownerPaysTransferFee, + OfferCrossing offerCrossing, + bool isDefaultPath, std::array, 2>& - seenDirectAssets_, ///< For detecting currency loops - boost::container::flat_set& seenBookOuts_, ///< For detecting book loops - AMMContext& ammContext_, + seenDirectAssets, ///< For detecting currency loops + boost::container::flat_set& seenBookOuts, ///< For detecting book loops + AMMContext& ammContext, std::optional const& domainID, - beast::Journal j_); ///< Journal for logging + beast::Journal j); ///< Journal for logging }; /// @cond INTERNAL diff --git a/include/xrpl/tx/transactors/account/AccountDelete.h b/include/xrpl/tx/transactors/account/AccountDelete.h index 23fc55da48..1491ae09d9 100644 --- a/include/xrpl/tx/transactors/account/AccountDelete.h +++ b/include/xrpl/tx/transactors/account/AccountDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class AccountDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit AccountDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/account/AccountSet.h b/include/xrpl/tx/transactors/account/AccountSet.h index fd2106e20c..780ad846da 100644 --- a/include/xrpl/tx/transactors/account/AccountSet.h +++ b/include/xrpl/tx/transactors/account/AccountSet.h @@ -8,7 +8,7 @@ namespace xrpl { class AccountSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; explicit AccountSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/account/SetRegularKey.h b/include/xrpl/tx/transactors/account/SetRegularKey.h index 54e574939a..22a40714db 100644 --- a/include/xrpl/tx/transactors/account/SetRegularKey.h +++ b/include/xrpl/tx/transactors/account/SetRegularKey.h @@ -7,7 +7,7 @@ namespace xrpl { class SetRegularKey : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit SetRegularKey(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/account/SignerListSet.h b/include/xrpl/tx/transactors/account/SignerListSet.h index 12419076e3..16e7bf3a06 100644 --- a/include/xrpl/tx/transactors/account/SignerListSet.h +++ b/include/xrpl/tx/transactors/account/SignerListSet.h @@ -18,13 +18,13 @@ class SignerListSet : public Transactor { private: // Values determined during preCompute for use later. - enum class Operation { unknown, set, destroy }; - Operation do_{Operation::unknown}; + enum class Operation { Unknown, Set, Destroy }; + Operation do_{Operation::Unknown}; std::uint32_t quorum_{0}; std::vector signers_; public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit SignerListSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/bridge/XChainBridge.h b/include/xrpl/tx/transactors/bridge/XChainBridge.h index cd16c0b791..79755c0c2f 100644 --- a/include/xrpl/tx/transactors/bridge/XChainBridge.h +++ b/include/xrpl/tx/transactors/bridge/XChainBridge.h @@ -5,14 +5,14 @@ namespace xrpl { -constexpr size_t xbridgeMaxAccountCreateClaims = 128; +constexpr size_t kXBRIDGE_MAX_ACCOUNT_CREATE_CLAIMS = 128; // Attach a new bridge to a door account. Once this is done, the cross-chain // transfer transactions may be used to transfer funds from this account. class XChainCreateBridge : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit XChainCreateBridge(ApplyContext& ctx) : Transactor(ctx) { @@ -45,7 +45,7 @@ public: class BridgeModify : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit BridgeModify(ApplyContext& ctx) : Transactor(ctx) { @@ -95,7 +95,7 @@ class XChainClaim : public Transactor { public: // Blocker since we cannot accurately calculate the consequences - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit XChainClaim(ApplyContext& ctx) : Transactor(ctx) { @@ -133,7 +133,7 @@ public: class XChainCommit : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; static TxConsequences makeTxConsequences(PreflightContext const& ctx); @@ -179,7 +179,7 @@ public: class XChainCreateClaimID : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit XChainCreateClaimID(ApplyContext& ctx) : Transactor(ctx) { @@ -222,7 +222,7 @@ class XChainAddClaimAttestation : public Transactor { public: // Blocker since we cannot accurately calculate the consequences - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit XChainAddClaimAttestation(ApplyContext& ctx) : Transactor(ctx) { @@ -256,7 +256,7 @@ class XChainAddAccountCreateAttestation : public Transactor { public: // Blocker since we cannot accurately calculate the consequences - static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Blocker}; explicit XChainAddAccountCreateAttestation(ApplyContext& ctx) : Transactor(ctx) { @@ -314,7 +314,7 @@ public: class XChainCreateAccountCommit : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit XChainCreateAccountCommit(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/check/CheckCancel.h b/include/xrpl/tx/transactors/check/CheckCancel.h index 14abeaa978..4861a05a02 100644 --- a/include/xrpl/tx/transactors/check/CheckCancel.h +++ b/include/xrpl/tx/transactors/check/CheckCancel.h @@ -7,7 +7,7 @@ namespace xrpl { class CheckCancel : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CheckCancel(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/check/CheckCash.h b/include/xrpl/tx/transactors/check/CheckCash.h index 312c5a983e..c831cc279e 100644 --- a/include/xrpl/tx/transactors/check/CheckCash.h +++ b/include/xrpl/tx/transactors/check/CheckCash.h @@ -7,7 +7,7 @@ namespace xrpl { class CheckCash : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CheckCash(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/check/CheckCreate.h b/include/xrpl/tx/transactors/check/CheckCreate.h index ff24d36e2c..494870cb1c 100644 --- a/include/xrpl/tx/transactors/check/CheckCreate.h +++ b/include/xrpl/tx/transactors/check/CheckCreate.h @@ -7,7 +7,7 @@ namespace xrpl { class CheckCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CheckCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/credentials/CredentialAccept.h b/include/xrpl/tx/transactors/credentials/CredentialAccept.h index f3abc80666..0da5dd6131 100644 --- a/include/xrpl/tx/transactors/credentials/CredentialAccept.h +++ b/include/xrpl/tx/transactors/credentials/CredentialAccept.h @@ -7,7 +7,7 @@ namespace xrpl { class CredentialAccept : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CredentialAccept(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/credentials/CredentialCreate.h b/include/xrpl/tx/transactors/credentials/CredentialCreate.h index 22247feb36..d7a1a245df 100644 --- a/include/xrpl/tx/transactors/credentials/CredentialCreate.h +++ b/include/xrpl/tx/transactors/credentials/CredentialCreate.h @@ -7,7 +7,7 @@ namespace xrpl { class CredentialCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CredentialCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/credentials/CredentialDelete.h b/include/xrpl/tx/transactors/credentials/CredentialDelete.h index 91ea4d05ad..60de0957ca 100644 --- a/include/xrpl/tx/transactors/credentials/CredentialDelete.h +++ b/include/xrpl/tx/transactors/credentials/CredentialDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class CredentialDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit CredentialDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/delegate/DelegateSet.h b/include/xrpl/tx/transactors/delegate/DelegateSet.h index eaa22532ae..ee4bfeaaef 100644 --- a/include/xrpl/tx/transactors/delegate/DelegateSet.h +++ b/include/xrpl/tx/transactors/delegate/DelegateSet.h @@ -7,7 +7,7 @@ namespace xrpl { class DelegateSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit DelegateSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMBid.h b/include/xrpl/tx/transactors/dex/AMMBid.h index e872c0d12d..979ca0250d 100644 --- a/include/xrpl/tx/transactors/dex/AMMBid.h +++ b/include/xrpl/tx/transactors/dex/AMMBid.h @@ -45,7 +45,7 @@ namespace xrpl { class AMMBid : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMBid(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMClawback.h b/include/xrpl/tx/transactors/dex/AMMClawback.h index 4f44da60d2..3cf6288ccf 100644 --- a/include/xrpl/tx/transactors/dex/AMMClawback.h +++ b/include/xrpl/tx/transactors/dex/AMMClawback.h @@ -7,7 +7,7 @@ class Sandbox; class AMMClawback : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMClawback(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMCreate.h b/include/xrpl/tx/transactors/dex/AMMCreate.h index a3ee083b9a..485273ca17 100644 --- a/include/xrpl/tx/transactors/dex/AMMCreate.h +++ b/include/xrpl/tx/transactors/dex/AMMCreate.h @@ -37,7 +37,7 @@ namespace xrpl { class AMMCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMDelete.h b/include/xrpl/tx/transactors/dex/AMMDelete.h index a1708eec88..1fbb4ec9e8 100644 --- a/include/xrpl/tx/transactors/dex/AMMDelete.h +++ b/include/xrpl/tx/transactors/dex/AMMDelete.h @@ -13,7 +13,7 @@ namespace xrpl { class AMMDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMDeposit.h b/include/xrpl/tx/transactors/dex/AMMDeposit.h index 87f2871d27..3847a2a529 100644 --- a/include/xrpl/tx/transactors/dex/AMMDeposit.h +++ b/include/xrpl/tx/transactors/dex/AMMDeposit.h @@ -42,7 +42,7 @@ class Sandbox; class AMMDeposit : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMDeposit(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMVote.h b/include/xrpl/tx/transactors/dex/AMMVote.h index f83cdcfcd2..c1fa059bd6 100644 --- a/include/xrpl/tx/transactors/dex/AMMVote.h +++ b/include/xrpl/tx/transactors/dex/AMMVote.h @@ -30,7 +30,7 @@ namespace xrpl { class AMMVote : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMVote(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/AMMWithdraw.h b/include/xrpl/tx/transactors/dex/AMMWithdraw.h index a07cfca693..cbaae78433 100644 --- a/include/xrpl/tx/transactors/dex/AMMWithdraw.h +++ b/include/xrpl/tx/transactors/dex/AMMWithdraw.h @@ -50,7 +50,7 @@ enum class WithdrawAll : bool { No = false, Yes }; class AMMWithdraw : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/OfferCancel.h b/include/xrpl/tx/transactors/dex/OfferCancel.h index d18808d236..a8e408492e 100644 --- a/include/xrpl/tx/transactors/dex/OfferCancel.h +++ b/include/xrpl/tx/transactors/dex/OfferCancel.h @@ -8,7 +8,7 @@ namespace xrpl { class OfferCancel : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit OfferCancel(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/dex/OfferCreate.h b/include/xrpl/tx/transactors/dex/OfferCreate.h index 09c9c0dd6f..2c5e63705a 100644 --- a/include/xrpl/tx/transactors/dex/OfferCreate.h +++ b/include/xrpl/tx/transactors/dex/OfferCreate.h @@ -12,7 +12,7 @@ class Sandbox; class OfferCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; /** Construct a Transactor subclass that creates an offer in the ledger. */ explicit OfferCreate(ApplyContext& ctx) : Transactor(ctx) @@ -56,7 +56,7 @@ public: private: std::pair - applyGuts(Sandbox& view, Sandbox& view_cancel); + applyGuts(Sandbox& view, Sandbox& viewCancel); // Determine if we are authorized to hold the asset we want to get. static TER @@ -76,13 +76,13 @@ private: std::optional const& domainID); static std::string - format_amount(STAmount const& amount); + formatAmount(STAmount const& amount); TER applyHybrid( Sandbox& sb, std::shared_ptr sleOffer, - Keylet const& offer_index, + Keylet const& offerIndex, STAmount const& saTakerPays, STAmount const& saTakerGets, std::function)> const& setDir); diff --git a/include/xrpl/tx/transactors/did/DIDDelete.h b/include/xrpl/tx/transactors/did/DIDDelete.h index 47b4112762..2699307b39 100644 --- a/include/xrpl/tx/transactors/did/DIDDelete.h +++ b/include/xrpl/tx/transactors/did/DIDDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class DIDDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit DIDDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/did/DIDSet.h b/include/xrpl/tx/transactors/did/DIDSet.h index 2e88570065..fa07cfc295 100644 --- a/include/xrpl/tx/transactors/did/DIDSet.h +++ b/include/xrpl/tx/transactors/did/DIDSet.h @@ -7,7 +7,7 @@ namespace xrpl { class DIDSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit DIDSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/escrow/EscrowCancel.h b/include/xrpl/tx/transactors/escrow/EscrowCancel.h index 253d88613f..13270b6741 100644 --- a/include/xrpl/tx/transactors/escrow/EscrowCancel.h +++ b/include/xrpl/tx/transactors/escrow/EscrowCancel.h @@ -7,7 +7,7 @@ namespace xrpl { class EscrowCancel : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit EscrowCancel(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/escrow/EscrowCreate.h b/include/xrpl/tx/transactors/escrow/EscrowCreate.h index 3cbeb47fa1..4e809e3bf5 100644 --- a/include/xrpl/tx/transactors/escrow/EscrowCreate.h +++ b/include/xrpl/tx/transactors/escrow/EscrowCreate.h @@ -7,7 +7,7 @@ namespace xrpl { class EscrowCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; explicit EscrowCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/escrow/EscrowFinish.h b/include/xrpl/tx/transactors/escrow/EscrowFinish.h index 6279b3a9af..0fc6b46311 100644 --- a/include/xrpl/tx/transactors/escrow/EscrowFinish.h +++ b/include/xrpl/tx/transactors/escrow/EscrowFinish.h @@ -7,7 +7,7 @@ namespace xrpl { class EscrowFinish : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit EscrowFinish(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanBrokerCoverClawback.h b/include/xrpl/tx/transactors/lending/LoanBrokerCoverClawback.h index 9a028b6448..a774e23717 100644 --- a/include/xrpl/tx/transactors/lending/LoanBrokerCoverClawback.h +++ b/include/xrpl/tx/transactors/lending/LoanBrokerCoverClawback.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanBrokerCoverClawback : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanBrokerCoverClawback(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanBrokerCoverDeposit.h b/include/xrpl/tx/transactors/lending/LoanBrokerCoverDeposit.h index 9b0cd9b176..f69c47afbc 100644 --- a/include/xrpl/tx/transactors/lending/LoanBrokerCoverDeposit.h +++ b/include/xrpl/tx/transactors/lending/LoanBrokerCoverDeposit.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanBrokerCoverDeposit : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanBrokerCoverDeposit(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.h b/include/xrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.h index 74c35d5667..b70b0a758a 100644 --- a/include/xrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.h +++ b/include/xrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanBrokerCoverWithdraw : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanBrokerCoverWithdraw(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanBrokerDelete.h b/include/xrpl/tx/transactors/lending/LoanBrokerDelete.h index 3de0f6fec2..ca58fc75bd 100644 --- a/include/xrpl/tx/transactors/lending/LoanBrokerDelete.h +++ b/include/xrpl/tx/transactors/lending/LoanBrokerDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanBrokerDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanBrokerDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanBrokerSet.h b/include/xrpl/tx/transactors/lending/LoanBrokerSet.h index 519ccd6ce9..6c07740f9a 100644 --- a/include/xrpl/tx/transactors/lending/LoanBrokerSet.h +++ b/include/xrpl/tx/transactors/lending/LoanBrokerSet.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanBrokerSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanBrokerSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanDelete.h b/include/xrpl/tx/transactors/lending/LoanDelete.h index 5c6ec46d33..6f9d3ed5f0 100644 --- a/include/xrpl/tx/transactors/lending/LoanDelete.h +++ b/include/xrpl/tx/transactors/lending/LoanDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanManage.h b/include/xrpl/tx/transactors/lending/LoanManage.h index 98b7e38ba6..c01d25e428 100644 --- a/include/xrpl/tx/transactors/lending/LoanManage.h +++ b/include/xrpl/tx/transactors/lending/LoanManage.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanManage : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanManage(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanPay.h b/include/xrpl/tx/transactors/lending/LoanPay.h index 83271cf4e7..6c2aa0ec47 100644 --- a/include/xrpl/tx/transactors/lending/LoanPay.h +++ b/include/xrpl/tx/transactors/lending/LoanPay.h @@ -7,7 +7,7 @@ namespace xrpl { class LoanPay : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanPay(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/lending/LoanSet.h b/include/xrpl/tx/transactors/lending/LoanSet.h index 3ede5adc4c..e926c927fb 100644 --- a/include/xrpl/tx/transactors/lending/LoanSet.h +++ b/include/xrpl/tx/transactors/lending/LoanSet.h @@ -8,7 +8,7 @@ namespace xrpl { class LoanSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LoanSet(ApplyContext& ctx) : Transactor(ctx) { @@ -53,16 +53,16 @@ public: beast::Journal const& j) override; public: - static std::uint32_t constexpr minPaymentTotal = 1; - static std::uint32_t constexpr defaultPaymentTotal = 1; - static_assert(defaultPaymentTotal >= minPaymentTotal); + static std::uint32_t constexpr kMIN_PAYMENT_TOTAL = 1; + static std::uint32_t constexpr kDEFAULT_PAYMENT_TOTAL = 1; + static_assert(kDEFAULT_PAYMENT_TOTAL >= kMIN_PAYMENT_TOTAL); - static std::uint32_t constexpr minPaymentInterval = 60; - static std::uint32_t constexpr defaultPaymentInterval = 60; - static_assert(defaultPaymentInterval >= minPaymentInterval); + static std::uint32_t constexpr kMIN_PAYMENT_INTERVAL = 60; + static std::uint32_t constexpr kDEFAULT_PAYMENT_INTERVAL = 60; + static_assert(kDEFAULT_PAYMENT_INTERVAL >= kMIN_PAYMENT_INTERVAL); - static std::uint32_t constexpr defaultGracePeriod = 60; - static_assert(defaultGracePeriod >= minPaymentInterval); + static std::uint32_t constexpr kDEFAULT_GRACE_PERIOD = 60; + static_assert(kDEFAULT_GRACE_PERIOD >= kMIN_PAYMENT_INTERVAL); }; //------------------------------------------------------------------------------ diff --git a/include/xrpl/tx/transactors/nft/NFTokenAcceptOffer.h b/include/xrpl/tx/transactors/nft/NFTokenAcceptOffer.h index 7291db9a2e..7c77b02277 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenAcceptOffer.h +++ b/include/xrpl/tx/transactors/nft/NFTokenAcceptOffer.h @@ -20,7 +20,7 @@ private: transferNFToken(AccountID const& buyer, AccountID const& seller, uint256 const& nfTokenID); public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenAcceptOffer(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/nft/NFTokenBurn.h b/include/xrpl/tx/transactors/nft/NFTokenBurn.h index 2830b7c22a..075bcc59ce 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenBurn.h +++ b/include/xrpl/tx/transactors/nft/NFTokenBurn.h @@ -7,7 +7,7 @@ namespace xrpl { class NFTokenBurn : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenBurn(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/nft/NFTokenCancelOffer.h b/include/xrpl/tx/transactors/nft/NFTokenCancelOffer.h index 540258b8d6..f78c29dfe5 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenCancelOffer.h +++ b/include/xrpl/tx/transactors/nft/NFTokenCancelOffer.h @@ -7,7 +7,7 @@ namespace xrpl { class NFTokenCancelOffer : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenCancelOffer(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/nft/NFTokenCreateOffer.h b/include/xrpl/tx/transactors/nft/NFTokenCreateOffer.h index 532aa5c120..bdb76e1c44 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenCreateOffer.h +++ b/include/xrpl/tx/transactors/nft/NFTokenCreateOffer.h @@ -7,7 +7,7 @@ namespace xrpl { class NFTokenCreateOffer : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenCreateOffer(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/nft/NFTokenMint.h b/include/xrpl/tx/transactors/nft/NFTokenMint.h index 6dcf8eaf12..5274e1b4b8 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenMint.h +++ b/include/xrpl/tx/transactors/nft/NFTokenMint.h @@ -9,7 +9,7 @@ namespace xrpl { class NFTokenMint : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenMint(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/nft/NFTokenModify.h b/include/xrpl/tx/transactors/nft/NFTokenModify.h index a1076a96a9..6d3bac49f5 100644 --- a/include/xrpl/tx/transactors/nft/NFTokenModify.h +++ b/include/xrpl/tx/transactors/nft/NFTokenModify.h @@ -7,7 +7,7 @@ namespace xrpl { class NFTokenModify : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit NFTokenModify(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/oracle/OracleDelete.h b/include/xrpl/tx/transactors/oracle/OracleDelete.h index 5de69e980f..85ca9a2a88 100644 --- a/include/xrpl/tx/transactors/oracle/OracleDelete.h +++ b/include/xrpl/tx/transactors/oracle/OracleDelete.h @@ -16,7 +16,7 @@ namespace xrpl { class OracleDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit OracleDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/oracle/OracleSet.h b/include/xrpl/tx/transactors/oracle/OracleSet.h index 426f46c2b4..7bedf9c837 100644 --- a/include/xrpl/tx/transactors/oracle/OracleSet.h +++ b/include/xrpl/tx/transactors/oracle/OracleSet.h @@ -16,7 +16,7 @@ namespace xrpl { class OracleSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit OracleSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/payment/DepositPreauth.h b/include/xrpl/tx/transactors/payment/DepositPreauth.h index f74be24c56..365ba157a5 100644 --- a/include/xrpl/tx/transactors/payment/DepositPreauth.h +++ b/include/xrpl/tx/transactors/payment/DepositPreauth.h @@ -7,7 +7,7 @@ namespace xrpl { class DepositPreauth : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit DepositPreauth(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/payment/Payment.h b/include/xrpl/tx/transactors/payment/Payment.h index 3baf1fa55f..4ad870ce3f 100644 --- a/include/xrpl/tx/transactors/payment/Payment.h +++ b/include/xrpl/tx/transactors/payment/Payment.h @@ -7,13 +7,13 @@ namespace xrpl { class Payment : public Transactor { /* The largest number of paths we allow */ - static std::size_t const MaxPathSize = 6; + static std::size_t const kMAX_PATH_SIZE = 6; /* The longest path we allow */ - static std::size_t const MaxPathLength = 8; + static std::size_t const kMAX_PATH_LENGTH = 8; public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; explicit Payment(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/payment_channel/PaymentChannelClaim.h b/include/xrpl/tx/transactors/payment_channel/PaymentChannelClaim.h index 6e9a269b8d..d5e8235d31 100644 --- a/include/xrpl/tx/transactors/payment_channel/PaymentChannelClaim.h +++ b/include/xrpl/tx/transactors/payment_channel/PaymentChannelClaim.h @@ -7,7 +7,7 @@ namespace xrpl { class PaymentChannelClaim : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit PaymentChannelClaim(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/payment_channel/PaymentChannelCreate.h b/include/xrpl/tx/transactors/payment_channel/PaymentChannelCreate.h index cd0250713a..94a43ea165 100644 --- a/include/xrpl/tx/transactors/payment_channel/PaymentChannelCreate.h +++ b/include/xrpl/tx/transactors/payment_channel/PaymentChannelCreate.h @@ -7,7 +7,7 @@ namespace xrpl { class PaymentChannelCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; explicit PaymentChannelCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/payment_channel/PaymentChannelFund.h b/include/xrpl/tx/transactors/payment_channel/PaymentChannelFund.h index befe9ac951..3f16cf1ec1 100644 --- a/include/xrpl/tx/transactors/payment_channel/PaymentChannelFund.h +++ b/include/xrpl/tx/transactors/payment_channel/PaymentChannelFund.h @@ -7,7 +7,7 @@ namespace xrpl { class PaymentChannelFund : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; explicit PaymentChannelFund(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.h b/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.h index 93879c55b2..4aaff83a7a 100644 --- a/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.h +++ b/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class PermissionedDomainDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit PermissionedDomainDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.h b/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.h index 3187be08e1..820b36688c 100644 --- a/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.h +++ b/include/xrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.h @@ -7,7 +7,7 @@ namespace xrpl { class PermissionedDomainSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit PermissionedDomainSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/system/Batch.h b/include/xrpl/tx/transactors/system/Batch.h index 1d9a66ec9a..b1af9a2f86 100644 --- a/include/xrpl/tx/transactors/system/Batch.h +++ b/include/xrpl/tx/transactors/system/Batch.h @@ -9,7 +9,7 @@ namespace xrpl { class Batch : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit Batch(ApplyContext& ctx) : Transactor(ctx) { @@ -47,7 +47,7 @@ public: ReadView const& view, beast::Journal const& j) override; - static constexpr auto disabledTxTypes = std::to_array({ + static constexpr auto kDISABLED_TX_TYPES = std::to_array({ ttVAULT_CREATE, ttVAULT_SET, ttVAULT_DELETE, diff --git a/include/xrpl/tx/transactors/system/Change.h b/include/xrpl/tx/transactors/system/Change.h index b966ef73ec..fc68fd55c2 100644 --- a/include/xrpl/tx/transactors/system/Change.h +++ b/include/xrpl/tx/transactors/system/Change.h @@ -7,7 +7,7 @@ namespace xrpl { class Change : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit Change(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/system/LedgerStateFix.h b/include/xrpl/tx/transactors/system/LedgerStateFix.h index da3cb33398..72ad8196c1 100644 --- a/include/xrpl/tx/transactors/system/LedgerStateFix.h +++ b/include/xrpl/tx/transactors/system/LedgerStateFix.h @@ -8,10 +8,10 @@ class LedgerStateFix : public Transactor { public: enum class FixType : std::uint16_t { - nfTokenPageLink = 1, + NfTokenPageLink = 1, }; - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit LedgerStateFix(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/system/TicketCreate.h b/include/xrpl/tx/transactors/system/TicketCreate.h index 13b6e7eca5..fc1743236f 100644 --- a/include/xrpl/tx/transactors/system/TicketCreate.h +++ b/include/xrpl/tx/transactors/system/TicketCreate.h @@ -7,9 +7,9 @@ namespace xrpl { class TicketCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Custom}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Custom}; - constexpr static std::uint32_t minValidCount = 1; + constexpr static std::uint32_t kMIN_VALID_COUNT = 1; // A note on how the maxValidCount was determined. The goal is for // a single TicketCreate transaction to not use more compute power than @@ -31,7 +31,7 @@ public: // about the same compute time as a single compute-intensive payment. // // October 2018. - constexpr static std::uint32_t maxValidCount = 250; + constexpr static std::uint32_t kMAX_VALID_COUNT = 250; // The maximum number of Tickets an account may hold. If a // TicketCreate would cause an account to own more than this many @@ -39,7 +39,7 @@ public: // // The number was chosen arbitrarily and is an effort toward avoiding // ledger-stuffing with Tickets. - constexpr static std::uint32_t maxTicketThreshold = 250; + constexpr static std::uint32_t kMAX_TICKET_THRESHOLD = 250; explicit TicketCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/Clawback.h b/include/xrpl/tx/transactors/token/Clawback.h index f7b77b872c..e21f98bd7a 100644 --- a/include/xrpl/tx/transactors/token/Clawback.h +++ b/include/xrpl/tx/transactors/token/Clawback.h @@ -7,7 +7,7 @@ namespace xrpl { class Clawback : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit Clawback(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/MPTokenAuthorize.h b/include/xrpl/tx/transactors/token/MPTokenAuthorize.h index 0cbc683e91..29cdda275a 100644 --- a/include/xrpl/tx/transactors/token/MPTokenAuthorize.h +++ b/include/xrpl/tx/transactors/token/MPTokenAuthorize.h @@ -16,7 +16,7 @@ struct MPTAuthorizeArgs class MPTokenAuthorize : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit MPTokenAuthorize(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h b/include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h index 6718d28e4d..0107c11598 100644 --- a/include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h +++ b/include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h @@ -27,7 +27,7 @@ struct MPTCreateArgs class MPTokenIssuanceCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit MPTokenIssuanceCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/MPTokenIssuanceDestroy.h b/include/xrpl/tx/transactors/token/MPTokenIssuanceDestroy.h index aaac508cf5..8e2a4c3dcd 100644 --- a/include/xrpl/tx/transactors/token/MPTokenIssuanceDestroy.h +++ b/include/xrpl/tx/transactors/token/MPTokenIssuanceDestroy.h @@ -7,7 +7,7 @@ namespace xrpl { class MPTokenIssuanceDestroy : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit MPTokenIssuanceDestroy(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/MPTokenIssuanceSet.h b/include/xrpl/tx/transactors/token/MPTokenIssuanceSet.h index 8dc423376a..e15027ab5e 100644 --- a/include/xrpl/tx/transactors/token/MPTokenIssuanceSet.h +++ b/include/xrpl/tx/transactors/token/MPTokenIssuanceSet.h @@ -7,7 +7,7 @@ namespace xrpl { class MPTokenIssuanceSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit MPTokenIssuanceSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/token/TrustSet.h b/include/xrpl/tx/transactors/token/TrustSet.h index cf4f042515..e99d599fe4 100644 --- a/include/xrpl/tx/transactors/token/TrustSet.h +++ b/include/xrpl/tx/transactors/token/TrustSet.h @@ -8,7 +8,7 @@ namespace xrpl { class TrustSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit TrustSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultClawback.h b/include/xrpl/tx/transactors/vault/VaultClawback.h index 9c69c88f75..4f0328aa4f 100644 --- a/include/xrpl/tx/transactors/vault/VaultClawback.h +++ b/include/xrpl/tx/transactors/vault/VaultClawback.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultClawback : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultClawback(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultCreate.h b/include/xrpl/tx/transactors/vault/VaultCreate.h index 6861c9d164..61b3e552cc 100644 --- a/include/xrpl/tx/transactors/vault/VaultCreate.h +++ b/include/xrpl/tx/transactors/vault/VaultCreate.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultCreate : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultCreate(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultDelete.h b/include/xrpl/tx/transactors/vault/VaultDelete.h index 33a86dd050..9a75fcebac 100644 --- a/include/xrpl/tx/transactors/vault/VaultDelete.h +++ b/include/xrpl/tx/transactors/vault/VaultDelete.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultDelete : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultDelete(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultDeposit.h b/include/xrpl/tx/transactors/vault/VaultDeposit.h index 5a0c63a3b1..21dc1749e2 100644 --- a/include/xrpl/tx/transactors/vault/VaultDeposit.h +++ b/include/xrpl/tx/transactors/vault/VaultDeposit.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultDeposit : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultDeposit(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultSet.h b/include/xrpl/tx/transactors/vault/VaultSet.h index 6abbe80fec..59a9639126 100644 --- a/include/xrpl/tx/transactors/vault/VaultSet.h +++ b/include/xrpl/tx/transactors/vault/VaultSet.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultSet : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultSet(ApplyContext& ctx) : Transactor(ctx) { diff --git a/include/xrpl/tx/transactors/vault/VaultWithdraw.h b/include/xrpl/tx/transactors/vault/VaultWithdraw.h index b8604d039e..f9b7665fd6 100644 --- a/include/xrpl/tx/transactors/vault/VaultWithdraw.h +++ b/include/xrpl/tx/transactors/vault/VaultWithdraw.h @@ -7,7 +7,7 @@ namespace xrpl { class VaultWithdraw : public Transactor { public: - static constexpr ConsequencesFactoryType ConsequencesFactory{Normal}; + static constexpr ConsequencesFactoryType kCONSEQUENCES_FACTORY{Normal}; explicit VaultWithdraw(ApplyContext& ctx) : Transactor(ctx) { diff --git a/src/libxrpl/protocol/AMMCore.cpp b/src/libxrpl/protocol/AMMCore.cpp index a30d9d2a52..c83251ff9b 100644 --- a/src/libxrpl/protocol/AMMCore.cpp +++ b/src/libxrpl/protocol/AMMCore.cpp @@ -29,7 +29,7 @@ Currency ammLPTCurrency(Asset const& asset1, Asset const& asset2) { // AMM LPToken is 0x03 plus 19 bytes of the hash - std::int32_t constexpr AMMCurrencyCode = 0x03; + std::int32_t constexpr kAMM_CURRENCY_CODE = 0x03; auto const& [minA, maxA] = std::minmax(asset1, asset2); uint256 const hash = std::visit( [](auto&& issue1, auto&& issue2) { @@ -44,7 +44,7 @@ ammLPTCurrency(Asset const& asset1, Asset const& asset2) minA.value(), maxA.value()); Currency currency; - *currency.begin() = AMMCurrencyCode; + *currency.begin() = kAMM_CURRENCY_CODE; std::copy(hash.begin(), hash.begin() + currency.size() - 1, currency.begin() + 1); return currency; } @@ -60,22 +60,22 @@ invalidAMMAsset(Asset const& asset, std::optional> const { auto const err = asset.visit( [](MPTIssue const& issue) -> std::optional { - if (issue.getIssuer() == beast::zero) - return temBAD_MPT; + if (issue.getIssuer() == beast::kZERO) + return TemBadMpt; return std::nullopt; }, [](Issue const& issue) -> std::optional { if (badCurrency() == issue.currency) - return temBAD_CURRENCY; + return TemBadCurrency; if (isXRP(issue) && issue.getIssuer().isNonZero()) - return temBAD_ISSUER; + return TemBadIssuer; return std::nullopt; }); if (err) return *err; if (pair && asset != pair->first && asset != pair->second) - return temBAD_AMM_TOKENS; - return tesSUCCESS; + return TemBadAmmTokens; + return TesSuccess; } NotTEC @@ -85,12 +85,12 @@ invalidAMMAssetPair( std::optional> const& pair) { if (asset1 == asset2) - return temBAD_AMM_TOKENS; + return TemBadAmmTokens; if (auto const res = invalidAMMAsset(asset1, pair)) return res; if (auto const res = invalidAMMAsset(asset2, pair)) return res; - return tesSUCCESS; + return TesSuccess; } NotTEC @@ -101,9 +101,9 @@ invalidAMMAmount( { if (auto const res = invalidAMMAsset(amount.asset(), pair)) return res; - if (amount < beast::zero || (!validZero && amount == beast::zero)) - return temBAD_AMOUNT; - return tesSUCCESS; + if (amount < beast::kZERO || (!validZero && amount == beast::kZERO)) + return TemBadAmount; + return TesSuccess; } std::optional @@ -113,13 +113,13 @@ ammAuctionTimeSlot(std::uint64_t current, STObject const& auctionSlot) // but check just to be safe auto const expiration = auctionSlot[sfExpiration]; XRPL_ASSERT( - expiration >= TOTAL_TIME_SLOT_SECS, "xrpl::ammAuctionTimeSlot : minimum expiration"); - if (expiration >= TOTAL_TIME_SLOT_SECS) + expiration >= kTOTAL_TIME_SLOT_SECS, "xrpl::ammAuctionTimeSlot : minimum expiration"); + if (expiration >= kTOTAL_TIME_SLOT_SECS) { - if (auto const start = expiration - TOTAL_TIME_SLOT_SECS; current >= start) + if (auto const start = expiration - kTOTAL_TIME_SLOT_SECS; current >= start) { - if (auto const diff = current - start; diff < TOTAL_TIME_SLOT_SECS) - return diff / AUCTION_SLOT_INTERVAL_DURATION; + if (auto const diff = current - start; diff < kTOTAL_TIME_SLOT_SECS) + return diff / kAUCTION_SLOT_INTERVAL_DURATION; } } return std::nullopt; diff --git a/src/libxrpl/protocol/IOUAmount.cpp b/src/libxrpl/protocol/IOUAmount.cpp index 1b3d92c1e9..263fe90009 100644 --- a/src/libxrpl/protocol/IOUAmount.cpp +++ b/src/libxrpl/protocol/IOUAmount.cpp @@ -19,11 +19,11 @@ namespace xrpl { /* The range for the mantissa when normalized */ // log(2^63,10) ~ 18.96 // -static std::int64_t constexpr minMantissa = STAmount::cMinValue; -static std::int64_t constexpr maxMantissa = STAmount::cMaxValue; +static std::int64_t constexpr kMIN_MANTISSA = STAmount::kC_MIN_VALUE; +static std::int64_t constexpr kMAX_MANTISSA = STAmount::kC_MAX_VALUE; /* The range for the exponent when normalized */ -static int constexpr minExponent = STAmount::cMinOffset; -static int constexpr maxExponent = STAmount::cMaxOffset; +static int constexpr kMIN_EXPONENT = STAmount::kC_MIN_OFFSET; +static int constexpr kMAX_EXPONENT = STAmount::kC_MAX_OFFSET; IOUAmount IOUAmount::fromNumber(Number const& number) @@ -32,14 +32,14 @@ IOUAmount::fromNumber(Number const& number) // to normalize, which calls fromNumber IOUAmount result{}; std::tie(result.mantissa_, result.exponent_) = - number.normalizeToRange(minMantissa, maxMantissa); + number.normalizeToRange(kMIN_MANTISSA, kMAX_MANTISSA); return result; } IOUAmount IOUAmount::minPositiveAmount() { - return IOUAmount(minMantissa, minExponent); + return IOUAmount(kMIN_MANTISSA, kMIN_EXPONENT); } void @@ -47,41 +47,41 @@ IOUAmount::normalize() { if (mantissa_ == 0) { - *this = beast::zero; + *this = beast::kZERO; return; } Number const v{mantissa_, exponent_}; *this = fromNumber(v); - if (exponent_ > maxExponent) + if (exponent_ > kMAX_EXPONENT) { Throw("value overflow"); } - if (exponent_ < minExponent) + if (exponent_ < kMIN_EXPONENT) { - *this = beast::zero; + *this = beast::kZERO; } } IOUAmount::IOUAmount(Number const& other) : IOUAmount(fromNumber(other)) { - if (exponent_ > maxExponent) + if (exponent_ > kMAX_EXPONENT) { Throw("value overflow"); } - if (exponent_ < minExponent) + if (exponent_ < kMIN_EXPONENT) { - *this = beast::zero; + *this = beast::kZERO; } } IOUAmount& IOUAmount::operator+=(IOUAmount const& other) { - if (other == beast::zero) + if (other == beast::kZERO) return *this; - if (*this == beast::zero) + if (*this == beast::kZERO) { *this = other; return *this; @@ -108,7 +108,7 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU // A vector with the value 10^index for indexes from 0 to 29 // The largest intermediate value we expect is 2^96, which // is less than 10^29 - static auto const powerTable = [] { + static auto const kPOWER_TABLE = [] { std::vector result; result.reserve(30); // 2^96 is largest intermediate result size uint128_t cur(1); @@ -122,11 +122,11 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU // Return floor(log10(v)) // Note: Returns -1 for v == 0 - static auto log10Floor = [](uint128_t const& v) { + static auto kLOG10_FLOOR = [](uint128_t const& v) { // Find the index of the first element >= the requested element, the // index is the log of the element in the log table. - auto const l = std::ranges::lower_bound(powerTable, v); - int index = std::distance(powerTable.begin(), l); + auto const l = std::ranges::lower_bound(kPOWER_TABLE, v); + int index = std::distance(kPOWER_TABLE.begin(), l); // If we're not equal, subtract to get the floor if (*l != v) --index; @@ -134,14 +134,14 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU }; // Return ceil(log10(v)) - static auto log10Ceil = [](uint128_t const& v) { + static auto kLOG10_CEIL = [](uint128_t const& v) { // Find the index of the first element >= the requested element, the // index is the log of the element in the log table. - auto const l = std::ranges::lower_bound(powerTable, v); - return int(std::distance(powerTable.begin(), l)); + auto const l = std::ranges::lower_bound(kPOWER_TABLE, v); + return int(std::distance(kPOWER_TABLE.begin(), l)); }; - static auto const fl64 = log10Floor(std::numeric_limits::max()); + static auto const kFL64 = kLOG10_FLOOR(std::numeric_limits::max()); bool const neg = amt.mantissa() < 0; uint128_t const den128(den); @@ -162,12 +162,12 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU // and (rem/den128) is as large as possible. Scale by multiplying low // and rem by 10 and subtracting one from the exponent. We could do this // with a loop, but it's more efficient to use logarithms. - auto const roomToGrow = fl64 - log10Ceil(low); + auto const roomToGrow = kFL64 - kLOG10_CEIL(low); if (roomToGrow > 0) { exponent -= roomToGrow; - low *= powerTable[roomToGrow]; - rem *= powerTable[roomToGrow]; + low *= kPOWER_TABLE[roomToGrow]; + rem *= kPOWER_TABLE[roomToGrow]; } auto const addRem = rem / den128; low += addRem; @@ -179,14 +179,14 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU // and adding one to the exponent until the low will fit in the 64-bit // mantissa. Use logarithms to avoid looping. bool hasRem = bool(rem); - auto const mustShrink = log10Ceil(low) - fl64; + auto const mustShrink = kLOG10_CEIL(low) - kFL64; if (mustShrink > 0) { uint128_t const sav(low); exponent += mustShrink; - low /= powerTable[mustShrink]; + low /= kPOWER_TABLE[mustShrink]; if (!hasRem) - hasRem = bool(sav - low * powerTable[mustShrink]); + hasRem = bool(sav - low * kPOWER_TABLE[mustShrink]); } std::int64_t mantissa = low.convert_to(); @@ -215,7 +215,7 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU { if (!result) { - return IOUAmount(-minMantissa, minExponent); + return IOUAmount(-kMIN_MANTISSA, kMIN_EXPONENT); } // This subtraction cannot underflow because `result` is not zero return IOUAmount(result.mantissa() - 1, result.exponent()); diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index 4d7747db93..8d1e5c69d6 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -47,9 +47,9 @@ namespace xrpl { -static std::uint64_t const tenTo14 = 100000000000000ull; -static std::uint64_t const tenTo14m1 = tenTo14 - 1; -static std::uint64_t const tenTo17 = tenTo14 * 1000; +static std::uint64_t const kTEN_TO14 = 100000000000000ull; +static std::uint64_t const kTEN_TO14M1 = kTEN_TO14 - 1; +static std::uint64_t const kTEN_TO17 = kTEN_TO14 * 1000; //------------------------------------------------------------------------------ static std::int64_t @@ -105,32 +105,32 @@ areComparable(STAmount const& v1, STAmount const& v2) v2.asset().value()); } -static_assert(INITIAL_XRP.drops() == STAmount::cMaxNativeN); +static_assert(kINITIAL_XRP.drops() == STAmount::kC_MAX_NATIVE_N); STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) { std::uint64_t value = sit.get64(); // native or MPT - if ((value & cIssuedCurrency) == 0) + if ((value & kC_ISSUED_CURRENCY) == 0) { - if ((value & cMPToken) != 0) + if ((value & kC_MP_TOKEN) != 0) { // is MPT - mOffset = 0; - mIsNegative = (value & cPositive) == 0; - mValue = (value << 8) | sit.get8(); - mAsset = sit.get192(); + mOffset_ = 0; + mIsNegative_ = (value & kC_POSITIVE) == 0; + mValue_ = (value << 8) | sit.get8(); + mAsset_ = sit.get192(); return; } // else is XRP - mAsset = xrpIssue(); + mAsset_ = xrpIssue(); // positive - if ((value & cPositive) != 0) + if ((value & kC_POSITIVE) != 0) { - mValue = value & cValueMask; - mOffset = 0; - mIsNegative = false; + mValue_ = value & kC_VALUE_MASK; + mOffset_ = 0; + mIsNegative_ = false; return; } @@ -138,9 +138,9 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) if (value == 0) Throw("negative zero is not canonical"); - mValue = value & cValueMask; - mOffset = 0; - mIsNegative = true; + mValue_ = value & kC_VALUE_MASK; + mOffset_ = 0; + mIsNegative_ = true; return; } @@ -165,15 +165,16 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) bool const isNegative = (offset & 256) == 0; offset = (offset & 255) - 97; // center the range - if (value < cMinValue || value > cMaxValue || offset < cMinOffset || offset > cMaxOffset) + if (value < kC_MIN_VALUE || value > kC_MAX_VALUE || offset < kC_MIN_OFFSET || + offset > kC_MAX_OFFSET) { Throw("invalid currency value"); } - mAsset = issue; - mValue = value; - mOffset = offset; - mIsNegative = isNegative; + mAsset_ = issue; + mValue_ = value; + mOffset_ = offset; + mIsNegative_ = isNegative; canonicalize(); return; } @@ -181,37 +182,37 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) if (offset != 512) Throw("invalid currency value"); - mAsset = issue; - mValue = 0; - mOffset = 0; - mIsNegative = false; + mAsset_ = issue; + mValue_ = 0; + mOffset_ = 0; + mIsNegative_ = false; canonicalize(); } STAmount::STAmount(SField const& name, std::int64_t mantissa) - : STBase(name), mAsset(xrpIssue()), mOffset(0) + : STBase(name), mAsset_(xrpIssue()), mOffset_(0) { set(mantissa); } STAmount::STAmount(SField const& name, std::uint64_t mantissa, bool negative) - : STBase(name), mAsset(xrpIssue()), mValue(mantissa), mOffset(0), mIsNegative(negative) + : STBase(name), mAsset_(xrpIssue()), mValue_(mantissa), mOffset_(0), mIsNegative_(negative) { XRPL_ASSERT( - mValue <= std::numeric_limits::max(), + mValue_ <= std::numeric_limits::max(), "xrpl::STAmount::STAmount(SField, std::uint64_t, bool) : maximum " "mantissa input"); } STAmount::STAmount(SField const& name, STAmount const& from) : STBase(name) - , mAsset(from.mAsset) - , mValue(from.mValue) - , mOffset(from.mOffset) - , mIsNegative(from.mIsNegative) + , mAsset_(from.mAsset_) + , mValue_(from.mValue_) + , mOffset_(from.mOffset_) + , mIsNegative_(from.mIsNegative_) { XRPL_ASSERT( - mValue <= std::numeric_limits::max(), + mValue_ <= std::numeric_limits::max(), "xrpl::STAmount::STAmount(SField, STAmount) : maximum input"); canonicalize(); } @@ -219,24 +220,24 @@ STAmount::STAmount(SField const& name, STAmount const& from) //------------------------------------------------------------------------------ STAmount::STAmount(std::uint64_t mantissa, bool negative) - : mAsset(xrpIssue()), mValue(mantissa), mOffset(0), mIsNegative(mantissa != 0 && negative) + : mAsset_(xrpIssue()), mValue_(mantissa), mOffset_(0), mIsNegative_(mantissa != 0 && negative) { XRPL_ASSERT( - mValue <= std::numeric_limits::max(), + mValue_ <= std::numeric_limits::max(), "xrpl::STAmount::STAmount(std::uint64_t, bool) : maximum mantissa " "input"); } STAmount::STAmount(XRPAmount const& amount) - : mAsset(xrpIssue()), mOffset(0), mIsNegative(amount < beast::zero) + : mAsset_(xrpIssue()), mOffset_(0), mIsNegative_(amount < beast::kZERO) { - if (mIsNegative) + if (mIsNegative_) { - mValue = unsafe_cast(-amount.drops()); + mValue_ = unsafeCast(-amount.drops()); } else { - mValue = unsafe_cast(amount.drops()); + mValue_ = unsafeCast(amount.drops()); } canonicalize(); @@ -271,10 +272,10 @@ STAmount::xrp() const if (!native()) Throw("Cannot return non-native STAmount as XRPAmount"); - auto drops = static_cast(mValue); - XRPL_ASSERT(mOffset == 0, "xrpl::STAmount::xrp : amount is canonical"); + auto drops = static_cast(mValue_); + XRPL_ASSERT(mOffset_ == 0, "xrpl::STAmount::xrp : amount is canonical"); - if (mIsNegative) + if (mIsNegative_) drops = -drops; return XRPAmount{drops}; @@ -286,10 +287,10 @@ STAmount::iou() const if (integral()) Throw("Cannot return non-IOU STAmount as IOUAmount"); - auto mantissa = static_cast(mValue); - auto exponent = mOffset; + auto mantissa = static_cast(mValue_); + auto exponent = mOffset_; - if (mIsNegative) + if (mIsNegative_) mantissa = -mantissa; return {mantissa, exponent}; @@ -301,10 +302,10 @@ STAmount::mpt() const if (!holds()) Throw("Cannot return STAmount as MPTAmount"); - auto value = static_cast(mValue); - XRPL_ASSERT(mOffset == 0, "xrpl::STAmount::mpt : amount is canonical"); + auto value = static_cast(mValue_); + XRPL_ASSERT(mOffset_ == 0, "xrpl::STAmount::mpt : amount is canonical"); - if (mIsNegative) + if (mIsNegative_) value = -value; return MPTAmount{value}; @@ -314,15 +315,15 @@ STAmount& STAmount::operator=(IOUAmount const& iou) { XRPL_ASSERT(integral() == false, "xrpl::STAmount::operator=(IOUAmount) : is not integral"); - mOffset = iou.exponent(); - mIsNegative = iou < beast::zero; - if (mIsNegative) + mOffset_ = iou.exponent(); + mIsNegative_ = iou < beast::kZERO; + if (mIsNegative_) { - mValue = static_cast(-iou.mantissa()); + mValue_ = static_cast(-iou.mantissa()); } else { - mValue = static_cast(iou.mantissa()); + mValue_ = static_cast(iou.mantissa()); } return *this; } @@ -333,14 +334,14 @@ STAmount::operator=(Number const& number) if (!getCurrentTransactionRules() || isFeatureEnabled(featureSingleAssetVault) || isFeatureEnabled(featureLendingProtocol)) { - *this = fromNumber(mAsset, number); + *this = fromNumber(mAsset_, number); } else { auto const originalMantissa = number.mantissa(); - mIsNegative = originalMantissa < 0; - mValue = mIsNegative ? -originalMantissa : originalMantissa; - mOffset = number.exponent(); + mIsNegative_ = originalMantissa < 0; + mValue_ = mIsNegative_ ? -originalMantissa : originalMantissa; + mOffset_ = number.exponent(); } canonicalize(); return *this; @@ -372,10 +373,10 @@ operator+(STAmount const& v1, STAmount const& v2) if (!areComparable(v1, v2)) Throw("Can't add amounts that are't comparable!"); - if (v2 == beast::zero) + if (v2 == beast::kZERO) return v1; - if (v1 == beast::zero) + if (v1 == beast::kZERO) { // Result must be in terms of v1 currency and issuer. return {v1.getFName(), v1.asset(), v2.mantissa(), v2.exponent(), v2.negative()}; @@ -384,7 +385,7 @@ operator+(STAmount const& v1, STAmount const& v2) if (v1.native()) return {v1.getFName(), getSNValue(v1) + getSNValue(v2)}; if (v1.holds()) - return {v1.mAsset, v1.mpt().value() + v2.mpt().value()}; + return {v1.mAsset_, v1.mpt().value() + v2.mpt().value()}; auto x = v1; x = v1.iou() + v2.iou(); @@ -399,12 +400,12 @@ operator-(STAmount const& v1, STAmount const& v2) //------------------------------------------------------------------------------ -std::uint64_t const STAmount::uRateOne = getRate(STAmount(1), STAmount(1)); +std::uint64_t const STAmount::kU_RATE_ONE = getRate(STAmount(1), STAmount(1)); void STAmount::setIssue(Asset const& asset) { - mAsset = asset; + mAsset_ = asset; } // Convert an offer into an index amount so they sort by rate. @@ -419,13 +420,13 @@ STAmount::setIssue(Asset const& asset) std::uint64_t getRate(STAmount const& offerOut, STAmount const& offerIn) { - if (offerOut == beast::zero) + if (offerOut == beast::kZERO) return 0; try { STAmount const r = divide(offerIn, offerOut, noIssue()); - if (r == beast::zero) // offer is too good + if (r == beast::kZERO) // offer is too good return 0; XRPL_ASSERT( (r.exponent() >= -100) && (r.exponent() <= 155), @@ -466,20 +467,20 @@ canAdd(STAmount const& a, STAmount const& b) return false; // special case: adding anything to zero is always fine - if (a == beast::zero || b == beast::zero) + if (a == beast::kZERO || b == beast::kZERO) return true; // XRP case (overflow & underflow check) if (isXRP(a) && isXRP(b)) { - XRPAmount const A = a.xrp(); - XRPAmount const B = b.xrp(); + XRPAmount const a = a.xrp(); + XRPAmount const b = b.xrp(); return !( - (B > XRPAmount{0} && - A > XRPAmount{std::numeric_limits::max()} - B) || - (B < XRPAmount{0} && - A < XRPAmount{std::numeric_limits::min()} - B)); + (b > XRPAmount{0} && + a > XRPAmount{std::numeric_limits::max()} - b) || + (b < XRPAmount{0} && + a < XRPAmount{std::numeric_limits::min()} - b)); } // IOU case (precision check) @@ -488,23 +489,23 @@ canAdd(STAmount const& a, STAmount const& b) TIss1 const&, TIss2 const&) -> std::optional { if constexpr (is_issue_v && is_issue_v) { - static STAmount const one{IOUAmount{1, 0}, noIssue()}; - static STAmount const maxLoss{IOUAmount{1, -4}, noIssue()}; - STAmount const lhs = divide((a - b) + b, a, noIssue()) - one; - STAmount const rhs = divide((b - a) + a, b, noIssue()) - one; - return ((rhs.negative() ? -rhs : rhs) + (lhs.negative() ? -lhs : lhs)) <= maxLoss; + static STAmount const kONE{IOUAmount{1, 0}, noIssue()}; + static STAmount const kMAX_LOSS{IOUAmount{1, -4}, noIssue()}; + STAmount const lhs = divide((a - b) + b, a, noIssue()) - kONE; + STAmount const rhs = divide((b - a) + a, b, noIssue()) - kONE; + return ((rhs.negative() ? -rhs : rhs) + (lhs.negative() ? -lhs : lhs)) <= kMAX_LOSS; } // MPT (overflow & underflow check) if constexpr (is_mptissue_v && is_mptissue_v) { - MPTAmount const A = a.mpt(); - MPTAmount const B = b.mpt(); + MPTAmount const a = a.mpt(); + MPTAmount const b = b.mpt(); return !( - (B > MPTAmount{0} && - A > MPTAmount{std::numeric_limits::max()} - B) || - (B < MPTAmount{0} && - A < MPTAmount{std::numeric_limits::min()} - B)); + (b > MPTAmount{0} && + a > MPTAmount{std::numeric_limits::max()} - b) || + (b < MPTAmount{0} && + a < MPTAmount{std::numeric_limits::min()} - b)); } return std::nullopt; }, @@ -543,21 +544,21 @@ canSubtract(STAmount const& a, STAmount const& b) return false; // Special case: subtracting zero is always fine - if (b == beast::zero) + if (b == beast::kZERO) return true; // XRP case (underflow & overflow check) if (isXRP(a) && isXRP(b)) { - XRPAmount const A = a.xrp(); - XRPAmount const B = b.xrp(); + XRPAmount const a = a.xrp(); + XRPAmount const b = b.xrp(); // Check for underflow - if (B > XRPAmount{0} && A < B) + if (b > XRPAmount{0} && a < b) return false; // Check for overflow - if (B < XRPAmount{0} && - A > XRPAmount{std::numeric_limits::max()} + B) + if (b < XRPAmount{0} && + a > XRPAmount{std::numeric_limits::max()} + b) return false; return true; @@ -575,16 +576,16 @@ canSubtract(STAmount const& a, STAmount const& b) // MPT case (underflow & overflow check) if constexpr (is_mptissue_v && is_mptissue_v) { - MPTAmount const A = a.mpt(); - MPTAmount const B = b.mpt(); + MPTAmount const a = a.mpt(); + MPTAmount const b = b.mpt(); // Underflow check - if (B > MPTAmount{0} && A < B) + if (b > MPTAmount{0} && a < b) return false; // Overflow check - if (B < MPTAmount{0} && - A > MPTAmount{std::numeric_limits::max()} + B) + if (b < MPTAmount{0} && + a > MPTAmount{std::numeric_limits::max()} + b) return false; return true; } @@ -603,14 +604,14 @@ canSubtract(STAmount const& a, STAmount const& b) void STAmount::setJson(Json::Value& elem) const { - elem = Json::objectValue; + elem = Json::ObjectValue; if (!native()) { // It is an error for currency or issuer not to be specified for valid // json. - elem[jss::value] = getText(); - mAsset.setJson(elem); + elem[jss::kVALUE] = getText(); + mAsset_.setJson(elem); } else { @@ -627,7 +628,7 @@ STAmount::setJson(Json::Value& elem) const SerializedTypeID STAmount::getSType() const { - return STI_AMOUNT; + return StiAmount; } std::string @@ -636,7 +637,7 @@ STAmount::getFullText() const std::string ret; ret.reserve(64); - ret = getText() + "/" + mAsset.getText(); + ret = getText() + "/" + mAsset_.getText(); return ret; } @@ -644,85 +645,85 @@ std::string STAmount::getText() const { // keep full internal accuracy, but make more human friendly if possible - if (*this == beast::zero) + if (*this == beast::kZERO) return "0"; - std::string const raw_value(std::to_string(mValue)); + std::string const rawValue(std::to_string(mValue_)); std::string ret; - if (mIsNegative) + if (mIsNegative_) ret.append(1, '-'); - bool const scientific((mOffset != 0) && ((mOffset < -25) || (mOffset > -5))); + bool const scientific((mOffset_ != 0) && ((mOffset_ < -25) || (mOffset_ > -5))); - if (native() || mAsset.holds() || scientific) + if (native() || mAsset_.holds() || scientific) { - ret.append(raw_value); + ret.append(rawValue); if (scientific) { ret.append(1, 'e'); - ret.append(std::to_string(mOffset)); + ret.append(std::to_string(mOffset_)); } return ret; } - XRPL_ASSERT(mOffset + 43 > 0, "xrpl::STAmount::getText : minimum offset"); + XRPL_ASSERT(mOffset_ + 43 > 0, "xrpl::STAmount::getText : minimum offset"); - size_t const pad_prefix = 27; - size_t const pad_suffix = 23; + size_t const padPrefix = 27; + size_t const padSuffix = 23; std::string val; - val.reserve(raw_value.length() + pad_prefix + pad_suffix); - val.append(pad_prefix, '0'); - val.append(raw_value); - val.append(pad_suffix, '0'); + val.reserve(rawValue.length() + padPrefix + padSuffix); + val.append(padPrefix, '0'); + val.append(rawValue); + val.append(padSuffix, '0'); - size_t const offset(mOffset + 43); + size_t const offset(mOffset_ + 43); - auto pre_from(val.begin()); - auto const pre_to(val.begin() + offset); + auto preFrom(val.begin()); + auto const preTo(val.begin() + offset); - auto const post_from(val.begin() + offset); - auto post_to(val.end()); + auto const postFrom(val.begin() + offset); + auto postTo(val.end()); // Crop leading zeroes. Take advantage of the fact that there's always a // fixed amount of leading zeroes and skip them. - if (std::distance(pre_from, pre_to) > pad_prefix) - pre_from += pad_prefix; + if (std::distance(preFrom, preTo) > padPrefix) + preFrom += padPrefix; - XRPL_ASSERT(post_to >= post_from, "xrpl::STAmount::getText : first distance check"); + XRPL_ASSERT(postTo >= postFrom, "xrpl::STAmount::getText : first distance check"); - pre_from = std::find_if(pre_from, pre_to, [](char c) { return c != '0'; }); + preFrom = std::find_if(preFrom, preTo, [](char c) { return c != '0'; }); // Crop trailing zeroes. Take advantage of the fact that there's always a // fixed amount of trailing zeroes and skip them. - if (std::distance(post_from, post_to) > pad_suffix) - post_to -= pad_suffix; + if (std::distance(postFrom, postTo) > padSuffix) + postTo -= padSuffix; - XRPL_ASSERT(post_to >= post_from, "xrpl::STAmount::getText : second distance check"); + XRPL_ASSERT(postTo >= postFrom, "xrpl::STAmount::getText : second distance check"); - post_to = std::find_if( - std::make_reverse_iterator(post_to), - std::make_reverse_iterator(post_from), - [](char c) { return c != '0'; }) - .base(); + postTo = std::find_if( + std::make_reverse_iterator(postTo), + std::make_reverse_iterator(postFrom), + [](char c) { return c != '0'; }) + .base(); // Assemble the output: - if (pre_from == pre_to) + if (preFrom == preTo) { ret.append(1, '0'); } else { - ret.append(pre_from, pre_to); + ret.append(preFrom, preTo); } - if (post_to != post_from) + if (postTo != postFrom) { ret.append(1, '.'); - ret.append(post_from, post_to); + ret.append(postFrom, postTo); } return ret; @@ -739,44 +740,45 @@ STAmount::getJson(JsonOptions) const void STAmount::add(Serializer& s) const { - mAsset.visit( + mAsset_.visit( [&](MPTIssue const& issue) { - auto u8 = static_cast(cMPToken >> 56); - if (!mIsNegative) - u8 |= static_cast(cPositive >> 56); + auto u8 = static_cast(kC_MP_TOKEN >> 56); + if (!mIsNegative_) + u8 |= static_cast(kC_POSITIVE >> 56); s.add8(u8); - s.add64(mValue); + s.add64(mValue_); s.addBitString(issue.getMptID()); }, [&](Issue const& issue) { if (native()) { - XRPL_ASSERT(mOffset == 0, "xrpl::STAmount::add : zero offset"); + XRPL_ASSERT(mOffset_ == 0, "xrpl::STAmount::add : zero offset"); - if (!mIsNegative) + if (!mIsNegative_) { - s.add64(mValue | cPositive); + s.add64(mValue_ | kC_POSITIVE); } else { - s.add64(mValue); + s.add64(mValue_); } } else { - if (*this == beast::zero) + if (*this == beast::kZERO) { - s.add64(cIssuedCurrency); + s.add64(kC_ISSUED_CURRENCY); } - else if (mIsNegative) // 512 = not native + else if (mIsNegative_) // 512 = not native { - s.add64(mValue | (static_cast(mOffset + 512 + 97) << (64 - 10))); + s.add64( + mValue_ | (static_cast(mOffset_ + 512 + 97) << (64 - 10))); } else // 256 = positive { s.add64( - mValue | - (static_cast(mOffset + 512 + 256 + 97) << (64 - 10))); + mValue_ | + (static_cast(mOffset_ + 512 + 256 + 97) << (64 - 10))); } s.addBitString(issue.currency); s.addBitString(issue.account); @@ -794,7 +796,7 @@ STAmount::isEquivalent(STBase const& t) const bool STAmount::isDefault() const { - return (mValue == 0) && native(); + return (mValue_ == 0) && native(); } //------------------------------------------------------------------------------ @@ -822,32 +824,32 @@ STAmount::canonicalize() { // native and MPT currency amounts should always have an offset of zero // log(2^64,10) ~ 19.2 - if (mValue == 0 || mOffset <= -20) + if (mValue_ == 0 || mOffset_ <= -20) { - mValue = 0; - mOffset = 0; - mIsNegative = false; + mValue_ = 0; + mOffset_ = 0; + mIsNegative_ = false; return; } // log(cMaxNativeN, 10) == 17 - if (native() && mOffset > 17) + if (native() && mOffset_ > 17) Throw("Native currency amount out of range"); // log(maxMPTokenAmount, 10) ~ 18.96 - if (mAsset.holds() && mOffset > 18) + if (mAsset_.holds() && mOffset_ > 18) Throw("MPT amount out of range"); - Number const num(mIsNegative, mValue, mOffset, Number::unchecked{}); + Number const num(mIsNegative_, mValue_, mOffset_, Number::Unchecked{}); auto set = [&](auto const& val) { auto const value = val.value(); - mIsNegative = value < 0; - mValue = mIsNegative ? -value : value; + mIsNegative_ = value < 0; + mValue_ = mIsNegative_ ? -value : value; }; if (native()) { set(XRPAmount{num}); } - else if (mAsset.holds()) + else if (mAsset_.holds()) { set(MPTAmount{num}); } @@ -855,13 +857,13 @@ STAmount::canonicalize() { Throw("Unknown integral asset type"); } - mOffset = 0; + mOffset_ = 0; - if (native() && mValue > cMaxNativeN) + if (native() && mValue_ > kC_MAX_NATIVE_N) { Throw("Native currency amount out of range"); } - else if (!native() && mValue > maxMPTokenAmount) + else if (!native() && mValue_ > kMAX_MP_TOKEN_AMOUNT) { Throw("MPT amount out of range"); } @@ -877,13 +879,13 @@ STAmount::set(std::int64_t v) { if (v < 0) { - mIsNegative = true; - mValue = static_cast(-v); + mIsNegative_ = true; + mValue_ = static_cast(-v); } else { - mIsNegative = false; - mValue = static_cast(v); + mIsNegative_ = false; + mValue_ = static_cast(v); } } @@ -929,23 +931,23 @@ amountFromJson(SField const& name, Json::Value const& v) if (!validJSONAsset(v)) Throw("Invalid Asset's Json specification"); - value = v[jss::value]; - if (v.isMember(jss::mpt_issuance_id)) + value = v[jss::kVALUE]; + if (v.isMember(jss::kMPT_ISSUANCE_ID)) { isMPT = true; - currencyOrMPTID = v[jss::mpt_issuance_id]; + currencyOrMPTID = v[jss::kMPT_ISSUANCE_ID]; } else { - currencyOrMPTID = v[jss::currency]; - issuer = v[jss::issuer]; + currencyOrMPTID = v[jss::kCURRENCY]; + issuer = v[jss::kISSUER]; } } else if (v.isArray()) { value = v.get(Json::UInt(0), 0); - currencyOrMPTID = v.get(Json::UInt(1), Json::nullValue); - issuer = v.get(Json::UInt(2), Json::nullValue); + currencyOrMPTID = v.get(Json::UInt(1), Json::NullValue); + issuer = v.get(Json::UInt(2), Json::NullValue); } else if (v.isString()) { @@ -1039,7 +1041,7 @@ amountFromJsonNoThrow(STAmount& result, Json::Value const& jvSource) { try { - result = amountFromJson(sfGeneric, jvSource); + result = amountFromJson(kSF_GENERIC, jvSource); return true; } catch (std::exception const& e) @@ -1107,7 +1109,7 @@ operator-(STAmount const& value) value.mantissa(), value.exponent(), !value.negative(), - STAmount::unchecked{}); + STAmount::Unchecked{}); } //------------------------------------------------------------------------------ @@ -1137,7 +1139,7 @@ muldiv(std::uint64_t multiplier, std::uint64_t multiplicand, std::uint64_t divis } static std::uint64_t -muldiv_round( +muldivRound( std::uint64_t multiplier, std::uint64_t multiplicand, std::uint64_t divisor, @@ -1162,10 +1164,10 @@ muldiv_round( STAmount divide(STAmount const& num, STAmount const& den, Asset const& asset) { - if (den == beast::zero) + if (den == beast::kZERO) Throw("division by zero"); - if (num == beast::zero) + if (num == beast::kZERO) return {asset}; std::uint64_t numVal = num.mantissa(); @@ -1175,7 +1177,7 @@ divide(STAmount const& num, STAmount const& den, Asset const& asset) if (num.integral()) { - while (numVal < STAmount::cMinValue) + while (numVal < STAmount::kC_MIN_VALUE) { // Need to bring into range numVal *= 10; @@ -1185,7 +1187,7 @@ divide(STAmount const& num, STAmount const& den, Asset const& asset) if (den.integral()) { - while (denVal < STAmount::cMinValue) + while (denVal < STAmount::kC_MIN_VALUE) { denVal *= 10; --denOffset; @@ -1199,7 +1201,7 @@ divide(STAmount const& num, STAmount const& den, Asset const& asset) // is in the range of 10^16 to 10^15. return STAmount( asset, - muldiv(numVal, tenTo17, denVal) + 5, + muldiv(numVal, kTEN_TO17, denVal) + 5, numOffset - denOffset - 17, num.negative() != den.negative()); } @@ -1207,7 +1209,7 @@ divide(STAmount const& num, STAmount const& den, Asset const& asset) STAmount multiply(STAmount const& v1, STAmount const& v2, Asset const& asset) { - if (v1 == beast::zero || v2 == beast::zero) + if (v1 == beast::kZERO || v2 == beast::kZERO) return STAmount(asset); if (v1.native() && v2.native() && asset.native()) @@ -1282,9 +1284,9 @@ canonicalizeRound(bool integral, std::uint64_t& value, int& offset, bool) ++offset; } } - else if (value > STAmount::cMaxValue) + else if (value > STAmount::kC_MAX_VALUE) { - while (value > (10 * STAmount::cMaxValue)) + while (value > (10 * STAmount::kC_MAX_VALUE)) { value /= 10; ++offset; @@ -1324,9 +1326,9 @@ canonicalizeRoundStrict(bool integral, std::uint64_t& value, int& offset, bool r ++offset; } } - else if (value > STAmount::cMaxValue) + else if (value > STAmount::kC_MAX_VALUE) { - while (value > (10 * STAmount::cMaxValue)) + while (value > (10 * STAmount::kC_MAX_VALUE)) { value /= 10; ++offset; @@ -1338,14 +1340,14 @@ canonicalizeRoundStrict(bool integral, std::uint64_t& value, int& offset, bool r } STAmount -roundToScale(STAmount const& value, std::int32_t scale, Number::rounding_mode rounding) +roundToScale(STAmount const& value, std::int32_t scale, Number::RoundingMode rounding) { // Nothing to do for integral types. if (value.integral()) return value; // Nothing to do for zero. - if (value == beast::zero) + if (value == beast::kZERO) return value; // If the value's exponent is greater than or equal to the scale, then @@ -1354,7 +1356,7 @@ roundToScale(STAmount const& value, std::int32_t scale, Number::rounding_mode ro if (value.exponent() >= scale) return value; - STAmount const referenceValue{value.asset(), STAmount::cMinValue, scale, value.negative()}; + STAmount const referenceValue{value.asset(), STAmount::kC_MIN_VALUE, scale, value.negative()}; NumberRoundModeGuard const mg(rounding); // With an IOU, the the result of addition will be truncated to the @@ -1371,7 +1373,7 @@ namespace { class DontAffectNumberRoundMode { public: - explicit DontAffectNumberRoundMode(Number::rounding_mode mode) noexcept + explicit DontAffectNumberRoundMode(Number::RoundingMode mode) noexcept { } @@ -1391,7 +1393,7 @@ template static STAmount divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool roundUp) { - if (den == beast::zero) + if (den == beast::kZERO) Throw("division by zero"); - if (num == beast::zero) + if (num == beast::kZERO) return {asset}; std::uint64_t numVal = num.mantissa(), denVal = den.mantissa(); @@ -1516,7 +1518,7 @@ divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool if (num.integral()) { - while (numVal < STAmount::cMinValue) + while (numVal < STAmount::kC_MIN_VALUE) { numVal *= 10; --numOffset; @@ -1525,7 +1527,7 @@ divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool if (den.integral()) { - while (denVal < STAmount::cMinValue) + while (denVal < STAmount::kC_MIN_VALUE) { denVal *= 10; --denOffset; @@ -1543,7 +1545,7 @@ divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool // We round away from zero if we're rounding up or // truncate if we're rounding down. std::uint64_t amount = - muldiv_round(numVal, tenTo17, denVal, (resultNegative != roundUp) ? denVal - 1 : 0); + muldivRound(numVal, kTEN_TO17, denVal, (resultNegative != roundUp) ? denVal - 1 : 0); int offset = numOffset - denOffset - 17; @@ -1554,8 +1556,8 @@ divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool // If appropriate, tell Number the rounding mode we are using. // Note that "roundUp == true" actually means "round away from zero". // Otherwise, round toward zero. - using enum Number::rounding_mode; - MightSaveRound const savedRound(roundUp ^ resultNegative ? upward : downward); + using enum Number::RoundingMode; + MightSaveRound const savedRound(roundUp ^ resultNegative ? Upward : Downward); return STAmount(asset, amount, offset, resultNegative); }(); @@ -1570,8 +1572,8 @@ divRoundImpl(STAmount const& num, STAmount const& den, Asset const& asset, bool else { // return the smallest value above zero - amount = STAmount::cMinValue; - offset = STAmount::cMinOffset; + amount = STAmount::kC_MIN_VALUE; + offset = STAmount::kC_MIN_OFFSET; } return STAmount(asset, amount, offset, resultNegative); } diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index 295ca9b8ab..b433127dab 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -55,11 +55,11 @@ namespace xrpl { NotTEC preflight0(PreflightContext const& ctx, std::uint32_t flagMask) { - if (isPseudoTx(ctx.tx) && ctx.tx.isFlag(tfInnerBatchTxn)) + if (isPseudoTx(ctx.tx) && ctx.tx.isFlag(kTF_INNER_BATCH_TXN)) { JLOG(ctx.j.warn()) << "Pseudo transactions cannot contain the " "tfInnerBatchTxn flag."; - return temINVALID_FLAG; + return TemInvalidFlag; } if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID)) @@ -72,36 +72,36 @@ preflight0(PreflightContext const& ctx, std::uint32_t flagMask) // legacy networks have ids less than 1024, these networks cannot // specify NetworkID in txn if (txNID) - return telNETWORK_ID_MAKES_TX_NON_CANONICAL; + return TelNetworkIdMakesTxNonCanonical; } else { // new networks both require the field to be present and require it // to match if (!txNID) - return telREQUIRES_NETWORK_ID; + return TelRequiresNetworkId; if (*txNID != nodeNID) - return telWRONG_NETWORK; + return TelWrongNetwork; } } auto const txID = ctx.tx.getTransactionID(); - if (txID == beast::zero) + if (txID == beast::kZERO) { JLOG(ctx.j.warn()) << "applyTransaction: transaction id may not be zero"; - return temINVALID; + return TemInvalid; } if ((ctx.tx.getFlags() & flagMask) != 0u) { JLOG(ctx.j.debug()) << ctx.tx.peekAtField(sfTransactionType).getFullText() << ": invalid flags."; - return temINVALID_FLAG; + return TemInvalidFlag; } - return tesSUCCESS; + return TesSuccess; } namespace detail { @@ -117,28 +117,28 @@ preflightCheckSigningKey(STObject const& sigObject, beast::Journal j) !spk.empty() && !publicKeyType(makeSlice(spk))) { JLOG(j.debug()) << "preflightCheckSigningKey: invalid signing key"; - return temBAD_SIGNATURE; + return TemBadSignature; } - return tesSUCCESS; + return TesSuccess; } std::optional preflightCheckSimulateKeys(ApplyFlags flags, STObject const& sigObject, beast::Journal j) { - if ((flags & tapDRY_RUN) != 0u) // simulation + if ((flags & TapDryRun) != 0u) // simulation { std::optional const signature = sigObject[~sfTxnSignature]; if (signature && !signature->empty()) { // NOTE: This code should never be hit because it's checked in the // `simulate` RPC - return temINVALID; // LCOV_EXCL_LINE + return TemInvalid; // LCOV_EXCL_LINE } if (!sigObject.isFieldPresent(sfSigners)) { // no signers, no signature - a valid simulation - return tesSUCCESS; + return TesSuccess; } for (auto const& signer : sigObject.getFieldArray(sfSigners)) @@ -147,7 +147,7 @@ preflightCheckSimulateKeys(ApplyFlags flags, STObject const& sigObject, beast::J { // NOTE: This code should never be hit because it's // checked in the `simulate` RPC - return temINVALID; // LCOV_EXCL_LINE + return TemInvalid; // LCOV_EXCL_LINE } } @@ -155,9 +155,9 @@ preflightCheckSimulateKeys(ApplyFlags flags, STObject const& sigObject, beast::J if (!signingPubKey.empty()) { // trying to single-sign _and_ multi-sign a transaction - return temINVALID; + return TemInvalid; } - return tesSUCCESS; + return TesSuccess; } return {}; } @@ -171,20 +171,20 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) if (ctx.tx.isFieldPresent(sfDelegate)) { if (!ctx.rules.enabled(featurePermissionDelegationV1_1)) - return temDISABLED; + return TemDisabled; if (ctx.tx[sfDelegate] == ctx.tx[sfAccount]) - return temBAD_SIGNER; + return TemBadSigner; } if (auto const ret = preflight0(ctx, flagMask)) return ret; auto const id = ctx.tx.getAccountID(sfAccount); - if (id == beast::zero) + if (id == beast::kZERO) { JLOG(ctx.j.warn()) << "preflight1: bad account id"; - return temBAD_SRC_ACCOUNT; + return TemBadSrcAccount; } // No point in going any further if the transaction fee is malformed. @@ -192,7 +192,7 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) if (!fee.native() || fee.negative() || !isLegalAmount(fee.xrp())) { JLOG(ctx.j.debug()) << "preflight1: invalid fee"; - return temBAD_FEE; + return TemBadFee; } if (auto const ret = detail::preflightCheckSigningKey(ctx.tx, ctx.j)) @@ -205,17 +205,17 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) // // We return temINVALID for such transactions. if (ctx.tx.getSeqProxy().isTicket() && ctx.tx.isFieldPresent(sfAccountTxnID)) - return temINVALID; + return TemInvalid; - if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatch)) - return temINVALID_FLAG; + if (ctx.tx.isFlag(kTF_INNER_BATCH_TXN) && !ctx.rules.enabled(featureBatch)) + return TemInvalidFlag; XRPL_ASSERT( - ctx.tx.isFlag(tfInnerBatchTxn) == ctx.parentBatchId.has_value() || + ctx.tx.isFlag(kTF_INNER_BATCH_TXN) == ctx.parentBatchId.has_value() || !ctx.rules.enabled(featureBatch), "Inner batch transaction must have a parent batch ID."); - return tesSUCCESS; + return TesSuccess; } /** Checks whether the signature appears valid */ @@ -232,12 +232,12 @@ Transactor::preflight2(PreflightContext const& ctx) // It should be impossible for the InnerBatchTxn flag to be set without // featureBatch being enabled XRPL_ASSERT_PARTS( - !ctx.tx.isFlag(tfInnerBatchTxn) || ctx.rules.enabled(featureBatch), + !ctx.tx.isFlag(kTF_INNER_BATCH_TXN) || ctx.rules.enabled(featureBatch), "xrpl::Transactor::preflight2", "InnerBatch flag only set if feature enabled"); // Skip signature check on batch inner transactions - if (ctx.tx.isFlag(tfInnerBatchTxn) && ctx.rules.enabled(featureBatch)) - return tesSUCCESS; + if (ctx.tx.isFlag(kTF_INNER_BATCH_TXN) && ctx.rules.enabled(featureBatch)) + return TesSuccess; // Do not add any checks after this point that are relevant for // batch inner transactions. They will be skipped. @@ -245,14 +245,14 @@ Transactor::preflight2(PreflightContext const& ctx) if (sigValid.first == Validity::SigBad) { // LCOV_EXCL_START JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second; - return temINVALID; + return TemInvalid; // LCOV_EXCL_STOP } // Do not add any checks after this point that are relevant for // batch inner transactions. They will be skipped. - return tesSUCCESS; + return TesSuccess; } //------------------------------------------------------------------------------ @@ -276,13 +276,13 @@ Transactor::validDataLength(std::optional const& slice, std::size_t maxLe std::uint32_t Transactor::getFlagsMask(PreflightContext const& ctx) { - return tfUniversalMask; + return kTF_UNIVERSAL_MASK; } NotTEC Transactor::preflightSigValidated(PreflightContext const& ctx) { - return tesSUCCESS; + return TesSuccess; } NotTEC @@ -290,13 +290,13 @@ Transactor::checkPermission(ReadView const& view, STTx const& tx) { auto const delegate = tx[~sfDelegate]; if (!delegate) - return tesSUCCESS; + return TesSuccess; auto const delegateKey = keylet::delegate(tx[sfAccount], *delegate); auto const sle = view.read(delegateKey); if (!sle) - return terNO_DELEGATE_PERMISSION; + return TerNoDelegatePermission; return checkTxPermission(sle, tx); } @@ -347,28 +347,28 @@ Transactor::minimumFee( Fees const& fees, ApplyFlags flags) { - return scaleFeeLoad(baseFee, registry.getFeeTrack(), fees, (flags & tapUNLIMITED) != 0u); + return scaleFeeLoad(baseFee, registry.getFeeTrack(), fees, (flags & TapUnlimited) != 0u); } TER Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) { if (!ctx.tx[sfFee].native()) - return temBAD_FEE; + return TemBadFee; auto const feePaid = ctx.tx[sfFee].xrp(); - if ((ctx.flags & tapBATCH) != 0u) + if ((ctx.flags & TapBatch) != 0u) { - if (feePaid == beast::zero) - return tesSUCCESS; + if (feePaid == beast::kZERO) + return TesSuccess; JLOG(ctx.j.trace()) << "Batch: Fee must be zero."; - return temBAD_FEE; // LCOV_EXCL_LINE + return TemBadFee; // LCOV_EXCL_LINE } - if (!isLegalAmount(feePaid) || feePaid < beast::zero) - return temBAD_FEE; + if (!isLegalAmount(feePaid) || feePaid < beast::kZERO) + return TemBadFee; // Only check fee is sufficient when the ledger is open. if (ctx.view.open()) @@ -379,17 +379,17 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) { JLOG(ctx.j.trace()) << "Insufficient fee paid: " << to_string(feePaid) << "/" << to_string(feeDue); - return telINSUF_FEE_P; + return TelInsufFeeP; } } - if (feePaid == beast::zero) - return tesSUCCESS; + if (feePaid == beast::kZERO) + return TesSuccess; auto const id = ctx.tx.getFeePayer(); auto const sle = ctx.view.read(keylet::account(id)); if (!sle) - return terNO_ACCOUNT; + return TerNoAccount; auto const balance = (*sle)[sfBalance].xrp(); @@ -405,16 +405,16 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) JLOG(ctx.j.trace()) << "Insufficient balance:" << " balance=" << to_string(balance) << " paid=" << to_string(feePaid); - if ((balance > beast::zero) && !ctx.view.open()) + if ((balance > beast::kZERO) && !ctx.view.open()) { // Closed ledger, non-zero balance, less than fee - return tecINSUFF_FEE; + return TecInsuffFee; } - return terINSUF_FEE_B; + return TerInsufFeeB; } - return tesSUCCESS; + return TesSuccess; } TER @@ -425,7 +425,7 @@ Transactor::payFee() auto const feePayer = ctx_.tx.getFeePayer(); auto const sle = view().peek(keylet::account(feePayer)); if (!sle) - return tefINTERNAL; // LCOV_EXCL_LINE + return TefInternal; // LCOV_EXCL_LINE // Deduct the fee, so it's not available during the transaction. // Will only write the account back if the transaction succeeds. @@ -434,7 +434,7 @@ Transactor::payFee() view().update(sle); // done in `apply()` for the account // VFALCO Should we call view().rawDestroyXRP() here as well? - return tesSUCCESS; + return TesSuccess; } NotTEC @@ -448,58 +448,58 @@ Transactor::checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j { JLOG(j.trace()) << "applyTransaction: delay: source account does not exist " << toBase58(id); - return terNO_ACCOUNT; + return TerNoAccount; } - SeqProxy const t_seqProx = tx.getSeqProxy(); - SeqProxy const a_seq = SeqProxy::sequence((*sle)[sfSequence]); + SeqProxy const tSeqProx = tx.getSeqProxy(); + SeqProxy const aSeq = SeqProxy::sequence((*sle)[sfSequence]); - if (t_seqProx.isSeq()) + if (tSeqProx.isSeq()) { if (tx.isFieldPresent(sfTicketSequence)) { JLOG(j.trace()) << "applyTransaction: has both a TicketSequence " "and a non-zero Sequence number"; - return temSEQ_AND_TICKET; + return TemSeqAndTicket; } - if (t_seqProx != a_seq) + if (tSeqProx != aSeq) { - if (a_seq < t_seqProx) + if (aSeq < tSeqProx) { JLOG(j.trace()) << "applyTransaction: has future sequence number " - << "a_seq=" << a_seq << " t_seq=" << t_seqProx; - return terPRE_SEQ; + << "a_seq=" << aSeq << " t_seq=" << tSeqProx; + return TerPreSeq; } // It's an already-used sequence number. JLOG(j.trace()) << "applyTransaction: has past sequence number " - << "a_seq=" << a_seq << " t_seq=" << t_seqProx; - return tefPAST_SEQ; + << "a_seq=" << aSeq << " t_seq=" << tSeqProx; + return TefPastSeq; } } - else if (t_seqProx.isTicket()) + else if (tSeqProx.isTicket()) { // Bypass the type comparison. Apples and oranges. - if (a_seq.value() <= t_seqProx.value()) + if (aSeq.value() <= tSeqProx.value()) { // If the Ticket number is greater than or equal to the // account sequence there's the possibility that the // transaction to create the Ticket has not hit the ledger // yet. Allow a retry. JLOG(j.trace()) << "applyTransaction: has future ticket id " - << "a_seq=" << a_seq << " t_seq=" << t_seqProx; - return terPRE_TICKET; + << "a_seq=" << aSeq << " t_seq=" << tSeqProx; + return TerPreTicket; } // Transaction can never succeed if the Ticket is not in the ledger. - if (!view.exists(keylet::ticket(id, t_seqProx))) + if (!view.exists(keylet::kTICKET(id, tSeqProx))) { JLOG(j.trace()) << "applyTransaction: ticket already used or never created " - << "a_seq=" << a_seq << " t_seq=" << t_seqProx; - return tefNO_TICKET; + << "a_seq=" << aSeq << " t_seq=" << tSeqProx; + return TefNoTicket; } } - return tesSUCCESS; + return TesSuccess; } NotTEC @@ -513,21 +513,21 @@ Transactor::checkPriorTxAndLastLedger(PreclaimContext const& ctx) { JLOG(ctx.j.trace()) << "applyTransaction: delay: source account does not exist " << toBase58(id); - return terNO_ACCOUNT; + return TerNoAccount; } if (ctx.tx.isFieldPresent(sfAccountTxnID) && (sle->getFieldH256(sfAccountTxnID) != ctx.tx.getFieldH256(sfAccountTxnID))) - return tefWRONG_PRIOR; + return TefWrongPrior; if (ctx.tx.isFieldPresent(sfLastLedgerSequence) && (ctx.view.seq() > ctx.tx.getFieldU32(sfLastLedgerSequence))) - return tefMAX_LEDGER; + return TefMaxLedger; if (ctx.view.txExists(ctx.tx.getTransactionID())) - return tefALREADY; + return TefAlready; - return tesSUCCESS; + return TesSuccess; } TER @@ -541,7 +541,7 @@ Transactor::consumeSeqProxy(SLE::pointer const& sleAccount) // the transaction will modify the account root sfSequence // yet again. sleAccount->setFieldU32(sfSequence, seqProx.value() + 1); - return tesSUCCESS; + return TesSuccess; } return ticketDelete(view(), account_, getTicketIndex(account_, seqProx), j_); } @@ -556,12 +556,12 @@ Transactor::ticketDelete( { // Delete the Ticket, adjust the account root ticket count, and // reduce the owner count. - SLE::pointer const sleTicket = view.peek(keylet::ticket(ticketIndex)); + SLE::pointer const sleTicket = view.peek(keylet::kTICKET(ticketIndex)); if (!sleTicket) { // LCOV_EXCL_START JLOG(j.fatal()) << "Ticket disappeared from ledger."; - return tefBAD_LEDGER; + return TefBadLedger; // LCOV_EXCL_STOP } @@ -570,7 +570,7 @@ Transactor::ticketDelete( { // LCOV_EXCL_START JLOG(j.fatal()) << "Unable to delete Ticket from owner."; - return tefBAD_LEDGER; + return TefBadLedger; // LCOV_EXCL_STOP } @@ -581,7 +581,7 @@ Transactor::ticketDelete( { // LCOV_EXCL_START JLOG(j.fatal()) << "Could not find Ticket owner account root."; - return tefBAD_LEDGER; + return TefBadLedger; // LCOV_EXCL_STOP } @@ -600,7 +600,7 @@ Transactor::ticketDelete( { // LCOV_EXCL_START JLOG(j.fatal()) << "TicketCount field missing from account root."; - return tefBAD_LEDGER; + return TefBadLedger; // LCOV_EXCL_STOP } @@ -609,14 +609,14 @@ Transactor::ticketDelete( // Remove Ticket from ledger. view.erase(sleTicket); - return tesSUCCESS; + return TesSuccess; } // check stuff before you bother to lock the ledger void Transactor::preCompute() { - XRPL_ASSERT(account_ != beast::zero, "xrpl::Transactor::preCompute : nonzero account"); + XRPL_ASSERT(account_ != beast::kZERO, "xrpl::Transactor::preCompute : nonzero account"); } TER @@ -631,7 +631,7 @@ Transactor::apply() // sle must exist except for transactions // that allow zero account. XRPL_ASSERT( - sle != nullptr || account_ == beast::zero, + sle != nullptr || account_ == beast::kZERO, "xrpl::Transactor::apply : non-null SLE or zero account"); if (sle) @@ -672,7 +672,7 @@ Transactor::checkSign( // Pseudo-accounts can't sign transactions. This check is gated on // the Lending Protocol amendment because that's the project it was // added under, and it doesn't justify another amendment - return tefBAD_AUTH; + return TefBadAuth; } } @@ -684,16 +684,16 @@ Transactor::checkSign( if (sigObject.isFieldPresent(sfTxnSignature) || !pkSigner.empty() || sigObject.isFieldPresent(sfSigners)) { - return temINVALID_FLAG; // LCOV_EXCL_LINE + return TemInvalidFlag; // LCOV_EXCL_LINE } - return tesSUCCESS; + return TesSuccess; } - if (((flags & tapDRY_RUN) != 0u) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners)) + if (((flags & TapDryRun) != 0u) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners)) { // simulate: skip signature validation when neither SigningPubKey nor // Signers are provided - return tesSUCCESS; + return TesSuccess; } // If the pk is empty and not simulate or simulate and signers, @@ -709,14 +709,14 @@ Transactor::checkSign( if (!publicKeyType(makeSlice(pkSigner))) { JLOG(j.trace()) << "checkSign: signing public key type is unknown"; - return tefBAD_AUTH; // FIXME: should be better error! + return TefBadAuth; // FIXME: should be better error! } // Look up the account. auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner))); auto const sleAccount = view.read(keylet::account(idAccount)); if (!sleAccount) - return terNO_ACCOUNT; + return TerNoAccount; return checkSingleSign(view, idSigner, idAccount, sleAccount, j); } @@ -732,7 +732,7 @@ Transactor::checkSign(PreclaimContext const& ctx) NotTEC Transactor::checkBatchSign(PreclaimContext const& ctx) { - NotTEC ret = tesSUCCESS; + NotTEC ret = TesSuccess; STArray const& signers{ctx.tx.getFieldArray(sfBatchSigners)}; for (auto const& signer : signers) { @@ -749,7 +749,7 @@ Transactor::checkBatchSign(PreclaimContext const& ctx) { // LCOV_EXCL_START if (!publicKeyType(makeSlice(pkSigner))) - return tefBAD_AUTH; + return TefBadAuth; // LCOV_EXCL_STOP auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner))); @@ -760,9 +760,9 @@ Transactor::checkBatchSign(PreclaimContext const& ctx) if (!sleAccount) { if (idAccount != idSigner) - return tefBAD_AUTH; + return TefBadAuth; - return tesSUCCESS; + return TesSuccess; } if (ret = checkSingleSign(ctx.view, idSigner, idAccount, sleAccount, ctx.j); @@ -781,28 +781,28 @@ Transactor::checkSingleSign( std::shared_ptr sleAccount, beast::Journal const j) { - bool const isMasterDisabled = sleAccount->isFlag(lsfDisableMaster); + bool const isMasterDisabled = sleAccount->isFlag(LsfDisableMaster); // Signed with regular key. if ((*sleAccount)[~sfRegularKey] == idSigner) { - return tesSUCCESS; + return TesSuccess; } // Signed with enabled master key. if (!isMasterDisabled && idAccount == idSigner) { - return tesSUCCESS; + return TesSuccess; } // Signed with disabled master key. if (isMasterDisabled && idAccount == idSigner) { - return tefMASTER_DISABLED; + return TefMasterDisabled; } // Signed with any other key. - return tefBAD_AUTH; + return TefBadAuth; } NotTEC @@ -819,7 +819,7 @@ Transactor::checkMultiSign( if (!sleAccountSigners) { JLOG(j.trace()) << "applyTransaction: Invalid: Not a multi-signing account."; - return tefNOT_MULTI_SIGNING; + return TefNotMultiSigning; } // We have plans to support multiple SignerLists in the future. The @@ -856,14 +856,14 @@ Transactor::checkMultiSign( if (++iter == accountSigners->end()) { JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account."; - return tefBAD_SIGNATURE; + return TefBadSignature; } } if (iter->account != txSignerAcctID) { // The SigningAccount is not in the SignerEntries. JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account."; - return tefBAD_SIGNATURE; + return TefBadSignature; } // We found the SigningAccount in the list of valid signers. Now we @@ -876,11 +876,11 @@ Transactor::checkMultiSign( if (!spk.empty() && !publicKeyType(makeSlice(spk))) { JLOG(j.trace()) << "checkMultiSign: signing public key type is unknown"; - return tefBAD_SIGNATURE; + return TefBadSignature; } XRPL_ASSERT( - (flags & tapDRY_RUN) || !spk.empty(), + (flags & TapDryRun) || !spk.empty(), "xrpl::Transactor::checkMultiSign : non-empty signer or " "simulation"); AccountID const signingAcctIDFromPubKey = @@ -921,10 +921,10 @@ Transactor::checkMultiSign( // Master Key. Account may not have asfDisableMaster set. std::uint32_t const signerAccountFlags = sleTxSignerRoot->getFieldU32(sfFlags); - if ((signerAccountFlags & lsfDisableMaster) != 0u) + if ((signerAccountFlags & LsfDisableMaster) != 0u) { JLOG(j.trace()) << "applyTransaction: Signer:Account lsfDisableMaster."; - return tefMASTER_DISABLED; + return TefMasterDisabled; } } } @@ -936,18 +936,18 @@ Transactor::checkMultiSign( { JLOG(j.trace()) << "applyTransaction: Non-phantom signer " "lacks account root."; - return tefBAD_SIGNATURE; + return TefBadSignature; } if (!sleTxSignerRoot->isFieldPresent(sfRegularKey)) { JLOG(j.trace()) << "applyTransaction: Account lacks RegularKey."; - return tefBAD_SIGNATURE; + return TefBadSignature; } if (signingAcctIDFromPubKey != sleTxSignerRoot->getAccountID(sfRegularKey)) { JLOG(j.trace()) << "applyTransaction: Account doesn't match RegularKey."; - return tefBAD_SIGNATURE; + return TefBadSignature; } } // The signer is legitimate. Add their weight toward the quorum. @@ -958,11 +958,11 @@ Transactor::checkMultiSign( if (weightSum < sleAccountSigners->getFieldU32(sfSignerQuorum)) { JLOG(j.trace()) << "applyTransaction: Signers failed to meet quorum."; - return tefBAD_QUORUM; + return TefBadQuorum; } // Met the quorum. Continue. - return tesSUCCESS; + return TesSuccess; } //------------------------------------------------------------------------------ @@ -978,7 +978,7 @@ removeUnfundedOffers(ApplyView& view, std::vector const& offers, beast: { // offer is unfunded offerDelete(view, sleOffer, viewJ); - if (++removed == unfundedOfferRemoveLimit) + if (++removed == kUNFUNDED_OFFER_REMOVE_LIMIT) return; } } @@ -997,7 +997,7 @@ removeExpiredNFTokenOffers( if (auto const offer = view.peek(keylet::nftoffer(index))) { nft::deleteTokenOffer(view, offer); - if (++removed == expiredOfferRemoveLimit) + if (++removed == kEXPIRED_OFFER_REMOVE_LIMIT) return; } } @@ -1019,7 +1019,7 @@ removeDeletedTrustLines( std::vector const& trustLines, beast::Journal viewJ) { - if (trustLines.size() > maxDeletableAMMTrustLines) + if (trustLines.size() > kMAX_DELETABLE_AMM_TRUST_LINES) { JLOG(viewJ.error()) << "removeDeletedTrustLines: deleted trustlines exceed max " << trustLines.size(); @@ -1049,7 +1049,7 @@ removeDeletedMPTs(ApplyView& view, std::vector const& mpts, beast::Jour for (auto const& index : mpts) { if (auto const sleState = view.peek({ltMPTOKEN, index}); sleState && - deleteAMMMPToken(view, sleState, (*sleState)[sfIssuer], viewJ) != tesSUCCESS) + deleteAMMMPToken(view, sleState, (*sleState)[sfIssuer], viewJ) != TesSuccess) { JLOG(viewJ.error()) << "removeDeletedMPTs: failed to delete AMM MPT"; } @@ -1071,17 +1071,17 @@ Transactor::reset(XRPAmount fee) // The account should never be missing from the ledger. But if it // is missing then we can't very well charge it a fee, can we? if (!txnAcct) - return {tefINTERNAL, beast::zero}; + return {TefInternal, beast::kZERO}; auto const payerSle = view().peek(keylet::account(ctx_.tx.getFeePayer())); if (!payerSle) - return {tefINTERNAL, beast::zero}; // LCOV_EXCL_LINE + return {TefInternal, beast::kZERO}; // LCOV_EXCL_LINE auto const balance = payerSle->getFieldAmount(sfBalance).xrp(); // balance should have already been checked in checkFee / preFlight. XRPL_ASSERT( - balance != beast::zero && (!view().open() || balance >= fee), + balance != beast::kZERO && (!view().open() || balance >= fee), "xrpl::Transactor::reset : valid balance"); // We retry/reject the transaction if the account balance is zero or @@ -1134,8 +1134,8 @@ Transactor::checkTransactionInvariants(TER result, XRPAmount fee) { JLOG(ctx_.journal.fatal()) << // "Transaction has failed one or more transaction invariants, tx: " << // - to_string(ctx_.tx.getJson(JsonOptions::none)); - return tecINVARIANT_FAILED; + to_string(ctx_.tx.getJson(JsonOptions::None)); + return TecInvariantFailed; } } catch (std::exception const& ex) @@ -1144,9 +1144,9 @@ Transactor::checkTransactionInvariants(TER result, XRPAmount fee) "Exception while checking transaction invariants: " << // ex.what() << // ", tx: " << // - to_string(ctx_.tx.getJson(JsonOptions::none)); + to_string(ctx_.tx.getJson(JsonOptions::None)); - return tecINVARIANT_FAILED; + return TecInvariantFailed; } return result; @@ -1164,10 +1164,10 @@ Transactor::checkInvariants(TER result, XRPAmount fee) auto const protoResult = ctx_.checkInvariants(result, fee); // Fail if either check failed. tef (fatal) takes priority over tec. - if (protoResult == tefINVARIANT_FAILED) - return tefINVARIANT_FAILED; - if (txResult == tecINVARIANT_FAILED || protoResult == tecINVARIANT_FAILED) - return tecINVARIANT_FAILED; + if (protoResult == TefInvariantFailed) + return TefInvariantFailed; + if (txResult == TecInvariantFailed || protoResult == TecInvariantFailed) + return TecInvariantFailed; return result; } @@ -1190,8 +1190,8 @@ Transactor::operator()() { // LCOV_EXCL_START JLOG(j_.fatal()) << "Transaction serdes mismatch"; - JLOG(j_.fatal()) << ctx_.tx.getJson(JsonOptions::none); - JLOG(j_.fatal()) << s2.getJson(JsonOptions::none); + JLOG(j_.fatal()) << ctx_.tx.getJson(JsonOptions::None); + JLOG(j_.fatal()) << s2.getJson(JsonOptions::None); UNREACHABLE("xrpl::Transactor::operator() : transaction serdes mismatch"); // LCOV_EXCL_STOP } @@ -1210,7 +1210,7 @@ Transactor::operator()() // No transaction can return temUNKNOWN from apply, // and it can't be passed in from a preclaim. - XRPL_ASSERT(result != temUNKNOWN, "xrpl::Transactor::operator() : result is not temUNKNOWN"); + XRPL_ASSERT(result != TemUnknown, "xrpl::Transactor::operator() : result is not temUNKNOWN"); if (auto stream = j_.trace()) stream << "preclaim result: " << transToken(result); @@ -1218,10 +1218,10 @@ Transactor::operator()() bool applied = isTesSuccess(result); auto fee = ctx_.tx.getFieldAmount(sfFee).xrp(); - if (ctx_.size() > oversizeMetaDataCap) - result = tecOVERSIZE; + if (ctx_.size() > kOVERSIZE_META_DATA_CAP) + result = TecOversize; - if (isTecClaim(result) && ((view().flags() & tapFAIL_HARD) != 0u)) + if (isTecClaim(result) && ((view().flags() & TapFailHard) != 0u)) { // If the tapFAIL_HARD flag is set, a tec result // must not do anything @@ -1229,8 +1229,8 @@ Transactor::operator()() applied = false; } else if ( - (result == tecOVERSIZE) || (result == tecKILLED) || (result == tecINCOMPLETE) || - (result == tecEXPIRED) || (isTecClaimHardFail(result, view().flags()))) + (result == TecOversize) || (result == TecKilled) || (result == TecIncomplete) || + (result == TecExpired) || (isTecClaimHardFail(result, view().flags()))) { JLOG(j_.trace()) << "reapplying because of " << transToken(result); @@ -1244,10 +1244,10 @@ Transactor::operator()() std::vector expiredNFTokenOffers; std::vector expiredCredentials; - bool const doOffers = ((result == tecOVERSIZE) || (result == tecKILLED)); - bool const doLinesOrMPTs = (result == tecINCOMPLETE); - bool const doNFTokenOffers = (result == tecEXPIRED); - bool const doCredentials = (result == tecEXPIRED); + bool const doOffers = ((result == TecOversize) || (result == TecKilled)); + bool const doLinesOrMPTs = (result == TecIncomplete); + bool const doNFTokenOffers = (result == TecExpired); + bool const doCredentials = (result == TecExpired); if (doOffers || doLinesOrMPTs || doNFTokenOffers || doCredentials) { ctx_.visit([doOffers, @@ -1309,25 +1309,25 @@ Transactor::operator()() } // If necessary, remove any offers found unfunded during processing - if ((result == tecOVERSIZE) || (result == tecKILLED)) + if ((result == TecOversize) || (result == TecKilled)) { removeUnfundedOffers(view(), removedOffers, ctx_.registry.get().getJournal("View")); } - if (result == tecEXPIRED) + if (result == TecExpired) { removeExpiredNFTokenOffers( view(), expiredNFTokenOffers, ctx_.registry.get().getJournal("View")); } - if (result == tecINCOMPLETE) + if (result == TecIncomplete) { removeDeletedTrustLines( view(), removedTrustLines, ctx_.registry.get().getJournal("View")); removeDeletedMPTs(view(), removedMPTs, ctx_.registry.get().getJournal("View")); } - if (result == tecEXPIRED) + if (result == TecExpired) { removeExpiredCredentials( view(), expiredCredentials, ctx_.registry.get().getJournal("View")); @@ -1341,7 +1341,7 @@ Transactor::operator()() // Check invariants: if `tecINVARIANT_FAILED` is not returned, we can // proceed to apply the tx result = checkInvariants(result, fee); - if (result == tecINVARIANT_FAILED) + if (result == TecInvariantFailed) { // Reset to fee-claim only auto const resetResult = reset(fee); @@ -1373,21 +1373,21 @@ Transactor::operator()() // The transactor and invariant checkers guarantee that this will // *never* trigger but if it, somehow, happens, don't allow a tx // that charges a negative fee. - if (fee < beast::zero) + if (fee < beast::kZERO) Throw("fee charged is negative!"); // Charge whatever fee they specified. The fee has already been // deducted from the balance of the account that issued the // transaction. We just need to account for it in the ledger // header. - if (!view().open() && fee != beast::zero) + if (!view().open() && fee != beast::kZERO) ctx_.destroyXRP(fee); // Once we call apply, we will no longer be able to look at view() metadata = ctx_.apply(result); } - if ((ctx_.flags() & tapDRY_RUN) != 0u) + if ((ctx_.flags() & TapDryRun) != 0u) { applied = false; } diff --git a/src/libxrpl/tx/apply.cpp b/src/libxrpl/tx/apply.cpp index ad8dd763ba..79a94dc163 100644 --- a/src/libxrpl/tx/apply.cpp +++ b/src/libxrpl/tx/apply.cpp @@ -26,10 +26,10 @@ namespace xrpl { // These are the same flags defined as HashRouterFlags::PRIVATE1-4 in // HashRouter.h -constexpr HashRouterFlags SF_SIGBAD = HashRouterFlags::PRIVATE1; // Signature is bad -constexpr HashRouterFlags SF_SIGGOOD = HashRouterFlags::PRIVATE2; // Signature is good -constexpr HashRouterFlags SF_LOCALBAD = HashRouterFlags::PRIVATE3; // Local checks failed -constexpr HashRouterFlags SF_LOCALGOOD = HashRouterFlags::PRIVATE4; // Local checks passed +constexpr HashRouterFlags kSF_SIGBAD = HashRouterFlags::PRIVATE1; // Signature is bad +constexpr HashRouterFlags kSF_SIGGOOD = HashRouterFlags::PRIVATE2; // Signature is good +constexpr HashRouterFlags kSF_LOCALBAD = HashRouterFlags::PRIVATE3; // Local checks failed +constexpr HashRouterFlags kSF_LOCALGOOD = HashRouterFlags::PRIVATE4; // Local checks passed //------------------------------------------------------------------------------ @@ -40,7 +40,7 @@ checkValidity(HashRouter& router, STTx const& tx, Rules const& rules) auto const flags = router.getFlags(id); // Ignore signature check on batch inner transactions - if (tx.isFlag(tfInnerBatchTxn) && rules.enabled(featureBatch)) + if (tx.isFlag(kTF_INNER_BATCH_TXN) && rules.enabled(featureBatch)) { // Defensive Check: These values are also checked in Batch::preflight if (tx.isFieldPresent(sfTxnSignature) || !tx.getSigningPubKey().empty() || @@ -56,41 +56,41 @@ checkValidity(HashRouter& router, STTx const& tx, Rules const& rules) std::string reason; if (!passesLocalChecks(tx, reason)) { - router.setFlags(id, SF_LOCALBAD); + router.setFlags(id, kSF_LOCALBAD); return {Validity::SigGoodOnly, reason}; } - router.setFlags(id, SF_SIGGOOD); + router.setFlags(id, kSF_SIGGOOD); return {Validity::Valid, ""}; } } - if (any(flags & SF_SIGBAD)) + if (any(flags & kSF_SIGBAD)) { // Signature is known bad return {Validity::SigBad, "Transaction has bad signature."}; } - if (!any(flags & SF_SIGGOOD)) + if (!any(flags & kSF_SIGGOOD)) { auto const sigVerify = tx.checkSign(rules); if (!sigVerify) { - router.setFlags(id, SF_SIGBAD); + router.setFlags(id, kSF_SIGBAD); return {Validity::SigBad, sigVerify.error()}; } - router.setFlags(id, SF_SIGGOOD); + router.setFlags(id, kSF_SIGGOOD); } // Signature is now known good - if (any(flags & SF_LOCALBAD)) + if (any(flags & kSF_LOCALBAD)) { // ...but the local checks // are known bad. return {Validity::SigGoodOnly, "Local checks failed."}; } - if (any(flags & SF_LOCALGOOD)) + if (any(flags & kSF_LOCALGOOD)) { // ...and the local checks // are known good. @@ -101,10 +101,10 @@ checkValidity(HashRouter& router, STTx const& tx, Rules const& rules) std::string reason; if (!passesLocalChecks(tx, reason)) { - router.setFlags(id, SF_LOCALBAD); + router.setFlags(id, kSF_LOCALBAD); return {Validity::SigGoodOnly, reason}; } - router.setFlags(id, SF_LOCALGOOD); + router.setFlags(id, kSF_LOCALGOOD); return {Validity::Valid, ""}; } @@ -115,10 +115,10 @@ forceValidity(HashRouter& router, uint256 const& txid, Validity validity) switch (validity) { case Validity::Valid: - flags |= SF_LOCALGOOD; + flags |= kSF_LOCALGOOD; [[fallthrough]]; case Validity::SigGoodOnly: - flags |= SF_SIGGOOD; + flags |= kSF_SIGGOOD; [[fallthrough]]; case Validity::SigBad: // would be silly to call directly @@ -171,9 +171,9 @@ applyBatchTransactions( auto const mode = batchTxn.getFlags(); auto applyOneTransaction = [®istry, &j, &parentBatchId, &batchView](STTx const& tx) { - OpenView perTxBatchView(batch_view, batchView); + OpenView perTxBatchView(kBATCH_VIEW, batchView); - auto const ret = apply(registry, perTxBatchView, parentBatchId, tx, tapBATCH, j); + auto const ret = apply(registry, perTxBatchView, parentBatchId, tx, TapBatch, j); XRPL_ASSERT( ret.applied == (isTesSuccess(ret.ter) || isTecClaim(ret.ter)), "Inner transaction should not be applied"); @@ -203,13 +203,13 @@ applyBatchTransactions( if (!isTesSuccess(result.ter)) { - if ((mode & tfAllOrNothing) != 0u) + if ((mode & kTF_ALL_OR_NOTHING) != 0u) return false; - if ((mode & tfUntilFailure) != 0u) + if ((mode & kTF_UNTIL_FAILURE) != 0u) break; } - else if ((mode & tfOnlyOne) != 0u) + else if ((mode & kTF_ONLY_ONE) != 0u) { break; } @@ -229,7 +229,7 @@ applyTransaction( { // Returns false if the transaction has need not be retried. if (retryAssured) - flags = flags | tapRETRY; + flags = flags | TapRetry; JLOG(j.debug()) << "TXN " << txn.getTransactionID() << (retryAssured ? "/retry" : "/final"); @@ -245,7 +245,7 @@ applyTransaction( // its inner transactions as necessary. if (isTesSuccess(result.ter) && txn.getTxnType() == ttBATCH) { - OpenView wholeBatchView(batch_view, view); + OpenView wholeBatchView(kBATCH_VIEW, view); if (applyBatchTransactions(registry, wholeBatchView, txn, j)) wholeBatchView.apply(view); diff --git a/src/libxrpl/tx/applySteps.cpp b/src/libxrpl/tx/applySteps.cpp index 798fa2b447..e46f8bf2ab 100644 --- a/src/libxrpl/tx/applySteps.cpp +++ b/src/libxrpl/tx/applySteps.cpp @@ -55,7 +55,7 @@ struct UnknownTxnType : std::exception // throw an "UnknownTxnType" exception on error template auto -with_txn_type(Rules const& rules, TxType txnType, F&& f) +withTxnType(Rules const& rules, TxType txnType, F&& f) { // These global updates really should have been for every Transaction // step: preflight, preclaim, calculateBaseFee, and doApply. Unfortunately, @@ -79,7 +79,7 @@ with_txn_type(Rules const& rules, TxType txnType, F&& f) else { // Without those features enabled, always use the old number rules. - mantissaScaleGuard.emplace(MantissaRange::mantissa_scale::small); + mantissaScaleGuard.emplace(MantissaRange::MantissaScale::Small); } switch (txnType) @@ -125,7 +125,7 @@ template TxConsequences consequences_helper(PreflightContext const& ctx) { - return TxConsequences(ctx.tx, TxConsequences::Category::blocker); + return TxConsequences(ctx.tx, TxConsequences::Category::Blocker); }; // For Transactor::Custom @@ -138,11 +138,11 @@ consequences_helper(PreflightContext const& ctx) }; static std::pair -invoke_preflight(PreflightContext const& ctx) +invokePreflight(PreflightContext const& ctx) { try { - return with_txn_type(ctx.rules, ctx.tx.getTxnType(), [&]() { + return withTxnType(ctx.rules, ctx.tx.getTxnType(), [&]() { auto const tec = Transactor::invokePreflight(ctx); return std::make_pair( tec, isTesSuccess(tec) ? consequences_helper(ctx) : TxConsequences{tec}); @@ -154,19 +154,19 @@ invoke_preflight(PreflightContext const& ctx) // LCOV_EXCL_START JLOG(ctx.j.fatal()) << "Unknown transaction type in preflight: " << e.txnType; UNREACHABLE("xrpl::invoke_preflight : unknown transaction type"); - return {temUNKNOWN, TxConsequences{temUNKNOWN}}; + return {TemUnknown, TxConsequences{TemUnknown}}; // LCOV_EXCL_STOP } } static TER -invoke_preclaim(PreclaimContext const& ctx) +invokePreclaim(PreclaimContext const& ctx) { try { // use name hiding to accomplish compile-time polymorphism of static // class functions for Transactor and derived classes. - return with_txn_type(ctx.view.rules(), ctx.tx.getTxnType(), [&]() -> TER { + return withTxnType(ctx.view.rules(), ctx.tx.getTxnType(), [&]() -> TER { // preclaim functionality is divided into two sections: // 1. Up to and including the signature check: returns NotTEC. // All transaction checks before and including checkSign @@ -181,7 +181,7 @@ invoke_preclaim(PreclaimContext const& ctx) // a flagged a failure. auto const id = ctx.tx.getAccountID(sfAccount); - if (id != beast::zero) + if (id != beast::kZERO) { if (NotTEC const preSigResult = [&]() -> NotTEC { if (NotTEC const result = T::checkSeqProxy(ctx.view, ctx.tx, ctx.j)) @@ -196,7 +196,7 @@ invoke_preclaim(PreclaimContext const& ctx) if (NotTEC const result = T::checkSign(ctx)) return result; - return tesSUCCESS; + return TesSuccess; }()) return preSigResult; @@ -213,7 +213,7 @@ invoke_preclaim(PreclaimContext const& ctx) // LCOV_EXCL_START JLOG(ctx.j.fatal()) << "Unknown transaction type in preclaim: " << e.txnType; UNREACHABLE("xrpl::invoke_preclaim : unknown transaction type"); - return temUNKNOWN; + return TemUnknown; // LCOV_EXCL_STOP } } @@ -235,11 +235,11 @@ invoke_preclaim(PreclaimContext const& ctx) * logs an error and returns an XRPAmount of zero. */ static XRPAmount -invoke_calculateBaseFee(ReadView const& view, STTx const& tx) +invokeCalculateBaseFee(ReadView const& view, STTx const& tx) { try { - return with_txn_type(view.rules(), tx.getTxnType(), [&]() { + return withTxnType(view.rules(), tx.getTxnType(), [&]() { return T::calculateBaseFee(view, tx); }); } @@ -254,8 +254,8 @@ invoke_calculateBaseFee(ReadView const& view, STTx const& tx) TxConsequences::TxConsequences(NotTEC pfResult) : isBlocker_(false) - , fee_(beast::zero) - , potentialSpend_(beast::zero) + , fee_(beast::kZERO) + , potentialSpend_(beast::kZERO) , seqProx_(SeqProxy::sequence(0)) , sequencesConsumed_(0) { @@ -265,8 +265,8 @@ TxConsequences::TxConsequences(NotTEC pfResult) TxConsequences::TxConsequences(STTx const& tx) : isBlocker_(false) - , fee_(tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() : beast::zero) - , potentialSpend_(beast::zero) + , fee_(tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() : beast::kZERO) + , potentialSpend_(beast::kZERO) , seqProx_(tx.getSeqProxy()) , sequencesConsumed_(tx.getSeqProxy().isSeq() ? 1 : 0) { @@ -274,7 +274,7 @@ TxConsequences::TxConsequences(STTx const& tx) TxConsequences::TxConsequences(STTx const& tx, Category category) : TxConsequences(tx) { - isBlocker_ = (category == Category::blocker); + isBlocker_ = (category == Category::Blocker); } TxConsequences::TxConsequences(STTx const& tx, XRPAmount potentialSpend) : TxConsequences(tx) @@ -288,11 +288,11 @@ TxConsequences::TxConsequences(STTx const& tx, std::uint32_t sequencesConsumed) } static ApplyResult -invoke_apply(ApplyContext& ctx) +invokeApply(ApplyContext& ctx) { try { - return with_txn_type(ctx.view().rules(), ctx.tx.getTxnType(), [&]() { + return withTxnType(ctx.view().rules(), ctx.tx.getTxnType(), [&]() { T p(ctx); return p(); }); @@ -303,7 +303,7 @@ invoke_apply(ApplyContext& ctx) // LCOV_EXCL_START JLOG(ctx.journal.fatal()) << "Unknown transaction type in apply: " << e.txnType; UNREACHABLE("xrpl::invoke_apply : unknown transaction type"); - return {temUNKNOWN, false}; + return {TemUnknown, false}; // LCOV_EXCL_STOP } } @@ -314,7 +314,7 @@ invoke_apply(ApplyContext& ctx) std::unique_ptr makeTransactor(ApplyContext& ctx) { - return with_txn_type( + return withTxnType( ctx.view().rules(), ctx.tx.getTxnType(), [&]() -> std::unique_ptr { return std::make_unique(ctx); }); @@ -331,12 +331,12 @@ preflight( PreflightContext const pfCtx(registry, tx, rules, flags, j); try { - return {pfCtx, invoke_preflight(pfCtx)}; + return {pfCtx, invokePreflight(pfCtx)}; } catch (std::exception const& e) { JLOG(j.fatal()) << "apply (preflight): " << e.what(); - return {pfCtx, {tefEXCEPTION, TxConsequences{tx}}}; + return {pfCtx, {TefException, TxConsequences{tx}}}; } } @@ -352,12 +352,12 @@ preflight( PreflightContext const pfCtx(registry, tx, parentBatchId, rules, flags, j); try { - return {pfCtx, invoke_preflight(pfCtx)}; + return {pfCtx, invokePreflight(pfCtx)}; } catch (std::exception const& e) { JLOG(j.fatal()) << "apply (preflight): " << e.what(); - return {pfCtx, {tefEXCEPTION, TxConsequences{tx}}}; + return {pfCtx, {TefException, TxConsequences{tx}}}; } } @@ -412,19 +412,19 @@ preclaim(PreflightResult const& preflightResult, ServiceRegistry& registry, Open { if (!isTesSuccess(ctx->preflightResult)) return {*ctx, ctx->preflightResult}; - return {*ctx, invoke_preclaim(*ctx)}; + return {*ctx, invokePreclaim(*ctx)}; } catch (std::exception const& e) { JLOG(ctx->j.fatal()) << "apply (preclaim): " << e.what(); - return {*ctx, tefEXCEPTION}; + return {*ctx, TefException}; } } XRPAmount calculateBaseFee(ReadView const& view, STTx const& tx) { - return invoke_calculateBaseFee(view, tx); + return invokeCalculateBaseFee(view, tx); } XRPAmount @@ -440,7 +440,7 @@ doApply(PreclaimResult const& preclaimResult, ServiceRegistry& registry, OpenVie { // Logic error from the caller. Don't have enough // info to recover. - return {tefEXCEPTION, false}; + return {TefException, false}; } try { @@ -455,12 +455,12 @@ doApply(PreclaimResult const& preclaimResult, ServiceRegistry& registry, OpenVie calculateBaseFee(view, preclaimResult.tx), preclaimResult.flags, preclaimResult.j); - return invoke_apply(ctx); + return invokeApply(ctx); } catch (std::exception const& e) { JLOG(preclaimResult.j.fatal()) << "apply: " << e.what(); - return {tefEXCEPTION, false}; + return {TefException, false}; } } diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index 0017c8f71d..5b60ea256b 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -73,7 +73,7 @@ namespace xrpl::test { struct AMM_test : public jtx::AMMTest { // Use small Number mantissas for the life of this test. - NumberMantissaScaleGuard const sg_{xrpl::MantissaRange::mantissa_scale::small}; + NumberMantissaScaleGuard const sg{xrpl::MantissaRange::MantissaScale::Small}; private: static FeatureBitset @@ -108,7 +108,7 @@ private: testAMM( [&](AMM& ammAlice, Env&) { BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000, 0})); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000, 0})); }, {}, 0, @@ -118,52 +118,52 @@ private: // IOU to IOU testAMM( [&](AMM& ammAlice, Env&) { - BEAST_EXPECT(ammAlice.expectBalances(USD(20'000), BTC(0.5), IOUAmount{100, 0})); + BEAST_EXPECT(ammAlice.expectBalances(USD_(20'000), BTC_(0.5), IOUAmount{100, 0})); }, - {{USD(20'000), BTC(0.5)}}); + {{USD_(20'000), BTC_(0.5)}}); // IOU to IOU + transfer fee { Env env{*this}; - fund(env, gw, {alice}, {USD(20'000), BTC(0.5)}, Fund::All); - env(rate(gw, 1.25)); + fund(env, gw_, {alice_}, {USD_(20'000), BTC_(0.5)}, Fund::All); + env(rate(gw_, 1.25)); env.close(); // no transfer fee on create - AMM const ammAlice(env, alice, USD(20'000), BTC(0.5)); - BEAST_EXPECT(ammAlice.expectBalances(USD(20'000), BTC(0.5), IOUAmount{100, 0})); - BEAST_EXPECT(expectHolding(env, alice, USD(0))); - BEAST_EXPECT(expectHolding(env, alice, BTC(0))); + AMM const ammAlice(env, alice_, USD_(20'000), BTC_(0.5)); + BEAST_EXPECT(ammAlice.expectBalances(USD_(20'000), BTC_(0.5), IOUAmount{100, 0})); + BEAST_EXPECT(expectHolding(env, alice_, USD_(0))); + BEAST_EXPECT(expectHolding(env, alice_, BTC_(0))); } // Require authorization is set, account is authorized { Env env{*this}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env(fset(gw, asfRequireAuth)); - env(trust(alice, gw["USD"](30'000), 0)); - env(trust(gw, alice["USD"](0), tfSetfAuth)); + env(fset(gw_, kASF_REQUIRE_AUTH)); + env(trust(alice_, gw_["USD"](30'000), 0)); + env(trust(gw_, alice_["USD"](0), kTF_SETF_AUTH)); env.close(); - env(pay(gw, alice, USD(10'000))); + env(pay(gw_, alice_, USD_(10'000))); env.close(); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'000)); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'000)); } // Cleared global freeze { Env env{*this}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env.trust(USD(30'000), alice); + env.trust(USD_(30'000), alice_); env.close(); - env(pay(gw, alice, USD(10'000))); + env(pay(gw_, alice_, USD_(10'000))); env.close(); - env(fset(gw, asfGlobalFreeze)); + env(fset(gw_, kASF_GLOBAL_FREEZE)); env.close(); - AMM const ammAliceFail(env, alice, XRP(10'000), USD(10'000), ter(tecFROZEN)); - env(fclear(gw, asfGlobalFreeze)); + AMM const ammAliceFail(env, alice_, kXRP(10'000), USD_(10'000), Ter(TecFrozen)); + env(fclear(gw_, kASF_GLOBAL_FREEZE)); env.close(); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'000)); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'000)); } // Trading fee @@ -177,11 +177,11 @@ private: // Make sure asset comparison works. BEAST_EXPECT( - STIssue(sfAsset, STAmount(XRP(2'000)).asset()) == - STIssue(sfAsset, STAmount(XRP(2'000)).asset())); + STIssue(sfAsset, STAmount(kXRP(2'000)).asset()) == + STIssue(sfAsset, STAmount(kXRP(2'000)).asset())); BEAST_EXPECT( - STIssue(sfAsset, STAmount(XRP(2'000)).asset()) != - STIssue(sfAsset, STAmount(USD(2'000)).asset())); + STIssue(sfAsset, STAmount(kXRP(2'000)).asset()) != + STIssue(sfAsset, STAmount(USD_(2'000)).asset())); } void @@ -194,97 +194,97 @@ private: // Can't have both XRP tokens { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, XRP(10'000), XRP(10'000), ter(temBAD_AMM_TOKENS)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, kXRP(10'000), kXRP(10'000), Ter(TemBadAmmTokens)); BEAST_EXPECT(!ammAlice.ammExists()); } // Can't have both tokens the same IOU { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, USD(10'000), USD(10'000), ter(temBAD_AMM_TOKENS)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, USD_(10'000), USD_(10'000), Ter(TemBadAmmTokens)); BEAST_EXPECT(!ammAlice.ammExists()); } // Can't have zero or negative amounts { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, XRP(0), USD(10'000), ter(temBAD_AMOUNT)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, kXRP(0), USD_(10'000), Ter(TemBadAmount)); BEAST_EXPECT(!ammAlice.ammExists()); - AMM const ammAlice1(env, alice, XRP(10'000), USD(0), ter(temBAD_AMOUNT)); + AMM const ammAlice1(env, alice_, kXRP(10'000), USD_(0), Ter(TemBadAmount)); BEAST_EXPECT(!ammAlice1.ammExists()); - AMM const ammAlice2(env, alice, XRP(10'000), USD(-10'000), ter(temBAD_AMOUNT)); + AMM const ammAlice2(env, alice_, kXRP(10'000), USD_(-10'000), Ter(TemBadAmount)); BEAST_EXPECT(!ammAlice2.ammExists()); - AMM const ammAlice3(env, alice, XRP(-10'000), USD(10'000), ter(temBAD_AMOUNT)); + AMM const ammAlice3(env, alice_, kXRP(-10'000), USD_(10'000), Ter(TemBadAmount)); BEAST_EXPECT(!ammAlice3.ammExists()); } // Bad currency { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, XRP(10'000), BAD(10'000), ter(temBAD_CURRENCY)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, kXRP(10'000), BAD_(10'000), Ter(TemBadCurrency)); BEAST_EXPECT(!ammAlice.ammExists()); } // Insufficient IOU balance { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, XRP(10'000), USD(40'000), ter(tecUNFUNDED_AMM)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(40'000), Ter(TecUnfundedAmm)); BEAST_EXPECT(!ammAlice.ammExists()); } // Insufficient XRP balance { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); - AMM const ammAlice(env, alice, XRP(40'000), USD(10'000), ter(tecUNFUNDED_AMM)); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); + AMM const ammAlice(env, alice_, kXRP(40'000), USD_(10'000), Ter(TecUnfundedAmm)); BEAST_EXPECT(!ammAlice.ammExists()); } // Invalid trading fee { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); AMM const ammAlice( env, - alice, - XRP(10'000), - USD(10'000), + alice_, + kXRP(10'000), + USD_(10'000), false, 65'001, 10, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_FEE)); + Ter(TemBadFee)); BEAST_EXPECT(!ammAlice.ammExists()); } // AMM already exists testAMM([&](AMM& ammAlice, Env& env) { - AMM const ammCarol(env, carol, XRP(10'000), USD(10'000), ter(tecDUPLICATE)); + AMM const ammCarol(env, carol_, kXRP(10'000), USD_(10'000), Ter(TecDuplicate)); }); // Invalid flags { Env env{*this}; - fund(env, gw, {alice}, {USD(30'000)}, Fund::All); + fund(env, gw_, {alice_}, {USD_(30'000)}, Fund::All); AMM const ammAlice( env, - alice, - XRP(10'000), - USD(10'000), + alice_, + kXRP(10'000), + USD_(10'000), false, 0, 10, - tfWithdrawAll, + kTF_WITHDRAW_ALL, std::nullopt, std::nullopt, - ter(temINVALID_FLAG)); + Ter(TemInvalidFlag)); BEAST_EXPECT(!ammAlice.ammExists()); } @@ -296,43 +296,43 @@ private: AMM const ammAlice( env, bad, - XRP(10'000), - USD(10'000), + kXRP(10'000), + USD_(10'000), false, 0, 10, std::nullopt, - seq(1), + Seq(1), std::nullopt, - ter(terNO_ACCOUNT)); + Ter(TerNoAccount)); BEAST_EXPECT(!ammAlice.ammExists()); } // Require authorization is set { Env env{*this}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env(fset(gw, asfRequireAuth)); + env(fset(gw_, kASF_REQUIRE_AUTH)); env.close(); - env(trust(gw, alice["USD"](30'000))); + env(trust(gw_, alice_["USD"](30'000))); env.close(); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'000), ter(tecNO_AUTH)); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'000), Ter(TecNoAuth)); BEAST_EXPECT(!ammAlice.ammExists()); } // Globally frozen { Env env{*this}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env(fset(gw, asfGlobalFreeze)); + env(fset(gw_, kASF_GLOBAL_FREEZE)); env.close(); - env(trust(gw, alice["USD"](30'000))); + env(trust(gw_, alice_["USD"](30'000))); env.close(); - for (auto const& account : {alice, gw}) + for (auto const& account : {alice_, gw_}) { - AMM const amm(env, account, XRP(10'000), USD(10'000), ter(tecFROZEN)); + AMM const amm(env, account, kXRP(10'000), USD_(10'000), Ter(TecFrozen)); BEAST_EXPECT(!amm.ammExists()); } } @@ -340,121 +340,121 @@ private: // Individually frozen { Env env{*this}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env(trust(gw, alice["USD"](30'000))); + env(trust(gw_, alice_["USD"](30'000))); env.close(); - env(trust(gw, alice["USD"](0), tfSetFreeze)); + env(trust(gw_, alice_["USD"](0), kTF_SET_FREEZE)); env.close(); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'000), ter(tecFROZEN)); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'000), Ter(TecFrozen)); BEAST_EXPECT(!ammAlice.ammExists()); // issuer can create - AMM const amm(env, gw, XRP(10'000), USD(10'000)); + AMM const amm(env, gw_, kXRP(10'000), USD_(10'000)); } // Insufficient reserve, XRP/IOU { Env env(*this); - auto const starting_xrp = XRP(1'000) + reserve(env, 3) + env.current()->fees().base * 4; - env.fund(starting_xrp, gw); - env.fund(starting_xrp, alice); - env.trust(USD(2'000), alice); + auto const startingXrp = kXRP(1'000) + reserve(env, 3) + env.current()->fees().base * 4; + env.fund(startingXrp, gw_); + env.fund(startingXrp, alice_); + env.trust(USD_(2'000), alice_); env.close(); - env(pay(gw, alice, USD(2'000))); + env(pay(gw_, alice_, USD_(2'000))); env.close(); - env(offer(alice, XRP(101), USD(100))); - env(offer(alice, XRP(102), USD(100))); - AMM const ammAlice(env, alice, XRP(1'000), USD(1'000), ter(tecUNFUNDED_AMM)); + env(offer(alice_, kXRP(101), USD_(100))); + env(offer(alice_, kXRP(102), USD_(100))); + AMM const ammAlice(env, alice_, kXRP(1'000), USD_(1'000), Ter(TecUnfundedAmm)); } // Insufficient reserve, IOU/IOU { Env env(*this); - auto const starting_xrp = reserve(env, 4) + env.current()->fees().base * 5; - env.fund(starting_xrp, gw); - env.fund(starting_xrp, alice); - env.trust(USD(2'000), alice); - env.trust(EUR(2'000), alice); + auto const startingXrp = reserve(env, 4) + env.current()->fees().base * 5; + env.fund(startingXrp, gw_); + env.fund(startingXrp, alice_); + env.trust(USD_(2'000), alice_); + env.trust(EUR_(2'000), alice_); env.close(); - env(pay(gw, alice, USD(2'000))); - env(pay(gw, alice, EUR(2'000))); + env(pay(gw_, alice_, USD_(2'000))); + env(pay(gw_, alice_, EUR_(2'000))); env.close(); - env(offer(alice, EUR(101), USD(100))); - env(offer(alice, EUR(102), USD(100))); - AMM const ammAlice(env, alice, EUR(1'000), USD(1'000), ter(tecINSUF_RESERVE_LINE)); + env(offer(alice_, EUR_(101), USD_(100))); + env(offer(alice_, EUR_(102), USD_(100))); + AMM const ammAlice(env, alice_, EUR_(1'000), USD_(1'000), Ter(TecInsufReserveLine)); } // Insufficient fee { Env env(*this); - fund(env, gw, {alice}, XRP(2'000), {USD(2'000), EUR(2'000)}); + fund(env, gw_, {alice_}, kXRP(2'000), {USD_(2'000), EUR_(2'000)}); AMM const ammAlice( env, - alice, - EUR(1'000), - USD(1'000), + alice_, + EUR_(1'000), + USD_(1'000), false, 0, ammCrtFee(env).drops() - 1, std::nullopt, std::nullopt, std::nullopt, - ter(telINSUF_FEE_P)); + Ter(TelInsufFeeP)); } // AMM with LPTokens // AMM with one LPToken from another AMM. testAMM([&](AMM& ammAlice, Env& env) { - fund(env, gw, {alice}, {EUR(10'000)}, Fund::TokenOnly); + fund(env, gw_, {alice_}, {EUR_(10'000)}, Fund::TokenOnly); AMM const ammAMMToken( env, - alice, - EUR(10'000), + alice_, + EUR_(10'000), STAmount{ammAlice.lptIssue(), 1'000'000}, - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); AMM const ammAMMToken1( env, - alice, + alice_, STAmount{ammAlice.lptIssue(), 1'000'000}, - EUR(10'000), - ter(tecAMM_INVALID_TOKENS)); + EUR_(10'000), + Ter(TecAmmInvalidTokens)); }); // AMM with two LPTokens from other AMMs. testAMM([&](AMM& ammAlice, Env& env) { - fund(env, gw, {alice}, {EUR(10'000)}, Fund::TokenOnly); - AMM const ammAlice1(env, alice, XRP(10'000), EUR(10'000)); + fund(env, gw_, {alice_}, {EUR_(10'000)}, Fund::TokenOnly); + AMM const ammAlice1(env, alice_, kXRP(10'000), EUR_(10'000)); auto const token1 = ammAlice.lptIssue(); auto const token2 = ammAlice1.lptIssue(); AMM const ammAMMTokens( env, - alice, + alice_, STAmount{token1, 1'000'000}, STAmount{token2, 1'000'000}, - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); }); // Issuer has DefaultRipple disabled { Env env(*this); - env.fund(XRP(30'000), gw); - env(fclear(gw, asfDefaultRipple)); - AMM const ammGw(env, gw, XRP(10'000), USD(10'000), ter(terNO_RIPPLE)); - env.fund(XRP(30'000), alice); - env.trust(USD(30'000), alice); - env(pay(gw, alice, USD(30'000))); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'000), ter(terNO_RIPPLE)); + env.fund(kXRP(30'000), gw_); + env(fclear(gw_, kASF_DEFAULT_RIPPLE)); + AMM const ammGw(env, gw_, kXRP(10'000), USD_(10'000), Ter(TerNoRipple)); + env.fund(kXRP(30'000), alice_); + env.trust(USD_(30'000), alice_); + env(pay(gw_, alice_, USD_(30'000))); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'000), Ter(TerNoRipple)); Account const gw1("gw1"); - env.fund(XRP(30'000), gw1); - env(fclear(gw1, asfDefaultRipple)); - env.trust(USD(30'000), gw1); - env(pay(gw, gw1, USD(30'000))); - auto const USD1 = gw1["USD"]; - AMM const ammGwGw1(env, gw, USD(10'000), USD1(10'000), ter(terNO_RIPPLE)); - env.trust(USD1(30'000), alice); - env(pay(gw1, alice, USD1(30'000))); - AMM const ammAlice1(env, alice, USD(10'000), USD1(10'000), ter(terNO_RIPPLE)); + env.fund(kXRP(30'000), gw1); + env(fclear(gw1, kASF_DEFAULT_RIPPLE)); + env.trust(USD_(30'000), gw1); + env(pay(gw_, gw1, USD_(30'000))); + auto const usD1 = gw1["USD"]; + AMM const ammGwGw1(env, gw_, USD_(10'000), usD1(10'000), Ter(TerNoRipple)); + env.trust(usD1(30'000), alice_); + env(pay(gw1, alice_, usD1(30'000))); + AMM const ammAlice1(env, alice_, USD_(10'000), usD1(10'000), Ter(TerNoRipple)); } } @@ -467,7 +467,8 @@ private: testAMM([&](AMM& ammAlice, Env& env) { // Invalid flags - ammAlice.deposit(alice, 1'000'000, std::nullopt, tfWithdrawAll, ter(temINVALID_FLAG)); + ammAlice.deposit( + alice_, 1'000'000, std::nullopt, kTF_WITHDRAW_ALL, Ter(TemInvalidFlag)); // Invalid options std::vector, std::optional>> const invalidOptions = { // flags, tokens, asset1In, asset2in, EPrice, tfee - {tfLPToken, 1'000, std::nullopt, USD(100), std::nullopt, std::nullopt}, - {tfLPToken, 1'000, XRP(100), std::nullopt, std::nullopt, std::nullopt}, - {tfLPToken, 1'000, std::nullopt, std::nullopt, STAmount{USD, 1, -1}, std::nullopt}, - {tfLPToken, + {kTF_LP_TOKEN, 1'000, std::nullopt, USD_(100), std::nullopt, std::nullopt}, + {kTF_LP_TOKEN, 1'000, kXRP(100), std::nullopt, std::nullopt, std::nullopt}, + {kTF_LP_TOKEN, + 1'000, std::nullopt, - USD(100), std::nullopt, - STAmount{USD, 1, -1}, + STAmount{USD_, 1, -1}, std::nullopt}, - {tfLPToken, 1'000, XRP(100), std::nullopt, STAmount{USD, 1, -1}, std::nullopt}, - {tfLPToken, 1'000, std::nullopt, std::nullopt, std::nullopt, 1'000}, - {tfSingleAsset, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, - {tfSingleAsset, std::nullopt, std::nullopt, USD(100), std::nullopt, std::nullopt}, - {tfSingleAsset, + {kTF_LP_TOKEN, std::nullopt, + USD_(100), std::nullopt, - std::nullopt, - STAmount{USD, 1, -1}, + STAmount{USD_, 1, -1}, std::nullopt}, - {tfSingleAsset, std::nullopt, USD(100), std::nullopt, std::nullopt, 1'000}, - {tfTwoAsset, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, - {tfTwoAsset, std::nullopt, XRP(100), USD(100), STAmount{USD, 1, -1}, std::nullopt}, - {tfTwoAsset, std::nullopt, XRP(100), std::nullopt, std::nullopt, std::nullopt}, - {tfTwoAsset, std::nullopt, XRP(100), USD(100), std::nullopt, 1'000}, - {tfTwoAsset, + {kTF_LP_TOKEN, 1'000, kXRP(100), std::nullopt, STAmount{USD_, 1, -1}, std::nullopt}, + {kTF_LP_TOKEN, 1'000, std::nullopt, std::nullopt, std::nullopt, 1'000}, + {kTF_SINGLE_ASSET, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, + {kTF_SINGLE_ASSET, std::nullopt, std::nullopt, - USD(100), - STAmount{USD, 1, -1}, + USD_(100), + std::nullopt, std::nullopt}, - {tfOneAssetLPToken, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, - {tfOneAssetLPToken, std::nullopt, XRP(100), USD(100), std::nullopt, std::nullopt}, - {tfOneAssetLPToken, + {kTF_SINGLE_ASSET, std::nullopt, - XRP(100), std::nullopt, - STAmount{USD, 1, -1}, + std::nullopt, + STAmount{USD_, 1, -1}, std::nullopt}, - {tfOneAssetLPToken, 1'000, XRP(100), std::nullopt, std::nullopt, 1'000}, - {tfLimitLPToken, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, - {tfLimitLPToken, 1'000, USD(100), std::nullopt, std::nullopt, std::nullopt}, - {tfLimitLPToken, std::nullopt, USD(100), XRP(100), std::nullopt, std::nullopt}, - {tfLimitLPToken, std::nullopt, XRP(100), std::nullopt, STAmount{USD, 1, -1}, 1'000}, - {tfTwoAssetIfEmpty, std::nullopt, std::nullopt, std::nullopt, std::nullopt, 1'000}, - {tfTwoAssetIfEmpty, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, - {tfTwoAssetIfEmpty, + {kTF_SINGLE_ASSET, std::nullopt, USD_(100), std::nullopt, std::nullopt, 1'000}, + {kTF_TWO_ASSET, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, + {kTF_TWO_ASSET, std::nullopt, - XRP(100), - USD(100), - STAmount{USD, 1, -1}, + kXRP(100), + USD_(100), + STAmount{USD_, 1, -1}, std::nullopt}, - {tfTwoAssetIfEmpty | tfLPToken, + {kTF_TWO_ASSET, std::nullopt, kXRP(100), std::nullopt, std::nullopt, std::nullopt}, + {kTF_TWO_ASSET, std::nullopt, kXRP(100), USD_(100), std::nullopt, 1'000}, + {kTF_TWO_ASSET, std::nullopt, - XRP(100), - USD(100), - STAmount{USD, 1, -1}, + std::nullopt, + USD_(100), + STAmount{USD_, 1, -1}, + std::nullopt}, + {kTF_ONE_ASSET_LP_TOKEN, + 1'000, + std::nullopt, + std::nullopt, + std::nullopt, + std::nullopt}, + {kTF_ONE_ASSET_LP_TOKEN, + std::nullopt, + kXRP(100), + USD_(100), + std::nullopt, + std::nullopt}, + {kTF_ONE_ASSET_LP_TOKEN, + std::nullopt, + kXRP(100), + std::nullopt, + STAmount{USD_, 1, -1}, + std::nullopt}, + {kTF_ONE_ASSET_LP_TOKEN, 1'000, kXRP(100), std::nullopt, std::nullopt, 1'000}, + {kTF_LIMIT_LP_TOKEN, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt}, + {kTF_LIMIT_LP_TOKEN, 1'000, USD_(100), std::nullopt, std::nullopt, std::nullopt}, + {kTF_LIMIT_LP_TOKEN, + std::nullopt, + USD_(100), + kXRP(100), + std::nullopt, + std::nullopt}, + {kTF_LIMIT_LP_TOKEN, + std::nullopt, + kXRP(100), + std::nullopt, + STAmount{USD_, 1, -1}, + 1'000}, + {kTF_TWO_ASSET_IF_EMPTY, + std::nullopt, + std::nullopt, + std::nullopt, + std::nullopt, + 1'000}, + {kTF_TWO_ASSET_IF_EMPTY, + 1'000, + std::nullopt, + std::nullopt, + std::nullopt, + std::nullopt}, + {kTF_TWO_ASSET_IF_EMPTY, + std::nullopt, + kXRP(100), + USD_(100), + STAmount{USD_, 1, -1}, + std::nullopt}, + {kTF_TWO_ASSET_IF_EMPTY | kTF_LP_TOKEN, + std::nullopt, + kXRP(100), + USD_(100), + STAmount{USD_, 1, -1}, std::nullopt}}; for (auto const& it : invalidOptions) { ammAlice.deposit( - alice, + alice_, std::get<1>(it), std::get<2>(it), std::get<3>(it), @@ -547,55 +593,55 @@ private: std::nullopt, std::nullopt, std::get<5>(it), - ter(temMALFORMED)); + Ter(TemMalformed)); } { // bad preflight1 - Json::Value jv = Json::objectValue; - jv[jss::Account] = alice.human(); - jv[jss::TransactionType] = jss::AMMDeposit; - jv[jss::Asset] = STIssue(sfAsset, XRP).getJson(JsonOptions::none); - jv[jss::Asset2] = STIssue(sfAsset, USD).getJson(JsonOptions::none); - jv[jss::Fee] = "-1"; - env(jv, ter(temBAD_FEE)); + Json::Value jv = Json::ObjectValue; + jv[jss::kACCOUNT] = alice_.human(); + jv[jss::kTRANSACTION_TYPE] = jss::AMMDeposit; + jv[jss::kASSET] = STIssue(sfAsset, kXRP).getJson(JsonOptions::None); + jv[jss::kASSET2] = STIssue(sfAsset, USD_).getJson(JsonOptions::None); + jv[jss::kFEE] = "-1"; + env(jv, Ter(TemBadFee)); } // Invalid tokens - ammAlice.deposit(alice, 0, std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + ammAlice.deposit(alice_, 0, std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); ammAlice.deposit( - alice, IOUAmount{-1}, std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + alice_, IOUAmount{-1}, std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); { - Json::Value jv = Json::objectValue; - jv[jss::Account] = alice.human(); - jv[jss::TransactionType] = jss::AMMDeposit; - jv[jss::Asset] = STIssue(sfAsset, XRP).getJson(JsonOptions::none); - jv[jss::Asset2] = STIssue(sfAsset, USD).getJson(JsonOptions::none); - jv[jss::LPTokenOut] = USD(100).value().getJson(JsonOptions::none); - jv[jss::Flags] = tfLPToken; - env(jv, ter(temBAD_AMM_TOKENS)); + Json::Value jv = Json::ObjectValue; + jv[jss::kACCOUNT] = alice_.human(); + jv[jss::kTRANSACTION_TYPE] = jss::AMMDeposit; + jv[jss::kASSET] = STIssue(sfAsset, kXRP).getJson(JsonOptions::None); + jv[jss::kASSET2] = STIssue(sfAsset, USD_).getJson(JsonOptions::None); + jv[jss::kLP_TOKEN_OUT] = USD_(100).value().getJson(JsonOptions::None); + jv[jss::kFLAGS] = kTF_LP_TOKEN; + env(jv, Ter(TemBadAmmTokens)); } // Invalid trading fee ammAlice.deposit( - carol, + carol_, std::nullopt, - XRP(200), - USD(200), + kXRP(200), + USD_(200), std::nullopt, - tfTwoAssetIfEmpty, + kTF_TWO_ASSET_IF_EMPTY, std::nullopt, std::nullopt, 10'000, - ter(temBAD_FEE)); + Ter(TemBadFee)); // Invalid tokens - bogus currency { - auto const iss1 = Issue{Currency(0xabc), gw.id()}; - auto const iss2 = Issue{Currency(0xdef), gw.id()}; + auto const iss1 = Issue{Currency(0xabc), gw_.id()}; + auto const iss2 = Issue{Currency(0xdef), gw_.id()}; ammAlice.deposit( - alice, + alice_, 1'000, std::nullopt, std::nullopt, @@ -604,32 +650,32 @@ private: {{iss1, iss2}}, std::nullopt, std::nullopt, - ter(terNO_AMM)); + Ter(TerNoAmm)); } // Depositing mismatched token, invalid Asset1In.issue ammAlice.deposit( - alice, GBP(100), std::nullopt, std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + alice_, GBP_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); // Depositing mismatched token, invalid Asset2In.issue ammAlice.deposit( - alice, USD(100), GBP(100), std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + alice_, USD_(100), GBP_(100), std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); // Depositing mismatched token, Asset1In.issue == Asset2In.issue ammAlice.deposit( - alice, USD(100), USD(100), std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + alice_, USD_(100), USD_(100), std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); // Invalid amount value ammAlice.deposit( - alice, USD(0), std::nullopt, std::nullopt, std::nullopt, ter(temBAD_AMOUNT)); + alice_, USD_(0), std::nullopt, std::nullopt, std::nullopt, Ter(TemBadAmount)); ammAlice.deposit( - alice, USD(-1'000), std::nullopt, std::nullopt, std::nullopt, ter(temBAD_AMOUNT)); + alice_, USD_(-1'000), std::nullopt, std::nullopt, std::nullopt, Ter(TemBadAmount)); ammAlice.deposit( - alice, USD(10), std::nullopt, USD(-1), std::nullopt, ter(temBAD_AMOUNT)); + alice_, USD_(10), std::nullopt, USD_(-1), std::nullopt, Ter(TemBadAmount)); // Bad currency ammAlice.deposit( - alice, BAD(100), std::nullopt, std::nullopt, std::nullopt, ter(temBAD_CURRENCY)); + alice_, BAD_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TemBadCurrency)); // Invalid Account Account const bad("bad"); @@ -642,93 +688,98 @@ private: std::nullopt, std::nullopt, std::nullopt, - seq(1), + Seq(1), std::nullopt, - ter(terNO_ACCOUNT)); + Ter(TerNoAccount)); // Invalid AMM ammAlice.deposit( - alice, + alice_, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - {{USD, GBP}}, + {{USD_, GBP_}}, std::nullopt, std::nullopt, - ter(terNO_AMM)); + Ter(TerNoAmm)); // Single deposit: 100000 tokens worth of USD // Amount to deposit exceeds Max ammAlice.deposit( - carol, + carol_, 100'000, - USD(200), + USD_(200), std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Single deposit: 100000 tokens worth of XRP // Amount to deposit exceeds Max ammAlice.deposit( - carol, + carol_, 100'000, - XRP(200), + kXRP(200), std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Deposit amount is invalid // Calculated amount to deposit is 98,000,000 ammAlice.deposit( - alice, - USD(0), + alice_, + USD_(0), std::nullopt, - STAmount{USD, 1, -1}, + STAmount{USD_, 1, -1}, std::nullopt, - ter(tecUNFUNDED_AMM)); + Ter(TecUnfundedAmm)); // Calculated amount is 0 ammAlice.deposit( - alice, - USD(0), + alice_, + USD_(0), std::nullopt, - STAmount{USD, 2'000, -6}, + STAmount{USD_, 2'000, -6}, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Deposit non-empty AMM ammAlice.deposit( - carol, XRP(100), USD(100), std::nullopt, tfTwoAssetIfEmpty, ter(tecAMM_NOT_EMPTY)); + carol_, + kXRP(100), + USD_(100), + std::nullopt, + kTF_TWO_ASSET_IF_EMPTY, + Ter(TecAmmNotEmpty)); }); // Tiny deposit testAMM( [&](AMM& ammAlice, Env& env) { - auto const enabledV1_3 = env.current()->rules().enabled(fixAMMv1_3); - auto const err = !enabledV1_3 ? ter(temBAD_AMOUNT) : ter(tesSUCCESS); + auto const enabledV13 = env.current()->rules().enabled(fixAMMv1_3); + auto const err = !enabledV13 ? Ter(TemBadAmount) : Ter(TesSuccess); // Pre-amendment XRP deposit side is rounded to 0 // and deposit fails. // Post-amendment XRP deposit side is rounded to 1 // and deposit succeeds. - ammAlice.deposit(carol, IOUAmount{1, -4}, std::nullopt, std::nullopt, err); + ammAlice.deposit(carol_, IOUAmount{1, -4}, std::nullopt, std::nullopt, err); // Pre/post-amendment LPTokens is rounded to 0 and deposit // fails with tecAMM_INVALID_TOKENS. ammAlice.deposit( - carol, - STAmount{USD, 1, -12}, + carol_, + STAmount{USD_, 1, -12}, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); }, std::nullopt, 0, @@ -737,20 +788,20 @@ private: // Invalid AMM testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.withdrawAll(alice); - ammAlice.deposit(alice, 10'000, std::nullopt, std::nullopt, ter(terNO_AMM)); + ammAlice.withdrawAll(alice_); + ammAlice.deposit(alice_, 10'000, std::nullopt, std::nullopt, Ter(TerNoAmm)); }); // Globally frozen asset testAMM( [&](AMM& ammAlice, Env& env) { - env(fset(gw, asfGlobalFreeze)); + env(fset(gw_, kASF_GLOBAL_FREEZE)); if (!features[featureAMMClawback]) { // If the issuer set global freeze, the holder still can // deposit the other non-frozen token when AMMClawback is // not enabled. - ammAlice.deposit(carol, XRP(100)); + ammAlice.deposit(carol_, kXRP(100)); } else { @@ -758,21 +809,26 @@ private: // deposit the other non-frozen token when AMMClawback is // enabled. ammAlice.deposit( - carol, XRP(100), std::nullopt, std::nullopt, std::nullopt, ter(tecFROZEN)); + carol_, + kXRP(100), + std::nullopt, + std::nullopt, + std::nullopt, + Ter(TecFrozen)); } - for (auto const& account : {carol, gw}) + for (auto const& account : {carol_, gw_}) { ammAlice.deposit( account, - USD(100), + USD_(100), std::nullopt, std::nullopt, std::nullopt, - ter(tecFROZEN)); + Ter(TecFrozen)); ammAlice.deposit( - account, 1'000'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + account, 1'000'000, std::nullopt, std::nullopt, Ter(TecFrozen)); ammAlice.deposit( - account, XRP(100), USD(100), std::nullopt, std::nullopt, ter(tecFROZEN)); + account, kXRP(100), USD_(100), std::nullopt, std::nullopt, Ter(TecFrozen)); } }, std::nullopt, @@ -783,37 +839,42 @@ private: // Individually frozen (AMM) account testAMM( [&](AMM& ammAlice, Env& env) { - env(trust(gw, carol["USD"](0), tfSetFreeze)); + env(trust(gw_, carol_["USD"](0), kTF_SET_FREEZE)); env.close(); if (!features[featureAMMClawback]) { // Can deposit non-frozen token if AMMClawback is not // enabled - ammAlice.deposit(carol, XRP(100)); + ammAlice.deposit(carol_, kXRP(100)); } else { // Cannot deposit non-frozen token if the other token is // frozen when AMMClawback is enabled ammAlice.deposit( - carol, XRP(100), std::nullopt, std::nullopt, std::nullopt, ter(tecFROZEN)); + carol_, + kXRP(100), + std::nullopt, + std::nullopt, + std::nullopt, + Ter(TecFrozen)); } - ammAlice.deposit(carol, 1'000'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.deposit(carol_, 1'000'000, std::nullopt, std::nullopt, Ter(TecFrozen)); ammAlice.deposit( - carol, USD(100), std::nullopt, std::nullopt, std::nullopt, ter(tecFROZEN)); - env(trust(gw, carol["USD"](0), tfClearFreeze)); + carol_, USD_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TecFrozen)); + env(trust(gw_, carol_["USD"](0), kTF_CLEAR_FREEZE)); // Individually frozen AMM env(trust( - gw, - STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, - tfSetFreeze)); + gw_, + STAmount{Issue{gw_["USD"].currency, ammAlice.ammAccount()}, 0}, + kTF_SET_FREEZE)); env.close(); // Can deposit non-frozen token - ammAlice.deposit(carol, XRP(100)); - ammAlice.deposit(carol, 1'000'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.deposit(carol_, kXRP(100)); + ammAlice.deposit(carol_, 1'000'000, std::nullopt, std::nullopt, Ter(TecFrozen)); ammAlice.deposit( - carol, USD(100), std::nullopt, std::nullopt, std::nullopt, ter(tecFROZEN)); + carol_, USD_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TecFrozen)); }, std::nullopt, 0, @@ -823,41 +884,41 @@ private: // Individually frozen (AMM) account with IOU/IOU AMM testAMM( [&](AMM& ammAlice, Env& env) { - env(trust(gw, carol["USD"](0), tfSetFreeze)); - env(trust(gw, carol["BTC"](0), tfSetFreeze)); + env(trust(gw_, carol_["USD"](0), kTF_SET_FREEZE)); + env(trust(gw_, carol_["BTC"](0), kTF_SET_FREEZE)); env.close(); - ammAlice.deposit(carol, 1'000'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.deposit(carol_, 1'000'000, std::nullopt, std::nullopt, Ter(TecFrozen)); ammAlice.deposit( - carol, USD(100), std::nullopt, std::nullopt, std::nullopt, ter(tecFROZEN)); - env(trust(gw, carol["USD"](0), tfClearFreeze)); + carol_, USD_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TecFrozen)); + env(trust(gw_, carol_["USD"](0), kTF_CLEAR_FREEZE)); // Individually frozen AMM env(trust( - gw, - STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, - tfSetFreeze)); + gw_, + STAmount{Issue{gw_["USD"].currency, ammAlice.ammAccount()}, 0}, + kTF_SET_FREEZE)); env.close(); // Cannot deposit non-frozen token - ammAlice.deposit(carol, 1'000'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.deposit(carol_, 1'000'000, std::nullopt, std::nullopt, Ter(TecFrozen)); ammAlice.deposit( - carol, USD(100), BTC(0.01), std::nullopt, std::nullopt, ter(tecFROZEN)); + carol_, USD_(100), BTC_(0.01), std::nullopt, std::nullopt, Ter(TecFrozen)); }, - {{USD(20'000), BTC(0.5)}}); + {{USD_(20'000), BTC_(0.5)}}); // Deposit unauthorized token. { Env env(*this, features); - env.fund(XRP(1000), gw, alice, bob); - env(fset(gw, asfRequireAuth)); + env.fund(kXRP(1000), gw_, alice_, bob_); + env(fset(gw_, kASF_REQUIRE_AUTH)); env.close(); - env(trust(gw, alice["USD"](100)), txflags(tfSetfAuth)); - env(trust(alice, gw["USD"](20))); + env(trust(gw_, alice_["USD"](100)), Txflags(kTF_SETF_AUTH)); + env(trust(alice_, gw_["USD"](20))); env.close(); - env(pay(gw, alice, gw["USD"](10))); + env(pay(gw_, alice_, gw_["USD"](10))); env.close(); - env(trust(gw, bob["USD"](100))); + env(trust(gw_, bob_["USD"](100))); env.close(); - AMM amm(env, alice, XRP(10), gw["USD"](10), ter(tesSUCCESS)); + AMM amm(env, alice_, kXRP(10), gw_["USD"](10), Ter(TesSuccess)); env.close(); if (features[featureAMMClawback]) @@ -866,39 +927,39 @@ private: // because he's not authorized to hold the paired token // gw["USD"]. amm.deposit( - bob, XRP(10), std::nullopt, std::nullopt, std::nullopt, ter(tecNO_AUTH)); + bob_, kXRP(10), std::nullopt, std::nullopt, std::nullopt, Ter(TecNoAuth)); } else { amm.deposit( - bob, XRP(10), std::nullopt, std::nullopt, std::nullopt, ter(tesSUCCESS)); + bob_, kXRP(10), std::nullopt, std::nullopt, std::nullopt, Ter(TesSuccess)); } } // Insufficient XRP balance testAMM([&](AMM& ammAlice, Env& env) { - env.fund(XRP(1'000), bob); + env.fund(kXRP(1'000), bob_); env.close(); // Adds LPT trustline - ammAlice.deposit(bob, XRP(10)); + ammAlice.deposit(bob_, kXRP(10)); ammAlice.deposit( - bob, XRP(1'000), std::nullopt, std::nullopt, std::nullopt, ter(tecUNFUNDED_AMM)); + bob_, kXRP(1'000), std::nullopt, std::nullopt, std::nullopt, Ter(TecUnfundedAmm)); }); // Insufficient USD balance testAMM([&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, {USD(1'000)}, Fund::Acct); + fund(env, gw_, {bob_}, {USD_(1'000)}, Fund::Acct); env.close(); ammAlice.deposit( - bob, USD(1'001), std::nullopt, std::nullopt, std::nullopt, ter(tecUNFUNDED_AMM)); + bob_, USD_(1'001), std::nullopt, std::nullopt, std::nullopt, Ter(TecUnfundedAmm)); }); // Insufficient USD balance by tokens testAMM([&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, {USD(1'000)}, Fund::Acct); + fund(env, gw_, {bob_}, {USD_(1'000)}, Fund::Acct); env.close(); ammAlice.deposit( - bob, + bob_, 10'000'000, std::nullopt, std::nullopt, @@ -907,18 +968,18 @@ private: std::nullopt, std::nullopt, std::nullopt, - ter(tecUNFUNDED_AMM)); + Ter(TecUnfundedAmm)); }); // Insufficient XRP balance by tokens testAMM([&](AMM& ammAlice, Env& env) { - env.fund(XRP(1'000), bob); - env.trust(USD(100'000), bob); + env.fund(kXRP(1'000), bob_); + env.trust(USD_(100'000), bob_); env.close(); - env(pay(gw, bob, USD(90'000))); + env(pay(gw_, bob_, USD_(90'000))); env.close(); ammAlice.deposit( - bob, + bob_, 10'000'000, std::nullopt, std::nullopt, @@ -927,202 +988,202 @@ private: std::nullopt, std::nullopt, std::nullopt, - ter(tecUNFUNDED_AMM)); + Ter(TecUnfundedAmm)); }); // Insufficient reserve, XRP/IOU { Env env(*this); - auto const starting_xrp = reserve(env, 4) + env.current()->fees().base * 4; - env.fund(XRP(10'000), gw); - env.fund(XRP(10'000), alice); - env.fund(starting_xrp, carol); - env.trust(USD(2'000), alice); - env.trust(USD(2'000), carol); + auto const startingXrp = reserve(env, 4) + env.current()->fees().base * 4; + env.fund(kXRP(10'000), gw_); + env.fund(kXRP(10'000), alice_); + env.fund(startingXrp, carol_); + env.trust(USD_(2'000), alice_); + env.trust(USD_(2'000), carol_); env.close(); - env(pay(gw, alice, USD(2'000))); - env(pay(gw, carol, USD(2'000))); + env(pay(gw_, alice_, USD_(2'000))); + env(pay(gw_, carol_, USD_(2'000))); env.close(); - env(offer(carol, XRP(100), USD(101))); - env(offer(carol, XRP(100), USD(102))); - AMM ammAlice(env, alice, XRP(1'000), USD(1'000)); + env(offer(carol_, kXRP(100), USD_(101))); + env(offer(carol_, kXRP(100), USD_(102))); + AMM ammAlice(env, alice_, kXRP(1'000), USD_(1'000)); ammAlice.deposit( - carol, - XRP(100), + carol_, + kXRP(100), std::nullopt, std::nullopt, std::nullopt, - ter(tecINSUF_RESERVE_LINE)); + Ter(TecInsufReserveLine)); - env(offer(carol, XRP(100), USD(103))); + env(offer(carol_, kXRP(100), USD_(103))); ammAlice.deposit( - carol, - USD(100), + carol_, + USD_(100), std::nullopt, std::nullopt, std::nullopt, - ter(tecINSUF_RESERVE_LINE)); + Ter(TecInsufReserveLine)); } // Insufficient reserve, IOU/IOU { Env env(*this); - auto const starting_xrp = reserve(env, 4) + env.current()->fees().base * 4; - env.fund(XRP(10'000), gw); - env.fund(XRP(10'000), alice); - env.fund(starting_xrp, carol); - env.trust(USD(2'000), alice); - env.trust(EUR(2'000), alice); - env.trust(USD(2'000), carol); - env.trust(EUR(2'000), carol); + auto const startingXrp = reserve(env, 4) + env.current()->fees().base * 4; + env.fund(kXRP(10'000), gw_); + env.fund(kXRP(10'000), alice_); + env.fund(startingXrp, carol_); + env.trust(USD_(2'000), alice_); + env.trust(EUR_(2'000), alice_); + env.trust(USD_(2'000), carol_); + env.trust(EUR_(2'000), carol_); env.close(); - env(pay(gw, alice, USD(2'000))); - env(pay(gw, alice, EUR(2'000))); - env(pay(gw, carol, USD(2'000))); - env(pay(gw, carol, EUR(2'000))); + env(pay(gw_, alice_, USD_(2'000))); + env(pay(gw_, alice_, EUR_(2'000))); + env(pay(gw_, carol_, USD_(2'000))); + env(pay(gw_, carol_, EUR_(2'000))); env.close(); - env(offer(carol, XRP(100), USD(101))); - env(offer(carol, XRP(100), USD(102))); - AMM ammAlice(env, alice, XRP(1'000), USD(1'000)); + env(offer(carol_, kXRP(100), USD_(101))); + env(offer(carol_, kXRP(100), USD_(102))); + AMM ammAlice(env, alice_, kXRP(1'000), USD_(1'000)); ammAlice.deposit( - carol, - XRP(100), + carol_, + kXRP(100), std::nullopt, std::nullopt, std::nullopt, - ter(tecINSUF_RESERVE_LINE)); + Ter(TecInsufReserveLine)); } // Invalid min testAMM([&](AMM& ammAlice, Env& env) { // min tokens can't be <= zero - ammAlice.deposit(carol, 0, XRP(100), tfSingleAsset, ter(temBAD_AMM_TOKENS)); - ammAlice.deposit(carol, -1, XRP(100), tfSingleAsset, ter(temBAD_AMM_TOKENS)); + ammAlice.deposit(carol_, 0, kXRP(100), kTF_SINGLE_ASSET, Ter(TemBadAmmTokens)); + ammAlice.deposit(carol_, -1, kXRP(100), kTF_SINGLE_ASSET, Ter(TemBadAmmTokens)); ammAlice.deposit( - carol, + carol_, 0, - XRP(100), - USD(100), + kXRP(100), + USD_(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_AMM_TOKENS)); + Ter(TemBadAmmTokens)); // min amounts can't be <= zero ammAlice.deposit( - carol, + carol_, 1'000, - XRP(0), - USD(100), + kXRP(0), + USD_(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_AMOUNT)); + Ter(TemBadAmount)); ammAlice.deposit( - carol, + carol_, 1'000, - XRP(100), - USD(-1), + kXRP(100), + USD_(-1), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_AMOUNT)); + Ter(TemBadAmount)); // min amount bad currency ammAlice.deposit( - carol, + carol_, 1'000, - XRP(100), - BAD(100), + kXRP(100), + BAD_(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_CURRENCY)); + Ter(TemBadCurrency)); // min amount bad token pair ammAlice.deposit( - carol, + carol_, 1'000, - XRP(100), - XRP(100), + kXRP(100), + kXRP(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_AMM_TOKENS)); + Ter(TemBadAmmTokens)); ammAlice.deposit( - carol, + carol_, 1'000, - XRP(100), - GBP(100), + kXRP(100), + GBP_(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(temBAD_AMM_TOKENS)); + Ter(TemBadAmmTokens)); }); // Min deposit testAMM([&](AMM& ammAlice, Env& env) { // Equal deposit by tokens ammAlice.deposit( - carol, + carol_, 1'000'000, - XRP(1'000), - USD(1'001), + kXRP(1'000), + USD_(1'001), std::nullopt, - tfLPToken, + kTF_LP_TOKEN, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); ammAlice.deposit( - carol, + carol_, 1'000'000, - XRP(1'001), - USD(1'000), + kXRP(1'001), + USD_(1'000), std::nullopt, - tfLPToken, + kTF_LP_TOKEN, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Equal deposit by asset ammAlice.deposit( - carol, + carol_, 100'001, - XRP(100), - USD(100), + kXRP(100), + USD_(100), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Single deposit by asset ammAlice.deposit( - carol, + carol_, 488'090, - XRP(1'000), + kXRP(1'000), std::nullopt, std::nullopt, - tfSingleAsset, + kTF_SINGLE_ASSET, std::nullopt, std::nullopt, std::nullopt, - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); }); // Equal deposit, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { - amm.deposit(DepositArg{.tokens = IOUAmount{1, -12}, .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{.tokens = IOUAmount{1, -12}, .err = Ter(TecAmmInvalidTokens)}); }); // Equal deposit limit, tokens rounded to 0 @@ -1130,23 +1191,23 @@ private: [&](AMM& amm, Env& env) { amm.deposit( DepositArg{ - .asset1In = STAmount{USD, 1, -15}, + .asset1In = STAmount{USD_, 1, -15}, .asset2In = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .err = Ter(TecAmmInvalidTokens)}); }, - {.pool = {{USD(1'000'000), XRP(1'000'000)}}, .features = {features - fixAMMv1_3}}); + {.pool = {{USD_(1'000'000), kXRP(1'000'000)}}, .features = {features - fixAMMv1_3}}); testAMM([&](AMM& amm, Env& env) { amm.deposit( DepositArg{ - .asset1In = STAmount{USD, 1, -15}, + .asset1In = STAmount{USD_, 1, -15}, .asset2In = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .err = Ter(TecAmmInvalidTokens)}); }); // Single deposit by asset, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { amm.deposit( - DepositArg{.asset1In = STAmount{USD, 1, -15}, .err = ter(tecAMM_INVALID_TOKENS)}); + DepositArg{.asset1In = STAmount{USD_, 1, -15}, .err = Ter(TecAmmInvalidTokens)}); }); // Single deposit by tokens, tokens rounded to 0 @@ -1154,17 +1215,17 @@ private: amm.deposit( DepositArg{ .tokens = IOUAmount{1, -10}, - .asset1In = STAmount{USD, 1, -15}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .asset1In = STAmount{USD_, 1, -15}, + .err = Ter(TecAmmInvalidTokens)}); }); // Single deposit with EPrice, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { amm.deposit( DepositArg{ - .asset1In = STAmount{USD, 1, -15}, - .maxEP = STAmount{USD, 1, -1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .asset1In = STAmount{USD_, 1, -15}, + .maxEP = STAmount{USD_, 1, -1}, + .err = Ter(TecAmmInvalidTokens)}); }); } @@ -1179,13 +1240,13 @@ private: // Equal deposit: 1000000 tokens, 10% of the current pool testAMM([&](AMM& ammAlice, Env& env) { auto const baseFee = env.current()->fees().base; - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); // 30,000 less deposited 1,000 - BEAST_EXPECT(expectHolding(env, carol, USD(29'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(29'000))); // 30,000 less deposited 1,000 and 10 drops tx fee - BEAST_EXPECT(expectLedgerEntryRoot(env, carol, XRPAmount{29'000'000'000 - baseFee})); + BEAST_EXPECT(expectLedgerEntryRoot(env, carol_, XRPAmount{29'000'000'000 - baseFee})); }); // equal asset deposit: unit test to exercise the rounding-down of @@ -1200,7 +1261,7 @@ private: IOUAmount const newLPTokens{deltaLPTokens}; // carol performs a two-asset deposit - ammAlice.deposit(DepositArg{.account = carol, .tokens = newLPTokens}); + ammAlice.deposit(DepositArg{.account = carol_, .tokens = newLPTokens}); IOUAmount const finalLPToken = ammAlice.getLPTokensBalance(); @@ -1221,21 +1282,21 @@ private: Number const deltaXRP = fr * 1e10; Number const deltaUSD = fr * 1e4; - STAmount const depositUSD = STAmount{USD, deltaUSD}; + STAmount const depositUSD = STAmount{USD_, deltaUSD}; - STAmount const depositXRP = STAmount{XRP, deltaXRP}; + STAmount const depositXRP = STAmount{kXRP, deltaXRP}; // initial LPTokens (1e7) + newLPTokens BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000) + depositXRP, - USD(10'000) + depositUSD, + kXRP(10'000) + depositXRP, + USD_(10'000) + depositUSD, IOUAmount{1, 7} + newLPTokens)); // 30,000 less deposited depositUSD - BEAST_EXPECT(expectHolding(env, carol, USD(30'000) - depositUSD)); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000) - depositUSD)); // 30,000 less deposited depositXRP and 10 drops tx fee BEAST_EXPECT( - expectLedgerEntryRoot(env, carol, XRP(30'000) - depositXRP - txfee(env, 1))); + expectLedgerEntryRoot(env, carol_, kXRP(30'000) - depositXRP - txfee(env, 1))); }); } @@ -1245,147 +1306,148 @@ private: // to the pool composition not to exceed 100USD. Fail if exceeded. // Deposit 100USD/100XRP testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(100), XRP(100)); + ammAlice.deposit(carol_, USD_(100), kXRP(100)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'100), USD(10'100), IOUAmount{10'100'000, 0})); + ammAlice.expectBalances(kXRP(10'100), USD_(10'100), IOUAmount{10'100'000, 0})); }); // Equal limit deposit. // Try to deposit 200USD/100XRP. Is truncated to 100USD/100XRP. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(200), XRP(100)); + ammAlice.deposit(carol_, USD_(200), kXRP(100)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'100), USD(10'100), IOUAmount{10'100'000, 0})); + ammAlice.expectBalances(kXRP(10'100), USD_(10'100), IOUAmount{10'100'000, 0})); }); // Try to deposit 100USD/200XRP. Is truncated to 100USD/100XRP. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(100), XRP(200)); + ammAlice.deposit(carol_, USD_(100), kXRP(200)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'100), USD(10'100), IOUAmount{10'100'000, 0})); + ammAlice.expectBalances(kXRP(10'100), USD_(10'100), IOUAmount{10'100'000, 0})); }); // Single deposit: 1000 USD testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(1'000)); + ammAlice.deposit(carol_, USD_(1'000)); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'999'99999999999), -11}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'999'99999999999), -11}, IOUAmount{10'488'088'48170151, -8})); }); // Single deposit: 1000 XRP testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, XRP(1'000)); + ammAlice.deposit(carol_, kXRP(1'000)); BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), USD(10'000), IOUAmount{10'488'088'48170151, -8})); + kXRP(11'000), USD_(10'000), IOUAmount{10'488'088'48170151, -8})); }); // Single deposit: 100000 tokens worth of USD testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 100000, USD(205)); + ammAlice.deposit(carol_, 100000, USD_(205)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'201), IOUAmount{10'100'000, 0})); + ammAlice.expectBalances(kXRP(10'000), USD_(10'201), IOUAmount{10'100'000, 0})); }); // Single deposit: 100000 tokens worth of XRP testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 100'000, XRP(205)); + ammAlice.deposit(carol_, 100'000, kXRP(205)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'201), USD(10'000), IOUAmount{10'100'000, 0})); + ammAlice.expectBalances(kXRP(10'201), USD_(10'000), IOUAmount{10'100'000, 0})); }); // Single deposit with EP not exceeding specified: // 100USD with EP not to exceed 0.1 (AssetIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(1'000), std::nullopt, STAmount{USD, 1, -1}); + ammAlice.deposit(carol_, USD_(1'000), std::nullopt, STAmount{USD_, 1, -1}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'999'99999999999), -11}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'999'99999999999), -11}, IOUAmount{10'488'088'48170151, -8})); }); // Single deposit with EP not exceeding specified: // 100USD with EP not to exceed 0.002004 (AssetIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(100), std::nullopt, STAmount{USD, 2004, -6}); + ammAlice.deposit(carol_, USD_(100), std::nullopt, STAmount{USD_, 2004, -6}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), STAmount{USD, 10'080'16, -2}, IOUAmount{10'040'000, 0})); + kXRP(10'000), STAmount{USD_, 10'080'16, -2}, IOUAmount{10'040'000, 0})); }); // Single deposit with EP not exceeding specified: // 0USD with EP not to exceed 0.002004 (AssetIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(0), std::nullopt, STAmount{USD, 2004, -6}); + ammAlice.deposit(carol_, USD_(0), std::nullopt, STAmount{USD_, 2004, -6}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), STAmount{USD, 10'080'16, -2}, IOUAmount{10'040'000, 0})); + kXRP(10'000), STAmount{USD_, 10'080'16, -2}, IOUAmount{10'040'000, 0})); }); // IOU to IOU + transfer fee { Env env{*this}; - fund(env, gw, {alice}, {USD(20'000), BTC(0.5)}, Fund::All); - env(rate(gw, 1.25)); + fund(env, gw_, {alice_}, {USD_(20'000), BTC_(0.5)}, Fund::All); + env(rate(gw_, 1.25)); env.close(); - AMM ammAlice(env, alice, USD(20'000), BTC(0.5)); - BEAST_EXPECT(ammAlice.expectBalances(USD(20'000), BTC(0.5), IOUAmount{100, 0})); - BEAST_EXPECT(expectHolding(env, alice, USD(0))); - BEAST_EXPECT(expectHolding(env, alice, BTC(0))); - fund(env, gw, {carol}, {USD(2'000), BTC(0.05)}, Fund::Acct); + AMM ammAlice(env, alice_, USD_(20'000), BTC_(0.5)); + BEAST_EXPECT(ammAlice.expectBalances(USD_(20'000), BTC_(0.5), IOUAmount{100, 0})); + BEAST_EXPECT(expectHolding(env, alice_, USD_(0))); + BEAST_EXPECT(expectHolding(env, alice_, BTC_(0))); + fund(env, gw_, {carol_}, {USD_(2'000), BTC_(0.05)}, Fund::Acct); // no transfer fee on deposit - ammAlice.deposit(carol, 10); - BEAST_EXPECT(ammAlice.expectBalances(USD(22'000), BTC(0.55), IOUAmount{110, 0})); - BEAST_EXPECT(expectHolding(env, carol, USD(0))); - BEAST_EXPECT(expectHolding(env, carol, BTC(0))); + ammAlice.deposit(carol_, 10); + BEAST_EXPECT(ammAlice.expectBalances(USD_(22'000), BTC_(0.55), IOUAmount{110, 0})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(0))); + BEAST_EXPECT(expectHolding(env, carol_, BTC_(0))); } // Tiny deposits testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, IOUAmount{1, -3}); + ammAlice.deposit(carol_, IOUAmount{1, -3}); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{10'000'000'001}, - STAmount{USD, UINT64_C(10'000'000001), -6}, + STAmount{USD_, UINT64_C(10'000'000001), -6}, IOUAmount{10'000'000'001, -3})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{1, -3})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{1, -3})); }); testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, XRPAmount{1}); + ammAlice.deposit(carol_, XRPAmount{1}); BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{10'000'000'001}, USD(10'000), IOUAmount{1'000'000'000049999, -8})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{49999, -8})); + XRPAmount{10'000'000'001}, USD_(10'000), IOUAmount{1'000'000'000049999, -8})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{49999, -8})); }); testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, STAmount{USD, 1, -10}); + ammAlice.deposit(carol_, STAmount{USD_, 1, -10}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'000'00000000008), -11}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'000'00000000008), -11}, IOUAmount{10'000'000'00000004, -8})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{4, -8})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{4, -8})); }); // Issuer create/deposit for (auto const& feat : {all, all - fixAMMv1_3}) { Env env(*this, feat); - env.fund(XRP(30000), gw); - AMM ammGw(env, gw, XRP(10'000), USD(10'000)); - BEAST_EXPECT(ammGw.expectBalances(XRP(10'000), USD(10'000), ammGw.tokens())); - ammGw.deposit(gw, 1'000'000); - BEAST_EXPECT(ammGw.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000})); - ammGw.deposit(gw, USD(1'000)); + env.fund(kXRP(30000), gw_); + AMM ammGw(env, gw_, kXRP(10'000), USD_(10'000)); + BEAST_EXPECT(ammGw.expectBalances(kXRP(10'000), USD_(10'000), ammGw.tokens())); + ammGw.deposit(gw_, 1'000'000); + BEAST_EXPECT(ammGw.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000})); + ammGw.deposit(gw_, USD_(1'000)); BEAST_EXPECT(ammGw.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(11'999'99999999998), -11}, + kXRP(11'000), + STAmount{USD_, UINT64_C(11'999'99999999998), -11}, IOUAmount{11'489'125'29307605, -8})); } // Issuer deposit testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.deposit(gw, 1'000'000); - BEAST_EXPECT(ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000})); - ammAlice.deposit(gw, USD(1'000)); + ammAlice.deposit(gw_, 1'000'000); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000})); + ammAlice.deposit(gw_, USD_(1'000)); BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(11'999'99999999998), -11}, + kXRP(11'000), + STAmount{USD_, UINT64_C(11'999'99999999998), -11}, IOUAmount{11'489'125'29307605, -8})); }); @@ -1393,59 +1455,59 @@ private: testAMM([&](AMM& ammAlice, Env& env) { // Equal deposit by tokens ammAlice.deposit( - carol, + carol_, 1'000'000, - XRP(1'000), - USD(1'000), + kXRP(1'000), + USD_(1'000), std::nullopt, - tfLPToken, + kTF_LP_TOKEN, std::nullopt, std::nullopt); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); }); testAMM([&](AMM& ammAlice, Env& env) { // Equal deposit by asset ammAlice.deposit( - carol, + carol_, 1'000'000, - XRP(1'000), - USD(1'000), + kXRP(1'000), + USD_(1'000), std::nullopt, - tfTwoAsset, + kTF_TWO_ASSET, std::nullopt, std::nullopt); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); }); testAMM([&](AMM& ammAlice, Env& env) { // Single deposit by asset ammAlice.deposit( - carol, + carol_, 488'088, - XRP(1'000), + kXRP(1'000), std::nullopt, std::nullopt, - tfSingleAsset, + kTF_SINGLE_ASSET, std::nullopt, std::nullopt); BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), USD(10'000), IOUAmount{10'488'088'48170151, -8})); + kXRP(11'000), USD_(10'000), IOUAmount{10'488'088'48170151, -8})); }); testAMM([&](AMM& ammAlice, Env& env) { // Single deposit by asset ammAlice.deposit( - carol, + carol_, 488'088, - USD(1'000), + USD_(1'000), std::nullopt, std::nullopt, - tfSingleAsset, + kTF_SINGLE_ASSET, std::nullopt, std::nullopt); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'999'99999999999), -11}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'999'99999999999), -11}, IOUAmount{10'488'088'48170151, -8})); }); } @@ -1461,42 +1523,42 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .asset1Out = XRP(100), - .err = ter(tecAMM_BALANCE), + .asset1Out = kXRP(100), + .err = Ter(TecAmmBalance), }; ammAlice.withdraw(args); }, - {{XRP(99), USD(99)}}); + {{kXRP(99), USD_(99)}}); testAMM( [&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .asset1Out = USD(100), - .err = ter(tecAMM_BALANCE), + .asset1Out = USD_(100), + .err = Ter(TecAmmBalance), }; ammAlice.withdraw(args); }, - {{XRP(99), USD(99)}}); + {{kXRP(99), USD_(99)}}); { Env env{*this}; - env.fund(XRP(30'000), gw, alice, bob); + env.fund(kXRP(30'000), gw_, alice_, bob_); env.close(); - env(fset(gw, asfRequireAuth)); + env(fset(gw_, kASF_REQUIRE_AUTH)); env.close(); - env(trust(alice, gw["USD"](30'000), 0)); - env(trust(gw, alice["USD"](0), tfSetfAuth)); + env(trust(alice_, gw_["USD"](30'000), 0)); + env(trust(gw_, alice_["USD"](0), kTF_SETF_AUTH)); // Bob trusts Gateway to owe him USD... - env(trust(bob, gw["USD"](30'000), 0)); + env(trust(bob_, gw_["USD"](30'000), 0)); // ...but Gateway does not authorize Bob to hold its USD. env.close(); - env(pay(gw, alice, USD(10'000))); + env(pay(gw_, alice_, USD_(10'000))); env.close(); - AMM ammAlice(env, alice, XRP(10'000), USD(10'000)); + AMM ammAlice(env, alice_, kXRP(10'000), USD_(10'000)); WithdrawArg const args{ - .account = bob, - .asset1Out = USD(100), - .err = ter(tecNO_AUTH), + .account = bob_, + .asset1Out = USD_(100), + .err = Ter(TecNoAuth), }; ammAlice.withdraw(args); } @@ -1504,25 +1566,25 @@ private: testAMM([&](AMM& ammAlice, Env& env) { // Invalid flags ammAlice.withdraw( - alice, + alice_, 1'000'000, std::nullopt, std::nullopt, std::nullopt, - tfBurnable, + kTF_BURNABLE, std::nullopt, std::nullopt, - ter(temINVALID_FLAG)); + Ter(TemInvalidFlag)); ammAlice.withdraw( - alice, + alice_, 1'000'000, std::nullopt, std::nullopt, std::nullopt, - tfTwoAssetIfEmpty, + kTF_TWO_ASSET_IF_EMPTY, std::nullopt, std::nullopt, - ter(temINVALID_FLAG)); + Ter(TemInvalidFlag)); // Invalid options std::vector(it), std::get<1>(it), std::get<2>(it), @@ -1594,45 +1666,45 @@ private: std::get<4>(it), std::nullopt, std::nullopt, - ter(std::get<5>(it))); + Ter(std::get<5>(it))); } // Invalid tokens - ammAlice.withdraw(alice, 0, std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + ammAlice.withdraw(alice_, 0, std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); ammAlice.withdraw( - alice, IOUAmount{-1}, std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + alice_, IOUAmount{-1}, std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); // Mismatched token, invalid Asset1Out issue - ammAlice.withdraw(alice, GBP(100), std::nullopt, std::nullopt, ter(temBAD_AMM_TOKENS)); + ammAlice.withdraw(alice_, GBP_(100), std::nullopt, std::nullopt, Ter(TemBadAmmTokens)); // Mismatched token, invalid Asset2Out issue - ammAlice.withdraw(alice, USD(100), GBP(100), std::nullopt, ter(temBAD_AMM_TOKENS)); + ammAlice.withdraw(alice_, USD_(100), GBP_(100), std::nullopt, Ter(TemBadAmmTokens)); // Mismatched token, Asset1Out.issue == Asset2Out.issue - ammAlice.withdraw(alice, USD(100), USD(100), std::nullopt, ter(temBAD_AMM_TOKENS)); + ammAlice.withdraw(alice_, USD_(100), USD_(100), std::nullopt, Ter(TemBadAmmTokens)); // Invalid amount value - ammAlice.withdraw(alice, USD(0), std::nullopt, std::nullopt, ter(temBAD_AMOUNT)); - ammAlice.withdraw(alice, USD(-100), std::nullopt, std::nullopt, ter(temBAD_AMOUNT)); - ammAlice.withdraw(alice, USD(10), std::nullopt, IOUAmount{-1}, ter(temBAD_AMOUNT)); + ammAlice.withdraw(alice_, USD_(0), std::nullopt, std::nullopt, Ter(TemBadAmount)); + ammAlice.withdraw(alice_, USD_(-100), std::nullopt, std::nullopt, Ter(TemBadAmount)); + ammAlice.withdraw(alice_, USD_(10), std::nullopt, IOUAmount{-1}, Ter(TemBadAmount)); // Invalid amount/token value, withdraw all tokens from one side // of the pool. - ammAlice.withdraw(alice, USD(10'000), std::nullopt, std::nullopt, ter(tecAMM_BALANCE)); - ammAlice.withdraw(alice, XRP(10'000), std::nullopt, std::nullopt, ter(tecAMM_BALANCE)); + ammAlice.withdraw(alice_, USD_(10'000), std::nullopt, std::nullopt, Ter(TecAmmBalance)); + ammAlice.withdraw(alice_, kXRP(10'000), std::nullopt, std::nullopt, Ter(TecAmmBalance)); ammAlice.withdraw( - alice, + alice_, std::nullopt, - USD(0), + USD_(0), std::nullopt, std::nullopt, - tfOneAssetWithdrawAll, + kTF_ONE_ASSET_WITHDRAW_ALL, std::nullopt, std::nullopt, - ter(tecAMM_BALANCE)); + Ter(TecAmmBalance)); // Bad currency - ammAlice.withdraw(alice, BAD(100), std::nullopt, std::nullopt, ter(temBAD_CURRENCY)); + ammAlice.withdraw(alice_, BAD_(100), std::nullopt, std::nullopt, Ter(TemBadCurrency)); // Invalid Account Account const bad("bad"); @@ -1645,40 +1717,40 @@ private: std::nullopt, std::nullopt, std::nullopt, - seq(1), - ter(terNO_ACCOUNT)); + Seq(1), + Ter(TerNoAccount)); // Invalid AMM ammAlice.withdraw( - alice, + alice_, 1'000, std::nullopt, std::nullopt, std::nullopt, std::nullopt, - {{USD, GBP}}, + {{USD_, GBP_}}, std::nullopt, - ter(terNO_AMM)); + Ter(TerNoAmm)); // Carol is not a Liquidity Provider - ammAlice.withdraw(carol, 10'000, std::nullopt, std::nullopt, ter(tecAMM_BALANCE)); + ammAlice.withdraw(carol_, 10'000, std::nullopt, std::nullopt, Ter(TecAmmBalance)); // Withdrawing from one side. // XRP by tokens ammAlice.withdraw( - alice, IOUAmount(9'999'999'9999, -4), XRP(0), std::nullopt, ter(tecAMM_BALANCE)); + alice_, IOUAmount(9'999'999'9999, -4), kXRP(0), std::nullopt, Ter(TecAmmBalance)); // USD by tokens ammAlice.withdraw( - alice, IOUAmount(9'999'999'9, -1), USD(0), std::nullopt, ter(tecAMM_BALANCE)); + alice_, IOUAmount(9'999'999'9, -1), USD_(0), std::nullopt, Ter(TecAmmBalance)); // XRP - ammAlice.withdraw(alice, XRP(10'000), std::nullopt, std::nullopt, ter(tecAMM_BALANCE)); + ammAlice.withdraw(alice_, kXRP(10'000), std::nullopt, std::nullopt, Ter(TecAmmBalance)); // USD ammAlice.withdraw( - alice, - STAmount{USD, UINT64_C(9'999'9999999999999), -13}, + alice_, + STAmount{USD_, UINT64_C(9'999'9999999999999), -13}, std::nullopt, std::nullopt, - ter(tecAMM_BALANCE)); + Ter(TecAmmBalance)); }); testAMM( @@ -1690,13 +1762,13 @@ private: // while leaving a tiny amount in USD pool. // Post-amendment: // Most of the pool is withdrawn with remaining tiny amounts - auto err = env.enabled(fixAMMv1_3) ? ter(tesSUCCESS) : ter(tecAMM_BALANCE); + auto err = env.enabled(fixAMMv1_3) ? Ter(TesSuccess) : Ter(TecAmmBalance); ammAlice.withdraw( - alice, IOUAmount{9'999'999'9999, -4}, std::nullopt, std::nullopt, err); + alice_, IOUAmount{9'999'999'9999, -4}, std::nullopt, std::nullopt, err); if (env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount(1), STAmount{USD, 1, -7}, IOUAmount{1, -4})); + XRPAmount(1), STAmount{USD_, 1, -7}, IOUAmount{1, -4})); } }, std::nullopt, @@ -1712,13 +1784,13 @@ private: // Equal withdraw but due to XRP precision limit, // this results in full withdraw of XRP pool only, // while leaving a tiny amount in USD pool. - auto err = env.enabled(fixAMMv1_3) ? ter(tesSUCCESS) : ter(tecAMM_BALANCE); + auto err = env.enabled(fixAMMv1_3) ? Ter(TesSuccess) : Ter(TecAmmBalance); ammAlice.withdraw( - alice, IOUAmount{9'999'999'999999999, -9}, std::nullopt, std::nullopt, err); + alice_, IOUAmount{9'999'999'999999999, -9}, std::nullopt, std::nullopt, err); if (env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount(1), STAmount{USD, 1, -11}, IOUAmount{1, -8})); + XRPAmount(1), STAmount{USD_, 1, -11}, IOUAmount{1, -8})); } }, std::nullopt, @@ -1728,64 +1800,66 @@ private: // Invalid AMM testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.withdrawAll(alice); - ammAlice.withdraw(alice, 10'000, std::nullopt, std::nullopt, ter(terNO_AMM)); + ammAlice.withdrawAll(alice_); + ammAlice.withdraw(alice_, 10'000, std::nullopt, std::nullopt, Ter(TerNoAmm)); }); // Globally frozen asset testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.deposit({.account = gw, .asset1In = USD(1'000), .asset2In = XRP(1'000)}); - env(fset(gw, asfGlobalFreeze)); + ammAlice.deposit({.account = gw_, .asset1In = USD_(1'000), .asset2In = kXRP(1'000)}); + env(fset(gw_, kASF_GLOBAL_FREEZE)); env.close(); // Can withdraw non-frozen token - for (auto const& account : {alice, gw}) + for (auto const& account : {alice_, gw_}) { - ammAlice.withdraw(account, XRP(100)); - ammAlice.withdraw(account, USD(100), std::nullopt, std::nullopt, ter(tecFROZEN)); - ammAlice.withdraw(account, 1'000, std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.withdraw(account, kXRP(100)); + ammAlice.withdraw(account, USD_(100), std::nullopt, std::nullopt, Ter(TecFrozen)); + ammAlice.withdraw(account, 1'000, std::nullopt, std::nullopt, Ter(TecFrozen)); } }); // Individually frozen (AMM) account testAMM([&](AMM& ammAlice, Env& env) { - env(trust(gw, alice["USD"](0), tfSetFreeze)); + env(trust(gw_, alice_["USD"](0), kTF_SET_FREEZE)); env.close(); // Can withdraw non-frozen token - ammAlice.withdraw(alice, XRP(100)); - ammAlice.withdraw(alice, 1'000, std::nullopt, std::nullopt, ter(tecFROZEN)); - ammAlice.withdraw(alice, USD(100), std::nullopt, std::nullopt, ter(tecFROZEN)); - env(trust(gw, alice["USD"](0), tfClearFreeze)); + ammAlice.withdraw(alice_, kXRP(100)); + ammAlice.withdraw(alice_, 1'000, std::nullopt, std::nullopt, Ter(TecFrozen)); + ammAlice.withdraw(alice_, USD_(100), std::nullopt, std::nullopt, Ter(TecFrozen)); + env(trust(gw_, alice_["USD"](0), kTF_CLEAR_FREEZE)); // Individually frozen AMM env(trust( - gw, STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); + gw_, + STAmount{Issue{gw_["USD"].currency, ammAlice.ammAccount()}, 0}, + kTF_SET_FREEZE)); // Can withdraw non-frozen token - ammAlice.withdraw(alice, XRP(100)); - ammAlice.withdraw(alice, 1'000, std::nullopt, std::nullopt, ter(tecFROZEN)); - ammAlice.withdraw(alice, USD(100), std::nullopt, std::nullopt, ter(tecFROZEN)); + ammAlice.withdraw(alice_, kXRP(100)); + ammAlice.withdraw(alice_, 1'000, std::nullopt, std::nullopt, Ter(TecFrozen)); + ammAlice.withdraw(alice_, USD_(100), std::nullopt, std::nullopt, Ter(TecFrozen)); }); // Carol withdraws more than she owns testAMM([&](AMM& ammAlice, Env&) { // Single deposit of 100000 worth of tokens, // which is 10% of the pool. Carol is LP now. - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); ammAlice.withdraw( - carol, 2'000'000, std::nullopt, std::nullopt, ter(tecAMM_INVALID_TOKENS)); + carol_, 2'000'000, std::nullopt, std::nullopt, Ter(TecAmmInvalidTokens)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); }); // Withdraw with EPrice limit. Fails to withdraw, calculated tokens // to withdraw are 0. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); auto const err = - env.enabled(fixAMMv1_3) ? ter(tecAMM_INVALID_TOKENS) : ter(tecAMM_FAILED); - ammAlice.withdraw(carol, USD(100), std::nullopt, IOUAmount{500, 0}, err); + env.enabled(fixAMMv1_3) ? Ter(TecAmmInvalidTokens) : Ter(TecAmmFailed); + ammAlice.withdraw(carol_, USD_(100), std::nullopt, IOUAmount{500, 0}, err); }, std::nullopt, 0, @@ -1795,46 +1869,46 @@ private: // Withdraw with EPrice limit. Fails to withdraw, calculated tokens // to withdraw are greater than the LP shares. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); ammAlice.withdraw( - carol, USD(100), std::nullopt, IOUAmount{600, 0}, ter(tecAMM_INVALID_TOKENS)); + carol_, USD_(100), std::nullopt, IOUAmount{600, 0}, Ter(TecAmmInvalidTokens)); }); // Withdraw with EPrice limit. Fails to withdraw, amount1 // to withdraw is less than 1700USD. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); ammAlice.withdraw( - carol, USD(1'700), std::nullopt, IOUAmount{520, 0}, ter(tecAMM_FAILED)); + carol_, USD_(1'700), std::nullopt, IOUAmount{520, 0}, Ter(TecAmmFailed)); }); // Deposit/Withdraw the same amount with the trading fee testAMM( [&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(1'000)); + ammAlice.deposit(carol_, USD_(1'000)); ammAlice.withdraw( - carol, USD(1'000), std::nullopt, std::nullopt, ter(tecAMM_INVALID_TOKENS)); + carol_, USD_(1'000), std::nullopt, std::nullopt, Ter(TecAmmInvalidTokens)); }, std::nullopt, 1'000); testAMM( [&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, XRP(1'000)); + ammAlice.deposit(carol_, kXRP(1'000)); ammAlice.withdraw( - carol, XRP(1'000), std::nullopt, std::nullopt, ter(tecAMM_INVALID_TOKENS)); + carol_, kXRP(1'000), std::nullopt, std::nullopt, Ter(TecAmmInvalidTokens)); }, std::nullopt, 1'000); // Deposit/Withdraw the same amount fails due to the tokens adjustment testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, STAmount{USD, 1, -6}); + ammAlice.deposit(carol_, STAmount{USD_, 1, -6}); ammAlice.withdraw( - carol, - STAmount{USD, 1, -6}, + carol_, + STAmount{USD_, 1, -6}, std::nullopt, std::nullopt, - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); }); // Withdraw close to one side of the pool. Account's LP tokens @@ -1842,10 +1916,10 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { auto const err = - env.enabled(fixAMMv1_3) ? ter(tecINVARIANT_FAILED) : ter(tecAMM_BALANCE); + env.enabled(fixAMMv1_3) ? Ter(TecInvariantFailed) : Ter(TecAmmBalance); ammAlice.withdraw( - alice, - STAmount{USD, UINT64_C(9'999'999999999999), -12}, + alice_, + STAmount{USD_, UINT64_C(9'999'999999999999), -12}, std::nullopt, std::nullopt, err); @@ -1856,35 +1930,35 @@ private: testAMM([&](AMM& ammAlice, Env&) { // XRP amount to withdraw is 0 ammAlice.withdraw( - alice, IOUAmount{1, -5}, std::nullopt, std::nullopt, ter(tecAMM_FAILED)); + alice_, IOUAmount{1, -5}, std::nullopt, std::nullopt, Ter(TecAmmFailed)); // Calculated tokens to withdraw are 0 ammAlice.withdraw( - alice, + alice_, std::nullopt, - STAmount{USD, 1, -11}, + STAmount{USD_, 1, -11}, std::nullopt, - ter(tecAMM_INVALID_TOKENS)); - ammAlice.deposit(carol, STAmount{USD, 1, -10}); + Ter(TecAmmInvalidTokens)); + ammAlice.deposit(carol_, STAmount{USD_, 1, -10}); ammAlice.withdraw( - carol, + carol_, std::nullopt, - STAmount{USD, 1, -9}, + STAmount{USD_, 1, -9}, std::nullopt, - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); ammAlice.withdraw( - carol, std::nullopt, XRPAmount{1}, std::nullopt, ter(tecAMM_INVALID_TOKENS)); + carol_, std::nullopt, XRPAmount{1}, std::nullopt, Ter(TecAmmInvalidTokens)); ammAlice.withdraw( - WithdrawArg{.tokens = IOUAmount{1, -10}, .err = ter(tecAMM_INVALID_TOKENS)}); + WithdrawArg{.tokens = IOUAmount{1, -10}, .err = Ter(TecAmmInvalidTokens)}); ammAlice.withdraw( WithdrawArg{ - .asset1Out = STAmount{USD, 1, -15}, + .asset1Out = STAmount{USD_, 1, -15}, .asset2Out = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .err = Ter(TecAmmInvalidTokens)}); ammAlice.withdraw( WithdrawArg{ .tokens = IOUAmount{1, -10}, - .asset1Out = STAmount{USD, 1, -15}, - .err = ter(tecAMM_INVALID_TOKENS)}); + .asset1Out = STAmount{USD_, 1, -15}, + .err = Ter(TecAmmInvalidTokens)}); }); } @@ -1902,28 +1976,29 @@ private: auto const baseFee = env.current()->fees().base.drops(); // Single deposit of 100000 worth of tokens, // which is 10% of the pool. Carol is LP now. - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{1'000'000, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{11'000'000, 0})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{1'000'000, 0})); // 30,000 less deposited 1,000 - BEAST_EXPECT(expectHolding(env, carol, USD(29'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(29'000))); // 30,000 less deposited 1,000 and 10 drops tx fee - BEAST_EXPECT(expectLedgerEntryRoot(env, carol, XRPAmount{29'000'000'000 - baseFee})); + BEAST_EXPECT(expectLedgerEntryRoot(env, carol_, XRPAmount{29'000'000'000 - baseFee})); // Carol withdraws all tokens - ammAlice.withdraw(carol, 1'000'000); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount(beast::Zero()))); - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + ammAlice.withdraw(carol_, 1'000'000); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount(beast::Zero()))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); BEAST_EXPECT( - expectLedgerEntryRoot(env, carol, XRPAmount{30'000'000'000 - (2 * baseFee)})); + expectLedgerEntryRoot(env, carol_, XRPAmount{30'000'000'000 - (2 * baseFee)})); }); // Equal withdrawal by tokens 1000000, 10% // of the current pool testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, 1'000'000); - BEAST_EXPECT(ammAlice.expectBalances(XRP(9'000), USD(9'000), IOUAmount{9'000'000, 0})); + ammAlice.withdraw(alice_, 1'000'000); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(9'000), USD_(9'000), IOUAmount{9'000'000, 0})); }); // Equal withdrawal with a limit. Withdraw XRP200. @@ -1932,29 +2007,31 @@ private: // and proportionally withdraw XRP. It's the latter // in this case - XRP100/USD100. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, XRP(200), USD(100)); - BEAST_EXPECT(ammAlice.expectBalances(XRP(9'900), USD(9'900), IOUAmount{9'900'000, 0})); + ammAlice.withdraw(alice_, kXRP(200), USD_(100)); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(9'900), USD_(9'900), IOUAmount{9'900'000, 0})); }); // Equal withdrawal with a limit. XRP100/USD100. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, XRP(100), USD(200)); - BEAST_EXPECT(ammAlice.expectBalances(XRP(9'900), USD(9'900), IOUAmount{9'900'000, 0})); + ammAlice.withdraw(alice_, kXRP(100), USD_(200)); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(9'900), USD_(9'900), IOUAmount{9'900'000, 0})); }); // Single withdrawal by amount XRP1000 testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw(alice, XRP(1'000)); + ammAlice.withdraw(alice_, kXRP(1'000)); if (!env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(9'000), USD(10'000), IOUAmount{9'486'832'98050514, -8})); + kXRP(9'000), USD_(10'000), IOUAmount{9'486'832'98050514, -8})); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{9'000'000'001}, USD(10'000), IOUAmount{9'486'832'98050514, -8})); + XRPAmount{9'000'000'001}, USD_(10'000), IOUAmount{9'486'832'98050514, -8})); } }, std::nullopt, @@ -1964,45 +2041,45 @@ private: // Single withdrawal by tokens 10000. testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, 10'000, USD(0)); + ammAlice.withdraw(alice_, 10'000, USD_(0)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(9980.01), IOUAmount{9'990'000, 0})); + ammAlice.expectBalances(kXRP(10'000), USD_(9980.01), IOUAmount{9'990'000, 0})); }); // Withdraw all tokens. testAMM([&](AMM& ammAlice, Env& env) { - env(trust(carol, STAmount{ammAlice.lptIssue(), 10'000})); + env(trust(carol_, STAmount{ammAlice.lptIssue(), 10'000})); // Can TrustSet only for AMM LP tokens - env(trust(carol, STAmount{Issue{EUR.currency, ammAlice.ammAccount()}, 10'000}), - ter(tecNO_PERMISSION)); + env(trust(carol_, STAmount{Issue{EUR_.currency, ammAlice.ammAccount()}, 10'000}), + Ter(TecNoPermission)); env.close(); - ammAlice.withdrawAll(alice); + ammAlice.withdrawAll(alice_); BEAST_EXPECT(!ammAlice.ammExists()); BEAST_EXPECT(!env.le(keylet::ownerDir(ammAlice.ammAccount()))); // Can create AMM for the XRP/USD pair - AMM const ammCarol(env, carol, XRP(10'000), USD(10'000)); + AMM const ammCarol(env, carol_, kXRP(10'000), USD_(10'000)); BEAST_EXPECT( - ammCarol.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000, 0})); + ammCarol.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000, 0})); }); // Single deposit 1000USD, withdraw all tokens in USD testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, USD(1'000)); - ammAlice.withdrawAll(carol, USD(0)); + ammAlice.deposit(carol_, USD_(1'000)); + ammAlice.withdrawAll(carol_, USD_(0)); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000, 0})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount(beast::Zero()))); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000, 0})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount(beast::Zero()))); }); // Single deposit 1000USD, withdraw all tokens in XRP testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, USD(1'000)); - ammAlice.withdrawAll(carol, XRP(0)); + ammAlice.deposit(carol_, USD_(1'000)); + ammAlice.withdrawAll(carol_, kXRP(0)); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(9'090'909'091), - STAmount{USD, UINT64_C(10'999'99999999999), -11}, + STAmount{USD_, UINT64_C(10'999'99999999999), -11}, IOUAmount{10'000'000, 0})); }); @@ -2012,23 +2089,23 @@ private: // Since a smaller amount might be deposited due to // the lp tokens adjustment, withdrawing by tokens // is generally preferred to withdrawing by amount. - auto lpTokens = ammAlice.deposit(carol, USD(1'000)); - ammAlice.withdraw(carol, lpTokens, USD(0)); - lpTokens = ammAlice.deposit(carol, STAmount(USD, 1, -6)); - ammAlice.withdraw(carol, lpTokens, USD(0)); - lpTokens = ammAlice.deposit(carol, XRPAmount(1)); - ammAlice.withdraw(carol, lpTokens, XRPAmount(0)); + auto lpTokens = ammAlice.deposit(carol_, USD_(1'000)); + ammAlice.withdraw(carol_, lpTokens, USD_(0)); + lpTokens = ammAlice.deposit(carol_, STAmount(USD_, 1, -6)); + ammAlice.withdraw(carol_, lpTokens, USD_(0)); + lpTokens = ammAlice.deposit(carol_, XRPAmount(1)); + ammAlice.withdraw(carol_, lpTokens, XRPAmount(0)); if (!env.enabled(fixAMMv1_3)) { BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), ammAlice.tokens())); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), ammAlice.tokens())); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount(10'000'000'001), USD(10'000), ammAlice.tokens())); + XRPAmount(10'000'000'001), USD_(10'000), ammAlice.tokens())); } - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0})); }, std::nullopt, 0, @@ -2038,98 +2115,98 @@ private: // Single deposit by different accounts and then withdraw // in reverse. testAMM([&](AMM& ammAlice, Env&) { - auto const carolTokens = ammAlice.deposit(carol, USD(1'000)); - auto const aliceTokens = ammAlice.deposit(alice, USD(1'000)); - ammAlice.withdraw(alice, aliceTokens, USD(0)); - ammAlice.withdraw(carol, carolTokens, USD(0)); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'000), USD(10'000), ammAlice.tokens())); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0})); - BEAST_EXPECT(ammAlice.expectLPTokens(alice, ammAlice.tokens())); + auto const carolTokens = ammAlice.deposit(carol_, USD_(1'000)); + auto const aliceTokens = ammAlice.deposit(alice_, USD_(1'000)); + ammAlice.withdraw(alice_, aliceTokens, USD_(0)); + ammAlice.withdraw(carol_, carolTokens, USD_(0)); + BEAST_EXPECT(ammAlice.expectBalances(kXRP(10'000), USD_(10'000), ammAlice.tokens())); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0})); + BEAST_EXPECT(ammAlice.expectLPTokens(alice_, ammAlice.tokens())); }); // Equal deposit 10%, withdraw all tokens testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 1'000'000); - ammAlice.withdrawAll(carol); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.withdrawAll(carol_); BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000, 0})); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000, 0})); }); // Equal deposit 10%, withdraw all tokens in USD testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 1'000'000); - ammAlice.withdrawAll(carol, USD(0)); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.withdrawAll(carol_, USD_(0)); BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(9'090'909090909092), -12}, + kXRP(11'000), + STAmount{USD_, UINT64_C(9'090'909090909092), -12}, IOUAmount{10'000'000, 0})); }); // Equal deposit 10%, withdraw all tokens in XRP testAMM([&](AMM& ammAlice, Env&) { - ammAlice.deposit(carol, 1'000'000); - ammAlice.withdrawAll(carol, XRP(0)); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.withdrawAll(carol_, kXRP(0)); BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount(9'090'909'091), USD(11'000), IOUAmount{10'000'000, 0})); + XRPAmount(9'090'909'091), USD_(11'000), IOUAmount{10'000'000, 0})); }); // Withdraw with EPrice limit. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); - ammAlice.withdraw(carol, USD(100), std::nullopt, IOUAmount{520, 0}); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{153'846'15384616, -8})); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.withdraw(carol_, USD_(100), std::nullopt, IOUAmount{520, 0}); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{153'846'15384616, -8})); if (!env.enabled(fixAMMv1_1) && !env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(11'000'000'000), - STAmount{USD, UINT64_C(9'372'781065088757), -12}, + STAmount{USD_, UINT64_C(9'372'781065088757), -12}, IOUAmount{10'153'846'15384616, -8})); } else if (env.enabled(fixAMMv1_1) && !env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(11'000'000'000), - STAmount{USD, UINT64_C(9'372'781065088769), -12}, + STAmount{USD_, UINT64_C(9'372'781065088769), -12}, IOUAmount{10'153'846'15384616, -8})); } else if (env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(11'000'000'000), - STAmount{USD, UINT64_C(9'372'78106508877), -11}, + STAmount{USD_, UINT64_C(9'372'78106508877), -11}, IOUAmount{10'153'846'15384616, -8})); } - ammAlice.withdrawAll(carol); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0})); + ammAlice.withdrawAll(carol_); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0})); }, {.features = {all, all - fixAMMv1_3, all - fixAMMv1_1 - fixAMMv1_3}, .noLog = true}); // Withdraw with EPrice limit. AssetOut is 0. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); - ammAlice.withdraw(carol, USD(0), std::nullopt, IOUAmount{520, 0}); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{153'846'15384616, -8})); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.withdraw(carol_, USD_(0), std::nullopt, IOUAmount{520, 0}); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{153'846'15384616, -8})); if (!env.enabled(fixAMMv1_1) && !env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(9'372'781065088757), -12}, + kXRP(11'000), + STAmount{USD_, UINT64_C(9'372'781065088757), -12}, IOUAmount{10'153'846'15384616, -8})); } else if (env.enabled(fixAMMv1_1) && !env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(9'372'781065088769), -12}, + kXRP(11'000), + STAmount{USD_, UINT64_C(9'372'781065088769), -12}, IOUAmount{10'153'846'15384616, -8})); } else if (env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(11'000), - STAmount{USD, UINT64_C(9'372'78106508877), -11}, + kXRP(11'000), + STAmount{USD_, UINT64_C(9'372'78106508877), -11}, IOUAmount{10'153'846'15384616, -8})); } }, @@ -2141,50 +2218,50 @@ private: // IOU to IOU + transfer fee { Env env{*this}; - fund(env, gw, {alice}, {USD(20'000), BTC(0.5)}, Fund::All); - env(rate(gw, 1.25)); + fund(env, gw_, {alice_}, {USD_(20'000), BTC_(0.5)}, Fund::All); + env(rate(gw_, 1.25)); env.close(); // no transfer fee on create - AMM ammAlice(env, alice, USD(20'000), BTC(0.5)); - BEAST_EXPECT(ammAlice.expectBalances(USD(20'000), BTC(0.5), IOUAmount{100, 0})); - BEAST_EXPECT(expectHolding(env, alice, USD(0))); - BEAST_EXPECT(expectHolding(env, alice, BTC(0))); - fund(env, gw, {carol}, {USD(2'000), BTC(0.05)}, Fund::Acct); + AMM ammAlice(env, alice_, USD_(20'000), BTC_(0.5)); + BEAST_EXPECT(ammAlice.expectBalances(USD_(20'000), BTC_(0.5), IOUAmount{100, 0})); + BEAST_EXPECT(expectHolding(env, alice_, USD_(0))); + BEAST_EXPECT(expectHolding(env, alice_, BTC_(0))); + fund(env, gw_, {carol_}, {USD_(2'000), BTC_(0.05)}, Fund::Acct); // no transfer fee on deposit - ammAlice.deposit(carol, 10); - BEAST_EXPECT(ammAlice.expectBalances(USD(22'000), BTC(0.55), IOUAmount{110, 0})); - BEAST_EXPECT(expectHolding(env, carol, USD(0))); - BEAST_EXPECT(expectHolding(env, carol, BTC(0))); + ammAlice.deposit(carol_, 10); + BEAST_EXPECT(ammAlice.expectBalances(USD_(22'000), BTC_(0.55), IOUAmount{110, 0})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(0))); + BEAST_EXPECT(expectHolding(env, carol_, BTC_(0))); // no transfer fee on withdraw - ammAlice.withdraw(carol, 10); - BEAST_EXPECT(ammAlice.expectBalances(USD(20'000), BTC(0.5), IOUAmount{100, 0})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0, 0})); - BEAST_EXPECT(expectHolding(env, carol, USD(2'000))); - BEAST_EXPECT(expectHolding(env, carol, BTC(0.05))); + ammAlice.withdraw(carol_, 10); + BEAST_EXPECT(ammAlice.expectBalances(USD_(20'000), BTC_(0.5), IOUAmount{100, 0})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0, 0})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(2'000))); + BEAST_EXPECT(expectHolding(env, carol_, BTC_(0.05))); } // Tiny withdraw testAMM([&](AMM& ammAlice, Env&) { // By tokens - ammAlice.withdraw(alice, IOUAmount{1, -3}); + ammAlice.withdraw(alice_, IOUAmount{1, -3}); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{9'999'999'999}, - STAmount{USD, UINT64_C(9'999'999999), -6}, + STAmount{USD_, UINT64_C(9'999'999999), -6}, IOUAmount{9'999'999'999, -3})); }); testAMM( [&](AMM& ammAlice, Env& env) { // Single XRP pool - ammAlice.withdraw(alice, std::nullopt, XRPAmount{1}); + ammAlice.withdraw(alice_, std::nullopt, XRPAmount{1}); if (!env.enabled(fixAMMv1_3)) { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{9'999'999'999}, USD(10'000), IOUAmount{9'999'999'9995, -4})); + XRPAmount{9'999'999'999}, USD_(10'000), IOUAmount{9'999'999'9995, -4})); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), USD(10'000), IOUAmount{9'999'999'9995, -4})); + kXRP(10'000), USD_(10'000), IOUAmount{9'999'999'9995, -4})); } }, std::nullopt, @@ -2193,40 +2270,41 @@ private: {all, all - fixAMMv1_3}); testAMM([&](AMM& ammAlice, Env&) { // Single USD pool - ammAlice.withdraw(alice, std::nullopt, STAmount{USD, 1, -10}); + ammAlice.withdraw(alice_, std::nullopt, STAmount{USD_, 1, -10}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(9'999'9999999999), -10}, + kXRP(10'000), + STAmount{USD_, UINT64_C(9'999'9999999999), -10}, IOUAmount{9'999'999'99999995, -8})); }); // Withdraw close to entire pool // Equal by tokens testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, IOUAmount{9'999'999'999, -3}); + ammAlice.withdraw(alice_, IOUAmount{9'999'999'999, -3}); BEAST_EXPECT( - ammAlice.expectBalances(XRPAmount{1}, STAmount{USD, 1, -6}, IOUAmount{1, -3})); + ammAlice.expectBalances(XRPAmount{1}, STAmount{USD_, 1, -6}, IOUAmount{1, -3})); }); // USD by tokens testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, IOUAmount{9'999'999}, USD(0)); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'000), STAmount{USD, 1, -10}, IOUAmount{1})); + ammAlice.withdraw(alice_, IOUAmount{9'999'999}, USD_(0)); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'000), STAmount{USD_, 1, -10}, IOUAmount{1})); }); // XRP by tokens testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, IOUAmount{9'999'900}, XRP(0)); - BEAST_EXPECT(ammAlice.expectBalances(XRPAmount{1}, USD(10'000), IOUAmount{100})); + ammAlice.withdraw(alice_, IOUAmount{9'999'900}, kXRP(0)); + BEAST_EXPECT(ammAlice.expectBalances(XRPAmount{1}, USD_(10'000), IOUAmount{100})); }); // USD testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, STAmount{USD, UINT64_C(9'999'99999999999), -11}); + ammAlice.withdraw(alice_, STAmount{USD_, UINT64_C(9'999'99999999999), -11}); BEAST_EXPECT(ammAlice.expectBalances( - XRP(10000), STAmount{USD, 1, -11}, IOUAmount{316227765, -9})); + kXRP(10000), STAmount{USD_, 1, -11}, IOUAmount{316227765, -9})); }); // XRP testAMM([&](AMM& ammAlice, Env&) { - ammAlice.withdraw(alice, XRPAmount{9'999'999'999}); - BEAST_EXPECT(ammAlice.expectBalances(XRPAmount{1}, USD(10'000), IOUAmount{100})); + ammAlice.withdraw(alice_, XRPAmount{9'999'999'999}); + BEAST_EXPECT(ammAlice.expectBalances(XRPAmount{1}, USD_(10'000), IOUAmount{100})); }); } @@ -2241,33 +2319,33 @@ private: ammAlice.vote( std::nullopt, 1'000, - tfWithdrawAll, + kTF_WITHDRAW_ALL, std::nullopt, std::nullopt, - ter(temINVALID_FLAG)); + Ter(TemInvalidFlag)); // Invalid fee. ammAlice.vote( - std::nullopt, 1'001, std::nullopt, std::nullopt, std::nullopt, ter(temBAD_FEE)); + std::nullopt, 1'001, std::nullopt, std::nullopt, std::nullopt, Ter(TemBadFee)); BEAST_EXPECT(ammAlice.expectTradingFee(0)); // Invalid Account Account const bad("bad"); env.memoize(bad); - ammAlice.vote(bad, 1'000, std::nullopt, seq(1), std::nullopt, ter(terNO_ACCOUNT)); + ammAlice.vote(bad, 1'000, std::nullopt, Seq(1), std::nullopt, Ter(TerNoAccount)); // Invalid AMM - ammAlice.vote(alice, 1'000, std::nullopt, std::nullopt, {{USD, GBP}}, ter(terNO_AMM)); + ammAlice.vote(alice_, 1'000, std::nullopt, std::nullopt, {{USD_, GBP_}}, Ter(TerNoAmm)); // Account is not LP ammAlice.vote( - carol, 1'000, std::nullopt, std::nullopt, std::nullopt, ter(tecAMM_INVALID_TOKENS)); + carol_, 1'000, std::nullopt, std::nullopt, std::nullopt, Ter(TecAmmInvalidTokens)); }); // Invalid AMM testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.withdrawAll(alice); - ammAlice.vote(alice, 1'000, std::nullopt, std::nullopt, std::nullopt, ter(terNO_AMM)); + ammAlice.withdrawAll(alice_); + ammAlice.vote(alice_, 1'000, std::nullopt, std::nullopt, std::nullopt, Ter(TerNoAmm)); }); } @@ -2300,7 +2378,7 @@ private: // deposit to succeed if (env.enabled(fixAMMv1_3)) ++fundUSD; - fund(env, gw, {a}, {USD(fundUSD)}, Fund::Acct); + fund(env, gw_, {a}, {USD_(fundUSD)}, Fund::Acct); ammAlice.deposit(a, tokens); ammAlice.vote(a, 50 * (i + 1)); if (accounts) @@ -2360,8 +2438,8 @@ private: BEAST_EXPECT(ammAlice.expectTradingFee(175)); for (int i = 0; i < 7; ++i) ammAlice.withdrawAll(accounts[i]); - ammAlice.deposit(carol, 10'000'000); - ammAlice.vote(carol, 1'000); + ammAlice.deposit(carol_, 10'000'000); + ammAlice.vote(carol_, 1'000); // The initial LP set the fee to 1000. Carol gets 50% voting // power, and the new fee is 500. BEAST_EXPECT(ammAlice.expectTradingFee(500)); @@ -2377,12 +2455,12 @@ private: BEAST_EXPECT(ammAlice.expectTradingFee(175)); for (int i = 0; i < 7; ++i) ammAlice.withdraw(accounts[i], 9'000'000); - ammAlice.deposit(carol, 1'000); + ammAlice.deposit(carol_, 1'000); // The vote is not added to the slots - ammAlice.vote(carol, 1'000); - auto const info = ammAlice.ammRpcInfo()[jss::amm][jss::vote_slots]; + ammAlice.vote(carol_, 1'000); + auto const info = ammAlice.ammRpcInfo()[jss::amm][jss::kVOTE_SLOTS]; for (std::uint32_t i = 0; i < info.size(); ++i) - BEAST_EXPECT(info[i][jss::account] != carol.human()); + BEAST_EXPECT(info[i][jss::account] != carol_.human()); // But the slots are refreshed and the fee is changed BEAST_EXPECT(ammAlice.expectTradingFee(82)); }); @@ -2398,8 +2476,8 @@ private: // burn all the LPTokens through a AMMBid transaction { Env env(*this); - fund(env, gw, {alice}, XRP(2'000), {USD(2'000)}); - AMM amm(env, gw, XRP(1'000), USD(1'000), false, 1'000); + fund(env, gw_, {alice_}, kXRP(2'000), {USD_(2'000)}); + AMM amm(env, gw_, kXRP(1'000), USD_(1'000), false, 1'000); // auction slot is owned by the creator of the AMM i.e. gw BEAST_EXPECT(amm.expectAuctionSlot(100, 0, IOUAmount{0})); @@ -2408,17 +2486,17 @@ private: // this transaction fails because AMMBid transaction can not burn // all the outstanding LPTokens env(amm.bid({ - .account = gw, + .account = gw_, .bidMin = 1'000'000, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); } // burn all the LPTokens through a AMMBid transaction { Env env(*this); - fund(env, gw, {alice}, XRP(2'000), {USD(2'000)}); - AMM amm(env, gw, XRP(1'000), USD(1'000), false, 1'000); + fund(env, gw_, {alice_}, kXRP(2'000), {USD_(2'000)}); + AMM amm(env, gw_, kXRP(1'000), USD_(1'000), false, 1'000); // auction slot is owned by the creator of the AMM i.e. gw BEAST_EXPECT(amm.expectAuctionSlot(100, 0, IOUAmount{0})); @@ -2427,63 +2505,63 @@ private: // this transaction succeeds because the bid price is less than // the total outstanding LPToken balance env(amm.bid({ - .account = gw, + .account = gw_, .bidMin = STAmount{amm.lptIssue(), UINT64_C(999'999)}, }), - ter(tesSUCCESS)) + Ter(TesSuccess)) .close(); // gw must own the auction slot BEAST_EXPECT(amm.expectAuctionSlot(100, 0, IOUAmount{999'999})); // 999'999 tokens are burned, only 1 LPToken is owned by gw - BEAST_EXPECT(amm.expectBalances(XRP(1'000), USD(1'000), IOUAmount{1})); + BEAST_EXPECT(amm.expectBalances(kXRP(1'000), USD_(1'000), IOUAmount{1})); // gw owns only 1 LPToken in its balance - BEAST_EXPECT(Number{amm.getLPTokensBalance(gw)} == 1); + BEAST_EXPECT(Number{amm.getLPTokensBalance(gw_)} == 1); // gw attempts to burn the last of its LPTokens in an AMMBid // transaction. This transaction fails because it would burn all // the remaining LPTokens env(amm.bid({ - .account = gw, + .account = gw_, .bidMin = 1, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); } testAMM([&](AMM& ammAlice, Env& env) { // Invalid flags env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 0, - .flags = tfWithdrawAll, + .flags = kTF_WITHDRAW_ALL, }), - ter(temINVALID_FLAG)); + Ter(TemInvalidFlag)); - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); // Invalid Bid price <= 0 for (auto bid : {0, -100}) { env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = bid, }), - ter(temBAD_AMOUNT)); + Ter(TemBadAmount)); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMax = bid, }), - ter(temBAD_AMOUNT)); + Ter(TemBadAmount)); } // Invalid Min/Max combination env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 200, .bidMax = 100, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); // Invalid Account Account const bad("bad"); @@ -2492,59 +2570,59 @@ private: .account = bad, .bidMax = 100, }), - seq(1), - ter(terNO_ACCOUNT)); + Seq(1), + Ter(TerNoAccount)); // Account is not LP Account const dan("dan"); - env.fund(XRP(1'000), dan); + env.fund(kXRP(1'000), dan); env(ammAlice.bid({ .account = dan, .bidMin = 100, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); env(ammAlice.bid({ .account = dan, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); // Auth account is invalid. env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 100, - .authAccounts = {bob}, + .authAccounts = {bob_}, }), - ter(terNO_ACCOUNT)); + Ter(TerNoAccount)); // Invalid Assets env(ammAlice.bid({ - .account = alice, + .account = alice_, .bidMax = 100, - .assets = {{USD, GBP}}, + .assets = {{USD_, GBP_}}, }), - ter(terNO_AMM)); + Ter(TerNoAmm)); // Invalid Min/Max issue env(ammAlice.bid({ - .account = alice, - .bidMax = STAmount{USD, 100}, + .account = alice_, + .bidMax = STAmount{USD_, 100}, }), - ter(temBAD_AMM_TOKENS)); + Ter(TemBadAmmTokens)); env(ammAlice.bid({ - .account = alice, - .bidMin = STAmount{USD, 100}, + .account = alice_, + .bidMin = STAmount{USD_, 100}, }), - ter(temBAD_AMM_TOKENS)); + Ter(TemBadAmmTokens)); }); // Invalid AMM testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.withdrawAll(alice); + ammAlice.withdrawAll(alice_); env(ammAlice.bid({ - .account = alice, + .account = alice_, .bidMax = 100, }), - ter(terNO_AMM)); + Ter(TerNoAmm)); }); // More than four Auth accounts. @@ -2553,62 +2631,62 @@ private: Account const bill("bill"); Account const scott("scott"); Account const james("james"); - env.fund(XRP(1'000), bob, ed, bill, scott, james); + env.fund(kXRP(1'000), bob_, ed, bill, scott, james); env.close(); - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 100, - .authAccounts = {bob, ed, bill, scott, james}, + .authAccounts = {bob_, ed, bill, scott, james}, }), - ter(temMALFORMED)); + Ter(TemMalformed)); }); // Bid price exceeds LP owned tokens testAMM([&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(1'000), {USD(100)}, Fund::Acct); - ammAlice.deposit(carol, 1'000'000); - ammAlice.deposit(bob, 10); + fund(env, gw_, {bob_}, kXRP(1'000), {USD_(100)}, Fund::Acct); + ammAlice.deposit(carol_, 1'000'000); + ammAlice.deposit(bob_, 10); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 1'000'001, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMax = 1'000'001, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 1'000, })); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{1'000})); // Slot purchase price is more than 1000 but bob only has 10 tokens env(ammAlice.bid({ - .account = bob, + .account = bob_, }), - ter(tecAMM_INVALID_TOKENS)); + Ter(TecAmmInvalidTokens)); }); // Bid all tokens, still own the slot { Env env(*this); - fund(env, gw, {alice, bob}, XRP(1'000), {USD(1'000)}); - AMM amm(env, gw, XRP(10), USD(1'000)); + fund(env, gw_, {alice_, bob_}, kXRP(1'000), {USD_(1'000)}); + AMM amm(env, gw_, kXRP(10), USD_(1'000)); auto const lpIssue = amm.lptIssue(); - env.trust(STAmount{lpIssue, 100}, alice); - env.trust(STAmount{lpIssue, 50}, bob); - env(pay(gw, alice, STAmount{lpIssue, 100})); - env(pay(gw, bob, STAmount{lpIssue, 50})); - env(amm.bid({.account = alice, .bidMin = 100})); + env.trust(STAmount{lpIssue, 100}, alice_); + env.trust(STAmount{lpIssue, 50}, bob_); + env(pay(gw_, alice_, STAmount{lpIssue, 100})); + env(pay(gw_, bob_, STAmount{lpIssue, 50})); + env(amm.bid({.account = alice_, .bidMin = 100})); // Alice doesn't have any more tokens, but // she still owns the slot. env(amm.bid({ - .account = bob, + .account = bob_, .bidMax = 50, }), - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); } } @@ -2628,12 +2706,12 @@ private: // Bid 110 tokens. Pay bidMin. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); - env(ammAlice.bid({.account = carol, .bidMin = 110})); + ammAlice.deposit(carol_, 1'000'000); + env(ammAlice.bid({.account = carol_, .bidMin = 110})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{110})); // 110 tokens are burned. BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{10'999'890, 0})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{10'999'890, 0})); }, std::nullopt, 0, @@ -2643,17 +2721,17 @@ private: // Bid with min/max when the pay price is less than min. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); // Bid exactly 110. Pay 110 because the pay price is < 110. - env(ammAlice.bid({.account = carol, .bidMin = 110, .bidMax = 110})); + env(ammAlice.bid({.account = carol_, .bidMin = 110, .bidMax = 110})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{110})); BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{10'999'890})); + ammAlice.expectBalances(kXRP(11'000), USD_(11'000), IOUAmount{10'999'890})); // Bid exactly 180-200. Pay 180 because the pay price is < 180. - env(ammAlice.bid({.account = alice, .bidMin = 180, .bidMax = 200})); + env(ammAlice.bid({.account = alice_, .bidMin = 180, .bidMax = 200})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{180})); - BEAST_EXPECT( - ammAlice.expectBalances(XRP(11'000), USD(11'000), IOUAmount{10'999'814'5, -1})); + BEAST_EXPECT(ammAlice.expectBalances( + kXRP(11'000), USD_(11'000), IOUAmount{10'999'814'5, -1})); }, std::nullopt, 0, @@ -2663,37 +2741,37 @@ private: // Start bid at bidMin 110. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); // Bid, pay bidMin. - env(ammAlice.bid({.account = carol, .bidMin = 110})); + env(ammAlice.bid({.account = carol_, .bidMin = 110})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{110})); - fund(env, gw, {bob}, {USD(10'000)}, Fund::Acct); - ammAlice.deposit(bob, 1'000'000); + fund(env, gw_, {bob_}, {USD_(10'000)}, Fund::Acct); + ammAlice.deposit(bob_, 1'000'000); // Bid, pay the computed price. - env(ammAlice.bid({.account = bob})); + env(ammAlice.bid({.account = bob_})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount(1155, -1))); // Bid bidMax fails because the computed price is higher. env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMax = 120, }), - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Bid MaxSlotPrice succeeds - pay computed price - env(ammAlice.bid({.account = carol, .bidMax = 600})); + env(ammAlice.bid({.account = carol_, .bidMax = 600})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{121'275, -3})); // Bid Min/MaxSlotPrice fails because the computed price is not // in range env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 10, .bidMax = 100, }), - ter(tecAMM_FAILED)); + Ter(TecAmmFailed)); // Bid Min/MaxSlotPrice succeeds - pay computed price - env(ammAlice.bid({.account = carol, .bidMin = 100, .bidMax = 600})); + env(ammAlice.bid({.account = carol_, .bidMin = 100, .bidMax = 600})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{127'33875, -5})); }, std::nullopt, @@ -2704,54 +2782,54 @@ private: // Slot states. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); - fund(env, gw, {bob}, {USD(10'000)}, Fund::Acct); - ammAlice.deposit(bob, 1'000'000); + fund(env, gw_, {bob_}, {USD_(10'000)}, Fund::Acct); + ammAlice.deposit(bob_, 1'000'000); if (!features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(12'000), USD(12'000), IOUAmount{12'000'000, 0})); + kXRP(12'000), USD_(12'000), IOUAmount{12'000'000, 0})); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{12'000'000'001}, USD(12'000), IOUAmount{12'000'000, 0})); + XRPAmount{12'000'000'001}, USD_(12'000), IOUAmount{12'000'000, 0})); } // Initial state. Pay bidMin. - env(ammAlice.bid({.account = carol, .bidMin = 110})).close(); + env(ammAlice.bid({.account = carol_, .bidMin = 110})).close(); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{110})); // 1st Interval after close, price for 0th interval. - env(ammAlice.bid({.account = bob})); - env.close(seconds(AUCTION_SLOT_INTERVAL_DURATION + 1)); + env(ammAlice.bid({.account = bob_})); + env.close(seconds(kAUCTION_SLOT_INTERVAL_DURATION + 1)); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 1, IOUAmount{1'155, -1})); // 10th Interval after close, price for 1st interval. - env(ammAlice.bid({.account = carol})); - env.close(seconds((10 * AUCTION_SLOT_INTERVAL_DURATION) + 1)); + env(ammAlice.bid({.account = carol_})); + env.close(seconds((10 * kAUCTION_SLOT_INTERVAL_DURATION) + 1)); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 10, IOUAmount{121'275, -3})); // 20th Interval (expired) after close, price for 10th interval. - env(ammAlice.bid({.account = bob})); + env(ammAlice.bid({.account = bob_})); env.close( - seconds((AUCTION_SLOT_TIME_INTERVALS * AUCTION_SLOT_INTERVAL_DURATION) + 1)); + seconds((kAUCTION_SLOT_TIME_INTERVALS * kAUCTION_SLOT_INTERVAL_DURATION) + 1)); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, std::nullopt, IOUAmount{127'33875, -5})); // 0 Interval. - env(ammAlice.bid({.account = carol, .bidMin = 110})).close(); + env(ammAlice.bid({.account = carol_, .bidMin = 110})).close(); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, std::nullopt, IOUAmount{110})); // ~321.09 tokens burnt on bidding fees. if (!features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(12'000), USD(12'000), IOUAmount{11'999'678'91, -2})); + kXRP(12'000), USD_(12'000), IOUAmount{11'999'678'91, -2})); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{12'000'000'001}, USD(12'000), IOUAmount{11'999'678'91, -2})); + XRPAmount{12'000'000'001}, USD_(12'000), IOUAmount{11'999'678'91, -2})); } }, std::nullopt, @@ -2767,75 +2845,79 @@ private: [&](AMM& ammAlice, Env& env) { Account const dan("dan"); Account const ed("ed"); - fund(env, gw, {bob, dan, ed}, {USD(20'000)}, Fund::Acct); - ammAlice.deposit(bob, 1'000'000); + fund(env, gw_, {bob_, dan, ed}, {USD_(20'000)}, Fund::Acct); + ammAlice.deposit(bob_, 1'000'000); ammAlice.deposit(ed, 1'000'000); - ammAlice.deposit(carol, 500'000); + ammAlice.deposit(carol_, 500'000); ammAlice.deposit(dan, 500'000); auto ammTokens = ammAlice.getLPTokensBalance(); env(ammAlice.bid({ - .account = carol, + .account = carol_, .bidMin = 120, - .authAccounts = {bob, ed}, + .authAccounts = {bob_, ed}, })); auto const slotPrice = IOUAmount{5'200}; ammTokens -= slotPrice; BEAST_EXPECT(ammAlice.expectAuctionSlot(100, 0, slotPrice)); if (!features[fixAMMv1_3]) { - BEAST_EXPECT(ammAlice.expectBalances(XRP(13'000), USD(13'000), ammTokens)); + BEAST_EXPECT(ammAlice.expectBalances(kXRP(13'000), USD_(13'000), ammTokens)); } else { - BEAST_EXPECT( - ammAlice.expectBalances(XRPAmount{13'000'000'003}, USD(13'000), ammTokens)); + BEAST_EXPECT(ammAlice.expectBalances( + XRPAmount{13'000'000'003}, USD_(13'000), ammTokens)); } // Discounted trade for (int i = 0; i < 10; ++i) { - auto tokens = ammAlice.deposit(carol, USD(100)); - ammAlice.withdraw(carol, tokens, USD(0)); - tokens = ammAlice.deposit(bob, USD(100)); - ammAlice.withdraw(bob, tokens, USD(0)); - tokens = ammAlice.deposit(ed, USD(100)); - ammAlice.withdraw(ed, tokens, USD(0)); + auto tokens = ammAlice.deposit(carol_, USD_(100)); + ammAlice.withdraw(carol_, tokens, USD_(0)); + tokens = ammAlice.deposit(bob_, USD_(100)); + ammAlice.withdraw(bob_, tokens, USD_(0)); + tokens = ammAlice.deposit(ed, USD_(100)); + ammAlice.withdraw(ed, tokens, USD_(0)); } // carol, bob, and ed pay ~0.99USD in fees. if (!features[fixAMMv1_1]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'499'00572620545), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'499'00572620545), -11)); BEAST_EXPECT( - env.balance(bob, USD) == STAmount(USD, UINT64_C(18'999'00572616195), -11)); + env.balance(bob_, USD_) == + STAmount(USD_, UINT64_C(18'999'00572616195), -11)); BEAST_EXPECT( - env.balance(ed, USD) == STAmount(USD, UINT64_C(18'999'00572611841), -11)); + env.balance(ed, USD_) == STAmount(USD_, UINT64_C(18'999'00572611841), -11)); // USD pool is slightly higher because of the fees. BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), STAmount(USD, UINT64_C(13'002'98282151419), -11), ammTokens)); + kXRP(13'000), + STAmount(USD_, UINT64_C(13'002'98282151419), -11), + ammTokens)); } else { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'499'00572620544), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'499'00572620544), -11)); BEAST_EXPECT( - env.balance(bob, USD) == STAmount(USD, UINT64_C(18'999'00572616194), -11)); + env.balance(bob_, USD_) == + STAmount(USD_, UINT64_C(18'999'00572616194), -11)); BEAST_EXPECT( - env.balance(ed, USD) == STAmount(USD, UINT64_C(18'999'0057261184), -10)); + env.balance(ed, USD_) == STAmount(USD_, UINT64_C(18'999'0057261184), -10)); // USD pool is slightly higher because of the fees. if (!features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), - STAmount(USD, UINT64_C(13'002'98282151422), -11), + kXRP(13'000), + STAmount(USD_, UINT64_C(13'002'98282151422), -11), ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'003}, - STAmount(USD, UINT64_C(13'002'98282151422), -11), + STAmount(USD_, UINT64_C(13'002'98282151422), -11), ammTokens)); } } @@ -2843,8 +2925,8 @@ private: // Trade with the fee for (int i = 0; i < 10; ++i) { - auto const tokens = ammAlice.deposit(dan, USD(100)); - ammAlice.withdraw(dan, tokens, USD(0)); + auto const tokens = ammAlice.deposit(dan, USD_(100)); + ammAlice.withdraw(dan, tokens, USD_(0)); } // dan pays ~9.94USD, which is ~10 times more in fees than // carol, bob, ed. the discounted fee is 10 times less @@ -2852,22 +2934,26 @@ private: if (!features[fixAMMv1_1]) { BEAST_EXPECT( - env.balance(dan, USD) == STAmount(USD, UINT64_C(19'490'056722744), -9)); + env.balance(dan, USD_) == STAmount(USD_, UINT64_C(19'490'056722744), -9)); // USD pool gains more in dan's fees. BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), STAmount{USD, UINT64_C(13'012'92609877019), -11}, ammTokens)); + kXRP(13'000), + STAmount{USD_, UINT64_C(13'012'92609877019), -11}, + ammTokens)); // Discounted fee payment - ammAlice.deposit(carol, USD(100)); + ammAlice.deposit(carol_, USD_(100)); ammTokens = ammAlice.getLPTokensBalance(); BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), STAmount{USD, UINT64_C(13'112'92609877019), -11}, ammTokens)); - env(pay(carol, bob, USD(100)), path(~USD), sendmax(XRP(110))); + kXRP(13'000), + STAmount{USD_, UINT64_C(13'112'92609877019), -11}, + ammTokens)); + env(pay(carol_, bob_, USD_(100)), Path(~USD_), Sendmax(kXRP(110))); env.close(); // carol pays 100000 drops in fees // 99900668XRP swapped in for 100USD BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'100'000'668}, - STAmount{USD, UINT64_C(13'012'92609877019), -11}, + STAmount{USD_, UINT64_C(13'012'92609877019), -11}, ammTokens)); } else @@ -2875,48 +2961,48 @@ private: if (!features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(dan, USD) == - STAmount(USD, UINT64_C(19'490'05672274399), -11)); + env.balance(dan, USD_) == + STAmount(USD_, UINT64_C(19'490'05672274399), -11)); } else { BEAST_EXPECT( - env.balance(dan, USD) == - STAmount(USD, UINT64_C(19'490'05672274398), -11)); + env.balance(dan, USD_) == + STAmount(USD_, UINT64_C(19'490'05672274398), -11)); } // USD pool gains more in dan's fees. if (!features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), - STAmount{USD, UINT64_C(13'012'92609877023), -11}, + kXRP(13'000), + STAmount{USD_, UINT64_C(13'012'92609877023), -11}, ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'003}, - STAmount{USD, UINT64_C(13'012'92609877024), -11}, + STAmount{USD_, UINT64_C(13'012'92609877024), -11}, ammTokens)); } // Discounted fee payment - ammAlice.deposit(carol, USD(100)); + ammAlice.deposit(carol_, USD_(100)); ammTokens = ammAlice.getLPTokensBalance(); if (!features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(13'000), - STAmount{USD, UINT64_C(13'112'92609877023), -11}, + kXRP(13'000), + STAmount{USD_, UINT64_C(13'112'92609877023), -11}, ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'003}, - STAmount{USD, UINT64_C(13'112'92609877024), -11}, + STAmount{USD_, UINT64_C(13'112'92609877024), -11}, ammTokens)); } - env(pay(carol, bob, USD(100)), path(~USD), sendmax(XRP(110))); + env(pay(carol_, bob_, USD_(100)), Path(~USD_), Sendmax(kXRP(110))); env.close(); // carol pays 100000 drops in fees // 99900668XRP swapped in for 100USD @@ -2924,19 +3010,19 @@ private: { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'100'000'668}, - STAmount{USD, UINT64_C(13'012'92609877023), -11}, + STAmount{USD_, UINT64_C(13'012'92609877023), -11}, ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'100'000'671}, - STAmount{USD, UINT64_C(13'012'92609877024), -11}, + STAmount{USD_, UINT64_C(13'012'92609877024), -11}, ammTokens)); } } // Payment with the trading fee - env(pay(alice, carol, XRP(100)), path(~XRP), sendmax(USD(110))); + env(pay(alice_, carol_, kXRP(100)), Path(~kXRP), Sendmax(USD_(110))); env.close(); // alice pays ~1.011USD in fees, which is ~10 times more // than carol's fee @@ -2945,78 +3031,78 @@ private: { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'668}, - STAmount{USD, UINT64_C(13'114'03663047264), -11}, + STAmount{USD_, UINT64_C(13'114'03663047264), -11}, ammTokens)); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'668}, - STAmount{USD, UINT64_C(13'114'03663047269), -11}, + STAmount{USD_, UINT64_C(13'114'03663047269), -11}, ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'671}, - STAmount{USD, UINT64_C(13'114'03663044937), -11}, + STAmount{USD_, UINT64_C(13'114'03663044937), -11}, ammTokens)); } // Auction slot expired, no discounted fee - env.close(seconds(TOTAL_TIME_SLOT_SECS + 1)); + env.close(seconds(kTOTAL_TIME_SLOT_SECS + 1)); // clock is parent's based env.close(); if (!features[fixAMMv1_1]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'399'00572620545), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'399'00572620545), -11)); } else if (!features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'399'00572620544), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'399'00572620544), -11)); } ammTokens = ammAlice.getLPTokensBalance(); for (int i = 0; i < 10; ++i) { - auto const tokens = ammAlice.deposit(carol, USD(100)); - ammAlice.withdraw(carol, tokens, USD(0)); + auto const tokens = ammAlice.deposit(carol_, USD_(100)); + ammAlice.withdraw(carol_, tokens, USD_(0)); } // carol pays ~9.94USD in fees, which is ~10 times more in // trading fees vs discounted fee. if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'389'06197177128), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'389'06197177128), -11)); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'668}, - STAmount{USD, UINT64_C(13'123'98038490681), -11}, + STAmount{USD_, UINT64_C(13'123'98038490681), -11}, ammTokens)); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'389'06197177124), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'389'06197177124), -11)); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'668}, - STAmount{USD, UINT64_C(13'123'98038490689), -11}, + STAmount{USD_, UINT64_C(13'123'98038490689), -11}, ammTokens)); } else { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'389'06197177129), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'389'06197177129), -11)); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{13'000'000'671}, - STAmount{USD, UINT64_C(13'123'98038488352), -11}, + STAmount{USD_, UINT64_C(13'123'98038488352), -11}, ammTokens)); } - env(pay(carol, bob, USD(100)), path(~USD), sendmax(XRP(110))); + env(pay(carol_, bob_, USD_(100)), Path(~USD_), Sendmax(kXRP(110))); env.close(); // carol pays ~1.008XRP in trading fee, which is // ~10 times more than the discounted fee. @@ -3025,21 +3111,21 @@ private: { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(13'100'824'790), - STAmount{USD, UINT64_C(13'023'98038490681), -11}, + STAmount{USD_, UINT64_C(13'023'98038490681), -11}, ammTokens)); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(13'100'824'790), - STAmount{USD, UINT64_C(13'023'98038490689), -11}, + STAmount{USD_, UINT64_C(13'023'98038490689), -11}, ammTokens)); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(13'100'824'793), - STAmount{USD, UINT64_C(13'023'98038488352), -11}, + STAmount{USD_, UINT64_C(13'023'98038488352), -11}, ammTokens)); } }, @@ -3052,23 +3138,25 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { // Bid a tiny amount - auto const tiny = Number{STAmount::cMinValue, STAmount::cMinOffset}; - env(ammAlice.bid({.account = alice, .bidMin = IOUAmount{tiny}})); + auto const tiny = Number{STAmount::kC_MIN_VALUE, STAmount::kC_MIN_OFFSET}; + env(ammAlice.bid({.account = alice_, .bidMin = IOUAmount{tiny}})); // Auction slot purchase price is equal to the tiny amount // since the minSlotPrice is 0 with no trading fee. BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{tiny})); // The purchase price is too small to affect the total tokens - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'000), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), ammAlice.tokens())); // Bid the tiny amount env(ammAlice.bid({ - .account = alice, - .bidMin = IOUAmount{STAmount::cMinValue, STAmount::cMinOffset}, + .account = alice_, + .bidMin = IOUAmount{STAmount::kC_MIN_VALUE, STAmount::kC_MIN_OFFSET}, })); // Pay slightly higher price BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{tiny * Number{105, -2}})); // The purchase price is still too small to affect the total // tokens - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'000), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), ammAlice.tokens())); }, std::nullopt, 0, @@ -3079,18 +3167,18 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { env(ammAlice.bid({ - .account = alice, + .account = alice_, .bidMin = IOUAmount{100}, - .authAccounts = {carol}, + .authAccounts = {carol_}, })); - BEAST_EXPECT(ammAlice.expectAuctionSlot({carol})); - env(ammAlice.bid({.account = alice, .bidMin = IOUAmount{100}})); + BEAST_EXPECT(ammAlice.expectAuctionSlot({carol_})); + env(ammAlice.bid({.account = alice_, .bidMin = IOUAmount{100}})); BEAST_EXPECT(ammAlice.expectAuctionSlot({})); Account const bob("bob"); Account const dan("dan"); - fund(env, {bob, dan}, XRP(1'000)); + fund(env, {bob, dan}, kXRP(1'000)); env(ammAlice.bid({ - .account = alice, + .account = alice_, .bidMin = IOUAmount{100}, .authAccounts = {bob, dan}, })); @@ -3104,36 +3192,36 @@ private: // Bid all tokens, still own the slot and trade at a discount { Env env(*this, features); - fund(env, gw, {alice, bob}, XRP(2'000), {USD(2'000)}); - AMM amm(env, gw, XRP(1'000), USD(1'010), false, 1'000); + fund(env, gw_, {alice_, bob_}, kXRP(2'000), {USD_(2'000)}); + AMM amm(env, gw_, kXRP(1'000), USD_(1'010), false, 1'000); auto const lpIssue = amm.lptIssue(); - env.trust(STAmount{lpIssue, 500}, alice); - env.trust(STAmount{lpIssue, 50}, bob); - env(pay(gw, alice, STAmount{lpIssue, 500})); - env(pay(gw, bob, STAmount{lpIssue, 50})); + env.trust(STAmount{lpIssue, 500}, alice_); + env.trust(STAmount{lpIssue, 50}, bob_); + env(pay(gw_, alice_, STAmount{lpIssue, 500})); + env(pay(gw_, bob_, STAmount{lpIssue, 50})); // Alice doesn't have anymore lp tokens - env(amm.bid({.account = alice, .bidMin = 500})); + env(amm.bid({.account = alice_, .bidMin = 500})); BEAST_EXPECT(amm.expectAuctionSlot(100, 0, IOUAmount{500})); - BEAST_EXPECT(expectHolding(env, alice, STAmount{lpIssue, 0})); + BEAST_EXPECT(expectHolding(env, alice_, STAmount{lpIssue, 0})); // But trades with the discounted fee since she still owns the slot. // Alice pays 10011 drops in fees - env(pay(alice, bob, USD(10)), path(~USD), sendmax(XRP(11))); + env(pay(alice_, bob_, USD_(10)), Path(~USD_), Sendmax(kXRP(11))); BEAST_EXPECT(amm.expectBalances( - XRPAmount{1'010'010'011}, USD(1'000), IOUAmount{1'004'487'562112089, -9})); + XRPAmount{1'010'010'011}, USD_(1'000), IOUAmount{1'004'487'562112089, -9})); // Bob pays the full fee ~0.1USD - env(pay(bob, alice, XRP(10)), path(~XRP), sendmax(USD(11))); + env(pay(bob_, alice_, kXRP(10)), Path(~kXRP), Sendmax(USD_(11))); if (!features[fixAMMv1_1]) { BEAST_EXPECT(amm.expectBalances( XRPAmount{1'000'010'011}, - STAmount{USD, UINT64_C(1'010'10090898081), -11}, + STAmount{USD_, UINT64_C(1'010'10090898081), -11}, IOUAmount{1'004'487'562112089, -9})); } else { BEAST_EXPECT(amm.expectBalances( XRPAmount{1'000'010'011}, - STAmount{USD, UINT64_C(1'010'100908980811), -12}, + STAmount{USD_, UINT64_C(1'010'100908980811), -12}, IOUAmount{1'004'487'562112089, -9})); } } @@ -3143,39 +3231,39 @@ private: Env env(*this, features); auto const baseFee = env.current()->fees().base; - fund(env, gw, {alice, bob}, XRP(2'000), {USD(2'000)}); - AMM amm(env, gw, XRP(1'000), USD(1'010), false, 1'000); - Json::Value const tx = amm.bid({.account = alice, .bidMin = 500}); + fund(env, gw_, {alice_, bob_}, kXRP(2'000), {USD_(2'000)}); + AMM amm(env, gw_, kXRP(1'000), USD_(1'010), false, 1'000); + Json::Value const tx = amm.bid({.account = alice_, .bidMin = 500}); { - auto jtx = env.jt(tx, seq(1), fee(baseFee)); + auto jtx = env.jt(tx, Seq(1), Fee(baseFee)); env.app().config().features.erase(featureAMM); PreflightContext const pfCtx( - env.app(), *jtx.stx, env.current()->rules(), tapNONE, env.journal); + env.app(), *jtx.stx, env.current()->rules(), TapNone, env.journal); auto pf = Transactor::invokePreflight(pfCtx); - BEAST_EXPECT(pf == temDISABLED); + BEAST_EXPECT(pf == TemDisabled); env.app().config().features.insert(featureAMM); } { - auto jtx = env.jt(tx, seq(1), fee(baseFee)); + auto jtx = env.jt(tx, Seq(1), Fee(baseFee)); jtx.jv["TxnSignature"] = "deadbeef"; jtx.stx = env.ust(jtx); PreflightContext const pfCtx( - env.app(), *jtx.stx, env.current()->rules(), tapNONE, env.journal); + env.app(), *jtx.stx, env.current()->rules(), TapNone, env.journal); auto pf = Transactor::invokePreflight(pfCtx); BEAST_EXPECT(!isTesSuccess(pf)); } { - auto jtx = env.jt(tx, seq(1), fee(baseFee)); + auto jtx = env.jt(tx, Seq(1), Fee(baseFee)); jtx.jv["Asset2"]["currency"] = "XRP"; jtx.jv["Asset2"].removeMember("issuer"); jtx.stx = env.ust(jtx); PreflightContext const pfCtx( - env.app(), *jtx.stx, env.current()->rules(), tapNONE, env.journal); + env.app(), *jtx.stx, env.current()->rules(), TapNone, env.journal); auto pf = Transactor::invokePreflight(pfCtx); - BEAST_EXPECT(pf == temBAD_AMM_TOKENS); + BEAST_EXPECT(pf == TemBadAmmTokens); } } } @@ -3190,139 +3278,141 @@ private: // Can't pay into AMM account. // Can't pay out since there is no keys - for (auto const& acct : {gw, alice}) + for (auto const& acct : {gw_, alice_}) { { Env env(*this); - fund(env, gw, {alice, carol}, XRP(1'000), {USD(100)}); + fund(env, gw_, {alice_, carol_}, kXRP(1'000), {USD_(100)}); // XRP balance is below reserve - AMM const ammAlice(env, acct, XRP(10), USD(10)); + AMM const ammAlice(env, acct, kXRP(10), USD_(10)); // Pay below reserve - env(pay(carol, ammAlice.ammAccount(), XRP(10)), ter(tecNO_PERMISSION)); + env(pay(carol_, ammAlice.ammAccount(), kXRP(10)), Ter(TecNoPermission)); // Pay above reserve - env(pay(carol, ammAlice.ammAccount(), XRP(300)), ter(tecNO_PERMISSION)); + env(pay(carol_, ammAlice.ammAccount(), kXRP(300)), Ter(TecNoPermission)); // Pay IOU - env(pay(carol, ammAlice.ammAccount(), USD(10)), ter(tecNO_PERMISSION)); + env(pay(carol_, ammAlice.ammAccount(), USD_(10)), Ter(TecNoPermission)); } { Env env(*this); - fund(env, gw, {alice, carol}, XRP(10'000'000), {USD(10'000)}); + fund(env, gw_, {alice_, carol_}, kXRP(10'000'000), {USD_(10'000)}); // XRP balance is above reserve - AMM const ammAlice(env, acct, XRP(1'000'000), USD(100)); + AMM const ammAlice(env, acct, kXRP(1'000'000), USD_(100)); // Pay below reserve - env(pay(carol, ammAlice.ammAccount(), XRP(10)), ter(tecNO_PERMISSION)); + env(pay(carol_, ammAlice.ammAccount(), kXRP(10)), Ter(TecNoPermission)); // Pay above reserve - env(pay(carol, ammAlice.ammAccount(), XRP(1'000'000)), ter(tecNO_PERMISSION)); + env(pay(carol_, ammAlice.ammAccount(), kXRP(1'000'000)), Ter(TecNoPermission)); } } // Can't pay into AMM with escrow. testAMM([&](AMM& ammAlice, Env& env) { auto const baseFee = env.current()->fees().base; - env(escrow::create(carol, ammAlice.ammAccount(), XRP(1)), - escrow::condition(escrow::cb1), - escrow::finish_time(env.now() + 1s), - escrow::cancel_time(env.now() + 2s), - fee(baseFee * 150), - ter(tecNO_PERMISSION)); + env(escrow::create(carol_, ammAlice.ammAccount(), kXRP(1)), + escrow::kCONDITION(escrow::kCB1), + escrow::kFINISH_TIME(env.now() + 1s), + escrow::kCANCEL_TIME(env.now() + 2s), + Fee(baseFee * 150), + Ter(TecNoPermission)); }); // Can't pay into AMM with paychan. testAMM([&](AMM& ammAlice, Env& env) { - auto const pk = carol.pk(); + auto const pk = carol_.pk(); auto const settleDelay = 100s; NetClock::time_point const cancelAfter = env.current()->header().parentCloseTime + 200s; env(paychan::create( - carol, ammAlice.ammAccount(), XRP(1'000), settleDelay, pk, cancelAfter), - ter(tecNO_PERMISSION)); + carol_, ammAlice.ammAccount(), kXRP(1'000), settleDelay, pk, cancelAfter), + Ter(TecNoPermission)); }); // Can't pay into AMM with checks. testAMM([&](AMM& ammAlice, Env& env) { - env(check::create(env.master.id(), ammAlice.ammAccount(), XRP(100)), - ter(tecNO_PERMISSION)); + env(check::create(env.master.id(), ammAlice.ammAccount(), kXRP(100)), + Ter(TecNoPermission)); }); // Pay amounts close to one side of the pool testAMM( [&](AMM& ammAlice, Env& env) { // Can't consume whole pool - env(pay(alice, carol, USD(100)), - path(~USD), - sendmax(XRP(1'000'000'000)), - ter(tecPATH_PARTIAL)); - env(pay(alice, carol, XRP(100)), - path(~XRP), - sendmax(USD(1'000'000'000)), - ter(tecPATH_PARTIAL)); + env(pay(alice_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(1'000'000'000)), + Ter(TecPathPartial)); + env(pay(alice_, carol_, kXRP(100)), + Path(~kXRP), + Sendmax(USD_(1'000'000'000)), + Ter(TecPathPartial)); // Overflow - env(pay(alice, carol, STAmount{USD, UINT64_C(99'999999999), -9}), - path(~USD), - sendmax(XRP(1'000'000'000)), - ter(tecPATH_PARTIAL)); - env(pay(alice, carol, STAmount{USD, UINT64_C(999'99999999), -8}), - path(~USD), - sendmax(XRP(1'000'000'000)), - ter(tecPATH_PARTIAL)); - env(pay(alice, carol, STAmount{xrpIssue(), 99'999'999}), - path(~XRP), - sendmax(USD(1'000'000'000)), - ter(tecPATH_PARTIAL)); + env(pay(alice_, carol_, STAmount{USD_, UINT64_C(99'999999999), -9}), + Path(~USD_), + Sendmax(kXRP(1'000'000'000)), + Ter(TecPathPartial)); + env(pay(alice_, carol_, STAmount{USD_, UINT64_C(999'99999999), -8}), + Path(~USD_), + Sendmax(kXRP(1'000'000'000)), + Ter(TecPathPartial)); + env(pay(alice_, carol_, STAmount{xrpIssue(), 99'999'999}), + Path(~kXRP), + Sendmax(USD_(1'000'000'000)), + Ter(TecPathPartial)); // Sender doesn't have enough funds - env(pay(alice, carol, USD(99.99)), - path(~USD), - sendmax(XRP(1'000'000'000)), - ter(tecPATH_PARTIAL)); - env(pay(alice, carol, STAmount{xrpIssue(), 99'990'000}), - path(~XRP), - sendmax(USD(1'000'000'000)), - ter(tecPATH_PARTIAL)); + env(pay(alice_, carol_, USD_(99.99)), + Path(~USD_), + Sendmax(kXRP(1'000'000'000)), + Ter(TecPathPartial)); + env(pay(alice_, carol_, STAmount{xrpIssue(), 99'990'000}), + Path(~kXRP), + Sendmax(USD_(1'000'000'000)), + Ter(TecPathPartial)); }, - {{XRP(100), USD(100)}}); + {{kXRP(100), USD_(100)}}); // Globally frozen testAMM([&](AMM& ammAlice, Env& env) { - env(fset(gw, asfGlobalFreeze)); + env(fset(gw_, kASF_GLOBAL_FREEZE)); env.close(); - env(pay(alice, carol, USD(1)), - path(~USD), - txflags(tfPartialPayment | tfNoRippleDirect), - sendmax(XRP(10)), - ter(tecPATH_DRY)); - env(pay(alice, carol, XRP(1)), - path(~XRP), - txflags(tfPartialPayment | tfNoRippleDirect), - sendmax(USD(10)), - ter(tecPATH_DRY)); + env(pay(alice_, carol_, USD_(1)), + Path(~USD_), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT), + Sendmax(kXRP(10)), + Ter(TecPathDry)); + env(pay(alice_, carol_, kXRP(1)), + Path(~kXRP), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT), + Sendmax(USD_(10)), + Ter(TecPathDry)); }); // Individually frozen AMM testAMM([&](AMM& ammAlice, Env& env) { env(trust( - gw, STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); + gw_, + STAmount{Issue{gw_["USD"].currency, ammAlice.ammAccount()}, 0}, + kTF_SET_FREEZE)); env.close(); - env(pay(alice, carol, USD(1)), - path(~USD), - txflags(tfPartialPayment | tfNoRippleDirect), - sendmax(XRP(10)), - ter(tecPATH_DRY)); - env(pay(alice, carol, XRP(1)), - path(~XRP), - txflags(tfPartialPayment | tfNoRippleDirect), - sendmax(USD(10)), - ter(tecPATH_DRY)); + env(pay(alice_, carol_, USD_(1)), + Path(~USD_), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT), + Sendmax(kXRP(10)), + Ter(TecPathDry)); + env(pay(alice_, carol_, kXRP(1)), + Path(~kXRP), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT), + Sendmax(USD_(10)), + Ter(TecPathDry)); }); // Individually frozen accounts testAMM([&](AMM& ammAlice, Env& env) { - env(trust(gw, carol["USD"](0), tfSetFreeze)); - env(trust(gw, alice["USD"](0), tfSetFreeze)); + env(trust(gw_, carol_["USD"](0), kTF_SET_FREEZE)); + env(trust(gw_, alice_["USD"](0), kTF_SET_FREEZE)); env.close(); - env(pay(alice, carol, XRP(1)), - path(~XRP), - sendmax(USD(10)), - txflags(tfNoRippleDirect | tfPartialPayment), - ter(tecPATH_DRY)); + env(pay(alice_, carol_, kXRP(1)), + Path(~kXRP), + Sendmax(USD_(10)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT), + Ter(TecPathDry)); }); } @@ -3341,21 +3431,22 @@ private: // Force one path with tfNoRippleDirect. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); - env(pay(bob, carol, USD(100)), - path(~USD), - sendmax(XRP(100)), - txflags(tfNoRippleDirect)); + env(pay(bob_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(100)), + Txflags(kTF_NO_RIPPLE_DIRECT)); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'100), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'100), USD_(10'000), ammAlice.tokens())); // Initial balance 30,000 + 100 - BEAST_EXPECT(expectHolding(env, carol, USD(30'100))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'100))); // Initial balance 30,000 - 100(sendmax) - 10(tx fee) BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(100) - txfee(env, 1))); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(100) - txfee(env, 1))); }, - {{XRP(10'000), USD(10'100)}}, + {{kXRP(10'000), USD_(10'100)}}, 0, std::nullopt, {features}); @@ -3363,18 +3454,19 @@ private: // Payment 100USD for 100XRP, use default path. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); - env(pay(bob, carol, USD(100)), sendmax(XRP(100))); + env(pay(bob_, carol_, USD_(100)), Sendmax(kXRP(100))); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'100), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'100), USD_(10'000), ammAlice.tokens())); // Initial balance 30,000 + 100 - BEAST_EXPECT(expectHolding(env, carol, USD(30'100))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'100))); // Initial balance 30,000 - 100(sendmax) - 10(tx fee) BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(100) - txfee(env, 1))); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(100) - txfee(env, 1))); }, - {{XRP(10'000), USD(10'100)}}, + {{kXRP(10'000), USD_(10'100)}}, 0, std::nullopt, {features}); @@ -3383,18 +3475,19 @@ private: // both default path and path, activeStrands has one path. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); - env(pay(bob, carol, USD(100)), path(~USD), sendmax(XRP(100))); + env(pay(bob_, carol_, USD_(100)), Path(~USD_), Sendmax(kXRP(100))); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'100), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'100), USD_(10'000), ammAlice.tokens())); // Initial balance 30,000 + 100 - BEAST_EXPECT(expectHolding(env, carol, USD(30'100))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'100))); // Initial balance 30,000 - 100(sendmax) - 10(tx fee) BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(100) - txfee(env, 1))); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(100) - txfee(env, 1))); }, - {{XRP(10'000), USD(10'100)}}, + {{kXRP(10'000), USD_(10'100)}}, 0, std::nullopt, {features}); @@ -3402,33 +3495,34 @@ private: // Payment with limitQuality set. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); // Pays 10USD for 10XRP. A larger payment of ~99.11USD/100XRP // would have been sent has it not been for limitQuality. - env(pay(bob, carol, USD(100)), - path(~USD), - sendmax(XRP(100)), - txflags(tfNoRippleDirect | tfPartialPayment | tfLimitQuality)); + env(pay(bob_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(100)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT | kTF_LIMIT_QUALITY)); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'010), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'010), USD_(10'000), ammAlice.tokens())); // Initial balance 30,000 + 10(limited by limitQuality) - BEAST_EXPECT(expectHolding(env, carol, USD(30'010))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'010))); // Initial balance 30,000 - 10(limited by limitQuality) - 10(tx // fee) BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(10) - txfee(env, 1))); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(10) - txfee(env, 1))); // Fails because of limitQuality. Would have sent // ~98.91USD/110XRP has it not been for limitQuality. - env(pay(bob, carol, USD(100)), - path(~USD), - sendmax(XRP(100)), - txflags(tfNoRippleDirect | tfPartialPayment | tfLimitQuality), - ter(tecPATH_DRY)); + env(pay(bob_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(100)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT | kTF_LIMIT_QUALITY), + Ter(TecPathDry)); env.close(); }, - {{XRP(10'000), USD(10'010)}}, + {{kXRP(10'000), USD_(10'010)}}, 0, std::nullopt, {features}); @@ -3436,26 +3530,27 @@ private: // Payment with limitQuality and transfer fee set. testAMM( [&](AMM& ammAlice, Env& env) { - env(rate(gw, 1.1)); + env(rate(gw_, 1.1)); env.close(); - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); // Pays 10USD for 10XRP. A larger payment of ~99.11USD/100XRP // would have been sent has it not been for limitQuality and // the transfer fee. - env(pay(bob, carol, USD(100)), - path(~USD), - sendmax(XRP(110)), - txflags(tfNoRippleDirect | tfPartialPayment | tfLimitQuality)); + env(pay(bob_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(110)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT | kTF_LIMIT_QUALITY)); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'010), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'010), USD_(10'000), ammAlice.tokens())); // 10USD - 10% transfer fee BEAST_EXPECT( - expectHolding(env, carol, STAmount{USD, UINT64_C(30'009'09090909091), -11})); + expectHolding(env, carol_, STAmount{USD_, UINT64_C(30'009'09090909091), -11})); BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(10) - txfee(env, 1))); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(10) - txfee(env, 1))); }, - {{XRP(10'000), USD(10'010)}}, + {{kXRP(10'000), USD_(10'010)}}, 0, std::nullopt, {features}); @@ -3463,15 +3558,15 @@ private: // Fail when partial payment is not set. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(jtx::XRP(30'000), bob); + env.fund(jtx::kXRP(30'000), bob_); env.close(); - env(pay(bob, carol, USD(100)), - path(~USD), - sendmax(XRP(100)), - txflags(tfNoRippleDirect), - ter(tecPATH_PARTIAL)); + env(pay(bob_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(100)), + Txflags(kTF_NO_RIPPLE_DIRECT), + Ter(TecPathPartial)); }, - {{XRP(10'000), USD(10'000)}}, + {{kXRP(10'000), USD_(10'000)}}, 0, std::nullopt, {features}); @@ -3482,60 +3577,60 @@ private: // is taken from the offer. { Env env(*this, features); - fund(env, gw, {alice, carol}, {USD(30'000), EUR(30'000)}, Fund::All); + fund(env, gw_, {alice_, carol_}, {USD_(30'000), EUR_(30'000)}, Fund::All); env.close(); - env.fund(XRP(1'000), bob); + env.fund(kXRP(1'000), bob_); env.close(); - auto ammEUR_XRP = AMM(env, alice, XRP(10'000), EUR(10'000)); - auto ammUSD_EUR = AMM(env, alice, EUR(10'000), USD(10'000)); - env(offer(alice, XRP(101), USD(100)), txflags(tfPassive)); + auto ammEurXrp = AMM(env, alice_, kXRP(10'000), EUR_(10'000)); + auto ammUsdEur = AMM(env, alice_, EUR_(10'000), USD_(10'000)); + env(offer(alice_, kXRP(101), USD_(100)), Txflags(kTF_PASSIVE)); env.close(); - env(pay(bob, carol, USD(100)), - path(~EUR, ~USD), - sendmax(XRP(102)), - txflags(tfPartialPayment)); + env(pay(bob_, carol_, USD_(100)), + Path(~EUR_, ~USD_), + Sendmax(kXRP(102)), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); - BEAST_EXPECT(ammEUR_XRP.expectBalances( + BEAST_EXPECT(ammEurXrp.expectBalances( XRPAmount(10'030'082'730), - STAmount(EUR, UINT64_C(9'970'007498125468), -12), - ammEUR_XRP.tokens())); + STAmount(EUR_, UINT64_C(9'970'007498125468), -12), + ammEurXrp.tokens())); if (!features[fixAMMv1_1]) { - BEAST_EXPECT(ammUSD_EUR.expectBalances( - STAmount(USD, UINT64_C(9'970'097277662122), -12), - STAmount(EUR, UINT64_C(10'029'99250187452), -11), - ammUSD_EUR.tokens())); + BEAST_EXPECT(ammUsdEur.expectBalances( + STAmount(USD_, UINT64_C(9'970'097277662122), -12), + STAmount(EUR_, UINT64_C(10'029'99250187452), -11), + ammUsdEur.tokens())); // fixReducedOffersV2 changes the expected results slightly. Amounts const expectedAmounts = env.closed()->rules().enabled(fixReducedOffersV2) - ? Amounts{XRPAmount(30'201'749), STAmount(USD, UINT64_C(29'90272233787816), -14)} + ? Amounts{XRPAmount(30'201'749), STAmount(USD_, UINT64_C(29'90272233787816), -14)} : Amounts{ - XRPAmount(30'201'749), STAmount(USD, UINT64_C(29'90272233787818), -14)}; + XRPAmount(30'201'749), STAmount(USD_, UINT64_C(29'90272233787818), -14)}; - BEAST_EXPECT(expectOffers(env, alice, 1, {{expectedAmounts}})); + BEAST_EXPECT(expectOffers(env, alice_, 1, {{expectedAmounts}})); } else { - BEAST_EXPECT(ammUSD_EUR.expectBalances( - STAmount(USD, UINT64_C(9'970'097277662172), -12), - STAmount(EUR, UINT64_C(10'029'99250187452), -11), - ammUSD_EUR.tokens())); + BEAST_EXPECT(ammUsdEur.expectBalances( + STAmount(USD_, UINT64_C(9'970'097277662172), -12), + STAmount(EUR_, UINT64_C(10'029'99250187452), -11), + ammUsdEur.tokens())); // fixReducedOffersV2 changes the expected results slightly. Amounts const expectedAmounts = env.closed()->rules().enabled(fixReducedOffersV2) - ? Amounts{XRPAmount(30'201'749), STAmount(USD, UINT64_C(29'90272233782839), -14)} + ? Amounts{XRPAmount(30'201'749), STAmount(USD_, UINT64_C(29'90272233782839), -14)} : Amounts{ - XRPAmount(30'201'749), STAmount(USD, UINT64_C(29'90272233782840), -14)}; + XRPAmount(30'201'749), STAmount(USD_, UINT64_C(29'90272233782840), -14)}; - BEAST_EXPECT(expectOffers(env, alice, 1, {{expectedAmounts}})); + BEAST_EXPECT(expectOffers(env, alice_, 1, {{expectedAmounts}})); } // Initial 30,000 + 100 - BEAST_EXPECT(expectHolding(env, carol, STAmount{USD, 30'100})); + BEAST_EXPECT(expectHolding(env, carol_, STAmount{USD_, 30'100})); // Initial 1,000 - 30082730(AMM pool) - 70798251(offer) - 10(tx fee) BEAST_EXPECT(expectLedgerEntryRoot( env, - bob, - XRP(1'000) - XRPAmount{30'082'730} - XRPAmount{70'798'251} - txfee(env, 1))); + bob_, + kXRP(1'000) - XRPAmount{30'082'730} - XRPAmount{70'798'251} - txfee(env, 1))); } // Default path (with AMM) has a better quality than a non-default path. @@ -3543,41 +3638,41 @@ private: // path ~49XRP/49USD. The rest is taken from the offer. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(XRP(1'000), bob); + env.fund(kXRP(1'000), bob_); env.close(); - env.trust(EUR(2'000), alice); + env.trust(EUR_(2'000), alice_); env.close(); - env(pay(gw, alice, EUR(1'000))); - env(offer(alice, XRP(101), EUR(100)), txflags(tfPassive)); + env(pay(gw_, alice_, EUR_(1'000))); + env(offer(alice_, kXRP(101), EUR_(100)), Txflags(kTF_PASSIVE)); env.close(); - env(offer(alice, EUR(100), USD(100)), txflags(tfPassive)); + env(offer(alice_, EUR_(100), USD_(100)), Txflags(kTF_PASSIVE)); env.close(); - env(pay(bob, carol, USD(100)), - path(~EUR, ~USD), - sendmax(XRP(102)), - txflags(tfPartialPayment)); + env(pay(bob_, carol_, USD_(100)), + Path(~EUR_, ~USD_), + Sendmax(kXRP(102)), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount(10'050'238'637), - STAmount(USD, UINT64_C(9'950'01249687578), -11), + STAmount(USD_, UINT64_C(9'950'01249687578), -11), ammAlice.tokens())); BEAST_EXPECT(expectOffers( env, - alice, + alice_, 2, - {{Amounts{XRPAmount(50'487'378), STAmount(EUR, UINT64_C(49'98750312422), -11)}, + {{Amounts{XRPAmount(50'487'378), STAmount(EUR_, UINT64_C(49'98750312422), -11)}, Amounts{ - STAmount(EUR, UINT64_C(49'98750312422), -11), - STAmount(USD, UINT64_C(49'98750312422), -11)}}})); + STAmount(EUR_, UINT64_C(49'98750312422), -11), + STAmount(USD_, UINT64_C(49'98750312422), -11)}}})); // Initial 30,000 + 99.99999999999 BEAST_EXPECT( - expectHolding(env, carol, STAmount{USD, UINT64_C(30'099'99999999999), -11})); + expectHolding(env, carol_, STAmount{USD_, UINT64_C(30'099'99999999999), -11})); // Initial 1,000 - 50238637(AMM pool) - 50512622(offer) - 10(tx // fee) BEAST_EXPECT(expectLedgerEntryRoot( env, - bob, - XRP(1'000) - XRPAmount{50'238'637} - XRPAmount{50'512'622} - txfee(env, 1))); + bob_, + kXRP(1'000) - XRPAmount{50'238'637} - XRPAmount{50'512'622} - txfee(env, 1))); }, std::nullopt, 0, @@ -3588,38 +3683,40 @@ private: // remaining amount is consumed by the offer. testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, {USD(100)}, Fund::Acct); + fund(env, gw_, {bob_}, {USD_(100)}, Fund::Acct); env.close(); - env(offer(bob, XRP(100), USD(100)), txflags(tfPassive)); + env(offer(bob_, kXRP(100), USD_(100)), Txflags(kTF_PASSIVE)); env.close(); - env(pay(alice, carol, USD(200)), sendmax(XRP(200)), txflags(tfPartialPayment)); + env(pay(alice_, carol_, USD_(200)), + Sendmax(kXRP(200)), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); if (!features[fixAMMv1_1]) { BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'100), USD(10'000), ammAlice.tokens())); + ammAlice.expectBalances(kXRP(10'100), USD_(10'000), ammAlice.tokens())); // Initial 30,000 + 200 - BEAST_EXPECT(expectHolding(env, carol, USD(30'200))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'200))); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'100), - STAmount(USD, UINT64_C(10'000'00000000001), -11), + kXRP(10'100), + STAmount(USD_, UINT64_C(10'000'00000000001), -11), ammAlice.tokens())); BEAST_EXPECT(expectHolding( - env, carol, STAmount(USD, UINT64_C(30'199'99999999999), -11))); + env, carol_, STAmount(USD_, UINT64_C(30'199'99999999999), -11))); } // Initial 30,000 - 10000(AMM pool LP) - 100(AMM offer) - // - 100(offer) - 10(tx fee) - one reserve BEAST_EXPECT(expectLedgerEntryRoot( env, - alice, - XRP(30'000) - XRP(10'000) - XRP(100) - XRP(100) - ammCrtFee(env) - + alice_, + kXRP(30'000) - kXRP(10'000) - kXRP(100) - kXRP(100) - ammCrtFee(env) - txfee(env, 1))); - BEAST_EXPECT(expectOffers(env, bob, 0)); + BEAST_EXPECT(expectOffers(env, bob_, 0)); }, - {{XRP(10'000), USD(10'100)}}, + {{kXRP(10'000), USD_(10'100)}}, 0, std::nullopt, {features}); @@ -3629,34 +3726,35 @@ private: // Remaining amount is consumed by AMM. { Env env(*this, features); - fund(env, gw, {alice, bob, carol}, XRP(20'000), {USD(2'000)}); + fund(env, gw_, {alice_, bob_, carol_}, kXRP(20'000), {USD_(2'000)}); env.close(); - env(offer(bob, XRP(50), USD(150)), txflags(tfPassive)); + env(offer(bob_, kXRP(50), USD_(150)), Txflags(kTF_PASSIVE)); env.close(); - AMM const ammAlice(env, alice, XRP(1'000), USD(1'050)); - env(pay(alice, carol, USD(200)), sendmax(XRP(200)), txflags(tfPartialPayment)); + AMM const ammAlice(env, alice_, kXRP(1'000), USD_(1'050)); + env(pay(alice_, carol_, USD_(200)), Sendmax(kXRP(200)), Txflags(kTF_PARTIAL_PAYMENT)); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(1'050), USD(1'000), ammAlice.tokens())); - BEAST_EXPECT(expectHolding(env, carol, USD(2'200))); - BEAST_EXPECT(expectOffers(env, bob, 0)); + BEAST_EXPECT(ammAlice.expectBalances(kXRP(1'050), USD_(1'000), ammAlice.tokens())); + BEAST_EXPECT(expectHolding(env, carol_, USD_(2'200))); + BEAST_EXPECT(expectOffers(env, bob_, 0)); } // Offer crossing XRP/IOU testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, {USD(1'000)}, Fund::Acct); + fund(env, gw_, {bob_}, {USD_(1'000)}, Fund::Acct); env.close(); - env(offer(bob, USD(100), XRP(100))); + env(offer(bob_, USD_(100), kXRP(100))); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'100), USD(10'000), ammAlice.tokens())); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'100), USD_(10'000), ammAlice.tokens())); // Initial 1,000 + 100 - BEAST_EXPECT(expectHolding(env, bob, USD(1'100))); + BEAST_EXPECT(expectHolding(env, bob_, USD_(1'100))); // Initial 30,000 - 100(offer) - 10(tx fee) BEAST_EXPECT( - expectLedgerEntryRoot(env, bob, XRP(30'000) - XRP(100) - txfee(env, 1))); - BEAST_EXPECT(expectOffers(env, bob, 0)); + expectLedgerEntryRoot(env, bob_, kXRP(30'000) - kXRP(100) - txfee(env, 1))); + BEAST_EXPECT(expectOffers(env, bob_, 0)); }, - {{XRP(10'000), USD(10'100)}}, + {{kXRP(10'000), USD_(10'100)}}, 0, std::nullopt, {features}); @@ -3665,32 +3763,32 @@ private: // Single path AMM offer testAMM( [&](AMM& ammAlice, Env& env) { - env(rate(gw, 1.25)); + env(rate(gw_, 1.25)); env.close(); // This offer succeeds to cross pre- and post-amendment // because the strand's out amount is small enough to match // limitQuality value and limitOut() function in StrandFlow // doesn't require an adjustment to out value. - env(offer(carol, EUR(100), GBP(100))); + env(offer(carol_, EUR_(100), GBP_(100))); env.close(); // No transfer fee - BEAST_EXPECT(ammAlice.expectBalances(GBP(1'100), EUR(1'000), ammAlice.tokens())); + BEAST_EXPECT(ammAlice.expectBalances(GBP_(1'100), EUR_(1'000), ammAlice.tokens())); // Initial 30,000 - 100(offer) - 25% transfer fee - BEAST_EXPECT(expectHolding(env, carol, GBP(29'875))); + BEAST_EXPECT(expectHolding(env, carol_, GBP_(29'875))); // Initial 30,000 + 100(offer) - BEAST_EXPECT(expectHolding(env, carol, EUR(30'100))); - BEAST_EXPECT(expectOffers(env, bob, 0)); + BEAST_EXPECT(expectHolding(env, carol_, EUR_(30'100))); + BEAST_EXPECT(expectOffers(env, bob_, 0)); }, - {{GBP(1'000), EUR(1'100)}}, + {{GBP_(1'000), EUR_(1'100)}}, 0, std::nullopt, {features}); // Single-path AMM offer testAMM( [&](AMM& amm, Env& env) { - env(rate(gw, 1.001)); + env(rate(gw_, 1.001)); env.close(); - env(offer(carol, XRP(100), USD(55))); + env(offer(carol_, kXRP(100), USD_(55))); env.close(); if (!features[fixAMMv1_1]) { @@ -3701,8 +3799,8 @@ private: // on higher limit out, which generates a larger offer // with lower quality. Consequently, the offer fails // to cross. - BEAST_EXPECT(amm.expectBalances(XRP(1'000), USD(500), amm.tokens())); - BEAST_EXPECT(expectOffers(env, carol, 1, {{Amounts{XRP(100), USD(55)}}})); + BEAST_EXPECT(amm.expectBalances(kXRP(1'000), USD_(500), amm.tokens())); + BEAST_EXPECT(expectOffers(env, carol_, 1, {{Amounts{kXRP(100), USD_(55)}}})); } else { @@ -3715,44 +3813,44 @@ private: // AMM offer ~50USD/91XRP BEAST_EXPECT(amm.expectBalances( XRPAmount(909'090'909), - STAmount{USD, UINT64_C(550'000000055), -9}, + STAmount{USD_, UINT64_C(550'000000055), -9}, amm.tokens())); // Offer ~91XRP/49.99USD BEAST_EXPECT(expectOffers( env, - carol, + carol_, 1, - {{Amounts{XRPAmount{9'090'909}, STAmount{USD, 4'99999995, -8}}}})); + {{Amounts{XRPAmount{9'090'909}, STAmount{USD_, 4'99999995, -8}}}})); // Carol pays 0.1% fee on ~50USD =~ 0.05USD BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(29'949'94999999494), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(29'949'94999999494), -11)); } }, - {{XRP(1'000), USD(500)}}, + {{kXRP(1'000), USD_(500)}}, 0, std::nullopt, {features}); testAMM( [&](AMM& amm, Env& env) { - env(rate(gw, 1.001)); + env(rate(gw_, 1.001)); env.close(); - env(offer(carol, XRP(10), USD(5.5))); + env(offer(carol_, kXRP(10), USD_(5.5))); env.close(); if (!features[fixAMMv1_1]) { BEAST_EXPECT(amm.expectBalances( - XRP(990), STAmount{USD, UINT64_C(505'050505050505), -12}, amm.tokens())); - BEAST_EXPECT(expectOffers(env, carol, 0)); + kXRP(990), STAmount{USD_, UINT64_C(505'050505050505), -12}, amm.tokens())); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } else { BEAST_EXPECT(amm.expectBalances( - XRP(990), STAmount{USD, UINT64_C(505'0505050505051), -13}, amm.tokens())); - BEAST_EXPECT(expectOffers(env, carol, 0)); + kXRP(990), STAmount{USD_, UINT64_C(505'0505050505051), -13}, amm.tokens())); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } }, - {{XRP(1'000), USD(500)}}, + {{kXRP(1'000), USD_(500)}}, 0, std::nullopt, {features}); @@ -3760,8 +3858,8 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { Account const ed("ed"); - fund(env, gw, {bob, ed}, XRP(30'000), {GBP(2'000), EUR(2'000)}, Fund::Acct); - env(rate(gw, 1.25)); + fund(env, gw_, {bob_, ed}, kXRP(30'000), {GBP_(2'000), EUR_(2'000)}, Fund::Acct); + env(rate(gw_, 1.25)); env.close(); // The auto-bridge is worse quality than AMM, is not consumed // first and initially forces multi-path AMM offer generation. @@ -3769,10 +3867,10 @@ private: // is less than the auto-bridge offers quality. Auto-bridge // offers are consumed afterward. Then the behavior is // different pre-amendment and post-amendment. - env(offer(bob, GBP(10), XRP(10)), txflags(tfPassive)); - env(offer(ed, XRP(10), EUR(10)), txflags(tfPassive)); + env(offer(bob_, GBP_(10), kXRP(10)), Txflags(kTF_PASSIVE)); + env(offer(ed, kXRP(10), EUR_(10)), Txflags(kTF_PASSIVE)); env.close(); - env(offer(carol, EUR(100), GBP(100))); + env(offer(carol_, EUR_(100), GBP_(100))); env.close(); if (!features[fixAMMv1_1]) { @@ -3783,18 +3881,18 @@ private: // and the single path AMM offer fails to consume. // Total consumed ~37.06GBP/39.32EUR BEAST_EXPECT(ammAlice.expectBalances( - STAmount{GBP, UINT64_C(1'037'06583722133), -11}, - STAmount{EUR, UINT64_C(1'060'684828792831), -12}, + STAmount{GBP_, UINT64_C(1'037'06583722133), -11}, + STAmount{EUR_, UINT64_C(1'060'684828792831), -12}, ammAlice.tokens())); // Consumed offer ~49.32EUR/49.32GBP BEAST_EXPECT(expectOffers( env, - carol, + carol_, 1, {Amounts{ - STAmount{EUR, UINT64_C(50'684828792831), -12}, - STAmount{GBP, UINT64_C(50'684828792831), -12}}})); - BEAST_EXPECT(expectOffers(env, bob, 0)); + STAmount{EUR_, UINT64_C(50'684828792831), -12}, + STAmount{GBP_, UINT64_C(50'684828792831), -12}}})); + BEAST_EXPECT(expectOffers(env, bob_, 0)); BEAST_EXPECT(expectOffers(env, ed, 0)); // Initial 30,000 - ~47.06(offers = 37.06(AMM) + 10(LOB)) @@ -3803,10 +3901,10 @@ private: // carol bought ~72.93EUR at the cost of ~70.68GBP // the offer is partially consumed BEAST_EXPECT(expectHolding( - env, carol, STAmount{GBP, UINT64_C(29'941'16770347333), -11})); + env, carol_, STAmount{GBP_, UINT64_C(29'941'16770347333), -11})); // Initial 30,000 + ~49.3(offers = 39.3(AMM) + 10(LOB)) BEAST_EXPECT(expectHolding( - env, carol, STAmount{EUR, UINT64_C(30'049'31517120716), -11})); + env, carol_, STAmount{EUR_, UINT64_C(30'049'31517120716), -11})); } else { @@ -3818,18 +3916,18 @@ private: // liquidity is consumed overall in post-amendment. // Total consumed ~60.68GBP/62.93EUR BEAST_EXPECT(ammAlice.expectBalances( - STAmount{GBP, UINT64_C(1'060'684828792832), -12}, - STAmount{EUR, UINT64_C(1'037'06583722134), -11}, + STAmount{GBP_, UINT64_C(1'060'684828792832), -12}, + STAmount{EUR_, UINT64_C(1'037'06583722134), -11}, ammAlice.tokens())); // Consumed offer ~72.93EUR/72.93GBP BEAST_EXPECT(expectOffers( env, - carol, + carol_, 1, {Amounts{ - STAmount{EUR, UINT64_C(27'06583722134028), -14}, - STAmount{GBP, UINT64_C(27'06583722134028), -14}}})); - BEAST_EXPECT(expectOffers(env, bob, 0)); + STAmount{EUR_, UINT64_C(27'06583722134028), -14}, + STAmount{GBP_, UINT64_C(27'06583722134028), -14}}})); + BEAST_EXPECT(expectOffers(env, bob_, 0)); BEAST_EXPECT(expectOffers(env, ed, 0)); // Initial 30,000 - ~70.68(offers = 60.68(AMM) + 10(LOB)) @@ -3838,17 +3936,17 @@ private: // carol bought ~72.93EUR at the cost of ~70.68GBP // the offer is partially consumed BEAST_EXPECT(expectHolding( - env, carol, STAmount{GBP, UINT64_C(29'911'64396400896), -11})); + env, carol_, STAmount{GBP_, UINT64_C(29'911'64396400896), -11})); // Initial 30,000 + ~72.93(offers = 62.93(AMM) + 10(LOB)) BEAST_EXPECT(expectHolding( - env, carol, STAmount{EUR, UINT64_C(30'072'93416277865), -11})); + env, carol_, STAmount{EUR_, UINT64_C(30'072'93416277865), -11})); } // Initial 2000 + 10 = 2010 - BEAST_EXPECT(expectHolding(env, bob, GBP(2'010))); + BEAST_EXPECT(expectHolding(env, bob_, GBP_(2'010))); // Initial 2000 - 10 * 1.25 = 1987.5 - BEAST_EXPECT(expectHolding(env, ed, EUR(1'987.5))); + BEAST_EXPECT(expectHolding(env, ed, EUR_(1'987.5))); }, - {{GBP(1'000), EUR(1'100)}}, + {{GBP_(1'000), EUR_(1'100)}}, 0, std::nullopt, {features}); @@ -3862,19 +3960,19 @@ private: // 100EUR/1.25 = 80EUR paid to carol testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, {GBP(200), EUR(200)}, Fund::Acct); - env(rate(gw, 1.25)); + fund(env, gw_, {bob_}, {GBP_(200), EUR_(200)}, Fund::Acct); + env(rate(gw_, 1.25)); env.close(); - env(pay(bob, carol, EUR(100)), - path(~EUR), - sendmax(GBP(125)), - txflags(tfPartialPayment)); + env(pay(bob_, carol_, EUR_(100)), + Path(~EUR_), + Sendmax(GBP_(125)), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); - BEAST_EXPECT(ammAlice.expectBalances(GBP(1'100), EUR(1'000), ammAlice.tokens())); - BEAST_EXPECT(expectHolding(env, bob, GBP(75))); - BEAST_EXPECT(expectHolding(env, carol, EUR(30'080))); + BEAST_EXPECT(ammAlice.expectBalances(GBP_(1'100), EUR_(1'000), ammAlice.tokens())); + BEAST_EXPECT(expectHolding(env, bob_, GBP_(75))); + BEAST_EXPECT(expectHolding(env, carol_, EUR_(30'080))); }, - {{GBP(1'000), EUR(1'100)}}, + {{GBP_(1'000), EUR_(1'100)}}, 0, std::nullopt, {features}); @@ -3894,28 +3992,29 @@ private: [&](AMM& ammAlice, Env& env) { Account const dan("dan"); Account const ed("ed"); - auto const CAN = gw["CAN"]; - fund(env, gw, {dan}, {CAN(200), GBP(200)}, Fund::Acct); - fund(env, gw, {ed}, {EUR(200), USD(200)}, Fund::Acct); - fund(env, gw, {bob}, {CAN(195.3125)}, Fund::Acct); - env(trust(carol, USD(100))); - env(rate(gw, 1.25)); + auto const can = gw_["CAN"]; + fund(env, gw_, {dan}, {can(200), GBP_(200)}, Fund::Acct); + fund(env, gw_, {ed}, {EUR_(200), USD_(200)}, Fund::Acct); + fund(env, gw_, {bob_}, {can(195.3125)}, Fund::Acct); + env(trust(carol_, USD_(100))); + env(rate(gw_, 1.25)); env.close(); - env(offer(dan, CAN(200), GBP(200))); - env(offer(ed, EUR(200), USD(200))); + env(offer(dan, can(200), GBP_(200))); + env(offer(ed, EUR_(200), USD_(200))); env.close(); - env(pay(bob, carol, USD(100)), - path(~GBP, ~EUR, ~USD), - sendmax(CAN(195.3125)), - txflags(tfPartialPayment)); + env(pay(bob_, carol_, USD_(100)), + Path(~GBP_, ~EUR_, ~USD_), + Sendmax(can(195.3125)), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); - BEAST_EXPECT(expectHolding(env, bob, CAN(0))); - BEAST_EXPECT(expectHolding(env, dan, CAN(356.25), GBP(43.75))); - BEAST_EXPECT(ammAlice.expectBalances(GBP(10'125), EUR(10'000), ammAlice.tokens())); - BEAST_EXPECT(expectHolding(env, ed, EUR(300), USD(100))); - BEAST_EXPECT(expectHolding(env, carol, USD(80))); + BEAST_EXPECT(expectHolding(env, bob_, can(0))); + BEAST_EXPECT(expectHolding(env, dan, can(356.25), GBP_(43.75))); + BEAST_EXPECT( + ammAlice.expectBalances(GBP_(10'125), EUR_(10'000), ammAlice.tokens())); + BEAST_EXPECT(expectHolding(env, ed, EUR_(300), USD_(100))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(80))); }, - {{GBP(10'000), EUR(10'125)}}, + {{GBP_(10'000), EUR_(10'125)}}, 0, std::nullopt, {features}); @@ -3923,28 +4022,28 @@ private: // Pay amounts close to one side of the pool testAMM( [&](AMM& ammAlice, Env& env) { - env(pay(alice, carol, USD(99.99)), - path(~USD), - sendmax(XRP(1)), - txflags(tfPartialPayment), - ter(tesSUCCESS)); - env(pay(alice, carol, USD(100)), - path(~USD), - sendmax(XRP(1)), - txflags(tfPartialPayment), - ter(tesSUCCESS)); - env(pay(alice, carol, XRP(100)), - path(~XRP), - sendmax(USD(1)), - txflags(tfPartialPayment), - ter(tesSUCCESS)); - env(pay(alice, carol, STAmount{xrpIssue(), 99'999'900}), - path(~XRP), - sendmax(USD(1)), - txflags(tfPartialPayment), - ter(tesSUCCESS)); + env(pay(alice_, carol_, USD_(99.99)), + Path(~USD_), + Sendmax(kXRP(1)), + Txflags(kTF_PARTIAL_PAYMENT), + Ter(TesSuccess)); + env(pay(alice_, carol_, USD_(100)), + Path(~USD_), + Sendmax(kXRP(1)), + Txflags(kTF_PARTIAL_PAYMENT), + Ter(TesSuccess)); + env(pay(alice_, carol_, kXRP(100)), + Path(~kXRP), + Sendmax(USD_(1)), + Txflags(kTF_PARTIAL_PAYMENT), + Ter(TesSuccess)); + env(pay(alice_, carol_, STAmount{xrpIssue(), 99'999'900}), + Path(~kXRP), + Sendmax(USD_(1)), + Txflags(kTF_PARTIAL_PAYMENT), + Ter(TesSuccess)); }, - {{XRP(100), USD(100)}}, + {{kXRP(100), USD_(100)}}, 0, std::nullopt, {features}); @@ -3952,69 +4051,69 @@ private: // Multiple paths/steps { Env env(*this, features); - auto const ETH = gw["ETH"]; + auto const eth = gw_["ETH"]; fund( env, - gw, - {alice}, - XRP(100'000), - {EUR(50'000), BTC(50'000), ETH(50'000), USD(50'000)}); - fund(env, gw, {carol, bob}, XRP(1'000), {USD(200)}, Fund::Acct); - AMM const xrp_eur(env, alice, XRP(10'100), EUR(10'000)); - AMM const eur_btc(env, alice, EUR(10'000), BTC(10'200)); - AMM const btc_usd(env, alice, BTC(10'100), USD(10'000)); - AMM const xrp_usd(env, alice, XRP(10'150), USD(10'200)); - AMM const xrp_eth(env, alice, XRP(10'000), ETH(10'100)); - AMM const eth_eur(env, alice, ETH(10'900), EUR(11'000)); - AMM const eur_usd(env, alice, EUR(10'100), USD(10'000)); - env(pay(bob, carol, USD(100)), - path(~EUR, ~BTC, ~USD), - path(~USD), - path(~ETH, ~EUR, ~USD), - sendmax(XRP(200))); + gw_, + {alice_}, + kXRP(100'000), + {EUR_(50'000), BTC_(50'000), eth(50'000), USD_(50'000)}); + fund(env, gw_, {carol_, bob_}, kXRP(1'000), {USD_(200)}, Fund::Acct); + AMM const xrpEur(env, alice_, kXRP(10'100), EUR_(10'000)); + AMM const eurBtc(env, alice_, EUR_(10'000), BTC_(10'200)); + AMM const btcUsd(env, alice_, BTC_(10'100), USD_(10'000)); + AMM const xrpUsd(env, alice_, kXRP(10'150), USD_(10'200)); + AMM const xrpEth(env, alice_, kXRP(10'000), eth(10'100)); + AMM const ethEur(env, alice_, eth(10'900), EUR_(11'000)); + AMM const eurUsd(env, alice_, EUR_(10'100), USD_(10'000)); + env(pay(bob_, carol_, USD_(100)), + Path(~EUR_, ~BTC_, ~USD_), + Path(~USD_), + Path(~eth, ~EUR_, ~USD_), + Sendmax(kXRP(200))); if (!features[fixAMMv1_1]) { // XRP-ETH-EUR-USD // This path provides ~26.06USD/26.2XRP - BEAST_EXPECT(xrp_eth.expectBalances( + BEAST_EXPECT(xrpEth.expectBalances( XRPAmount(10'026'208'900), - STAmount{ETH, UINT64_C(10'073'65779244494), -11}, - xrp_eth.tokens())); - BEAST_EXPECT(eth_eur.expectBalances( - STAmount{ETH, UINT64_C(10'926'34220755506), -11}, - STAmount{EUR, UINT64_C(10'973'54232078752), -11}, - eth_eur.tokens())); - BEAST_EXPECT(eur_usd.expectBalances( - STAmount{EUR, UINT64_C(10'126'45767921248), -11}, - STAmount{USD, UINT64_C(9'973'93151712086), -11}, - eur_usd.tokens())); + STAmount{eth, UINT64_C(10'073'65779244494), -11}, + xrpEth.tokens())); + BEAST_EXPECT(ethEur.expectBalances( + STAmount{eth, UINT64_C(10'926'34220755506), -11}, + STAmount{EUR_, UINT64_C(10'973'54232078752), -11}, + ethEur.tokens())); + BEAST_EXPECT(eurUsd.expectBalances( + STAmount{EUR_, UINT64_C(10'126'45767921248), -11}, + STAmount{USD_, UINT64_C(9'973'93151712086), -11}, + eurUsd.tokens())); // XRP-USD path // This path provides ~73.9USD/74.1XRP - BEAST_EXPECT(xrp_usd.expectBalances( + BEAST_EXPECT(xrpUsd.expectBalances( XRPAmount(10'224'106'246), - STAmount{USD, UINT64_C(10'126'06848287914), -11}, - xrp_usd.tokens())); + STAmount{USD_, UINT64_C(10'126'06848287914), -11}, + xrpUsd.tokens())); } else { - BEAST_EXPECT(xrp_eth.expectBalances( + BEAST_EXPECT(xrpEth.expectBalances( XRPAmount(10'026'208'900), - STAmount{ETH, UINT64_C(10'073'65779244461), -11}, - xrp_eth.tokens())); - BEAST_EXPECT(eth_eur.expectBalances( - STAmount{ETH, UINT64_C(10'926'34220755539), -11}, - STAmount{EUR, UINT64_C(10'973'5423207872), -10}, - eth_eur.tokens())); - BEAST_EXPECT(eur_usd.expectBalances( - STAmount{EUR, UINT64_C(10'126'4576792128), -10}, - STAmount{USD, UINT64_C(9'973'93151712057), -11}, - eur_usd.tokens())); + STAmount{eth, UINT64_C(10'073'65779244461), -11}, + xrpEth.tokens())); + BEAST_EXPECT(ethEur.expectBalances( + STAmount{eth, UINT64_C(10'926'34220755539), -11}, + STAmount{EUR_, UINT64_C(10'973'5423207872), -10}, + ethEur.tokens())); + BEAST_EXPECT(eurUsd.expectBalances( + STAmount{EUR_, UINT64_C(10'126'4576792128), -10}, + STAmount{USD_, UINT64_C(9'973'93151712057), -11}, + eurUsd.tokens())); // XRP-USD path // This path provides ~73.9USD/74.1XRP - BEAST_EXPECT(xrp_usd.expectBalances( + BEAST_EXPECT(xrpUsd.expectBalances( XRPAmount(10'224'106'246), - STAmount{USD, UINT64_C(10'126'06848287943), -11}, - xrp_usd.tokens())); + STAmount{USD_, UINT64_C(10'126'06848287943), -11}, + xrpUsd.tokens())); } // XRP-EUR-BTC-USD @@ -4023,120 +4122,120 @@ private: // shows a different distribution: // XRP-EUR-BTC-USD 11.6USD/11.64XRP, XRP-USD 60.7USD/60.8XRP, // XRP-ETH-EUR-USD 27.6USD/27.6XRP - BEAST_EXPECT(xrp_eur.expectBalances(XRP(10'100), EUR(10'000), xrp_eur.tokens())); - BEAST_EXPECT(eur_btc.expectBalances(EUR(10'000), BTC(10'200), eur_btc.tokens())); - BEAST_EXPECT(btc_usd.expectBalances(BTC(10'100), USD(10'000), btc_usd.tokens())); + BEAST_EXPECT(xrpEur.expectBalances(kXRP(10'100), EUR_(10'000), xrpEur.tokens())); + BEAST_EXPECT(eurBtc.expectBalances(EUR_(10'000), BTC_(10'200), eurBtc.tokens())); + BEAST_EXPECT(btcUsd.expectBalances(BTC_(10'100), USD_(10'000), btcUsd.tokens())); - BEAST_EXPECT(expectHolding(env, carol, USD(300))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(300))); } // Dependent AMM { Env env(*this, features); - auto const ETH = gw["ETH"]; + auto const eth = gw_["ETH"]; fund( env, - gw, - {alice}, - XRP(40'000), - {EUR(50'000), BTC(50'000), ETH(50'000), USD(50'000)}); - fund(env, gw, {carol, bob}, XRP(1000), {USD(200)}, Fund::Acct); - AMM const xrp_eur(env, alice, XRP(10'100), EUR(10'000)); - AMM const eur_btc(env, alice, EUR(10'000), BTC(10'200)); - AMM const btc_usd(env, alice, BTC(10'100), USD(10'000)); - AMM const xrp_eth(env, alice, XRP(10'000), ETH(10'100)); - AMM const eth_eur(env, alice, ETH(10'900), EUR(11'000)); - env(pay(bob, carol, USD(100)), - path(~EUR, ~BTC, ~USD), - path(~ETH, ~EUR, ~BTC, ~USD), - sendmax(XRP(200))); + gw_, + {alice_}, + kXRP(40'000), + {EUR_(50'000), BTC_(50'000), eth(50'000), USD_(50'000)}); + fund(env, gw_, {carol_, bob_}, kXRP(1000), {USD_(200)}, Fund::Acct); + AMM const xrpEur(env, alice_, kXRP(10'100), EUR_(10'000)); + AMM const eurBtc(env, alice_, EUR_(10'000), BTC_(10'200)); + AMM const btcUsd(env, alice_, BTC_(10'100), USD_(10'000)); + AMM const xrpEth(env, alice_, kXRP(10'000), eth(10'100)); + AMM const ethEur(env, alice_, eth(10'900), EUR_(11'000)); + env(pay(bob_, carol_, USD_(100)), + Path(~EUR_, ~BTC_, ~USD_), + Path(~eth, ~EUR_, ~BTC_, ~USD_), + Sendmax(kXRP(200))); if (!features[fixAMMv1_1]) { // XRP-EUR-BTC-USD path provides ~17.8USD/~18.7XRP // XRP-ETH-EUR-BTC-USD path provides ~82.2USD/82.4XRP - BEAST_EXPECT(xrp_eur.expectBalances( + BEAST_EXPECT(xrpEur.expectBalances( XRPAmount(10'118'738'472), - STAmount{EUR, UINT64_C(9'981'544436337968), -12}, - xrp_eur.tokens())); - BEAST_EXPECT(eur_btc.expectBalances( - STAmount{EUR, UINT64_C(10'101'16096785173), -11}, - STAmount{BTC, UINT64_C(10'097'91426968066), -11}, - eur_btc.tokens())); - BEAST_EXPECT(btc_usd.expectBalances( - STAmount{BTC, UINT64_C(10'202'08573031934), -11}, - USD(9'900), - btc_usd.tokens())); - BEAST_EXPECT(xrp_eth.expectBalances( + STAmount{EUR_, UINT64_C(9'981'544436337968), -12}, + xrpEur.tokens())); + BEAST_EXPECT(eurBtc.expectBalances( + STAmount{EUR_, UINT64_C(10'101'16096785173), -11}, + STAmount{BTC_, UINT64_C(10'097'91426968066), -11}, + eurBtc.tokens())); + BEAST_EXPECT(btcUsd.expectBalances( + STAmount{BTC_, UINT64_C(10'202'08573031934), -11}, + USD_(9'900), + btcUsd.tokens())); + BEAST_EXPECT(xrpEth.expectBalances( XRPAmount(10'082'446'397), - STAmount{ETH, UINT64_C(10'017'41072778012), -11}, - xrp_eth.tokens())); - BEAST_EXPECT(eth_eur.expectBalances( - STAmount{ETH, UINT64_C(10'982'58927221988), -11}, - STAmount{EUR, UINT64_C(10'917'2945958103), -10}, - eth_eur.tokens())); + STAmount{eth, UINT64_C(10'017'41072778012), -11}, + xrpEth.tokens())); + BEAST_EXPECT(ethEur.expectBalances( + STAmount{eth, UINT64_C(10'982'58927221988), -11}, + STAmount{EUR_, UINT64_C(10'917'2945958103), -10}, + ethEur.tokens())); } else { - BEAST_EXPECT(xrp_eur.expectBalances( + BEAST_EXPECT(xrpEur.expectBalances( XRPAmount(10'118'738'472), - STAmount{EUR, UINT64_C(9'981'544436337923), -12}, - xrp_eur.tokens())); - BEAST_EXPECT(eur_btc.expectBalances( - STAmount{EUR, UINT64_C(10'101'16096785188), -11}, - STAmount{BTC, UINT64_C(10'097'91426968059), -11}, - eur_btc.tokens())); - BEAST_EXPECT(btc_usd.expectBalances( - STAmount{BTC, UINT64_C(10'202'08573031941), -11}, - USD(9'900), - btc_usd.tokens())); - BEAST_EXPECT(xrp_eth.expectBalances( + STAmount{EUR_, UINT64_C(9'981'544436337923), -12}, + xrpEur.tokens())); + BEAST_EXPECT(eurBtc.expectBalances( + STAmount{EUR_, UINT64_C(10'101'16096785188), -11}, + STAmount{BTC_, UINT64_C(10'097'91426968059), -11}, + eurBtc.tokens())); + BEAST_EXPECT(btcUsd.expectBalances( + STAmount{BTC_, UINT64_C(10'202'08573031941), -11}, + USD_(9'900), + btcUsd.tokens())); + BEAST_EXPECT(xrpEth.expectBalances( XRPAmount(10'082'446'397), - STAmount{ETH, UINT64_C(10'017'41072777996), -11}, - xrp_eth.tokens())); - BEAST_EXPECT(eth_eur.expectBalances( - STAmount{ETH, UINT64_C(10'982'58927222004), -11}, - STAmount{EUR, UINT64_C(10'917'2945958102), -10}, - eth_eur.tokens())); + STAmount{eth, UINT64_C(10'017'41072777996), -11}, + xrpEth.tokens())); + BEAST_EXPECT(ethEur.expectBalances( + STAmount{eth, UINT64_C(10'982'58927222004), -11}, + STAmount{EUR_, UINT64_C(10'917'2945958102), -10}, + ethEur.tokens())); } - BEAST_EXPECT(expectHolding(env, carol, USD(300))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(300))); } // AMM offers limit // Consuming 30 CLOB offers, results in hitting 30 AMM offers limit. testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(XRP(1'000), bob); - fund(env, gw, {bob}, {EUR(400)}, Fund::TokenOnly); - env(trust(alice, EUR(200))); + env.fund(kXRP(1'000), bob_); + fund(env, gw_, {bob_}, {EUR_(400)}, Fund::TokenOnly); + env(trust(alice_, EUR_(200))); for (int i = 0; i < 30; ++i) - env(offer(alice, EUR(1.0 + (0.01 * i)), XRP(1))); + env(offer(alice_, EUR_(1.0 + (0.01 * i)), kXRP(1))); // This is worse quality offer than 30 offers above. // It will not be consumed because of AMM offers limit. - env(offer(alice, EUR(140), XRP(100))); - env(pay(bob, carol, USD(100)), - path(~XRP, ~USD), - sendmax(EUR(400)), - txflags(tfPartialPayment | tfNoRippleDirect)); + env(offer(alice_, EUR_(140), kXRP(100))); + env(pay(bob_, carol_, USD_(100)), + Path(~kXRP, ~USD_), + Sendmax(EUR_(400)), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT)); if (!features[fixAMMv1_1]) { // Carol gets ~29.91USD because of the AMM offers limit BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'030), - STAmount{USD, UINT64_C(9'970'089730807577), -12}, + kXRP(10'030), + STAmount{USD_, UINT64_C(9'970'089730807577), -12}, ammAlice.tokens())); BEAST_EXPECT(expectHolding( - env, carol, STAmount{USD, UINT64_C(30'029'91026919241), -11})); + env, carol_, STAmount{USD_, UINT64_C(30'029'91026919241), -11})); } else { BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'030), - STAmount{USD, UINT64_C(9'970'089730807827), -12}, + kXRP(10'030), + STAmount{USD_, UINT64_C(9'970'089730807827), -12}, ammAlice.tokens())); BEAST_EXPECT(expectHolding( - env, carol, STAmount{USD, UINT64_C(30'029'91026919217), -11})); + env, carol_, STAmount{USD_, UINT64_C(30'029'91026919217), -11})); } - BEAST_EXPECT(expectOffers(env, alice, 1, {{{EUR(140), XRP(100)}}})); + BEAST_EXPECT(expectOffers(env, alice_, 1, {{{EUR_(140), kXRP(100)}}})); }, std::nullopt, 0, @@ -4145,35 +4244,35 @@ private: // This payment is fulfilled testAMM( [&](AMM& ammAlice, Env& env) { - env.fund(XRP(1'000), bob); - fund(env, gw, {bob}, {EUR(400)}, Fund::TokenOnly); - env(trust(alice, EUR(200))); + env.fund(kXRP(1'000), bob_); + fund(env, gw_, {bob_}, {EUR_(400)}, Fund::TokenOnly); + env(trust(alice_, EUR_(200))); for (int i = 0; i < 29; ++i) - env(offer(alice, EUR(1.0 + (0.01 * i)), XRP(1))); + env(offer(alice_, EUR_(1.0 + (0.01 * i)), kXRP(1))); // This is worse quality offer than 30 offers above. // It will not be consumed because of AMM offers limit. - env(offer(alice, EUR(140), XRP(100))); - env(pay(bob, carol, USD(100)), - path(~XRP, ~USD), - sendmax(EUR(400)), - txflags(tfPartialPayment | tfNoRippleDirect)); + env(offer(alice_, EUR_(140), kXRP(100))); + env(pay(bob_, carol_, USD_(100)), + Path(~kXRP, ~USD_), + Sendmax(EUR_(400)), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT)); BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{10'101'010'102}, USD(9'900), ammAlice.tokens())); + XRPAmount{10'101'010'102}, USD_(9'900), ammAlice.tokens())); if (!features[fixAMMv1_1]) { // Carol gets ~100USD BEAST_EXPECT(expectHolding( - env, carol, STAmount{USD, UINT64_C(30'099'99999999999), -11})); + env, carol_, STAmount{USD_, UINT64_C(30'099'99999999999), -11})); } else { - BEAST_EXPECT(expectHolding(env, carol, USD(30'100))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'100))); } BEAST_EXPECT(expectOffers( env, - alice, + alice_, 1, - {{{STAmount{EUR, UINT64_C(39'1858572), -7}, XRPAmount{27'989'898}}}})); + {{{STAmount{EUR_, UINT64_C(39'1858572), -7}, XRPAmount{27'989'898}}}})); }, std::nullopt, 0, @@ -4184,48 +4283,48 @@ private: // quality and is consumed first. { Env env(*this, features); - fund(env, gw, {alice, carol, bob}, XRP(30'000), {USD(30'000)}); - env(offer(bob, XRP(100), USD(100.001))); - AMM const ammAlice(env, alice, XRP(10'000), USD(10'100)); - env(offer(carol, USD(100), XRP(100))); + fund(env, gw_, {alice_, carol_, bob_}, kXRP(30'000), {USD_(30'000)}); + env(offer(bob_, kXRP(100), USD_(100.001))); + AMM const ammAlice(env, alice_, kXRP(10'000), USD_(10'100)); + env(offer(carol_, USD_(100), kXRP(100))); if (!features[fixAMMv1_1]) { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{10'049'825'373}, - STAmount{USD, UINT64_C(10'049'92586949302), -11}, + STAmount{USD_, UINT64_C(10'049'92586949302), -11}, ammAlice.tokens())); BEAST_EXPECT(expectOffers( env, - bob, + bob_, 1, - {{{XRPAmount{50'074'629}, STAmount{USD, UINT64_C(50'07513050698), -11}}}})); + {{{XRPAmount{50'074'629}, STAmount{USD_, UINT64_C(50'07513050698), -11}}}})); } else { BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{10'049'825'372}, - STAmount{USD, UINT64_C(10'049'92587049303), -11}, + STAmount{USD_, UINT64_C(10'049'92587049303), -11}, ammAlice.tokens())); BEAST_EXPECT(expectOffers( env, - bob, + bob_, 1, - {{{XRPAmount{50'074'628}, STAmount{USD, UINT64_C(50'07512950697), -11}}}})); - BEAST_EXPECT(expectHolding(env, carol, USD(30'100))); + {{{XRPAmount{50'074'628}, STAmount{USD_, UINT64_C(50'07512950697), -11}}}})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'100))); } } // Individually frozen account testAMM( [&](AMM& ammAlice, Env& env) { - env(trust(gw, carol["USD"](0), tfSetFreeze)); - env(trust(gw, alice["USD"](0), tfSetFreeze)); + env(trust(gw_, carol_["USD"](0), kTF_SET_FREEZE)); + env(trust(gw_, alice_["USD"](0), kTF_SET_FREEZE)); env.close(); - env(pay(alice, carol, USD(1)), - path(~USD), - sendmax(XRP(10)), - txflags(tfNoRippleDirect | tfPartialPayment), - ter(tesSUCCESS)); + env(pay(alice_, carol_, USD_(1)), + Path(~USD_), + Sendmax(kXRP(10)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT), + Ter(TesSuccess)); }, std::nullopt, 0, @@ -4249,58 +4348,61 @@ private: STAmount{token1, 5'000'000}, 0); // Carol places an order to buy LPTokens - env(offer(carol, STAmount{token1, 5'000'000}, priceXRP)); + env(offer(carol_, STAmount{token1, 5'000'000}, priceXRP)); // Alice places an order to sell LPTokens - env(offer(alice, priceXRP, STAmount{token1, 5'000'000})); + env(offer(alice_, priceXRP, STAmount{token1, 5'000'000})); // Pool's LPTokens balance doesn't change - BEAST_EXPECT(ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000})); + BEAST_EXPECT( + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000})); // Carol is Liquidity Provider - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{5'000'000})); - BEAST_EXPECT(ammAlice.expectLPTokens(alice, IOUAmount{5'000'000})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{5'000'000})); + BEAST_EXPECT(ammAlice.expectLPTokens(alice_, IOUAmount{5'000'000})); // Carol votes - ammAlice.vote(carol, 1'000); + ammAlice.vote(carol_, 1'000); BEAST_EXPECT(ammAlice.expectTradingFee(500)); - ammAlice.vote(carol, 0); + ammAlice.vote(carol_, 0); BEAST_EXPECT(ammAlice.expectTradingFee(0)); // Carol bids - env(ammAlice.bid({.account = carol, .bidMin = 100})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{4'999'900})); + env(ammAlice.bid({.account = carol_, .bidMin = 100})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{4'999'900})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{100})); - BEAST_EXPECT(accountBalance(env, carol) == std::to_string(22500000000 - (4 * baseFee))); + BEAST_EXPECT( + accountBalance(env, carol_) == std::to_string(22500000000 - (4 * baseFee))); priceXRP = ammAssetOut( STAmount{XRPAmount{10'000'000'000}}, STAmount{token1, 9'999'900}, STAmount{token1, 4'999'900}, 0); // Carol withdraws - ammAlice.withdrawAll(carol, XRP(0)); - BEAST_EXPECT(accountBalance(env, carol) == std::to_string(29999949999 - (5 * baseFee))); + ammAlice.withdrawAll(carol_, kXRP(0)); + BEAST_EXPECT( + accountBalance(env, carol_) == std::to_string(29999949999 - (5 * baseFee))); BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount{10'000'000'000} - priceXRP, USD(10'000), IOUAmount{5'000'000})); - BEAST_EXPECT(ammAlice.expectLPTokens(alice, IOUAmount{5'000'000})); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0})); + XRPAmount{10'000'000'000} - priceXRP, USD_(10'000), IOUAmount{5'000'000})); + BEAST_EXPECT(ammAlice.expectLPTokens(alice_, IOUAmount{5'000'000})); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0})); }); // Offer crossing with two AMM LPTokens. testAMM([&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); - fund(env, gw, {alice, carol}, {EUR(10'000)}, Fund::TokenOnly); - AMM ammAlice1(env, alice, XRP(10'000), EUR(10'000)); - ammAlice1.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); + fund(env, gw_, {alice_, carol_}, {EUR_(10'000)}, Fund::TokenOnly); + AMM ammAlice1(env, alice_, kXRP(10'000), EUR_(10'000)); + ammAlice1.deposit(carol_, 1'000'000); auto const token1 = ammAlice.lptIssue(); auto const token2 = ammAlice1.lptIssue(); - env(offer(alice, STAmount{token1, 100}, STAmount{token2, 100}), txflags(tfPassive)); + env(offer(alice_, STAmount{token1, 100}, STAmount{token2, 100}), Txflags(kTF_PASSIVE)); env.close(); - BEAST_EXPECT(expectOffers(env, alice, 1)); - env(offer(carol, STAmount{token2, 100}, STAmount{token1, 100})); + BEAST_EXPECT(expectOffers(env, alice_, 1)); + env(offer(carol_, STAmount{token2, 100}, STAmount{token1, 100})); env.close(); BEAST_EXPECT( - expectHolding(env, alice, STAmount{token1, 10'000'100}) && - expectHolding(env, alice, STAmount{token2, 9'999'900})); + expectHolding(env, alice_, STAmount{token1, 10'000'100}) && + expectHolding(env, alice_, STAmount{token2, 9'999'900})); BEAST_EXPECT( - expectHolding(env, carol, STAmount{token2, 1'000'100}) && - expectHolding(env, carol, STAmount{token1, 999'900})); - BEAST_EXPECT(expectOffers(env, alice, 0) && expectOffers(env, carol, 0)); + expectHolding(env, carol_, STAmount{token2, 1'000'100}) && + expectHolding(env, carol_, STAmount{token1, 999'900})); + BEAST_EXPECT(expectOffers(env, alice_, 0) && expectOffers(env, carol_, 0)); }); // LPs pay LPTokens directly. Must trust set because the trust line @@ -4308,30 +4410,30 @@ private: // trust line. testAMM([&](AMM& ammAlice, Env& env) { auto const token1 = ammAlice.lptIssue(); - env.trust(STAmount{token1, 2'000'000}, carol); + env.trust(STAmount{token1, 2'000'000}, carol_); env.close(); - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); BEAST_EXPECT( - ammAlice.expectLPTokens(alice, IOUAmount{10'000'000, 0}) && - ammAlice.expectLPTokens(carol, IOUAmount{1'000'000, 0})); + ammAlice.expectLPTokens(alice_, IOUAmount{10'000'000, 0}) && + ammAlice.expectLPTokens(carol_, IOUAmount{1'000'000, 0})); // Pool balance doesn't change, only tokens moved from // one line to another. - env(pay(alice, carol, STAmount{token1, 100})); + env(pay(alice_, carol_, STAmount{token1, 100})); env.close(); BEAST_EXPECT( // Alice initial token1 10,000,000 - 100 - ammAlice.expectLPTokens(alice, IOUAmount{9'999'900, 0}) && + ammAlice.expectLPTokens(alice_, IOUAmount{9'999'900, 0}) && // Carol initial token1 1,000,000 + 100 - ammAlice.expectLPTokens(carol, IOUAmount{1'000'100, 0})); + ammAlice.expectLPTokens(carol_, IOUAmount{1'000'100, 0})); - env.trust(STAmount{token1, 20'000'000}, alice); + env.trust(STAmount{token1, 20'000'000}, alice_); env.close(); - env(pay(carol, alice, STAmount{token1, 100})); + env(pay(carol_, alice_, STAmount{token1, 100})); env.close(); // Back to the original balance BEAST_EXPECT( - ammAlice.expectLPTokens(alice, IOUAmount{10'000'000, 0}) && - ammAlice.expectLPTokens(carol, IOUAmount{1'000'000, 0})); + ammAlice.expectLPTokens(alice_, IOUAmount{10'000'000, 0}) && + ammAlice.expectLPTokens(carol_, IOUAmount{1'000'000, 0})); }); } @@ -4341,16 +4443,16 @@ private: testcase("Amendment"); using namespace jtx; Env env{*this, testable_amendments() - featureAMM}; - fund(env, gw, {alice}, {USD(1'000)}, Fund::All); - AMM amm(env, alice, XRP(1'000), USD(1'000), ter(temDISABLED)); + fund(env, gw_, {alice_}, {USD_(1'000)}, Fund::All); + AMM amm(env, alice_, kXRP(1'000), USD_(1'000), Ter(TemDisabled)); - env(amm.bid({.bidMax = 1000}), ter(temMALFORMED)); - env(amm.bid({}), ter(temDISABLED)); - amm.vote(VoteArg{.tfee = 100, .err = ter(temDISABLED)}); - amm.withdraw(WithdrawArg{.tokens = 100, .err = ter(temMALFORMED)}); - amm.withdraw(WithdrawArg{.err = ter(temDISABLED)}); - amm.deposit(DepositArg{.asset1In = USD(100), .err = ter(temDISABLED)}); - amm.ammDelete(alice, ter(temDISABLED)); + env(amm.bid({.bidMax = 1000}), Ter(TemMalformed)); + env(amm.bid({}), Ter(TemDisabled)); + amm.vote(VoteArg{.tfee = 100, .err = Ter(TemDisabled)}); + amm.withdraw(WithdrawArg{.tokens = 100, .err = Ter(TemMalformed)}); + amm.withdraw(WithdrawArg{.err = Ter(TemDisabled)}); + amm.deposit(DepositArg{.asset1In = USD_(100), .err = Ter(TemDisabled)}); + amm.ammDelete(alice_, Ter(TemDisabled)); } void @@ -4364,8 +4466,8 @@ private: "json", "account_info", std::string("{\"account\": \"" + to_string(ammAlice.ammAccount()) + "\"}")); - auto const flags = info[jss::result][jss::account_data][jss::Flags].asUInt(); - BEAST_EXPECT(flags == (lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth)); + auto const flags = info[jss::kRESULT][jss::kACCOUNT_DATA][jss::kFLAGS].asUInt(); + BEAST_EXPECT(flags == (LsfDisableMaster | LsfDefaultRipple | LsfDepositAuth)); }); } @@ -4387,35 +4489,35 @@ private: // for 0 limit. { Env env(*this); - auto const A = Account("A"); - auto const B = Account("B"); - auto const TSTA = A["TST"]; - auto const TSTB = B["TST"]; - auto const C = Account("C"); - auto const D = Account("D"); + auto const a = Account("A"); + auto const b = Account("B"); + auto const tsta = a["TST"]; + auto const tstb = b["TST"]; + auto const c = Account("C"); + auto const d = Account("D"); - env.fund(XRP(10'000), A); - env.fund(XRP(10'000), B); - env.fund(XRP(10'000), C); - env.fund(XRP(10'000), D); + env.fund(kXRP(10'000), a); + env.fund(kXRP(10'000), b); + env.fund(kXRP(10'000), c); + env.fund(kXRP(10'000), d); - env.trust(TSTA(10'000), C); - env.trust(TSTB(10'000), C); - env(pay(A, C, TSTA(10'000))); - env(pay(B, C, TSTB(10'000))); - AMM const amm(env, C, TSTA(5'000), TSTB(5'000)); - auto const ammIss = Issue(TSTA.currency, amm.ammAccount()); + env.trust(tsta(10'000), c); + env.trust(tstb(10'000), c); + env(pay(a, c, tsta(10'000))); + env(pay(b, c, tstb(10'000))); + AMM const amm(env, c, tsta(5'000), tstb(5'000)); + auto const ammIss = Issue(tsta.currency, amm.ammAccount()); // Can TrustSet only for AMM LP tokens - env(trust(D, STAmount{ammIss, 10'000}), ter(tecNO_PERMISSION)); + env(trust(d, STAmount{ammIss, 10'000}), Ter(TecNoPermission)); env.close(); // The payment would fail because of above, but check just in case - env(pay(C, D, STAmount{ammIss, 10}), - sendmax(TSTA(100)), - path(amm.ammAccount()), - txflags(tfPartialPayment | tfNoRippleDirect), - ter(tecPATH_DRY)); + env(pay(c, d, STAmount{ammIss, 10}), + Sendmax(tsta(100)), + Path(amm.ammAccount()), + Txflags(kTF_PARTIAL_PAYMENT | kTF_NO_RIPPLE_DIRECT), + Ter(TecPathDry)); } } @@ -4425,23 +4527,23 @@ private: testcase("AMMAndCLOB, offer quality change"); using namespace jtx; auto const gw = Account("gw"); - auto const TST = gw["TST"]; - auto const LP1 = Account("LP1"); - auto const LP2 = Account("LP2"); + auto const tst = gw["TST"]; + auto const lP1 = Account("LP1"); + auto const lP2 = Account("LP2"); auto prep = [&](auto const& offerCb, auto const& expectCb) { Env env(*this, features); - env.fund(XRP(30'000'000'000), gw); - env(offer(gw, XRP(11'500'000'000), TST(1'000'000'000))); + env.fund(kXRP(30'000'000'000), gw); + env(offer(gw, kXRP(11'500'000'000), tst(1'000'000'000))); - env.fund(XRP(10'000), LP1); - env.fund(XRP(10'000), LP2); - env(offer(LP1, TST(25), XRPAmount(287'500'000))); + env.fund(kXRP(10'000), lP1); + env.fund(kXRP(10'000), lP2); + env(offer(lP1, tst(25), XRPAmount(287'500'000))); // Either AMM or CLOB offer offerCb(env); - env(offer(LP2, TST(25), XRPAmount(287'500'000))); + env(offer(lP2, tst(25), XRPAmount(287'500'000))); expectCb(env); }; @@ -4453,10 +4555,10 @@ private: std::string lp2TakerPays; // Execute with AMM first prep( - [&](Env& env) { AMM const amm(env, LP1, TST(25), XRP(250)); }, + [&](Env& env) { AMM const amm(env, lP1, tst(25), kXRP(250)); }, [&](Env& env) { - lp2TSTBalance = getAccountLines(env, LP2, TST)["lines"][0u]["balance"].asString(); - auto const offer = getAccountOffers(env, LP2)["offers"][0u]; + lp2TSTBalance = getAccountLines(env, lP2, tst)["lines"][0u]["balance"].asString(); + auto const offer = getAccountOffers(env, lP2)["offers"][0u]; lp2TakerGets = offer["taker_gets"].asString(); lp2TakerPays = offer["taker_pays"]["value"].asString(); }); @@ -4466,25 +4568,25 @@ private: if (!features[fixAMMv1_1]) { env(offer( - LP1, + lP1, XRPAmount{18'095'133}, - STAmount{TST, UINT64_C(1'68737984885388), -14}), - txflags(tfPassive)); + STAmount{tst, UINT64_C(1'68737984885388), -14}), + Txflags(kTF_PASSIVE)); } else { env(offer( - LP1, + lP1, XRPAmount{18'095'132}, - STAmount{TST, UINT64_C(1'68737976189735), -14}), - txflags(tfPassive)); + STAmount{tst, UINT64_C(1'68737976189735), -14}), + Txflags(kTF_PASSIVE)); } }, [&](Env& env) { BEAST_EXPECT( lp2TSTBalance == - getAccountLines(env, LP2, TST)["lines"][0u]["balance"].asString()); - auto const offer = getAccountOffers(env, LP2)["offers"][0u]; + getAccountLines(env, lP2, tst)["lines"][0u]["balance"].asString()); + auto const offer = getAccountOffers(env, lP2)["offers"][0u]; BEAST_EXPECT(lp2TakerGets == offer["taker_gets"].asString()); BEAST_EXPECT(lp2TakerPays == offer["taker_pays"]["value"].asString()); }); @@ -4500,27 +4602,27 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { // No fee - ammAlice.deposit(carol, USD(3'000)); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{1'000})); - ammAlice.withdrawAll(carol, USD(3'000)); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{0})); - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + ammAlice.deposit(carol_, USD_(3'000)); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{1'000})); + ammAlice.withdrawAll(carol_, USD_(3'000)); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{0})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); // Set fee to 1% - ammAlice.vote(alice, 1'000); + ammAlice.vote(alice_, 1'000); BEAST_EXPECT(ammAlice.expectTradingFee(1'000)); // Carol gets fewer LPToken ~994, because of the single deposit // fee - ammAlice.deposit(carol, USD(3'000)); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{994'981155689671, -12})); - BEAST_EXPECT(expectHolding(env, carol, USD(27'000))); + ammAlice.deposit(carol_, USD_(3'000)); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{994'981155689671, -12})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(27'000))); // Set fee to 0 - ammAlice.vote(alice, 0); - ammAlice.withdrawAll(carol, USD(0)); + ammAlice.vote(alice_, 0); + ammAlice.withdrawAll(carol_, USD_(0)); // Carol gets back less than the original deposit BEAST_EXPECT( - expectHolding(env, carol, STAmount{USD, UINT64_C(29'994'96220068281), -11})); + expectHolding(env, carol_, STAmount{USD_, UINT64_C(29'994'96220068281), -11})); }, - {{USD(1'000), EUR(1'000)}}, + {{USD_(1'000), EUR_(1'000)}}, 0, std::nullopt, {features}); @@ -4529,14 +4631,14 @@ private: // 100USD with EP not to exceed 0.1 (AssetIn/TokensOut). 1% fee. testAMM( [&](AMM& ammAlice, Env& env) { - auto const balance = env.balance(carol, USD); + auto const balance = env.balance(carol_, USD_); auto tokensFee = - ammAlice.deposit(carol, USD(1'000), std::nullopt, STAmount{USD, 1, -1}); - auto const deposit = balance - env.balance(carol, USD); - ammAlice.withdrawAll(carol, USD(0)); - ammAlice.vote(alice, 0); + ammAlice.deposit(carol_, USD_(1'000), std::nullopt, STAmount{USD_, 1, -1}); + auto const deposit = balance - env.balance(carol_, USD_); + ammAlice.withdrawAll(carol_, USD_(0)); + ammAlice.vote(alice_, 0); BEAST_EXPECT(ammAlice.expectTradingFee(0)); - auto const tokensNoFee = ammAlice.deposit(carol, deposit); + auto const tokensNoFee = ammAlice.deposit(carol_, deposit); // carol pays ~2008 LPTokens in fees or ~0.5% of the no-fee // LPTokens BEAST_EXPECT(tokensFee == IOUAmount(485'636'0611129, -7)); @@ -4551,14 +4653,14 @@ private: // 200USD with EP not to exceed 0.002020 (AssetIn/TokensOut). 1% fee testAMM( [&](AMM& ammAlice, Env& env) { - auto const balance = env.balance(carol, USD); + auto const balance = env.balance(carol_, USD_); auto const tokensFee = - ammAlice.deposit(carol, USD(200), std::nullopt, STAmount{USD, 2020, -6}); - auto const deposit = balance - env.balance(carol, USD); - ammAlice.withdrawAll(carol, USD(0)); - ammAlice.vote(alice, 0); + ammAlice.deposit(carol_, USD_(200), std::nullopt, STAmount{USD_, 2020, -6}); + auto const deposit = balance - env.balance(carol_, USD_); + ammAlice.withdrawAll(carol_, USD_(0)); + ammAlice.vote(alice_, 0); BEAST_EXPECT(ammAlice.expectTradingFee(0)); - auto const tokensNoFee = ammAlice.deposit(carol, deposit); + auto const tokensNoFee = ammAlice.deposit(carol_, deposit); // carol pays ~475 LPTokens in fees or ~0.5% of the no-fee // LPTokens BEAST_EXPECT(tokensFee == IOUAmount(98'000'00000002, -8)); @@ -4573,19 +4675,19 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { // No fee - ammAlice.deposit(carol, USD(3'000)); + ammAlice.deposit(carol_, USD_(3'000)); - BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{1'000})); - BEAST_EXPECT(expectHolding(env, carol, USD(27'000))); + BEAST_EXPECT(ammAlice.expectLPTokens(carol_, IOUAmount{1'000})); + BEAST_EXPECT(expectHolding(env, carol_, USD_(27'000))); // Set fee to 1% - ammAlice.vote(alice, 1'000); + ammAlice.vote(alice_, 1'000); BEAST_EXPECT(ammAlice.expectTradingFee(1'000)); // Single withdrawal. Carol gets ~5USD less than deposited. - ammAlice.withdrawAll(carol, USD(0)); + ammAlice.withdrawAll(carol_, USD_(0)); BEAST_EXPECT( - expectHolding(env, carol, STAmount{USD, UINT64_C(29'994'97487437186), -11})); + expectHolding(env, carol_, STAmount{USD_, UINT64_C(29'994'97487437186), -11})); }, - {{USD(1'000), EUR(1'000)}}, + {{USD_(1'000), EUR_(1'000)}}, 0, std::nullopt, {features}); @@ -4593,47 +4695,47 @@ private: // Withdraw with EPrice limit, 1% fee. testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.deposit(carol, 1'000'000); + ammAlice.deposit(carol_, 1'000'000); auto const tokensFee = - ammAlice.withdraw(carol, USD(100), std::nullopt, IOUAmount{520, 0}); + ammAlice.withdraw(carol_, USD_(100), std::nullopt, IOUAmount{520, 0}); // carol withdraws ~1,443.44USD auto const balanceAfterWithdraw = [&]() { if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { - return STAmount(USD, UINT64_C(30'443'43891402715), -11); + return STAmount(USD_, UINT64_C(30'443'43891402715), -11); } if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { - return STAmount(USD, UINT64_C(30'443'43891402714), -11); + return STAmount(USD_, UINT64_C(30'443'43891402714), -11); } - return STAmount(USD, UINT64_C(30'443'43891402713), -11); + return STAmount(USD_, UINT64_C(30'443'43891402713), -11); }(); - BEAST_EXPECT(env.balance(carol, USD) == balanceAfterWithdraw); + BEAST_EXPECT(env.balance(carol_, USD_) == balanceAfterWithdraw); // Set to original pool size - auto const deposit = balanceAfterWithdraw - USD(29'000); - ammAlice.deposit(carol, deposit); + auto const deposit = balanceAfterWithdraw - USD_(29'000); + ammAlice.deposit(carol_, deposit); // fee 0% - ammAlice.vote(alice, 0); + ammAlice.vote(alice_, 0); BEAST_EXPECT(ammAlice.expectTradingFee(0)); - auto const tokensNoFee = ammAlice.withdraw(carol, deposit); + auto const tokensNoFee = ammAlice.withdraw(carol_, deposit); if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(30'443'43891402717), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(30'443'43891402717), -11)); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(30'443'43891402716), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(30'443'43891402716), -11)); } else { BEAST_EXPECT( - env.balance(carol, USD) == - STAmount(USD, UINT64_C(30'443'43891402713), -11)); + env.balance(carol_, USD_) == + STAmount(USD_, UINT64_C(30'443'43891402713), -11)); } // carol pays ~4008 LPTokens in fees or ~0.5% of the no-fee // LPTokens @@ -4659,42 +4761,42 @@ private: // Payment, 1% fee testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(1'000), {USD(1'000), EUR(1'000)}, Fund::Acct); + fund(env, gw_, {bob_}, kXRP(1'000), {USD_(1'000), EUR_(1'000)}, Fund::Acct); // Alice contributed 1010EUR and 1000USD to the pool - BEAST_EXPECT(expectHolding(env, alice, EUR(28'990))); - BEAST_EXPECT(expectHolding(env, alice, USD(29'000))); - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + BEAST_EXPECT(expectHolding(env, alice_, EUR_(28'990))); + BEAST_EXPECT(expectHolding(env, alice_, USD_(29'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); // Carol pays to Alice with no fee - env(pay(carol, alice, EUR(10)), - path(~EUR), - sendmax(USD(10)), - txflags(tfNoRippleDirect)); + env(pay(carol_, alice_, EUR_(10)), + Path(~EUR_), + Sendmax(USD_(10)), + Txflags(kTF_NO_RIPPLE_DIRECT)); env.close(); // Alice has 10EUR more and Carol has 10USD less - BEAST_EXPECT(expectHolding(env, alice, EUR(29'000))); - BEAST_EXPECT(expectHolding(env, alice, USD(29'000))); - BEAST_EXPECT(expectHolding(env, carol, USD(29'990))); + BEAST_EXPECT(expectHolding(env, alice_, EUR_(29'000))); + BEAST_EXPECT(expectHolding(env, alice_, USD_(29'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(29'990))); // Set fee to 1% - ammAlice.vote(alice, 1'000); + ammAlice.vote(alice_, 1'000); BEAST_EXPECT(ammAlice.expectTradingFee(1'000)); // Bob pays to Carol with 1% fee - env(pay(bob, carol, USD(10)), - path(~USD), - sendmax(EUR(15)), - txflags(tfNoRippleDirect)); + env(pay(bob_, carol_, USD_(10)), + Path(~USD_), + Sendmax(EUR_(15)), + Txflags(kTF_NO_RIPPLE_DIRECT)); env.close(); // Bob sends 10.1~EUR to pay 10USD BEAST_EXPECT( - expectHolding(env, bob, STAmount{EUR, UINT64_C(989'8989898989899), -13})); + expectHolding(env, bob_, STAmount{EUR_, UINT64_C(989'8989898989899), -13})); // Carol got 10USD - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); BEAST_EXPECT(ammAlice.expectBalances( - USD(1'000), - STAmount{EUR, UINT64_C(1'010'10101010101), -11}, + USD_(1'000), + STAmount{EUR_, UINT64_C(1'010'10101010101), -11}, ammAlice.tokens())); }, - {{USD(1'000), EUR(1'010)}}, + {{USD_(1'000), EUR_(1'010)}}, 0, std::nullopt, {features}); @@ -4703,47 +4805,47 @@ private: testAMM( [&](AMM& ammAlice, Env& env) { // No fee - env(offer(carol, EUR(10), USD(10))); + env(offer(carol_, EUR_(10), USD_(10))); env.close(); - BEAST_EXPECT(expectHolding(env, carol, USD(29'990))); - BEAST_EXPECT(expectHolding(env, carol, EUR(30'010))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(29'990))); + BEAST_EXPECT(expectHolding(env, carol_, EUR_(30'010))); // Change pool composition back - env(offer(carol, USD(10), EUR(10))); + env(offer(carol_, USD_(10), EUR_(10))); env.close(); // Set fee to 0.5% - ammAlice.vote(alice, 500); + ammAlice.vote(alice_, 500); BEAST_EXPECT(ammAlice.expectTradingFee(500)); - env(offer(carol, EUR(10), USD(10))); + env(offer(carol_, EUR_(10), USD_(10))); env.close(); // Alice gets fewer ~4.97EUR for ~5.02USD, the difference goes // to the pool BEAST_EXPECT( - expectHolding(env, carol, STAmount{USD, UINT64_C(29'995'02512562814), -11})); + expectHolding(env, carol_, STAmount{USD_, UINT64_C(29'995'02512562814), -11})); BEAST_EXPECT( - expectHolding(env, carol, STAmount{EUR, UINT64_C(30'004'97487437186), -11})); + expectHolding(env, carol_, STAmount{EUR_, UINT64_C(30'004'97487437186), -11})); BEAST_EXPECT(expectOffers( env, - carol, + carol_, 1, {{Amounts{ - STAmount{EUR, UINT64_C(5'025125628140703), -15}, - STAmount{USD, UINT64_C(5'025125628140703), -15}}}})); + STAmount{EUR_, UINT64_C(5'025125628140703), -15}, + STAmount{USD_, UINT64_C(5'025125628140703), -15}}}})); if (!features[fixAMMv1_1]) { BEAST_EXPECT(ammAlice.expectBalances( - STAmount{USD, UINT64_C(1'004'974874371859), -12}, - STAmount{EUR, UINT64_C(1'005'025125628141), -12}, + STAmount{USD_, UINT64_C(1'004'974874371859), -12}, + STAmount{EUR_, UINT64_C(1'005'025125628141), -12}, ammAlice.tokens())); } else { BEAST_EXPECT(ammAlice.expectBalances( - STAmount{USD, UINT64_C(1'004'97487437186), -11}, - STAmount{EUR, UINT64_C(1'005'025125628141), -12}, + STAmount{USD_, UINT64_C(1'004'97487437186), -11}, + STAmount{EUR_, UINT64_C(1'005'025125628141), -12}, ammAlice.tokens())); } }, - {{USD(1'000), EUR(1'010)}}, + {{USD_(1'000), EUR_(1'010)}}, 0, std::nullopt, {features}); @@ -4755,26 +4857,29 @@ private: { Env env(*this, features); Account const ed("ed"); - fund(env, gw, {alice, bob, carol, ed}, XRP(1'000), {USD(2'000), EUR(2'000)}); - env(offer(carol, EUR(5), USD(5))); - AMM const ammAlice(env, alice, USD(1'005), EUR(1'000)); - env(pay(bob, ed, USD(10)), path(~USD), sendmax(EUR(15)), txflags(tfNoRippleDirect)); - BEAST_EXPECT(expectHolding(env, ed, USD(2'010))); + fund(env, gw_, {alice_, bob_, carol_, ed}, kXRP(1'000), {USD_(2'000), EUR_(2'000)}); + env(offer(carol_, EUR_(5), USD_(5))); + AMM const ammAlice(env, alice_, USD_(1'005), EUR_(1'000)); + env(pay(bob_, ed, USD_(10)), + Path(~USD_), + Sendmax(EUR_(15)), + Txflags(kTF_NO_RIPPLE_DIRECT)); + BEAST_EXPECT(expectHolding(env, ed, USD_(2'010))); if (!features[fixAMMv1_1]) { - BEAST_EXPECT(expectHolding(env, bob, EUR(1'990))); - BEAST_EXPECT(ammAlice.expectBalances(USD(1'000), EUR(1'005), ammAlice.tokens())); + BEAST_EXPECT(expectHolding(env, bob_, EUR_(1'990))); + BEAST_EXPECT(ammAlice.expectBalances(USD_(1'000), EUR_(1'005), ammAlice.tokens())); } else { BEAST_EXPECT( - expectHolding(env, bob, STAmount(EUR, UINT64_C(1989'999999999999), -12))); + expectHolding(env, bob_, STAmount(EUR_, UINT64_C(1989'999999999999), -12))); BEAST_EXPECT(ammAlice.expectBalances( - USD(1'000), - STAmount(EUR, UINT64_C(1005'000000000001), -12), + USD_(1'000), + STAmount(EUR_, UINT64_C(1005'000000000001), -12), ammAlice.tokens())); } - BEAST_EXPECT(expectOffers(env, carol, 0)); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } // Payment with AMM and CLOB offer. Same as above but with 0.25% @@ -4782,31 +4887,34 @@ private: { Env env(*this, features); Account const ed("ed"); - fund(env, gw, {alice, bob, carol, ed}, XRP(1'000), {USD(2'000), EUR(2'000)}); - env(offer(carol, EUR(5), USD(5))); + fund(env, gw_, {alice_, bob_, carol_, ed}, kXRP(1'000), {USD_(2'000), EUR_(2'000)}); + env(offer(carol_, EUR_(5), USD_(5))); // Set 0.25% fee - AMM const ammAlice(env, alice, USD(1'005), EUR(1'000), false, 250); - env(pay(bob, ed, USD(10)), path(~USD), sendmax(EUR(15)), txflags(tfNoRippleDirect)); - BEAST_EXPECT(expectHolding(env, ed, USD(2'010))); + AMM const ammAlice(env, alice_, USD_(1'005), EUR_(1'000), false, 250); + env(pay(bob_, ed, USD_(10)), + Path(~USD_), + Sendmax(EUR_(15)), + Txflags(kTF_NO_RIPPLE_DIRECT)); + BEAST_EXPECT(expectHolding(env, ed, USD_(2'010))); if (!features[fixAMMv1_1]) { BEAST_EXPECT( - expectHolding(env, bob, STAmount{EUR, UINT64_C(1'989'987453007618), -12})); + expectHolding(env, bob_, STAmount{EUR_, UINT64_C(1'989'987453007618), -12})); BEAST_EXPECT(ammAlice.expectBalances( - USD(1'000), - STAmount{EUR, UINT64_C(1'005'012546992382), -12}, + USD_(1'000), + STAmount{EUR_, UINT64_C(1'005'012546992382), -12}, ammAlice.tokens())); } else { BEAST_EXPECT( - expectHolding(env, bob, STAmount{EUR, UINT64_C(1'989'987453007628), -12})); + expectHolding(env, bob_, STAmount{EUR_, UINT64_C(1'989'987453007628), -12})); BEAST_EXPECT(ammAlice.expectBalances( - USD(1'000), - STAmount{EUR, UINT64_C(1'005'012546992372), -12}, + USD_(1'000), + STAmount{EUR_, UINT64_C(1'005'012546992372), -12}, ammAlice.tokens())); } - BEAST_EXPECT(expectOffers(env, carol, 0)); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } // Payment with AMM and CLOB offer. AMM has a better @@ -4815,15 +4923,18 @@ private: { Env env(*this, features); Account const ed("ed"); - fund(env, gw, {alice, bob, carol, ed}, XRP(1'000), {USD(2'000), EUR(2'000)}); - env(offer(carol, EUR(10), USD(10))); + fund(env, gw_, {alice_, bob_, carol_, ed}, kXRP(1'000), {USD_(2'000), EUR_(2'000)}); + env(offer(carol_, EUR_(10), USD_(10))); // Set 1% fee - AMM const ammAlice(env, alice, USD(1'005), EUR(1'000), false, 1'000); - env(pay(bob, ed, USD(10)), path(~USD), sendmax(EUR(15)), txflags(tfNoRippleDirect)); - BEAST_EXPECT(expectHolding(env, ed, USD(2'010))); - BEAST_EXPECT(expectHolding(env, bob, EUR(1'990))); - BEAST_EXPECT(ammAlice.expectBalances(USD(1'005), EUR(1'000), ammAlice.tokens())); - BEAST_EXPECT(expectOffers(env, carol, 0)); + AMM const ammAlice(env, alice_, USD_(1'005), EUR_(1'000), false, 1'000); + env(pay(bob_, ed, USD_(10)), + Path(~USD_), + Sendmax(EUR_(15)), + Txflags(kTF_NO_RIPPLE_DIRECT)); + BEAST_EXPECT(expectHolding(env, ed, USD_(2'010))); + BEAST_EXPECT(expectHolding(env, bob_, EUR_(1'990))); + BEAST_EXPECT(ammAlice.expectBalances(USD_(1'005), EUR_(1'000), ammAlice.tokens())); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } // Payment with AMM and CLOB offer. AMM has a better @@ -4833,16 +4944,20 @@ private: { Env env(*this, features); Account const ed("ed"); - fund(env, gw, {alice, bob, carol, ed}, XRP(1'000), {USD(2'000), EUR(2'000)}); - env(offer(carol, EUR(9), USD(9))); + fund(env, gw_, {alice_, bob_, carol_, ed}, kXRP(1'000), {USD_(2'000), EUR_(2'000)}); + env(offer(carol_, EUR_(9), USD_(9))); // Set 1% fee - AMM const ammAlice(env, alice, USD(1'005), EUR(1'000), false, 1'000); - env(pay(bob, ed, USD(10)), path(~USD), sendmax(EUR(15)), txflags(tfNoRippleDirect)); - BEAST_EXPECT(expectHolding(env, ed, USD(2'010))); - BEAST_EXPECT(expectHolding(env, bob, STAmount{EUR, UINT64_C(1'989'993923296712), -12})); + AMM const ammAlice(env, alice_, USD_(1'005), EUR_(1'000), false, 1'000); + env(pay(bob_, ed, USD_(10)), + Path(~USD_), + Sendmax(EUR_(15)), + Txflags(kTF_NO_RIPPLE_DIRECT)); + BEAST_EXPECT(expectHolding(env, ed, USD_(2'010))); + BEAST_EXPECT( + expectHolding(env, bob_, STAmount{EUR_, UINT64_C(1'989'993923296712), -12})); BEAST_EXPECT(ammAlice.expectBalances( - USD(1'004), STAmount{EUR, UINT64_C(1'001'006076703288), -12}, ammAlice.tokens())); - BEAST_EXPECT(expectOffers(env, carol, 0)); + USD_(1'004), STAmount{EUR_, UINT64_C(1'001'006076703288), -12}, ammAlice.tokens())); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } } @@ -4866,30 +4981,30 @@ private: Account const natalie("natalie"); fund( env, - gw, + gw_, {bob, ed, paul, dan, chris, simon, ben, natalie}, - {USD(1'500'000)}, + {USD_(1'500'000)}, Fund::Acct); for (int i = 0; i < 10; ++i) { - ammAlice.deposit(ben, STAmount{USD, 1, -10}); - ammAlice.withdrawAll(ben, USD(0)); - ammAlice.deposit(simon, USD(0.1)); - ammAlice.withdrawAll(simon, USD(0)); - ammAlice.deposit(chris, USD(1)); - ammAlice.withdrawAll(chris, USD(0)); - ammAlice.deposit(dan, USD(10)); - ammAlice.withdrawAll(dan, USD(0)); - ammAlice.deposit(bob, USD(100)); - ammAlice.withdrawAll(bob, USD(0)); - ammAlice.deposit(carol, USD(1'000)); - ammAlice.withdrawAll(carol, USD(0)); - ammAlice.deposit(ed, USD(10'000)); - ammAlice.withdrawAll(ed, USD(0)); - ammAlice.deposit(paul, USD(100'000)); - ammAlice.withdrawAll(paul, USD(0)); - ammAlice.deposit(natalie, USD(1'000'000)); - ammAlice.withdrawAll(natalie, USD(0)); + ammAlice.deposit(ben, STAmount{USD_, 1, -10}); + ammAlice.withdrawAll(ben, USD_(0)); + ammAlice.deposit(simon, USD_(0.1)); + ammAlice.withdrawAll(simon, USD_(0)); + ammAlice.deposit(chris, USD_(1)); + ammAlice.withdrawAll(chris, USD_(0)); + ammAlice.deposit(dan, USD_(10)); + ammAlice.withdrawAll(dan, USD_(0)); + ammAlice.deposit(bob, USD_(100)); + ammAlice.withdrawAll(bob, USD_(0)); + ammAlice.deposit(carol_, USD_(1'000)); + ammAlice.withdrawAll(carol_, USD_(0)); + ammAlice.deposit(ed, USD_(10'000)); + ammAlice.withdrawAll(ed, USD_(0)); + ammAlice.deposit(paul, USD_(100'000)); + ammAlice.withdrawAll(paul, USD_(0)); + ammAlice.deposit(natalie, USD_(1'000'000)); + ammAlice.withdrawAll(natalie, USD_(0)); } // Due to round off some accounts have a tiny gain, while // other have a tiny loss. The last account to withdraw @@ -4897,75 +5012,75 @@ private: if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'000'0000000013), -10}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'000'0000000013), -10}, IOUAmount{10'000'000})); } else if (features[fixAMMv1_3]) { BEAST_EXPECT(ammAlice.expectBalances( - XRP(10'000), - STAmount{USD, UINT64_C(10'000'0000000003), -10}, + kXRP(10'000), + STAmount{USD_, UINT64_C(10'000'0000000003), -10}, IOUAmount{10'000'000})); } else { BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000})); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000})); } - BEAST_EXPECT(expectHolding(env, ben, USD(1'500'000))); - BEAST_EXPECT(expectHolding(env, simon, USD(1'500'000))); - BEAST_EXPECT(expectHolding(env, chris, USD(1'500'000))); - BEAST_EXPECT(expectHolding(env, dan, USD(1'500'000))); + BEAST_EXPECT(expectHolding(env, ben, USD_(1'500'000))); + BEAST_EXPECT(expectHolding(env, simon, USD_(1'500'000))); + BEAST_EXPECT(expectHolding(env, chris, USD_(1'500'000))); + BEAST_EXPECT(expectHolding(env, dan, USD_(1'500'000))); if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(expectHolding( - env, carol, STAmount{USD, UINT64_C(30'000'00000000001), -11})); + env, carol_, STAmount{USD_, UINT64_C(30'000'00000000001), -11})); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); } else { - BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); + BEAST_EXPECT(expectHolding(env, carol_, USD_(30'000))); } - BEAST_EXPECT(expectHolding(env, ed, USD(1'500'000))); - BEAST_EXPECT(expectHolding(env, paul, USD(1'500'000))); + BEAST_EXPECT(expectHolding(env, ed, USD_(1'500'000))); + BEAST_EXPECT(expectHolding(env, paul, USD_(1'500'000))); if (!features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(expectHolding( - env, natalie, STAmount{USD, UINT64_C(1'500'000'000000002), -9})); + env, natalie, STAmount{USD_, UINT64_C(1'500'000'000000002), -9})); } else if (features[fixAMMv1_1] && !features[fixAMMv1_3]) { BEAST_EXPECT(expectHolding( - env, natalie, STAmount{USD, UINT64_C(1'500'000'000000005), -9})); + env, natalie, STAmount{USD_, UINT64_C(1'500'000'000000005), -9})); } else { - BEAST_EXPECT(expectHolding(env, natalie, USD(1'500'000))); + BEAST_EXPECT(expectHolding(env, natalie, USD_(1'500'000))); } - ammAlice.withdrawAll(alice); + ammAlice.withdrawAll(alice_); BEAST_EXPECT(!ammAlice.ammExists()); if (!features[fixAMMv1_1]) { - BEAST_EXPECT( - expectHolding(env, alice, STAmount{USD, UINT64_C(30'000'0000000013), -10})); + BEAST_EXPECT(expectHolding( + env, alice_, STAmount{USD_, UINT64_C(30'000'0000000013), -10})); } else if (features[fixAMMv1_3]) { - BEAST_EXPECT( - expectHolding(env, alice, STAmount{USD, UINT64_C(30'000'0000000003), -10})); + BEAST_EXPECT(expectHolding( + env, alice_, STAmount{USD_, UINT64_C(30'000'0000000003), -10})); } else { - BEAST_EXPECT(expectHolding(env, alice, USD(30'000))); + BEAST_EXPECT(expectHolding(env, alice_, USD_(30'000))); } // alice XRP balance is 30,000 initial - 50 AMMCreate fee - // 10drops fee BEAST_EXPECT( - accountBalance(env, alice) == + accountBalance(env, alice_) == std::to_string(29950000000 - env.current()->fees().base.drops())); }, std::nullopt, @@ -4986,42 +5101,42 @@ private: Account const natalie("natalie"); fund( env, - gw, + gw_, {bob, ed, paul, dan, chris, simon, ben, natalie}, - XRP(2'000'000), + kXRP(2'000'000), {}, Fund::Acct); for (int i = 0; i < 10; ++i) { ammAlice.deposit(ben, XRPAmount{1}); - ammAlice.withdrawAll(ben, XRP(0)); + ammAlice.withdrawAll(ben, kXRP(0)); ammAlice.deposit(simon, XRPAmount(1'000)); - ammAlice.withdrawAll(simon, XRP(0)); - ammAlice.deposit(chris, XRP(1)); - ammAlice.withdrawAll(chris, XRP(0)); - ammAlice.deposit(dan, XRP(10)); - ammAlice.withdrawAll(dan, XRP(0)); - ammAlice.deposit(bob, XRP(100)); - ammAlice.withdrawAll(bob, XRP(0)); - ammAlice.deposit(carol, XRP(1'000)); - ammAlice.withdrawAll(carol, XRP(0)); - ammAlice.deposit(ed, XRP(10'000)); - ammAlice.withdrawAll(ed, XRP(0)); - ammAlice.deposit(paul, XRP(100'000)); - ammAlice.withdrawAll(paul, XRP(0)); - ammAlice.deposit(natalie, XRP(1'000'000)); - ammAlice.withdrawAll(natalie, XRP(0)); + ammAlice.withdrawAll(simon, kXRP(0)); + ammAlice.deposit(chris, kXRP(1)); + ammAlice.withdrawAll(chris, kXRP(0)); + ammAlice.deposit(dan, kXRP(10)); + ammAlice.withdrawAll(dan, kXRP(0)); + ammAlice.deposit(bob, kXRP(100)); + ammAlice.withdrawAll(bob, kXRP(0)); + ammAlice.deposit(carol_, kXRP(1'000)); + ammAlice.withdrawAll(carol_, kXRP(0)); + ammAlice.deposit(ed, kXRP(10'000)); + ammAlice.withdrawAll(ed, kXRP(0)); + ammAlice.deposit(paul, kXRP(100'000)); + ammAlice.withdrawAll(paul, kXRP(0)); + ammAlice.deposit(natalie, kXRP(1'000'000)); + ammAlice.withdrawAll(natalie, kXRP(0)); } auto const baseFee = env.current()->fees().base.drops(); if (!features[fixAMMv1_3]) { // No round off with XRP in this test BEAST_EXPECT( - ammAlice.expectBalances(XRP(10'000), USD(10'000), IOUAmount{10'000'000})); - ammAlice.withdrawAll(alice); + ammAlice.expectBalances(kXRP(10'000), USD_(10'000), IOUAmount{10'000'000})); + ammAlice.withdrawAll(alice_); BEAST_EXPECT(!ammAlice.ammExists()); // 20,000 initial - (deposit+withdraw) * 10 - auto const xrpBalance = (XRP(2'000'000) - txfee(env, 20)).getText(); + auto const xrpBalance = (kXRP(2'000'000) - txfee(env, 20)).getText(); BEAST_EXPECT(accountBalance(env, ben) == xrpBalance); BEAST_EXPECT(accountBalance(env, simon) == xrpBalance); BEAST_EXPECT(accountBalance(env, chris) == xrpBalance); @@ -5029,37 +5144,37 @@ private: // 30,000 initial - (deposit+withdraw) * 10 BEAST_EXPECT( - accountBalance(env, carol) == + accountBalance(env, carol_) == std::to_string(30'000'000'000 - (20 * baseFee))); BEAST_EXPECT(accountBalance(env, ed) == xrpBalance); BEAST_EXPECT(accountBalance(env, paul) == xrpBalance); BEAST_EXPECT(accountBalance(env, natalie) == xrpBalance); // 30,000 initial - 50 AMMCreate fee - 10drops withdraw fee BEAST_EXPECT( - accountBalance(env, alice) == std::to_string(29'950'000'000 - baseFee)); + accountBalance(env, alice_) == std::to_string(29'950'000'000 - baseFee)); } else { // post-amendment the rounding takes place to ensure // AMM invariant BEAST_EXPECT(ammAlice.expectBalances( - XRPAmount(10'000'000'080), USD(10'000), IOUAmount{10'000'000})); - ammAlice.withdrawAll(alice); + XRPAmount(10'000'000'080), USD_(10'000), IOUAmount{10'000'000})); + ammAlice.withdrawAll(alice_); BEAST_EXPECT(!ammAlice.ammExists()); - auto const xrpBalance = XRP(2'000'000) - txfee(env, 20) - drops(10); + auto const xrpBalance = kXRP(2'000'000) - txfee(env, 20) - drops(10); auto const xrpBalanceText = xrpBalance.getText(); BEAST_EXPECT(accountBalance(env, ben) == xrpBalanceText); BEAST_EXPECT(accountBalance(env, simon) == xrpBalanceText); BEAST_EXPECT(accountBalance(env, chris) == xrpBalanceText); BEAST_EXPECT(accountBalance(env, dan) == xrpBalanceText); BEAST_EXPECT( - accountBalance(env, carol) == + accountBalance(env, carol_) == std::to_string(30'000'000'000 - (20 * baseFee) - 10)); BEAST_EXPECT(accountBalance(env, ed) == (xrpBalance + drops(2)).getText()); BEAST_EXPECT(accountBalance(env, paul) == (xrpBalance + drops(3)).getText()); BEAST_EXPECT(accountBalance(env, natalie) == (xrpBalance + drops(5)).getText()); BEAST_EXPECT( - accountBalance(env, alice) == + accountBalance(env, alice_) == std::to_string(29'950'000'000 - baseFee + 80)); } }, @@ -5085,52 +5200,51 @@ private: return cfg; }), all); - fund(env, gw, {alice}, XRP(20'000), {USD(10'000)}); - AMM amm(env, gw, XRP(10'000), USD(10'000)); - for (auto i = 0; i < maxDeletableAMMTrustLines + 10; ++i) + fund(env, gw_, {alice_}, kXRP(20'000), {USD_(10'000)}); + AMM amm(env, gw_, kXRP(10'000), USD_(10'000)); + for (auto i = 0; i < kMAX_DELETABLE_AMM_TRUST_LINES + 10; ++i) { Account const a{std::to_string(i)}; - env.fund(XRP(1'000), a); + env.fund(kXRP(1'000), a); env(trust(a, STAmount{amm.lptIssue(), 10'000})); env.close(); } // The trustlines are partially deleted, // AMM is set to an empty state. - amm.withdrawAll(gw); + amm.withdrawAll(gw_); BEAST_EXPECT(amm.ammExists()); // Bid,Vote,Deposit,Withdraw,TrustSet failing with // tecAMM_EMPTY. Deposit succeeds with tfTwoAssetIfEmpty option. env(amm.bid({ - .account = alice, + .account = alice_, .bidMin = 1000, }), - ter(tecAMM_EMPTY)); - amm.vote( - std::nullopt, 100, std::nullopt, std::nullopt, std::nullopt, ter(tecAMM_EMPTY)); - amm.withdraw(alice, 100, std::nullopt, std::nullopt, ter(tecAMM_EMPTY)); + Ter(TecAmmEmpty)); + amm.vote(std::nullopt, 100, std::nullopt, std::nullopt, std::nullopt, Ter(TecAmmEmpty)); + amm.withdraw(alice_, 100, std::nullopt, std::nullopt, Ter(TecAmmEmpty)); amm.deposit( - alice, USD(100), std::nullopt, std::nullopt, std::nullopt, ter(tecAMM_EMPTY)); - env(trust(alice, STAmount{amm.lptIssue(), 10'000}), ter(tecAMM_EMPTY)); + alice_, USD_(100), std::nullopt, std::nullopt, std::nullopt, Ter(TecAmmEmpty)); + env(trust(alice_, STAmount{amm.lptIssue(), 10'000}), Ter(TecAmmEmpty)); // Can deposit with tfTwoAssetIfEmpty option amm.deposit( - alice, + alice_, std::nullopt, - XRP(10'000), - USD(10'000), + kXRP(10'000), + USD_(10'000), std::nullopt, - tfTwoAssetIfEmpty, + kTF_TWO_ASSET_IF_EMPTY, std::nullopt, std::nullopt, 1'000); - BEAST_EXPECT(amm.expectBalances(XRP(10'000), USD(10'000), amm.tokens())); + BEAST_EXPECT(amm.expectBalances(kXRP(10'000), USD_(10'000), amm.tokens())); BEAST_EXPECT(amm.expectTradingFee(1'000)); BEAST_EXPECT(amm.expectAuctionSlot(100, 0, IOUAmount{0})); // Withdrawing all tokens deletes AMM since the number // of remaining trustlines is less than max - amm.withdrawAll(alice); + amm.withdrawAll(alice_); BEAST_EXPECT(!amm.ammExists()); BEAST_EXPECT(!env.le(keylet::ownerDir(amm.ammAccount()))); } @@ -5143,29 +5257,29 @@ private: return cfg; }), all); - fund(env, gw, {alice}, XRP(20'000), {USD(10'000)}); - AMM amm(env, gw, XRP(10'000), USD(10'000)); - for (auto i = 0; i < (maxDeletableAMMTrustLines * 2) + 10; ++i) + fund(env, gw_, {alice_}, kXRP(20'000), {USD_(10'000)}); + AMM amm(env, gw_, kXRP(10'000), USD_(10'000)); + for (auto i = 0; i < (kMAX_DELETABLE_AMM_TRUST_LINES * 2) + 10; ++i) { Account const a{std::to_string(i)}; - env.fund(XRP(1'000), a); + env.fund(kXRP(1'000), a); env(trust(a, STAmount{amm.lptIssue(), 10'000})); env.close(); } // The trustlines are partially deleted. - amm.withdrawAll(gw); + amm.withdrawAll(gw_); BEAST_EXPECT(amm.ammExists()); // AMMDelete has to be called twice to delete AMM. - amm.ammDelete(alice, ter(tecINCOMPLETE)); + amm.ammDelete(alice_, Ter(TecIncomplete)); BEAST_EXPECT(amm.ammExists()); // Deletes remaining trustlines and deletes AMM. - amm.ammDelete(alice); + amm.ammDelete(alice_); BEAST_EXPECT(!amm.ammExists()); BEAST_EXPECT(!env.le(keylet::ownerDir(amm.ammAccount()))); // Try redundant delete - amm.ammDelete(alice, ter(terNO_AMM)); + amm.ammDelete(alice_, Ter(TerNoAmm)); } } @@ -5175,10 +5289,10 @@ private: testcase("Clawback"); using namespace jtx; Env env(*this); - env.fund(XRP(2'000), gw); - env.fund(XRP(2'000), alice); - AMM const amm(env, gw, XRP(1'000), USD(1'000)); - env(fset(gw, asfAllowTrustLineClawback), ter(tecOWNERS)); + env.fund(kXRP(2'000), gw_); + env.fund(kXRP(2'000), alice_); + AMM const amm(env, gw_, kXRP(1'000), USD_(1'000)); + env(fset(gw_, kASF_ALLOW_TRUST_LINE_CLAWBACK), Ter(TecOwners)); } void @@ -5195,15 +5309,15 @@ private: try { BEAST_EXPECT( - info[jss::result][jss::account_data][jss::AMMID].asString() == + info[jss::kRESULT][jss::kACCOUNT_DATA][jss::kAMMID].asString() == to_string(amm.ammID())); } catch (...) { fail(); } - amm.deposit(carol, 1'000); - auto affected = env.meta()->getJson(JsonOptions::none)[sfAffectedNodes.fieldName]; + amm.deposit(carol_, 1'000); + auto affected = env.meta()->getJson(JsonOptions::None)[sfAffectedNodes.fieldName]; try { bool found = false; @@ -5212,10 +5326,10 @@ private: if (node.isMember(sfModifiedNode.fieldName) && node[sfModifiedNode.fieldName][sfLedgerEntryType.fieldName].asString() == "AccountRoot" && - node[sfModifiedNode.fieldName][sfFinalFields.fieldName][jss::Account] + node[sfModifiedNode.fieldName][sfFinalFields.fieldName][jss::kACCOUNT] .asString() == to_string(amm.ammAccount())) { - found = node[sfModifiedNode.fieldName][sfFinalFields.fieldName][jss::AMMID] + found = node[sfModifiedNode.fieldName][sfFinalFields.fieldName][jss::kAMMID] .asString() == to_string(amm.ammID()); break; } @@ -5236,18 +5350,18 @@ private: using namespace jtx; Account const ed("ed"); Account const gw1("gw1"); - auto const ETH = gw1["ETH"]; - auto const CAN = gw1["CAN"]; + auto const eth = gw1["ETH"]; + auto const can = gw1["CAN"]; // These tests are expected to fail if the OwnerPaysFee feature // is ever supported. Updates will need to be made to AMM handling // in the payment engine, and these tests will need to be updated. auto prep = [&](Env& env, auto gwRate, auto gw1Rate) { - fund(env, gw, {alice, carol, bob, ed}, XRP(2'000), {USD(2'000)}); - env.fund(XRP(2'000), gw1); - fund(env, gw1, {alice, carol, bob, ed}, {ETH(2'000), CAN(2'000)}, Fund::TokenOnly); - env(rate(gw, gwRate)); + fund(env, gw_, {alice_, carol_, bob_, ed}, kXRP(2'000), {USD_(2'000)}); + env.fund(kXRP(2'000), gw1); + fund(env, gw1, {alice_, carol_, bob_, ed}, {eth(2'000), can(2'000)}, Fund::TokenOnly); + env(rate(gw_, gwRate)); env(rate(gw1, gw1Rate)); env.close(); }; @@ -5273,23 +5387,23 @@ private: std::optional amm; if (i == 0 || i == 2) { - env(offer(ed, ETH(400), USD(400)), txflags(tfPassive)); + env(offer(ed, eth(400), USD_(400)), Txflags(kTF_PASSIVE)); env.close(); } if (i > 0) - amm.emplace(env, ed, USD(1'000), ETH(1'000)); - env(pay(carol, bob, USD(100)), path(~USD), sendmax(ETH(500))); + amm.emplace(env, ed, USD_(1'000), eth(1'000)); + env(pay(carol_, bob_, USD_(100)), Path(~USD_), Sendmax(eth(500))); env.close(); // CLOB and AMM, AMM is not selected if (i == 2) { - BEAST_EXPECT(amm->expectBalances(USD(1'000), ETH(1'000), amm->tokens())); + BEAST_EXPECT(amm->expectBalances(USD_(1'000), eth(1'000), amm->tokens())); } - BEAST_EXPECT(expectHolding(env, bob, USD(2'100))); + BEAST_EXPECT(expectHolding(env, bob_, USD_(2'100))); q[i] = Quality( Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + eth(2'000) - env.balance(carol_, eth), + env.balance(bob_, USD_) - USD_(2'000)}); } // CLOB is better quality than AMM BEAST_EXPECT(q[0] > q[1]); @@ -5308,27 +5422,27 @@ private: std::optional amm; if (i == 0 || i == 2) { - env(offer(ed, ETH(400), USD(400)), txflags(tfPassive)); + env(offer(ed, eth(400), USD_(400)), Txflags(kTF_PASSIVE)); env.close(); } if (i > 0) - amm.emplace(env, ed, USD(1'000), ETH(1'000)); - env(offer(alice, USD(400), ETH(400))); + amm.emplace(env, ed, USD_(1'000), eth(1'000)); + env(offer(alice_, USD_(400), eth(400))); env.close(); // AMM is not selected if (i > 0) { - BEAST_EXPECT(amm->expectBalances(USD(1'000), ETH(1'000), amm->tokens())); + BEAST_EXPECT(amm->expectBalances(USD_(1'000), eth(1'000), amm->tokens())); } if (i == 0 || i == 2) { // Fully crosses - BEAST_EXPECT(expectOffers(env, alice, 0)); + BEAST_EXPECT(expectOffers(env, alice_, 0)); } // Fails to cross because AMM is not selected else { - BEAST_EXPECT(expectOffers(env, alice, 1, {Amounts{USD(400), ETH(400)}})); + BEAST_EXPECT(expectOffers(env, alice_, 1, {Amounts{USD_(400), eth(400)}})); } BEAST_EXPECT(expectOffers(env, ed, 0)); } @@ -5346,17 +5460,17 @@ private: std::optional amm; if (i == 0 || i == 2) { - env(offer(ed, ETH(400), USD(300)), txflags(tfPassive)); + env(offer(ed, eth(400), USD_(300)), Txflags(kTF_PASSIVE)); env.close(); } if (i > 0) - amm.emplace(env, ed, USD(1'000), ETH(1'000)); - env(pay(carol, bob, USD(100)), path(~USD), sendmax(ETH(500))); + amm.emplace(env, ed, USD_(1'000), eth(1'000)); + env(pay(carol_, bob_, USD_(100)), Path(~USD_), Sendmax(eth(500))); env.close(); // AMM and CLOB are selected if (i > 0) { - BEAST_EXPECT(!amm->expectBalances(USD(1'000), ETH(1'000), amm->tokens())); + BEAST_EXPECT(!amm->expectBalances(USD_(1'000), eth(1'000), amm->tokens())); } if (i == 2 && !features[fixAMMv1_1]) { @@ -5369,8 +5483,8 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(378'6327949540823), -13}, - STAmount{USD, UINT64_C(283'9745962155617), -13}}}})); + STAmount{eth, UINT64_C(378'6327949540823), -13}, + STAmount{USD_, UINT64_C(283'9745962155617), -13}}}})); } else { @@ -5379,8 +5493,8 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(378'6327949540813), -13}, - STAmount{USD, UINT64_C(283'974596215561), -12}}}})); + STAmount{eth, UINT64_C(378'6327949540813), -13}, + STAmount{USD_, UINT64_C(283'974596215561), -12}}}})); } } else @@ -5392,8 +5506,8 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(325'299461620749), -12}, - STAmount{USD, UINT64_C(243'9745962155617), -13}}}})); + STAmount{eth, UINT64_C(325'299461620749), -12}, + STAmount{USD_, UINT64_C(243'9745962155617), -13}}}})); } else { @@ -5402,8 +5516,8 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(325'299461620748), -12}, - STAmount{USD, UINT64_C(243'974596215561), -12}}}})); + STAmount{eth, UINT64_C(325'299461620748), -12}, + STAmount{USD_, UINT64_C(243'974596215561), -12}}}})); } } } @@ -5416,8 +5530,8 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(378'6327949540812), -13}, - STAmount{USD, UINT64_C(283'9745962155609), -13}}}})); + STAmount{eth, UINT64_C(378'6327949540812), -13}, + STAmount{USD_, UINT64_C(283'9745962155609), -13}}}})); } else { @@ -5426,15 +5540,15 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(325'2994616207479), -13}, - STAmount{USD, UINT64_C(243'9745962155609), -13}}}})); + STAmount{eth, UINT64_C(325'2994616207479), -13}, + STAmount{USD_, UINT64_C(243'9745962155609), -13}}}})); } } - BEAST_EXPECT(expectHolding(env, bob, USD(2'100))); + BEAST_EXPECT(expectHolding(env, bob_, USD_(2'100))); q[i] = Quality( Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + eth(2'000) - env.balance(carol_, eth), + env.balance(bob_, USD_) - USD_(2'000)}); } // AMM is better quality BEAST_EXPECT(q[1] > q[0]); @@ -5450,17 +5564,17 @@ private: std::optional amm; if (i == 0 || i == 2) { - env(offer(ed, ETH(400), USD(250)), txflags(tfPassive)); + env(offer(ed, eth(400), USD_(250)), Txflags(kTF_PASSIVE)); env.close(); } if (i > 0) - amm.emplace(env, ed, USD(1'000), ETH(1'000)); - env(offer(alice, USD(250), ETH(400))); + amm.emplace(env, ed, USD_(1'000), eth(1'000)); + env(offer(alice_, USD_(250), eth(400))); env.close(); // AMM is selected in both cases if (i > 0) { - BEAST_EXPECT(!amm->expectBalances(USD(1'000), ETH(1'000), amm->tokens())); + BEAST_EXPECT(!amm->expectBalances(USD_(1'000), eth(1'000), amm->tokens())); } // Partially crosses, AMM is selected, CLOB fails // limitQuality @@ -5470,14 +5584,15 @@ private: { if (!features[fixAMMv1_1]) { - BEAST_EXPECT(expectOffers(env, ed, 1, {{Amounts{ETH(400), USD(250)}}})); + BEAST_EXPECT( + expectOffers(env, ed, 1, {{Amounts{eth(400), USD_(250)}}})); BEAST_EXPECT(expectOffers( env, - alice, + alice_, 1, {{Amounts{ - STAmount{USD, UINT64_C(40'5694150420947), -13}, - STAmount{ETH, UINT64_C(64'91106406735152), -14}, + STAmount{USD_, UINT64_C(40'5694150420947), -13}, + STAmount{eth, UINT64_C(64'91106406735152), -14}, }}})); } else @@ -5490,10 +5605,10 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(335'0889359326475), -13}, - STAmount{USD, UINT64_C(209'4305849579047), -13}, + STAmount{eth, UINT64_C(335'0889359326475), -13}, + STAmount{USD_, UINT64_C(209'4305849579047), -13}, }}})); - BEAST_EXPECT(expectOffers(env, alice, 0)); + BEAST_EXPECT(expectOffers(env, alice_, 0)); } } else @@ -5506,10 +5621,10 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(335'0889359326485), -13}, - STAmount{USD, UINT64_C(209'4305849579053), -13}, + STAmount{eth, UINT64_C(335'0889359326485), -13}, + STAmount{USD_, UINT64_C(209'4305849579053), -13}, }}})); - BEAST_EXPECT(expectOffers(env, alice, 0)); + BEAST_EXPECT(expectOffers(env, alice_, 0)); } else { @@ -5519,10 +5634,10 @@ private: ed, 1, {{Amounts{ - STAmount{ETH, UINT64_C(335'0889359326475), -13}, - STAmount{USD, UINT64_C(209'4305849579047), -13}, + STAmount{eth, UINT64_C(335'0889359326475), -13}, + STAmount{USD_, UINT64_C(209'4305849579047), -13}, }}})); - BEAST_EXPECT(expectOffers(env, alice, 0)); + BEAST_EXPECT(expectOffers(env, alice_, 0)); } } } @@ -5554,18 +5669,21 @@ private: if (i == 0 || i == 2) { - env(offer(ed, ETH(400), CAN(400)), txflags(tfPassive)); - env(offer(ed, CAN(400), USD(400))), txflags(tfPassive); + env(offer(ed, eth(400), can(400)), Txflags(kTF_PASSIVE)); + env(offer(ed, can(400), USD_(400))), Txflags(kTF_PASSIVE); env.close(); } if (i > 0) - amm.emplace(env, ed, ETH(1'000), USD(1'000)); + amm.emplace(env, ed, eth(1'000), USD_(1'000)); - env(pay(carol, bob, USD(100)), path(~USD), path(~CAN, ~USD), sendmax(ETH(600))); + env(pay(carol_, bob_, USD_(100)), + Path(~USD_), + Path(~can, ~USD_), + Sendmax(eth(600))); env.close(); - BEAST_EXPECT(expectHolding(env, bob, USD(2'100))); + BEAST_EXPECT(expectHolding(env, bob_, USD_(2'100))); if (i == 2 && !features[fixAMMv1_1]) { @@ -5573,27 +5691,27 @@ private: { // Liquidity is consumed from AMM strand only BEAST_EXPECT(amm->expectBalances( - STAmount{ETH, UINT64_C(1'176'66038955758), -11}, - USD(850), + STAmount{eth, UINT64_C(1'176'66038955758), -11}, + USD_(850), amm->tokens())); } else { BEAST_EXPECT(amm->expectBalances( - STAmount{ETH, UINT64_C(1'179'540094339627), -12}, - STAmount{USD, UINT64_C(847'7880529867501), -13}, + STAmount{eth, UINT64_C(1'179'540094339627), -12}, + STAmount{USD_, UINT64_C(847'7880529867501), -13}, amm->tokens())); BEAST_EXPECT(expectOffers( env, ed, 2, {{Amounts{ - STAmount{ETH, UINT64_C(343'3179205198749), -13}, - STAmount{CAN, UINT64_C(343'3179205198749), -13}, + STAmount{eth, UINT64_C(343'3179205198749), -13}, + STAmount{can, UINT64_C(343'3179205198749), -13}, }, Amounts{ - STAmount{CAN, UINT64_C(362'2119470132499), -13}, - STAmount{USD, UINT64_C(362'2119470132499), -13}, + STAmount{can, UINT64_C(362'2119470132499), -13}, + STAmount{USD_, UINT64_C(362'2119470132499), -13}, }}})); } } @@ -5603,34 +5721,34 @@ private: { // Liquidity is consumed from AMM strand only BEAST_EXPECT(amm->expectBalances( - STAmount{ETH, UINT64_C(1'176'660389557593), -12}, - USD(850), + STAmount{eth, UINT64_C(1'176'660389557593), -12}, + USD_(850), amm->tokens())); } else { BEAST_EXPECT(amm->expectBalances( - STAmount{ETH, UINT64_C(1'179'54009433964), -11}, - STAmount{USD, UINT64_C(847'7880529867501), -13}, + STAmount{eth, UINT64_C(1'179'54009433964), -11}, + STAmount{USD_, UINT64_C(847'7880529867501), -13}, amm->tokens())); BEAST_EXPECT(expectOffers( env, ed, 2, {{Amounts{ - STAmount{ETH, UINT64_C(343'3179205198749), -13}, - STAmount{CAN, UINT64_C(343'3179205198749), -13}, + STAmount{eth, UINT64_C(343'3179205198749), -13}, + STAmount{can, UINT64_C(343'3179205198749), -13}, }, Amounts{ - STAmount{CAN, UINT64_C(362'2119470132499), -13}, - STAmount{USD, UINT64_C(362'2119470132499), -13}, + STAmount{can, UINT64_C(362'2119470132499), -13}, + STAmount{USD_, UINT64_C(362'2119470132499), -13}, }}})); } } q[i] = Quality( Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + eth(2'000) - env.balance(carol_, eth), + env.balance(bob_, USD_) - USD_(2'000)}); } BEAST_EXPECT(q[1] > q[0]); BEAST_EXPECT(q[2] > q[0] && q[2] < q[1]); @@ -5654,53 +5772,53 @@ private: bool closeLedger, std::optional extra = std::nullopt) { Env env(*this, features); - fund(env, gw, {alice}, XRP(1'000), {USD(10)}); - AMM amm(env, gw, XRP(10), USD(10), {.tfee = tfee, .close = closeLedger}); - amm.deposit(alice, USD(10), XRP(10)); - amm.vote(VoteArg{.account = alice, .tfee = tfee, .err = ter(err1)}); - amm.withdraw(WithdrawArg{.account = gw, .asset1Out = USD(1), .err = ter(err2)}); + fund(env, gw_, {alice_}, kXRP(1'000), {USD_(10)}); + AMM amm(env, gw_, kXRP(10), USD_(10), {.tfee = tfee, .close = closeLedger}); + amm.deposit(alice_, USD_(10), kXRP(10)); + amm.vote(VoteArg{.account = alice_, .tfee = tfee, .err = Ter(err1)}); + amm.withdraw(WithdrawArg{.account = gw_, .asset1Out = USD_(1), .err = Ter(err2)}); // with the amendment disabled and ledger not closed, // second vote succeeds if the first vote sets the trading fee // to non-zero; if the first vote sets the trading fee to >0 && // <9 then the second withdraw succeeds if the second vote sets // the trading fee so that the discounted fee is non-zero - amm.vote(VoteArg{.account = alice, .tfee = 20, .err = ter(err3)}); - amm.withdraw(WithdrawArg{.account = gw, .asset1Out = USD(2), .err = ter(err4)}); + amm.vote(VoteArg{.account = alice_, .tfee = 20, .err = Ter(err3)}); + amm.withdraw(WithdrawArg{.account = gw_, .asset1Out = USD_(2), .err = Ter(err4)}); }; // ledger is closed after each transaction, vote/withdraw don't fail // regardless whether the amendment is enabled or not - test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, true); - test(all - fixInnerObjTemplate, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, true); + test(all, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 0, true); + test(all - fixInnerObjTemplate, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 0, true); // ledger is not closed after each transaction // vote/withdraw don't fail if the amendment is enabled - test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, false); + test(all, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 0, false); // vote/withdraw fail if the amendment is not enabled // second vote/withdraw still fail: second vote fails because // the initial trading fee is 0, consequently second withdraw fails // because the second vote fails test( all - fixInnerObjTemplate, - tefEXCEPTION, - tefEXCEPTION, - tefEXCEPTION, - tefEXCEPTION, + TefException, + TefException, + TefException, + TefException, 0, false); // if non-zero trading/discounted fee then vote/withdraw // don't fail whether the ledger is closed or not and // the amendment is enabled or not - test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, true); - test(all - fixInnerObjTemplate, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, true); - test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, false); - test(all - fixInnerObjTemplate, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, false); + test(all, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 10, true); + test(all - fixInnerObjTemplate, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 10, true); + test(all, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 10, false); + test(all - fixInnerObjTemplate, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 10, false); // non-zero trading fee but discounted fee is 0, vote doesn't fail // but withdraw fails - test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 9, false); + test(all, TesSuccess, TesSuccess, TesSuccess, TesSuccess, 9, false); // second vote sets the trading fee to non-zero, consequently // second withdraw doesn't fail even if the amendment is not // enabled and the ledger is not closed - test(all - fixInnerObjTemplate, tesSUCCESS, tefEXCEPTION, tesSUCCESS, tesSUCCESS, 9, false); + test(all - fixInnerObjTemplate, TesSuccess, TefException, TesSuccess, TesSuccess, 9, false); } void @@ -5724,8 +5842,8 @@ private: Succeed // Both succeed }; using enum Status; - auto const xrpIouAmounts10_100 = TAmounts{XRPAmount{10}, IOUAmount{100}}; - auto const iouXrpAmounts10_100 = TAmounts{IOUAmount{10}, XRPAmount{100}}; + auto const xrpIouAmounts10100 = TAmounts{XRPAmount{10}, IOUAmount{100}}; + auto const iouXrpAmounts10100 = TAmounts{IOUAmount{10}, XRPAmount{100}}; // clang-format off std::vector> const tests = { //Pool In , Pool Out, Quality , Fee, Status @@ -5763,8 +5881,8 @@ private: {"0.009059512633902926", "7994028", Quality{5477511954775533172}, 1000, Fail}, {"1", "1.0", Quality{0}, 100, Fail}, {"1.0", "1", Quality{0}, 100, Fail}, - {"10", "10.0", Quality{xrpIouAmounts10_100}, 100, Fail}, - {"10.0", "10", Quality{iouXrpAmounts10_100}, 100, Fail}, + {"10", "10.0", Quality{xrpIouAmounts10100}, 100, Fail}, + {"10.0", "10", Quality{iouXrpAmounts10100}, 100, Fail}, {"69864389131", "287631.4543025075", Quality{6487623473313516078}, 451, Succeed}, {"4328342973", "12453825.99247381", Quality{6272522264364865181}, 997, Succeed}, {"32347017", "7003.93031579449", Quality{6347261126087916670}, 1000, Succeed}, @@ -5794,7 +5912,7 @@ private: Env const env(*this, features, std::make_unique(&logs)); auto rules = env.current()->rules(); CurrentTransactionRulesGuard const rg(rules); - NumberMantissaScaleGuard const sg(MantissaRange::mantissa_scale::small); + NumberMantissaScaleGuard const sg(MantissaRange::MantissaScale::Small); for (auto const& t : tests) { @@ -5914,55 +6032,55 @@ private: testAMM([&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .flags = tfSingleAsset, - .err = ter(temMALFORMED), + .flags = kTF_SINGLE_ASSET, + .err = Ter(TemMalformed), }; ammAlice.withdraw(args); }); testAMM([&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .flags = tfOneAssetLPToken, - .err = ter(temMALFORMED), + .flags = kTF_ONE_ASSET_LP_TOKEN, + .err = Ter(TemMalformed), }; ammAlice.withdraw(args); }); testAMM([&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .flags = tfLimitLPToken, - .err = ter(temMALFORMED), + .flags = kTF_LIMIT_LP_TOKEN, + .err = Ter(TemMalformed), }; ammAlice.withdraw(args); }); testAMM([&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .asset1Out = XRP(100), - .asset2Out = XRP(100), - .err = ter(temBAD_AMM_TOKENS), + .asset1Out = kXRP(100), + .asset2Out = kXRP(100), + .err = Ter(TemBadAmmTokens), }; ammAlice.withdraw(args); }); testAMM([&](AMM& ammAlice, Env& env) { WithdrawArg const args{ - .asset1Out = XRP(100), - .asset2Out = BAD(100), - .err = ter(temBAD_CURRENCY), + .asset1Out = kXRP(100), + .asset2Out = BAD_(100), + .err = Ter(TemBadCurrency), }; ammAlice.withdraw(args); }); testAMM([&](AMM& ammAlice, Env& env) { Json::Value jv; - jv[jss::TransactionType] = jss::AMMWithdraw; - jv[jss::Flags] = tfLimitLPToken; - jv[jss::Account] = alice.human(); + jv[jss::kTRANSACTION_TYPE] = jss::AMMWithdraw; + jv[jss::kFLAGS] = kTF_LIMIT_LP_TOKEN; + jv[jss::kACCOUNT] = alice_.human(); ammAlice.setTokens(jv); - XRP(100).value().setJson(jv[jss::Amount]); - USD(100).value().setJson(jv[jss::EPrice]); - env(jv, ter(temBAD_AMM_TOKENS)); + kXRP(100).value().setJson(jv[jss::kAMOUNT]); + USD_(100).value().setJson(jv[jss::kE_PRICE]); + env(jv, Ter(TemBadAmmTokens)); }); } @@ -5988,7 +6106,7 @@ private: char const* testCase; double const poolUsdBIT; double const poolUsdGH; - sendmax const sendMaxUsdBIT; + Sendmax const sendMaxUsdBIT; STAmount const sendUsdGH; STAmount const failUsdGH; STAmount const failUsdGHr; @@ -6207,7 +6325,7 @@ private: { Env env(*this, features, std::make_unique(&logs)); - env.fund(XRP(5'000), gatehub, bitstamp, trader); + env.fund(kXRP(5'000), gatehub, bitstamp, trader); env.close(); if (input.rateGH != 0.0) @@ -6235,10 +6353,10 @@ private: env.close(); env(pay(trader, trader, input.sendUsdGH), - path(~usdGH), - path(~btcGH, ~usdGH), - sendmax(input.sendMaxUsdBIT), - txflags(tfPartialPayment)); + Path(~usdGH), + Path(~btcGH, ~usdGH), + Sendmax(input.sendMaxUsdBIT), + Txflags(kTF_PARTIAL_PAYMENT)); env.close(); auto const failUsdGH = features[fixAMMv1_1] ? input.failUsdGHr : input.failUsdGH; @@ -6288,24 +6406,24 @@ private: testcase("swapRounding"); using namespace jtx; - STAmount const xrpPool{XRP, UINT64_C(51600'000981)}; - STAmount const iouPool{USD, UINT64_C(803040'9987141784), -10}; + STAmount const xrpPool{kXRP, UINT64_C(51600'000981)}; + STAmount const iouPool{USD_, UINT64_C(803040'9987141784), -10}; - STAmount const xrpBob{XRP, UINT64_C(1092'878933)}; - STAmount const iouBob{USD, UINT64_C(3'988035892323031), -28}; // 3.9...e-13 + STAmount const xrpBob{kXRP, UINT64_C(1092'878933)}; + STAmount const iouBob{USD_, UINT64_C(3'988035892323031), -28}; // 3.9...e-13 testAMM( [&](AMM& amm, Env& env) { // Check our AMM starting conditions. - auto [xrpBegin, iouBegin, lptBegin] = amm.balances(XRP, USD); + auto [xrpBegin, iouBegin, lptBegin] = amm.balances(kXRP, USD_); // Set Bob's starting conditions. - env.fund(xrpBob, bob); - env.trust(USD(1'000'000), bob); - env(pay(gw, bob, iouBob)); + env.fund(xrpBob, bob_); + env.trust(USD_(1'000'000), bob_); + env(pay(gw_, bob_, iouBob)); env.close(); - env(offer(bob, XRP(6300), USD(100'000))); + env(offer(bob_, kXRP(6300), USD_(100'000))); env.close(); // Assert that AMM is unchanged. @@ -6329,32 +6447,32 @@ private: { Env env(*this, features); - fund(env, gw, {alice, carol}, XRP(1'000'000), {USD(1'000'000)}); + fund(env, gw_, {alice_, carol_}, kXRP(1'000'000), {USD_(1'000'000)}); // This offer blocks AMM offer in pre-amendment - env(offer(alice, XRP(1), USD(0.01))); + env(offer(alice_, kXRP(1), USD_(0.01))); env.close(); - AMM const amm(env, gw, XRP(200'000), USD(100'000)); + AMM const amm(env, gw_, kXRP(200'000), USD_(100'000)); // The offer doesn't cross AMM in pre-amendment code // It crosses AMM in post-amendment code - env(offer(carol, USD(0.49), XRP(1))); + env(offer(carol_, USD_(0.49), kXRP(1))); env.close(); if (!features[fixAMMv1_1]) { - BEAST_EXPECT(amm.expectBalances(XRP(200'000), USD(100'000), amm.tokens())); - BEAST_EXPECT(expectOffers(env, alice, 1, {{Amounts{XRP(1), USD(0.01)}}})); + BEAST_EXPECT(amm.expectBalances(kXRP(200'000), USD_(100'000), amm.tokens())); + BEAST_EXPECT(expectOffers(env, alice_, 1, {{Amounts{kXRP(1), USD_(0.01)}}})); // Carol's offer is blocked by alice's offer - BEAST_EXPECT(expectOffers(env, carol, 1, {{Amounts{USD(0.49), XRP(1)}}})); + BEAST_EXPECT(expectOffers(env, carol_, 1, {{Amounts{USD_(0.49), kXRP(1)}}})); } else { BEAST_EXPECT( - amm.expectBalances(XRPAmount(200'000'980'005), USD(99'999.51), amm.tokens())); - BEAST_EXPECT(expectOffers(env, alice, 1, {{Amounts{XRP(1), USD(0.01)}}})); + amm.expectBalances(XRPAmount(200'000'980'005), USD_(99'999.51), amm.tokens())); + BEAST_EXPECT(expectOffers(env, alice_, 1, {{Amounts{kXRP(1), USD_(0.01)}}})); // Carol's offer crosses AMM - BEAST_EXPECT(expectOffers(env, carol, 0)); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } } @@ -6363,53 +6481,53 @@ private: { Env env(*this, features); - fund(env, gw, {alice, carol}, XRP(1'000'000), {USD(1'000'000)}); + fund(env, gw_, {alice_, carol_}, kXRP(1'000'000), {USD_(1'000'000)}); // There is no blocking offer // env(offer(alice, XRP(1), USD(0.01))); - AMM const amm(env, gw, XRP(200'000), USD(100'000)); + AMM const amm(env, gw_, kXRP(200'000), USD_(100'000)); // The offer crosses AMM - env(offer(carol, USD(0.49), XRP(1))); + env(offer(carol_, USD_(0.49), kXRP(1))); env.close(); // The same result as with the blocking offer BEAST_EXPECT( - amm.expectBalances(XRPAmount(200'000'980'005), USD(99'999.51), amm.tokens())); + amm.expectBalances(XRPAmount(200'000'980'005), USD_(99'999.51), amm.tokens())); // Carol's offer crosses AMM - BEAST_EXPECT(expectOffers(env, carol, 0)); + BEAST_EXPECT(expectOffers(env, carol_, 0)); } // XRP/USD crosses AMM { Env env(*this, features); - fund(env, gw, {alice, carol, bob}, XRP(10'000), {USD(1'000)}); + fund(env, gw_, {alice_, carol_, bob_}, kXRP(10'000), {USD_(1'000)}); // This offer blocks AMM offer in pre-amendment // It crosses AMM in post-amendment code - env(offer(bob, USD(1), XRPAmount(500))); + env(offer(bob_, USD_(1), XRPAmount(500))); env.close(); - AMM const amm(env, alice, XRP(1'000), USD(500)); - env(offer(carol, XRP(100), USD(55))); + AMM const amm(env, alice_, kXRP(1'000), USD_(500)); + env(offer(carol_, kXRP(100), USD_(55))); env.close(); if (!features[fixAMMv1_1]) { - BEAST_EXPECT(amm.expectBalances(XRP(1'000), USD(500), amm.tokens())); - BEAST_EXPECT(expectOffers(env, bob, 1, {{Amounts{USD(1), XRPAmount(500)}}})); - BEAST_EXPECT(expectOffers(env, carol, 1, {{Amounts{XRP(100), USD(55)}}})); + BEAST_EXPECT(amm.expectBalances(kXRP(1'000), USD_(500), amm.tokens())); + BEAST_EXPECT(expectOffers(env, bob_, 1, {{Amounts{USD_(1), XRPAmount(500)}}})); + BEAST_EXPECT(expectOffers(env, carol_, 1, {{Amounts{kXRP(100), USD_(55)}}})); } else { BEAST_EXPECT(amm.expectBalances( XRPAmount(909'090'909), - STAmount{USD, UINT64_C(550'000000055), -9}, + STAmount{USD_, UINT64_C(550'000000055), -9}, amm.tokens())); BEAST_EXPECT(expectOffers( env, - carol, + carol_, 1, - {{Amounts{XRPAmount{9'090'909}, STAmount{USD, 4'99999995, -8}}}})); - BEAST_EXPECT(expectOffers(env, bob, 1, {{Amounts{USD(1), XRPAmount(500)}}})); + {{Amounts{XRPAmount{9'090'909}, STAmount{USD_, 4'99999995, -8}}}})); + BEAST_EXPECT(expectOffers(env, bob_, 1, {{Amounts{USD_(1), XRPAmount(500)}}})); } } @@ -6417,15 +6535,15 @@ private: // pre- and post-amendment. { Env env(*this, features); - fund(env, gw, {alice, carol, bob}, XRP(10'000), {USD(1'000)}); + fund(env, gw_, {alice_, carol_, bob_}, kXRP(10'000), {USD_(1'000)}); - AMM const amm(env, alice, XRP(1'000), USD(500)); - env(offer(carol, XRP(100), USD(55))); + AMM const amm(env, alice_, kXRP(1'000), USD_(500)); + env(offer(carol_, kXRP(100), USD_(55))); env.close(); BEAST_EXPECT(amm.expectBalances( - XRPAmount(909'090'909), STAmount{USD, UINT64_C(550'000000055), -9}, amm.tokens())); + XRPAmount(909'090'909), STAmount{USD_, UINT64_C(550'000000055), -9}, amm.tokens())); BEAST_EXPECT(expectOffers( - env, carol, 1, {{Amounts{XRPAmount{9'090'909}, STAmount{USD, 4'99999995, -8}}}})); + env, carol_, 1, {{Amounts{XRPAmount{9'090'909}, STAmount{USD_, 4'99999995, -8}}}})); } } @@ -6439,54 +6557,54 @@ private: { std::string logs; Env env(*this, features, std::make_unique(&logs)); - fund(env, gw, {alice, carol}, XRP(1'000'000'000), {USD(1'000'000'000)}); - AMM amm(env, gw, XRP(2), USD(1)); - amm.deposit(alice, IOUAmount{1'876123487565916, -15}); - amm.deposit(carol, IOUAmount{1'000'000}); - amm.withdrawAll(alice); - BEAST_EXPECT(amm.expectLPTokens(alice, IOUAmount{0})); - amm.withdrawAll(carol); - BEAST_EXPECT(amm.expectLPTokens(carol, IOUAmount{0})); + fund(env, gw_, {alice_, carol_}, kXRP(1'000'000'000), {USD_(1'000'000'000)}); + AMM amm(env, gw_, kXRP(2), USD_(1)); + amm.deposit(alice_, IOUAmount{1'876123487565916, -15}); + amm.deposit(carol_, IOUAmount{1'000'000}); + amm.withdrawAll(alice_); + BEAST_EXPECT(amm.expectLPTokens(alice_, IOUAmount{0})); + amm.withdrawAll(carol_); + BEAST_EXPECT(amm.expectLPTokens(carol_, IOUAmount{0})); auto const lpToken = - getAccountLines(env, gw, amm.lptIssue())[jss::lines][0u][jss::balance]; - auto const lpTokenBalance = amm.ammRpcInfo()[jss::amm][jss::lp_token][jss::value]; + getAccountLines(env, gw_, amm.lptIssue())[jss::kLINES][0u][jss::kBALANCE]; + auto const lpTokenBalance = amm.ammRpcInfo()[jss::amm][jss::kLP_TOKEN][jss::kVALUE]; BEAST_EXPECT(lpToken == "1414.213562373095" && lpTokenBalance == "1414.213562373"); if (!features[fixAMMv1_1]) { - amm.withdrawAll(gw, std::nullopt, ter(tecAMM_BALANCE)); + amm.withdrawAll(gw_, std::nullopt, Ter(TecAmmBalance)); BEAST_EXPECT(amm.ammExists()); } else { - amm.withdrawAll(gw); + amm.withdrawAll(gw_); BEAST_EXPECT(!amm.ammExists()); } } // Last Liquidity Provider is the issuer of two tokens, or not // the issuer - for (auto const& lp : {gw, bob}) + for (auto const& lp : {gw_, bob_}) { Env env(*this, features); - auto const ABC = gw["ABC"]; + auto const abc = gw_["ABC"]; fund( env, - gw, - {alice, carol, bob}, - XRP(1'000), - {USD(1'000'000'000), ABC(1'000'000'000'000)}); - AMM amm(env, lp, ABC(2'000'000), USD(1)); - amm.deposit(alice, IOUAmount{1'876123487565916, -15}); - amm.deposit(carol, IOUAmount{1'000'000}); - amm.withdrawAll(alice); - amm.withdrawAll(carol); + gw_, + {alice_, carol_, bob_}, + kXRP(1'000), + {USD_(1'000'000'000), abc(1'000'000'000'000)}); + AMM amm(env, lp, abc(2'000'000), USD_(1)); + amm.deposit(alice_, IOUAmount{1'876123487565916, -15}); + amm.deposit(carol_, IOUAmount{1'000'000}); + amm.withdrawAll(alice_); + amm.withdrawAll(carol_); auto const lpToken = - getAccountLines(env, lp, amm.lptIssue())[jss::lines][0u][jss::balance]; - auto const lpTokenBalance = amm.ammRpcInfo()[jss::amm][jss::lp_token][jss::value]; + getAccountLines(env, lp, amm.lptIssue())[jss::kLINES][0u][jss::kBALANCE]; + auto const lpTokenBalance = amm.ammRpcInfo()[jss::amm][jss::kLP_TOKEN][jss::kVALUE]; BEAST_EXPECT(lpToken == "1414.213562373095" && lpTokenBalance == "1414.213562373"); if (!features[fixAMMv1_1]) { - amm.withdrawAll(lp, std::nullopt, ter(tecAMM_BALANCE)); + amm.withdrawAll(lp, std::nullopt, Ter(TecAmmBalance)); BEAST_EXPECT(amm.ammExists()); } else @@ -6500,35 +6618,35 @@ private: // XRP/IOU { Env env(*this, features); - fund(env, gw, {alice}, XRP(1'000), {USD(1'000)}); - AMM amm(env, gw, XRP(10), USD(10)); - amm.deposit(alice, 1'000); - auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw); + fund(env, gw_, {alice_}, kXRP(1'000), {USD_(1'000)}); + AMM amm(env, gw_, kXRP(10), USD_(10)); + amm.deposit(alice_, 1'000); + auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw_); BEAST_EXPECT(res && !res.value()); - res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), alice); + res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), alice_); BEAST_EXPECT(res && !res.value()); } // IOU/IOU, issuer of both IOU { Env env(*this, features); - fund(env, gw, {alice}, XRP(1'000), {USD(1'000), EUR(1'000)}); - AMM amm(env, gw, EUR(10), USD(10)); - amm.deposit(alice, 1'000); - auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw); + fund(env, gw_, {alice_}, kXRP(1'000), {USD_(1'000), EUR_(1'000)}); + AMM amm(env, gw_, EUR_(10), USD_(10)); + amm.deposit(alice_, 1'000); + auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw_); BEAST_EXPECT(res && !res.value()); - res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), alice); + res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), alice_); BEAST_EXPECT(res && !res.value()); } // IOU/IOU, issuer of one IOU { Env env(*this, features); Account const gw1("gw1"); - auto const YAN = gw1["YAN"]; - fund(env, gw, {gw1}, XRP(1'000), {USD(1'000)}); - fund(env, gw1, {gw}, XRP(1'000), {YAN(1'000)}, Fund::TokenOnly); - AMM amm(env, gw1, YAN(10), USD(10)); - amm.deposit(gw, 1'000); - auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw); + auto const yan = gw1["YAN"]; + fund(env, gw_, {gw1}, kXRP(1'000), {USD_(1'000)}); + fund(env, gw1, {gw_}, kXRP(1'000), {yan(1'000)}, Fund::TokenOnly); + AMM amm(env, gw1, yan(10), USD_(10)); + amm.deposit(gw_, 1'000); + auto res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw_); BEAST_EXPECT(res && !res.value()); res = isOnlyLiquidityProvider(*env.current(), amm.lptIssue(), gw1); BEAST_EXPECT(res && !res.value()); @@ -6543,21 +6661,21 @@ private: // Issuer has clawback enabled Env env(*this, features); - env.fund(XRP(1'000), gw); - env(fset(gw, asfAllowTrustLineClawback)); - fund(env, gw, {alice}, XRP(1'000), {USD(1'000)}, Fund::Acct); + env.fund(kXRP(1'000), gw_); + env(fset(gw_, kASF_ALLOW_TRUST_LINE_CLAWBACK)); + fund(env, gw_, {alice_}, kXRP(1'000), {USD_(1'000)}, Fund::Acct); env.close(); // If featureAMMClawback is not enabled, AMMCreate is not allowed for // clawback-enabled issuer if (!features[featureAMMClawback]) { - AMM const amm(env, gw, XRP(100), USD(100), ter(tecNO_PERMISSION)); - AMM const amm1(env, alice, USD(100), XRP(100), ter(tecNO_PERMISSION)); - env(fclear(gw, asfAllowTrustLineClawback)); + AMM const amm(env, gw_, kXRP(100), USD_(100), Ter(TecNoPermission)); + AMM const amm1(env, alice_, USD_(100), kXRP(100), Ter(TecNoPermission)); + env(fclear(gw_, kASF_ALLOW_TRUST_LINE_CLAWBACK)); env.close(); // Can't be cleared - AMM const amm2(env, gw, XRP(100), USD(100), ter(tecNO_PERMISSION)); + AMM const amm2(env, gw_, kXRP(100), USD_(100), Ter(TecNoPermission)); } // If featureAMMClawback is enabled, AMMCreate is allowed for // clawback-enabled issuer. Clawback from the AMM Account is not @@ -6566,8 +6684,8 @@ private: // AMMClawback transaction to claw back from AMM Account. else { - AMM const amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS)); - AMM const amm1(env, alice, USD(100), XRP(200), ter(tecDUPLICATE)); + AMM const amm(env, gw_, kXRP(100), USD_(100), Ter(TesSuccess)); + AMM const amm1(env, alice_, USD_(100), kXRP(200), Ter(TecDuplicate)); // Construct the amount being clawed back using AMM account. // By doing this, we make the clawback transaction's Amount field's @@ -6578,10 +6696,10 @@ private: // `issuer` subfield represents the account being clawed back, which // is confusing. auto const error = - features[featureSingleAssetVault] ? ter{tecPSEUDO_ACCOUNT} : ter{tecAMM_ACCOUNT}; - Issue const usd(USD.issue().currency, amm.ammAccount()); + features[featureSingleAssetVault] ? Ter{TecPseudoAccount} : Ter{TecAmmAccount}; + Issue const usd(USD_.issue().currency, amm.ammAccount()); auto amount = amountFromString(usd, "10"); - env(claw(gw, amount), error); + env(claw(gw_, amount), error); } } @@ -6595,11 +6713,11 @@ private: // between gw and alice, and create an AMM account. // And also test the callback function. auto testAMMDeposit = [&](Env& env, std::function cb) { - env.fund(XRP(1'000), gw); - fund(env, gw, {alice}, XRP(1'000), {USD(1'000)}, Fund::Acct); + env.fund(kXRP(1'000), gw_); + fund(env, gw_, {alice_}, kXRP(1'000), {USD_(1'000)}, Fund::Acct); env.close(); - AMM amm(env, alice, XRP(100), USD(100), ter(tesSUCCESS)); - env(trust(gw, alice["USD"](0), tfSetFreeze)); + AMM amm(env, alice_, kXRP(100), USD_(100), Ter(TesSuccess)); + env(trust(gw_, alice_["USD"](0), kTF_SET_FREEZE)); cb(amm); }; @@ -6608,7 +6726,8 @@ private: { Env env(*this, features); testAMMDeposit(env, [&](AMM& amm) { - amm.deposit(alice, USD(100), XRP(100), std::nullopt, tfTwoAsset, ter(tecFROZEN)); + amm.deposit( + alice_, USD_(100), kXRP(100), std::nullopt, kTF_TWO_ASSET, Ter(TecFrozen)); }); } @@ -6618,7 +6737,12 @@ private: Env env(*this, features); testAMMDeposit(env, [&](AMM& amm) { amm.deposit( - alice, USD(100), std::nullopt, std::nullopt, tfSingleAsset, ter(tecFROZEN)); + alice_, + USD_(100), + std::nullopt, + std::nullopt, + kTF_SINGLE_ASSET, + Ter(TecFrozen)); }); } @@ -6630,7 +6754,12 @@ private: Env env(*this, features); testAMMDeposit(env, [&](AMM& amm) { amm.deposit( - alice, XRP(100), std::nullopt, std::nullopt, tfSingleAsset, ter(tecFROZEN)); + alice_, + kXRP(100), + std::nullopt, + std::nullopt, + kTF_SINGLE_ASSET, + Ter(TecFrozen)); }); } else @@ -6641,7 +6770,12 @@ private: Env env(*this, features); testAMMDeposit(env, [&](AMM& amm) { amm.deposit( - alice, XRP(100), std::nullopt, std::nullopt, tfSingleAsset, ter(tesSUCCESS)); + alice_, + kXRP(100), + std::nullopt, + std::nullopt, + kTF_SINGLE_ASSET, + Ter(TesSuccess)); }); } } @@ -6652,39 +6786,39 @@ private: testcase("Fix Reserve Check On Withdrawal"); using namespace jtx; - auto const err = features[fixAMMv1_2] ? ter(tecINSUFFICIENT_RESERVE) : ter(tesSUCCESS); + auto const err = features[fixAMMv1_2] ? Ter(TecInsufficientReserve) : Ter(TesSuccess); auto test = [&](auto&& cb) { Env env(*this, features); - auto const starting_xrp = reserve(env, 2) + env.current()->fees().base * 5; - env.fund(starting_xrp, gw); - env.fund(starting_xrp, alice); - env.trust(USD(2'000), alice); + auto const startingXrp = reserve(env, 2) + env.current()->fees().base * 5; + env.fund(startingXrp, gw_); + env.fund(startingXrp, alice_); + env.trust(USD_(2'000), alice_); env.close(); - env(pay(gw, alice, USD(2'000))); + env(pay(gw_, alice_, USD_(2'000))); env.close(); - AMM amm(env, gw, EUR(1'000), USD(1'000)); - amm.deposit(alice, USD(1)); + AMM amm(env, gw_, EUR_(1'000), USD_(1'000)); + amm.deposit(alice_, USD_(1)); cb(amm); }; // Equal withdraw - test([&](AMM& amm) { amm.withdrawAll(alice, std::nullopt, err); }); + test([&](AMM& amm) { amm.withdrawAll(alice_, std::nullopt, err); }); // Equal withdraw with a limit test([&](AMM& amm) { amm.withdraw( WithdrawArg{ - .account = alice, .asset1Out = EUR(0.1), .asset2Out = USD(0.1), .err = err}); + .account = alice_, .asset1Out = EUR_(0.1), .asset2Out = USD_(0.1), .err = err}); amm.withdraw( WithdrawArg{ - .account = alice, .asset1Out = USD(0.1), .asset2Out = EUR(0.1), .err = err}); + .account = alice_, .asset1Out = USD_(0.1), .asset2Out = EUR_(0.1), .err = err}); }); // Single withdraw test([&](AMM& amm) { - amm.withdraw(WithdrawArg{.account = alice, .asset1Out = EUR(0.1), .err = err}); - amm.withdraw(WithdrawArg{.account = alice, .asset1Out = USD(0.1)}); + amm.withdraw(WithdrawArg{.account = alice_, .asset1Out = EUR_(0.1), .err = err}); + amm.withdraw(WithdrawArg{.account = alice_, .asset1Out = USD_(0.1)}); }); } @@ -6697,31 +6831,31 @@ private: testcase("Fail pseudo-account allocation " + suffix); std::string logs; Env env{*this, features, std::make_unique(&logs)}; - env.fund(XRP(30'000), gw, alice); + env.fund(kXRP(30'000), gw_, alice_); env.close(); - env(trust(alice, gw["USD"](30'000), 0)); - env(pay(gw, alice, USD(10'000))); + env(trust(alice_, gw_["USD"](30'000), 0)); + env(pay(gw_, alice_, USD_(10'000))); env.close(); - STAmount const amount = XRP(10'000); - STAmount const amount2 = USD(10'000); + STAmount const amount = kXRP(10'000); + STAmount const amount2 = USD_(10'000); auto const keylet = keylet::amm(amount.asset(), amount2.asset()); for (int i = 0; i < 256; ++i) { AccountID const accountId = xrpl::pseudoAccountAddress(*env.current(), keylet.key); - env(pay(env.master.id(), accountId, XRP(1000)), - seq(autofill), - fee(autofill), - sig(autofill)); + env(pay(env.master.id(), accountId, kXRP(1000)), + Seq(kAUTOFILL), + Fee(kAUTOFILL), + Sig(kAUTOFILL)); } AMM const ammAlice( env, - alice, + alice_, amount, amount2, - features[featureSingleAssetVault] ? ter{terADDRESS_COLLISION} : ter{tecDUPLICATE}); + features[featureSingleAssetVault] ? Ter{TerAddressCollision} : Ter{TecDuplicate}); }; testCase("tecDUPLICATE", testable_amendments() - featureSingleAssetVault); @@ -6734,39 +6868,39 @@ private: testcase("Deposit and Withdraw Rounding V2"); using namespace jtx; - auto const XPM = gw["XPM"]; + auto const xpm = gw_["XPM"]; STAmount xrpBalance{XRPAmount(692'614'492'126)}; - STAmount xpmBalance{XPM, UINT64_C(18'610'359'80246901), -8}; - STAmount amount{XPM, UINT64_C(6'566'496939465400), -12}; + STAmount xpmBalance{xpm, UINT64_C(18'610'359'80246901), -8}; + STAmount amount{xpm, UINT64_C(6'566'496939465400), -12}; std::uint16_t const tfee = 941; - auto test = [&](auto&& cb, std::uint16_t tfee_) { + auto test = [&](auto&& cb, std::uint16_t tfee) { Env env(*this, features); - env.fund(XRP(1'000'000), gw); - env.fund(XRP(1'000), alice); - env(trust(alice, XPM(7'000))); - env(pay(gw, alice, amount)); + env.fund(kXRP(1'000'000), gw_); + env.fund(kXRP(1'000), alice_); + env(trust(alice_, xpm(7'000))); + env(pay(gw_, alice_, amount)); - AMM amm(env, gw, xrpBalance, xpmBalance, CreateArg{.tfee = tfee_}); + AMM amm(env, gw_, xrpBalance, xpmBalance, CreateArg{.tfee = tfee}); // AMM LPToken balance required to replicate single deposit failure STAmount const lptAMMBalance{amm.lptIssue(), UINT64_C(3'234'987'266'485968), -6}; auto const burn = IOUAmount{amm.getLPTokensBalance() - lptAMMBalance}; // burn tokens to get to the required AMM state - env(amm.bid(BidArg{.account = gw, .bidMin = burn, .bidMax = burn})); + env(amm.bid(BidArg{.account = gw_, .bidMin = burn, .bidMax = burn})); cb(amm, env); }; test( [&](AMM& amm, Env& env) { - auto const err = env.enabled(fixAMMv1_3) ? ter(tesSUCCESS) : ter(tecUNFUNDED_AMM); - amm.deposit(DepositArg{.account = alice, .asset1In = amount, .err = err}); + auto const err = env.enabled(fixAMMv1_3) ? Ter(TesSuccess) : Ter(TecUnfundedAmm); + amm.deposit(DepositArg{.account = alice_, .asset1In = amount, .err = err}); }, tfee); test( [&](AMM& amm, Env& env) { - auto const [amount, amount2, lptAMM] = amm.balances(XRP, XPM); - auto const withdraw = STAmount{XPM, 1, -5}; - amm.withdraw(WithdrawArg{.asset1Out = STAmount{XPM, 1, -5}}); - auto const [amount_, amount2_, lptAMM_] = amm.balances(XRP, XPM); + auto const [amount, amount2, lptAMM] = amm.balances(kXRP, xpm); + auto const withdraw = STAmount{xpm, 1, -5}; + amm.withdraw(WithdrawArg{.asset1Out = STAmount{xpm, 1, -5}}); + auto const [amount_, amount2_, lptAMM_] = amm.balances(kXRP, xpm); if (!env.enabled(fixAMMv1_3)) { BEAST_EXPECT((amount2 - amount2_) > withdraw); @@ -6782,11 +6916,11 @@ private: void invariant(jtx::AMM& amm, jtx::Env& env, std::string const& msg, bool shouldFail) { - auto const [amount, amount2, lptBalance] = amm.balances(GBP, EUR); + auto const [amount, amount2, lptBalance] = amm.balances(GBP_, EUR_); - NumberMantissaScaleGuard const sg(MantissaRange::mantissa_scale::small); + NumberMantissaScaleGuard const sg(MantissaRange::MantissaScale::Small); NumberRoundModeGuard const g( - env.enabled(fixAMMv1_3) ? Number::rounding_mode::upward : Number::getround()); + env.enabled(fixAMMv1_3) ? Number::RoundingMode::Upward : Number::getround()); auto const res = root2(amount * amount2); if (shouldFail) @@ -6807,26 +6941,32 @@ private: // Single asset deposit for (auto const& deposit : - {STAmount(EUR, 1, 1), - STAmount(EUR, 1, 2), - STAmount(EUR, 1, 5), - STAmount(EUR, 1, -3), // fail - STAmount(EUR, 1, -6), - STAmount(EUR, 1, -9)}) + {STAmount(EUR_, 1, 1), + STAmount(EUR_, 1, 2), + STAmount(EUR_, 1, 5), + STAmount(EUR_, 1, -3), // fail + STAmount(EUR_, 1, -6), + STAmount(EUR_, 1, -9)}) { testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, + gw_, + {bob_}, + kXRP(10'000'000), + {GBP_(100'000), EUR_(100'000)}, + Fund::Acct); env.close(); - ammAlice.deposit(DepositArg{.account = bob, .asset1In = deposit}); + ammAlice.deposit(DepositArg{.account = bob_, .asset1In = deposit}); invariant( ammAlice, env, "dep1", - deposit == STAmount{EUR, 1, -3} && !env.enabled(fixAMMv1_3)); + deposit == STAmount{EUR_, 1, -3} && !env.enabled(fixAMMv1_3)); }, - {{GBP(30'000), EUR(30'000)}}, + {{GBP_(30'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6835,17 +6975,18 @@ private: // Two-asset proportional deposit (1:1 pool ratio) testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, gw_, {bob_}, kXRP(10'000'000), {GBP_(100'000), EUR_(100'000)}, Fund::Acct); env.close(); - STAmount const depositEuro{EUR, UINT64_C(10'1234567890123456), -16}; - STAmount const depositGBP{GBP, UINT64_C(10'1234567890123456), -16}; + STAmount const depositEuro{EUR_, UINT64_C(10'1234567890123456), -16}; + STAmount const depositGBP{GBP_, UINT64_C(10'1234567890123456), -16}; ammAlice.deposit( - DepositArg{.account = bob, .asset1In = depositEuro, .asset2In = depositGBP}); + DepositArg{.account = bob_, .asset1In = depositEuro, .asset2In = depositGBP}); invariant(ammAlice, env, "dep2", false); }, - {{GBP(30'000), EUR(30'000)}}, + {{GBP_(30'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6855,18 +6996,24 @@ private: { testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, + gw_, + {bob_}, + kXRP(10'000'000), + {GBP_(100'000), EUR_(100'000)}, + Fund::Acct); env.close(); - STAmount const depositEuro{EUR, 1, exponent}; - STAmount const depositGBP{GBP, 1, exponent}; + STAmount const depositEuro{EUR_, 1, exponent}; + STAmount const depositGBP{GBP_, 1, exponent}; ammAlice.deposit( DepositArg{ - .account = bob, .asset1In = depositEuro, .asset2In = depositGBP}); + .account = bob_, .asset1In = depositEuro, .asset2In = depositGBP}); invariant(ammAlice, env, "dep3", exponent != -3 && !env.enabled(fixAMMv1_3)); }, - {{GBP(10'000), EUR(30'000)}}, + {{GBP_(10'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6875,14 +7022,15 @@ private: // tfLPToken deposit testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, gw_, {bob_}, kXRP(10'000'000), {GBP_(100'000), EUR_(100'000)}, Fund::Acct); env.close(); ammAlice.deposit( - DepositArg{.account = bob, .tokens = IOUAmount{10'1234567890123456, -16}}); + DepositArg{.account = bob_, .tokens = IOUAmount{10'1234567890123456, -16}}); invariant(ammAlice, env, "dep4", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6902,19 +7050,19 @@ private: [&](AMM& ammAlice, Env& env) { fund( env, - gw, - {bob}, - XRP(10'000'000), - {GBP(100'000), EUR(1'000'000)}, + gw_, + {bob_}, + kXRP(10'000'000), + {GBP_(100'000), EUR_(1'000'000)}, Fund::Acct); env.close(); ammAlice.deposit( DepositArg{ - .account = bob, .tokens = tokens, .asset1In = STAmount{EUR, 1, 6}}); + .account = bob_, .tokens = tokens, .asset1In = STAmount{EUR_, 1, 6}}); invariant(ammAlice, env, "dep5", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6924,13 +7072,14 @@ private: // 1'000 GBP with EP not to exceed 5 (GBP/TokensOut) testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, gw_, {bob_}, kXRP(10'000'000), {GBP_(100'000), EUR_(100'000)}, Fund::Acct); env.close(); - ammAlice.deposit(bob, GBP(1'000), std::nullopt, STAmount{GBP, 5}); + ammAlice.deposit(bob_, GBP_(1'000), std::nullopt, STAmount{GBP_, 5}); invariant(ammAlice, env, "dep6", false); }, - {{GBP(30'000), EUR(30'000)}}, + {{GBP_(30'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6946,10 +7095,10 @@ private: // tfLPToken mode testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw(alice, 1'000); + ammAlice.withdraw(alice_, 1'000); invariant(ammAlice, env, "with1", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6957,10 +7106,10 @@ private: // tfWithdrawAll mode testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw(WithdrawArg{.account = alice, .flags = tfWithdrawAll}); + ammAlice.withdraw(WithdrawArg{.account = alice_, .flags = kTF_WITHDRAW_ALL}); invariant(ammAlice, env, "with2", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6970,13 +7119,13 @@ private: [&](AMM& ammAlice, Env& env) { ammAlice.withdraw( WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 3'500}, - .asset2Out = STAmount{EUR, 15'000}, - .flags = tfTwoAsset}); + .account = alice_, + .asset1Out = STAmount{GBP_, 3'500}, + .asset2Out = STAmount{EUR_, 15'000}, + .flags = kTF_TWO_ASSET}); invariant(ammAlice, env, "with3", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -6990,12 +7139,12 @@ private: [&](AMM& ammAlice, Env& env) { ammAlice.withdraw( WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 1'234}, - .flags = tfSingleAsset}); + .account = alice_, + .asset1Out = STAmount{GBP_, 1'234}, + .flags = kTF_SINGLE_ASSET}); invariant(ammAlice, env, "with4", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -7003,19 +7152,20 @@ private: // tfOneAssetWithdrawAll mode testAMM( [&](AMM& ammAlice, Env& env) { - fund(env, gw, {bob}, XRP(10'000'000), {GBP(100'000), EUR(100'000)}, Fund::Acct); + fund( + env, gw_, {bob_}, kXRP(10'000'000), {GBP_(100'000), EUR_(100'000)}, Fund::Acct); env.close(); - ammAlice.deposit(DepositArg{.account = bob, .asset1In = STAmount{GBP, 3'456}}); + ammAlice.deposit(DepositArg{.account = bob_, .asset1In = STAmount{GBP_, 3'456}}); ammAlice.withdraw( WithdrawArg{ - .account = bob, - .asset1Out = STAmount{GBP, 1'000}, - .flags = tfOneAssetWithdrawAll}); + .account = bob_, + .asset1Out = STAmount{GBP_, 1'000}, + .flags = kTF_ONE_ASSET_WITHDRAW_ALL}); invariant(ammAlice, env, "with5", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -7025,13 +7175,13 @@ private: [&](AMM& ammAlice, Env& env) { ammAlice.withdraw( WithdrawArg{ - .account = alice, + .account = alice_, .tokens = 1'000, - .asset1Out = STAmount{GBP, 100}, - .flags = tfOneAssetLPToken}); + .asset1Out = STAmount{GBP_, 100}, + .flags = kTF_ONE_ASSET_LP_TOKEN}); invariant(ammAlice, env, "with6", false); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); @@ -7041,13 +7191,13 @@ private: [&](AMM& ammAlice, Env& env) { ammAlice.withdraw( WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 100}, + .account = alice_, + .asset1Out = STAmount{GBP_, 100}, .maxEP = IOUAmount{2}, - .flags = tfLimitLPToken}); + .flags = kTF_LIMIT_LP_TOKEN}); invariant(ammAlice, env, "with7", true); }, - {{GBP(7'000), EUR(30'000)}}, + {{GBP_(7'000), EUR_(30'000)}}, 0, std::nullopt, {all}); diff --git a/src/test/app/NFToken_test.cpp b/src/test/app/NFToken_test.cpp index 259e0c8ed7..eb27290939 100644 --- a/src/test/app/NFToken_test.cpp +++ b/src/test/app/NFToken_test.cpp @@ -54,7 +54,7 @@ namespace xrpl { -class NFTokenBaseUtil_test : public beast::unit_test::suite +class NFTokenBaseUtil_test : public beast::unit_test::Suite { // Helper function that returns the number of NFTs minted by an issuer. static std::uint32_t @@ -82,9 +82,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { Json::Value params; params[jss::account] = acct.human(); - params[jss::type] = "state"; + params[jss::kTYPE] = "state"; Json::Value nfts = env.rpc("json", "account_nfts", to_string(params)); - return nfts[jss::result][jss::account_nfts].size(); + return nfts[jss::kRESULT][jss::kACCOUNT_NFTS].size(); }; // Helper function that returns the number of tickets held by an account. @@ -133,18 +133,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(mintedCount(env, master) == 1); BEAST_EXPECT(burnedCount(env, master) == 1); - uint256 const nftId1{token::getNextID(env, env.master, 0u, tfTransferable)}; - env(token::mint(env.master, 0u), txflags(tfTransferable)); + uint256 const nftId1{token::getNextID(env, env.master, 0u, kTF_TRANSFERABLE)}; + env(token::mint(env.master, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, master) == 1); BEAST_EXPECT(mintedCount(env, master) == 2); BEAST_EXPECT(burnedCount(env, master) == 1); Account const alice{"alice"}; - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); uint256 const aliceOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId1, XRP(1000)), token::owner(master)); + env(token::createOffer(alice, nftId1, kXRP(1000)), token::Owner(master)); env.close(); BEAST_EXPECT(ownerCount(env, master) == 1); @@ -196,7 +196,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice does not have enough XRP to cover the reserve for an NFT // page. - env(token::mint(alice, 0u), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(alice, 0u), Ter(TecInsufficientReserve)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); @@ -233,7 +233,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice still does not have enough XRP for the reserve of an NFT // page. - env(token::mint(alice, 0u), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(alice, 0u), Ter(TecInsufficientReserve)); env.close(); checkAliceOwnerMintedBurned(0, 0, 0, __LINE__); @@ -258,7 +258,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // That NFT page is full. Creating an additional NFT page requires // additional reserve. - env(token::mint(alice), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(alice), Ter(TecInsufficientReserve)); env.close(); checkAliceOwnerMintedBurned(1, 32, 0, __LINE__); @@ -268,7 +268,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice still does not have enough XRP for the reserve of an NFT // page. - env(token::mint(alice), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(alice), Ter(TecInsufficientReserve)); env.close(); checkAliceOwnerMintedBurned(1, 32, 0, __LINE__); @@ -292,7 +292,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // alice burns a non-existent NFT. - env(token::burn(alice, token::getID(env, alice, 197, 5)), ter(tecNO_ENTRY)); + env(token::burn(alice, token::getID(env, alice, 197, 5)), Ter(TecNoEntry)); env.close(); checkAliceOwnerMintedBurned(0, 33, 33, __LINE__); @@ -346,9 +346,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // page. Just for grins (and code coverage), minter mints NFTs that // include a URI. env(token::mint(minter), - token::issuer(alice), - token::uri("uri"), - ter(tecINSUFFICIENT_RESERVE)); + token::Issuer(alice), + token::Uri("uri"), + Ter(TecInsufficientReserve)); env.close(); checkMintersOwnerMintedBurned(0, 33, nftSeq, 0, 0, 0, __LINE__); @@ -357,7 +357,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // Now minter can mint an NFT for alice. - env(token::mint(minter), token::issuer(alice), token::uri("uri")); + env(token::mint(minter), token::Issuer(alice), token::Uri("uri")); env.close(); checkMintersOwnerMintedBurned(0, 34, nftSeq, 1, 0, 0, __LINE__); @@ -365,7 +365,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // without any additional reserve requirements. for (int i = 1; i < 32; ++i) { - env(token::mint(minter), token::issuer(alice), token::uri("uri")); + env(token::mint(minter), token::Issuer(alice), token::Uri("uri")); checkMintersOwnerMintedBurned(0, i + 34, nftSeq, 1, 0, 0, __LINE__); } @@ -377,9 +377,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // That NFT page is full. Creating an additional NFT page requires // additional reserve. env(token::mint(minter), - token::issuer(alice), - token::uri("uri"), - ter(tecINSUFFICIENT_RESERVE)); + token::Issuer(alice), + token::Uri("uri"), + Ter(TecInsufficientReserve)); env.close(); checkMintersOwnerMintedBurned(0, 65, nftSeq, 1, 0, 0, __LINE__); @@ -388,7 +388,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // Now minter can mint an NFT. - env(token::mint(minter), token::issuer(alice), token::uri("uri")); + env(token::mint(minter), token::Issuer(alice), token::Uri("uri")); env.close(); checkMintersOwnerMintedBurned(0, 66, nftSeq, 2, 0, 0, __LINE__); @@ -408,7 +408,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkMintersOwnerMintedBurned(0, 66, nftSeq, 0, 0, 0, __LINE__); // minter burns a non-existent NFT. - env(token::burn(minter, token::getID(env, alice, 2009, 3)), ter(tecNO_ENTRY)); + env(token::burn(minter, token::getID(env, alice, 2009, 3)), Ter(TecNoEntry)); env.close(); checkMintersOwnerMintedBurned(0, 66, nftSeq, 0, 0, 0, __LINE__); } @@ -424,7 +424,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice{"alice"}; Env env{*this, features}; - env.fund(XRP(1000), alice); + env.fund(kXRP(1000), alice); env.close(); // We're going to hack the ledger in order to avoid generating @@ -468,8 +468,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite }); // See whether alice is at the boundary that causes an error. - env(token::mint(alice, 0u), ter(tesSUCCESS)); - env(token::mint(alice, 0u), ter(tecMAX_SEQUENCE_REACHED)); + env(token::mint(alice, 0u), Ter(TesSuccess)); + env(token::mint(alice, 0u), Ter(TecMaxSequenceReached)); } void @@ -487,57 +487,57 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Fund alice and minter enough to exist, but not enough to meet // the reserve for creating their first NFT. Account reserve for unit // tests is 200 XRP, not 20. - env.fund(XRP(200), alice, minter); + env.fund(kXRP(200), alice, minter); env.close(); - env(token::mint(alice, 0u), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(alice, 0u), Ter(TecInsufficientReserve)); env.close(); // Fund alice enough to start minting NFTs. - env(pay(env.master, alice, XRP(1000))); + env(pay(env.master, alice, kXRP(1000))); env.close(); //---------------------------------------------------------------------- // preflight // Set a negative fee. - env(token::mint(alice, 0u), fee(STAmount(10ull, true)), ter(temBAD_FEE)); + env(token::mint(alice, 0u), Fee(STAmount(10ull, true)), Ter(TemBadFee)); // Set an invalid flag. - env(token::mint(alice, 0u), txflags(0x00008000), ter(temINVALID_FLAG)); + env(token::mint(alice, 0u), Txflags(0x00008000), Ter(TemInvalidFlag)); // Can't set a transfer fee if the NFT does not have the tfTRANSFERABLE // flag set. - env(token::mint(alice, 0u), token::xferFee(maxTransferFee), ter(temMALFORMED)); + env(token::mint(alice, 0u), token::XferFee(kMAX_TRANSFER_FEE), Ter(TemMalformed)); // Set a bad transfer fee. env(token::mint(alice, 0u), - token::xferFee(maxTransferFee + 1), - txflags(tfTransferable), - ter(temBAD_NFTOKEN_TRANSFER_FEE)); + token::XferFee(kMAX_TRANSFER_FEE + 1), + Txflags(kTF_TRANSFERABLE), + Ter(TemBadNftokenTransferFee)); // Account can't also be issuer. - env(token::mint(alice, 0u), token::issuer(alice), ter(temMALFORMED)); + env(token::mint(alice, 0u), token::Issuer(alice), Ter(TemMalformed)); // Invalid URI: zero length. - env(token::mint(alice, 0u), token::uri(""), ter(temMALFORMED)); + env(token::mint(alice, 0u), token::Uri(""), Ter(TemMalformed)); // Invalid URI: too long. env(token::mint(alice, 0u), - token::uri(std::string(maxTokenURILength + 1, 'q')), - ter(temMALFORMED)); + token::Uri(std::string(kMAX_TOKEN_URI_LENGTH + 1, 'q')), + Ter(TemMalformed)); //---------------------------------------------------------------------- // preclaim // Non-existent issuer. - env(token::mint(alice, 0u), token::issuer(Account("demon")), ter(tecNO_ISSUER)); + env(token::mint(alice, 0u), token::Issuer(Account("demon")), Ter(TecNoIssuer)); //---------------------------------------------------------------------- // doApply // Existent issuer, but not given minting permission - env(token::mint(minter, 0u), token::issuer(alice), ter(tecNO_PERMISSION)); + env(token::mint(minter, 0u), token::Issuer(alice), Ter(TecNoPermission)); } void @@ -558,12 +558,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Fund alice and minter enough to exist and create an NFT, but not // enough to meet the reserve for creating their first NFTOffer. // Account reserve for unit tests is 200 XRP, not 20. - env.fund(XRP(250), alice, buyer, minter, gw); + env.fund(kXRP(250), alice, buyer, minter, gw); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); - uint256 const nftAlice0ID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftAlice0ID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); @@ -571,12 +571,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // preflight // Set a negative fee. - env(token::burn(alice, nftAlice0ID), fee(STAmount(10ull, true)), ter(temBAD_FEE)); + env(token::burn(alice, nftAlice0ID), Fee(STAmount(10ull, true)), Ter(TemBadFee)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // Set an invalid flag. - env(token::burn(alice, nftAlice0ID), txflags(0x00008000), ter(temINVALID_FLAG)); + env(token::burn(alice, nftAlice0ID), Txflags(0x00008000), Ter(TemInvalidFlag)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); @@ -584,7 +584,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // preclaim // Try to burn a token that doesn't exist. - env(token::burn(alice, token::getID(env, alice, 0, 1)), ter(tecNO_ENTRY)); + env(token::burn(alice, token::getID(env, alice, 0, 1)), Ter(TecNoEntry)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); @@ -611,17 +611,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Fund alice enough to exist and create an NFT, but not // enough to meet the reserve for creating their first NFTOffer. // Account reserve for unit tests is 200 XRP, not 20. - env.fund(XRP(250), alice, buyer, gw); + env.fund(kXRP(250), alice, buyer, gw); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); - uint256 const nftAlice0ID = token::getNextID(env, alice, 0, tfTransferable, 10); - env(token::mint(alice, 0u), txflags(tfTransferable), token::xferFee(10)); + uint256 const nftAlice0ID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE, 10); + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE), token::XferFee(10)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); - uint256 const nftXrpOnlyID = token::getNextID(env, alice, 0, tfOnlyXRP | tfTransferable); - env(token::mint(alice, 0), txflags(tfOnlyXRP | tfTransferable)); + uint256 const nftXrpOnlyID = + token::getNextID(env, alice, 0, kTF_ONLY_XRP | kTF_TRANSFERABLE); + env(token::mint(alice, 0), Txflags(kTF_ONLY_XRP | kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); @@ -639,74 +640,74 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // buyer tries to create an NFTokenOffer, but doesn't have the reserve. - env(token::createOffer(buyer, nftAlice0ID, XRP(1000)), - token::owner(alice), - ter(tecINSUFFICIENT_RESERVE)); + env(token::createOffer(buyer, nftAlice0ID, kXRP(1000)), + token::Owner(alice), + Ter(TecInsufficientReserve)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // Set a negative fee. - env(token::createOffer(buyer, nftAlice0ID, XRP(1000)), - fee(STAmount(10ull, true)), - ter(temBAD_FEE)); + env(token::createOffer(buyer, nftAlice0ID, kXRP(1000)), + Fee(STAmount(10ull, true)), + Ter(TemBadFee)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // Set an invalid flag. - env(token::createOffer(buyer, nftAlice0ID, XRP(1000)), - txflags(0x00008000), - ter(temINVALID_FLAG)); + env(token::createOffer(buyer, nftAlice0ID, kXRP(1000)), + Txflags(0x00008000), + Ter(TemInvalidFlag)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // Set an invalid amount. - env(token::createOffer(buyer, nftXrpOnlyID, buyer["USD"](1)), ter(temBAD_AMOUNT)); - env(token::createOffer(buyer, nftAlice0ID, buyer["USD"](0)), ter(temBAD_AMOUNT)); - env(token::createOffer(buyer, nftXrpOnlyID, drops(0)), ter(temBAD_AMOUNT)); + env(token::createOffer(buyer, nftXrpOnlyID, buyer["USD"](1)), Ter(TemBadAmount)); + env(token::createOffer(buyer, nftAlice0ID, buyer["USD"](0)), Ter(TemBadAmount)); + env(token::createOffer(buyer, nftXrpOnlyID, drops(0)), Ter(TemBadAmount)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // Set a bad expiration. env(token::createOffer(buyer, nftAlice0ID, buyer["USD"](1)), - token::expiration(0), - ter(temBAD_EXPIRATION)); + token::Expiration(0), + Ter(TemBadExpiration)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // Invalid Owner field and tfSellToken flag relationships. // A buy offer must specify the owner. - env(token::createOffer(buyer, nftXrpOnlyID, XRP(1000)), ter(temMALFORMED)); + env(token::createOffer(buyer, nftXrpOnlyID, kXRP(1000)), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // A sell offer must not specify the owner; the owner is implicit. - env(token::createOffer(alice, nftXrpOnlyID, XRP(1000)), - token::owner(alice), - txflags(tfSellNFToken), - ter(temMALFORMED)); + env(token::createOffer(alice, nftXrpOnlyID, kXRP(1000)), + token::Owner(alice), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // An owner may not offer to buy their own token. - env(token::createOffer(alice, nftXrpOnlyID, XRP(1000)), - token::owner(alice), - ter(temMALFORMED)); + env(token::createOffer(alice, nftXrpOnlyID, kXRP(1000)), + token::Owner(alice), + Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // The destination may not be the account submitting the transaction. - env(token::createOffer(alice, nftXrpOnlyID, XRP(1000)), - token::destination(alice), - txflags(tfSellNFToken), - ter(temMALFORMED)); + env(token::createOffer(alice, nftXrpOnlyID, kXRP(1000)), + token::Destination(alice), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // The destination must be an account already established in the ledger. - env(token::createOffer(alice, nftXrpOnlyID, XRP(1000)), - token::destination(Account("demon")), - txflags(tfSellNFToken), - ter(tecNO_DST)); + env(token::createOffer(alice, nftXrpOnlyID, kXRP(1000)), + token::Destination(Account("demon")), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoDst)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); @@ -714,31 +715,31 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // preclaim // The new NFTokenOffer may not have passed its expiration time. - env(token::createOffer(buyer, nftXrpOnlyID, XRP(1000)), - token::owner(alice), - token::expiration(lastClose(env)), - ter(tecEXPIRED)); + env(token::createOffer(buyer, nftXrpOnlyID, kXRP(1000)), + token::Owner(alice), + token::Expiration(lastClose(env)), + Ter(TecExpired)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // The nftID must be present in the ledger. - env(token::createOffer(buyer, token::getID(env, alice, 0, 1), XRP(1000)), - token::owner(alice), - ter(tecNO_ENTRY)); + env(token::createOffer(buyer, token::getID(env, alice, 0, 1), kXRP(1000)), + token::Owner(alice), + Ter(TecNoEntry)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // The nftID must be present in the ledger of a sell offer too. - env(token::createOffer(alice, token::getID(env, alice, 0, 1), XRP(1000)), - txflags(tfSellNFToken), - ter(tecNO_ENTRY)); + env(token::createOffer(alice, token::getID(env, alice, 0, 1), kXRP(1000)), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoEntry)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); // buyer must have the funds to pay for their offer. env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecNO_LINE)); + token::Owner(alice), + Ter(TecNoLine)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); @@ -749,53 +750,53 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Issuer (alice) must have a trust line for the offered funds. env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecNO_LINE)); + token::Owner(alice), + Ter(TecNoLine)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Give alice the needed trust line, but freeze it. - env(trust(gw, alice["AUD"](999), tfSetFreeze)); + env(trust(gw, alice["AUD"](999), kTF_SET_FREEZE)); env.close(); // Issuer (alice) must have a trust line for the offered funds and // the trust line may not be frozen. env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecFROZEN)); + token::Owner(alice), + Ter(TecFrozen)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Unfreeze alice's trustline. - env(trust(gw, alice["AUD"](999), tfClearFreeze)); + env(trust(gw, alice["AUD"](999), kTF_CLEAR_FREEZE)); env.close(); // Can't transfer the NFT if the transferable flag is not set. env(token::createOffer(buyer, nftNoXferID, gwAUD(1000)), - token::owner(alice), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + token::Owner(alice), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Give buyer the needed trust line, but freeze it. - env(trust(gw, buyer["AUD"](999), tfSetFreeze)); + env(trust(gw, buyer["AUD"](999), kTF_SET_FREEZE)); env.close(); env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecFROZEN)); + token::Owner(alice), + Ter(TecFrozen)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Unfreeze buyer's trust line, but buyer has no actual gwAUD. // to cover the offer. - env(trust(gw, buyer["AUD"](999), tfClearFreeze)); + env(trust(gw, buyer["AUD"](999), kTF_CLEAR_FREEZE)); env(trust(buyer, gwAUD(1000))); env.close(); env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecUNFUNDED_OFFER)); + token::Owner(alice), + Ter(TecUnfundedOffer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // the trust line. @@ -809,19 +810,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // However buyer doesn't have enough XRP to cover the reserve for // an NFT offer. env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecINSUFFICIENT_RESERVE)); + token::Owner(alice), + Ter(TecInsufficientReserve)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Give buyer almost enough XRP to cover the reserve. auto const baseFee = env.current()->fees().base; - env(pay(env.master, buyer, XRP(50) + drops(baseFee * 12 - 1))); + env(pay(env.master, buyer, kXRP(50) + drops(baseFee * 12 - 1))); env.close(); env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tecINSUFFICIENT_RESERVE)); + token::Owner(alice), + Ter(TecInsufficientReserve)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); @@ -832,8 +833,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // We don't care whether the offer is fully funded until the offer is // accepted. Success at last! env(token::createOffer(buyer, nftAlice0ID, gwAUD(1000)), - token::owner(alice), - ter(tesSUCCESS)); + token::Owner(alice), + Ter(TesSuccess)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 2); } @@ -851,18 +852,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const gw("gw"); IOU const gwAUD(gw["AUD"]); - env.fund(XRP(1000), alice, buyer, gw); + env.fund(kXRP(1000), alice, buyer, gw); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); - uint256 const nftAlice0ID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftAlice0ID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // This is the offer we'll try to cancel. uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftAlice0ID, XRP(1)), token::owner(alice), ter(tesSUCCESS)); + env(token::createOffer(buyer, nftAlice0ID, kXRP(1)), token::Owner(alice), Ter(TesSuccess)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); @@ -871,43 +872,41 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Set a negative fee. env(token::cancelOffer(buyer, {buyerOfferIndex}), - fee(STAmount(10ull, true)), - ter(temBAD_FEE)); + Fee(STAmount(10ull, true)), + Ter(TemBadFee)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Set an invalid flag. - env(token::cancelOffer(buyer, {buyerOfferIndex}), - txflags(0x00008000), - ter(temINVALID_FLAG)); + env(token::cancelOffer(buyer, {buyerOfferIndex}), Txflags(0x00008000), Ter(TemInvalidFlag)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Empty list of tokens to delete. { Json::Value jv = token::cancelOffer(buyer); - jv[sfNFTokenOffers.jsonName] = Json::arrayValue; - env(jv, ter(temMALFORMED)); + jv[sfNFTokenOffers.jsonName] = Json::ArrayValue; + env(jv, Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); } // List of tokens to delete is too long. { - std::vector const offers(maxTokenOfferCancelCount + 1, buyerOfferIndex); + std::vector const offers(kMAX_TOKEN_OFFER_CANCEL_COUNT + 1, buyerOfferIndex); - env(token::cancelOffer(buyer, offers), ter(temMALFORMED)); + env(token::cancelOffer(buyer, offers), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); } // Duplicate entries are not allowed in the list of offers to cancel. - env(token::cancelOffer(buyer, {buyerOfferIndex, buyerOfferIndex}), ter(temMALFORMED)); + env(token::cancelOffer(buyer, {buyerOfferIndex, buyerOfferIndex}), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // Provide neither offers to cancel nor a root index. - env(token::cancelOffer(buyer), ter(temMALFORMED)); + env(token::cancelOffer(buyer), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); @@ -915,21 +914,21 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // preclaim // Make a non-root directory that we can pass as a root index. - env(pay(env.master, gw, XRP(5000))); + env(pay(env.master, gw, kXRP(5000))); env.close(); for (std::uint32_t i = 1; i < 34; ++i) { - env(offer(gw, XRP(i), gwAUD(1))); + env(offer(gw, kXRP(i), gwAUD(1))); env.close(); } { // gw attempts to cancel a Check as through it is an NFTokenOffer. auto const gwCheckId = keylet::check(gw, env.seq(gw)).key; - env(check::create(gw, env.master, XRP(300))); + env(check::create(gw, env.master, kXRP(300))); env.close(); - env(token::cancelOffer(gw, {gwCheckId}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(gw, {gwCheckId}), Ter(TecNoPermission)); env.close(); // Cancel the check so it doesn't mess up later tests. @@ -938,7 +937,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // gw attempts to cancel an offer they don't have permission to cancel. - env(token::cancelOffer(gw, {buyerOfferIndex}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(gw, {buyerOfferIndex}), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); @@ -965,19 +964,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const gw("gw"); IOU const gwAUD(gw["AUD"]); - env.fund(XRP(1000), alice, buyer, gw); + env.fund(kXRP(1000), alice, buyer, gw); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); BEAST_EXPECT(ownerCount(env, buyer) == 0); - uint256 const nftAlice0ID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftAlice0ID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); uint8_t aliceCount = 1; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); - uint256 const nftXrpOnlyID = token::getNextID(env, alice, 0, tfOnlyXRP | tfTransferable); - env(token::mint(alice, 0), txflags(tfOnlyXRP | tfTransferable)); + uint256 const nftXrpOnlyID = + token::getNextID(env, alice, 0, kTF_ONLY_XRP | kTF_TRANSFERABLE); + env(token::mint(alice, 0), Txflags(kTF_ONLY_XRP | kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == aliceCount); @@ -988,43 +988,43 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice creates sell offers for her nfts. uint256 const plainOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAlice0ID, XRP(10)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftAlice0ID, kXRP(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); aliceCount++; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); uint256 const audOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAlice0ID, gwAUD(30)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftAlice0ID, gwAUD(30)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); aliceCount++; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); uint256 const xrpOnlyOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftXrpOnlyID, XRP(20)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftXrpOnlyID, kXRP(20)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); aliceCount++; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); uint256 const noXferOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftNoXferID, XRP(30)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftNoXferID, kXRP(30)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); aliceCount++; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); // alice creates a sell offer that will expire soon. uint256 const aliceExpOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftNoXferID, XRP(40)), - txflags(tfSellNFToken), - token::expiration(lastClose(env) + 5)); + env(token::createOffer(alice, nftNoXferID, kXRP(40)), + Txflags(kTF_SELL_NF_TOKEN), + token::Expiration(lastClose(env) + 5)); env.close(); aliceCount++; BEAST_EXPECT(ownerCount(env, alice) == aliceCount); // buyer creates a Buy offer that will expire soon. uint256 const buyerExpOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftAlice0ID, XRP(40)), - token::owner(alice), - token::expiration(lastClose(env) + 5)); + env(token::createOffer(buyer, nftAlice0ID, kXRP(40)), + token::Owner(alice), + token::Expiration(lastClose(env) + 5)); env.close(); uint8_t buyerCount = 1; BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1034,15 +1034,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Set a negative fee. env(token::acceptSellOffer(buyer, noXferOfferIndex), - fee(STAmount(10ull, true)), - ter(temBAD_FEE)); + Fee(STAmount(10ull, true)), + Ter(TemBadFee)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // Set an invalid flag. env(token::acceptSellOffer(buyer, noXferOfferIndex), - txflags(0x00008000), - ter(temINVALID_FLAG)); + Txflags(0x00008000), + Ter(TemInvalidFlag)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1050,7 +1050,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { Json::Value jv = token::acceptSellOffer(buyer, noXferOfferIndex); jv.removeMember(sfNFTokenSellOffer.jsonName); - env(jv, ter(temMALFORMED)); + env(jv, Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); } @@ -1058,8 +1058,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // A buy offer may not contain a sfNFTokenBrokerFee field. { Json::Value jv = token::acceptBuyOffer(buyer, noXferOfferIndex); - jv[sfNFTokenBrokerFee.jsonName] = STAmount(500000).getJson(JsonOptions::none); - env(jv, ter(temMALFORMED)); + jv[sfNFTokenBrokerFee.jsonName] = STAmount(500000).getJson(JsonOptions::None); + env(jv, Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); } @@ -1067,16 +1067,16 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // A sell offer may not contain a sfNFTokenBrokerFee field. { Json::Value jv = token::acceptSellOffer(buyer, noXferOfferIndex); - jv[sfNFTokenBrokerFee.jsonName] = STAmount(500000).getJson(JsonOptions::none); - env(jv, ter(temMALFORMED)); + jv[sfNFTokenBrokerFee.jsonName] = STAmount(500000).getJson(JsonOptions::None); + env(jv, Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); } // A brokered offer may not contain a negative or zero brokerFee. env(token::brokerOffers(buyer, noXferOfferIndex, xrpOnlyOfferIndex), - token::brokerFee(gwAUD(0)), - ter(temMALFORMED)); + token::BrokerFee(gwAUD(0)), + Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1084,20 +1084,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // preclaim // The buy offer must be non-zero. - env(token::acceptBuyOffer(buyer, beast::zero), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptBuyOffer(buyer, beast::kZERO), Ter(TecObjectNotFound)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The buy offer must be present in the ledger. uint256 const missingOfferIndex = keylet::nftoffer(alice, 1).key; - env(token::acceptBuyOffer(buyer, missingOfferIndex), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptBuyOffer(buyer, missingOfferIndex), Ter(TecObjectNotFound)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The buy offer must not have expired. // NOTE: this is only a preclaim check with the // fixSecurity3_1_3 amendment disabled. - env(token::acceptBuyOffer(alice, buyerExpOfferIndex), ter(tecEXPIRED)); + env(token::acceptBuyOffer(alice, buyerExpOfferIndex), Ter(TecExpired)); env.close(); if (features[fixSecurity3_1_3]) { @@ -1106,19 +1106,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The sell offer must be non-zero. - env(token::acceptSellOffer(buyer, beast::zero), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptSellOffer(buyer, beast::kZERO), Ter(TecObjectNotFound)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The sell offer must be present in the ledger. - env(token::acceptSellOffer(buyer, missingOfferIndex), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptSellOffer(buyer, missingOfferIndex), Ter(TecObjectNotFound)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The sell offer must not have expired. // NOTE: this is only a preclaim check with the // fixSecurity3_1_3 amendment disabled. - env(token::acceptSellOffer(buyer, aliceExpOfferIndex), ter(tecEXPIRED)); + env(token::acceptSellOffer(buyer, aliceExpOfferIndex), Ter(TecExpired)); env.close(); // Alice's count is decremented by one when the expired offer is // removed. @@ -1152,27 +1152,27 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // buyer creates a buy offer for one of alice's nfts. uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftAlice0ID, gwAUD(29)), token::owner(alice)); + env(token::createOffer(buyer, nftAlice0ID, gwAUD(29)), token::Owner(alice)); env.close(); buyerCount++; BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // gw attempts to broker offers that are not for the same token. env(token::brokerOffers(gw, buyerOfferIndex, xrpOnlyOfferIndex), - ter(tecNFTOKEN_BUY_SELL_MISMATCH)); + Ter(TecNftokenBuySellMismatch)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // gw attempts to broker offers that are not for the same currency. env(token::brokerOffers(gw, buyerOfferIndex, plainOfferIndex), - ter(tecNFTOKEN_BUY_SELL_MISMATCH)); + Ter(TecNftokenBuySellMismatch)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // In a brokered offer, the buyer must offer greater than or // equal to the selling price. env(token::brokerOffers(gw, buyerOfferIndex, audOfferIndex), - ter(tecINSUFFICIENT_PAYMENT)); + Ter(TecInsufficientPayment)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1185,7 +1185,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // buyer creates a buy offer for one of alice's nfts. uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftAlice0ID, gwAUD(31)), token::owner(alice)); + env(token::createOffer(buyer, nftAlice0ID, gwAUD(31)), token::Owner(alice)); env.close(); buyerCount++; BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1193,23 +1193,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Broker sets their fee in a denomination other than the one // used by the offers env(token::brokerOffers(gw, buyerOfferIndex, audOfferIndex), - token::brokerFee(XRP(40)), - ter(tecNFTOKEN_BUY_SELL_MISMATCH)); + token::BrokerFee(kXRP(40)), + Ter(TecNftokenBuySellMismatch)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // Broker fee way too big. env(token::brokerOffers(gw, buyerOfferIndex, audOfferIndex), - token::brokerFee(gwAUD(31)), - ter(tecINSUFFICIENT_PAYMENT)); + token::BrokerFee(gwAUD(31)), + Ter(TecInsufficientPayment)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // Broker fee is smaller, but still too big once the offer // seller's minimum is taken into account. env(token::brokerOffers(gw, buyerOfferIndex, audOfferIndex), - token::brokerFee(gwAUD(1.5)), - ter(tecINSUFFICIENT_PAYMENT)); + token::BrokerFee(gwAUD(1.5)), + Ter(TecInsufficientPayment)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1224,19 +1224,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // buyer creates a buy offer for one of alice's nfts. uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftAlice0ID, gwAUD(30)), token::owner(alice)); + env(token::createOffer(buyer, nftAlice0ID, gwAUD(30)), token::Owner(alice)); env.close(); buyerCount++; BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // Don't accept a buy offer if the sell flag is set. - env(token::acceptBuyOffer(buyer, plainOfferIndex), ter(tecNFTOKEN_OFFER_TYPE_MISMATCH)); + env(token::acceptBuyOffer(buyer, plainOfferIndex), Ter(TecNftokenOfferTypeMismatch)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == aliceCount); // An account can't accept its own offer. - env(token::acceptBuyOffer(buyer, buyerOfferIndex), - ter(tecCANT_ACCEPT_OWN_NFTOKEN_OFFER)); + env(token::acceptBuyOffer(buyer, buyerOfferIndex), Ter(TecCantAcceptOwnNftokenOffer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1244,14 +1243,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(pay(buyer, gw, gwAUD(30))); env.close(); BEAST_EXPECT(env.balance(buyer, gwAUD) == gwAUD(0)); - env(token::acceptBuyOffer(alice, buyerOfferIndex), ter(tecINSUFFICIENT_FUNDS)); + env(token::acceptBuyOffer(alice, buyerOfferIndex), Ter(TecInsufficientFunds)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // alice gives her NFT to gw, so alice no longer owns nftAlice0. { uint256 const offerIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAlice0ID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftAlice0ID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(gw, offerIndex)); env.close(); @@ -1261,7 +1260,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // alice can't accept a buy offer for an NFT she no longer owns. - env(token::acceptBuyOffer(alice, buyerOfferIndex), ter(tecNO_PERMISSION)); + env(token::acceptBuyOffer(alice, buyerOfferIndex), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1276,26 +1275,24 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // buyer creates a buy offer for one of alice's nfts. uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftXrpOnlyID, XRP(30)), token::owner(alice)); + env(token::createOffer(buyer, nftXrpOnlyID, kXRP(30)), token::Owner(alice)); env.close(); buyerCount++; BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // Don't accept a sell offer without the sell flag set. - env(token::acceptSellOffer(alice, buyerOfferIndex), - ter(tecNFTOKEN_OFFER_TYPE_MISMATCH)); + env(token::acceptSellOffer(alice, buyerOfferIndex), Ter(TecNftokenOfferTypeMismatch)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == aliceCount); // An account can't accept its own offer. - env(token::acceptSellOffer(alice, plainOfferIndex), - ter(tecCANT_ACCEPT_OWN_NFTOKEN_OFFER)); + env(token::acceptSellOffer(alice, plainOfferIndex), Ter(TecCantAcceptOwnNftokenOffer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // The seller must currently be in possession of the token they // are selling. alice gave nftAlice0ID to gw. - env(token::acceptSellOffer(buyer, plainOfferIndex), ter(tecNO_PERMISSION)); + env(token::acceptSellOffer(buyer, plainOfferIndex), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); @@ -1304,7 +1301,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // insufficient funds. { uint256 const offerIndex = keylet::nftoffer(gw, env.seq(gw)).key; - env(token::createOffer(gw, nftAlice0ID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(gw, nftAlice0ID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(alice, offerIndex)); env.close(); @@ -1313,7 +1310,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(pay(buyer, gw, gwAUD(30))); env.close(); BEAST_EXPECT(env.balance(buyer, gwAUD) == gwAUD(0)); - env(token::acceptSellOffer(buyer, audOfferIndex), ter(tecINSUFFICIENT_FUNDS)); + env(token::acceptSellOffer(buyer, audOfferIndex), Ter(TecInsufficientFunds)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); } @@ -1339,7 +1336,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const minter1{"minter1"}; Account const minter2{"minter2"}; - env.fund(XRP(1000), alice, buyer, minter1, minter2); + env.fund(kXRP(1000), alice, buyer, minter1, minter2); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); @@ -1353,11 +1350,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // 3. transfers that nft to buyer. auto nftToBuyer = [&env, &alice, &minter1, &buyer](std::uint32_t flags) { uint256 const nftID{token::getNextID(env, alice, 0u, flags)}; - env(token::mint(minter1, 0u), token::issuer(alice), txflags(flags)); + env(token::mint(minter1, 0u), token::Issuer(alice), Txflags(flags)); env.close(); uint256 const offerIndex = keylet::nftoffer(minter1, env.seq(minter1)).key; - env(token::createOffer(minter1, nftID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(minter1, nftID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(buyer, offerIndex)); @@ -1369,32 +1366,32 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // An NFT without flagBurnable can only be burned by its owner. { uint256 const noBurnID = nftToBuyer(0); - env(token::burn(alice, noBurnID), token::owner(buyer), ter(tecNO_PERMISSION)); + env(token::burn(alice, noBurnID), token::Owner(buyer), Ter(TecNoPermission)); env.close(); - env(token::burn(minter1, noBurnID), token::owner(buyer), ter(tecNO_PERMISSION)); + env(token::burn(minter1, noBurnID), token::Owner(buyer), Ter(TecNoPermission)); env.close(); - env(token::burn(minter2, noBurnID), token::owner(buyer), ter(tecNO_PERMISSION)); + env(token::burn(minter2, noBurnID), token::Owner(buyer), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); - env(token::burn(buyer, noBurnID), token::owner(buyer)); + env(token::burn(buyer, noBurnID), token::Owner(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); } // An NFT with flagBurnable can be burned by the issuer. { - uint256 const burnableID = nftToBuyer(tfBurnable); - env(token::burn(minter2, burnableID), token::owner(buyer), ter(tecNO_PERMISSION)); + uint256 const burnableID = nftToBuyer(kTF_BURNABLE); + env(token::burn(minter2, burnableID), token::Owner(buyer), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); - env(token::burn(alice, burnableID), token::owner(buyer)); + env(token::burn(alice, burnableID), token::Owner(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); } // An NFT with flagBurnable can be burned by the owner. { - uint256 const burnableID = nftToBuyer(tfBurnable); + uint256 const burnableID = nftToBuyer(kTF_BURNABLE); BEAST_EXPECT(ownerCount(env, buyer) == 1); env(token::burn(buyer, burnableID)); env.close(); @@ -1402,16 +1399,16 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // An NFT with flagBurnable can be burned by the minter. { - uint256 const burnableID = nftToBuyer(tfBurnable); + uint256 const burnableID = nftToBuyer(kTF_BURNABLE); BEAST_EXPECT(ownerCount(env, buyer) == 1); - env(token::burn(buyer, burnableID), token::owner(buyer)); + env(token::burn(buyer, burnableID), token::Owner(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); } // An nft with flagBurnable may be burned by the issuers' minter, // who may not be the original minter. { - uint256 const burnableID = nftToBuyer(tfBurnable); + uint256 const burnableID = nftToBuyer(kTF_BURNABLE); BEAST_EXPECT(ownerCount(env, buyer) == 1); env(token::setMinter(alice, minter2)); @@ -1419,12 +1416,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter1 is no longer alice's minter, so no longer has // permission to burn alice's nfts. - env(token::burn(minter1, burnableID), token::owner(buyer), ter(tecNO_PERMISSION)); + env(token::burn(minter1, burnableID), token::Owner(buyer), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // minter2, however, can burn alice's nfts. - env(token::burn(minter2, burnableID), token::owner(buyer)); + env(token::burn(minter2, burnableID), token::Owner(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); } @@ -1445,7 +1442,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite IOU const gwAUD(gw["AUD"]); // Set trust lines so alice and buyer can use gwAUD. - env.fund(XRP(1000), alice, buyer, gw); + env.fund(kXRP(1000), alice, buyer, gw); env.close(); env(trust(alice, gwAUD(1000))); env(trust(buyer, gwAUD(1000))); @@ -1454,19 +1451,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Don't set flagOnlyXRP and offers can be made with IOUs. { - uint256 const nftIOUsOkayID{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftIOUsOkayID{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); uint256 const aliceOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftIOUsOkayID, gwAUD(50)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftIOUsOkayID, gwAUD(50)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 3); BEAST_EXPECT(ownerCount(env, buyer) == 1); uint256 const buyerOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftIOUsOkayID, gwAUD(50)), token::owner(alice)); + env(token::createOffer(buyer, nftIOUsOkayID, gwAUD(50)), token::Owner(alice)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 2); @@ -1486,32 +1483,32 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Set flagOnlyXRP and offers using IOUs are rejected. { uint256 const nftOnlyXrpID{ - token::getNextID(env, alice, 0u, tfOnlyXRP | tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfOnlyXRP | tfTransferable)); + token::getNextID(env, alice, 0u, kTF_ONLY_XRP | kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_ONLY_XRP | kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); env(token::createOffer(alice, nftOnlyXrpID, gwAUD(50)), - txflags(tfSellNFToken), - ter(temBAD_AMOUNT)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(TemBadAmount)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); BEAST_EXPECT(ownerCount(env, buyer) == 1); env(token::createOffer(buyer, nftOnlyXrpID, gwAUD(50)), - token::owner(alice), - ter(temBAD_AMOUNT)); + token::Owner(alice), + Ter(TemBadAmount)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 1); // However offers for XRP are okay. BEAST_EXPECT(ownerCount(env, alice) == 2); - env(token::createOffer(alice, nftOnlyXrpID, XRP(60)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftOnlyXrpID, kXRP(60)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 3); BEAST_EXPECT(ownerCount(env, buyer) == 1); - env(token::createOffer(buyer, nftOnlyXrpID, XRP(60)), token::owner(alice)); + env(token::createOffer(buyer, nftOnlyXrpID, kXRP(60)), token::Owner(alice)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 2); } @@ -1540,7 +1537,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite {features - fixRemoveNFTokenAutoTrustLine, features | fixRemoveNFTokenAutoTrustLine}) { Env env{*this, tweakedFeatures}; - env.fund(XRP(1000), alice, becky, cheri, gw); + env.fund(kXRP(1000), alice, becky, cheri, gw); env.close(); // Set trust lines so becky and cheri can use gw's currency. @@ -1563,30 +1560,30 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite for (std::uint32_t const xferFee : {0, 1}) { uint256 const nftNoAutoTrustID{ - token::getNextID(env, alice, 0u, tfTransferable, xferFee)}; - env(token::mint(alice, 0u), token::xferFee(xferFee), txflags(tfTransferable)); + token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, xferFee)}; + env(token::mint(alice, 0u), token::XferFee(xferFee), Txflags(kTF_TRANSFERABLE)); env.close(); // becky buys the nft for 1 drop. uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::owner(alice)); + env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::Owner(alice)); env.close(); env(token::acceptBuyOffer(alice, beckyBuyOfferIndex)); env.close(); // becky attempts to sell the nft for AUD. - TER const createOfferTER = (xferFee != 0u) ? TER(tecNO_LINE) : TER(tesSUCCESS); + TER const createOfferTER = (xferFee != 0u) ? TER(TecNoLine) : TER(TesSuccess); uint256 const beckyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; env(token::createOffer(becky, nftNoAutoTrustID, gwAUD(100)), - txflags(tfSellNFToken), - ter(createOfferTER)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(createOfferTER)); env.close(); // cheri offers to buy the nft for CAD. uint256 const cheriOfferIndex = keylet::nftoffer(cheri, env.seq(cheri)).key; env(token::createOffer(cheri, nftNoAutoTrustID, gwCAD(100)), - token::owner(becky), - ter(createOfferTER)); + token::Owner(becky), + Ter(createOfferTER)); env.close(); // To keep things tidy, cancel the offers. @@ -1599,20 +1596,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { std::uint16_t const transferFee = 10000; // 10% - uint256 const nftAutoTrustID{ - token::getNextID(env, alice, 0u, tfTransferable | tfTrustLine, transferFee)}; + uint256 const nftAutoTrustID{token::getNextID( + env, alice, 0u, kTF_TRANSFERABLE | kTF_TRUST_LINE, transferFee)}; // If the fixRemoveNFTokenAutoTrustLine amendment is active // then this transaction fails. { TER const mintTER = tweakedFeatures[fixRemoveNFTokenAutoTrustLine] - ? static_cast(temINVALID_FLAG) - : static_cast(tesSUCCESS); + ? static_cast(TemInvalidFlag) + : static_cast(TesSuccess); env(token::mint(alice, 0u), - token::xferFee(transferFee), - txflags(tfTransferable | tfTrustLine), - ter(mintTER)); + token::XferFee(transferFee), + Txflags(kTF_TRANSFERABLE | kTF_TRUST_LINE), + Ter(mintTER)); env.close(); // If fixRemoveNFTokenAutoTrustLine is active the rest @@ -1622,14 +1619,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // becky buys the nft for 1 drop. uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::owner(alice)); + env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::Owner(alice)); env.close(); env(token::acceptBuyOffer(alice, beckyBuyOfferIndex)); env.close(); // becky sells the nft for AUD. uint256 const beckySellOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, gwAUD(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftAutoTrustID, gwAUD(100)), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(cheri, beckySellOfferIndex)); env.close(); @@ -1639,7 +1637,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky buys the nft back for CAD. uint256 const beckyBuyBackOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, gwCAD(50)), token::owner(cheri)); + env(token::createOffer(becky, nftAutoTrustID, gwCAD(50)), token::Owner(cheri)); env.close(); env(token::acceptBuyOffer(cheri, beckyBuyBackOfferIndex)); env.close(); @@ -1653,14 +1651,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { std::uint16_t const transferFee = 5000; // 5% uint256 const nftNoAutoTrustID{ - token::getNextID(env, alice, 0u, tfTransferable, transferFee)}; - env(token::mint(alice, 0u), token::xferFee(transferFee), txflags(tfTransferable)); + token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, transferFee)}; + env(token::mint(alice, 0u), token::XferFee(transferFee), Txflags(kTF_TRANSFERABLE)); env.close(); // alice sells the nft using AUD. uint256 const aliceSellOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; env(token::createOffer(alice, nftNoAutoTrustID, gwAUD(200)), - txflags(tfSellNFToken)); + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(cheri, aliceSellOfferIndex)); env.close(); @@ -1672,12 +1670,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // cheri can't sell the NFT for EUR, but can for CAD. env(token::createOffer(cheri, nftNoAutoTrustID, gwEUR(50)), - txflags(tfSellNFToken), - ter(tecNO_LINE)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoLine)); env.close(); uint256 const cheriSellOfferIndex = keylet::nftoffer(cheri, env.seq(cheri)).key; env(token::createOffer(cheri, nftNoAutoTrustID, gwCAD(100)), - txflags(tfSellNFToken)); + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(becky, cheriSellOfferIndex)); env.close(); @@ -1704,26 +1702,27 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const becky{"becky"}; Account const minter{"minter"}; - env.fund(XRP(1000), alice, becky, minter); + env.fund(kXRP(1000), alice, becky, minter); env.close(); // First try an nft made by alice without flagTransferable set. { BEAST_EXPECT(ownerCount(env, alice) == 0); uint256 const nftAliceNoTransferID{token::getNextID(env, alice, 0u)}; - env(token::mint(alice, 0u), token::xferFee(0)); + env(token::mint(alice, 0u), token::XferFee(0)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // becky tries to offer to buy alice's nft. BEAST_EXPECT(ownerCount(env, becky) == 0); - env(token::createOffer(becky, nftAliceNoTransferID, XRP(20)), - token::owner(alice), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(becky, nftAliceNoTransferID, kXRP(20)), + token::Owner(alice), + Ter(TefNftokenIsNotTransferable)); // alice offers to sell the nft and becky accepts the offer. uint256 const aliceSellOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAliceNoTransferID, XRP(20)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftAliceNoTransferID, kXRP(20)), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(becky, aliceSellOfferIndex)); env.close(); @@ -1731,19 +1730,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, becky) == 1); // becky tries to offer the nft for sale. - env(token::createOffer(becky, nftAliceNoTransferID, XRP(21)), - txflags(tfSellNFToken), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(becky, nftAliceNoTransferID, kXRP(21)), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); BEAST_EXPECT(ownerCount(env, becky) == 1); // becky tries to offer the nft for sale with alice as the // destination. That also doesn't work. - env(token::createOffer(becky, nftAliceNoTransferID, XRP(21)), - txflags(tfSellNFToken), - token::destination(alice), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(becky, nftAliceNoTransferID, kXRP(21)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(alice), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); BEAST_EXPECT(ownerCount(env, becky) == 1); @@ -1751,7 +1750,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice offers to buy the nft back from becky. becky accepts // the offer. uint256 const aliceBuyOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAliceNoTransferID, XRP(22)), token::owner(becky)); + env(token::createOffer(alice, nftAliceNoTransferID, kXRP(22)), token::Owner(becky)); env.close(); env(token::acceptBuyOffer(becky, aliceBuyOfferIndex)); env.close(); @@ -1771,15 +1770,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, minter) == 0); uint256 const nftMinterNoTransferID{token::getNextID(env, alice, 0u)}; - env(token::mint(minter), token::issuer(alice)); + env(token::mint(minter), token::Issuer(alice)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 1); // becky tries to offer to buy minter's nft. BEAST_EXPECT(ownerCount(env, becky) == 0); - env(token::createOffer(becky, nftMinterNoTransferID, XRP(20)), - token::owner(minter), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(becky, nftMinterNoTransferID, kXRP(20)), + token::Owner(minter), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, becky) == 0); @@ -1789,9 +1788,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter tries to offer their nft for sale. BEAST_EXPECT(ownerCount(env, minter) == 1); - env(token::createOffer(minter, nftMinterNoTransferID, XRP(21)), - txflags(tfSellNFToken), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(minter, nftMinterNoTransferID, kXRP(21)), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -1807,7 +1806,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter successfully offers their nft for sale. BEAST_EXPECT(ownerCount(env, minter) == 1); uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftMinterNoTransferID, XRP(22)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftMinterNoTransferID, kXRP(22)), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -1825,24 +1825,24 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, minter) == 0); // becky attempts to sell the nft. - env(token::createOffer(becky, nftMinterNoTransferID, XRP(23)), - txflags(tfSellNFToken), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(becky, nftMinterNoTransferID, kXRP(23)), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TefNftokenIsNotTransferable)); env.close(); // Since minter is not, at the moment, alice's official minter // they cannot create an offer to buy the nft they minted. BEAST_EXPECT(ownerCount(env, minter) == 0); - env(token::createOffer(minter, nftMinterNoTransferID, XRP(24)), - token::owner(becky), - ter(tefNFTOKEN_IS_NOT_TRANSFERABLE)); + env(token::createOffer(minter, nftMinterNoTransferID, kXRP(24)), + token::Owner(becky), + Ter(TefNftokenIsNotTransferable)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 0); // alice can create an offer to buy the nft. BEAST_EXPECT(ownerCount(env, alice) == 0); uint256 const aliceBuyOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftMinterNoTransferID, XRP(25)), token::owner(becky)); + env(token::createOffer(alice, nftMinterNoTransferID, kXRP(25)), token::Owner(becky)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); @@ -1857,7 +1857,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Now minter can create an offer to buy the nft. BEAST_EXPECT(ownerCount(env, minter) == 0); uint256 const minterBuyOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftMinterNoTransferID, XRP(26)), token::owner(becky)); + env(token::createOffer(minter, nftMinterNoTransferID, kXRP(26)), token::Owner(becky)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -1877,7 +1877,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter burns their nft and alice cancels her offer so the // next tests can start with a clean slate. - env(token::burn(minter, nftMinterNoTransferID), ter(tesSUCCESS)); + env(token::burn(minter, nftMinterNoTransferID), Ter(TesSuccess)); env.close(); env(token::cancelOffer(alice, {aliceBuyOfferIndex})); env.close(); @@ -1889,19 +1889,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // by anybody. { BEAST_EXPECT(ownerCount(env, alice) == 0); - uint256 const nftAliceID{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftAliceID{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 1); // Both alice and becky can make offers for alice's nft. uint256 const aliceSellOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftAliceID, XRP(20)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftAliceID, kXRP(20)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAliceID, XRP(21)), token::owner(alice)); + env(token::createOffer(becky, nftAliceID, kXRP(21)), token::Owner(alice)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); @@ -1913,7 +1913,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky offers to sell the nft. uint256 const beckySellOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAliceID, XRP(22)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftAliceID, kXRP(22)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); BEAST_EXPECT(ownerCount(env, becky) == 3); @@ -1928,7 +1928,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter offers to sell the nft. uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftAliceID, XRP(23)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftAliceID, kXRP(23)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); BEAST_EXPECT(ownerCount(env, becky) == 1); @@ -1977,7 +1977,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const gw{"gw"}; IOU const gwXAU(gw["XAU"]); - env.fund(XRP(1000), alice, becky, carol, minter, gw); + env.fund(kXRP(1000), alice, becky, carol, minter, gw); env.close(); env(trust(alice, gwXAU(2000))); @@ -2004,13 +2004,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, carol) == 1); BEAST_EXPECT(ownerCount(env, minter) == 1); - uint256 const nftID = token::getNextID(env, alice, 0u, tfTransferable); - env(token::mint(alice), txflags(tfTransferable)); + uint256 const nftID = token::getNextID(env, alice, 0u, kTF_TRANSFERABLE); + env(token::mint(alice), Txflags(kTF_TRANSFERABLE)); env.close(); // Becky buys the nft for XAU(10). Check balances. uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(10)), token::owner(alice)); + env(token::createOffer(becky, nftID, gwXAU(10)), token::Owner(alice)); env.close(); BEAST_EXPECT(env.balance(alice, gwXAU) == gwXAU(1000)); BEAST_EXPECT(env.balance(becky, gwXAU) == gwXAU(1000)); @@ -2022,7 +2022,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky sells nft to carol. alice's balance should not change. uint256 const beckySellOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(10)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftID, gwXAU(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(carol, beckySellOfferIndex)); env.close(); @@ -2032,7 +2032,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter buys nft from carol. alice's balance should not change. uint256 const minterBuyOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(10)), token::owner(carol)); + env(token::createOffer(minter, nftID, gwXAU(10)), token::Owner(carol)); env.close(); env(token::acceptBuyOffer(carol, minterBuyOfferIndex)); env.close(); @@ -2044,7 +2044,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter sells the nft to alice. gwXAU balances should finish // where they started. uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(10)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(alice, minterSellOfferIndex)); env.close(); @@ -2065,13 +2065,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Set the smallest possible transfer fee. { // An nft with a transfer fee of 1 basis point. - uint256 const nftID = token::getNextID(env, alice, 0u, tfTransferable, 1); - env(token::mint(alice), txflags(tfTransferable), token::xferFee(1)); + uint256 const nftID = token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, 1); + env(token::mint(alice), Txflags(kTF_TRANSFERABLE), token::XferFee(1)); env.close(); // Becky buys the nft for XAU(10). Check balances. uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(10)), token::owner(alice)); + env(token::createOffer(becky, nftID, gwXAU(10)), token::Owner(alice)); env.close(); BEAST_EXPECT(env.balance(alice, gwXAU) == gwXAU(1000)); BEAST_EXPECT(env.balance(becky, gwXAU) == gwXAU(1000)); @@ -2083,7 +2083,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky sells nft to carol. alice's balance goes up. uint256 const beckySellOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(10)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftID, gwXAU(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(carol, beckySellOfferIndex)); env.close(); @@ -2094,7 +2094,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter buys nft from carol. alice's balance goes up. uint256 const minterBuyOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(10)), token::owner(carol)); + env(token::createOffer(minter, nftID, gwXAU(10)), token::Owner(carol)); env.close(); env(token::acceptBuyOffer(carol, minterBuyOfferIndex)); env.close(); @@ -2107,7 +2107,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter sells the nft to alice. Because alice is part of the // transaction no transfer fee is removed. uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(10)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(alice, minterSellOfferIndex)); env.close(); @@ -2140,19 +2140,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // A transfer fee greater than 50% is not allowed. env(token::mint(alice), - txflags(tfTransferable), - token::xferFee(maxTransferFee + 1), - ter(temBAD_NFTOKEN_TRANSFER_FEE)); + Txflags(kTF_TRANSFERABLE), + token::XferFee(kMAX_TRANSFER_FEE + 1), + Ter(TemBadNftokenTransferFee)); env.close(); // Make an nft with a transfer fee of 50%. - uint256 const nftID = token::getNextID(env, alice, 0u, tfTransferable, maxTransferFee); - env(token::mint(alice), txflags(tfTransferable), token::xferFee(maxTransferFee)); + uint256 const nftID = + token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, kMAX_TRANSFER_FEE); + env(token::mint(alice), Txflags(kTF_TRANSFERABLE), token::XferFee(kMAX_TRANSFER_FEE)); env.close(); // Becky buys the nft for XAU(10). Check balances. uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(10)), token::owner(alice)); + env(token::createOffer(becky, nftID, gwXAU(10)), token::Owner(alice)); env.close(); BEAST_EXPECT(env.balance(alice, gwXAU) == gwXAU(1000)); BEAST_EXPECT(env.balance(becky, gwXAU) == gwXAU(1000)); @@ -2164,7 +2165,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky sells nft to minter. alice's balance goes up. uint256 const beckySellOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, gwXAU(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftID, gwXAU(100)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(minter, beckySellOfferIndex)); env.close(); @@ -2175,7 +2176,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // carol buys nft from minter. alice's balance goes up. uint256 const carolBuyOfferIndex = keylet::nftoffer(carol, env.seq(carol)).key; - env(token::createOffer(carol, nftID, gwXAU(10)), token::owner(minter)); + env(token::createOffer(carol, nftID, gwXAU(10)), token::Owner(minter)); env.close(); env(token::acceptBuyOffer(minter, carolBuyOfferIndex)); env.close(); @@ -2188,7 +2189,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // carol sells the nft to alice. Because alice is part of the // transaction no transfer fee is removed. uint256 const carolSellOfferIndex = keylet::nftoffer(carol, env.seq(carol)).key; - env(token::createOffer(carol, nftID, gwXAU(10)), txflags(tfSellNFToken)); + env(token::createOffer(carol, nftID, gwXAU(10)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(alice, carolSellOfferIndex)); env.close(); @@ -2220,8 +2221,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // of drops. { // An nft with a transfer fee of 1 basis point. - uint256 const nftID = token::getNextID(env, alice, 0u, tfTransferable, 1); - env(token::mint(alice), txflags(tfTransferable), token::xferFee(1)); + uint256 const nftID = token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, 1); + env(token::mint(alice), Txflags(kTF_TRANSFERABLE), token::XferFee(1)); env.close(); // minter buys the nft for XRP(1). Since the transfer involves @@ -2229,12 +2230,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite STAmount aliceBalance = env.balance(alice); STAmount minterBalance = env.balance(minter); uint256 const minterBuyOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, XRP(1)), token::owner(alice)); + env(token::createOffer(minter, nftID, kXRP(1)), token::Owner(alice)); env.close(); env(token::acceptBuyOffer(alice, minterBuyOfferIndex)); env.close(); - aliceBalance += XRP(1) - baseFee; - minterBalance -= XRP(1) + baseFee; + aliceBalance += kXRP(1) - baseFee; + minterBalance -= kXRP(1) + baseFee; BEAST_EXPECT(env.balance(alice) == aliceBalance); BEAST_EXPECT(env.balance(minter) == minterBalance); @@ -2243,7 +2244,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto pmt = drops(50000); STAmount carolBalance = env.balance(carol); uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, pmt), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, pmt), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(carol, minterSellOfferIndex)); env.close(); @@ -2258,7 +2259,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite STAmount beckyBalance = env.balance(becky); uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; pmt = drops(50001); - env(token::createOffer(becky, nftID, pmt), token::owner(carol)); + env(token::createOffer(becky, nftID, pmt), token::Owner(carol)); env.close(); env(token::acceptBuyOffer(carol, beckyBuyOfferIndex)); env.close(); @@ -2276,8 +2277,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // of an IOU. { // An nft with a transfer fee of 1 basis point. - uint256 const nftID = token::getNextID(env, alice, 0u, tfTransferable, 1); - env(token::mint(alice), txflags(tfTransferable), token::xferFee(1)); + uint256 const nftID = token::getNextID(env, alice, 0u, kTF_TRANSFERABLE, 1); + env(token::mint(alice), Txflags(kTF_TRANSFERABLE), token::XferFee(1)); env.close(); // Due to the floating point nature of IOUs we need to @@ -2288,21 +2289,22 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(pay(becky, gw, env.balance(becky, gwXAU))); env.close(); - STAmount const startXAUBalance(gwXAU, STAmount::cMinValue, STAmount::cMinOffset + 5); + STAmount const startXAUBalance( + gwXAU, STAmount::kC_MIN_VALUE, STAmount::kC_MIN_OFFSET + 5); env(pay(gw, alice, startXAUBalance)); env(pay(gw, minter, startXAUBalance)); env(pay(gw, becky, startXAUBalance)); env.close(); // Here is the smallest expressible gwXAU amount. - STAmount const tinyXAU(gwXAU, STAmount::cMinValue, STAmount::cMinOffset); + STAmount const tinyXAU(gwXAU, STAmount::kC_MIN_VALUE, STAmount::kC_MIN_OFFSET); // minter buys the nft for tinyXAU. Since the transfer involves // alice there should be no transfer fee. STAmount aliceBalance = env.balance(alice, gwXAU); STAmount minterBalance = env.balance(minter, gwXAU); uint256 const minterBuyOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, tinyXAU), token::owner(alice)); + env(token::createOffer(minter, nftID, tinyXAU), token::Owner(alice)); env.close(); env(token::acceptBuyOffer(alice, minterBuyOfferIndex)); env.close(); @@ -2314,7 +2316,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter sells to carol. STAmount carolBalance = env.balance(carol, gwXAU); uint256 const minterSellOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, tinyXAU), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, tinyXAU), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(carol, minterSellOfferIndex)); env.close(); @@ -2328,11 +2330,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // carol sells to becky. This is the smallest gwXAU amount // to pay for a transfer that enables a transfer fee of 1. - STAmount const cheapNFT(gwXAU, STAmount::cMinValue, STAmount::cMinOffset + 5); + STAmount const cheapNFT(gwXAU, STAmount::kC_MIN_VALUE, STAmount::kC_MIN_OFFSET + 5); STAmount beckyBalance = env.balance(becky, gwXAU); uint256 const beckyBuyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftID, cheapNFT), token::owner(carol)); + env(token::createOffer(becky, nftID, cheapNFT), token::Owner(carol)); env.close(); env(token::acceptBuyOffer(carol, beckyBuyOfferIndex)); env.close(); @@ -2360,7 +2362,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice{"alice"}; Account const becky{"becky"}; - env.fund(XRP(1000), alice, becky); + env.fund(kXRP(1000), alice, becky); env.close(); // The taxon field is incorporated straight into the NFT ID. So @@ -2439,7 +2441,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice{"alice"}; Account const becky{"becky"}; - env.fund(XRP(10000), alice, becky); + env.fund(kXRP(10000), alice, becky); env.close(); // lambda that returns a randomly generated string which fits @@ -2466,7 +2468,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite std::string uri; std::uint32_t taxon; - Entry(std::string uri_, std::uint32_t taxon_) : uri(std::move(uri_)), taxon(taxon_) + Entry(std::string uri, std::uint32_t taxon) : uri(std::move(uri)), taxon(taxon) { } }; @@ -2485,7 +2487,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } else { - env(token::mint(alice, entry.taxon), token::uri(entry.uri)); + env(token::mint(alice, entry.taxon), token::Uri(entry.uri)); } env.close(); } @@ -2494,12 +2496,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Json::Value aliceNFTs = [&env, &alice]() { Json::Value params; params[jss::account] = alice.human(); - params[jss::type] = "state"; + params[jss::kTYPE] = "state"; return env.rpc("json", "account_nfts", to_string(params)); }(); // Verify that the returned NFTs match what we sent. - Json::Value& nfts = aliceNFTs[jss::result][jss::account_nfts]; + Json::Value& nfts = aliceNFTs[jss::kRESULT][jss::kACCOUNT_NFTS]; if (!BEAST_EXPECT(nfts.size() == entries.size())) return; @@ -2513,7 +2515,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite sortedNFTs, [](Json::Value const& lhs, Json::Value const& rhs) { - return lhs[jss::nft_serial] < rhs[jss::nft_serial]; + return lhs[jss::kNFT_SERIAL] < rhs[jss::kNFT_SERIAL]; }); for (std::size_t i = 0; i < entries.size(); ++i) @@ -2547,15 +2549,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const buyer{"buyer"}; Account const broker{"broker"}; - env.fund(XRP(1000), issuer, minter, buyer, broker); + env.fund(kXRP(1000), issuer, minter, buyer, broker); // We want to explore how issuers vs minters fits into the permission // scheme. So issuer issues and minter mints. env(token::setMinter(issuer, minter)); env.close(); - uint256 const nftokenID = token::getNextID(env, issuer, 0, tfTransferable); - env(token::mint(minter, 0), token::issuer(issuer), txflags(tfTransferable)); + uint256 const nftokenID = token::getNextID(env, issuer, 0, kTF_TRANSFERABLE); + env(token::mint(minter, 0), token::Issuer(issuer), Txflags(kTF_TRANSFERABLE)); env.close(); // Test how adding a Destination field to an offer affects permissions @@ -2563,23 +2565,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerMinterToIssuer = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(issuer), - txflags(tfSellNFToken)); + token::Destination(issuer), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerMinterToBuyer = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerIssuerToMinter = keylet::nftoffer(issuer, env.seq(issuer)).key; env(token::createOffer(issuer, nftokenID, drops(1)), - token::owner(minter), - token::destination(minter)); + token::Owner(minter), + token::Destination(minter)); uint256 const offerIssuerToBuyer = keylet::nftoffer(issuer, env.seq(issuer)).key; env(token::createOffer(issuer, nftokenID, drops(1)), - token::owner(minter), - token::destination(buyer)); + token::Owner(minter), + token::Destination(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 2); @@ -2593,10 +2595,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Note that issuer does not have any special permissions regarding // offer cancellation. issuer cannot cancel an offer for an // NFToken they issued. - env(token::cancelOffer(issuer, {offerMinterToBuyer}), ter(tecNO_PERMISSION)); - env(token::cancelOffer(buyer, {offerMinterToIssuer}), ter(tecNO_PERMISSION)); - env(token::cancelOffer(buyer, {offerIssuerToMinter}), ter(tecNO_PERMISSION)); - env(token::cancelOffer(minter, {offerIssuerToBuyer}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(issuer, {offerMinterToBuyer}), Ter(TecNoPermission)); + env(token::cancelOffer(buyer, {offerMinterToIssuer}), Ter(TecNoPermission)); + env(token::cancelOffer(buyer, {offerIssuerToMinter}), Ter(TecNoPermission)); + env(token::cancelOffer(minter, {offerIssuerToBuyer}), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 2); BEAST_EXPECT(ownerCount(env, minter) == 3); @@ -2619,8 +2621,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerMinterSellsToBuyer = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -2628,7 +2630,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // issuer cannot accept a sell offer where they are not the // destination. - env(token::acceptSellOffer(issuer, offerMinterSellsToBuyer), ter(tecNO_PERMISSION)); + env(token::acceptSellOffer(issuer, offerMinterSellsToBuyer), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -2647,8 +2649,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerMinterBuysFromBuyer = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::owner(buyer), - token::destination(buyer)); + token::Owner(buyer), + token::Destination(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -2656,7 +2658,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // issuer cannot accept a buy offer where they are the // destination. - env(token::acceptBuyOffer(issuer, offerMinterBuysFromBuyer), ter(tecNO_PERMISSION)); + env(token::acceptBuyOffer(issuer, offerMinterBuysFromBuyer), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -2674,14 +2676,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // simply accept the offer. uint256 const offerBuyerBuysFromMinter = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID, drops(1)), - token::owner(minter), - token::destination(broker)); + token::Owner(minter), + token::Destination(broker)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 1); BEAST_EXPECT(ownerCount(env, buyer) == 1); - env(token::acceptBuyOffer(minter, offerBuyerBuysFromMinter), ter(tecNO_PERMISSION)); + env(token::acceptBuyOffer(minter, offerBuyerBuysFromMinter), Ter(TecNoPermission)); env.close(); // Clean up the unused offer. @@ -2697,11 +2699,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerMinterToBroker = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(broker), - txflags(tfSellNFToken)); + token::Destination(broker), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerBuyerToMinter = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID, drops(1)), token::owner(minter)); + env(token::createOffer(buyer, nftokenID, drops(1)), token::Owner(minter)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); @@ -2712,7 +2714,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // issuer cannot broker the offers, because they are not the // Destination. env(token::brokerOffers(issuer, offerBuyerToMinter, offerMinterToBroker), - ter(tecNO_PERMISSION)); + Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -2734,14 +2736,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerBuyerToMinter = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID, drops(1)), - token::destination(minter), - txflags(tfSellNFToken)); + token::Destination(minter), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerMinterToBuyer = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftokenID, drops(1)), token::owner(buyer)); + env(token::createOffer(minter, nftokenID, drops(1)), token::Owner(buyer)); uint256 const offerIssuerToBuyer = keylet::nftoffer(issuer, env.seq(issuer)).key; - env(token::createOffer(issuer, nftokenID, drops(1)), token::owner(buyer)); + env(token::createOffer(issuer, nftokenID, drops(1)), token::Owner(buyer)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); @@ -2752,7 +2754,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Cannot broker offers when the sell destination is not the // buyer. env(token::brokerOffers(broker, offerIssuerToBuyer, offerBuyerToMinter), - ter(tecNO_PERMISSION)); + Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); @@ -2760,7 +2762,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, buyer) == 2); env(token::brokerOffers(broker, offerMinterToBuyer, offerBuyerToMinter), - ter(tecNO_PERMISSION)); + Ter(TecNoPermission)); env.close(); // Buyer is successful with acceptOffer. @@ -2790,19 +2792,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const offerMinterToBroker = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(broker), - txflags(tfSellNFToken)); + token::Destination(broker), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerBuyerToBroker = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID, drops(1)), - token::owner(minter), - token::destination(broker)); + token::Owner(minter), + token::Destination(broker)); { // Cannot broker offers when the sell destination is not the // buyer or the broker. env(token::brokerOffers(issuer, offerBuyerToBroker, offerMinterToBroker), - ter(tecNO_PERMISSION)); + Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -2832,25 +2834,25 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const buyer{"buyer"}; Account const alice{"alice"}; - env.fund(XRP(1000), issuer, minter, buyer, alice); + env.fund(kXRP(1000), issuer, minter, buyer, alice); env(token::setMinter(issuer, minter)); env.close(); - uint256 const nftokenID = token::getNextID(env, issuer, 0, tfTransferable); - env(token::mint(minter, 0), token::issuer(issuer), txflags(tfTransferable)); + uint256 const nftokenID = token::getNextID(env, issuer, 0, kTF_TRANSFERABLE); + env(token::mint(minter, 0), token::Issuer(issuer), Txflags(kTF_TRANSFERABLE)); env.close(); // enable flag - env(fset(buyer, asfDisallowIncomingNFTokenOffer)); + env(fset(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); env.close(); // a sell offer from the minter to the buyer should be rejected { env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken), - ter(tecNO_PERMISSION)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -2858,7 +2860,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // disable the flag - env(fclear(buyer, asfDisallowIncomingNFTokenOffer)); + env(fclear(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); env.close(); // create offer (allowed now) then cancel @@ -2866,8 +2868,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offerIndex = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::cancelOffer(minter, {offerIndex})); @@ -2879,17 +2881,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offerIndex = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); - env(fset(buyer, asfDisallowIncomingNFTokenOffer)); + env(fset(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); env.close(); env(token::cancelOffer(minter, {offerIndex})); env.close(); - env(fclear(buyer, asfDisallowIncomingNFTokenOffer)); + env(fclear(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); env.close(); } @@ -2898,8 +2900,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offerIndex = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID, drops(1)), - token::destination(buyer), - txflags(tfSellNFToken)); + token::Destination(buyer), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(buyer, offerIndex)); @@ -2909,22 +2911,22 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // buyer now owns the token // enable flag again - env(fset(buyer, asfDisallowIncomingNFTokenOffer)); + env(fset(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); env.close(); // a random offer to buy the token { env(token::createOffer(alice, nftokenID, drops(1)), - token::owner(buyer), - ter(tecNO_PERMISSION)); + token::Owner(buyer), + Ter(TecNoPermission)); env.close(); } // minter offer to buy the token { env(token::createOffer(minter, nftokenID, drops(1)), - token::owner(buyer), - ter(tecNO_PERMISSION)); + token::Owner(buyer), + Ter(TecNoPermission)); env.close(); } @@ -2932,17 +2934,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite if (features[featureNFTokenMintOffer]) { // enable flag - env(fset(buyer, asfDisallowIncomingNFTokenOffer)); + env(fset(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); // a sell offer from the minter to the buyer should be rejected env(token::mint(minter), - token::amount(drops(1)), - token::destination(buyer), - ter(tecNO_PERMISSION)); + token::Amount(drops(1)), + token::Destination(buyer), + Ter(TecNoPermission)); env.close(); // disable flag - env(fclear(buyer, asfDisallowIncomingNFTokenOffer)); - env(token::mint(minter), token::amount(drops(1)), token::destination(buyer)); + env(fclear(buyer, kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER)); + env(token::mint(minter), token::Amount(drops(1)), token::Destination(buyer)); env.close(); } } @@ -2961,19 +2963,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const minter{"minter"}; Account const buyer{"buyer"}; - env.fund(XRP(1000), issuer, minter, buyer); + env.fund(kXRP(1000), issuer, minter, buyer); // We want to explore how issuers vs minters fits into the permission // scheme. So issuer issues and minter mints. env(token::setMinter(issuer, minter)); env.close(); - uint256 const nftokenID0 = token::getNextID(env, issuer, 0, tfTransferable); - env(token::mint(minter, 0), token::issuer(issuer), txflags(tfTransferable)); + uint256 const nftokenID0 = token::getNextID(env, issuer, 0, kTF_TRANSFERABLE); + env(token::mint(minter, 0), token::Issuer(issuer), Txflags(kTF_TRANSFERABLE)); env.close(); - uint256 const nftokenID1 = token::getNextID(env, issuer, 0, tfTransferable); - env(token::mint(minter, 0), token::issuer(issuer), txflags(tfTransferable)); + uint256 const nftokenID1 = token::getNextID(env, issuer, 0, kTF_TRANSFERABLE); + env(token::mint(minter, 0), token::Issuer(issuer), Txflags(kTF_TRANSFERABLE)); env.close(); uint8_t issuerCount = 0, minterCount = 0, buyerCount = 0; @@ -2984,24 +2986,24 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offerMinterToIssuer = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID0, drops(1)), - token::destination(issuer), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Destination(issuer), + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerMinterToAnyone = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID0, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const offerIssuerToMinter = keylet::nftoffer(issuer, env.seq(issuer)).key; env(token::createOffer(issuer, nftokenID0, drops(1)), - token::owner(minter), - token::expiration(expiration)); + token::Owner(minter), + token::Expiration(expiration)); uint256 const offerBuyerToMinter = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID0, drops(1)), - token::owner(minter), - token::expiration(expiration)); + token::Owner(minter), + token::Expiration(expiration)); env.close(); issuerCount = 1; minterCount = 3; @@ -3016,8 +3018,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // // Note that these are tec responses, so these transactions will // not be retried by the ledger. - env(token::cancelOffer(issuer, {offerMinterToAnyone}), ter(tecNO_PERMISSION)); - env(token::cancelOffer(buyer, {offerIssuerToMinter}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(issuer, {offerMinterToAnyone}), Ter(TecNoPermission)); + env(token::cancelOffer(buyer, {offerIssuerToMinter}), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(lastClose(env) < expiration); BEAST_EXPECT(ownerCount(env, issuer) == issuerCount); @@ -3060,14 +3062,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offer0 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID0, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); minterCount++; uint256 const offer1 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID1, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); minterCount++; env.close(); BEAST_EXPECT(lastClose(env) < expiration); @@ -3089,7 +3091,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // No one can accept an expired sell offer. - env(token::acceptSellOffer(buyer, offer1), ter(tecEXPIRED)); + env(token::acceptSellOffer(buyer, offer1), Ter(TecExpired)); // With fixSecurity3_1_3 amendment, the first accept // attempt deletes the expired offer. Without the amendment, @@ -3098,13 +3100,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // After amendment: offer was deleted by first accept attempt minterCount--; - env(token::acceptSellOffer(issuer, offer1), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptSellOffer(issuer, offer1), Ter(TecObjectNotFound)); } else { // Before amendment: offer still exists, second accept also // fails - env(token::acceptSellOffer(issuer, offer1), ter(tecEXPIRED)); + env(token::acceptSellOffer(issuer, offer1), Ter(TecExpired)); } env.close(); @@ -3130,9 +3132,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Transfer nftokenID0 back to minter so we start the next test in // a simple place. uint256 const offerSellBack = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, XRP(0)), - txflags(tfSellNFToken), - token::destination(minter)); + env(token::createOffer(buyer, nftokenID0, kXRP(0)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(minter)); env.close(); env(token::acceptSellOffer(minter, offerSellBack)); buyerCount--; @@ -3150,14 +3152,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const offer0 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID0, drops(1)), - token::owner(minter), - token::expiration(expiration)); + token::Owner(minter), + token::Expiration(expiration)); buyerCount++; uint256 const offer1 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID1, drops(1)), - token::owner(minter), - token::expiration(expiration)); + token::Owner(minter), + token::Expiration(expiration)); buyerCount++; env.close(); BEAST_EXPECT(lastClose(env) < expiration); @@ -3177,7 +3179,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // An expired buy offer cannot be accepted. - env(token::acceptBuyOffer(minter, offer1), ter(tecEXPIRED)); + env(token::acceptBuyOffer(minter, offer1), Ter(TecExpired)); // With fixSecurity3_1_3 amendment, the first accept // attempt deletes the expired offer. Without the amendment, @@ -3186,13 +3188,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // After amendment: offer was deleted by first accept attempt buyerCount--; - env(token::acceptBuyOffer(issuer, offer1), ter(tecOBJECT_NOT_FOUND)); + env(token::acceptBuyOffer(issuer, offer1), Ter(TecObjectNotFound)); } else { // Before amendment: offer still exists, second accept also // fails - env(token::acceptBuyOffer(issuer, offer1), ter(tecEXPIRED)); + env(token::acceptBuyOffer(issuer, offer1), Ter(TecExpired)); } env.close(); @@ -3218,9 +3220,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Transfer nftokenID0 back to minter so we start the next test in // a simple place. uint256 const offerSellBack = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, XRP(0)), - txflags(tfSellNFToken), - token::destination(minter)); + env(token::createOffer(buyer, nftokenID0, kXRP(0)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(minter)); env.close(); env(token::acceptSellOffer(minter, offerSellBack)); env.close(); @@ -3238,22 +3240,22 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const sellOffer0 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID0, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); minterCount++; uint256 const sellOffer1 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID1, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); minterCount++; uint256 const buyOffer0 = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, drops(1)), token::owner(minter)); + env(token::createOffer(buyer, nftokenID0, drops(1)), token::Owner(minter)); buyerCount++; uint256 const buyOffer1 = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID1, drops(1)), token::owner(minter)); + env(token::createOffer(buyer, nftokenID1, drops(1)), token::Owner(minter)); buyerCount++; env.close(); @@ -3275,7 +3277,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, buyer) == buyerCount); // If the sell offer is expired it cannot be brokered. - env(token::brokerOffers(issuer, buyOffer1, sellOffer1), ter(tecEXPIRED)); + env(token::brokerOffers(issuer, buyOffer1, sellOffer1), Ter(TecExpired)); env.close(); if (features[fixSecurity3_1_3]) @@ -3312,9 +3314,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Transfer nftokenID0 back to minter so we start the next test in // a simple place. uint256 const offerSellBack = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, XRP(0)), - txflags(tfSellNFToken), - token::destination(minter)); + env(token::createOffer(buyer, nftokenID0, kXRP(0)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(minter)); env.close(); env(token::acceptSellOffer(minter, offerSellBack)); env.close(); @@ -3331,20 +3333,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite std::uint32_t const expiration = lastClose(env) + 25; uint256 const sellOffer0 = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftokenID0, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftokenID0, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); uint256 const sellOffer1 = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftokenID1, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftokenID1, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); uint256 const buyOffer0 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID0, drops(1)), - token::expiration(expiration), - token::owner(minter)); + token::Expiration(expiration), + token::Owner(minter)); uint256 const buyOffer1 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID1, drops(1)), - token::expiration(expiration), - token::owner(minter)); + token::Expiration(expiration), + token::Owner(minter)); env.close(); BEAST_EXPECT(lastClose(env) < expiration); @@ -3363,7 +3365,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, minter) == 2); BEAST_EXPECT(ownerCount(env, buyer) == 2); - env(token::brokerOffers(issuer, buyOffer1, sellOffer1), ter(tecEXPIRED)); + env(token::brokerOffers(issuer, buyOffer1, sellOffer1), Ter(TecExpired)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); @@ -3393,9 +3395,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Transfer nftokenID0 back to minter so we start the next test in // a simple place. uint256 const offerSellBack = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, XRP(0)), - txflags(tfSellNFToken), - token::destination(minter)); + env(token::createOffer(buyer, nftokenID0, kXRP(0)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(minter)); env.close(); env(token::acceptSellOffer(minter, offerSellBack)); env.close(); @@ -3413,23 +3415,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite uint256 const sellOffer0 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID0, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const sellOffer1 = keylet::nftoffer(minter, env.seq(minter)).key; env(token::createOffer(minter, nftokenID1, drops(1)), - token::expiration(expiration), - txflags(tfSellNFToken)); + token::Expiration(expiration), + Txflags(kTF_SELL_NF_TOKEN)); uint256 const buyOffer0 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID0, drops(1)), - token::expiration(expiration), - token::owner(minter)); + token::Expiration(expiration), + token::Owner(minter)); uint256 const buyOffer1 = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftokenID1, drops(1)), - token::expiration(expiration), - token::owner(minter)); + token::Expiration(expiration), + token::Owner(minter)); env.close(); BEAST_EXPECT(lastClose(env) < expiration); @@ -3448,7 +3450,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, minter) == 2); BEAST_EXPECT(ownerCount(env, buyer) == 2); - env(token::brokerOffers(issuer, buyOffer1, sellOffer1), ter(tecEXPIRED)); + env(token::brokerOffers(issuer, buyOffer1, sellOffer1), Ter(TecExpired)); env.close(); // The expired offers are still in the ledger. @@ -3469,9 +3471,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Transfer nftokenID0 back to minter so we start the next test in // a simple place. uint256 const offerSellBack = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftokenID0, XRP(0)), - txflags(tfSellNFToken), - token::destination(minter)); + env(token::createOffer(buyer, nftokenID0, kXRP(0)), + Txflags(kTF_SELL_NF_TOKEN), + token::Destination(minter)); env.close(); env(token::acceptSellOffer(minter, offerSellBack)); env.close(); @@ -3494,28 +3496,28 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice("alice"); Account const becky("becky"); Account const minter("minter"); - env.fund(XRP(50000), alice, becky, minter); + env.fund(kXRP(50000), alice, becky, minter); env.close(); // alice has a minter to see if minters have offer canceling permission. env(token::setMinter(alice, minter)); env.close(); - uint256 const nftokenID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(alice, 0), txflags(tfTransferable)); + uint256 const nftokenID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(alice, 0), Txflags(kTF_TRANSFERABLE)); env.close(); // Anyone can cancel an expired offer. uint256 const expiredOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftokenID, XRP(1000)), - txflags(tfSellNFToken), - token::expiration(lastClose(env) + 13)); + env(token::createOffer(alice, nftokenID, kXRP(1000)), + Txflags(kTF_SELL_NF_TOKEN), + token::Expiration(lastClose(env) + 13)); env.close(); // The offer has not expired yet, so becky can't cancel it now. BEAST_EXPECT(ownerCount(env, alice) == 2); - env(token::cancelOffer(becky, {expiredOfferIndex}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(becky, {expiredOfferIndex}), Ter(TecNoPermission)); env.close(); // Close a couple of ledgers and advance the time. Then becky @@ -3530,14 +3532,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // should be cancellable by the creator and the destination. uint256 const dest1OfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftokenID, XRP(1000)), - token::destination(becky), - txflags(tfSellNFToken)); + env(token::createOffer(alice, nftokenID, kXRP(1000)), + token::Destination(becky), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); // Minter can't cancel that offer, but becky (the destination) can. - env(token::cancelOffer(minter, {dest1OfferIndex}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(minter, {dest1OfferIndex}), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); @@ -3548,9 +3550,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice can cancel her own offer, even if becky is the destination. uint256 const dest2OfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftokenID, XRP(1000)), - token::destination(becky), - txflags(tfSellNFToken)); + env(token::createOffer(alice, nftokenID, kXRP(1000)), + token::Destination(becky), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 2); @@ -3561,19 +3563,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // The issuer has no special permissions regarding offer cancellation. // Minter creates a token with alice as issuer. alice cannot cancel // minter's offer. - uint256 const mintersNFTokenID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(minter, 0), token::issuer(alice), txflags(tfTransferable)); + uint256 const mintersNFTokenID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(minter, 0), token::Issuer(alice), Txflags(kTF_TRANSFERABLE)); env.close(); uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, mintersNFTokenID, XRP(1000)), txflags(tfSellNFToken)); + env(token::createOffer(minter, mintersNFTokenID, kXRP(1000)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 2); // Nobody other than minter should be able to cancel minter's offer. - env(token::cancelOffer(alice, {minterOfferIndex}), ter(tecNO_PERMISSION)); - env(token::cancelOffer(becky, {minterOfferIndex}), ter(tecNO_PERMISSION)); + env(token::cancelOffer(alice, {minterOfferIndex}), Ter(TecNoPermission)); + env(token::cancelOffer(becky, {minterOfferIndex}), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 2); @@ -3606,27 +3608,27 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // I can't think of any way to increase the metadata beyond this, // but I'm open to ideas. Account const alice("alice"); - env.fund(XRP(1000), alice); + env.fund(kXRP(1000), alice); env.close(); - std::string const uri(maxTokenURILength, '?'); + std::string const uri(kMAX_TOKEN_URI_LENGTH, '?'); std::vector offerIndexes; - offerIndexes.reserve(maxTokenOfferCancelCount + 1); - for (uint32_t i = 0; i < maxTokenOfferCancelCount + 1; ++i) + offerIndexes.reserve(kMAX_TOKEN_OFFER_CANCEL_COUNT + 1); + for (uint32_t i = 0; i < kMAX_TOKEN_OFFER_CANCEL_COUNT + 1; ++i) { Account const nftAcct(std::string("nftAcct") + std::to_string(i)); Account const offerAcct(std::string("offerAcct") + std::to_string(i)); - env.fund(XRP(1000), nftAcct, offerAcct); + env.fund(kXRP(1000), nftAcct, offerAcct); env.close(); - uint256 const nftokenID = token::getNextID(env, nftAcct, 0, tfTransferable); - env(token::mint(nftAcct, 0), token::uri(uri), txflags(tfTransferable)); + uint256 const nftokenID = token::getNextID(env, nftAcct, 0, kTF_TRANSFERABLE); + env(token::mint(nftAcct, 0), token::Uri(uri), Txflags(kTF_TRANSFERABLE)); env.close(); offerIndexes.push_back(keylet::nftoffer(offerAcct, env.seq(offerAcct)).key); env(token::createOffer(offerAcct, nftokenID, drops(1)), - token::owner(nftAcct), - token::expiration(lastClose(env) + 5)); + token::Owner(nftAcct), + token::Expiration(lastClose(env) + 5)); env.close(); } @@ -3641,7 +3643,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice attempts to cancel all of the expired offers. There is one // too many so the request fails. - env(token::cancelOffer(alice, offerIndexes), ter(temMALFORMED)); + env(token::cancelOffer(alice, offerIndexes), Ter(TemMalformed)); env.close(); // However alice can cancel just one of the offers. @@ -3654,12 +3656,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // But alice adds a sell offer to the list... { - uint256 const nftokenID = token::getNextID(env, alice, 0, tfTransferable); - env(token::mint(alice, 0), token::uri(uri), txflags(tfTransferable)); + uint256 const nftokenID = token::getNextID(env, alice, 0, kTF_TRANSFERABLE); + env(token::mint(alice, 0), token::Uri(uri), Txflags(kTF_TRANSFERABLE)); env.close(); offerIndexes.push_back(keylet::nftoffer(alice, env.seq(alice)).key); - env(token::createOffer(alice, nftokenID, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftokenID, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // alice's owner count should now to 2 for the nft and the offer. @@ -3667,7 +3669,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Because alice added the sell offer there are still too many // offers in the list to cancel. - env(token::cancelOffer(alice, offerIndexes), ter(temMALFORMED)); + env(token::cancelOffer(alice, offerIndexes), Ter(TemMalformed)); env.close(); // alice burns her nft which removes the nft and the offer. @@ -3717,7 +3719,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const gw{"gw"}; IOU const gwXAU(gw["XAU"]); - env.fund(XRP(1000), issuer, minter, buyer, broker, gw); + env.fund(kXRP(1000), issuer, minter, buyer, broker, gw); env.close(); env(trust(issuer, gwXAU(2000))); @@ -3749,11 +3751,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Lambda that mints an NFT and returns the nftID. auto mintNFT = [&env, &issuer, &minter](std::uint16_t xferFee = 0) { - uint256 const nftID = token::getNextID(env, issuer, 0, tfTransferable, xferFee); + uint256 const nftID = token::getNextID(env, issuer, 0, kTF_TRANSFERABLE, xferFee); env(token::mint(minter, 0), - token::issuer(issuer), - token::xferFee(xferFee), - txflags(tfTransferable)); + token::Issuer(issuer), + token::XferFee(xferFee), + Txflags(kTF_TRANSFERABLE)); env.close(); return nftID; }; @@ -3770,13 +3772,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates their offer. Note: a buy offer can never // offer zero. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, XRP(1)), token::owner(minter)); + env(token::createOffer(buyer, nftID, kXRP(1)), token::Owner(minter)); env.close(); auto const minterBalance = env.balance(minter); @@ -3790,8 +3792,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Note that minter's XRP balance goes up even though they // requested XRP(0). - BEAST_EXPECT(env.balance(minter) == minterBalance + XRP(1)); - BEAST_EXPECT(env.balance(buyer) == buyerBalance - XRP(1)); + BEAST_EXPECT(env.balance(minter) == minterBalance + kXRP(1)); + BEAST_EXPECT(env.balance(buyer) == buyerBalance - kXRP(1)); BEAST_EXPECT(env.balance(broker) == brokerBalance - baseFee); BEAST_EXPECT(env.balance(issuer) == issuerBalance); @@ -3812,19 +3814,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates their offer. Note: a buy offer can never // offer zero. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, XRP(1)), token::owner(minter)); + env(token::createOffer(buyer, nftID, kXRP(1)), token::Owner(minter)); env.close(); // Broker attempts to charge a 1.1 XRP brokerFee and fails. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(XRP(1.1)), - ter(tecINSUFFICIENT_PAYMENT)); + token::BrokerFee(kXRP(1.1)), + Ter(TecInsufficientPayment)); env.close(); auto const minterBalance = env.balance(minter); @@ -3834,14 +3836,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Broker charges a 0.5 XRP brokerFee. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(XRP(0.5))); + token::BrokerFee(kXRP(0.5))); env.close(); // Note that minter's XRP balance goes up even though they // requested XRP(0). - BEAST_EXPECT(env.balance(minter) == minterBalance + XRP(0.5)); - BEAST_EXPECT(env.balance(buyer) == buyerBalance - XRP(1)); - BEAST_EXPECT(env.balance(broker) == brokerBalance + XRP(0.5) - baseFee); + BEAST_EXPECT(env.balance(minter) == minterBalance + kXRP(0.5)); + BEAST_EXPECT(env.balance(buyer) == buyerBalance - kXRP(1)); + BEAST_EXPECT(env.balance(broker) == brokerBalance + kXRP(0.5) - baseFee); BEAST_EXPECT(env.balance(issuer) == issuerBalance); // Burn the NFT so the next test starts with a clean state. @@ -3857,17 +3859,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { checkOwnerCountIsOne({issuer, minter, buyer, broker}, __LINE__); - uint256 const nftID = mintNFT(maxTransferFee); + uint256 const nftID = mintNFT(kMAX_TRANSFER_FEE); // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates their offer. Note: a buy offer can never // offer zero. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, XRP(1)), token::owner(minter)); + env(token::createOffer(buyer, nftID, kXRP(1)), token::Owner(minter)); env.close(); auto const minterBalance = env.balance(minter); @@ -3881,10 +3883,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Note that minter's XRP balance goes up even though they // requested XRP(0). - BEAST_EXPECT(env.balance(minter) == minterBalance + XRP(0.5)); - BEAST_EXPECT(env.balance(buyer) == buyerBalance - XRP(1)); + BEAST_EXPECT(env.balance(minter) == minterBalance + kXRP(0.5)); + BEAST_EXPECT(env.balance(buyer) == buyerBalance - kXRP(1)); BEAST_EXPECT(env.balance(broker) == brokerBalance - baseFee); - BEAST_EXPECT(env.balance(issuer) == issuerBalance + XRP(0.5)); + BEAST_EXPECT(env.balance(issuer) == issuerBalance + kXRP(0.5)); // Burn the NFT so the next test starts with a clean state. env(token::burn(buyer, nftID)); @@ -3899,17 +3901,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { checkOwnerCountIsOne({issuer, minter, buyer, broker}, __LINE__); - uint256 const nftID = mintNFT(maxTransferFee); + uint256 const nftID = mintNFT(kMAX_TRANSFER_FEE); // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates their offer. Note: a buy offer can never // offer zero. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, XRP(1)), token::owner(minter)); + env(token::createOffer(buyer, nftID, kXRP(1)), token::Owner(minter)); env.close(); auto const minterBalance = env.balance(minter); @@ -3919,16 +3921,16 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Broker charges a 0.75 XRP brokerFee. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(XRP(0.75))); + token::BrokerFee(kXRP(0.75))); env.close(); // Note that, with a 50% transfer fee, issuer gets 1/2 of what's // left _after_ broker takes their fee. minter gets the // remainder after both broker and minter take their cuts - BEAST_EXPECT(env.balance(minter) == minterBalance + XRP(0.125)); - BEAST_EXPECT(env.balance(buyer) == buyerBalance - XRP(1)); - BEAST_EXPECT(env.balance(broker) == brokerBalance + XRP(0.75) - baseFee); - BEAST_EXPECT(env.balance(issuer) == issuerBalance + XRP(0.125)); + BEAST_EXPECT(env.balance(minter) == minterBalance + kXRP(0.125)); + BEAST_EXPECT(env.balance(buyer) == buyerBalance - kXRP(1)); + BEAST_EXPECT(env.balance(broker) == brokerBalance + kXRP(0.75) - baseFee); + BEAST_EXPECT(env.balance(issuer) == issuerBalance + kXRP(0.125)); // Burn the NFT so the next test starts with a clean state. env(token::burn(buyer, nftID)); @@ -3976,19 +3978,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(1000)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(1000)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); { // buyer creates an offer for more XAU than they currently // own. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1001)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1001)), token::Owner(minter)); env.close(); // broker attempts to broker the offers but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - ter(tecINSUFFICIENT_FUNDS)); + Ter(TecInsufficientFunds)); env.close(); // Cancel buyer's bad offer so the next test starts in a @@ -4000,12 +4002,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // buyer creates an offer for less that what minter is // asking. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(999)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(999)), token::Owner(minter)); env.close(); // broker attempts to broker the offers but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - ter(tecINSUFFICIENT_PAYMENT)); + Ter(TecInsufficientPayment)); env.close(); // Cancel buyer's bad offer so the next test starts in a @@ -4016,13 +4018,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // buyer creates a large enough offer. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1000)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1000)), token::Owner(minter)); env.close(); // Broker attempts to charge a brokerFee but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(gwXAU(0.1)), - ter(tecINSUFFICIENT_PAYMENT)); + token::BrokerFee(gwXAU(0.1)), + Ter(TecInsufficientPayment)); env.close(); // broker charges no brokerFee and succeeds. @@ -4049,22 +4051,22 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkOwnerCountIsOne({issuer, minter, buyer, broker}, __LINE__); setXAUBalance({issuer, minter, buyer, broker}, 1000, __LINE__); - uint256 const nftID = mintNFT(maxTransferFee); + uint256 const nftID = mintNFT(kMAX_TRANSFER_FEE); // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(900)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(900)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); { // buyer creates an offer for more XAU than they currently // own. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1001)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1001)), token::Owner(minter)); env.close(); // broker attempts to broker the offers but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - ter(tecINSUFFICIENT_FUNDS)); + Ter(TecInsufficientFunds)); env.close(); // Cancel buyer's bad offer so the next test starts in a @@ -4076,12 +4078,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // buyer creates an offer for less that what minter is // asking. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(899)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(899)), token::Owner(minter)); env.close(); // broker attempts to broker the offers but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - ter(tecINSUFFICIENT_PAYMENT)); + Ter(TecInsufficientPayment)); env.close(); // Cancel buyer's bad offer so the next test starts in a @@ -4091,20 +4093,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // buyer creates a large enough offer. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1000)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1000)), token::Owner(minter)); env.close(); // Broker attempts to charge a brokerFee larger than the // difference between the two offers but cannot. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(gwXAU(101)), - ter(tecINSUFFICIENT_PAYMENT)); + token::BrokerFee(gwXAU(101)), + Ter(TecInsufficientPayment)); env.close(); // broker charges the full difference between the two offers and // succeeds. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(gwXAU(100))); + token::BrokerFee(gwXAU(100))); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); @@ -4127,23 +4129,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkOwnerCountIsOne({issuer, minter, buyer, broker}, __LINE__); setXAUBalance({issuer, minter, buyer, broker}, 1000, __LINE__); - uint256 const nftID = mintNFT(maxTransferFee / 2); // 25% + uint256 const nftID = mintNFT(kMAX_TRANSFER_FEE / 2); // 25% // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(900)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(900)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates a large enough offer. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1000)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1000)), token::Owner(minter)); env.close(); // broker charges half difference between the two offers and // succeeds. 25% of the remaining difference goes to issuer. // The rest goes to minter. env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(gwXAU(50))); + token::BrokerFee(gwXAU(50))); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); @@ -4164,20 +4166,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkOwnerCountIsOne({issuer, minter, buyer, broker}, __LINE__); setXAUBalance({issuer, minter, buyer}, 1000, __LINE__); setXAUBalance({broker}, 500, __LINE__); - uint256 const nftID = mintNFT(maxTransferFee / 2); // 25% + uint256 const nftID = mintNFT(kMAX_TRANSFER_FEE / 2); // 25% // minter creates their offer. uint256 const minterOfferIndex = keylet::nftoffer(minter, env.seq(minter)).key; - env(token::createOffer(minter, nftID, gwXAU(900)), txflags(tfSellNFToken)); + env(token::createOffer(minter, nftID, gwXAU(900)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // buyer creates a large enough offer. uint256 const buyOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID, gwXAU(1000)), token::owner(minter)); + env(token::createOffer(buyer, nftID, gwXAU(1000)), token::Owner(minter)); env.close(); env(token::brokerOffers(broker, buyOfferIndex, minterOfferIndex), - token::brokerFee(gwXAU(50))); + token::BrokerFee(gwXAU(50))); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); BEAST_EXPECT(ownerCount(env, minter) == 1); @@ -4208,12 +4210,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const issuer{"issuer"}; Account const buyer1{"buyer1"}; Account const buyer2{"buyer2"}; - env.fund(XRP(10000), issuer, buyer1, buyer2); + env.fund(kXRP(10000), issuer, buyer1, buyer2); env.close(); // issuer creates an NFT. - uint256 const nftId{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(issuer, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); // Prove that issuer now owns nftId. @@ -4223,9 +4225,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Both buyer1 and buyer2 create buy offers for nftId. uint256 const buyer1OfferIndex = keylet::nftoffer(buyer1, env.seq(buyer1)).key; - env(token::createOffer(buyer1, nftId, XRP(100)), token::owner(issuer)); + env(token::createOffer(buyer1, nftId, kXRP(100)), token::Owner(issuer)); uint256 const buyer2OfferIndex = keylet::nftoffer(buyer2, env.seq(buyer2)).key; - env(token::createOffer(buyer2, nftId, XRP(100)), token::owner(issuer)); + env(token::createOffer(buyer2, nftId, kXRP(100)), token::Owner(issuer)); env.close(); // Lambda that counts the number of buy offers for a given NFT. @@ -4233,11 +4235,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // We know that in this case not very many offers will be // returned, so we skip the marker stuff. Json::Value params; - params[jss::nft_id] = to_string(nftId); + params[jss::kNFT_ID] = to_string(nftId); Json::Value buyOffers = env.rpc("json", "nft_buy_offers", to_string(params)); - if (buyOffers.isMember(jss::result) && buyOffers[jss::result].isMember(jss::offers)) - return buyOffers[jss::result][jss::offers].size(); + if (buyOffers.isMember(jss::kRESULT) && buyOffers[jss::kRESULT].isMember(jss::kOFFERS)) + return buyOffers[jss::kRESULT][jss::kOFFERS].size(); return 0; }; @@ -4284,7 +4286,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const issuer{"issuer"}; Account const buyer{"buyer"}; - env.fund(XRP(10000), issuer, buyer); + env.fund(kXRP(10000), issuer, buyer); env.close(); // issuer and buyer grab enough tickets for all of the following @@ -4304,8 +4306,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // NFTokenMint BEAST_EXPECT(ownerCount(env, issuer) == 10); - uint256 const nftId{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(issuer, 0u), txflags(tfTransferable), ticket::use(issuerTicketSeq++)); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 0u), Txflags(kTF_TRANSFERABLE), ticket::Use(issuerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 10); BEAST_EXPECT(ticketCount(env, issuer) == 9); @@ -4313,37 +4315,37 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // NFTokenCreateOffer BEAST_EXPECT(ownerCount(env, buyer) == 10); uint256 const offerIndex0 = keylet::nftoffer(buyer, buyerTicketSeq).key; - env(token::createOffer(buyer, nftId, XRP(1)), - token::owner(issuer), - ticket::use(buyerTicketSeq++)); + env(token::createOffer(buyer, nftId, kXRP(1)), + token::Owner(issuer), + ticket::Use(buyerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 10); BEAST_EXPECT(ticketCount(env, buyer) == 9); // NFTokenCancelOffer - env(token::cancelOffer(buyer, {offerIndex0}), ticket::use(buyerTicketSeq++)); + env(token::cancelOffer(buyer, {offerIndex0}), ticket::Use(buyerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 8); BEAST_EXPECT(ticketCount(env, buyer) == 8); // NFTokenCreateOffer. buyer tries again. uint256 const offerIndex1 = keylet::nftoffer(buyer, buyerTicketSeq).key; - env(token::createOffer(buyer, nftId, XRP(2)), - token::owner(issuer), - ticket::use(buyerTicketSeq++)); + env(token::createOffer(buyer, nftId, kXRP(2)), + token::Owner(issuer), + ticket::Use(buyerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 8); BEAST_EXPECT(ticketCount(env, buyer) == 7); // NFTokenAcceptOffer. issuer accepts buyer's offer. - env(token::acceptBuyOffer(issuer, offerIndex1), ticket::use(issuerTicketSeq++)); + env(token::acceptBuyOffer(issuer, offerIndex1), ticket::Use(issuerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 8); BEAST_EXPECT(ownerCount(env, buyer) == 8); BEAST_EXPECT(ticketCount(env, issuer) == 8); // NFTokenBurn. buyer burns the token they just bought. - env(token::burn(buyer, nftId), ticket::use(buyerTicketSeq++)); + env(token::burn(buyer, nftId), ticket::Use(buyerTicketSeq++)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 8); BEAST_EXPECT(ownerCount(env, buyer) == 6); @@ -4374,7 +4376,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const carla{"carla"}; Account const daria{"daria"}; - env.fund(XRP(10000), issuer, minter, becky, carla, daria); + env.fund(kXRP(10000), issuer, minter, becky, carla, daria); env.close(); // Allow enough ledgers to pass so any of these accounts can be deleted. @@ -4384,15 +4386,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(token::setMinter(issuer, minter)); env.close(); - uint256 const nftId{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(minter, 0u), token::issuer(issuer), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(minter, 0u), token::Issuer(issuer), Txflags(kTF_TRANSFERABLE)); env.close(); // At the moment issuer and minter cannot delete themselves. // o issuer has an issued NFT in the ledger. // o minter owns an NFT. - env(acctdelete(issuer, daria), fee(XRP(50)), ter(tecHAS_OBLIGATIONS)); - env(acctdelete(minter, daria), fee(XRP(50)), ter(tecHAS_OBLIGATIONS)); + env(acctdelete(issuer, daria), Fee(kXRP(50)), Ter(TecHasObligations)); + env(acctdelete(minter, daria), Fee(kXRP(50)), Ter(TecHasObligations)); env.close(); // Let enough ledgers pass so the account delete transactions are @@ -4401,16 +4403,16 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // becky and carla create offers for minter's NFT. - env(token::createOffer(becky, nftId, XRP(2)), token::owner(minter)); + env(token::createOffer(becky, nftId, kXRP(2)), token::Owner(minter)); env.close(); uint256 const carlaOfferIndex = keylet::nftoffer(carla, env.seq(carla)).key; - env(token::createOffer(carla, nftId, XRP(3)), token::owner(minter)); + env(token::createOffer(carla, nftId, kXRP(3)), token::Owner(minter)); env.close(); // It should be possible for becky to delete herself, even though // becky has an active NFT offer. - env(acctdelete(becky, daria), fee(XRP(50))); + env(acctdelete(becky, daria), Fee(kXRP(50))); env.close(); // minter accepts carla's offer. @@ -4419,14 +4421,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Now it should be possible for minter to delete themselves since // they no longer own an NFT. - env(acctdelete(minter, daria), fee(XRP(50))); + env(acctdelete(minter, daria), Fee(kXRP(50))); env.close(); // 1. issuer cannot delete themselves because they issued an NFT that // is still in the ledger. // 2. carla owns an NFT, so she cannot delete herself. - env(acctdelete(issuer, daria), fee(XRP(50)), ter(tecHAS_OBLIGATIONS)); - env(acctdelete(carla, daria), fee(XRP(50)), ter(tecHAS_OBLIGATIONS)); + env(acctdelete(issuer, daria), Fee(kXRP(50)), Ter(TecHasObligations)); + env(acctdelete(carla, daria), Fee(kXRP(50)), Ter(TecHasObligations)); env.close(); // Let enough ledgers pass so the account delete transactions are @@ -4439,8 +4441,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(token::burn(carla, nftId)); env.close(); - env(acctdelete(issuer, daria), fee(XRP(50))); - env(acctdelete(carla, daria), fee(XRP(50))); + env(acctdelete(issuer, daria), Fee(kXRP(50))); + env(acctdelete(carla, daria), Fee(kXRP(50))); env.close(); } @@ -4464,12 +4466,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const buyer{"buyer"}; // A lot of offers requires a lot for reserve. - env.fund(XRP(1000000), issuer, buyer); + env.fund(kXRP(1000000), issuer, buyer); env.close(); // Create an NFT that we'll make offers for. - uint256 const nftID{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(issuer, 0), txflags(tfTransferable)); + uint256 const nftID{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 0), Txflags(kTF_TRANSFERABLE)); env.close(); // A lambda that validates nft_XXX_offers query responses. @@ -4479,7 +4481,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite int expectMarkerCount, int line) { int markerCount = 0; - Json::Value allOffers(Json::arrayValue); + Json::Value allOffers(Json::ArrayValue); std::string marker; // The do/while collects results until no marker is returned. @@ -4487,10 +4489,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { Json::Value nftOffers = [&env, &nftID, &request, &marker]() { Json::Value params; - params[jss::nft_id] = to_string(nftID); + params[jss::kNFT_ID] = to_string(nftID); if (!marker.empty()) - params[jss::marker] = marker; + params[jss::kMARKER] = marker; return env.rpc("json", request, to_string(params)); }(); @@ -4498,16 +4500,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite if (expectCount == 0) { if (expect( - nftOffers.isMember(jss::result), "expected \"result\"", __FILE__, line)) + nftOffers.isMember(jss::kRESULT), + "expected \"result\"", + __FILE__, + line)) { if (expect( - nftOffers[jss::result].isMember(jss::error), + nftOffers[jss::kRESULT].isMember(jss::kERROR), "expected \"error\"", __FILE__, line)) { expect( - nftOffers[jss::result][jss::error].asString() == "objectNotFound", + nftOffers[jss::kRESULT][jss::kERROR].asString() == "objectNotFound", "expected \"objectNotFound\"", __FILE__, line); @@ -4517,19 +4522,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } marker.clear(); - if (expect(nftOffers.isMember(jss::result), "expected \"result\"", __FILE__, line)) + if (expect(nftOffers.isMember(jss::kRESULT), "expected \"result\"", __FILE__, line)) { - Json::Value& result = nftOffers[jss::result]; + Json::Value& result = nftOffers[jss::kRESULT]; - if (result.isMember(jss::marker)) + if (result.isMember(jss::kMARKER)) { ++markerCount; - marker = result[jss::marker].asString(); + marker = result[jss::kMARKER].asString(); } - if (expect(result.isMember(jss::offers), "expected \"offers\"", __FILE__, line)) + if (expect( + result.isMember(jss::kOFFERS), "expected \"offers\"", __FILE__, line)) { - Json::Value& someOffers = result[jss::offers]; + Json::Value& someOffers = result[jss::kOFFERS]; for (std::size_t i = 0; i < someOffers.size(); ++i) allOffers.append(someOffers[i]); } @@ -4547,18 +4553,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // The flags on all found offers should be the same. if (!globalFlags) - globalFlags = offer[jss::flags].asInt(); + globalFlags = offer[jss::kFLAGS].asInt(); expect( - *globalFlags == offer[jss::flags].asInt(), + *globalFlags == offer[jss::kFLAGS].asInt(), "Inconsistent flags returned", __FILE__, line); // The test conditions should produce unique indexes and // amounts for all offers. - offerIndexes.insert(offer[jss::nft_offer_index].asString()); - amounts.insert(offer[jss::amount].asString()); + offerIndexes.insert(offer[jss::kNFT_OFFER_INDEX].asString()); + amounts.insert(offer[jss::kAMOUNT].asString()); } expect( @@ -4570,14 +4576,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkOffers("nft_sell_offers", 0, 0, __LINE__); // A lambda that generates sell offers. - STAmount sellPrice = XRP(0); + STAmount sellPrice = kXRP(0); auto makeSellOffers = [&env, &issuer, &nftID, &sellPrice](STAmount const& limit) { // Save a little test time by not closing too often. int offerCount = 0; while (sellPrice < limit) { - sellPrice += XRP(1); - env(token::createOffer(issuer, nftID, sellPrice), txflags(tfSellNFToken)); + sellPrice += kXRP(1); + env(token::createOffer(issuer, nftID, sellPrice), Txflags(kTF_SELL_NF_TOKEN)); if (++offerCount % 10 == 0) env.close(); } @@ -4585,37 +4591,37 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite }; // There is one sell offer. - makeSellOffers(XRP(1)); + makeSellOffers(kXRP(1)); checkOffers("nft_sell_offers", 1, 0, __LINE__); // There are 250 sell offers. - makeSellOffers(XRP(250)); + makeSellOffers(kXRP(250)); checkOffers("nft_sell_offers", 250, 0, __LINE__); // There are 251 sell offers. - makeSellOffers(XRP(251)); + makeSellOffers(kXRP(251)); checkOffers("nft_sell_offers", 251, 1, __LINE__); // There are 500 sell offers. - makeSellOffers(XRP(500)); + makeSellOffers(kXRP(500)); checkOffers("nft_sell_offers", 500, 1, __LINE__); // There are 501 sell offers. - makeSellOffers(XRP(501)); + makeSellOffers(kXRP(501)); checkOffers("nft_sell_offers", 501, 2, __LINE__); // There are no buy offers. checkOffers("nft_buy_offers", 0, 0, __LINE__); // A lambda that generates buy offers. - STAmount buyPrice = XRP(0); + STAmount buyPrice = kXRP(0); auto makeBuyOffers = [&env, &buyer, &issuer, &nftID, &buyPrice](STAmount const& limit) { // Save a little test time by not closing too often. int offerCount = 0; while (buyPrice < limit) { - buyPrice += XRP(1); - env(token::createOffer(buyer, nftID, buyPrice), token::owner(issuer)); + buyPrice += kXRP(1); + env(token::createOffer(buyer, nftID, buyPrice), token::Owner(issuer)); if (++offerCount % 10 == 0) env.close(); } @@ -4623,23 +4629,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite }; // There is one buy offer; - makeBuyOffers(XRP(1)); + makeBuyOffers(kXRP(1)); checkOffers("nft_buy_offers", 1, 0, __LINE__); // There are 250 buy offers. - makeBuyOffers(XRP(250)); + makeBuyOffers(kXRP(250)); checkOffers("nft_buy_offers", 250, 0, __LINE__); // There are 251 buy offers. - makeBuyOffers(XRP(251)); + makeBuyOffers(kXRP(251)); checkOffers("nft_buy_offers", 251, 1, __LINE__); // There are 500 buy offers. - makeBuyOffers(XRP(500)); + makeBuyOffers(kXRP(500)); checkOffers("nft_buy_offers", 500, 1, __LINE__); // There are 501 buy offers. - makeBuyOffers(XRP(501)); + makeBuyOffers(kXRP(501)); checkOffers("nft_buy_offers", 501, 2, __LINE__); } @@ -4658,7 +4664,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { Env env{*this, features}; - env.fund(XRP(1000000), issuer, buyer, gw); + env.fund(kXRP(1000000), issuer, buyer, gw); env.close(); env(trust(issuer, gwXAU(2000))); @@ -4670,67 +4676,67 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // Create an NFT that we'll make XRP offers for. - uint256 const nftID0{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(issuer, 0), txflags(tfTransferable)); + uint256 const nftID0{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 0), Txflags(kTF_TRANSFERABLE)); env.close(); // Create an NFT that we'll make IOU offers for. - uint256 const nftID1{token::getNextID(env, issuer, 1u, tfTransferable)}; - env(token::mint(issuer, 1), txflags(tfTransferable)); + uint256 const nftID1{token::getNextID(env, issuer, 1u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 1), Txflags(kTF_TRANSFERABLE)); env.close(); - TER const offerCreateTER = temBAD_AMOUNT; + TER const offerCreateTER = TemBadAmount; // Make offers with negative amounts for the NFTs uint256 const sellNegXrpOfferIndex = keylet::nftoffer(issuer, env.seq(issuer)).key; - env(token::createOffer(issuer, nftID0, XRP(-2)), - txflags(tfSellNFToken), - ter(offerCreateTER)); + env(token::createOffer(issuer, nftID0, kXRP(-2)), + Txflags(kTF_SELL_NF_TOKEN), + Ter(offerCreateTER)); env.close(); uint256 const sellNegIouOfferIndex = keylet::nftoffer(issuer, env.seq(issuer)).key; env(token::createOffer(issuer, nftID1, gwXAU(-2)), - txflags(tfSellNFToken), - ter(offerCreateTER)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(offerCreateTER)); env.close(); uint256 const buyNegXrpOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; - env(token::createOffer(buyer, nftID0, XRP(-1)), - token::owner(issuer), - ter(offerCreateTER)); + env(token::createOffer(buyer, nftID0, kXRP(-1)), + token::Owner(issuer), + Ter(offerCreateTER)); env.close(); uint256 const buyNegIouOfferIndex = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::createOffer(buyer, nftID1, gwXAU(-1)), - token::owner(issuer), - ter(offerCreateTER)); + token::Owner(issuer), + Ter(offerCreateTER)); env.close(); { // Now try to accept the offers. - TER const offerAcceptTER = tecOBJECT_NOT_FOUND; + TER const offerAcceptTER = TecObjectNotFound; // Sell offers. - env(token::acceptSellOffer(buyer, sellNegXrpOfferIndex), ter(offerAcceptTER)); + env(token::acceptSellOffer(buyer, sellNegXrpOfferIndex), Ter(offerAcceptTER)); env.close(); - env(token::acceptSellOffer(buyer, sellNegIouOfferIndex), ter(offerAcceptTER)); + env(token::acceptSellOffer(buyer, sellNegIouOfferIndex), Ter(offerAcceptTER)); env.close(); // Buy offers. - env(token::acceptBuyOffer(issuer, buyNegXrpOfferIndex), ter(offerAcceptTER)); + env(token::acceptBuyOffer(issuer, buyNegXrpOfferIndex), Ter(offerAcceptTER)); env.close(); - env(token::acceptBuyOffer(issuer, buyNegIouOfferIndex), ter(offerAcceptTER)); + env(token::acceptBuyOffer(issuer, buyNegIouOfferIndex), Ter(offerAcceptTER)); env.close(); } { - TER const offerAcceptTER = tecOBJECT_NOT_FOUND; + TER const offerAcceptTER = TecObjectNotFound; // Brokered offers. env(token::brokerOffers(gw, buyNegXrpOfferIndex, sellNegXrpOfferIndex), - ter(offerAcceptTER)); + Ter(offerAcceptTER)); env.close(); env(token::brokerOffers(gw, buyNegIouOfferIndex, sellNegIouOfferIndex), - ter(offerAcceptTER)); + Ter(offerAcceptTER)); env.close(); } } @@ -4739,19 +4745,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Test buy offers with a destination. Env env{*this, features}; - env.fund(XRP(1000000), issuer, buyer); + env.fund(kXRP(1000000), issuer, buyer); // Create an NFT that we'll make offers for. - uint256 const nftID{token::getNextID(env, issuer, 0u, tfTransferable)}; - env(token::mint(issuer, 0), txflags(tfTransferable)); + uint256 const nftID{token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE)}; + env(token::mint(issuer, 0), Txflags(kTF_TRANSFERABLE)); env.close(); - TER const offerCreateTER = tesSUCCESS; + TER const offerCreateTER = TesSuccess; env(token::createOffer(buyer, nftID, drops(1)), - token::owner(issuer), - token::destination(issuer), - ter(offerCreateTER)); + token::Owner(issuer), + token::Destination(issuer), + Ter(offerCreateTER)); env.close(); } } @@ -4774,7 +4780,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite IOU const gwXAU(gw["XAU"]); IOU const gwXPB(gw["XPB"]); - env.fund(XRP(1000), gw, minter, secondarySeller, buyer, broker); + env.fund(kXRP(1000), gw, minter, secondarySeller, buyer, broker); env.close(); env(trust(minter, gwXAU(2000))); @@ -4851,8 +4857,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite }; auto mintNFT = [&env](Account const& minter, int transferFee = 0) { - uint256 const nftID = token::getNextID(env, minter, 0, tfTransferable, transferFee); - env(token::mint(minter), token::xferFee(transferFee), txflags(tfTransferable)); + uint256 const nftID = + token::getNextID(env, minter, 0, kTF_TRANSFERABLE, transferFee); + env(token::mint(minter), token::XferFee(transferFee), Txflags(kTF_TRANSFERABLE)); env.close(); return nftID; }; @@ -4865,8 +4872,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite std::optional const terCode = {}) { uint256 const offerID = keylet::nftoffer(offerer, env.seq(offerer)).key; env(token::createOffer(offerer, nftID, amount), - token::owner(owner), - terCode ? ter(*terCode) : ter(static_cast(tesSUCCESS))); + token::Owner(owner), + terCode ? Ter(*terCode) : Ter(static_cast(TesSuccess))); env.close(); return offerID; }; @@ -4878,8 +4885,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite std::optional const terCode = {}) { uint256 const offerID = keylet::nftoffer(offerer, env.seq(offerer)).key; env(token::createOffer(offerer, nftID, amount), - txflags(tfSellNFToken), - terCode ? ter(*terCode) : ter(static_cast(tesSUCCESS))); + Txflags(kTF_SELL_NF_TOKEN), + terCode ? Ter(*terCode) : Ter(static_cast(TesSuccess))); env.close(); return offerID; }; @@ -4890,8 +4897,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createSellOffer(minter, nftID, gwXAU(1000)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptSellOffer(buyer, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptSellOffer(buyer, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -4902,8 +4909,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createBuyOffer(buyer, minter, nftID, gwXAU(1000)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptBuyOffer(minter, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptBuyOffer(minter, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -4915,8 +4922,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createSellOffer(minter, nftID, gwXAU(995)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptSellOffer(buyer, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptSellOffer(buyer, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -4928,8 +4935,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createBuyOffer(buyer, minter, nftID, gwXAU(995)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptBuyOffer(minter, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptBuyOffer(minter, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -5015,8 +5022,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const nftID = mintNFT(minter); auto const offerID = createSellOffer(minter, nftID, gwXAU(1000)); - TER const sellTER = tesSUCCESS; - env(token::acceptSellOffer(gw, offerID), ter(sellTER)); + TER const sellTER = TesSuccess; + env(token::acceptSellOffer(gw, offerID), Ter(sellTER)); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(1000)); @@ -5028,10 +5035,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); - TER const offerTER = tesSUCCESS; + TER const offerTER = TesSuccess; auto const offerID = createBuyOffer(gw, minter, nftID, gwXAU(1000), {offerTER}); - TER const sellTER = tesSUCCESS; - env(token::acceptBuyOffer(minter, offerID), ter(sellTER)); + TER const sellTER = TesSuccess; + env(token::acceptBuyOffer(minter, offerID), Ter(sellTER)); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(1000)); @@ -5043,8 +5050,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createSellOffer(minter, nftID, gwXAU(5000)); - TER const sellTER = tesSUCCESS; - env(token::acceptSellOffer(gw, offerID), ter(sellTER)); + TER const sellTER = TesSuccess; + env(token::acceptSellOffer(gw, offerID), Ter(sellTER)); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(5000)); @@ -5056,10 +5063,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); - TER const offerTER = tesSUCCESS; + TER const offerTER = TesSuccess; auto const offerID = createBuyOffer(gw, minter, nftID, gwXAU(5000), {offerTER}); - TER const sellTER = tesSUCCESS; - env(token::acceptBuyOffer(minter, offerID), ter(sellTER)); + TER const sellTER = TesSuccess; + env(token::acceptBuyOffer(minter, offerID), Ter(sellTER)); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(5000)); @@ -5100,7 +5107,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const nftID = mintNFT(gw); auto const offerID = createSellOffer(gw, nftID, gwXAU(2000)); env(token::acceptSellOffer(buyer, offerID), - ter(static_cast(tecINSUFFICIENT_FUNDS))); + Ter(static_cast(TecInsufficientFunds))); env.close(); expectInitialState(); } @@ -5112,7 +5119,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const nftID = mintNFT(gw); auto const offerID = createBuyOffer(buyer, gw, nftID, gwXAU(2000)); env(token::acceptBuyOffer(gw, offerID), - ter(static_cast(tecINSUFFICIENT_FUNDS))); + Ter(static_cast(TecInsufficientFunds))); env.close(); expectInitialState(); } @@ -5123,7 +5130,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const nftID = mintNFT(minter); auto const offerID = createSellOffer(minter, nftID, gwXPB(10)); env(token::acceptSellOffer(buyer, offerID), - ter(static_cast(tecINSUFFICIENT_FUNDS))); + Ter(static_cast(TecInsufficientFunds))); env.close(); expectInitialState(); } @@ -5133,9 +5140,9 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite reinitializeTrustLineBalances(); auto const nftID = mintNFT(minter); auto const offerID = createBuyOffer( - buyer, minter, nftID, gwXPB(10), {static_cast(tecUNFUNDED_OFFER)}); + buyer, minter, nftID, gwXPB(10), {static_cast(TecUnfundedOffer)}); env(token::acceptBuyOffer(minter, offerID), - ter(static_cast(tecOBJECT_NOT_FOUND))); + Ter(static_cast(TecObjectNotFound))); env.close(); expectInitialState(); } @@ -5183,14 +5190,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // secondarySeller has to sell it because transfer fees only // happen on secondary sales auto const nftID = mintNFT(minter, 3000); // 3% - auto const primaryOfferID = createSellOffer(minter, nftID, XRP(0)); + auto const primaryOfferID = createSellOffer(minter, nftID, kXRP(0)); env(token::acceptSellOffer(secondarySeller, primaryOfferID)); env.close(); // now we can do a secondary sale auto const offerID = createSellOffer(secondarySeller, nftID, gwXAU(1000)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptSellOffer(buyer, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptSellOffer(buyer, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -5203,14 +5210,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // secondarySeller has to sell it because transfer fees only // happen on secondary sales auto const nftID = mintNFT(minter, 3000); // 3% - auto const primaryOfferID = createSellOffer(minter, nftID, XRP(0)); + auto const primaryOfferID = createSellOffer(minter, nftID, kXRP(0)); env(token::acceptSellOffer(secondarySeller, primaryOfferID)); env.close(); // now we can do a secondary sale auto const offerID = createBuyOffer(buyer, secondarySeller, nftID, gwXAU(1000)); - TER const sellTER = tecINSUFFICIENT_FUNDS; - env(token::acceptBuyOffer(secondarySeller, offerID), ter(sellTER)); + TER const sellTER = TecInsufficientFunds; + env(token::acceptBuyOffer(secondarySeller, offerID), Ter(sellTER)); env.close(); expectInitialState(); @@ -5223,7 +5230,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // secondarySeller has to sell it because transfer fees only // happen on secondary sales auto const nftID = mintNFT(minter, 3000); // 3% - auto const primaryOfferID = createSellOffer(minter, nftID, XRP(0)); + auto const primaryOfferID = createSellOffer(minter, nftID, kXRP(0)); env(token::acceptSellOffer(secondarySeller, primaryOfferID)); env.close(); @@ -5247,7 +5254,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // secondarySeller has to sell it because transfer fees only // happen on secondary sales auto const nftID = mintNFT(minter, 3000); // 3% - auto const primaryOfferID = createSellOffer(minter, nftID, XRP(0)); + auto const primaryOfferID = createSellOffer(minter, nftID, kXRP(0)); env(token::acceptSellOffer(secondarySeller, primaryOfferID)); env.close(); @@ -5287,7 +5294,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const nftID = mintNFT(minter); auto const sellOffer = createSellOffer(minter, nftID, gwXAU(300)); auto const buyOffer = createBuyOffer(buyer, minter, nftID, gwXAU(500)); - env(token::brokerOffers(broker, buyOffer, sellOffer), token::brokerFee(gwXAU(100))); + env(token::brokerOffers(broker, buyOffer, sellOffer), token::BrokerFee(gwXAU(100))); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(400)); @@ -5318,14 +5325,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // secondarySeller has to sell it because transfer fees only // happen on secondary sales auto const nftID = mintNFT(minter, 3000); // 3% - auto const primaryOfferID = createSellOffer(minter, nftID, XRP(0)); + auto const primaryOfferID = createSellOffer(minter, nftID, kXRP(0)); env(token::acceptSellOffer(secondarySeller, primaryOfferID)); env.close(); // now we can do a secondary sale auto const sellOffer = createSellOffer(secondarySeller, nftID, gwXAU(300)); auto const buyOffer = createBuyOffer(buyer, secondarySeller, nftID, gwXAU(500)); - env(token::brokerOffers(broker, buyOffer, sellOffer), token::brokerFee(gwXAU(100))); + env(token::brokerOffers(broker, buyOffer, sellOffer), token::BrokerFee(gwXAU(100))); env.close(); BEAST_EXPECT(env.balance(minter, gwXAU) == gwXAU(12)); @@ -5363,7 +5370,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Env env{*this, features}; auto const baseFee = env.current()->fees().base; - env.fund(XRP(10000), alice, bob, broker); + env.fund(kXRP(10000), alice, bob, broker); env.close(); // For this scenario to occur we need the following steps: @@ -5383,19 +5390,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // 7. Now that bob has both a buy and a sell offer for the same NFT, // a broker can sell the NFT that bob owns to bob and pocket the // difference. - uint256 const nftId{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); // Bob creates a buy offer for 5 XRP. Alice creates a sell offer // for 0 XRP. uint256 const bobBuyOfferIndex = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId, XRP(5)), token::owner(alice)); + env(token::createOffer(bob, nftId, kXRP(5)), token::Owner(alice)); uint256 const aliceSellOfferIndex = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId, XRP(0)), - token::destination(bob), - txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId, kXRP(0)), + token::Destination(bob), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); // bob accepts alice's offer but forgets to remove the old buy offer. @@ -5407,7 +5414,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Bob creates a sell offer for the gift NFT from alice. uint256 const bobSellOfferIndex = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId, XRP(4)), txflags(tfSellNFToken)); + env(token::createOffer(bob, nftId, kXRP(4)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // bob now has a buy offer and a sell offer on the books. A broker @@ -5416,8 +5423,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const bobPriorBalance = env.balance(bob); auto const brokerPriorBalance = env.balance(broker); env(token::brokerOffers(broker, bobBuyOfferIndex, bobSellOfferIndex), - token::brokerFee(XRP(1)), - ter(tecCANT_ACCEPT_OWN_NFTOKEN_OFFER)); + token::BrokerFee(kXRP(1)), + Ter(TecCantAcceptOwnNftokenOffer)); env.close(); // A tec result was returned, so no state should change other @@ -5474,7 +5481,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice("alice"); Account const becky("becky"); - env.fund(XRP(10000), alice, becky); + env.fund(kXRP(10000), alice, becky); env.close(); // alice mint and burn a NFT @@ -5493,7 +5500,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice's account is deleted Keylet const aliceAcctKey{keylet::account(alice.id())}; auto const acctDelFee{drops(env.current()->fees().increment)}; - env(acctdelete(alice, becky), fee(acctDelFee)); + env(acctdelete(alice, becky), Fee(acctDelFee)); env.close(); // alice's account root is gone from the most recently @@ -5502,7 +5509,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(!env.current()->exists(aliceAcctKey)); // Fund alice to re-create her account - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // alice's account now exists and has minted 0 NFTokens @@ -5531,7 +5538,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const becky("becky"); Account const minter{"minter"}; - env.fund(XRP(10000), alice, becky, minter); + env.fund(kXRP(10000), alice, becky, minter); env.close(); // alice sets minter as her authorized minter @@ -5545,7 +5552,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const nftokenID = token::getNextID(env, alice, 0u); nftIDs.push_back(nftokenID); - env(token::mint(minter), token::issuer(alice)); + env(token::mint(minter), token::Issuer(alice)); } env.close(); @@ -5572,7 +5579,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // MintedNFTokens + 256> enabled by this amendment will enforce // alice to wait for more ledgers to close before she can // delete her account, to prevent duplicate NFTokenIDs - env(acctdelete(alice, becky), fee(acctDelFee), ter(tecTOO_SOON)); + env(acctdelete(alice, becky), Fee(acctDelFee), Ter(TecTooSoon)); env.close(); // alice's account is still present @@ -5584,7 +5591,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite incLgrSeqForFixNftRemint(env, alice); // alice's account is deleted - env(acctdelete(alice, becky), fee(acctDelFee)); + env(acctdelete(alice, becky), Fee(acctDelFee)); env.close(); // alice's account root is gone from the most recently @@ -5593,7 +5600,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(!env.current()->exists(aliceAcctKey)); // Fund alice to re-create her account - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // alice's account now exists and has minted 0 NFTokens @@ -5623,7 +5630,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice{"alice"}; Account const becky{"becky"}; - env.fund(XRP(10000), alice, becky); + env.fund(kXRP(10000), alice, becky); env.close(); // alice grab enough tickets for all of the following @@ -5642,14 +5649,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite for (int i = 0; i < 50; i++) { nftIDs.push_back(token::getNextID(env, alice, 0u)); - env(token::mint(alice, 0u), ticket::use(aliceTicketSeq++)); + env(token::mint(alice, 0u), ticket::Use(aliceTicketSeq++)); env.close(); } // alice burns 50 NFTs using tickets for (auto const nftokenID : nftIDs) { - env(token::burn(alice, nftokenID), ticket::use(aliceTicketSeq++)); + env(token::burn(alice, nftokenID), ticket::Use(aliceTicketSeq++)); } env.close(); @@ -5671,7 +5678,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // MintedNFTokens + 256> enabled by this amendment will enforce // alice to wait for more ledgers to close before she can // delete her account, to prevent duplicate NFTokenIDs - env(acctdelete(alice, becky), fee(acctDelFee), ter(tecTOO_SOON)); + env(acctdelete(alice, becky), Fee(acctDelFee), Ter(TecTooSoon)); env.close(); // alice's account is still present @@ -5683,7 +5690,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite incLgrSeqForFixNftRemint(env, alice); // alice's account is deleted - env(acctdelete(alice, becky), fee(acctDelFee)); + env(acctdelete(alice, becky), Fee(acctDelFee)); env.close(); // alice's account root is gone from the most recently @@ -5692,7 +5699,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(!env.current()->exists(aliceAcctKey)); // Fund alice to re-create her account - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // alice's account now exists and has minted 0 NFTokens @@ -5724,7 +5731,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const becky("becky"); Account const minter{"minter"}; - env.fund(XRP(10000), alice, becky, minter); + env.fund(kXRP(10000), alice, becky, minter); env.close(); // alice sets minter as her authorized minter @@ -5746,14 +5753,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { uint256 const nftokenID = token::getNextID(env, alice, 0u); nftIDs.push_back(nftokenID); - env(token::mint(minter), token::issuer(alice), ticket::use(minterTicketSeq++)); + env(token::mint(minter), token::Issuer(alice), ticket::Use(minterTicketSeq++)); } env.close(); // minter burns 50 NFTs using tickets for (auto const nftokenID : nftIDs) { - env(token::burn(minter, nftokenID), ticket::use(minterTicketSeq++)); + env(token::burn(minter, nftokenID), ticket::Use(minterTicketSeq++)); } env.close(); @@ -5774,7 +5781,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice to wait for more ledgers to close before she can delete her // account, to prevent duplicate NFTokenIDs auto const acctDelFee{drops(env.current()->fees().increment)}; - env(acctdelete(alice, becky), fee(acctDelFee), ter(tecTOO_SOON)); + env(acctdelete(alice, becky), Fee(acctDelFee), Ter(TecTooSoon)); env.close(); // alice's account is still present @@ -5786,7 +5793,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite incLgrSeqForFixNftRemint(env, alice); // alice's account is deleted - env(acctdelete(alice, becky), fee(acctDelFee)); + env(acctdelete(alice, becky), Fee(acctDelFee)); env.close(); // alice's account root is gone from the most recently @@ -5795,7 +5802,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(!env.current()->exists(aliceAcctKey)); // Fund alice to re-create her account - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // alice's account now exists and has minted 0 NFTokens @@ -5831,16 +5838,16 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const alice("alice"); Account const buyer("buyer"); - env.fund(XRP(10000), alice, buyer); + env.fund(kXRP(10000), alice, buyer); env.close(); - env(token::mint(alice), token::amount(XRP(10000)), ter(temDISABLED)); + env(token::mint(alice), token::Amount(kXRP(10000)), Ter(TemDisabled)); env.close(); - env(token::mint(alice), token::destination("buyer"), ter(temDISABLED)); + env(token::mint(alice), token::Destination("buyer"), Ter(TemDisabled)); env.close(); - env(token::mint(alice), token::expiration(lastClose(env) + 25), ter(temDISABLED)); + env(token::mint(alice), token::Expiration(lastClose(env) + 25), Ter(TemDisabled)); env.close(); return; @@ -5858,17 +5865,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const bob("bob"); IOU const gwAUD(gw["AUD"]); - env.fund(XRP(10000), alice, buyer, gw, issuer, minter); + env.fund(kXRP(10000), alice, buyer, gw, issuer, minter); env.close(); { // Destination field specified but Amount field not specified - env(token::mint(alice), token::destination(buyer), ter(temMALFORMED)); + env(token::mint(alice), token::Destination(buyer), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // Expiration field specified but Amount field not specified - env(token::mint(alice), token::expiration(lastClose(env) + 25), ter(temMALFORMED)); + env(token::mint(alice), token::Expiration(lastClose(env) + 25), Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, buyer) == 0); } @@ -5877,18 +5884,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // The destination may not be the account submitting the // transaction. env(token::mint(alice), - token::amount(XRP(1000)), - token::destination(alice), - ter(temMALFORMED)); + token::Amount(kXRP(1000)), + token::Destination(alice), + Ter(TemMalformed)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // The destination must be an account already established in the // ledger. env(token::mint(alice), - token::amount(XRP(1000)), - token::destination(Account("demon")), - ter(tecNO_DST)); + token::Amount(kXRP(1000)), + token::Destination(Account("demon")), + Ter(TecNoDst)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); } @@ -5896,17 +5903,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // Set a bad expiration. env(token::mint(alice), - token::amount(XRP(1000)), - token::expiration(0), - ter(temBAD_EXPIRATION)); + token::Amount(kXRP(1000)), + token::Expiration(0), + Ter(TemBadExpiration)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // The new NFTokenOffer may not have passed its expiration time. env(token::mint(alice), - token::amount(XRP(1000)), - token::expiration(lastClose(env)), - ter(tecEXPIRED)); + token::Amount(kXRP(1000)), + token::Expiration(lastClose(env)), + Ter(TecExpired)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); } @@ -5914,19 +5921,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // Set an invalid amount. env(token::mint(alice), - token::amount(buyer["USD"](1)), - txflags(tfOnlyXRP), - ter(temBAD_AMOUNT)); - env(token::mint(alice), token::amount(buyer["USD"](0)), ter(temBAD_AMOUNT)); + token::Amount(buyer["USD"](1)), + Txflags(kTF_ONLY_XRP), + Ter(TemBadAmount)); + env(token::mint(alice), token::Amount(buyer["USD"](0)), Ter(TemBadAmount)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // Issuer (alice) must have a trust line for the offered funds. env(token::mint(alice), - token::amount(gwAUD(1000)), - txflags(tfTransferable), - token::xferFee(10), - ter(tecNO_LINE)); + token::Amount(gwAUD(1000)), + Txflags(kTF_TRANSFERABLE), + token::XferFee(10), + Ter(TecNoLine)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); @@ -5934,32 +5941,32 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // then that issuer does not need a trust line to accept their // fee. env(token::mint(gw), - token::amount(gwAUD(1000)), - txflags(tfTransferable), - token::xferFee(10)); + token::Amount(gwAUD(1000)), + Txflags(kTF_TRANSFERABLE), + token::XferFee(10)); env.close(); // Give alice the needed trust line, but freeze it. - env(trust(gw, alice["AUD"](999), tfSetFreeze)); + env(trust(gw, alice["AUD"](999), kTF_SET_FREEZE)); env.close(); // Issuer (alice) must have a trust line for the offered funds // and the trust line may not be frozen. env(token::mint(alice), - token::amount(gwAUD(1000)), - txflags(tfTransferable), - token::xferFee(10), - ter(tecFROZEN)); + token::Amount(gwAUD(1000)), + Txflags(kTF_TRANSFERABLE), + token::XferFee(10), + Ter(TecFrozen)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // Seller (alice) must have a trust line may not be frozen. - env(token::mint(alice), token::amount(gwAUD(1000)), ter(tecFROZEN)); + env(token::mint(alice), token::Amount(gwAUD(1000)), Ter(TecFrozen)); env.close(); BEAST_EXPECT(ownerCount(env, alice) == 0); // Unfreeze alice's trustline. - env(trust(gw, alice["AUD"](999), tfClearFreeze)); + env(trust(gw, alice["AUD"](999), kTF_CLEAR_FREEZE)); env.close(); } @@ -5972,66 +5979,66 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // doesn't have reserve for 2 objects (NFTokenPage, Offer) - env(token::mint(bob), token::amount(XRP(0)), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(bob), token::Amount(kXRP(0)), Ter(TecInsufficientReserve)); env.close(); // have reserve for NFTokenPage, Offer env(pay(env.master, bob, incReserve + drops(baseFee))); env.close(); - env(token::mint(bob), token::amount(XRP(0))); + env(token::mint(bob), token::Amount(kXRP(0))); env.close(); // doesn't have reserve for Offer env(pay(env.master, bob, drops(baseFee))); env.close(); - env(token::mint(bob), token::amount(XRP(0)), ter(tecINSUFFICIENT_RESERVE)); + env(token::mint(bob), token::Amount(kXRP(0)), Ter(TecInsufficientReserve)); env.close(); // have reserve for Offer env(pay(env.master, bob, incReserve + drops(baseFee))); env.close(); - env(token::mint(bob), token::amount(XRP(0))); + env(token::mint(bob), token::Amount(kXRP(0))); env.close(); } // Amount field specified BEAST_EXPECT(ownerCount(env, alice) == 0); - env(token::mint(alice), token::amount(XRP(10))); + env(token::mint(alice), token::Amount(kXRP(10))); BEAST_EXPECT(ownerCount(env, alice) == 2); env.close(); // Amount field and Destination field, Expiration field specified env(token::mint(alice), - token::amount(XRP(10)), - token::destination(buyer), - token::expiration(lastClose(env) + 25)); + token::Amount(kXRP(10)), + token::Destination(buyer), + token::Expiration(lastClose(env) + 25)); env.close(); // With TransferFee field env(trust(alice, gwAUD(1000))); env.close(); env(token::mint(alice), - token::amount(gwAUD(1)), - token::destination(buyer), - token::expiration(lastClose(env) + 25), - txflags(tfTransferable), - token::xferFee(10)); + token::Amount(gwAUD(1)), + token::Destination(buyer), + token::Expiration(lastClose(env) + 25), + Txflags(kTF_TRANSFERABLE), + token::XferFee(10)); env.close(); // Can be canceled by the issuer. env(token::mint(alice), - token::amount(XRP(10)), - token::destination(buyer), - token::expiration(lastClose(env) + 25)); + token::Amount(kXRP(10)), + token::Destination(buyer), + token::Expiration(lastClose(env) + 25)); uint256 const offerAliceSellsToBuyer = keylet::nftoffer(alice, env.seq(alice)).key; env(token::cancelOffer(alice, {offerAliceSellsToBuyer})); env.close(); // Can be canceled by the buyer. env(token::mint(buyer), - token::amount(XRP(10)), - token::destination(alice), - token::expiration(lastClose(env) + 25)); + token::Amount(kXRP(10)), + token::Destination(alice), + token::Expiration(lastClose(env) + 25)); uint256 const offerBuyerSellsToAlice = keylet::nftoffer(buyer, env.seq(buyer)).key; env(token::cancelOffer(alice, {offerBuyerSellsToAlice})); env.close(); @@ -6042,7 +6049,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Minter will have offer not issuer BEAST_EXPECT(ownerCount(env, minter) == 0); BEAST_EXPECT(ownerCount(env, issuer) == 0); - env(token::mint(minter), token::issuer(issuer), token::amount(drops(1))); + env(token::mint(minter), token::Issuer(issuer), token::Amount(drops(1))); env.close(); BEAST_EXPECT(ownerCount(env, minter) == 2); BEAST_EXPECT(ownerCount(env, issuer) == 0); @@ -6051,12 +6058,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Env env{*this, features}; Account const alice("alice"); - env.fund(XRP(1000000), alice); + env.fund(kXRP(1000000), alice); - TER const offerCreateTER = temBAD_AMOUNT; + TER const offerCreateTER = TemBadAmount; // Make offers with negative amounts for the NFTs - env(token::mint(alice), token::amount(XRP(-2)), ter(offerCreateTER)); + env(token::mint(alice), token::Amount(kXRP(-2)), Ter(offerCreateTER)); env.close(); } @@ -6083,7 +6090,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite Account const broker{"broker"}; Env env{*this, features}; - env.fund(XRP(10000), alice, bob, broker); + env.fund(kXRP(10000), alice, bob, broker); env.close(); // Verify `nftoken_id` value equals to the NFTokenID that was @@ -6091,19 +6098,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // transaction auto verifyNFTokenID = [&](uint256 const& actualNftID) { // Get the hash for the most recent transaction. - std::string const txHash{env.tx()->getJson(JsonOptions::none)[jss::hash].asString()}; + std::string const txHash{env.tx()->getJson(JsonOptions::None)[jss::kHASH].asString()}; env.close(); - Json::Value const meta = env.rpc("tx", txHash)[jss::result][jss::meta]; + Json::Value const meta = env.rpc("tx", txHash)[jss::kRESULT][jss::kMETA]; // Expect nftokens_id field - if (!BEAST_EXPECT(meta.isMember(jss::nftoken_id))) + if (!BEAST_EXPECT(meta.isMember(jss::kNFTOKEN_ID))) return; // Check the value of NFT ID in the meta with the // actual value uint256 nftID; - BEAST_EXPECT(nftID.parseHex(meta[jss::nftoken_id].asString())); + BEAST_EXPECT(nftID.parseHex(meta[jss::kNFTOKEN_ID].asString())); BEAST_EXPECT(nftID == actualNftID); }; @@ -6111,20 +6118,20 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // changed in the most recent NFTokenCancelOffer transaction auto verifyNFTokenIDsInCancelOffer = [&](std::vector actualNftIDs) { // Get the hash for the most recent transaction. - std::string const txHash{env.tx()->getJson(JsonOptions::none)[jss::hash].asString()}; + std::string const txHash{env.tx()->getJson(JsonOptions::None)[jss::kHASH].asString()}; env.close(); - Json::Value const meta = env.rpc("tx", txHash)[jss::result][jss::meta]; + Json::Value const meta = env.rpc("tx", txHash)[jss::kRESULT][jss::kMETA]; // Expect nftokens_ids field and verify the values - if (!BEAST_EXPECT(meta.isMember(jss::nftoken_ids))) + if (!BEAST_EXPECT(meta.isMember(jss::kNFTOKEN_IDS))) return; // Convert NFT IDs from Json::Value to uint256 std::vector metaIDs; std::transform( - meta[jss::nftoken_ids].begin(), - meta[jss::nftoken_ids].end(), + meta[jss::kNFTOKEN_IDS].begin(), + meta[jss::kNFTOKEN_IDS].end(), std::back_inserter(metaIDs), [this](Json::Value id) { uint256 nftID; @@ -6149,17 +6156,17 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // changed in the most recent NFTokenCreateOffer tx auto verifyNFTokenOfferID = [&](uint256 const& offerID) { // Get the hash for the most recent transaction. - std::string const txHash{env.tx()->getJson(JsonOptions::none)[jss::hash].asString()}; + std::string const txHash{env.tx()->getJson(JsonOptions::None)[jss::kHASH].asString()}; env.close(); - Json::Value const meta = env.rpc("tx", txHash)[jss::result][jss::meta]; + Json::Value const meta = env.rpc("tx", txHash)[jss::kRESULT][jss::kMETA]; // Expect offer_id field and verify the value - if (!BEAST_EXPECT(meta.isMember(jss::offer_id))) + if (!BEAST_EXPECT(meta.isMember(jss::kOFFER_ID))) return; uint256 metaOfferID; - BEAST_EXPECT(metaOfferID.parseHex(meta[jss::offer_id].asString())); + BEAST_EXPECT(metaOfferID.parseHex(meta[jss::kOFFER_ID].asString())); BEAST_EXPECT(metaOfferID == offerID); }; @@ -6167,13 +6174,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // Alice mints 2 NFTs // Verify the NFTokenIDs are correct in the NFTokenMint tx meta - uint256 const nftId1{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId1{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); verifyNFTokenID(nftId1); - uint256 const nftId2{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId2{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); verifyNFTokenID(nftId2); @@ -6181,12 +6188,12 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Verify the offer indexes are correct in the NFTokenCreateOffer tx // meta uint256 const aliceOfferIndex1 = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId1, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId1, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); verifyNFTokenOfferID(aliceOfferIndex1); uint256 const aliceOfferIndex2 = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId2, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId2, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); verifyNFTokenOfferID(aliceOfferIndex2); @@ -6200,7 +6207,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Bobs creates a buy offer for nftId1 // Verify the offer id is correct in the NFTokenCreateOffer tx meta auto const bobBuyOfferIndex = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId1, drops(1)), token::owner(alice)); + env(token::createOffer(bob, nftId1, drops(1)), token::Owner(alice)); env.close(); verifyNFTokenOfferID(bobBuyOfferIndex); @@ -6214,22 +6221,22 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Check `nftoken_ids` in brokered mode { // Alice mints a NFT - uint256 const nftId{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); verifyNFTokenID(nftId); // Alice creates sell offer and set broker as destination uint256 const offerAliceToBroker = keylet::nftoffer(alice, env.seq(alice)).key; env(token::createOffer(alice, nftId, drops(1)), - token::destination(broker), - txflags(tfSellNFToken)); + token::Destination(broker), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); verifyNFTokenOfferID(offerAliceToBroker); // Bob creates buy offer uint256 const offerBobToBroker = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId, drops(1)), token::owner(alice)); + env(token::createOffer(bob, nftId, drops(1)), token::Owner(alice)); env.close(); verifyNFTokenOfferID(offerBobToBroker); @@ -6243,19 +6250,19 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // multiple offers are cancelled for the same NFT { // Alice mints a NFT - uint256 const nftId{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); verifyNFTokenID(nftId); // Alice creates 2 sell offers for the same NFT uint256 const aliceOfferIndex1 = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); verifyNFTokenOfferID(aliceOfferIndex1); uint256 const aliceOfferIndex2 = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId, drops(1)), txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId, drops(1)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); verifyNFTokenOfferID(aliceOfferIndex2); @@ -6269,7 +6276,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite if (features[featureNFTokenMintOffer]) { uint256 const aliceMintWithOfferIndex1 = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::mint(alice), token::amount(XRP(0))); + env(token::mint(alice), token::Amount(kXRP(0))); env.close(); verifyNFTokenOfferID(aliceMintWithOfferIndex1); } @@ -6286,13 +6293,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto mintAndCreateSellOffer = [](test::jtx::Env& env, test::jtx::Account const& acct, STAmount const amt) -> uint256 { // acct mints a NFT - uint256 const nftId{token::getNextID(env, acct, 0u, tfTransferable)}; - env(token::mint(acct, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, acct, 0u, kTF_TRANSFERABLE)}; + env(token::mint(acct, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); // acct makes an sell offer uint256 const sellOfferIndex = keylet::nftoffer(acct, env.seq(acct)).key; - env(token::createOffer(acct, nftId, amt), txflags(tfSellNFToken)); + env(token::createOffer(acct, nftId, amt), Txflags(kTF_SELL_NF_TOKEN)); env.close(); return sellOfferIndex; @@ -6310,7 +6317,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const incReserve = env.current()->fees().increment; auto const baseFee = env.current()->fees().base; - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // Bob is funded with minimum XRP reserve @@ -6318,7 +6325,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // alice mints an NFT and create a sell offer for 0 XRP - auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, XRP(0)); + auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, kXRP(0)); // Bob owns no object BEAST_EXPECT(ownerCount(env, bob) == 0); @@ -6347,7 +6354,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // Bob is not able to accept the offer with only the account // reserve (200,000,000 drops) - env(token::acceptSellOffer(bob, sellOfferIndex), ter(tecINSUFFICIENT_RESERVE)); + env(token::acceptSellOffer(bob, sellOfferIndex), Ter(TecInsufficientReserve)); env.close(); // after prev transaction, Bob owns `200M - base fee` drops due @@ -6363,7 +6370,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // However, this transaction will still fail because the reserve // requirement is `base fee` drops higher - env(token::acceptSellOffer(bob, sellOfferIndex), ter(tecINSUFFICIENT_RESERVE)); + env(token::acceptSellOffer(bob, sellOfferIndex), Ter(TecInsufficientReserve)); env.close(); // Send bob `base fee * 2` drops @@ -6389,10 +6396,10 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const acctReserve = env.current()->fees().reserve; auto const incReserve = env.current()->fees().increment; - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); - env.fund(acctReserve + XRP(1), bob); + env.fund(acctReserve + kXRP(1), bob); env.close(); if (!features[fixNFTokenReserve]) @@ -6401,7 +6408,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite for (size_t i = 0; i < 200; i++) { // alice mints an NFT and creates a sell offer for 0 XRP - auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, XRP(0)); + auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, kXRP(0)); // Bob is able to accept the offer env(token::acceptSellOffer(bob, sellOfferIndex)); @@ -6411,11 +6418,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite else { // alice mints the first NFT and creates a sell offer for 0 XRP - auto const sellOfferIndex1 = mintAndCreateSellOffer(env, alice, XRP(0)); + auto const sellOfferIndex1 = mintAndCreateSellOffer(env, alice, kXRP(0)); // Bob cannot accept this offer because he doesn't have the // reserve for the NFT - env(token::acceptSellOffer(bob, sellOfferIndex1), ter(tecINSUFFICIENT_RESERVE)); + env(token::acceptSellOffer(bob, sellOfferIndex1), Ter(TecInsufficientReserve)); env.close(); // Give bob enough reserve @@ -6435,7 +6442,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite for (size_t i = 0; i < 31; i++) { // alice mints an NFT and creates a sell offer for 0 XRP - auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, XRP(0)); + auto const sellOfferIndex = mintAndCreateSellOffer(env, alice, kXRP(0)); // Bob can accept the offer because the new NFT is stored in // an existing NFTokenPage so no new reserve is required @@ -6447,11 +6454,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // alice now mints the 33rd NFT and creates an sell offer for 0 // XRP - auto const sellOfferIndex33 = mintAndCreateSellOffer(env, alice, XRP(0)); + auto const sellOfferIndex33 = mintAndCreateSellOffer(env, alice, kXRP(0)); // Bob fails to accept this NFT because he does not have enough // reserve for a new NFTokenPage - env(token::acceptSellOffer(bob, sellOfferIndex33), ter(tecINSUFFICIENT_RESERVE)); + env(token::acceptSellOffer(bob, sellOfferIndex33), Ter(TecInsufficientReserve)); env.close(); // Send bob incremental reserve @@ -6481,29 +6488,29 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const incReserve = env.current()->fees().increment; auto const baseFee = env.current()->fees().base; - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); // Bob is funded with account reserve + increment reserve + 1 XRP // increment reserve is for the buy offer, and 1 XRP is for offer // price - env.fund(acctReserve + incReserve + XRP(1), bob); + env.fund(acctReserve + incReserve + kXRP(1), bob); env.close(); // Alice mints a NFT - uint256 const nftId{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); // Bob makes a buy offer for 1 XRP auto const buyOfferIndex = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId, XRP(1)), token::owner(alice)); + env(token::createOffer(bob, nftId, kXRP(1)), token::Owner(alice)); env.close(); // accepting the buy offer fails because bob's balance is `base fee` // drops lower than the required amount, since the previous tx burnt // drops for tx fee. - env(token::acceptBuyOffer(alice, buyOfferIndex), ter(tecINSUFFICIENT_FUNDS)); + env(token::acceptBuyOffer(alice, buyOfferIndex), Ter(TecInsufficientFunds)); env.close(); // send Bob `base fee` drops @@ -6530,29 +6537,29 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite auto const incReserve = env.current()->fees().increment; auto const baseFee = env.current()->fees().base; - env.fund(XRP(10000), alice, broker); + env.fund(kXRP(10000), alice, broker); env.close(); // Bob is funded with account reserve + incr reserve + 1 XRP(offer // price) - env.fund(acctReserve + incReserve + XRP(1), bob); + env.fund(acctReserve + incReserve + kXRP(1), bob); env.close(); // Alice mints a NFT - uint256 const nftId{token::getNextID(env, alice, 0u, tfTransferable)}; - env(token::mint(alice, 0u), txflags(tfTransferable)); + uint256 const nftId{token::getNextID(env, alice, 0u, kTF_TRANSFERABLE)}; + env(token::mint(alice, 0u), Txflags(kTF_TRANSFERABLE)); env.close(); // Alice creates sell offer and set broker as destination uint256 const offerAliceToBroker = keylet::nftoffer(alice, env.seq(alice)).key; - env(token::createOffer(alice, nftId, XRP(1)), - token::destination(broker), - txflags(tfSellNFToken)); + env(token::createOffer(alice, nftId, kXRP(1)), + token::Destination(broker), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); // Bob creates buy offer uint256 const offerBobToBroker = keylet::nftoffer(bob, env.seq(bob)).key; - env(token::createOffer(bob, nftId, XRP(1)), token::owner(alice)); + env(token::createOffer(bob, nftId, kXRP(1)), token::Owner(alice)); env.close(); // broker offers. @@ -6560,7 +6567,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // created his buy offer, which makes his spendable balance to be // less than the required amount. env(token::brokerOffers(broker, offerBobToBroker, offerAliceToBroker), - ter(tecINSUFFICIENT_FUNDS)); + Ter(TecInsufficientFunds)); env.close(); // send Bob `base fee` drops @@ -6619,7 +6626,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite localFeatures | fixEnforceNFTokenTrustline}) { Env env{*this, feats}; - env.fund(XRP(1000), issuer, becky, cheri, gw); + env.fund(kXRP(1000), issuer, becky, cheri, gw); env.close(); // Set trust lines so becky and cheri can use gw's currency. @@ -6632,24 +6639,24 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // issuer creates two NFTs: one with and one without AutoTrustLine. std::uint16_t const xferFee = 5000; // 5% uint256 const nftAutoTrustID{ - token::getNextID(env, issuer, 0u, tfTransferable | tfTrustLine, xferFee)}; + token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE | kTF_TRUST_LINE, xferFee)}; env(token::mint(issuer, 0u), - token::xferFee(xferFee), - txflags(tfTransferable | tfTrustLine)); + token::XferFee(xferFee), + Txflags(kTF_TRANSFERABLE | kTF_TRUST_LINE)); env.close(); uint256 const nftNoAutoTrustID{ - token::getNextID(env, issuer, 0u, tfTransferable, xferFee)}; - env(token::mint(issuer, 0u), token::xferFee(xferFee), txflags(tfTransferable)); + token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE, xferFee)}; + env(token::mint(issuer, 0u), token::XferFee(xferFee), Txflags(kTF_TRANSFERABLE)); env.close(); // becky buys the nfts for 1 drop each. { uint256 const beckyBuyOfferIndex1 = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::owner(issuer)); + env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::Owner(issuer)); uint256 const beckyBuyOfferIndex2 = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::owner(issuer)); + env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::Owner(issuer)); env.close(); env(token::acceptBuyOffer(issuer, beckyBuyOfferIndex1)); @@ -6659,14 +6666,14 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // becky creates offers to sell the nfts for AUD. uint256 const beckyAutoTrustOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, gwAUD(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftAutoTrustID, gwAUD(100)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // Creating an offer for the NFToken without tfTrustLine fails // because issuer does not have a trust line for AUD. env(token::createOffer(becky, nftNoAutoTrustID, gwAUD(100)), - txflags(tfSellNFToken), - ter(tecNO_LINE)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoLine)); env.close(); // issuer creates a trust line. Now the offer create for the @@ -6677,7 +6684,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(ownerCount(env, issuer) == 1); uint256 const beckyNoAutoTrustOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftNoAutoTrustID, gwAUD(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftNoAutoTrustID, gwAUD(100)), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); // Now that the offers are in place, issuer removes the trustline. @@ -6707,7 +6715,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // With fixEnforceNFTokenTrustline cheri can't accept the // offer because issuer could not get their transfer fee // without the appropriate trustline. - env(token::acceptSellOffer(cheri, beckyNoAutoTrustOfferIndex), ter(tecNO_LINE)); + env(token::acceptSellOffer(cheri, beckyNoAutoTrustOfferIndex), Ter(TecNoLine)); env.close(); // But if issuer re-establishes the trustline then the offer @@ -6775,7 +6783,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite FeatureBitset const localFeatures = features - fixRemoveNFTokenAutoTrustLine; Env env{*this, localFeatures}; - env.fund(XRP(1000), issuer, becky, cheri); + env.fund(kXRP(1000), issuer, becky, cheri); env.close(); // Set trust lines so becky and cheri can use isISU. @@ -6788,23 +6796,24 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // issuer creates two NFTs: one with and one without AutoTrustLine. std::uint16_t const xferFee = 5000; // 5% uint256 const nftAutoTrustID{ - token::getNextID(env, issuer, 0u, tfTransferable | tfTrustLine, xferFee)}; + token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE | kTF_TRUST_LINE, xferFee)}; env(token::mint(issuer, 0u), - token::xferFee(xferFee), - txflags(tfTransferable | tfTrustLine)); + token::XferFee(xferFee), + Txflags(kTF_TRANSFERABLE | kTF_TRUST_LINE)); env.close(); - uint256 const nftNoAutoTrustID{token::getNextID(env, issuer, 0u, tfTransferable, xferFee)}; - env(token::mint(issuer, 0u), token::xferFee(xferFee), txflags(tfTransferable)); + uint256 const nftNoAutoTrustID{ + token::getNextID(env, issuer, 0u, kTF_TRANSFERABLE, xferFee)}; + env(token::mint(issuer, 0u), token::XferFee(xferFee), Txflags(kTF_TRANSFERABLE)); env.close(); // becky buys the nfts for 1 drop each. { uint256 const beckyBuyOfferIndex1 = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::owner(issuer)); + env(token::createOffer(becky, nftAutoTrustID, drops(1)), token::Owner(issuer)); uint256 const beckyBuyOfferIndex2 = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::owner(issuer)); + env(token::createOffer(becky, nftNoAutoTrustID, drops(1)), token::Owner(issuer)); env.close(); env(token::acceptBuyOffer(issuer, beckyBuyOfferIndex1)); @@ -6820,18 +6829,18 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // create an offer for a non-tfTrustLine NFToken that would // pay the transfer fee in issuer's own IOU. env(token::createOffer(becky, nftNoAutoTrustID, isISU(100)), - txflags(tfSellNFToken), - ter(tecNO_LINE)); + Txflags(kTF_SELL_NF_TOKEN), + Ter(TecNoLine)); env.close(); // And issuer can't create a trust line to themselves. - env(trust(issuer, isISU(1000)), ter(temDST_IS_SRC)); + env(trust(issuer, isISU(1000)), Ter(TemDstIsSrc)); env.close(); // However if the NFToken has the tfTrustLine flag set, // then becky can create the offer. uint256 const beckyAutoTrustOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, isISU(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftAutoTrustID, isISU(100)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // And cheri can accept the offer. @@ -6848,10 +6857,11 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // With featureNFTokenMintOffer things go better. // becky creates offers to sell the nfts for ISU. uint256 const beckyNoAutoTrustOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftNoAutoTrustID, isISU(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftNoAutoTrustID, isISU(100)), + Txflags(kTF_SELL_NF_TOKEN)); env.close(); uint256 const beckyAutoTrustOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; - env(token::createOffer(becky, nftAutoTrustID, isISU(100)), txflags(tfSellNFToken)); + env(token::createOffer(becky, nftAutoTrustID, isISU(100)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); // cheri accepts becky's offers. Behavior is uniform: @@ -6891,23 +6901,23 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { // Mint with tfMutable Env env{*this, features}; - env.fund(XRP(10000), issuer); + env.fund(kXRP(10000), issuer); env.close(); - auto const expectedTer = modifyEnabled ? TER{tesSUCCESS} : TER{temINVALID_FLAG}; - env(token::mint(issuer, 0u), txflags(tfMutable), ter(expectedTer)); + auto const expectedTer = modifyEnabled ? TER{TesSuccess} : TER{TemInvalidFlag}; + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE), Ter(expectedTer)); env.close(); } { Env env{*this, features}; - env.fund(XRP(10000), issuer); + env.fund(kXRP(10000), issuer); env.close(); // Modify a nftoken - uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)}; + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; if (modifyEnabled) { - env(token::mint(issuer, 0u), txflags(tfMutable)); + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 1); env(token::modify(issuer, nftId)); @@ -6917,7 +6927,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { env(token::mint(issuer, 0u)); env.close(); - env(token::modify(issuer, nftId), ter(temDISABLED)); + env(token::modify(issuer, nftId), Ter(TemDisabled)); env.close(); } } @@ -6926,45 +6936,45 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { Env env{*this, features}; - env.fund(XRP(10000), issuer); + env.fund(kXRP(10000), issuer); env.close(); - uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)}; - env(token::mint(issuer, 0u), txflags(tfMutable)); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE)); env.close(); // Set a negative fee. Exercises invalid preflight1. - env(token::modify(issuer, nftId), fee(STAmount(10ull, true)), ter(temBAD_FEE)); + env(token::modify(issuer, nftId), Fee(STAmount(10ull, true)), Ter(TemBadFee)); env.close(); // Invalid Flags - env(token::modify(issuer, nftId), txflags(0x00000001), ter(temINVALID_FLAG)); + env(token::modify(issuer, nftId), Txflags(0x00000001), Ter(TemInvalidFlag)); // Invalid Owner - env(token::modify(issuer, nftId), token::owner(issuer), ter(temMALFORMED)); + env(token::modify(issuer, nftId), token::Owner(issuer), Ter(TemMalformed)); env.close(); // Invalid URI length = 0 - env(token::modify(issuer, nftId), token::uri(""), ter(temMALFORMED)); + env(token::modify(issuer, nftId), token::Uri(""), Ter(TemMalformed)); env.close(); // Invalid URI length > 256 env(token::modify(issuer, nftId), - token::uri(std::string(maxTokenURILength + 1, 'q')), - ter(temMALFORMED)); + token::Uri(std::string(kMAX_TOKEN_URI_LENGTH + 1, 'q')), + Ter(TemMalformed)); env.close(); } { Env env{*this, features}; - env.fund(XRP(10000), issuer, alice, bob); + env.fund(kXRP(10000), issuer, alice, bob); env.close(); { // NFToken not exists - uint256 const nftIDNotExists{token::getNextID(env, issuer, 0u, tfMutable)}; + uint256 const nftIDNotExists{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; env.close(); - env(token::modify(issuer, nftIDNotExists), ter(tecNO_ENTRY)); + env(token::modify(issuer, nftIDNotExists), Ter(TecNoEntry)); env.close(); } { @@ -6973,50 +6983,50 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env(token::mint(issuer, 0u)); env.close(); - env(token::modify(issuer, nftIDNotModifiable), ter(tecNO_PERMISSION)); + env(token::modify(issuer, nftIDNotModifiable), Ter(TecNoPermission)); env.close(); } { // Unauthorized account - uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)}; - env(token::mint(issuer, 0u), txflags(tfMutable)); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE)); env.close(); - env(token::modify(bob, nftId), token::owner(issuer), ter(tecNO_PERMISSION)); + env(token::modify(bob, nftId), token::Owner(issuer), Ter(TecNoPermission)); env.close(); env(token::setMinter(issuer, alice)); env.close(); - env(token::modify(bob, nftId), token::owner(issuer), ter(tecNO_PERMISSION)); + env(token::modify(bob, nftId), token::Owner(issuer), Ter(TecNoPermission)); env.close(); } } { Env env{*this, features}; - env.fund(XRP(10000), issuer, alice, bob); + env.fund(kXRP(10000), issuer, alice, bob); env.close(); // modify with tfFullyCanonicalSig should success - uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)}; - env(token::mint(issuer, 0u), txflags(tfMutable), token::uri("uri")); + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE), token::Uri("uri")); env.close(); - env(token::modify(issuer, nftId), txflags(tfFullyCanonicalSig)); + env(token::modify(issuer, nftId), Txflags(kTF_FULLY_CANONICAL_SIG)); env.close(); } { Env env{*this, features}; - env.fund(XRP(10000), issuer, alice, bob); + env.fund(kXRP(10000), issuer, alice, bob); env.close(); // lambda that returns the JSON form of NFTokens held by acct auto accountNFTs = [&env](Account const& acct) { Json::Value params; params[jss::account] = acct.human(); - params[jss::type] = "state"; + params[jss::kTYPE] = "state"; auto response = env.rpc("json", "account_nfts", to_string(params)); - return response[jss::result][jss::account_nfts]; + return response[jss::kRESULT][jss::kACCOUNT_NFTS]; }; // lambda that checks for the expected URI value of an NFToken @@ -7061,15 +7071,15 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } }; - uint256 const nftId{token::getNextID(env, issuer, 0u, tfMutable)}; + uint256 const nftId{token::getNextID(env, issuer, 0u, kTF_MUTABLE)}; env.close(); - env(token::mint(issuer, 0u), txflags(tfMutable), token::uri("uri")); + env(token::mint(issuer, 0u), Txflags(kTF_MUTABLE), token::Uri("uri")); env.close(); checkURI(issuer, "uri", __LINE__); // set URI Field - env(token::modify(issuer, nftId), token::uri("new_uri")); + env(token::modify(issuer, nftId), token::Uri("new_uri")); env.close(); checkURI(issuer, "new_uri", __LINE__); @@ -7079,13 +7089,13 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkURI(issuer, nullptr, __LINE__); // set URI Field - env(token::modify(issuer, nftId), token::uri("uri")); + env(token::modify(issuer, nftId), token::Uri("uri")); env.close(); checkURI(issuer, "uri", __LINE__); // Account != Owner uint256 const offerID = keylet::nftoffer(issuer, env.seq(issuer)).key; - env(token::createOffer(issuer, nftId, XRP(0)), txflags(tfSellNFToken)); + env(token::createOffer(issuer, nftId, kXRP(0)), Txflags(kTF_SELL_NF_TOKEN)); env.close(); env(token::acceptSellOffer(alice, offerID)); env.close(); @@ -7094,45 +7104,45 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite checkURI(alice, "uri", __LINE__); // Modify by owner fails. - env(token::modify(alice, nftId), token::uri("new_uri"), ter(tecNO_PERMISSION)); + env(token::modify(alice, nftId), token::Uri("new_uri"), Ter(TecNoPermission)); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, alice) == 1); checkURI(alice, "uri", __LINE__); - env(token::modify(issuer, nftId), token::owner(alice), token::uri("new_uri")); + env(token::modify(issuer, nftId), token::Owner(alice), token::Uri("new_uri")); env.close(); BEAST_EXPECT(ownerCount(env, issuer) == 0); BEAST_EXPECT(ownerCount(env, alice) == 1); checkURI(alice, "new_uri", __LINE__); - env(token::modify(issuer, nftId), token::owner(alice)); + env(token::modify(issuer, nftId), token::Owner(alice)); env.close(); checkURI(alice, nullptr, __LINE__); - env(token::modify(issuer, nftId), token::owner(alice), token::uri("uri")); + env(token::modify(issuer, nftId), token::Owner(alice), token::Uri("uri")); env.close(); checkURI(alice, "uri", __LINE__); // Modify by authorized minter env(token::setMinter(issuer, bob)); env.close(); - env(token::modify(bob, nftId), token::owner(alice), token::uri("new_uri")); + env(token::modify(bob, nftId), token::Owner(alice), token::Uri("new_uri")); env.close(); checkURI(alice, "new_uri", __LINE__); - env(token::modify(bob, nftId), token::owner(alice)); + env(token::modify(bob, nftId), token::Owner(alice)); env.close(); checkURI(alice, nullptr, __LINE__); - env(token::modify(bob, nftId), token::owner(alice), token::uri("uri")); + env(token::modify(bob, nftId), token::Owner(alice), token::Uri("uri")); env.close(); checkURI(alice, "uri", __LINE__); } } protected: - FeatureBitset const allFeatures{test::jtx::testable_amendments()}; + FeatureBitset const allFeatures_{test::jtx::testable_amendments()}; void testWithFeats(FeatureBitset features) @@ -7179,7 +7189,7 @@ public: run() override { testWithFeats( - allFeatures - fixNFTokenReserve - featureNFTokenMintOffer - featureDynamicNFT - + allFeatures_ - fixNFTokenReserve - featureNFTokenMintOffer - featureDynamicNFT - fixSecurity3_1_3); } }; @@ -7190,7 +7200,7 @@ class NFTokenDisallowIncoming_test : public NFTokenBaseUtil_test run() override { testWithFeats( - allFeatures - fixNFTokenReserve - featureNFTokenMintOffer - featureDynamicNFT); + allFeatures_ - fixNFTokenReserve - featureNFTokenMintOffer - featureDynamicNFT); } }; @@ -7199,7 +7209,7 @@ class NFTokenWOMintOffer_test : public NFTokenBaseUtil_test void run() override { - testWithFeats(allFeatures - featureNFTokenMintOffer - featureDynamicNFT); + testWithFeats(allFeatures_ - featureNFTokenMintOffer - featureDynamicNFT); } }; @@ -7208,16 +7218,16 @@ class NFTokenWOModify_test : public NFTokenBaseUtil_test void run() override { - testWithFeats(allFeatures - featureDynamicNFT); + testWithFeats(allFeatures_ - featureDynamicNFT); } }; -class NFTokenWOExpiredOfferRemoval_test : public NFTokenBaseUtil_test +class NfTokenWoExpiredOfferRemovalTest : public NFTokenBaseUtil_test { void run() override { - testWithFeats(allFeatures - fixSecurity3_1_3); + testWithFeats(allFeatures_ - fixSecurity3_1_3); } }; @@ -7226,7 +7236,7 @@ class NFTokenAllFeatures_test : public NFTokenBaseUtil_test void run() override { - testWithFeats(allFeatures); + testWithFeats(allFeatures_); } }; diff --git a/src/test/app/OfferMPT_test.cpp b/src/test/app/OfferMPT_test.cpp index 3bf8187137..9574fa4534 100644 --- a/src/test/app/OfferMPT_test.cpp +++ b/src/test/app/OfferMPT_test.cpp @@ -53,7 +53,7 @@ namespace xrpl::test { -class OfferMPT_test : public beast::unit_test::suite +class OfferMPT_test : public beast::unit_test::Suite { static XRPAmount reserve(jtx::Env& env, std::uint32_t count) @@ -91,43 +91,43 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); env.close(); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice, bob, carol}}); - auto const BTC = + auto const btc = issue2({.env = env, .token = "BTC", .issuer = gw, .holders = {alice, bob, carol}}); - env(pay(gw, alice, BTC(1'000))); + env(pay(gw, alice, btc(1'000))); - env(pay(gw, carol, USD(1'000))); - env(pay(gw, carol, BTC(1'000))); + env(pay(gw, carol, usd(1'000))); + env(pay(gw, carol, btc(1'000))); // Must be two offers at the same quality // "taker gets" must be XRP // (Different amounts, so I can distinguish the offers) - env(offer(carol, BTC(49), XRP(49))); - env(offer(carol, BTC(51), XRP(51))); + env(offer(carol, btc(49), kXRP(49))); + env(offer(carol, btc(51), kXRP(51))); // Offers for the poor quality path // Must be two offers at the same quality - env(offer(carol, XRP(50), USD(50))); - env(offer(carol, XRP(50), USD(50))); + env(offer(carol, kXRP(50), usd(50))); + env(offer(carol, kXRP(50), usd(50))); // Offers for the good quality path - env(offer(carol, BTC(1), USD(100))); + env(offer(carol, btc(1), usd(100))); - PathSet const paths(Path(XRP, USD), Path(USD)); + PathSet const paths(Path(kXRP, usd), Path(usd)); - env(pay(alice, bob, USD(100)), - json(paths.json()), - sendmax(BTC(1'000)), - txflags(tfPartialPayment)); + env(pay(alice, bob, usd(100)), + Json(paths.json()), + Sendmax(btc(1'000)), + Txflags(kTF_PARTIAL_PAYMENT)); - env.require(balance(bob, USD(100))); + env.require(Balance(bob, usd(100))); BEAST_EXPECT( - !isOffer(env, carol, BTC(1), USD(100)) && isOffer(env, carol, BTC(49), XRP(49))); + !isOffer(env, carol, btc(1), usd(100)) && isOffer(env, carol, btc(49), kXRP(49))); }; testHelper2TokensMix(test); } @@ -143,68 +143,68 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - env.fund(XRP(10'000), alice, gw); + env.fund(kXRP(10'000), alice, gw); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - env(pay(gw, alice, USD(50))); + env(pay(gw, alice, usd(50))); env.close(); auto const offer1Seq = env.seq(alice); - env(offer(alice, XRP(500), USD(100)), require(offers(alice, 1))); + env(offer(alice, kXRP(500), usd(100)), Require(offers(alice, 1))); env.close(); - BEAST_EXPECT(isOffer(env, alice, XRP(500), USD(100))); + BEAST_EXPECT(isOffer(env, alice, kXRP(500), usd(100))); // cancel the offer above and replace it with a new offer auto const offer2Seq = env.seq(alice); - env(offer(alice, XRP(300), USD(100)), - json(jss::OfferSequence, offer1Seq), - require(offers(alice, 1))); + env(offer(alice, kXRP(300), usd(100)), + Json(jss::kOFFER_SEQUENCE, offer1Seq), + Require(offers(alice, 1))); env.close(); BEAST_EXPECT( - isOffer(env, alice, XRP(300), USD(100)) && !isOffer(env, alice, XRP(500), USD(100))); + isOffer(env, alice, kXRP(300), usd(100)) && !isOffer(env, alice, kXRP(500), usd(100))); // Test canceling non-existent offer. // auto const offer3Seq = env.seq (alice); - env(offer(alice, XRP(400), USD(200)), - json(jss::OfferSequence, offer1Seq), - require(offers(alice, 2))); + env(offer(alice, kXRP(400), usd(200)), + Json(jss::kOFFER_SEQUENCE, offer1Seq), + Require(offers(alice, 2))); env.close(); BEAST_EXPECT( - isOffer(env, alice, XRP(300), USD(100)) && isOffer(env, alice, XRP(400), USD(200))); + isOffer(env, alice, kXRP(300), usd(100)) && isOffer(env, alice, kXRP(400), usd(200))); // Test cancellation now with OfferCancel tx auto const offer4Seq = env.seq(alice); - env(offer(alice, XRP(222), USD(111)), require(offers(alice, 3))); + env(offer(alice, kXRP(222), usd(111)), Require(offers(alice, 3))); env.close(); - BEAST_EXPECT(isOffer(env, alice, XRP(222), USD(111))); + BEAST_EXPECT(isOffer(env, alice, kXRP(222), usd(111))); env(offer_cancel(alice, offer4Seq)); env.close(); BEAST_EXPECT(env.seq(alice) == offer4Seq + 2); - BEAST_EXPECT(!isOffer(env, alice, XRP(222), USD(111))); + BEAST_EXPECT(!isOffer(env, alice, kXRP(222), usd(111))); // Create an offer that both fails with a tecEXPIRED code and removes // an offer. Show that the attempt to remove the offer fails. env.require(offers(alice, 2)); - env(offer(alice, XRP(5), USD(2)), - json(sfExpiration.fieldName, lastClose(env)), - json(jss::OfferSequence, offer2Seq), - ter(TER{tecEXPIRED})); + env(offer(alice, kXRP(5), usd(2)), + Json(sfExpiration.fieldName, lastClose(env)), + Json(jss::kOFFER_SEQUENCE, offer2Seq), + Ter(TER{TecExpired})); env.close(); env.require(offers(alice, 2)); - BEAST_EXPECT(isOffer(env, alice, XRP(300), USD(100))); // offer2 - BEAST_EXPECT(!isOffer(env, alice, XRP(5), USD(2))); // expired + BEAST_EXPECT(isOffer(env, alice, kXRP(300), usd(100))); // offer2 + BEAST_EXPECT(!isOffer(env, alice, kXRP(5), usd(2))); // expired } void @@ -223,36 +223,36 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); env.close(); - auto const USD = issue1( + auto const usd = issue1( {.env = env, .token = "USD", .issuer = gw, .holders = {alice, bob, carol}, .limit = 400'000'000}); - auto const EUR = issue2( + auto const eur = issue2( {.env = env, .token = "EUR", .issuer = gw, .holders = {alice, bob, carol}, .limit = 400'000'000}); - env(pay(gw, alice, USD(100'000'000))); - env(pay(gw, carol, EUR(100'000'000))); + env(pay(gw, alice, usd(100'000'000))); + env(pay(gw, carol, eur(100'000'000))); // Create more offers than the loop max count in DeliverNodeReverse // Note: the DeliverNodeReverse code has been removed; however since // this is a regression test the original test is being left as-is // for now. for (int i = 0; i < 101; ++i) - env(offer(carol, USD(1'000'000), EUR(2'000'000))); + env(offer(carol, usd(1'000'000), eur(2'000'000))); // Original Offer test sends EUR(10**-81). MPT is integral, // therefore and integral value is sent respecting the exchange // rate. I.e. if EUR(1) is sent then it'll result in USD(0). - env(pay(alice, bob, EUR(2)), path(~EUR), sendmax(USD(100))); + env(pay(alice, bob, eur(2)), Path(~eur), Sendmax(usd(100))); }; testHelper2TokensMix(test); } @@ -288,17 +288,17 @@ public: Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, dan, erin, gw); + env.fund(kXRP(10'000), alice, bob, carol, dan, erin, gw); env.close(); - MPT const USD = MPTTester( + MPT const usd = MPTTester( {.env = env, .issuer = gw, .holders = {alice, bob, carol, dan, erin}, .pay = std::nullopt}); - env(pay(gw, carol, USD(99'999))); - env(pay(gw, dan, USD(100'000))); - env(pay(gw, erin, USD(100'000))); + env(pay(gw, carol, usd(99'999))); + env(pay(gw, dan, usd(100'000))); + env(pay(gw, erin, usd(100'000))); env.close(); // Carol doesn't quite have enough funds for this offer @@ -306,10 +306,10 @@ public: // STAmount to incorrectly round to zero when the next offer // (at a good quality) is considered. (when the now removed // stAmountCalcSwitchover2 patch was inactive) - env(offer(carol, drops(1), USD(99'999))); + env(offer(carol, drops(1), usd(99'999))); // Offer at a quality poor enough so when the input xrp is // calculated in the reverse pass, the amount is not zero. - env(offer(dan, XRP(100), USD(1))); + env(offer(dan, kXRP(100), usd(1))); env.close(); // This is the funded offer that will be incorrectly removed. @@ -318,18 +318,18 @@ public: // needed for this offer, it will incorrectly compute zero in both // the forward and reverse passes (when the now removed // stAmountCalcSwitchover2 was inactive.) - env(offer(erin, drops(2), USD(100'000))); + env(offer(erin, drops(2), usd(100'000))); - env(pay(alice, bob, USD(100'000)), - path(~USD), - sendmax(XRP(102)), - txflags(tfNoRippleDirect | tfPartialPayment)); + env(pay(alice, bob, usd(100'000)), + Path(~usd), + Sendmax(kXRP(102)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT)); env.require(offers(carol, 0), offers(dan, 1)); // offer was correctly consumed. There is still some // liquidity left on that offer. - env.require(balance(erin, USD(99'999)), offers(erin, 1)); + env.require(Balance(erin, usd(99'999)), offers(erin, 1)); } void @@ -354,42 +354,42 @@ public: { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob, carol}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob, carol}}); // underfund carol's offer - auto initialCarolUSD = USD(499); + auto initialCarolUSD = usd(499); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100'000))); + env(pay(gw, bob, usd(100'000))); env.close(); // This offer is underfunded - env(offer(carol, drops(1), USD(1'000))); + env(offer(carol, drops(1), usd(1'000))); env.close(); // offer at a lower quality - env(offer(bob, drops(2), USD(1'000), tfPassive)); + env(offer(bob, drops(2), usd(1'000), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); // alice places an offer that crosses carol's; depending on // "crossBothOffers" it may cross bob's as well auto aliceTakerGets = crossBothOffers ? drops(2) : drops(1); - env(offer(alice, USD(1'000), aliceTakerGets)); + env(offer(alice, usd(1'000), aliceTakerGets)); env.close(); env.require( offers(carol, 0), - balance( + Balance( carol, initialCarolUSD)); // offer is removed but not taken if (crossBothOffers) { env.require( - offers(alice, 0), balance(alice, USD(1'000))); // alice's offer is crossed + offers(alice, 0), Balance(alice, usd(1'000))); // alice's offer is crossed } else { env.require( - offers(alice, 1), balance(alice, USD(0))); // alice's offer is not crossed + offers(alice, 1), Balance(alice, usd(0))); // alice's offer is not crossed } } @@ -398,37 +398,38 @@ public: { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob, carol}}); - auto const initialCarolUSD = USD(999); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob, carol}}); + auto const initialCarolUSD = usd(999); env(pay(gw, carol, initialCarolUSD)); env.close(); - env(pay(gw, bob, USD(100'000))); + env(pay(gw, bob, usd(100'000))); env.close(); - env(offer(carol, drops(1), USD(1'000))); + env(offer(carol, drops(1), usd(1'000))); env.close(); - env(offer(bob, drops(2), USD(2'000), tfPassive)); + env(offer(bob, drops(2), usd(2'000), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); - std::uint32_t const flags = - partialPayment ? (tfNoRippleDirect | tfPartialPayment) : tfNoRippleDirect; + std::uint32_t const flags = partialPayment + ? (kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT) + : kTF_NO_RIPPLE_DIRECT; - TER const expectedTer = partialPayment ? TER{tesSUCCESS} : TER{tecPATH_PARTIAL}; + TER const expectedTer = partialPayment ? TER{TesSuccess} : TER{TecPathPartial}; - env(pay(alice, bob, USD(5'000)), - path(~USD), - sendmax(XRP(1)), - txflags(flags), - ter(expectedTer)); + env(pay(alice, bob, usd(5'000)), + Path(~usd), + Sendmax(kXRP(1)), + Txflags(flags), + Ter(expectedTer)); env.close(); - if (expectedTer == tesSUCCESS) + if (expectedTer == TesSuccess) { env.require(offers(carol, 0)); - env.require(balance(carol, + env.require(Balance(carol, initialCarolUSD)); // offer is removed but not taken } else @@ -483,60 +484,60 @@ public: { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); env.close(); - auto const USD = issue1( + auto const usd = issue1( {.env = env, .token = "USD", .issuer = gw, .holders = {alice, bob, carol}, .limit = 100'000'000}); - auto const EUR = issue2( + auto const eur = issue2( {.env = env, .token = "EUR", .issuer = gw, .holders = {alice, bob, carol}, .limit = 100'000'000}); // underfund carol's offer - auto initialCarolUSD = tinyAmount(USD); + auto initialCarolUSD = tinyAmount(usd); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100'000))); - env(pay(gw, alice, EUR(100'000))); + env(pay(gw, bob, usd(100'000))); + env(pay(gw, alice, eur(100'000))); env.close(); // This offer is underfunded - env(offer(carol, EUR(10), USD(10'000))); + env(offer(carol, eur(10), usd(10'000))); env.close(); // offer at a lower quality - env(offer(bob, EUR(10), USD(5'000), tfPassive)); + env(offer(bob, eur(10), usd(5'000), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); // alice places an offer that crosses carol's; depending on // "crossBothOffers" it may cross bob's as well // Whatever - auto aliceTakerGets = crossBothOffers ? EUR(2) : EUR(1); - env(offer(alice, USD(1'000), aliceTakerGets)); + auto aliceTakerGets = crossBothOffers ? eur(2) : eur(1); + env(offer(alice, usd(1'000), aliceTakerGets)); env.close(); // carol's offer can be partially crossed when EUR is IOU: // 10e-3EUR/1USD - using tEUR = std::decay_t; - bool constexpr isEURIOU = std::is_same_v; + using tEUR = std::decay_t; + bool constexpr kIS_EURIOU = std::is_same_v; // partially crossed if IOU, removed but not taken if MPT - auto const balanceCarolUSD = isEURIOU ? USD(0) : initialCarolUSD; + auto const balanceCarolUSD = kIS_EURIOU ? usd(0) : initialCarolUSD; - env.require(offers(carol, 0), balance(carol, balanceCarolUSD)); + env.require(offers(carol, 0), Balance(carol, balanceCarolUSD)); if (crossBothOffers) { env.require( - offers(alice, 0), balance(alice, USD(1'000))); // alice's offer is crossed + offers(alice, 0), Balance(alice, usd(1'000))); // alice's offer is crossed } else { // partially crossed if IOU, not crossed if MPT - auto const balanceAliceUSD = isEURIOU ? USD(1) : USD(0); - env.require(offers(alice, 1), balance(alice, balanceAliceUSD)); + auto const balanceAliceUSD = kIS_EURIOU ? usd(1) : usd(0); + env.require(offers(alice, 1), Balance(alice, balanceAliceUSD)); } } @@ -545,56 +546,57 @@ public: { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol, gw); + env.fund(kXRP(10'000), alice, bob, carol, gw); env.close(); - auto const USD = issue1( + auto const usd = issue1( {.env = env, .token = "USD", .issuer = gw, .holders = {alice, bob, carol}, .limit = 100'000'000}); - auto const EUR = issue2( + auto const eur = issue2( {.env = env, .token = "EUR", .issuer = gw, .holders = {alice, bob, carol}, .limit = 100'000'000}); // underfund carol's offer - auto const initialCarolUSD = tinyAmount(USD); + auto const initialCarolUSD = tinyAmount(usd); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100'000))); - env(pay(gw, alice, EUR(100'000))); + env(pay(gw, bob, usd(100'000))); + env(pay(gw, alice, eur(100'000))); env.close(); // This offer is underfunded - env(offer(carol, EUR(10), USD(2'000))); + env(offer(carol, eur(10), usd(2'000))); env.close(); - env(offer(bob, EUR(20), USD(4'000), tfPassive)); + env(offer(bob, eur(20), usd(4'000), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); - std::uint32_t const flags = - partialPayment ? (tfNoRippleDirect | tfPartialPayment) : tfNoRippleDirect; + std::uint32_t const flags = partialPayment + ? (kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT) + : kTF_NO_RIPPLE_DIRECT; - TER const expectedTer = partialPayment ? TER{tesSUCCESS} : TER{tecPATH_PARTIAL}; + TER const expectedTer = partialPayment ? TER{TesSuccess} : TER{TecPathPartial}; - env(pay(alice, bob, USD(5'000)), - path(~USD), - sendmax(EUR(100)), - txflags(flags), - ter(expectedTer)); + env(pay(alice, bob, usd(5'000)), + Path(~usd), + Sendmax(eur(100)), + Txflags(flags), + Ter(expectedTer)); env.close(); - if (expectedTer == tesSUCCESS) + if (expectedTer == TesSuccess) { // carol's offer can be partially crossed when EUR is IOU: // 10e-3EUR/1USD - using tEUR = std::decay_t; - bool constexpr isEURIOU = std::is_same_v; + using tEUR = std::decay_t; + bool constexpr kIS_EURIOU = std::is_same_v; // partially crossed if IOU, removed but not taken if MPT - auto const balanceCarolUSD = isEURIOU ? USD(0) : initialCarolUSD; + auto const balanceCarolUSD = kIS_EURIOU ? usd(0) : initialCarolUSD; env.require(offers(carol, 0)); - env.require(balance(carol, balanceCarolUSD)); + env.require(Balance(carol, balanceCarolUSD)); } else { @@ -626,34 +628,34 @@ public: auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - auto const xrpOffer = XRP(1'000); + auto const xrpOffer = kXRP(1'000); // No crossing: { Env env{*this, features}; - env.fund(XRP(1'000'000), gw); + env.fund(kXRP(1'000'000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); env.fund(r + f, alice); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - auto const usdOffer = USD(1'000); + auto const usdOffer = usd(1'000); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tecINSUF_RESERVE_OFFER)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TecInsufReserveOffer)); - env.require(balance(alice, r - f), owners(alice, 1)); + env.require(Balance(alice, r - f), Owners(alice, 1)); } // Partial cross: { Env env{*this, features}; - env.fund(XRP(1'000'000), gw); + env.fund(kXRP(1'000'000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); @@ -661,24 +663,24 @@ public: env.fund(r + f, alice); env.fund(r + 2 * f + xrpOffer, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - auto const usdOffer = USD(1'000); - auto const usdOffer2 = USD(500); - auto const xrpOffer2 = XRP(500); + auto const usdOffer = usd(1'000); + auto const usdOffer2 = usd(500); + auto const xrpOffer2 = kXRP(500); - env(offer(bob, usdOffer2, xrpOffer2), ter(tesSUCCESS)); + env(offer(bob, usdOffer2, xrpOffer2), Ter(TesSuccess)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tesSUCCESS)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TesSuccess)); env.require( - balance(alice, r - f + xrpOffer2), - balance(alice, usdOffer2), - owners(alice, 1), - balance(bob, r + xrpOffer2), - balance(bob, usdOffer2), - owners(bob, 1)); + Balance(alice, r - f + xrpOffer2), + Balance(alice, usdOffer2), + Owners(alice, 1), + Balance(bob, r + xrpOffer2), + Balance(bob, usdOffer2), + Owners(bob, 1)); } // Account has enough reserve as is, but not enough @@ -687,36 +689,36 @@ public: { Env env{*this, features}; - env.fund(XRP(1'000'000), gw); + env.fund(kXRP(1'000'000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); env.fund(r + f, alice); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - auto const usdOffer = USD(1'000); - auto const usdOffer2 = USD(500); - auto const xrpOffer2 = XRP(500); + auto const usdOffer = usd(1'000); + auto const usdOffer2 = usd(500); + auto const xrpOffer2 = kXRP(500); env.fund(r + f + xrpOffer, bob, carol); - env(offer(bob, usdOffer2, xrpOffer2), ter(tesSUCCESS)); - env(offer(carol, usdOffer, xrpOffer), ter(tesSUCCESS)); + env(offer(bob, usdOffer2, xrpOffer2), Ter(TesSuccess)); + env(offer(carol, usdOffer, xrpOffer), Ter(TesSuccess)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tesSUCCESS)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TesSuccess)); env.require( - balance(alice, r - f + xrpOffer), - balance(alice, USD(0)), - owners(alice, 1), - balance(bob, r + xrpOffer2), - balance(bob, usdOffer2), - owners(bob, 1), - balance(carol, r + xrpOffer2), - balance(carol, usdOffer2), - owners(carol, 2)); + Balance(alice, r - f + xrpOffer), + Balance(alice, usd(0)), + Owners(alice, 1), + Balance(bob, r + xrpOffer2), + Balance(bob, usdOffer2), + Owners(bob, 1), + Balance(carol, r + xrpOffer2), + Balance(carol, usdOffer2), + Owners(carol, 2)); } } @@ -739,7 +741,7 @@ public: using namespace jtx; - auto const startBalance = XRP(1'000'000); + auto const startBalance = kXRP(1'000'000); auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; @@ -755,50 +757,50 @@ public: env.fund(startBalance, gw, alice, bob); - MPTTester MUSD({.env = env, .issuer = gw}); - MPT const USD = MUSD["USD"]; + MPTTester musd({.env = env, .issuer = gw}); + MPT const usd = musd["USD"]; // bob creates an offer that expires before the next ledger close. - env(offer(bob, USD(500), XRP(500)), - json(sfExpiration.fieldName, lastClose(env) + 1), - ter(tesSUCCESS)); + env(offer(bob, usd(500), kXRP(500)), + Json(sfExpiration.fieldName, lastClose(env) + 1), + Ter(TesSuccess)); // The offer expires (it's not removed yet). env.close(); - env.require(owners(bob, 1), offers(bob, 1)); + env.require(Owners(bob, 1), offers(bob, 1)); // bob creates the offer that will be crossed. - env(offer(bob, USD(500), XRP(500)), ter(tesSUCCESS)); + env(offer(bob, usd(500), kXRP(500)), Ter(TesSuccess)); env.close(); - env.require(owners(bob, 2), offers(bob, 2)); + env.require(Owners(bob, 2), offers(bob, 2)); - MUSD.authorize({.account = alice}); - env(pay(gw, alice, USD(1'000)), ter(tesSUCCESS)); + musd.authorize({.account = alice}); + env(pay(gw, alice, usd(1'000)), Ter(TesSuccess)); // Order that can't be filled but will remove bob's expired offer: - env(offer(alice, XRP(1'000), USD(1'000)), txflags(tfFillOrKill), ter(tecKILLED)); + env(offer(alice, kXRP(1'000), usd(1'000)), Txflags(kTF_FILL_OR_KILL), Ter(TecKilled)); env.require( - balance(alice, startBalance - (f * 2)), - balance(alice, USD(1'000)), - owners(alice, 1), + Balance(alice, startBalance - (f * 2)), + Balance(alice, usd(1'000)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - (f * 2)), - balance(bob, USD(none)), - owners(bob, 1), + Balance(bob, startBalance - (f * 2)), + Balance(bob, usd(kNONE)), + Owners(bob, 1), offers(bob, 1)); // Order that can be filled - env(offer(alice, XRP(500), USD(500)), txflags(tfFillOrKill), ter(tesSUCCESS)); + env(offer(alice, kXRP(500), usd(500)), Txflags(kTF_FILL_OR_KILL), Ter(TesSuccess)); env.require( - balance(alice, startBalance - (f * 3) + XRP(500)), - balance(alice, USD(500)), - owners(alice, 1), + Balance(alice, startBalance - (f * 3) + kXRP(500)), + Balance(alice, usd(500)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - (f * 2) - XRP(500)), - balance(bob, USD(500)), - owners(bob, 1), + Balance(bob, startBalance - (f * 2) - kXRP(500)), + Balance(bob, usd(500)), + Owners(bob, 1), offers(bob, 0)); } @@ -811,49 +813,51 @@ public: env.fund(startBalance, gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - env(pay(gw, alice, USD(1'000)), ter(tesSUCCESS)); + env(pay(gw, alice, usd(1'000)), Ter(TesSuccess)); // No cross: { - env(offer(alice, XRP(1'000), USD(1000)), - txflags(tfImmediateOrCancel), - ter(tecKILLED)); + env(offer(alice, kXRP(1'000), usd(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL), + Ter(TecKilled)); } env.require( - balance(alice, startBalance - f - f), - balance(alice, USD(1000)), - owners(alice, 1), + Balance(alice, startBalance - f - f), + Balance(alice, usd(1000)), + Owners(alice, 1), offers(alice, 0)); // Partially cross: - env(offer(bob, USD(50), XRP(50)), ter(tesSUCCESS)); - env(offer(alice, XRP(1000), USD(1000)), txflags(tfImmediateOrCancel), ter(tesSUCCESS)); + env(offer(bob, usd(50), kXRP(50)), Ter(TesSuccess)); + env(offer(alice, kXRP(1000), usd(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL), + Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f + XRP(50)), - balance(alice, USD(950)), - owners(alice, 1), + Balance(alice, startBalance - f - f - f + kXRP(50)), + Balance(alice, usd(950)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - f - XRP(50)), - balance(bob, USD(50)), - owners(bob, 1), + Balance(bob, startBalance - f - kXRP(50)), + Balance(bob, usd(50)), + Owners(bob, 1), offers(bob, 0)); // Fully cross: - env(offer(bob, USD(50), XRP(50)), ter(tesSUCCESS)); - env(offer(alice, XRP(50), USD(50)), txflags(tfImmediateOrCancel), ter(tesSUCCESS)); + env(offer(bob, usd(50), kXRP(50)), Ter(TesSuccess)); + env(offer(alice, kXRP(50), usd(50)), Txflags(kTF_IMMEDIATE_OR_CANCEL), Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f - f + XRP(100)), - balance(alice, USD(900)), - owners(alice, 1), + Balance(alice, startBalance - f - f - f - f + kXRP(100)), + Balance(alice, usd(900)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - f - f - XRP(100)), - balance(bob, USD(100)), - owners(bob, 1), + Balance(bob, startBalance - f - f - kXRP(100)), + Balance(bob, usd(100)), + Owners(bob, 1), offers(bob, 0)); } @@ -864,12 +868,12 @@ public: env.fund(startBalance, gw, alice, bob); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); - env(pay(gw, bob, USD(1'000))); + env(pay(gw, bob, usd(1'000))); env.close(); - env(offer(alice, USD(1'000), XRP(2'000))); + env(offer(alice, usd(1'000), kXRP(2'000))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -877,13 +881,13 @@ public: for (auto const& offerPtr : aliceOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == XRP(2'000)); - BEAST_EXPECT(offer[sfTakerPays] == USD(1'000)); + BEAST_EXPECT(offer[sfTakerGets] == kXRP(2'000)); + BEAST_EXPECT(offer[sfTakerPays] == usd(1'000)); } // bob creates a passive offer that could cross alice's. // bob's offer should stay in the ledger. - env(offer(bob, XRP(2'000), USD(1'000), tfPassive)); + env(offer(bob, kXRP(2'000), usd(1'000), kTF_PASSIVE)); env.close(); env.require(offers(alice, 1)); @@ -892,18 +896,18 @@ public: for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == USD(1'000)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(2'000)); + BEAST_EXPECT(offer[sfTakerGets] == usd(1'000)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(2'000)); } // It should be possible for gw to cross both of those offers. - env(offer(gw, XRP(2'000), USD(1'000))); + env(offer(gw, kXRP(2'000), usd(1'000))); env.close(); env.require(offers(alice, 0)); env.require(offers(gw, 0)); env.require(offers(bob, 1)); - env(offer(gw, USD(1'000), XRP(2'000))); + env(offer(gw, usd(1'000), kXRP(2'000))); env.close(); env.require(offers(bob, 0)); env.require(offers(gw, 0)); @@ -916,13 +920,13 @@ public: env.fund(startBalance, gw, "alice", "bob"); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); - env(pay(gw, "bob", USD(10'000))); - env(offer("alice", USD(5'000), XRP(1'001))); + env(pay(gw, "bob", usd(10'000))); + env(offer("alice", usd(5'000), kXRP(1'001))); env.close(); - env(offer("alice", USD(5'000), XRP(1'000))); + env(offer("alice", usd(5'000), kXRP(1'000))); env.close(); auto const aliceOffers = offersOnAccount(env, "alice"); @@ -931,7 +935,7 @@ public: // bob creates a passive offer. That offer should cross one // of alice's (the one with better quality) and leave alice's // other offer untouched. - env(offer("bob", XRP(2'000), USD(10'000), tfPassive)); + env(offer("bob", kXRP(2'000), usd(10'000), kTF_PASSIVE)); env.close(); env.require(offers("alice", 1)); @@ -940,8 +944,8 @@ public: for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == USD(4'995)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(999)); + BEAST_EXPECT(offer[sfTakerGets] == usd(4'995)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(999)); } } } @@ -953,7 +957,7 @@ public: using namespace jtx; - auto const startBalance = XRP(1'000'000); + auto const startBalance = kXRP(1'000'000); auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; @@ -961,28 +965,28 @@ public: env.fund(startBalance, gw, alice); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); // Sell and buy the same asset { // Alice tries an MPT to MPT order: - env(pay(gw, alice, USD(1'000)), ter(tesSUCCESS)); - env(offer(alice, USD(1'000), USD(1'000)), ter(temREDUNDANT)); - env.require(owners(alice, 1), offers(alice, 0)); + env(pay(gw, alice, usd(1'000)), Ter(TesSuccess)); + env(offer(alice, usd(1'000), usd(1'000)), Ter(TemRedundant)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Offers with negative amounts { - env(offer(alice, -USD(1'000), XRP(1'000)), ter(temBAD_OFFER)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, -usd(1'000), kXRP(1'000)), Ter(TemBadOffer)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Bad MPT { - auto const BAD = MPT(badMPT()); + auto const bad = MPT(badMPT()); - env(offer(alice, XRP(1'000), BAD(1'000)), ter(temBAD_CURRENCY)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, kXRP(1'000), bad(1'000)), Ter(TemBadCurrency)); + env.require(Owners(alice, 1), offers(alice, 0)); } } @@ -997,8 +1001,8 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const startBalance = XRP(1'000'000); - auto const xrpOffer = XRP(1'000); + auto const startBalance = kXRP(1'000'000); + auto const xrpOffer = kXRP(1'000); Env env{*this, features}; @@ -1007,59 +1011,59 @@ public: auto const f = env.current()->fees().base; - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - auto const usdOffer = USD(1'000); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + auto const usdOffer = usd(1'000); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); env.close(); env.require( - balance(alice, startBalance - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1)); + Owners(alice, 1)); // Place an offer that should have already expired. env(offer(alice, xrpOffer, usdOffer), - json(sfExpiration.fieldName, lastClose(env)), - ter(TER{tecEXPIRED})); + Json(sfExpiration.fieldName, lastClose(env)), + Ter(TER{TecExpired})); env.require( - balance(alice, startBalance - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1)); + Owners(alice, 1)); env.close(); // Add an offer that expires before the next ledger close env(offer(alice, xrpOffer, usdOffer), - json(sfExpiration.fieldName, lastClose(env) + 1), - ter(tesSUCCESS)); + Json(sfExpiration.fieldName, lastClose(env) + 1), + Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 1), - owners(alice, 2)); + Owners(alice, 2)); // The offer expires (it's not removed yet) env.close(); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 1), - owners(alice, 2)); + Owners(alice, 2)); // Add offer - the expired offer is removed - env(offer(bob, usdOffer, xrpOffer), ter(tesSUCCESS)); + env(offer(bob, usdOffer, xrpOffer), Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1), - balance(bob, startBalance - f), - balance(bob, USD(none)), + Owners(alice, 1), + Balance(bob, startBalance - f), + Balance(bob, usd(kNONE)), offers(bob, 1), - owners(bob, 1)); + Owners(bob, 1)); } void @@ -1071,11 +1075,11 @@ public: auto const gw = Account{"gateway"}; - auto const xrpOffer = XRP(1'000); + auto const xrpOffer = kXRP(1'000); Env env{*this, features}; - env.fund(XRP(1'000'000), gw); + env.fund(kXRP(1'000'000), gw); // The fee that's charged for transactions auto const f = env.current()->fees().base; @@ -1083,41 +1087,41 @@ public: // Account is at the reserve, and will dip below once // fees are subtracted. env.fund(reserve(env, 0), "alice"); - MPT const USD = MPTTester({.env = env, .issuer = gw}); - auto const usdOffer = USD(1'000); - env(offer("alice", usdOffer, xrpOffer), ter(tecUNFUNDED_OFFER)); - env.require(balance("alice", reserve(env, 0) - f), owners("alice", 0)); + MPT const usd = MPTTester({.env = env, .issuer = gw}); + auto const usdOffer = usd(1'000); + env(offer("alice", usdOffer, xrpOffer), Ter(TecUnfundedOffer)); + env.require(Balance("alice", reserve(env, 0) - f), Owners("alice", 0)); // Account has just enough for the reserve and the // fee. env.fund(reserve(env, 0) + f, "bob"); - env(offer("bob", usdOffer, xrpOffer), ter(tecUNFUNDED_OFFER)); - env.require(balance("bob", reserve(env, 0)), owners("bob", 0)); + env(offer("bob", usdOffer, xrpOffer), Ter(TecUnfundedOffer)); + env.require(Balance("bob", reserve(env, 0)), Owners("bob", 0)); // Account has enough for the reserve, the fee and // the offer, and a bit more, but not enough for the // reserve after the offer is placed. - env.fund(reserve(env, 0) + f + XRP(1), "carol"); - env(offer("carol", usdOffer, xrpOffer), ter(tecINSUF_RESERVE_OFFER)); - env.require(balance("carol", reserve(env, 0) + XRP(1)), owners("carol", 0)); + env.fund(reserve(env, 0) + f + kXRP(1), "carol"); + env(offer("carol", usdOffer, xrpOffer), Ter(TecInsufReserveOffer)); + env.require(Balance("carol", reserve(env, 0) + kXRP(1)), Owners("carol", 0)); // Account has enough for the reserve plus one // offer, and the fee. env.fund(reserve(env, 1) + f, "dan"); - env(offer("dan", usdOffer, xrpOffer), ter(tesSUCCESS)); - env.require(balance("dan", reserve(env, 1)), owners("dan", 1)); + env(offer("dan", usdOffer, xrpOffer), Ter(TesSuccess)); + env.require(Balance("dan", reserve(env, 1)), Owners("dan", 1)); // Account has enough for the reserve plus one // offer, the fee and the entire offer amount. env.fund(reserve(env, 1) + f + xrpOffer, "eve"); - env(offer("eve", usdOffer, xrpOffer), ter(tesSUCCESS)); - env.require(balance("eve", reserve(env, 1) + xrpOffer), owners("eve", 1)); + env(offer("eve", usdOffer, xrpOffer), Ter(TesSuccess)); + env.require(Balance("eve", reserve(env, 1) + xrpOffer), Owners("eve", 1)); } void - testSelfCross(bool use_partner, FeatureBitset features) + testSelfCross(bool usePartner, FeatureBitset features) { - testcase(std::string("Self-crossing") + (use_partner ? ", with partner account" : "")); + testcase(std::string("Self-crossing") + (usePartner ? ", with partner account" : "")); using namespace jtx; auto const gw = Account{"gateway"}; @@ -1127,71 +1131,71 @@ public: Env env{*this, features}; env.close(); - env.fund(XRP(10'000), gw); - auto const USD = issue1({.env = env, .token = "USD", .issuer = gw}); - auto const BTC = issue2({.env = env, .token = "BTC", .issuer = gw}); - using tUSD = std::decay_t; - using tBTC = std::decay_t; - if (use_partner) + env.fund(kXRP(10'000), gw); + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw}); + auto const btc = issue2({.env = env, .token = "BTC", .issuer = gw}); + using tUSD = std::decay_t; + using tBTC = std::decay_t; + if (usePartner) { - env.fund(XRP(10'000), partner); + env.fund(kXRP(10'000), partner); if constexpr (std::is_same_v) { - env(trust(partner, USD(100))); + env(trust(partner, usd(100))); } else { - MPTTester MUSD(env, gw, USD); - MUSD.authorize({.account = partner}); + MPTTester musd(env, gw, usd); + musd.authorize({.account = partner}); } if constexpr (std::is_same_v) { - env(trust(partner, BTC(500))); + env(trust(partner, btc(500))); } else { - MPTTester MBTC(env, gw, BTC); - MBTC.authorize({.account = partner}); + MPTTester mbtc(env, gw, btc); + mbtc.authorize({.account = partner}); } - env(pay(gw, partner, USD(100))); - env(pay(gw, partner, BTC(500))); + env(pay(gw, partner, usd(100))); + env(pay(gw, partner, btc(500))); } - auto const& account_to_test = use_partner ? partner : gw; + auto const& accountToTest = usePartner ? partner : gw; env.close(); - env.require(offers(account_to_test, 0)); + env.require(offers(accountToTest, 0)); // PART 1: // we will make two offers that can be used to bridge BTC to USD // through XRP - env(offer(account_to_test, BTC(250), XRP(1'000))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, btc(250), kXRP(1'000))); + env.require(offers(accountToTest, 1)); // validate that the book now shows a BTC for XRP offer - BEAST_EXPECT(isOffer(env, account_to_test, BTC(250), XRP(1'000))); + BEAST_EXPECT(isOffer(env, accountToTest, btc(250), kXRP(1'000))); - auto const secondLegSeq = env.seq(account_to_test); - env(offer(account_to_test, XRP(1'000), USD(50))); - env.require(offers(account_to_test, 2)); + auto const secondLegSeq = env.seq(accountToTest); + env(offer(accountToTest, kXRP(1'000), usd(50))); + env.require(offers(accountToTest, 2)); // validate that the book also shows a XRP for USD offer - BEAST_EXPECT(isOffer(env, account_to_test, XRP(1'000), USD(50))); + BEAST_EXPECT(isOffer(env, accountToTest, kXRP(1'000), usd(50))); // now make an offer that will cross and auto-bridge, meaning // the outstanding offers will be taken leaving us with none - env(offer(account_to_test, USD(50), BTC(250))); + env(offer(accountToTest, usd(50), btc(250))); - auto jrr = getBookOffers(env, USD, BTC); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + auto jrr = getBookOffers(env, usd, btc); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); - jrr = getBookOffers(env, BTC, XRP); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, btc, kXRP); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); // At this point, all offers are expected to be consumed. { - auto acctOffers = offersOnAccount(env, account_to_test); + auto acctOffers = offersOnAccount(env, accountToTest); // No stale offers BEAST_EXPECT(acctOffers.empty()); @@ -1199,43 +1203,43 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(0)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(offer[sfTakerGets] == usd(0)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(0)); } } // cancel that lingering second offer so that it doesn't interfere // with the next set of offers we test. This will not be needed once // the bridging bug is fixed - env(offer_cancel(account_to_test, secondLegSeq)); - env.require(offers(account_to_test, 0)); + env(offer_cancel(accountToTest, secondLegSeq)); + env.require(offers(accountToTest, 0)); // PART 2: // simple direct crossing BTC to USD and then USD to BTC which // causes the first offer to be replaced - env(offer(account_to_test, BTC(250), USD(50))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, btc(250), usd(50))); + env.require(offers(accountToTest, 1)); // validate that the book shows one BTC for USD offer and no USD for // BTC offers - BEAST_EXPECT(isOffer(env, account_to_test, BTC(250), USD(50))); + BEAST_EXPECT(isOffer(env, accountToTest, btc(250), usd(50))); - jrr = getBookOffers(env, USD, BTC); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, usd, btc); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); // this second offer would self-cross directly, so it causes the // first offer by the same owner/taker to be removed - env(offer(account_to_test, USD(50), BTC(250))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, usd(50), btc(250))); + env.require(offers(accountToTest, 1)); // validate that we now have just the second offer...the first // was removed - jrr = getBookOffers(env, BTC, USD); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, btc, usd); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); - BEAST_EXPECT(isOffer(env, account_to_test, USD(50), BTC(250))); + BEAST_EXPECT(isOffer(env, accountToTest, usd(50), btc(250))); }; testHelper2TokensMix(test); } @@ -1258,55 +1262,55 @@ public: // these *interesting* amounts were taken // from the original JS test that was ported here - auto const gw_initial_balance = drops(1'149'999'730); - auto const alice_initial_balance = drops(499'946'999'680); - auto const bob_initial_balance = drops(10'199'999'920); + auto const gwInitialBalance = drops(1'149'999'730); + auto const aliceInitialBalance = drops(499'946'999'680); + auto const bobInitialBalance = drops(10'199'999'920); - env.fund(gw_initial_balance, gw); - env.fund(alice_initial_balance, alice); - env.fund(bob_initial_balance, bob); + env.fund(gwInitialBalance, gw); + env.fund(aliceInitialBalance, alice); + env.fund(bobInitialBalance, bob); - MPTTester const MUSD( + MPTTester const musd( {.env = env, .issuer = gw, .holders = {alice, bob}, .transferFee = 5'000}); - MPT const USD = MUSD; - auto const small_amount = STAmount{USD, 1}; + MPT const usd = musd; + auto const smallAmount = STAmount{usd, 1}; - env(pay(gw, alice, USD(50))); - env(pay(gw, bob, small_amount)); + env(pay(gw, alice, usd(50))); + env(pay(gw, bob, smallAmount)); - env(offer(alice, USD(50), XRP(150'000))); + env(offer(alice, usd(50), kXRP(150'000))); // unfund the offer - env(pay(alice, gw, USD(50))); + env(pay(alice, gw, usd(50))); // verify balances - auto jrr = ledgerEntryMPT(env, alice, USD); + auto jrr = ledgerEntryMPT(env, alice, usd); // this represents 0 since MPTAmount is a default field - BEAST_EXPECT(!jrr[jss::node].isMember(sfMPTAmount.fieldName)); + BEAST_EXPECT(!jrr[jss::kNODE].isMember(sfMPTAmount.fieldName)); - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "1"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "1"); // create crossing offer std::uint32_t const bobOfferSeq = env.seq(bob); - env(offer(bob, XRP(2000), USD(1))); + env(offer(bob, kXRP(2000), usd(1))); // With the rounding introduced by fixReducedOffersV2, bob's // offer does not cross alice's offer and goes straight into // the ledger. - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "1"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "1"); - Json::Value const bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq)[jss::node]; - BEAST_EXPECT(bobOffer[sfTakerGets.jsonName][jss::value] == "1"); + Json::Value const bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq)[jss::kNODE]; + BEAST_EXPECT(bobOffer[sfTakerGets.jsonName][jss::kVALUE] == "1"); BEAST_EXPECT(bobOffer[sfTakerPays.jsonName] == "2000000000"); } void - testOfferCrossWithXRP(bool reverse_order, FeatureBitset features) + testOfferCrossWithXRP(bool reverseOrder, FeatureBitset features) { testcase( - std::string("Offer Crossing with XRP, ") + (reverse_order ? "Reverse" : "Normal") + + std::string("Offer Crossing with XRP, ") + (reverseOrder ? "Reverse" : "Normal") + " order"); using namespace jtx; @@ -1317,40 +1321,40 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(10'000), gw, alice, bob); + env.fund(kXRP(10'000), gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env(pay(gw, alice, USD(500))); + env(pay(gw, alice, usd(500))); - if (reverse_order) - env(offer(bob, USD(1), XRP(4'000))); + if (reverseOrder) + env(offer(bob, usd(1), kXRP(4'000))); - env(offer(alice, XRP(150'000), USD(50))); + env(offer(alice, kXRP(150'000), usd(50))); - if (!reverse_order) - env(offer(bob, USD(1), XRP(4000))); + if (!reverseOrder) + env(offer(bob, usd(1), kXRP(4000))); // Existing offer pays better than this wants. // Fully consume existing offer. // Pay 1 USD, get 4000 XRP. - auto jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "1"); + auto jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "1"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == to_string( - (XRP(10000) - XRP(reverse_order ? 4000 : 3000) - env.current()->fees().base * 2) + (kXRP(10000) - kXRP(reverseOrder ? 4000 : 3000) - env.current()->fees().base * 2) .xrp())); - jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "499"); + jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "499"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == to_string( - (XRP(10000) + XRP(reverse_order ? 4000 : 3000) - env.current()->fees().base * 2) + (kXRP(10000) + kXRP(reverseOrder ? 4000 : 3000) - env.current()->fees().base * 2) .xrp())); } @@ -1367,28 +1371,28 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(100000), gw, alice, bob); + env.fund(kXRP(100000), gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - env(pay(gw, alice, USD(500))); + env(pay(gw, alice, usd(500))); - env(offer(alice, XRP(150'000), USD(50))); - env(offer(bob, USD(1), XRP(3'000))); + env(offer(alice, kXRP(150'000), usd(50))); + env(offer(bob, usd(1), kXRP(3'000))); - auto jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "1"); + auto jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "1"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(100'000) - XRP(3'000) - env.current()->fees().base * 1).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(100'000) - kXRP(3'000) - env.current()->fees().base * 1).xrp())); - jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "499"); + jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "499"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(100'000) + XRP(3'000) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(100'000) + kXRP(3'000) - env.current()->fees().base * 2).xrp())); } void @@ -1400,10 +1404,10 @@ public: Env env{*this, features}; - MPT const USD = MPTTester({.env = env, .issuer = env.master}); + MPT const usd = MPTTester({.env = env, .issuer = env.master}); auto const nextOfferSeq = env.seq(env.master); - env(offer(env.master, XRP(500), USD(100))); + env(offer(env.master, kXRP(500), usd(100))); env.close(); env(offer_cancel(env.master, nextOfferSeq)); @@ -1428,38 +1432,39 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(10'000), gw, alice, bob); - env.require(owners(bob, 0)); + env.fund(kXRP(10'000), gw, alice, bob); + env.require(Owners(bob, 0)); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env.require(owners(alice, 1), owners(bob, 1)); + env.require(Owners(alice, 1), Owners(bob, 1)); - env(pay(gw, alice, USD(100))); + env(pay(gw, alice, usd(100))); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, USD(100), XRP(500))); + env(offer(bob, usd(100), kXRP(500))); - env.require(owners(alice, 1), owners(bob, 2)); + env.require(Owners(alice, 1), Owners(bob, 2)); auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(500).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(100).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(500).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(100).value().getJson(JsonOptions::None)); - env(pay(alice, alice, XRP(500)), sendmax(USD(100))); + env(pay(alice, alice, kXRP(500)), Sendmax(usd(100))); - auto jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(!jrr[jss::node].isMember(sfMPTAmount.fieldName)); + auto jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(!jrr[jss::kNODE].isMember(sfMPTAmount.fieldName)); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10'000) + XRP(500) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(10'000) + kXRP(500) - env.current()->fees().base * 2).xrp())); - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "100"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "100"); jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); - env.require(owners(alice, 1), owners(bob, 1)); + env.require(Owners(alice, 1), Owners(bob, 1)); } void @@ -1475,22 +1480,22 @@ public: auto test = [&](auto&& issue1, auto&& issue2, auto&& issue3) { Env env{*this, features}; - env.fund(XRP(10'000), alice, bob, carol); + env.fund(kXRP(10'000), alice, bob, carol); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = alice, .holders = {bob}}); - auto const EURC = + auto const eurc = issue2({.env = env, .token = "EUC", .issuer = carol, .holders = {alice}}); - auto const EURB = + auto const eurb = issue3({.env = env, .token = "EUB", .issuer = bob, .holders = {carol}}); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, USD(50), EURC(200)), ter(tecUNFUNDED_OFFER)); + env(offer(bob, usd(50), eurc(200)), Ter(TecUnfundedOffer)); - env(offer(alice, EURC(200), USD(50))); + env(offer(alice, eurc(200), usd(50))); auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); }; testHelper3TokensMix(test); } @@ -1508,64 +1513,66 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(10'000), gw, alice, bob); + env.fund(kXRP(10'000), gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env(pay(gw, alice, USD(200))); + env(pay(gw, alice, usd(200))); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, USD(100), XRP(500))); + env(offer(bob, usd(100), kXRP(500))); - env(pay(alice, alice, XRP(200)), sendmax(USD(100))); + env(pay(alice, alice, kXRP(200)), Sendmax(usd(100))); // The previous payment reduced the remaining offer amount by 200 XRP auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(300).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(60).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(300).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(60).value().getJson(JsonOptions::None)); // the balance between alice and gw is 160 USD..200 less the 40 taken // by the offer - auto jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "160"); + auto jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "160"); // alice now has 200 more XRP from the payment jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10'000) + XRP(200) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(10'000) + kXRP(200) - env.current()->fees().base * 2).xrp())); // bob got 40 USD from partial consumption of the offer - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "40"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "40"); // Alice converts USD to XRP which should fail // due to PartialPayment. - env(pay(alice, alice, XRP(600)), sendmax(USD(100)), ter(tecPATH_PARTIAL)); + env(pay(alice, alice, kXRP(600)), Sendmax(usd(100)), Ter(TecPathPartial)); // Alice converts USD to XRP, should succeed because // we permit partial payment - env(pay(alice, alice, XRP(600)), sendmax(USD(100)), txflags(tfPartialPayment)); + env(pay(alice, alice, kXRP(600)), Sendmax(usd(100)), Txflags(kTF_PARTIAL_PAYMENT)); // Verify the offer was consumed jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); // verify balances look right after the partial payment // only 300 XRP should have been payed since that's all // that remained in the offer from bob. The alice balance is now // 100 USD because another 60 USD were transferred to bob in the second // payment - jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "100"); + jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "100"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10'000) + XRP(200) + XRP(300) - env.current()->fees().base * 4).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string( + (kXRP(10'000) + kXRP(200) + kXRP(300) - env.current()->fees().base * 4).xrp())); // bob now has 100 USD - 40 from the first payment and 60 from the // second (partial) payment - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "100"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "100"); } void @@ -1582,26 +1589,27 @@ public: auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - env.fund(XRP(10'000), gw, alice, bob, carol); + env.fund(kXRP(10'000), gw, alice, bob, carol); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {carol, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {carol, bob}}); - env(pay(gw, carol, USD(500))); + env(pay(gw, carol, usd(500))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, XRP(500), USD(50))); + env(offer(carol, kXRP(500), usd(50))); - env(pay(alice, bob, USD(25)), sendmax(XRP(333))); + env(pay(alice, bob, usd(25)), Sendmax(kXRP(333))); - auto jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "25"); + auto jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "25"); - jrr = ledgerEntryMPT(env, carol, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "475"); + jrr = ledgerEntryMPT(env, carol, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "475"); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == USD(25).value().getJson(JsonOptions::none)); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == XRP(250).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_GETS] == usd(25).value().getJson(JsonOptions::None)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_PAYS] == kXRP(250).value().getText()); } void @@ -1618,31 +1626,32 @@ public: auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - env.fund(XRP(10'000), gw, alice, bob, carol); + env.fund(kXRP(10'000), gw, alice, bob, carol); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, carol}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, carol}}); - env(pay(gw, alice, USD(500))); + env(pay(gw, alice, usd(500))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, USD(50), XRP(500))); + env(offer(carol, usd(50), kXRP(500))); - env(pay(alice, bob, XRP(250)), sendmax(USD(333))); + env(pay(alice, bob, kXRP(250)), Sendmax(usd(333))); - auto jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "475"); + auto jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "475"); - jrr = ledgerEntryMPT(env, carol, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "25"); + jrr = ledgerEntryMPT(env, carol, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "25"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - std::to_string(XRP(10'000).value().mantissa() + XRP(250).value().mantissa())); + jrr[jss::kNODE][sfBalance.fieldName] == + std::to_string(kXRP(10'000).value().mantissa() + kXRP(250).value().mantissa())); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(250).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(25).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(250).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(25).value().getJson(JsonOptions::None)); } void @@ -1661,40 +1670,40 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(10'000), gw1, gw2, alice, bob, carol, dan); + env.fund(kXRP(10'000), gw1, gw2, alice, bob, carol, dan); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw1, .holders = {alice, carol}}); - auto const EUR = + auto const eur = issue1({.env = env, .token = "EUR", .issuer = gw2, .holders = {bob, dan}}); - env(pay(gw1, alice, USD(500))); - env(pay(gw2, dan, EUR(400))); + env(pay(gw1, alice, usd(500))); + env(pay(gw2, dan, eur(400))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, USD(50), XRP(500))); + env(offer(carol, usd(50), kXRP(500))); auto const danOfferSeq = env.seq(dan); - env(offer(dan, XRP(500), EUR(50))); + env(offer(dan, kXRP(500), eur(50))); - Json::Value jtp{Json::arrayValue}; - jtp[0u][0u][jss::currency] = "XRP"; - env(pay(alice, bob, EUR(30)), json(jss::Paths, jtp), sendmax(USD(333))); + Json::Value jtp{Json::ArrayValue}; + jtp[0u][0u][jss::kCURRENCY] = "XRP"; + env(pay(alice, bob, eur(30)), Json(jss::kPATHS, jtp), Sendmax(usd(333))); - BEAST_EXPECT(env.balance(alice, USD) == USD(470)); - BEAST_EXPECT(env.balance(bob, EUR) == EUR(30)); - BEAST_EXPECT(env.balance(carol, USD) == USD(30)); - BEAST_EXPECT(env.balance(dan, EUR) == EUR(370)); + BEAST_EXPECT(env.balance(alice, usd) == usd(470)); + BEAST_EXPECT(env.balance(bob, eur) == eur(30)); + BEAST_EXPECT(env.balance(carol, usd) == usd(30)); + BEAST_EXPECT(env.balance(dan, eur) == eur(370)); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(200).value().getText()); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(200).value().getText()); BEAST_EXPECT( - jro[jss::node][jss::TakerPays] == USD(20).value().getJson(JsonOptions::none)); + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(20).value().getJson(JsonOptions::None)); jro = ledgerEntryOffer(env, dan, danOfferSeq); BEAST_EXPECT( - jro[jss::node][jss::TakerGets] == EUR(20).value().getJson(JsonOptions::none)); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == XRP(200).value().getText()); + jro[jss::kNODE][jss::kTAKER_GETS] == eur(20).value().getJson(JsonOptions::None)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_PAYS] == kXRP(200).value().getText()); }; testHelper2TokensMix(test); } @@ -1716,21 +1725,21 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env(*this, features); - env.fund(XRP(100'000'000), alice, bob, carol, gw); + env.fund(kXRP(100'000'000), alice, bob, carol, gw); env.close(); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice, carol}}); - auto const EUR = issue1({.env = env, .token = "EUR", .issuer = gw, .holders = {bob}}); + auto const eur = issue1({.env = env, .token = "EUR", .issuer = gw, .holders = {bob}}); - env(pay(gw, alice, USD(10))); - env(pay(gw, carol, USD(3))); + env(pay(gw, alice, usd(10))); + env(pay(gw, carol, usd(3))); - env(offer(alice, EUR(2), XRP(1))); - env(offer(alice, EUR(2), XRP(1))); + env(offer(alice, eur(2), kXRP(1))); + env(offer(alice, eur(2), kXRP(1))); - env(offer(alice, XRP(1), USD(4))); - env(offer(carol, XRP(1), USD(3))); + env(offer(alice, kXRP(1), usd(4))); + env(offer(carol, kXRP(1), usd(3))); env.close(); // Bob offers to buy 10 USD for 10 EUR. @@ -1742,26 +1751,26 @@ public: // The key for this test is that Alice's XRP->USD leg goes dry // before Alice's EUR->XRP. The XRP->USD leg is the second leg // which showed some sensitivity. - env(pay(gw, bob, EUR(10))); + env(pay(gw, bob, eur(10))); env.close(); - env(offer(bob, USD(10), EUR(10))); + env(offer(bob, usd(10), eur(10))); env.close(); - env.require(balance(bob, USD(7))); - env.require(balance(bob, EUR(6))); + env.require(Balance(bob, usd(7))); + env.require(Balance(bob, eur(6))); env.require(offers(bob, 1)); - env.require(owners(bob, 3)); + env.require(Owners(bob, 3)); - env.require(balance(alice, USD(6))); - env.require(balance(alice, EUR(4))); + env.require(Balance(alice, usd(6))); + env.require(Balance(alice, eur(4))); env.require(offers(alice, 0)); - env.require(owners(alice, 2)); + env.require(Owners(alice, 2)); - env.require(balance(carol, USD(0))); - env.require(balance(carol, EUR(none))); + env.require(Balance(carol, usd(0))); + env.require(Balance(carol, eur(kNONE))); env.require(offers(carol, 0)); - env.require(owners(carol, 1)); + env.require(Owners(carol, 1)); }; testHelper2TokensMix(test); } @@ -1787,29 +1796,29 @@ public: // 1 for each trust limit == 3 (alice < mtgox/amazon/bitstamp) + // 1 for payment == 4 auto const base = env.current()->fees().base; - auto const starting_xrp = XRP(100) + env.current()->fees().accountReserve(3) + base * 4; + auto const startingXrp = kXRP(100) + env.current()->fees().accountReserve(3) + base * 4; - env.fund(starting_xrp, gw1, gw2, gw3, alice, bob); + env.fund(startingXrp, gw1, gw2, gw3, alice, bob); env.close(); - auto const USD1 = + auto const usD1 = issue1({.env = env, .token = "US1", .issuer = gw1, .holders = {alice, bob}}); - auto const USD2 = + auto const usD2 = issue2({.env = env, .token = "US2", .issuer = gw2, .holders = {alice, bob}}); - auto const USD3 = + auto const usD3 = issue3({.env = env, .token = "US3", .issuer = gw3, .holders = {alice}}); - env(pay(gw1, bob, USD1(500))); + env(pay(gw1, bob, usD1(500))); - env(offer(bob, XRP(200), USD1(200))); + env(offer(bob, kXRP(200), usD1(200))); // Alice has 350 fees - a reserve of 50 = 250 reserve = 100 // available. Ask for more than available to prove reserve works. - env(offer(alice, USD1(200), XRP(200))); + env(offer(alice, usD1(200), kXRP(200))); - BEAST_EXPECT(env.balance(alice, USD1) == USD1(100)); + BEAST_EXPECT(env.balance(alice, usD1) == usD1(100)); BEAST_EXPECT(env.balance(alice) == STAmount(env.current()->fees().accountReserve(3))); - BEAST_EXPECT(env.balance(bob, USD1) == USD1(400)); + BEAST_EXPECT(env.balance(bob, usD1) == usD1(400)); }; testHelper3TokensMix(test); } @@ -1827,21 +1836,21 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(10'000), gw, alice, bob); + env.fund(kXRP(10'000), gw, alice, bob); - MPT const CUR = + MPT const cur = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}, .transferFee = 5'000}); - env(pay(gw, bob, CUR(100))); + env(pay(gw, bob, cur(100))); - env(offer(alice, CUR(50'000), XRP(150'000))); - env(offer(bob, XRP(100), CUR(100))); + env(offer(alice, cur(50'000), kXRP(150'000))); + env(offer(bob, kXRP(100), cur(100))); - auto jrr = ledgerEntryMPT(env, alice, CUR); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "34"); + auto jrr = ledgerEntryMPT(env, alice, cur); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "34"); - jrr = ledgerEntryMPT(env, bob, CUR); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "64"); + jrr = ledgerEntryMPT(env, bob, cur); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "64"); } void @@ -1857,30 +1866,30 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const starting_xrp = - XRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; + auto const startingXrp = + kXRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env(pay(gw, bob, USD(500))); + env(pay(gw, bob, usd(500))); - env(offer(bob, XRP(200), USD(200)), json(jss::Flags, tfSell)); + env(offer(bob, kXRP(200), usd(200)), Json(jss::kFLAGS, kTF_SELL)); // Alice has 350 + fees - a reserve of 50 = 250 reserve = 100 available. // Alice has 350 + fees - a reserve of 50 = 250 reserve = 100 available. // Ask for more than available to prove reserve works. - env(offer(alice, USD(200), XRP(200)), json(jss::Flags, tfSell)); + env(offer(alice, usd(200), kXRP(200)), Json(jss::kFLAGS, kTF_SELL)); - auto jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "100"); + auto jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "100"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == STAmount(env.current()->fees().accountReserve(1)).getText()); - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "400"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "400"); } void @@ -1896,32 +1905,32 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const starting_xrp = - XRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; + auto const startingXrp = + kXRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env(pay(gw, bob, USD(500))); + env(pay(gw, bob, usd(500))); - env(offer(bob, XRP(100), USD(200))); + env(offer(bob, kXRP(100), usd(200))); // Alice has 350 fees - a reserve of 50 = 250 reserve = 100 available. // Ask for more than available to prove reserve works. // Taker pays 100 USD for 100 XRP. // Selling XRP. // Will sell all 100 XRP and get more USD than asked for. - env(offer(alice, USD(100), XRP(100)), json(jss::Flags, tfSell)); + env(offer(alice, usd(100), kXRP(100)), Json(jss::kFLAGS, kTF_SELL)); - auto jrr = ledgerEntryMPT(env, alice, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "200"); + auto jrr = ledgerEntryMPT(env, alice, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "200"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == STAmount(env.current()->fees().accountReserve(1)).getText()); - jrr = ledgerEntryMPT(env, bob, USD); - BEAST_EXPECT(jrr[jss::node][sfMPTAmount.fieldName] == "300"); + jrr = ledgerEntryMPT(env, bob, usd); + BEAST_EXPECT(jrr[jss::kNODE][sfMPTAmount.fieldName] == "300"); } void @@ -1938,52 +1947,52 @@ public: Env env{*this, features}; auto const base = env.current()->fees().base; - auto const starting_xrp = - XRP(100.1) + env.current()->fees().accountReserve(1) + base * 2; + auto const startingXrp = + kXRP(100.1) + env.current()->fees().accountReserve(1) + base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); env.close(); - auto const XTS = + auto const xts = issue1({.env = env, .token = "XTS", .issuer = gw, .holders = {alice, bob}}); - auto const XXX = + auto const xxx = issue2({.env = env, .token = "XXX", .issuer = gw, .holders = {alice, bob}}); env.close(); - env(pay(gw, alice, XTS(1'000))); - env(pay(gw, alice, XXX(100))); - env(pay(gw, bob, XTS(1'000))); - env(pay(gw, bob, XXX(100))); + env(pay(gw, alice, xts(1'000))); + env(pay(gw, alice, xxx(100))); + env(pay(gw, bob, xts(1'000))); + env(pay(gw, bob, xxx(100))); - env(offer(alice, XTS(1'000), XXX(100))); + env(offer(alice, xts(1'000), xxx(100))); // WS client is used here because the RPC client could not // be convinced to pass the build_path argument auto wsc = makeWSClient(env.app().config()); Json::Value payment; - payment[jss::secret] = toBase58(generateSeed("bob")); - payment[jss::id] = env.seq(bob); - payment[jss::build_path] = true; - payment[jss::tx_json] = pay(bob, bob, XXX(1)); - payment[jss::tx_json][jss::Sequence] = + payment[jss::kSECRET] = toBase58(generateSeed("bob")); + payment[jss::kID] = env.seq(bob); + payment[jss::kBUILD_PATH] = true; + payment[jss::kTX_JSON] = pay(bob, bob, xxx(1)); + payment[jss::kTX_JSON][jss::kSEQUENCE] = env.current()->read(keylet::account(bob.id()))->getFieldU32(sfSequence); - payment[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base); - payment[jss::tx_json][jss::SendMax] = XTS(15).value().getJson(JsonOptions::none); + payment[jss::kTX_JSON][jss::kFEE] = to_string(env.current()->fees().base); + payment[jss::kTX_JSON][jss::kSEND_MAX] = xts(15).value().getJson(JsonOptions::None); auto jrr = wsc->invoke("submit", payment); - BEAST_EXPECT(jrr[jss::status] == "success"); - BEAST_EXPECT(jrr[jss::result][jss::engine_result] == "tesSUCCESS"); + BEAST_EXPECT(jrr[jss::kSTATUS] == "success"); + BEAST_EXPECT(jrr[jss::kRESULT][jss::kENGINE_RESULT] == "tesSUCCESS"); if (wsc->version() == 2) { - BEAST_EXPECT(jrr.isMember(jss::jsonrpc) && jrr[jss::jsonrpc] == "2.0"); - BEAST_EXPECT(jrr.isMember(jss::ripplerpc) && jrr[jss::ripplerpc] == "2.0"); - BEAST_EXPECT(jrr.isMember(jss::id) && jrr[jss::id] == 5); + BEAST_EXPECT(jrr.isMember(jss::kJSONRPC) && jrr[jss::kJSONRPC] == "2.0"); + BEAST_EXPECT(jrr.isMember(jss::kRIPPLERPC) && jrr[jss::kRIPPLERPC] == "2.0"); + BEAST_EXPECT(jrr.isMember(jss::kID) && jrr[jss::kID] == 5); } - BEAST_EXPECT(env.balance(alice, XTS) == XTS(1010)); - BEAST_EXPECT(env.balance(alice, XXX) == XXX(99)); + BEAST_EXPECT(env.balance(alice, xts) == xts(1010)); + BEAST_EXPECT(env.balance(alice, xxx) == xxx(99)); - BEAST_EXPECT(env.balance(bob, XTS) == XTS(990)); - BEAST_EXPECT(env.balance(bob, XXX) == XXX(101)); + BEAST_EXPECT(env.balance(bob, xts) == xts(990)); + BEAST_EXPECT(env.balance(bob, xxx) == xxx(101)); }; testHelper2TokensMix(test); } @@ -2002,23 +2011,23 @@ public: Env env{*this, features}; - env.fund(XRP(10'000'000), gw); + env.fund(kXRP(10'000'000), gw); env.close(); - auto MUSD = MPTTester({.env = env, .issuer = gw}); - MPT const USD = MUSD; + auto musd = MPTTester({.env = env, .issuer = gw}); + MPT const usd = musd; // The fee that's charged for transactions auto const f = env.current()->fees().base; // To keep things simple all offers are 1 : 1 for XRP : USD. - enum class preAuthType { noPreAuth, acctPreAuth }; + enum class PreAuthType { NoPreAuth, AcctPreAuth }; struct TestData { std::string account; // Account operated on STAmount fundXrp; // Account funded with int bookAmount; // USD -> XRP offer on the books - preAuthType preAuth; // If true, pre-auth MPToken + PreAuthType preAuth; // If true, pre-auth MPToken int offerAmount; // Account offers this much XRP -> USD TER tec; // Returned tec code STAmount spentXrp; // Amount removed from fundXrp @@ -2031,37 +2040,37 @@ public: // clang-format off TestData const tests[]{ // acct fundXrp bookAmt preTrust offerAmt tec spentXrp balanceUSD offers owners scale - {.account="ann", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account is at the reserve, and will dip below once fees are subtracted. - {.account="bev", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account has just enough for the reserve and the fee. - {.account="cam", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account has enough for the reserve, the fee and the offer, and a bit more, but not enough for the reserve after the offer is placed. - {.account="deb", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=2 * f, .balanceUsd=USD( 1), .offers=0, .owners=1, .scale=100000}, // Account has enough to buy a little USD then the offer runs dry. - {.account="eve", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=f, .balanceUsd=USD( 0), .offers=1, .owners=1}, // No offer to cross - {.account="flo", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="gay", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1000, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 50) + f, .balanceUsd=USD( 50), .offers=0, .owners=1}, - {.account="hye", .fundXrp=XRP(1000) + 1 * f, .bookAmount=1000, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 800) + f, .balanceUsd=USD( 800), .offers=0, .owners=1}, - {.account="ivy", .fundXrp=XRP( 1) + reserve(env, 1) + 1 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="joy", .fundXrp=XRP( 1) + reserve(env, 2) + 1 * f, .bookAmount=1, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=1, .owners=2}, - {.account="kim", .fundXrp=XRP( 900) + reserve(env, 2) + 1 * f, .bookAmount=999, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="liz", .fundXrp=XRP( 998) + reserve(env, 0) + 1 * f, .bookAmount=999, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 998) + f, .balanceUsd=USD( 998), .offers=0, .owners=1}, - {.account="meg", .fundXrp=XRP( 998) + reserve(env, 1) + 1 * f, .bookAmount=999, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="nia", .fundXrp=XRP( 998) + reserve(env, 2) + 1 * f, .bookAmount=999, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=1, .owners=2}, - {.account="ova", .fundXrp=XRP( 999) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="pam", .fundXrp=XRP( 999) + reserve(env, 1) + 1 * f, .bookAmount=1000, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(1000) + f, .balanceUsd=USD( 1000), .offers=0, .owners=1}, - {.account="rae", .fundXrp=XRP( 999) + reserve(env, 2) + 1 * f, .bookAmount=1000, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(1000) + f, .balanceUsd=USD( 1000), .offers=0, .owners=1}, - {.account="sue", .fundXrp=XRP(1000) + reserve(env, 2) + 1 * f, .bookAmount=0, .preAuth=preAuthType::noPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=f, .balanceUsd=USD( 0), .offers=1, .owners=1}, + {.account="ann", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account is at the reserve, and will dip below once fees are subtracted. + {.account="bev", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account has just enough for the reserve and the fee. + {.account="cam", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account has enough for the reserve, the fee and the offer, and a bit more, but not enough for the reserve after the offer is placed. + {.account="deb", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=2 * f, .balanceUsd=usd( 1), .offers=0, .owners=1, .scale=100000}, // Account has enough to buy a little USD then the offer runs dry. + {.account="eve", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=f, .balanceUsd=usd( 0), .offers=1, .owners=1}, // No offer to cross + {.account="flo", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="gay", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1000, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 50) + f, .balanceUsd=usd( 50), .offers=0, .owners=1}, + {.account="hye", .fundXrp=kXRP(1000) + 1 * f, .bookAmount=1000, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 800) + f, .balanceUsd=usd( 800), .offers=0, .owners=1}, + {.account="ivy", .fundXrp=kXRP( 1) + reserve(env, 1) + 1 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="joy", .fundXrp=kXRP( 1) + reserve(env, 2) + 1 * f, .bookAmount=1, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=1, .owners=2}, + {.account="kim", .fundXrp=kXRP( 900) + reserve(env, 2) + 1 * f, .bookAmount=999, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="liz", .fundXrp=kXRP( 998) + reserve(env, 0) + 1 * f, .bookAmount=999, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 998) + f, .balanceUsd=usd( 998), .offers=0, .owners=1}, + {.account="meg", .fundXrp=kXRP( 998) + reserve(env, 1) + 1 * f, .bookAmount=999, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="nia", .fundXrp=kXRP( 998) + reserve(env, 2) + 1 * f, .bookAmount=999, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=1, .owners=2}, + {.account="ova", .fundXrp=kXRP( 999) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="pam", .fundXrp=kXRP( 999) + reserve(env, 1) + 1 * f, .bookAmount=1000, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(1000) + f, .balanceUsd=usd( 1000), .offers=0, .owners=1}, + {.account="rae", .fundXrp=kXRP( 999) + reserve(env, 2) + 1 * f, .bookAmount=1000, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(1000) + f, .balanceUsd=usd( 1000), .offers=0, .owners=1}, + {.account="sue", .fundXrp=kXRP(1000) + reserve(env, 2) + 1 * f, .bookAmount=0, .preAuth=PreAuthType::NoPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=f, .balanceUsd=usd( 0), .offers=1, .owners=1}, //---------------- Pre-created MPT --------------------- // Unlike from IOU, an issuer can't pre-create MPToken for an account (see similar tests in Offer_test.cpp) - {.account="ned", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="ole", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="pat", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=0, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="quy", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="ron", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=0, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="syd", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=3 * f, .balanceUsd=USD( 1), .offers=0, .owners=1, .scale=100000}, - {.account="ted", .fundXrp=XRP( 20) + reserve(env, 1) + 2 * f, .bookAmount=1000, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(20) + 2 * f, .balanceUsd=USD( 20), .offers=0, .owners=1}, - {.account="uli", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=0, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="vic", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + 2 * f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="wes", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=0, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=1, .owners=2}, - {.account="xan", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=1, .preAuth=preAuthType::acctPreAuth, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + 2 * f, .balanceUsd=USD( 1), .offers=1, .owners=2}, + {.account="ned", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="ole", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="pat", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=0, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="quy", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="ron", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=0, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="syd", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=3 * f, .balanceUsd=usd( 1), .offers=0, .owners=1, .scale=100000}, + {.account="ted", .fundXrp=kXRP( 20) + reserve(env, 1) + 2 * f, .bookAmount=1000, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(20) + 2 * f, .balanceUsd=usd( 20), .offers=0, .owners=1}, + {.account="uli", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=0, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="vic", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + 2 * f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="wes", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=0, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=1, .owners=2}, + {.account="xan", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=1, .preAuth=PreAuthType::AcctPreAuth, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + 2 * f, .balanceUsd=usd( 1), .offers=1, .owners=2}, }; // clang-format on @@ -2077,21 +2086,21 @@ public: // The gateway optionally creates an offer that would be crossed. auto const book = t.bookAmount; if (book != 0) - env(offer(gw, XRP(book), USD(book * t.scale))); + env(offer(gw, kXRP(book), usd(book * t.scale))); env.close(); std::uint32_t const gwOfferSeq = env.seq(gw) - 1; // Optionally pre-authorize MPT for acct. // Note this is not really part of the test, so we expect there // to be enough XRP reserve for acct to create the trust line. - if (t.preAuth == preAuthType::acctPreAuth) - MUSD.authorize({.account = acct}); + if (t.preAuth == PreAuthType::AcctPreAuth) + musd.authorize({.account = acct}); env.close(); { // Acct creates an offer. This is the heart of the test. auto const acctOffer = t.offerAmount; - env(offer(acct, USD(acctOffer * t.scale), XRP(acctOffer)), ter(t.tec)); + env(offer(acct, usd(acctOffer * t.scale), kXRP(acctOffer)), Ter(t.tec)); env.close(); } std::uint32_t const acctOfferSeq = env.seq(acct) - 1; @@ -2101,12 +2110,12 @@ public: return t.balanceUsd; // crossed offer has XRP available balance of 1 fee // mpt to XRP ratio is 10 - return USD(f.value() / 10); + return usd(f.value() / 10); }(); - BEAST_EXPECT(env.balance(acct, USD) == expBalanceUsd); + BEAST_EXPECT(env.balance(acct, usd) == expBalanceUsd); BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp); env.require(offers(acct, t.offers)); - env.require(owners(acct, t.owners)); + env.require(Owners(acct, t.owners)); auto acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == t.offers); @@ -2115,21 +2124,21 @@ public: auto const& acctOffer = *(acctOffers.front()); auto const leftover = t.offerAmount - t.bookAmount; - BEAST_EXPECT(acctOffer[sfTakerGets] == XRP(leftover)); - BEAST_EXPECT(acctOffer[sfTakerPays] == USD(leftover)); + BEAST_EXPECT(acctOffer[sfTakerGets] == kXRP(leftover)); + BEAST_EXPECT(acctOffer[sfTakerPays] == usd(leftover)); } - if (t.preAuth == preAuthType::noPreAuth) + if (t.preAuth == PreAuthType::NoPreAuth) { if (t.balanceUsd.value().signum() != 0) { // Verify the correct contents of MPT - BEAST_EXPECT(env.balance(acct, USD) == expBalanceUsd); + BEAST_EXPECT(env.balance(acct, usd) == expBalanceUsd); } else { // Verify that no MPT was created. - auto const sle = env.le(keylet::mptoken(USD.issuanceID, acct)); + auto const sle = env.le(keylet::mptoken(usd.issuanceID, acct)); BEAST_EXPECT(!sle); } } @@ -2155,7 +2164,7 @@ public: Env env{*this, features}; - env.fund(XRP(1'000'000), gw, bob); + env.fund(kXRP(1'000'000), gw, bob); env.close(); // The fee that's charged for transactions. @@ -2166,14 +2175,14 @@ public: env.fund(reserve(env, 2) + fee * 2, alice); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - auto const usdOffer = USD(1'000); - auto const xrpOffer = XRP(1'000); + auto const usdOffer = usd(1'000); + auto const xrpOffer = kXRP(1'000); env(pay(gw, alice, usdOffer)); env.close(); - env.require(balance(alice, usdOffer), offers(alice, 0), offers(bob, 0)); + env.require(Balance(alice, usdOffer), offers(alice, 0), offers(bob, 0)); // The scenario: // o alice has USD but wants XRP. @@ -2187,32 +2196,32 @@ public: env.close(); env.require( - balance(alice, USD(0)), - balance(bob, usdOffer), - balance(alice, aliceXRP + xrpOffer - fee), - balance(bob, bobsXRP - xrpOffer - fee), + Balance(alice, usd(0)), + Balance(bob, usdOffer), + Balance(alice, aliceXRP + xrpOffer - fee), + Balance(bob, bobsXRP - xrpOffer - fee), offers(alice, 0), offers(bob, 0)); - BEAST_EXPECT(env.balance(bob, USD) == usdOffer); + BEAST_EXPECT(env.balance(bob, usd) == usdOffer); // Make two more offers that leave one of the offers non-dry. - env(offer(alice, USD(999), XRP(999))); + env(offer(alice, usd(999), kXRP(999))); env(offer(bob, xrpOffer, usdOffer)); env.close(); - env.require(balance(alice, USD(999))); - env.require(balance(bob, USD(1))); + env.require(Balance(alice, usd(999))); + env.require(Balance(bob, usd(1))); env.require(offers(alice, 0)); - BEAST_EXPECT(env.balance(bob, USD) == USD(1)); + BEAST_EXPECT(env.balance(bob, usd) == usd(1)); { auto const bobsOffers = offersOnAccount(env, bob); BEAST_EXPECT(bobsOffers.size() == 1); auto const& bobsOffer = *(bobsOffers.front()); BEAST_EXPECT(bobsOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(bobsOffer[sfTakerGets] == USD(1)); - BEAST_EXPECT(bobsOffer[sfTakerPays] == XRP(1)); + BEAST_EXPECT(bobsOffer[sfTakerGets] == usd(1)); + BEAST_EXPECT(bobsOffer[sfTakerPays] == kXRP(1)); } } @@ -2229,7 +2238,7 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); env.close(); // The fee that's charged for transactions. @@ -2241,17 +2250,17 @@ public: env.fund(reserve(env, 3) + fee * 2, bob); env.close(); - auto const USD = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice}}); - auto const EUR = issue2({.env = env, .token = "EUR", .issuer = gw, .holders = {bob}}); + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice}}); + auto const eur = issue2({.env = env, .token = "EUR", .issuer = gw, .holders = {bob}}); - auto const usdOffer = USD(1'000); - auto const eurOffer = EUR(1'000); + auto const usdOffer = usd(1'000); + auto const eurOffer = eur(1'000); env(pay(gw, alice, usdOffer)); env(pay(gw, bob, eurOffer)); env.close(); - env.require(balance(alice, usdOffer), balance(bob, eurOffer)); + env.require(Balance(alice, usdOffer), Balance(bob, eurOffer)); // The scenario: // o alice has USD but wants EUR. @@ -2261,12 +2270,12 @@ public: env.close(); env.require( - balance(alice, eurOffer), balance(bob, usdOffer), offers(alice, 0), offers(bob, 0)); + Balance(alice, eurOffer), Balance(bob, usdOffer), offers(alice, 0), offers(bob, 0)); // Alice's offer crossing created a default EUR trustline and // Bob's offer crossing created a default USD trustline: - BEAST_EXPECT(env.balance(alice, EUR) == eurOffer); - BEAST_EXPECT(env.balance(bob, USD) == usdOffer); + BEAST_EXPECT(env.balance(alice, eur) == eurOffer); + BEAST_EXPECT(env.balance(bob, usd) == usdOffer); // Make two more offers that leave one of the offers non-dry. // Guarantee the order of application by putting a close() @@ -2274,16 +2283,16 @@ public: env(offer(bob, eurOffer, usdOffer)); env.close(); - env(offer(alice, USD(999), eurOffer)); + env(offer(alice, usd(999), eurOffer)); env.close(); env.require(offers(alice, 0)); env.require(offers(bob, 1)); - env.require(balance(alice, USD(999))); - env.require(balance(alice, EUR(1))); - env.require(balance(bob, USD(1))); - env.require(balance(bob, EUR(999))); + env.require(Balance(alice, usd(999))); + env.require(Balance(alice, eur(1))); + env.require(Balance(bob, usd(1))); + env.require(Balance(bob, eur(999))); { auto bobsOffers = offersOnAccount(env, bob); @@ -2291,42 +2300,42 @@ public: { auto const& bobsOffer = *(bobsOffers.front()); - BEAST_EXPECT(bobsOffer[sfTakerGets] == USD(1)); - BEAST_EXPECT(bobsOffer[sfTakerPays] == EUR(1)); + BEAST_EXPECT(bobsOffer[sfTakerGets] == usd(1)); + BEAST_EXPECT(bobsOffer[sfTakerPays] == eur(1)); } } // alice makes one more offer that cleans out bob's offer. - env(offer(alice, USD(1), EUR(1))); + env(offer(alice, usd(1), eur(1))); env.close(); - env.require(balance(alice, USD(1'000))); - env.require(balance(alice, EUR(none))); - env.require(balance(bob, USD(none))); - env.require(balance(bob, EUR(1'000))); + env.require(Balance(alice, usd(1'000))); + env.require(Balance(alice, eur(kNONE))); + env.require(Balance(bob, usd(kNONE))); + env.require(Balance(bob, eur(1'000))); env.require(offers(alice, 0)); env.require(offers(bob, 0)); // The two MPT that were generated by the offers still here // Unlike IOU, MPToken is not automatically deleted - if constexpr (std::is_same_v, MPT>) + if constexpr (std::is_same_v, MPT>) { - BEAST_EXPECT(env.le(keylet::mptoken(EUR.issuanceID, alice))); - auto MEUR = MPTTester(env, gw, EUR, {bob}); + BEAST_EXPECT(env.le(keylet::mptoken(eur.issuanceID, alice))); + auto meur = MPTTester(env, gw, eur, {bob}); // Delete created MPToken to free up reserve - MEUR.authorize({.account = alice, .flags = tfMPTUnauthorize}); + meur.authorize({.account = alice, .flags = kTF_MPT_UNAUTHORIZE}); } - if constexpr (std::is_same_v, MPT>) + if constexpr (std::is_same_v, MPT>) { - BEAST_EXPECT(env.le(keylet::mptoken(USD.issuanceID, bob))); - auto MUSD = MPTTester(env, gw, USD, {alice}); + BEAST_EXPECT(env.le(keylet::mptoken(usd.issuanceID, bob))); + auto musd = MPTTester(env, gw, usd, {alice}); // Delete created MPToken to free up reserve - MUSD.authorize({.account = bob, .flags = tfMPTUnauthorize}); + musd.authorize({.account = bob, .flags = kTF_MPT_UNAUTHORIZE}); } // Make two more offers that leave one of the offers non-dry. We // need to properly sequence the transactions: - env(offer(alice, EUR(999), usdOffer)); + env(offer(alice, eur(999), usdOffer)); env.close(); env(offer(bob, usdOffer, eurOffer)); @@ -2335,10 +2344,10 @@ public: env.require(offers(alice, 0)); env.require(offers(bob, 0)); - env.require(balance(alice, USD(0))); - env.require(balance(alice, EUR(999))); - env.require(balance(bob, USD(1'000))); - env.require(balance(bob, EUR(1))); + env.require(Balance(alice, usd(0))); + env.require(Balance(alice, eur(999))); + env.require(Balance(bob, usd(1'000))); + env.require(Balance(bob, eur(1))); }; testHelper2TokensMix(test); } @@ -2357,14 +2366,14 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(1'000'000), gw, alice, bob, carol); + env.fund(kXRP(1'000'000), gw, alice, bob, carol); env.close(); - auto const USD = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice}}); - auto const EUR = issue2({.env = env, .token = "EUR", .issuer = gw, .holders = {carol}}); + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw, .holders = {alice}}); + auto const eur = issue2({.env = env, .token = "EUR", .issuer = gw, .holders = {carol}}); - auto const usdOffer = USD(1'000); - auto const eurOffer = EUR(1'000); + auto const usdOffer = usd(1'000); + auto const eurOffer = eur(1'000); env(pay(gw, alice, usdOffer)); env(pay(gw, carol, eurOffer)); @@ -2376,32 +2385,32 @@ public: // o carol has EUR but wants USD. // Note that carol's offer must come last. If carol's offer is // placed before bob's or alice's, then autobridging will not occur. - env(offer(alice, XRP(1'000), usdOffer)); - env(offer(bob, eurOffer, XRP(1'000))); + env(offer(alice, kXRP(1'000), usdOffer)); + env(offer(bob, eurOffer, kXRP(1'000))); auto const bobXrpBalance = env.balance(bob); env.close(); // carol makes an offer that partially consumes alice and bob's // offers. - env(offer(carol, USD(400), EUR(400))); + env(offer(carol, usd(400), eur(400))); env.close(); env.require( - balance(alice, USD(600)), - balance(bob, EUR(400)), - balance(carol, USD(400)), - balance(bob, bobXrpBalance - XRP(400)), + Balance(alice, usd(600)), + Balance(bob, eur(400)), + Balance(carol, usd(400)), + Balance(bob, bobXrpBalance - kXRP(400)), offers(carol, 0)); - BEAST_EXPECT(env.balance(bob, EUR) == EUR(400)); - BEAST_EXPECT(env.balance(carol, USD) == USD(400)); + BEAST_EXPECT(env.balance(bob, eur) == eur(400)); + BEAST_EXPECT(env.balance(carol, usd) == usd(400)); { auto const aliceOffers = offersOnAccount(env, alice); BEAST_EXPECT(aliceOffers.size() == 1); auto const& aliceOffer = *(aliceOffers.front()); BEAST_EXPECT(aliceOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(aliceOffer[sfTakerGets] == USD(600)); - BEAST_EXPECT(aliceOffer[sfTakerPays] == XRP(600)); + BEAST_EXPECT(aliceOffer[sfTakerGets] == usd(600)); + BEAST_EXPECT(aliceOffer[sfTakerPays] == kXRP(600)); } { auto const bobsOffers = offersOnAccount(env, bob); @@ -2409,24 +2418,24 @@ public: auto const& bobsOffer = *(bobsOffers.front()); BEAST_EXPECT(bobsOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(bobsOffer[sfTakerGets] == XRP(600)); - BEAST_EXPECT(bobsOffer[sfTakerPays] == EUR(600)); + BEAST_EXPECT(bobsOffer[sfTakerGets] == kXRP(600)); + BEAST_EXPECT(bobsOffer[sfTakerPays] == eur(600)); } // carol makes an offer that exactly consumes alice and bob's // offers. - env(offer(carol, USD(600), EUR(600))); + env(offer(carol, usd(600), eur(600))); env.close(); env.require( - balance(alice, USD(0)), - balance(bob, eurOffer), - balance(carol, usdOffer), - balance(bob, bobXrpBalance - XRP(1'000)), + Balance(alice, usd(0)), + Balance(bob, eurOffer), + Balance(carol, usdOffer), + Balance(bob, bobXrpBalance - kXRP(1'000)), offers(bob, 0), offers(carol, 0)); - BEAST_EXPECT(env.balance(bob, EUR) == EUR(1'000)); - BEAST_EXPECT(env.balance(carol, USD) == USD(1'000)); + BEAST_EXPECT(env.balance(bob, eur) == eur(1'000)); + BEAST_EXPECT(env.balance(carol, usd) == usd(1'000)); // In pre-flow code alice's offer is left empty in the ledger. auto const aliceOffers = offersOnAccount(env, alice); @@ -2436,8 +2445,8 @@ public: auto const& aliceOffer = *(aliceOffers.front()); BEAST_EXPECT(aliceOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(aliceOffer[sfTakerGets] == USD(0)); - BEAST_EXPECT(aliceOffer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(aliceOffer[sfTakerGets] == usd(0)); + BEAST_EXPECT(aliceOffer[sfTakerPays] == kXRP(0)); } }; testHelper2TokensMix(test); @@ -2457,10 +2466,10 @@ public: Env env{*this, features}; - env.fund(XRP(10'000'000), gw); + env.fund(kXRP(10'000'000), gw); - auto MUSD = MPTTester({.env = env, .issuer = gw}); - MPT const USD = MUSD; + auto musd = MPTTester({.env = env, .issuer = gw}); + MPT const usd = musd; // The fee that's charged for transactions auto const f = env.current()->fees().base; @@ -2485,64 +2494,64 @@ public: // Constructor with takerGets/takerPays TestData( - std::string&& account_, // Account operated on - STAmount fundXrp_, // XRP acct funded with - STAmount fundUSD_, // USD acct funded with - STAmount gwGets_, // gw's offer - STAmount gwPays_, // - STAmount acctGets_, // acct's offer - STAmount acctPays_, // - TER tec_, // Returned tec code - STAmount spentXrp_, // Amount removed from fundXrp - STAmount finalUsd_, // Final USD balance on acct - int offers_, // Offers on acct - int owners_, // Owners on acct - STAmount takerGets_, // Remainder of acct's offer - STAmount takerPays_) // - : account(std::move(account_)) - , fundXrp(std::move(fundXrp_)) - , fundUSD(std::move(fundUSD_)) - , gwGets(std::move(gwGets_)) - , gwPays(std::move(gwPays_)) - , acctGets(std::move(acctGets_)) - , acctPays(std::move(acctPays_)) - , tec(tec_) - , spentXrp(std::move(spentXrp_)) - , finalUsd(std::move(finalUsd_)) - , offers(offers_) - , owners(owners_) - , takerGets(std::move(takerGets_)) - , takerPays(std::move(takerPays_)) + std::string&& account, // Account operated on + STAmount fundXrp, // XRP acct funded with + STAmount fundUsd, // USD acct funded with + STAmount gwGets, // gw's offer + STAmount gwPays, // + STAmount acctGets, // acct's offer + STAmount acctPays, // + TER tec, // Returned tec code + STAmount spentXrp, // Amount removed from fundXrp + STAmount finalUsd, // Final USD balance on acct + int offers, // Offers on acct + int owners, // Owners on acct + STAmount takerGets, // Remainder of acct's offer + STAmount takerPays) // + : account(std::move(account)) + , fundXrp(std::move(fundXrp)) + , fundUSD(std::move(fundUsd)) + , gwGets(std::move(gwGets)) + , gwPays(std::move(gwPays)) + , acctGets(std::move(acctGets)) + , acctPays(std::move(acctPays)) + , tec(tec) + , spentXrp(std::move(spentXrp)) + , finalUsd(std::move(finalUsd)) + , offers(offers) + , owners(owners) + , takerGets(std::move(takerGets)) + , takerPays(std::move(takerPays)) { } // Constructor without takerGets/takerPays TestData( - std::string&& account_, // Account operated on - STAmount const& fundXrp_, // XRP acct funded with - STAmount const& fundUSD_, // USD acct funded with - STAmount const& gwGets_, // gw's offer - STAmount const& gwPays_, // - STAmount const& acctGets_, // acct's offer - STAmount const& acctPays_, // - TER tec_, // Returned tec code - STAmount const& spentXrp_, // Amount removed from fundXrp - STAmount const& finalUsd_, // Final USD balance on acct - int offers_, // Offers on acct - int owners_) // Owners on acct + std::string&& account, // Account operated on + STAmount const& fundXrp, // XRP acct funded with + STAmount const& fundUsd, // USD acct funded with + STAmount const& gwGets, // gw's offer + STAmount const& gwPays, // + STAmount const& acctGets, // acct's offer + STAmount const& acctPays, // + TER tec, // Returned tec code + STAmount const& spentXrp, // Amount removed from fundXrp + STAmount const& finalUsd, // Final USD balance on acct + int offers, // Offers on acct + int owners) // Owners on acct : TestData( - std::move(account_), - fundXrp_, - fundUSD_, - gwGets_, - gwPays_, - acctGets_, - acctPays_, - tec_, - spentXrp_, - finalUsd_, - offers_, - owners_, + std::move(account), + fundXrp, + fundUsd, + gwGets, + gwPays, + acctGets, + acctPays, + tec, + spentXrp, + finalUsd, + offers, + owners, STAmount{0}, STAmount{0}) { @@ -2553,26 +2562,26 @@ public: TestData const tests[]{ // acct pays XRP // acct fundXrp fundUSD gwGets gwPays acctGets acctPays tec spentXrp finalUSD offers owners takerGets takerPays - {"ann", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD( 5), USD(10), XRP(10), tecINSUF_RESERVE_OFFER, XRP( 0) + (1 * f), USD( 0), 0, 0}, - {"bev", XRP(10) + reserve(env, 1) + 1 * f, USD( 0), XRP(10), USD( 5), USD(10), XRP(10), tesSUCCESS, XRP( 0) + (1 * f), USD( 0), 1, 1, XRP(10), USD(10)}, - {"cam", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(10), USD(10), XRP(10), tesSUCCESS, XRP( 10) + (1 * f), USD(10), 0, 1}, - {"deb", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD(10), XRP(10), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"eve", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD( 5), XRP( 5), tesSUCCESS, XRP( 5) + (1 * f), USD(10), 0, 1}, - {"flo", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"gay", XRP(20) + reserve(env, 1) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"hye", XRP(20) + reserve(env, 2) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 1, 2, XRP(10), USD(10)}, + {"ann", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd( 5), usd(10), kXRP(10), TecInsufReserveOffer, kXRP( 0) + (1 * f), usd( 0), 0, 0}, + {"bev", kXRP(10) + reserve(env, 1) + 1 * f, usd( 0), kXRP(10), usd( 5), usd(10), kXRP(10), TesSuccess, kXRP( 0) + (1 * f), usd( 0), 1, 1, kXRP(10), usd(10)}, + {"cam", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(10), usd(10), kXRP(10), TesSuccess, kXRP( 10) + (1 * f), usd(10), 0, 1}, + {"deb", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd(10), kXRP(10), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"eve", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd( 5), kXRP( 5), TesSuccess, kXRP( 5) + (1 * f), usd(10), 0, 1}, + {"flo", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"gay", kXRP(20) + reserve(env, 1) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"hye", kXRP(20) + reserve(env, 2) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 1, 2, kXRP(10), usd(10)}, // acct pays USD - {"meg", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP( 5), XRP(10), USD(10), tecINSUF_RESERVE_OFFER, XRP( 0) + (2 * f), USD(10), 0, 1}, - {"nia", reserve(env, 2) + 2 * f, USD(10), USD(10), XRP( 5), XRP(10), USD(10), tesSUCCESS, XRP( 0) + (2 * f), USD(10), 1, 2, USD(10), XRP(10)}, - {"ova", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP(10), XRP(10), USD(10), tesSUCCESS, XRP(-10) + (2 * f), USD( 0), 0, 1}, - {"pam", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP(20), XRP(10), USD(10), tesSUCCESS, XRP(-20) + (2 * f), USD( 0), 0, 1}, - {"qui", reserve(env, 1) + 2 * f, USD(10), USD(20), XRP(40), XRP(10), USD(10), tesSUCCESS, XRP(-20) + (2 * f), USD( 0), 0, 1}, - {"rae", reserve(env, 2) + 2 * f, USD(10), USD( 5), XRP( 5), XRP(10), USD(10), tesSUCCESS, XRP( -5) + (2 * f), USD( 5), 1, 2, USD( 5), XRP( 5)}, - {"sue", reserve(env, 2) + 2 * f, USD(10), USD( 5), XRP(10), XRP(10), USD(10), tesSUCCESS, XRP(-10) + (2 * f), USD( 5), 1, 2, USD( 5), XRP( 5)}, + {"meg", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP( 5), kXRP(10), usd(10), TecInsufReserveOffer, kXRP( 0) + (2 * f), usd(10), 0, 1}, + {"nia", reserve(env, 2) + 2 * f, usd(10), usd(10), kXRP( 5), kXRP(10), usd(10), TesSuccess, kXRP( 0) + (2 * f), usd(10), 1, 2, usd(10), kXRP(10)}, + {"ova", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP(10), kXRP(10), usd(10), TesSuccess, kXRP(-10) + (2 * f), usd( 0), 0, 1}, + {"pam", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP(20), kXRP(10), usd(10), TesSuccess, kXRP(-20) + (2 * f), usd( 0), 0, 1}, + {"qui", reserve(env, 1) + 2 * f, usd(10), usd(20), kXRP(40), kXRP(10), usd(10), TesSuccess, kXRP(-20) + (2 * f), usd( 0), 0, 1}, + {"rae", reserve(env, 2) + 2 * f, usd(10), usd( 5), kXRP( 5), kXRP(10), usd(10), TesSuccess, kXRP( -5) + (2 * f), usd( 5), 1, 2, usd( 5), kXRP( 5)}, + {"sue", reserve(env, 2) + 2 * f, usd(10), usd( 5), kXRP(10), kXRP(10), usd(10), TesSuccess, kXRP(-10) + (2 * f), usd( 5), 1, 2, usd( 5), kXRP( 5)}, }; // clang-format on - auto const zeroUsd = USD(0); + auto const zeroUsd = usd(0); for (auto const& t : tests) { // Make sure gateway has no current offers. @@ -2588,7 +2597,7 @@ public: // on the trust line. if (t.fundUSD != zeroUsd) { - MUSD.authorize({.account = acct}); + musd.authorize({.account = acct}); env.close(); env(pay(gw, acct, t.fundUSD)); env.close(); @@ -2599,15 +2608,15 @@ public: std::uint32_t const gwOfferSeq = env.seq(gw) - 1; // Acct creates a tfSell offer. This is the heart of the test. - env(offer(acct, t.acctGets, t.acctPays, tfSell), ter(t.tec)); + env(offer(acct, t.acctGets, t.acctPays, kTF_SELL), Ter(t.tec)); env.close(); std::uint32_t const acctOfferSeq = env.seq(acct) - 1; // Check results - BEAST_EXPECT(env.balance(acct, USD) == t.finalUsd); + BEAST_EXPECT(env.balance(acct, usd) == t.finalUsd); BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp); env.require(offers(acct, t.offers)); - env.require(owners(acct, t.owners)); + env.require(Owners(acct, t.owners)); if (t.offers != 0) { @@ -2646,42 +2655,42 @@ public: Env env{*this, features}; - env.fund(XRP(10'000'000), gw, alice, bob); + env.fund(kXRP(10'000'000), gw, alice, bob); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); // bob offers XRP for USD. - env(pay(gw, bob, USD(100))); + env(pay(gw, bob, usd(100))); env.close(); - env(offer(bob, XRP(2'000), USD(20))); + env(offer(bob, kXRP(2'000), usd(20))); env.close(); { // alice submits a tfSell | tfFillOrKill offer that does not cross. - env(offer(alice, USD(21), XRP(2'100), tfSell | tfFillOrKill), ter(tecKILLED)); + env(offer(alice, usd(21), kXRP(2'100), kTF_SELL | kTF_FILL_OR_KILL), Ter(TecKilled)); env.close(); - env.require(balance(alice, USD(none))); + env.require(Balance(alice, usd(kNONE))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(100))); + env.require(Balance(bob, usd(100))); } { // alice submits a tfSell | tfFillOrKill offer that crosses. // Even though tfSell is present it doesn't matter this time. - env(offer(alice, USD(20), XRP(2'000), tfSell | tfFillOrKill)); + env(offer(alice, usd(20), kXRP(2'000), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(20))); + env.require(Balance(alice, usd(20))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(80))); + env.require(Balance(bob, usd(80))); } { // alice submits a tfSell | tfFillOrKill offer that crosses and // returns more than was asked for (because of the tfSell flag). - env(offer(bob, XRP(2'000), USD(20))); + env(offer(bob, kXRP(2'000), usd(20))); env.close(); - env(offer(alice, USD(10), XRP(1'500), tfSell | tfFillOrKill)); + env(offer(alice, usd(10), kXRP(1'500), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(35))); + env.require(Balance(alice, usd(35))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(65))); + env.require(Balance(bob, usd(65))); } { // alice submits a tfSell | tfFillOrKill offer that doesn't cross. @@ -2690,22 +2699,22 @@ public: // all of the offer is consumed. // We're using bob's left-over offer for XRP(500), USD(5) - env(offer(alice, USD(1), XRP(501), tfSell | tfFillOrKill), ter(tecKILLED)); + env(offer(alice, usd(1), kXRP(501), kTF_SELL | kTF_FILL_OR_KILL), Ter(TecKilled)); env.close(); - env.require(balance(alice, USD(35))); + env.require(Balance(alice, usd(35))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(65))); + env.require(Balance(bob, usd(65))); } { // Alice submits a tfSell | tfFillOrKill offer that finishes // off the remainder of bob's offer. // We're using bob's left-over offer for XRP(500), USD(5) - env(offer(alice, USD(1), XRP(500), tfSell | tfFillOrKill)); + env(offer(alice, usd(1), kXRP(500), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(40))); + env.require(Balance(alice, usd(40))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(60))); + env.require(Balance(bob, usd(60))); } } @@ -2723,32 +2732,32 @@ public: // The fee that's charged for transactions. auto const fee = env.current()->fees().base; - env.fund(XRP(100'000), gw1); + env.fund(kXRP(100'000), gw1); env.close(); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw1, .transferFee = 25'000}); - using tUSD = std::decay_t; + using tUSD = std::decay_t; { auto const ann = Account("ann"); auto const bob = Account("bob"); - env.fund(XRP(100) + reserve(env, 2) + (fee * 2), ann, bob); + env.fund(kXRP(100) + reserve(env, 2) + (fee * 2), ann, bob); env.close(); if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = ann}); - MUSD.authorize({.account = bob}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = ann}); + musd.authorize({.account = bob}); } else { - env(trust(ann, USD(20'000))); - env(trust(bob, USD(20'000))); + env(trust(ann, usd(20'000))); + env(trust(bob, usd(20'000))); env.close(); } - env(pay(gw1, bob, USD(12'500))); + env(pay(gw1, bob, usd(12'500))); env.close(); // bob offers to sell USD(100) for XRP. alice takes bob's @@ -2757,18 +2766,18 @@ public: // // A comparable payment would look like this: // env (pay (bob, alice, USD(100)), sendmax(USD(125))) - env(offer(bob, XRP(1), USD(10'000))); + env(offer(bob, kXRP(1), usd(10'000))); env.close(); - env(offer(ann, USD(10'000), XRP(1))); + env(offer(ann, usd(10'000), kXRP(1))); env.close(); - env.require(balance(ann, USD(10'000))); - env.require(balance(ann, XRP(99) + reserve(env, 2))); + env.require(Balance(ann, usd(10'000))); + env.require(Balance(ann, kXRP(99) + reserve(env, 2))); env.require(offers(ann, 0)); - env.require(balance(bob, USD(0))); - env.require(balance(bob, XRP(101) + reserve(env, 2))); + env.require(Balance(bob, usd(0))); + env.require(Balance(bob, kXRP(101) + reserve(env, 2))); env.require(offers(bob, 0)); } { @@ -2777,99 +2786,99 @@ public: // identically. auto const che = Account("che"); auto const deb = Account("deb"); - env.fund(XRP(100) + reserve(env, 2) + (fee * 2), che, deb); + env.fund(kXRP(100) + reserve(env, 2) + (fee * 2), che, deb); env.close(); if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = che}); - MUSD.authorize({.account = deb}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = che}); + musd.authorize({.account = deb}); } else { - env(trust(che, USD(20'000))); - env(trust(deb, USD(20'000))); + env(trust(che, usd(20'000))); + env(trust(deb, usd(20'000))); env.close(); } - env(pay(gw1, deb, USD(12'500))); + env(pay(gw1, deb, usd(12'500))); env.close(); - env(offer(che, USD(10'000), XRP(1))); + env(offer(che, usd(10'000), kXRP(1))); env.close(); - env(offer(deb, XRP(1), USD(10'000))); + env(offer(deb, kXRP(1), usd(10'000))); env.close(); - env.require(balance(che, USD(10'000))); - env.require(balance(che, XRP(99) + reserve(env, 2))); + env.require(Balance(che, usd(10'000))); + env.require(Balance(che, kXRP(99) + reserve(env, 2))); env.require(offers(che, 0)); - env.require(balance(deb, USD(0))); - env.require(balance(deb, XRP(101) + reserve(env, 2))); + env.require(Balance(deb, usd(0))); + env.require(Balance(deb, kXRP(101) + reserve(env, 2))); env.require(offers(deb, 0)); } { auto const eve = Account("eve"); auto const fyn = Account("fyn"); - env.fund(XRP(20'000) + (fee * 2), eve, fyn); + env.fund(kXRP(20'000) + (fee * 2), eve, fyn); env.close(); if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = eve}); - MUSD.authorize({.account = fyn}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = eve}); + musd.authorize({.account = fyn}); } else { - env(trust(eve, USD(20'000))); - env(trust(fyn, USD(20'000))); + env(trust(eve, usd(20'000))); + env(trust(fyn, usd(20'000))); env.close(); } - env(pay(gw1, eve, USD(10'000))); - env(pay(gw1, fyn, USD(10'000))); + env(pay(gw1, eve, usd(10'000))); + env(pay(gw1, fyn, usd(10'000))); env.close(); // This test verifies that the amount removed from an offer // accounts for the transfer fee that is removed from the // account but not from the remaining offer. - env(offer(eve, USD(1'000), XRP(4'000))); + env(offer(eve, usd(1'000), kXRP(4'000))); env.close(); std::uint32_t const eveOfferSeq = env.seq(eve) - 1; - env(offer(fyn, XRP(2'000), USD(500))); + env(offer(fyn, kXRP(2'000), usd(500))); env.close(); - env.require(balance(eve, USD(10'500))); - env.require(balance(eve, XRP(18'000))); + env.require(Balance(eve, usd(10'500))); + env.require(Balance(eve, kXRP(18'000))); auto const evesOffers = offersOnAccount(env, eve); BEAST_EXPECT(evesOffers.size() == 1); if (!evesOffers.empty()) { auto const& evesOffer = *(evesOffers.front()); BEAST_EXPECT(evesOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(evesOffer[sfTakerGets] == XRP(2'000)); - BEAST_EXPECT(evesOffer[sfTakerPays] == USD(500)); + BEAST_EXPECT(evesOffer[sfTakerGets] == kXRP(2'000)); + BEAST_EXPECT(evesOffer[sfTakerPays] == usd(500)); } env(offer_cancel(eve, eveOfferSeq)); // For later tests - env.require(balance(fyn, USD(9'375))); - env.require(balance(fyn, XRP(22'000))); + env.require(Balance(fyn, usd(9'375))); + env.require(Balance(fyn, kXRP(22'000))); env.require(offers(fyn, 0)); } // Start messing with two non-native currencies. auto const gw2 = Account("gateway2"); - env.fund(XRP(100'000), gw2); + env.fund(kXRP(100'000), gw2); env.close(); - auto const EUR = + auto const eur = issue2({.env = env, .token = "EUR", .issuer = gw2, .transferFee = 50'000}); - using tEUR = std::decay_t; + using tEUR = std::decay_t; { // Remove XRP from the equation. Give the two currencies two // different transfer rates so we can see both transfer rates @@ -2881,47 +2890,47 @@ public: if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = gay}); - MUSD.authorize({.account = hal}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = gay}); + musd.authorize({.account = hal}); } else { - env(trust(gay, USD(20'000))); - env(trust(hal, USD(20'000))); + env(trust(gay, usd(20'000))); + env(trust(hal, usd(20'000))); env.close(); } if constexpr (std::is_same_v) { - auto MEUR = MPTTester(env, gw2, EUR); - MEUR.authorize({.account = gay}); - MEUR.authorize({.account = hal}); + auto meur = MPTTester(env, gw2, eur); + meur.authorize({.account = gay}); + meur.authorize({.account = hal}); } else { - env(trust(gay, EUR(20'000))); - env(trust(hal, EUR(20'000))); + env(trust(gay, eur(20'000))); + env(trust(hal, eur(20'000))); env.close(); } - env(pay(gw1, gay, USD(12'500))); - env(pay(gw2, hal, EUR(150))); + env(pay(gw1, gay, usd(12'500))); + env(pay(gw2, hal, eur(150))); env.close(); - env(offer(gay, EUR(100), USD(10'000))); + env(offer(gay, eur(100), usd(10'000))); env.close(); - env(offer(hal, USD(10'000), EUR(100))); + env(offer(hal, usd(10'000), eur(100))); env.close(); - env.require(balance(gay, USD(0))); - env.require(balance(gay, EUR(100))); - env.require(balance(gay, reserve(env, 3))); + env.require(Balance(gay, usd(0))); + env.require(Balance(gay, eur(100))); + env.require(Balance(gay, reserve(env, 3))); env.require(offers(gay, 0)); - env.require(balance(hal, USD(10'000))); - env.require(balance(hal, EUR(0))); - env.require(balance(hal, reserve(env, 3))); + env.require(Balance(hal, usd(10'000))); + env.require(Balance(hal, eur(0))); + env.require(Balance(hal, reserve(env, 3))); env.require(offers(hal, 0)); } @@ -2930,7 +2939,7 @@ public: auto const ova = Account("ova"); auto const pat = Account("pat"); auto const qae = Account("qae"); - env.fund(XRP(2) + reserve(env, 3) + (fee * 3), ova, pat, qae); + env.fund(kXRP(2) + reserve(env, 3) + (fee * 3), ova, pat, qae); env.close(); // o ova has USD but wants XRP. @@ -2938,47 +2947,47 @@ public: // o qae has EUR but wants USD. if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = ova}); - MUSD.authorize({.account = pat}); - MUSD.authorize({.account = qae}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = ova}); + musd.authorize({.account = pat}); + musd.authorize({.account = qae}); } else { - env(trust(ova, USD(20'000))); - env(trust(pat, USD(20'000))); - env(trust(qae, USD(20'000))); + env(trust(ova, usd(20'000))); + env(trust(pat, usd(20'000))); + env(trust(qae, usd(20'000))); env.close(); } if constexpr (std::is_same_v) { - auto MEUR = MPTTester(env, gw2, EUR); - MEUR.authorize({.account = ova}); - MEUR.authorize({.account = pat}); - MEUR.authorize({.account = qae}); + auto meur = MPTTester(env, gw2, eur); + meur.authorize({.account = ova}); + meur.authorize({.account = pat}); + meur.authorize({.account = qae}); } else { - env(trust(ova, EUR(20'000))); - env(trust(pat, EUR(20'000))); - env(trust(qae, EUR(20'000))); + env(trust(ova, eur(20'000))); + env(trust(pat, eur(20'000))); + env(trust(qae, eur(20'000))); env.close(); } - env(pay(gw1, ova, USD(12'500))); - env(pay(gw2, qae, EUR(150))); + env(pay(gw1, ova, usd(12'500))); + env(pay(gw2, qae, eur(150))); env.close(); - env(offer(ova, XRP(2), USD(10'000))); - env(offer(pat, EUR(100), XRP(2))); + env(offer(ova, kXRP(2), usd(10'000))); + env(offer(pat, eur(100), kXRP(2))); env.close(); - env(offer(qae, USD(10'000), EUR(100))); + env(offer(qae, usd(10'000), eur(100))); env.close(); - env.require(balance(ova, USD(0))); - env.require(balance(ova, EUR(0))); - env.require(balance(ova, XRP(4) + reserve(env, 3))); + env.require(Balance(ova, usd(0))); + env.require(Balance(ova, eur(0))); + env.require(Balance(ova, kXRP(4) + reserve(env, 3))); // In pre-flow code ova's offer is left empty in the ledger. auto const ovasOffers = offersOnAccount(env, ova); @@ -2988,18 +2997,18 @@ public: auto const& ovasOffer = *(ovasOffers.front()); BEAST_EXPECT(ovasOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(ovasOffer[sfTakerGets] == USD(0)); - BEAST_EXPECT(ovasOffer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(ovasOffer[sfTakerGets] == usd(0)); + BEAST_EXPECT(ovasOffer[sfTakerPays] == kXRP(0)); } - env.require(balance(pat, USD(0))); - env.require(balance(pat, EUR(100))); - env.require(balance(pat, XRP(0) + reserve(env, 3))); + env.require(Balance(pat, usd(0))); + env.require(Balance(pat, eur(100))); + env.require(Balance(pat, kXRP(0) + reserve(env, 3))); env.require(offers(pat, 0)); - env.require(balance(qae, USD(10'000))); - env.require(balance(qae, EUR(0))); - env.require(balance(qae, XRP(2) + reserve(env, 3))); + env.require(Balance(qae, usd(10'000))); + env.require(Balance(qae, eur(0))); + env.require(Balance(qae, kXRP(2) + reserve(env, 3))); env.require(offers(qae, 0)); } }; @@ -3031,23 +3040,23 @@ public: // The fee that's charged for transactions. auto const fee = env.current()->fees().base; - auto const startBalance = XRP(1'000'000); + auto const startBalance = kXRP(1'000'000); env.fund(startBalance + (fee * 5), gw); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw}); + MPT const usd = MPTTester({.env = env, .issuer = gw}); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); // three offers + MPTokenIssuance - env.require(owners(gw, 4)); - env.require(balance(gw, startBalance + fee)); + env.require(Owners(gw, 4)); + env.require(Balance(gw, startBalance + fee)); auto gwOffers = offersOnAccount(env, gw); BEAST_EXPECT(gwOffers.size() == 3); @@ -3055,17 +3064,17 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == XRP(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(60)); + BEAST_EXPECT(offer[sfTakerGets] == kXRP(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(60)); } // Since this offer crosses the first offers, the previous offers // will be deleted and this offer will be put on the order book. - env(offer(gw, XRP(1'000), USD(100))); + env(offer(gw, kXRP(1'000), usd(100))); env.close(); - env.require(owners(gw, 2)); + env.require(Owners(gw, 2)); env.require(offers(gw, 1)); - env.require(balance(gw, startBalance)); + env.require(Balance(gw, startBalance)); gwOffers = offersOnAccount(env, gw); BEAST_EXPECT(gwOffers.size() == 1); @@ -3073,8 +3082,8 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(100)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(1'000)); + BEAST_EXPECT(offer[sfTakerGets] == usd(100)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(1'000)); } } @@ -3090,13 +3099,13 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env{*this, features}; - env.fund(XRP(1'000'000), gw1, gw2); + env.fund(kXRP(1'000'000), gw1, gw2); env.close(); - auto const USD = issue1({.env = env, .token = "USD", .issuer = gw1}); - using tUSD = std::decay_t; - auto const EUR = issue2({.env = env, .token = "EUR", .issuer = gw2}); - using tEUR = std::decay_t; + auto const usd = issue1({.env = env, .token = "USD", .issuer = gw1}); + using tUSD = std::decay_t; + auto const eur = issue2({.env = env, .token = "EUR", .issuer = gw2}); + using tEUR = std::decay_t; // The fee that's charged for transactions. auto const f = env.current()->fees().base; @@ -3115,12 +3124,12 @@ public: // clang-format off TestData const tests[]{ // acct fundXRP fundUSD fundEUR firstOfferTec secondOfferTec - {"ann", reserve(env, 3) + f * 4, USD(1000), EUR(1000), tesSUCCESS, tesSUCCESS}, - {"bev", reserve(env, 3) + f * 4, USD( 1), EUR(1000), tesSUCCESS, tesSUCCESS}, - {"cam", reserve(env, 3) + f * 4, USD(1000), EUR( 1), tesSUCCESS, tesSUCCESS}, - {"deb", reserve(env, 3) + f * 4, USD( 0), EUR( 1), tesSUCCESS, tecUNFUNDED_OFFER}, - {"eve", reserve(env, 3) + f * 4, USD( 1), EUR( 0), tecUNFUNDED_OFFER, tesSUCCESS}, - {"flo", reserve(env, 3) + 0, USD(1000), EUR(1000), tecINSUF_RESERVE_OFFER, tecINSUF_RESERVE_OFFER}, + {"ann", reserve(env, 3) + f * 4, usd(1000), eur(1000), TesSuccess, TesSuccess}, + {"bev", reserve(env, 3) + f * 4, usd( 1), eur(1000), TesSuccess, TesSuccess}, + {"cam", reserve(env, 3) + f * 4, usd(1000), eur( 1), TesSuccess, TesSuccess}, + {"deb", reserve(env, 3) + f * 4, usd( 0), eur( 1), TesSuccess, TecUnfundedOffer}, + {"eve", reserve(env, 3) + f * 4, usd( 1), eur( 0), TecUnfundedOffer, TesSuccess}, + {"flo", reserve(env, 3) + 0, usd(1000), eur(1000), TecInsufReserveOffer, TecInsufReserveOffer}, }; //clang-format on @@ -3132,39 +3141,39 @@ public: if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw1, USD); - MUSD.authorize({.account = acct}); + auto musd = MPTTester(env, gw1, usd); + musd.authorize({.account = acct}); } else { - env(trust(acct, USD(1'000))); + env(trust(acct, usd(1'000))); env.close(); } if constexpr (std::is_same_v) { - auto MEUR = MPTTester(env, gw2, EUR); - MEUR.authorize({.account = acct}); + auto meur = MPTTester(env, gw2, eur); + meur.authorize({.account = acct}); } else { - env(trust(acct, EUR(1'000))); + env(trust(acct, eur(1'000))); env.close(); } - if (t.fundUSD > USD(0)) + if (t.fundUSD > usd(0)) env(pay(gw1, acct, t.fundUSD)); - if (t.fundEUR > EUR(0)) + if (t.fundEUR > eur(0)) env(pay(gw2, acct, t.fundEUR)); env.close(); - env(offer(acct, USD(500), EUR(600)), ter(t.firstOfferTec)); + env(offer(acct, usd(500), eur(600)), Ter(t.firstOfferTec)); env.close(); std::uint32_t const firstOfferSeq = env.seq(acct) - 1; - int offerCount = t.firstOfferTec == tesSUCCESS ? 1 : 0; - env.require(owners(acct, 2 + offerCount)); - env.require(balance(acct, t.fundUSD)); - env.require(balance(acct, t.fundEUR)); + int offerCount = t.firstOfferTec == TesSuccess ? 1 : 0; + env.require(Owners(acct, 2 + offerCount)); + env.require(Balance(acct, t.fundUSD)); + env.require(Balance(acct, t.fundEUR)); auto acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == offerCount); @@ -3172,18 +3181,18 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == EUR(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(500)); + BEAST_EXPECT(offer[sfTakerGets] == eur(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(500)); } - env(offer(acct, EUR(600), USD(500)), ter(t.secondOfferTec)); + env(offer(acct, eur(600), usd(500)), Ter(t.secondOfferTec)); env.close(); std::uint32_t const secondOfferSeq = env.seq(acct) - 1; - offerCount = t.secondOfferTec == tesSUCCESS ? 1 : offerCount; - env.require(owners(acct, 2 + offerCount)); - env.require(balance(acct, t.fundUSD)); - env.require(balance(acct, t.fundEUR)); + offerCount = t.secondOfferTec == TesSuccess ? 1 : offerCount; + env.require(Owners(acct, 2 + offerCount)); + env.require(Balance(acct, t.fundUSD)); + env.require(Balance(acct, t.fundEUR)); acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == offerCount); @@ -3193,13 +3202,13 @@ public: BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); if (offer[sfSequence] == firstOfferSeq) { - BEAST_EXPECT(offer[sfTakerGets] == EUR(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(500)); + BEAST_EXPECT(offer[sfTakerGets] == eur(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(500)); } else { - BEAST_EXPECT(offer[sfTakerGets] == USD(500)); - BEAST_EXPECT(offer[sfTakerPays] == EUR(600)); + BEAST_EXPECT(offer[sfTakerGets] == usd(500)); + BEAST_EXPECT(offer[sfTakerPays] == eur(600)); } } @@ -3236,22 +3245,22 @@ public: auto const bob = Account("bob"); auto const f = env.current()->fees().base; - env.fund(XRP(50'000) + f, alice, bob); + env.fund(kXRP(50'000) + f, alice, bob); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = bob}); + MPT const usd = MPTTester({.env = env, .issuer = bob}); - env(offer(alice, USD(5'000), XRP(50'000))); + env(offer(alice, usd(5'000), kXRP(50'000))); env.close(); // This offer should take alice's offer up to Alice's reserve. - env(offer(bob, XRP(50'000), USD(5'000))); + env(offer(bob, kXRP(50'000), usd(5'000))); env.close(); // alice's offer should have been removed, since she's down to her // XRP reserve. - env.require(balance(alice, XRP(250))); - env.require(owners(alice, 1)); + env.require(Balance(alice, kXRP(250))); + env.require(Owners(alice, 1)); env.require(mptokens(alice, 1)); // However bob's offer should be in the ledger, since it was not @@ -3262,8 +3271,8 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(25)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(250)); + BEAST_EXPECT(offer[sfTakerGets] == usd(25)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(250)); } } @@ -3288,36 +3297,36 @@ public: env.fund(reserve(env, 4) + (fee * 5), ann, bob, cam); env.close(); - auto const A_BUX = issue1( + auto const aBux = issue1( {.env = env, .token = "AUX", .issuer = ann, .holders = {cam}}); - auto const B_BUX = issue2( + auto const bBux = issue2( {.env = env, .token = "BUX", .issuer = bob, .holders = {ann, cam}}); - env(pay(ann, cam, A_BUX(35))); - env(pay(bob, cam, B_BUX(35))); + env(pay(ann, cam, aBux(35))); + env(pay(bob, cam, bBux(35))); - env(offer(bob, A_BUX(30), B_BUX(30))); + env(offer(bob, aBux(30), bBux(30))); env.close(); // cam puts an offer on the books that her upcoming offer could // cross. But this offer should be deleted, not crossed, by her // upcoming offer. - env(offer(cam, A_BUX(29), B_BUX(30), tfPassive)); + env(offer(cam, aBux(29), bBux(30), kTF_PASSIVE)); env.close(); - env.require(balance(cam, A_BUX(35))); - env.require(balance(cam, B_BUX(35))); + env.require(Balance(cam, aBux(35))); + env.require(Balance(cam, bBux(35))); env.require(offers(cam, 1)); // This offer caused the assert. - env(offer(cam, B_BUX(30), A_BUX(30))); + env(offer(cam, bBux(30), aBux(30))); env.close(); - env.require(balance(bob, A_BUX(30))); - env.require(balance(cam, A_BUX(5))); - env.require(balance(cam, B_BUX(65))); + env.require(Balance(bob, aBux(30))); + env.require(Balance(cam, aBux(5))); + env.require(Balance(cam, bBux(65))); env.require(offers(cam, 0)); }; testHelper2TokensMix(test); @@ -3343,18 +3352,18 @@ public: env.fund(reserve(env, 2) + (fee * 4), gw); env.close(); - MPT const BTC = MPTTester( + MPT const btc = MPTTester( {.env = env, .issuer = gw, .holders = {ann}, .transferFee = 2'000}); - env(pay(gw, ann, BTC(2'856))); + env(pay(gw, ann, btc(2'856))); env.close(); - env(offer(ann, drops(365'611'702'030), BTC(5'713))); + env(offer(ann, drops(365'611'702'030), btc(5'713))); env.close(); // This offer caused the assert. - env(offer(ann, BTC(687), drops(20'000'000'000)), - ter(tecINSUF_RESERVE_OFFER)); + env(offer(ann, btc(687), drops(20'000'000'000)), + Ter(TecInsufReserveOffer)); } void @@ -3379,16 +3388,16 @@ public: env.fund(reserve(env, 2) + (fee * 4), gw); env.close(); - MPT const CNY = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); + MPT const cny = MPTTester({.env = env, .issuer = gw, .holders = {bob}}); - env(pay(gw, bob, CNY(3'000'000))); + env(pay(gw, bob, cny(3'000'000))); env.close(); - env(offer(bob, drops(5'400'000'000), CNY(2'160'540))); + env(offer(bob, drops(5'400'000'000), cny(2'160'540))); env.close(); // This offer did not round result of partial crossing correctly. - env(offer(alice, CNY(135'620'001), drops(339'000'000'000))); + env(offer(alice, cny(135'620'001), drops(339'000'000'000))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -3398,7 +3407,7 @@ public: auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT(offer[sfTakerGets] == drops(333'599'446'582)); - BEAST_EXPECT(offer[sfTakerPays] == CNY(13'3459'461)); + BEAST_EXPECT(offer[sfTakerPays] == cny(13'3459'461)); } } @@ -3426,32 +3435,32 @@ public: env.fund(reserve(env, 2) + (fee * 4), gw); env.close(); - auto const JPY = issue1( + auto const jpy = issue1( {.env = env, .token = "JPY", .issuer = gw, .holders = {alice}, - .limit = maxMPTokenAmount, + .limit = kMAX_MP_TOKEN_AMOUNT, .transferFee = 2'000}); - auto const BTC = issue2( + auto const btc = issue2( {.env = env, .token = "BTC", .issuer = gw, .holders = {bob}, - .limit = maxMPTokenAmount, + .limit = kMAX_MP_TOKEN_AMOUNT, .transferFee = 2'000}); - env(pay(gw, alice, JPY(3'699'034'802'280'317))); - env(pay(gw, bob, BTC(115'672'255'914'031'100))); + env(pay(gw, alice, jpy(3'699'034'802'280'317))); + env(pay(gw, bob, btc(115'672'255'914'031'100))); env.close(); env(offer( - bob, JPY(1'241'913'390'770'747), BTC(1'969'825'690'469'254))); + bob, jpy(1'241'913'390'770'747), btc(1'969'825'690'469'254))); env.close(); // This offer did not round result of partial crossing correctly. env(offer( - alice, BTC(5'507'568'706'427'876), JPY(3'472'696'773'391'072))); + alice, btc(5'507'568'706'427'876), jpy(3'472'696'773'391'072))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -3468,8 +3477,8 @@ public: // MPT test has the same order of magnitude for the scaled // values and the first 5 digits match. Is the difference due to // int arithmetics? - BEAST_EXPECT(offer[sfTakerGets] == JPY(2'230'659'191'281'247)); - BEAST_EXPECT(offer[sfTakerPays] == BTC(3'537'743'015'958'622)); + BEAST_EXPECT(offer[sfTakerGets] == jpy(2'230'659'191'281'247)); + BEAST_EXPECT(offer[sfTakerPays] == btc(3'537'743'015'958'622)); } }; testHelper2TokensMix(test); @@ -3521,24 +3530,24 @@ public: Env env{*this, features}; auto const baseFee = env.current()->fees().base.drops(); - auto const startXrpBalance = XRP(4'000'000); + auto const startXrpBalance = kXRP(4'000'000); env.fund(startXrpBalance, gw); env.close(); - auto const BTC = issue1( + auto const btc = issue1( {.env = env, .token = "BTC", .issuer = gw, .transferFee = 25'000}); - using tBTC = std::decay_t; + using tBTC = std::decay_t; env.close(); - auto const USD = issue2( + auto const usd = issue2( {.env = env, .token = "USD", .issuer = gw, .transferFee = 25'000}); - using tUSD = std::decay_t; + using tUSD = std::decay_t; env.close(); // Test cases @@ -3566,10 +3575,10 @@ public: // clang-format off TestData const tests[]{ // btcStart --------------------- actor[0] --------------------- -------------------- actor[1] ------------------- - {0, 0, 1, BTC(200), {{"ann", 0, drops(3900000'000000 - (4 * baseFee)), BTC(200), USD(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), BTC( 0), USD(750)}}}, // no BTC xfer fee - {0, 1, 0, BTC(200), {{"bev", 0, drops(4100000'000000 - (4 * baseFee)), BTC( 75), USD(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), BTC(100), USD( 0)}}}, // no USD xfer fee - {0, 0, 0, BTC(200), {{"cam", 0, drops(4000000'000000 - (5 * baseFee)), BTC(200), USD(2000)} }}, // no xfer fee - {0, 1, 0, BTC( 50), {{"deb", 1, drops(4040000'000000 - (4 * baseFee)), BTC( 0), USD(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), BTC( 40), USD( 0)}}}, // no USD xfer fee + {0, 0, 1, btc(200), {{"ann", 0, drops(3900000'000000 - (4 * baseFee)), btc(200), usd(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), btc( 0), usd(750)}}}, // no BTC xfer fee + {0, 1, 0, btc(200), {{"bev", 0, drops(4100000'000000 - (4 * baseFee)), btc( 75), usd(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), btc(100), usd( 0)}}}, // no USD xfer fee + {0, 0, 0, btc(200), {{"cam", 0, drops(4000000'000000 - (5 * baseFee)), btc(200), usd(2000)} }}, // no xfer fee + {0, 1, 0, btc( 50), {{"deb", 1, drops(4040000'000000 - (4 * baseFee)), btc( 0), usd(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), btc( 40), usd( 0)}}}, // no USD xfer fee }; // clang-format on @@ -3581,50 +3590,50 @@ public: for (auto const& actor : t.actors) { - env.fund(XRP(4'000'000), actor.acct); + env.fund(kXRP(4'000'000), actor.acct); env.close(); if constexpr (std::is_same_v) { - auto MBTC = MPTTester(env, gw, BTC); - MBTC.authorize({.account = actor.acct}); + auto mbtc = MPTTester(env, gw, btc); + mbtc.authorize({.account = actor.acct}); } else { - env(trust(actor.acct, BTC(400))); + env(trust(actor.acct, btc(400))); env.close(); } if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw, USD); - MUSD.authorize({.account = actor.acct}); + auto musd = MPTTester(env, gw, usd); + musd.authorize({.account = actor.acct}); } else { - env(trust(actor.acct, USD(8000))); + env(trust(actor.acct, usd(8000))); env.close(); } env.close(); } env(pay(gw, self, t.btcStart)); - env(pay(gw, self, USD(2'000))); + env(pay(gw, self, usd(2'000))); if (self.id() != leg1.id()) - env(pay(gw, leg1, USD(2'000))); + env(pay(gw, leg1, usd(2'000))); env.close(); // Get the initial offers in place. Remember their sequences // so we can delete them later. - env(offer(leg0, BTC(100), XRP(100'000), tfPassive)); + env(offer(leg0, btc(100), kXRP(100'000), kTF_PASSIVE)); env.close(); std::uint32_t const leg0OfferSeq = env.seq(leg0) - 1; - env(offer(leg1, XRP(100'000), USD(1'000), tfPassive)); + env(offer(leg1, kXRP(100'000), usd(1'000), kTF_PASSIVE)); env.close(); std::uint32_t const leg1OfferSeq = env.seq(leg1) - 1; // This is the offer that matters. - env(offer(self, USD(1'000), BTC(100))); + env(offer(self, usd(1'000), btc(100))); env.close(); std::uint32_t const selfOfferSeq = env.seq(self) - 1; @@ -3644,9 +3653,9 @@ public: })); BEAST_EXPECT(offerCount == actor.offers); - env.require(balance(actor.acct, actor.xrp)); - env.require(balance(actor.acct, actor.btc)); - env.require(balance(actor.acct, actor.usd)); + env.require(Balance(actor.acct, actor.xrp)); + env.require(Balance(actor.acct, actor.btc)); + env.require(Balance(actor.acct, actor.usd)); } // Remove any offers that might be left hanging around. They // could bollix up later loops. @@ -3703,17 +3712,17 @@ public: Env env{*this, features}; auto const baseFee = env.current()->fees().base.drops(); - auto const startXrpBalance = XRP(4'000'000); + auto const startXrpBalance = kXRP(4'000'000); env.fund(startXrpBalance, gw); env.close(); - auto const BTC = issue1( + auto const btc = issue1( {.env = env, .token = "BTC", .issuer = gw, .limit = 40, .transferFee = 25'000}); - using tBTC = std::decay_t; - auto const USD = issue2( + using tBTC = std::decay_t; + auto const usd = issue2( {.env = env, .token = "USD", .issuer = gw, .limit = 8'000, .transferFee = 25'000}); - using tUSD = std::decay_t; + using tUSD = std::decay_t; env.close(); // Test cases @@ -3741,8 +3750,8 @@ public: // clang-format off TestData const flowTests[]{ // btcStart ------------------- actor[0] -------------------- ------------------- actor[1] -------------------- - {0, 0, 1, BTC(5), {{"gay", 1, drops(3950000'000000 - (4 * baseFee)), BTC(5), USD (2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), BTC(0), USD(1375)}}}, // no BTC xfer fee - {0, 0, 0, BTC(5), {{"hye", 2, drops(4000000'000000 - (5 * baseFee)), BTC(5), USD (2000)} }} // no xfer fee + {0, 0, 1, btc(5), {{"gay", 1, drops(3950000'000000 - (4 * baseFee)), btc(5), usd (2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), btc(0), usd(1375)}}}, // no BTC xfer fee + {0, 0, 0, btc(5), {{"hye", 2, drops(4000000'000000 - (5 * baseFee)), btc(5), usd (2000)} }} // no xfer fee }; // clang-format on @@ -3754,49 +3763,49 @@ public: for (auto const& actor : t.actors) { - env.fund(XRP(4'000'000), actor.acct); + env.fund(kXRP(4'000'000), actor.acct); env.close(); if constexpr (std::is_same_v) { - auto MBTC = MPTTester(env, gw, BTC); - MBTC.authorize({.account = actor.acct}); + auto mbtc = MPTTester(env, gw, btc); + mbtc.authorize({.account = actor.acct}); } else { - env(trust(actor.acct, BTC(40))); + env(trust(actor.acct, btc(40))); env.close(); } if constexpr (std::is_same_v) { - auto MUSD = MPTTester(env, gw, USD); - MUSD.authorize({.account = actor.acct}); + auto musd = MPTTester(env, gw, usd); + musd.authorize({.account = actor.acct}); } else { - env(trust(actor.acct, USD(8'000))); + env(trust(actor.acct, usd(8'000))); env.close(); } } env(pay(gw, self, t.btcStart)); - env(pay(gw, self, USD(2'000))); + env(pay(gw, self, usd(2'000))); if (self.id() != leg1.id()) - env(pay(gw, leg1, USD(2'000))); + env(pay(gw, leg1, usd(2'000))); env.close(); // Get the initial offers in place. Remember their sequences // so we can delete them later. - env(offer(leg0, BTC(10), XRP(100'000), tfPassive)); + env(offer(leg0, btc(10), kXRP(100'000), kTF_PASSIVE)); env.close(); std::uint32_t const leg0OfferSeq = env.seq(leg0) - 1; - env(offer(leg1, XRP(100'000), USD(1'000), tfPassive)); + env(offer(leg1, kXRP(100'000), usd(1'000), kTF_PASSIVE)); env.close(); std::uint32_t const leg1OfferSeq = env.seq(leg1) - 1; // This is the offer that matters. - env(offer(self, USD(1'000), BTC(10))); + env(offer(self, usd(1'000), btc(10))); env.close(); std::uint32_t const selfOfferSeq = env.seq(self) - 1; @@ -3816,9 +3825,9 @@ public: })); BEAST_EXPECT(offerCount == actor.offers); - env.require(balance(actor.acct, actor.xrp)); - env.require(balance(actor.acct, actor.btc)); - env.require(balance(actor.acct, actor.usd)); + env.require(Balance(actor.acct, actor.xrp)); + env.require(Balance(actor.acct, actor.btc)); + env.require(Balance(actor.acct, actor.usd)); } // Remove any offers that might be left hanging around. They // could bollix up later loops. @@ -3846,12 +3855,12 @@ public: auto const alice = Account("alice"); auto const bob = Account("bob"); - env.fund(XRP(400'000), gw, alice, bob); + env.fund(kXRP(400'000), gw, alice, bob); env.close(); // GW requires authorization for holders of its IOUs auto gwMUSD = - MPTTester({.env = env, .issuer = gw, .flags = MPTDEXFlags | tfMPTRequireAuth}); + MPTTester({.env = env, .issuer = gw, .flags = kMPTDEX_FLAGS | kTF_MPT_REQUIRE_AUTH}); MPT const gwUSD = gwMUSD; // Have gw authorize bob and alice @@ -3860,26 +3869,26 @@ public: gwMUSD.authorize({.account = bob}); gwMUSD.authorize({.account = gw, .holder = bob}); // Alice is able to place the offer since the GW has authorized her - env(offer(alice, gwUSD(40), XRP(4'000))); + env(offer(alice, gwUSD(40), kXRP(4'000))); env.close(); env.require(offers(alice, 1)); - env.require(balance(alice, gwUSD(0))); + env.require(Balance(alice, gwUSD(0))); env(pay(gw, bob, gwUSD(50))); env.close(); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // Bob's offer should cross Alice's - env(offer(bob, XRP(4'000), gwUSD(40))); + env(offer(bob, kXRP(4'000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(40))); + env.require(Balance(alice, gwUSD(40))); env.require(offers(bob, 0)); - env.require(balance(bob, gwUSD(10))); + env.require(Balance(bob, gwUSD(10))); } void @@ -3906,31 +3915,31 @@ public: auto const alice = Account("alice"); auto const bob = Account("bob"); - env.fund(XRP(400'000), gw, alice, bob); + env.fund(kXRP(400'000), gw, alice, bob); env.close(); auto gwMUSD = - MPTTester({.env = env, .issuer = gw, .flags = MPTDEXFlags | tfMPTRequireAuth}); + MPTTester({.env = env, .issuer = gw, .flags = kMPTDEX_FLAGS | kTF_MPT_REQUIRE_AUTH}); MPT const gwUSD = gwMUSD; // alice can't create an offer because alice doesn't own // MPToken and MPTokenIssuance requires authorization - env(offer(alice, gwUSD(40), XRP(4'000)), ter(tecNO_AUTH)); + env(offer(alice, gwUSD(40), kXRP(4'000)), Ter(TecNoAuth)); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(none))); + env.require(Balance(alice, gwUSD(kNONE))); gwMUSD.authorize({.account = bob}); gwMUSD.authorize({.account = gw, .holder = bob}); env(pay(gw, bob, gwUSD(50))); env.close(); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // bob can create an offer since bob owns MPToken // and it is authorized. - env(offer(bob, XRP(4'000), gwUSD(40))); + env(offer(bob, kXRP(4'000), gwUSD(40))); env.close(); std::uint32_t const bobOfferSeq = env.seq(bob) - 1; @@ -3940,14 +3949,14 @@ public: // should still not be able to create an offer for USD/gw. gwMUSD.authorize({.account = alice}); - env(offer(alice, gwUSD(40), XRP(4'000)), ter(tecNO_AUTH)); + env(offer(alice, gwUSD(40), kXRP(4'000)), Ter(TecNoAuth)); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(0))); + env.require(Balance(alice, gwUSD(0))); env.require(offers(bob, 1)); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // Delete bob's offer so alice can create an offer without crossing. env(offer_cancel(bob, bobOfferSeq)); @@ -3958,20 +3967,20 @@ public: // offer should succeed. gwMUSD.authorize({.account = gw, .holder = alice}); - env(offer(alice, gwUSD(40), XRP(4'000))); + env(offer(alice, gwUSD(40), kXRP(4'000))); env.close(); env.require(offers(alice, 1)); // Now bob creates his offer again. alice's offer should cross. - env(offer(bob, XRP(4'000), gwUSD(40))); + env(offer(bob, kXRP(4'000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(40))); + env.require(Balance(alice, gwUSD(40))); env.require(offers(bob, 0)); - env.require(balance(bob, gwUSD(10))); + env.require(Balance(bob, gwUSD(10))); } void @@ -3986,15 +3995,15 @@ public: auto const gw = Account("gw"); auto const alice = Account("alice"); - env.fund(XRP(400'000), gw, alice); + env.fund(kXRP(400'000), gw, alice); env.close(); auto gwMUSD = - MPTTester({.env = env, .issuer = gw, .flags = MPTDEXFlags | tfMPTRequireAuth}); + MPTTester({.env = env, .issuer = gw, .flags = kMPTDEX_FLAGS | kTF_MPT_REQUIRE_AUTH}); MPT const gwUSD = gwMUSD; // Test that gw can create an offer to buy gw's currency. - env(offer(gw, gwUSD(40), XRP(4'000))); + env(offer(gw, gwUSD(40), kXRP(4'000))); env.close(); std::uint32_t const gwOfferSeq = env.seq(gw) - 1; env.require(offers(gw, 1)); @@ -4007,7 +4016,7 @@ public: // Before DepositPreauth an account with lsfRequireAuth set could not // create an offer to buy their own currency. After DepositPreauth // they can. - env(offer(gw, gwUSD(40), XRP(4'000))); + env(offer(gw, gwUSD(40), kXRP(4'000))); env.close(); env.require(offers(gw, 1)); @@ -4021,14 +4030,14 @@ public: env(pay(gw, alice, gwUSD(50))); env.close(); - env.require(balance(alice, gwUSD(50))); + env.require(Balance(alice, gwUSD(50))); // alice's offer should cross gw's - env(offer(alice, XRP(4'000), gwUSD(40))); + env(offer(alice, kXRP(4'000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(10))); + env.require(Balance(alice, gwUSD(10))); env.require(offers(gw, 0)); } @@ -4041,7 +4050,7 @@ public: testcase("Deleted offer issuer"); - auto MPTokenExists = + auto mpTokenExists = [](jtx::Env const& env, AccountID const& account, MPTID const& issuanceID) -> bool { return bool(env.le(keylet::mptoken(issuanceID, account))); }; @@ -4053,38 +4062,38 @@ public: Env env{*this, features}; - env.fund(XRP(10'000), alice, becky, carol, noripple(gw)); + env.fund(kXRP(10'000), alice, becky, carol, noripple(gw)); - auto MUSD = MPTTester({.env = env, .issuer = gw}); - MPT const USD = MUSD; + auto musd = MPTTester({.env = env, .issuer = gw}); + MPT const usd = musd; - MUSD.authorize({.account = becky}); - BEAST_EXPECT(MPTokenExists(env, becky, USD.issuanceID)); - env(pay(gw, becky, USD(5))); + musd.authorize({.account = becky}); + BEAST_EXPECT(mpTokenExists(env, becky, usd.issuanceID)); + env(pay(gw, becky, usd(5))); env.close(); - auto MBUX = MPTTester({.env = env, .issuer = alice}); - MPT const BUX = MBUX; + auto mbux = MPTTester({.env = env, .issuer = alice}); + MPT const bux = mbux; // Make offers that produce USD and can be crossed two ways: // direct XRP -> USD // direct BUX -> USD - env(offer(becky, XRP(2), USD(2)), txflags(tfPassive)); + env(offer(becky, kXRP(2), usd(2)), Txflags(kTF_PASSIVE)); std::uint32_t const beckyBuxUsdSeq{env.seq(becky)}; - env(offer(becky, BUX(3), USD(3)), txflags(tfPassive)); + env(offer(becky, bux(3), usd(3)), Txflags(kTF_PASSIVE)); env.close(); // becky keeps the offers, but removes MPT. - env(pay(becky, gw, USD(5))); - MUSD.authorize({.account = becky, .flags = tfMPTUnauthorize}); + env(pay(becky, gw, usd(5))); + musd.authorize({.account = becky, .flags = kTF_MPT_UNAUTHORIZE}); - BEAST_EXPECT(!MPTokenExists(env, becky, USD.issuanceID)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(!mpTokenExists(env, becky, usd.issuanceID)); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // Have to delete MPTokenIssuance in order to delete // the issuer account. - MUSD.destroy({}); + musd.destroy({}); // Delete gw's account. { @@ -4101,7 +4110,7 @@ public: env.close(); // Account deletion has a high fee. Account for that. - env(acctdelete(gw, alice), fee(drops(env.current()->fees().increment))); + env(acctdelete(gw, alice), Fee(drops(env.current()->fees().increment))); env.close(); // Verify that gw's account root is gone from the ledger. @@ -4110,38 +4119,38 @@ public: // alice crosses becky's first offer. The offer create fails because // the USD issuer is not in the ledger. - env(offer(alice, USD(2), XRP(2)), ter(tecNO_ISSUER)); + env(offer(alice, usd(2), kXRP(2)), Ter(TecNoIssuer)); env.close(); env.require(offers(alice, 0)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // alice crosses becky's second offer. Again, the offer create fails // because the USD issuer is not in the ledger. - env(offer(alice, USD(3), BUX(3)), ter(tecNO_ISSUER)); + env(offer(alice, usd(3), bux(3)), Ter(TecNoIssuer)); env.require(offers(alice, 0)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // Cancel becky's BUX -> USD offer so we can try auto-bridging. env(offer_cancel(becky, beckyBuxUsdSeq)); env.close(); - BEAST_EXPECT(!isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(!isOffer(env, becky, bux(3), usd(3))); // alice creates an offer that can be auto-bridged with becky's // remaining offer. - MBUX.authorize({.account = carol}); - env(pay(alice, carol, BUX(2))); + mbux.authorize({.account = carol}); + env(pay(alice, carol, bux(2))); - env(offer(alice, BUX(2), XRP(2))); + env(offer(alice, bux(2), kXRP(2))); env.close(); // carol attempts the auto-bridge. Again, the offer create fails // because the USD issuer is not in the ledger. - env(offer(carol, USD(2), BUX(2)), ter(tecNO_ISSUER)); + env(offer(carol, usd(2), bux(2)), Ter(TecNoIssuer)); env.close(); - BEAST_EXPECT(isOffer(env, alice, BUX(2), XRP(2))); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); + BEAST_EXPECT(isOffer(env, alice, bux(2), kXRP(2))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); } // Helper function that returns offers on an account sorted by sequence. @@ -4175,19 +4184,19 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - env.fund(XRP(10'000), gw, alice, bob); + env.fund(kXRP(10'000), gw, alice, bob); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice, bob}}); - env(pay(gw, alice, USD(200))); + env(pay(gw, alice, usd(200))); env.close(); // Create four offers from the same account with identical quality // so they go in the same order book. Each offer goes in a different // ledger so the chronology is clear. - std::uint32_t const offerId_0{env.seq(alice)}; - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerId0{env.seq(alice)}; + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create two tickets. @@ -4196,71 +4205,71 @@ public: env.close(); // Create another sequence-based offer. - std::uint32_t const offerId_1{env.seq(alice)}; - BEAST_EXPECT(offerId_1 == offerId_0 + 4); - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerId1{env.seq(alice)}; + BEAST_EXPECT(offerId1 == offerId0 + 4); + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create two ticket based offers in reverse order. - std::uint32_t const offerId_2{ticketSeq + 1}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerId_2)); + std::uint32_t const offerId2{ticketSeq + 1}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerId2)); env.close(); // Create the last offer. - std::uint32_t const offerId_3{ticketSeq}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerId_3)); + std::uint32_t const offerId3{ticketSeq}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerId3)); env.close(); // Verify that all of alice's offers are present. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 4); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_0); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId_2); - BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerId_1); - env.require(balance(alice, USD(200))); - env.require(owners(alice, 5)); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId0); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId2); + BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerId1); + env.require(Balance(alice, usd(200))); + env.require(Owners(alice, 5)); } // Cross alice's first offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the first offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 3); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_2); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId2); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId1); } // Cross alice's second offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the second offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 2); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_2); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId2); } // Cross alice's third offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the third offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 1); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); } // Cross alice's last offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the third offer alice created was consumed. @@ -4268,10 +4277,10 @@ public: auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.empty()); } - env.require(balance(alice, USD(0))); - env.require(owners(alice, 1)); - env.require(balance(bob, USD(200))); - env.require(owners(bob, 1)); + env.require(Balance(alice, usd(0))); + env.require(Owners(alice, 1)); + env.require(Balance(bob, usd(200))); + env.require(Owners(bob, 1)); } void @@ -4287,102 +4296,102 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - env.fund(XRP(10'000), gw, alice); + env.fund(kXRP(10'000), gw, alice); env.close(); - MPT const USD = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); + MPT const usd = MPTTester({.env = env, .issuer = gw, .holders = {alice}}); - env.require(owners(alice, 1), tickets(alice, 0)); + env.require(Owners(alice, 1), tickets(alice, 0)); - env(pay(gw, alice, USD(200))); + env(pay(gw, alice, usd(200))); env.close(); // Create the first of four offers using a sequence. - std::uint32_t const offerSeqId_0{env.seq(alice)}; - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerSeqId0{env.seq(alice)}; + env(offer(alice, kXRP(50), usd(50))); env.close(); - env.require(owners(alice, 2), tickets(alice, 0)); + env.require(Owners(alice, 2), tickets(alice, 0)); // Create four tickets. std::uint32_t const ticketSeq{env.seq(alice) + 1}; env(ticket::create(alice, 4)); env.close(); - env.require(owners(alice, 6), tickets(alice, 4)); + env.require(Owners(alice, 6), tickets(alice, 4)); // Create the second (also sequence-based) offer. - std::uint32_t const offerSeqId_1{env.seq(alice)}; - BEAST_EXPECT(offerSeqId_1 == offerSeqId_0 + 6); - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerSeqId1{env.seq(alice)}; + BEAST_EXPECT(offerSeqId1 == offerSeqId0 + 6); + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create the third (ticket-based) offer. - std::uint32_t const offerTixId_0{ticketSeq + 1}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerTixId_0)); + std::uint32_t const offerTixId0{ticketSeq + 1}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerTixId0)); env.close(); // Create the last offer. - std::uint32_t const offerTixId_1{ticketSeq}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerTixId_1)); + std::uint32_t const offerTixId1{ticketSeq}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerTixId1)); env.close(); // Verify that all of alice's offers are present. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 4); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId_0); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerTixId_0); - BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerSeqId_1); - env.require(balance(alice, USD(200))); - env.require(owners(alice, 7)); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId0); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerTixId0); + BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerSeqId1); + env.require(Balance(alice, usd(200))); + env.require(Owners(alice, 7)); } // Use a ticket to cancel an offer created with a sequence. - env(offer_cancel(alice, offerSeqId_0), ticket::use(ticketSeq + 2)); + env(offer_cancel(alice, offerSeqId0), ticket::Use(ticketSeq + 2)); env.close(); // Verify that offerSeqId_0 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 3); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId_0); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId0); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerSeqId1); } // Use a ticket to cancel an offer created with a ticket. - env(offer_cancel(alice, offerTixId_0), ticket::use(ticketSeq + 3)); + env(offer_cancel(alice, offerTixId0), ticket::Use(ticketSeq + 3)); env.close(); // Verify that offerTixId_0 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 2); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerSeqId1); } // All of alice's tickets should now be used up. - env.require(owners(alice, 3), tickets(alice, 0)); + env.require(Owners(alice, 3), tickets(alice, 0)); // Use a sequence to cancel an offer created with a ticket. - env(offer_cancel(alice, offerTixId_1)); + env(offer_cancel(alice, offerTixId1)); env.close(); // Verify that offerTixId_1 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 1); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId1); } // Use a sequence to cancel an offer created with a sequence. - env(offer_cancel(alice, offerSeqId_1)); + env(offer_cancel(alice, offerSeqId1)); env.close(); // Verify that offerSeqId_1 was canceled. // All of alice's tickets should now be used up. - env.require(owners(alice, 1), tickets(alice, 0), offers(alice, 0)); + env.require(Owners(alice, 1), tickets(alice, 0), offers(alice, 0)); } void @@ -4397,151 +4406,151 @@ public: auto test = [&](auto&& issue1, auto&& issue2) { Env env(*this, features); - env.fund(XRP(1'000), issuer); - env.fund(XRP(1'000), maker, taker); + env.fund(kXRP(1'000), issuer); + env.fund(kXRP(1'000), maker, taker); env.close(); - auto const USD = + auto const usd = issue1({.env = env, .token = "USD", .issuer = issuer, .holders = {maker, taker}}); - auto const EUR = + auto const eur = issue2({.env = env, .token = "EUR", .issuer = issuer, .holders = {maker, taker}}); - env(pay(issuer, maker, USD(1'000))); - env(pay(issuer, taker, USD(1'000))); - env(pay(issuer, maker, EUR(1'000))); + env(pay(issuer, maker, usd(1'000))); + env(pay(issuer, taker, usd(1'000))); + env(pay(issuer, maker, eur(1'000))); env.close(); - auto makerUSDBalance = env.balance(maker, USD).value(); - auto takerUSDBalance = env.balance(taker, USD).value(); - auto makerEURBalance = env.balance(maker, EUR).value(); - auto takerEURBalance = env.balance(taker, EUR).value(); - auto makerXRPBalance = env.balance(maker, XRP).value(); - auto takerXRPBalance = env.balance(taker, XRP).value(); + auto makerUSDBalance = env.balance(maker, usd).value(); + auto takerUSDBalance = env.balance(taker, usd).value(); + auto makerEURBalance = env.balance(maker, eur).value(); + auto takerEURBalance = env.balance(taker, eur).value(); + auto makerXRPBalance = env.balance(maker, kXRP).value(); + auto takerXRPBalance = env.balance(taker, kXRP).value(); // tfFillOrKill, TakerPays must be filled { - TER const err = features[fixFillOrKill] ? TER(tesSUCCESS) : tecKILLED; + TER const err = features[fixFillOrKill] ? TER(TesSuccess) : TecKilled; - env(offer(maker, XRP(100), USD(100))); + env(offer(maker, kXRP(100), usd(100))); env.close(); - env(offer(taker, USD(100), XRP(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, usd(100), kXRP(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); - if (err == tesSUCCESS) + if (err == TesSuccess) { - makerUSDBalance -= USD(100); - takerUSDBalance += USD(100); - makerXRPBalance += XRP(100).value(); - takerXRPBalance -= XRP(100).value(); + makerUSDBalance -= usd(100); + takerUSDBalance += usd(100); + makerXRPBalance += kXRP(100).value(); + takerXRPBalance -= kXRP(100).value(); } BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), XRP(100))); + env(offer(maker, usd(100), kXRP(100))); env.close(); - env(offer(taker, XRP(100), USD(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, kXRP(100), usd(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); - if (err == tesSUCCESS) + if (err == TesSuccess) { - makerUSDBalance += USD(100); - takerUSDBalance -= USD(100); - makerXRPBalance -= XRP(100).value(); - takerXRPBalance += XRP(100).value(); + makerUSDBalance += usd(100); + takerUSDBalance -= usd(100); + makerXRPBalance -= kXRP(100).value(); + takerXRPBalance += kXRP(100).value(); } BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), EUR(100))); + env(offer(maker, usd(100), eur(100))); env.close(); - env(offer(taker, EUR(100), USD(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, eur(100), usd(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); - if (err == tesSUCCESS) + if (err == TesSuccess) { - makerUSDBalance += USD(100); - takerUSDBalance -= USD(100); - makerEURBalance -= EUR(100); - takerEURBalance += EUR(100); + makerUSDBalance += usd(100); + takerUSDBalance -= usd(100); + makerEURBalance -= eur(100); + takerEURBalance += eur(100); } BEAST_EXPECT(expectOffers(env, taker, 0)); } // tfFillOrKill + tfSell, TakerGets must be filled { - env(offer(maker, XRP(101), USD(101))); + env(offer(maker, kXRP(101), usd(101))); env.close(); - env(offer(taker, USD(100), XRP(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, usd(100), kXRP(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance -= USD(101); - takerUSDBalance += USD(101); - makerXRPBalance += XRP(101).value() - txfee(env, 1); - takerXRPBalance -= XRP(101).value() + txfee(env, 1); + makerUSDBalance -= usd(101); + takerUSDBalance += usd(101); + makerXRPBalance += kXRP(101).value() - txfee(env, 1); + takerXRPBalance -= kXRP(101).value() + txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(101), XRP(101))); + env(offer(maker, usd(101), kXRP(101))); env.close(); - env(offer(taker, XRP(100), USD(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, kXRP(100), usd(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance += USD(101); - takerUSDBalance -= USD(101); - makerXRPBalance -= XRP(101).value() + txfee(env, 1); - takerXRPBalance += XRP(101).value() - txfee(env, 1); + makerUSDBalance += usd(101); + takerUSDBalance -= usd(101); + makerXRPBalance -= kXRP(101).value() + txfee(env, 1); + takerXRPBalance += kXRP(101).value() - txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(101), EUR(101))); + env(offer(maker, usd(101), eur(101))); env.close(); - env(offer(taker, EUR(100), USD(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, eur(100), usd(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance += USD(101); - takerUSDBalance -= USD(101); - makerEURBalance -= EUR(101); - takerEURBalance += EUR(101); + makerUSDBalance += usd(101); + takerUSDBalance -= usd(101); + makerEURBalance -= eur(101); + takerEURBalance += eur(101); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); } // Fail regardless of fixFillOrKill amendment - for (auto const flags : {tfFillOrKill, tfFillOrKill + tfSell}) + for (auto const flags : {kTF_FILL_OR_KILL, kTF_FILL_OR_KILL + kTF_SELL}) { - env(offer(maker, XRP(100), USD(100))); + env(offer(maker, kXRP(100), usd(100))); env.close(); - env(offer(taker, USD(100), XRP(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, usd(100), kXRP(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), XRP(100))); + env(offer(maker, usd(100), kXRP(100))); env.close(); - env(offer(taker, XRP(100), USD(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, kXRP(100), usd(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), EUR(100))); + env(offer(maker, usd(100), eur(100))); env.close(); - env(offer(taker, EUR(100), USD(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, eur(100), usd(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); @@ -4550,12 +4559,12 @@ public: } BEAST_EXPECT( - env.balance(maker, USD) == makerUSDBalance && - env.balance(taker, USD) == takerUSDBalance && - env.balance(maker, EUR) == makerEURBalance && - env.balance(taker, EUR) == takerEURBalance && - env.balance(maker, XRP) == makerXRPBalance && - env.balance(taker, XRP) == takerXRPBalance); + env.balance(maker, usd) == makerUSDBalance && + env.balance(taker, usd) == takerUSDBalance && + env.balance(maker, eur) == makerEURBalance && + env.balance(taker, eur) == takerEURBalance && + env.balance(maker, kXRP) == makerXRPBalance && + env.balance(taker, kXRP) == takerXRPBalance); }; testHelper2TokensMix(test); } @@ -4571,8 +4580,8 @@ public: auto const alice = Account{"alice"}; auto getIOU = [&](Env& env) -> PrettyAsset { - static int i = 0; - std::string const name = "IO" + std::to_string(i++); + static int kI = 0; + std::string const name = "IO" + std::to_string(kI++); auto const iou = gw[name]; env(trust(alice, iou(1'000))); env(pay(gw, alice, iou(100))); @@ -4584,7 +4593,7 @@ public: MPTTester({.env = env, .issuer = gw, .holders = {alice}, .pay = 1'000'000'000}); return mpt; }; - auto getXRP = [&](Env& env) -> PrettyAsset { return XRP; }; + auto getXRP = [&](Env& env) -> PrettyAsset { return kXRP; }; using ToAsset = std::function; struct TestInfo @@ -4609,11 +4618,11 @@ public: for (TestInfo const& t : tests) { Env env{*this, features}; - env.fund(XRP(10'000), gw, alice); + env.fund(kXRP(10'000), gw, alice); env.close(); - auto const XTS = t.toAsset1(env); - auto const XXX = t.toAsset2(env); + auto const xts = t.toAsset1(env); + auto const xxx = t.toAsset2(env); auto tokenType = [](PrettyAsset const& asset) -> std::string { return asset.raw().visit( @@ -4621,7 +4630,7 @@ public: [&](MPTIssue const&) { return "MPTIssue"; }); }; - testcase << "offer: " << tokenType(XTS) << "/" << tokenType(XXX); + testcase << "offer: " << tokenType(xts) << "/" << tokenType(xxx); { // Gateway sets its tick size to 5 @@ -4631,10 +4640,10 @@ public: BEAST_EXPECT((*env.le(gw))[sfTickSize] == 5); } - env(offer(alice, XTS(t.val1), XXX(t.val2))); - env(offer(alice, XTS(t.val2), XXX(t.val1))); - env(offer(alice, XTS(t.val1), XXX(t.val2)), json(jss::Flags, tfSell)); - env(offer(alice, XTS(t.val2), XXX(t.val1)), json(jss::Flags, tfSell)); + env(offer(alice, xts(t.val1), xxx(t.val2))); + env(offer(alice, xts(t.val2), xxx(t.val1))); + env(offer(alice, xts(t.val1), xxx(t.val2)), Json(jss::kFLAGS, kTF_SELL)); + env(offer(alice, xts(t.val2), xxx(t.val1)), Json(jss::kFLAGS, kTF_SELL)); std::map> offers; forEachItem(*env.current(), alice, [&](std::shared_ptr const& sle) { @@ -4649,51 +4658,51 @@ public: // first offer auto it = offers.begin(); BEAST_EXPECT(it != offers.end()); - if (XXX.native() && !XTS.holds()) + if (xxx.native() && !xts.holds()) { BEAST_EXPECT( - it->second.first == XTS(t.val1) && it->second.second == XRPAmount(29'999'400)); + it->second.first == xts(t.val1) && it->second.second == XRPAmount(29'999'400)); } - else if (!XXX.integral()) + else if (!xxx.integral()) { BEAST_EXPECT( - it->second.first == XTS(t.val1) && it->second.second < XXX(t.val2) && - it->second.second > STAmount(XXX, 29'9994, -4)); + it->second.first == xts(t.val1) && it->second.second < xxx(t.val2) && + it->second.second > STAmount(xxx, 29'9994, -4)); } else { - BEAST_EXPECT(it->second.first == XTS(t.val1) && it->second.second == XXX(t.val2)); + BEAST_EXPECT(it->second.first == xts(t.val1) && it->second.second == xxx(t.val2)); } // second offer ++it; BEAST_EXPECT(it != offers.end()); - BEAST_EXPECT(it->second.first == XTS(t.val2) && it->second.second == XXX(t.val1)); + BEAST_EXPECT(it->second.first == xts(t.val2) && it->second.second == xxx(t.val1)); // third offer ++it; BEAST_EXPECT(it != offers.end()); - if (XTS.native() && !XXX.holds()) + if (xts.native() && !xxx.holds()) { BEAST_EXPECT( - it->second.first == XRPAmount(10'000'200) && it->second.second == XXX(t.val2)); + it->second.first == XRPAmount(10'000'200) && it->second.second == xxx(t.val2)); } - else if (!XTS.integral()) + else if (!xts.integral()) { BEAST_EXPECT( - it->second.first == STAmount(XTS, 10'0002, -4) && - it->second.second == XXX(t.val2)); + it->second.first == STAmount(xts, 10'0002, -4) && + it->second.second == xxx(t.val2)); } else { - BEAST_EXPECT(it->second.first == XTS(t.val1) && it->second.second == XXX(t.val2)); + BEAST_EXPECT(it->second.first == xts(t.val1) && it->second.second == xxx(t.val2)); } // fourth offer // exact TakerPays is XTS(1/.033333) ++it; BEAST_EXPECT(it != offers.end()); - BEAST_EXPECT(it->second.first == XTS(t.val2) && it->second.second == XXX(t.val1)); + BEAST_EXPECT(it->second.first == xts(t.val2) && it->second.second == xxx(t.val1)); BEAST_EXPECT(++it == offers.end()); } @@ -4761,8 +4770,8 @@ public: run() override { using namespace jtx; - static FeatureBitset const all{testable_amendments()}; - testAll(all); + static FeatureBitset const kALL{testable_amendments()}; + testAll(kALL); } }; diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index f5d832ef40..edcd7ca3c0 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -56,7 +56,7 @@ namespace xrpl::test { -class OfferBaseUtil_test : public beast::unit_test::suite +class OfferBaseUtil_test : public beast::unit_test::Suite { static XRPAmount reserve(jtx::Env& env, std::uint32_t count) @@ -71,24 +71,24 @@ class OfferBaseUtil_test : public beast::unit_test::suite } static auto - ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offer_seq) + ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offerSeq) { Json::Value jvParams; jvParams[jss::offer][jss::account] = acct.human(); - jvParams[jss::offer][jss::seq] = offer_seq; - return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result]; + jvParams[jss::offer][jss::kSEQ] = offerSeq; + return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::kRESULT]; } static auto - getBookOffers(jtx::Env& env, Issue const& taker_pays, Issue const& taker_gets) + getBookOffers(jtx::Env& env, Issue const& takerPays, Issue const& takerGets) { Json::Value jvbp; - jvbp[jss::ledger_index] = "current"; - jvbp[jss::taker_pays][jss::currency] = to_string(taker_pays.currency); - jvbp[jss::taker_pays][jss::issuer] = to_string(taker_pays.account); - jvbp[jss::taker_gets][jss::currency] = to_string(taker_gets.currency); - jvbp[jss::taker_gets][jss::issuer] = to_string(taker_gets.account); - return env.rpc("json", "book_offers", to_string(jvbp))[jss::result]; + jvbp[jss::kLEDGER_INDEX] = "current"; + jvbp[jss::kTAKER_PAYS][jss::kCURRENCY] = to_string(takerPays.currency); + jvbp[jss::kTAKER_PAYS][jss::kISSUER] = to_string(takerPays.account); + jvbp[jss::kTAKER_GETS][jss::kCURRENCY] = to_string(takerGets.currency); + jvbp[jss::kTAKER_GETS][jss::kISSUER] = to_string(takerGets.account); + return env.rpc("json", "book_offers", to_string(jvbp))[jss::kRESULT]; } public: @@ -110,46 +110,46 @@ public: Env env{*this, features}; auto const gw = Account{"gateway"}; - auto const USD = gw["USD"]; - auto const BTC = gw["BTC"]; + auto const usd = gw["USD"]; + auto const btc = gw["BTC"]; Account const alice{"alice"}; Account const bob{"bob"}; Account const carol{"carol"}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); - env.trust(BTC(1000), alice, bob, carol); + env.trust(usd(1000), alice, bob, carol); + env.trust(btc(1000), alice, bob, carol); - env(pay(gw, alice, BTC(1000))); + env(pay(gw, alice, btc(1000))); - env(pay(gw, carol, USD(1000))); - env(pay(gw, carol, BTC(1000))); + env(pay(gw, carol, usd(1000))); + env(pay(gw, carol, btc(1000))); // Must be two offers at the same quality // "taker gets" must be XRP // (Different amounts so I can distinguish the offers) - env(offer(carol, BTC(49), XRP(49))); - env(offer(carol, BTC(51), XRP(51))); + env(offer(carol, btc(49), kXRP(49))); + env(offer(carol, btc(51), kXRP(51))); // Offers for the poor quality path // Must be two offers at the same quality - env(offer(carol, XRP(50), USD(50))); - env(offer(carol, XRP(50), USD(50))); + env(offer(carol, kXRP(50), usd(50))); + env(offer(carol, kXRP(50), usd(50))); // Offers for the good quality path - env(offer(carol, BTC(1), USD(100))); + env(offer(carol, btc(1), usd(100))); - PathSet const paths(Path(XRP, USD), Path(USD)); + PathSet const paths(Path(kXRP, usd), Path(usd)); - env(pay(alice, bob, USD(100)), - json(paths.json()), - sendmax(BTC(1000)), - txflags(tfPartialPayment)); + env(pay(alice, bob, usd(100)), + Json(paths.json()), + Sendmax(btc(1000)), + Txflags(kTF_PARTIAL_PAYMENT)); - env.require(balance(bob, USD(100))); + env.require(Balance(bob, usd(100))); BEAST_EXPECT( - !isOffer(env, carol, BTC(1), USD(100)) && isOffer(env, carol, BTC(49), XRP(49))); + !isOffer(env, carol, btc(1), usd(100)) && isOffer(env, carol, btc(49), kXRP(49))); } void @@ -162,70 +162,70 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), alice, gw); + env.fund(kXRP(10000), alice, gw); env.close(); - env.trust(USD(100), alice); + env.trust(usd(100), alice); env.close(); - env(pay(gw, alice, USD(50))); + env(pay(gw, alice, usd(50))); env.close(); auto const offer1Seq = env.seq(alice); - env(offer(alice, XRP(500), USD(100)), require(offers(alice, 1))); + env(offer(alice, kXRP(500), usd(100)), Require(offers(alice, 1))); env.close(); - BEAST_EXPECT(isOffer(env, alice, XRP(500), USD(100))); + BEAST_EXPECT(isOffer(env, alice, kXRP(500), usd(100))); // cancel the offer above and replace it with a new offer auto const offer2Seq = env.seq(alice); - env(offer(alice, XRP(300), USD(100)), - json(jss::OfferSequence, offer1Seq), - require(offers(alice, 1))); + env(offer(alice, kXRP(300), usd(100)), + Json(jss::kOFFER_SEQUENCE, offer1Seq), + Require(offers(alice, 1))); env.close(); BEAST_EXPECT( - isOffer(env, alice, XRP(300), USD(100)) && !isOffer(env, alice, XRP(500), USD(100))); + isOffer(env, alice, kXRP(300), usd(100)) && !isOffer(env, alice, kXRP(500), usd(100))); // Test canceling non-existent offer. // auto const offer3Seq = env.seq (alice); - env(offer(alice, XRP(400), USD(200)), - json(jss::OfferSequence, offer1Seq), - require(offers(alice, 2))); + env(offer(alice, kXRP(400), usd(200)), + Json(jss::kOFFER_SEQUENCE, offer1Seq), + Require(offers(alice, 2))); env.close(); BEAST_EXPECT( - isOffer(env, alice, XRP(300), USD(100)) && isOffer(env, alice, XRP(400), USD(200))); + isOffer(env, alice, kXRP(300), usd(100)) && isOffer(env, alice, kXRP(400), usd(200))); // Test cancellation now with OfferCancel tx auto const offer4Seq = env.seq(alice); - env(offer(alice, XRP(222), USD(111)), require(offers(alice, 3))); + env(offer(alice, kXRP(222), usd(111)), Require(offers(alice, 3))); env.close(); - BEAST_EXPECT(isOffer(env, alice, XRP(222), USD(111))); + BEAST_EXPECT(isOffer(env, alice, kXRP(222), usd(111))); env(offer_cancel(alice, offer4Seq)); env.close(); BEAST_EXPECT(env.seq(alice) == offer4Seq + 2); - BEAST_EXPECT(!isOffer(env, alice, XRP(222), USD(111))); + BEAST_EXPECT(!isOffer(env, alice, kXRP(222), usd(111))); // Create an offer that both fails with a tecEXPIRED code and removes // an offer. Show that the attempt to remove the offer fails. env.require(offers(alice, 2)); - env(offer(alice, XRP(5), USD(2)), - json(sfExpiration.fieldName, lastClose(env)), - json(jss::OfferSequence, offer2Seq), - ter(tecEXPIRED)); + env(offer(alice, kXRP(5), usd(2)), + Json(sfExpiration.fieldName, lastClose(env)), + Json(jss::kOFFER_SEQUENCE, offer2Seq), + Ter(TecExpired)); env.close(); env.require(offers(alice, 2)); - BEAST_EXPECT(isOffer(env, alice, XRP(300), USD(100))); // offer2 - BEAST_EXPECT(!isOffer(env, alice, XRP(5), USD(2))); // expired + BEAST_EXPECT(isOffer(env, alice, kXRP(300), usd(100))); // offer2 + BEAST_EXPECT(!isOffer(env, alice, kXRP(5), usd(2))); // expired } void @@ -241,26 +241,26 @@ public: auto const carol = Account{"carol"}; auto const gw = Account{"gw"}; - auto const USD = gw["USD"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const eur = gw["EUR"]; Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); - env.trust(EUR(1000), alice, bob, carol); - env(pay(gw, alice, USD(100))); - env(pay(gw, carol, EUR(100))); + env.trust(usd(1000), alice, bob, carol); + env.trust(eur(1000), alice, bob, carol); + env(pay(gw, alice, usd(100))); + env(pay(gw, carol, eur(100))); // Create more offers than the loop max count in DeliverNodeReverse // Note: the DeliverNodeReverse code has been removed; however since // this is a regression test the original test is being left as-is for // now. for (int i = 0; i < 101; ++i) - env(offer(carol, USD(1), EUR(2))); + env(offer(carol, usd(1), eur(2))); - env(pay(alice, bob, EUR(epsilon)), path(~EUR), sendmax(USD(100))); + env(pay(alice, bob, eur(kEPSILON)), Path(~eur), Sendmax(usd(100))); } void @@ -292,16 +292,16 @@ public: auto const erin = Account{"erin"}; auto const gw = Account{"gw"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, dan, erin, gw); + env.fund(kXRP(10000), alice, bob, carol, dan, erin, gw); env.close(); - env.trust(USD(1000), alice, bob, carol, dan, erin); + env.trust(usd(1000), alice, bob, carol, dan, erin); env.close(); - env(pay(gw, carol, USD(0.99999))); - env(pay(gw, dan, USD(1))); - env(pay(gw, erin, USD(1))); + env(pay(gw, carol, usd(0.99999))); + env(pay(gw, dan, usd(1))); + env(pay(gw, erin, usd(1))); env.close(); // Carol doesn't quite have enough funds for this offer @@ -309,10 +309,10 @@ public: // STAmount to incorrectly round to zero when the next offer // (at a good quality) is considered. (when the now removed // stAmountCalcSwitchover2 patch was inactive) - env(offer(carol, drops(1), USD(0.99999))); + env(offer(carol, drops(1), usd(0.99999))); // Offer at a quality poor enough so when the input xrp is // calculated in the reverse pass, the amount is not zero. - env(offer(dan, XRP(100), USD(1))); + env(offer(dan, kXRP(100), usd(1))); env.close(); // This is the funded offer that will be incorrectly removed. @@ -321,18 +321,18 @@ public: // needed for this offer, it will incorrectly compute zero in both // the forward and reverse passes (when the now removed // stAmountCalcSwitchover2 was inactive.) - env(offer(erin, drops(2), USD(1))); + env(offer(erin, drops(2), usd(1))); - env(pay(alice, bob, USD(1)), - path(~USD), - sendmax(XRP(102)), - txflags(tfNoRippleDirect | tfPartialPayment)); + env(pay(alice, bob, usd(1)), + Path(~usd), + Sendmax(kXRP(102)), + Txflags(kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT)); env.require(offers(carol, 0), offers(dan, 1)); // offer was correctly consumed. There is still some // liquidity left on that offer. - env.require(balance(erin, USD(0.99999)), offers(erin, 1)); + env.require(Balance(erin, usd(0.99999)), offers(erin, 1)); } void @@ -352,48 +352,48 @@ public: auto const carol = Account{"carol"}; auto const gw = Account{"gw"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; // Test offer crossing for (auto crossBothOffers : {false, true}) { Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); + env.trust(usd(1000), alice, bob, carol); // underfund carol's offer - auto initialCarolUSD = USD(0.499); + auto initialCarolUSD = usd(0.499); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100))); + env(pay(gw, bob, usd(100))); env.close(); // This offer is underfunded - env(offer(carol, drops(1), USD(1))); + env(offer(carol, drops(1), usd(1))); env.close(); // offer at a lower quality - env(offer(bob, drops(2), USD(1), tfPassive)); + env(offer(bob, drops(2), usd(1), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); // alice places an offer that crosses carol's; depending on // "crossBothOffers" it may cross bob's as well auto aliceTakerGets = crossBothOffers ? drops(2) : drops(1); - env(offer(alice, USD(1), aliceTakerGets)); + env(offer(alice, usd(1), aliceTakerGets)); env.close(); env.require( offers(carol, 0), - balance( + Balance( carol, initialCarolUSD)); // offer is removed but not taken if (crossBothOffers) { - env.require(offers(alice, 0), balance(alice, USD(1))); // alice's offer is crossed + env.require(offers(alice, 0), Balance(alice, usd(1))); // alice's offer is crossed } else { env.require( - offers(alice, 1), balance(alice, USD(0))); // alice's offer is not crossed + offers(alice, 1), Balance(alice, usd(0))); // alice's offer is not crossed } } @@ -402,37 +402,38 @@ public: { Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); + env.trust(usd(1000), alice, bob, carol); env.close(); - auto const initialCarolUSD = USD(0.999); + auto const initialCarolUSD = usd(0.999); env(pay(gw, carol, initialCarolUSD)); env.close(); - env(pay(gw, bob, USD(100))); + env(pay(gw, bob, usd(100))); env.close(); - env(offer(carol, drops(1), USD(1))); + env(offer(carol, drops(1), usd(1))); env.close(); - env(offer(bob, drops(2), USD(2), tfPassive)); + env(offer(bob, drops(2), usd(2), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); - std::uint32_t const flags = - partialPayment ? (tfNoRippleDirect | tfPartialPayment) : tfNoRippleDirect; + std::uint32_t const flags = partialPayment + ? (kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT) + : kTF_NO_RIPPLE_DIRECT; - TER const expectedTer = partialPayment ? TER{tesSUCCESS} : TER{tecPATH_PARTIAL}; + TER const expectedTer = partialPayment ? TER{TesSuccess} : TER{TecPathPartial}; - env(pay(alice, bob, USD(5)), - path(~USD), - sendmax(XRP(1)), - txflags(flags), - ter(expectedTer)); + env(pay(alice, bob, usd(5)), + Path(~usd), + Sendmax(kXRP(1)), + Txflags(flags), + Ter(expectedTer)); env.close(); if (isTesSuccess(expectedTer)) { env.require(offers(carol, 0)); - env.require(balance(carol, + env.require(Balance(carol, initialCarolUSD)); // offer is removed but not taken } else @@ -462,8 +463,8 @@ public: auto const carol = Account{"carol"}; auto const gw = Account{"gw"}; - auto const USD = gw["USD"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const eur = gw["EUR"]; auto tinyAmount = [&](IOU const& iou) -> PrettyAmount { STAmount const amt( @@ -478,44 +479,44 @@ public: { Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); - env.trust(EUR(1000), alice, bob, carol); + env.trust(usd(1000), alice, bob, carol); + env.trust(eur(1000), alice, bob, carol); // underfund carol's offer - auto initialCarolUSD = tinyAmount(USD); + auto initialCarolUSD = tinyAmount(usd); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100))); - env(pay(gw, alice, EUR(100))); + env(pay(gw, bob, usd(100))); + env(pay(gw, alice, eur(100))); env.close(); // This offer is underfunded - env(offer(carol, EUR(1), USD(10))); + env(offer(carol, eur(1), usd(10))); env.close(); // offer at a lower quality - env(offer(bob, EUR(1), USD(5), tfPassive)); + env(offer(bob, eur(1), usd(5), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); // alice places an offer that crosses carol's; depending on // "crossBothOffers" it may cross bob's as well // Whatever - auto aliceTakerGets = crossBothOffers ? EUR(0.2) : EUR(0.1); - env(offer(alice, USD(1), aliceTakerGets)); + auto aliceTakerGets = crossBothOffers ? eur(0.2) : eur(0.1); + env(offer(alice, usd(1), aliceTakerGets)); env.close(); env.require( offers(carol, 0), - balance( + Balance( carol, initialCarolUSD)); // offer is removed but not taken if (crossBothOffers) { - env.require(offers(alice, 0), balance(alice, USD(1))); // alice's offer is crossed + env.require(offers(alice, 0), Balance(alice, usd(1))); // alice's offer is crossed } else { env.require( - offers(alice, 1), balance(alice, USD(0))); // alice's offer is not crossed + offers(alice, 1), Balance(alice, usd(0))); // alice's offer is not crossed } } @@ -524,40 +525,41 @@ public: { Env env{*this, features}; - env.fund(XRP(10000), alice, bob, carol, gw); + env.fund(kXRP(10000), alice, bob, carol, gw); env.close(); - env.trust(USD(1000), alice, bob, carol); - env.trust(EUR(1000), alice, bob, carol); + env.trust(usd(1000), alice, bob, carol); + env.trust(eur(1000), alice, bob, carol); env.close(); // underfund carol's offer - auto const initialCarolUSD = tinyAmount(USD); + auto const initialCarolUSD = tinyAmount(usd); env(pay(gw, carol, initialCarolUSD)); - env(pay(gw, bob, USD(100))); - env(pay(gw, alice, EUR(100))); + env(pay(gw, bob, usd(100))); + env(pay(gw, alice, eur(100))); env.close(); // This offer is underfunded - env(offer(carol, EUR(1), USD(2))); + env(offer(carol, eur(1), usd(2))); env.close(); - env(offer(bob, EUR(2), USD(4), tfPassive)); + env(offer(bob, eur(2), usd(4), kTF_PASSIVE)); env.close(); env.require(offers(bob, 1), offers(carol, 1)); - std::uint32_t const flags = - partialPayment ? (tfNoRippleDirect | tfPartialPayment) : tfNoRippleDirect; + std::uint32_t const flags = partialPayment + ? (kTF_NO_RIPPLE_DIRECT | kTF_PARTIAL_PAYMENT) + : kTF_NO_RIPPLE_DIRECT; - TER const expectedTer = partialPayment ? TER{tesSUCCESS} : TER{tecPATH_PARTIAL}; + TER const expectedTer = partialPayment ? TER{TesSuccess} : TER{TecPathPartial}; - env(pay(alice, bob, USD(5)), - path(~USD), - sendmax(EUR(10)), - txflags(flags), - ter(expectedTer)); + env(pay(alice, bob, usd(5)), + Path(~usd), + Sendmax(eur(10)), + Txflags(flags), + Ter(expectedTer)); env.close(); if (isTesSuccess(expectedTer)) { env.require(offers(carol, 0)); - env.require(balance(carol, + env.require(Balance(carol, initialCarolUSD)); // offer is removed but not taken } else @@ -578,9 +580,9 @@ public: using namespace jtx; auto const gw = Account{"gateway"}; - auto const USD = gw["USD"]; - auto const BTC = gw["BTC"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const btc = gw["BTC"]; + auto const eur = gw["EUR"]; Account const alice{"alice"}; Account const bob{"bob"}; Account const carol{"carol"}; @@ -591,58 +593,58 @@ public: Env env{*this, features}; auto const gw1 = Account{"gw1"}; - auto const USD1 = gw1["USD"]; + auto const usD1 = gw1["USD"]; auto const gw2 = Account{"gw2"}; - auto const USD2 = gw2["USD"]; + auto const usD2 = gw2["USD"]; - env.fund(XRP(10000), alice, noripple(bob), carol, dan, gw1, gw2); + env.fund(kXRP(10000), alice, noripple(bob), carol, dan, gw1, gw2); env.close(); - env.trust(USD1(1000), alice, carol, dan); - env(trust(bob, USD1(1000), tfSetNoRipple)); - env.trust(USD2(1000), alice, carol, dan); - env(trust(bob, USD2(1000), tfSetNoRipple)); + env.trust(usD1(1000), alice, carol, dan); + env(trust(bob, usD1(1000), kTF_SET_NO_RIPPLE)); + env.trust(usD2(1000), alice, carol, dan); + env(trust(bob, usD2(1000), kTF_SET_NO_RIPPLE)); - env(pay(gw1, dan, USD1(50))); - env(pay(gw1, bob, USD1(50))); - env(pay(gw2, bob, USD2(50))); + env(pay(gw1, dan, usD1(50))); + env(pay(gw1, bob, usD1(50))); + env(pay(gw2, bob, usD2(50))); - env(offer(dan, XRP(50), USD1(50))); + env(offer(dan, kXRP(50), usD1(50))); - env(pay(alice, carol, USD2(50)), - path(~USD1, bob), - sendmax(XRP(50)), - txflags(tfNoRippleDirect), - ter(tecPATH_DRY)); + env(pay(alice, carol, usD2(50)), + Path(~usD1, bob), + Sendmax(kXRP(50)), + Txflags(kTF_NO_RIPPLE_DIRECT), + Ter(TecPathDry)); } { // Make sure payment works with default flags Env env{*this, features}; auto const gw1 = Account{"gw1"}; - auto const USD1 = gw1["USD"]; + auto const usD1 = gw1["USD"]; auto const gw2 = Account{"gw2"}; - auto const USD2 = gw2["USD"]; + auto const usD2 = gw2["USD"]; - env.fund(XRP(10000), alice, bob, carol, dan, gw1, gw2); + env.fund(kXRP(10000), alice, bob, carol, dan, gw1, gw2); env.close(); - env.trust(USD1(1000), alice, bob, carol, dan); - env.trust(USD2(1000), alice, bob, carol, dan); + env.trust(usD1(1000), alice, bob, carol, dan); + env.trust(usD2(1000), alice, bob, carol, dan); - env(pay(gw1, dan, USD1(50))); - env(pay(gw1, bob, USD1(50))); - env(pay(gw2, bob, USD2(50))); + env(pay(gw1, dan, usD1(50))); + env(pay(gw1, bob, usD1(50))); + env(pay(gw2, bob, usD2(50))); - env(offer(dan, XRP(50), USD1(50))); + env(offer(dan, kXRP(50), usD1(50))); - env(pay(alice, carol, USD2(50)), - path(~USD1, bob), - sendmax(XRP(50)), - txflags(tfNoRippleDirect)); + env(pay(alice, carol, usD2(50)), + Path(~usD1, bob), + Sendmax(kXRP(50)), + Txflags(kTF_NO_RIPPLE_DIRECT)); - env.require(balance(alice, xrpMinusFee(env, 10000 - 50))); - env.require(balance(bob, USD1(100))); - env.require(balance(bob, USD2(0))); - env.require(balance(carol, USD2(50))); + env.require(Balance(alice, xrpMinusFee(env, 10000 - 50))); + env.require(Balance(bob, usD1(100))); + env.require(Balance(bob, usD2(0))); + env.require(Balance(carol, usD2(50))); } } @@ -663,57 +665,57 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const usdOffer = USD(1000); - auto const xrpOffer = XRP(1000); + auto const usdOffer = usd(1000); + auto const xrpOffer = kXRP(1000); // No crossing: { Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); env.fund(r + f, alice); - env(trust(alice, usdOffer), ter(tesSUCCESS)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tecINSUF_RESERVE_OFFER)); + env(trust(alice, usdOffer), Ter(TesSuccess)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TecInsufReserveOffer)); - env.require(balance(alice, r - f), owners(alice, 1)); + env.require(Balance(alice, r - f), Owners(alice, 1)); } // Partial cross: { Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); - auto const usdOffer2 = USD(500); - auto const xrpOffer2 = XRP(500); + auto const usdOffer2 = usd(500); + auto const xrpOffer2 = kXRP(500); env.fund(r + f + xrpOffer, bob); - env(offer(bob, usdOffer2, xrpOffer2), ter(tesSUCCESS)); + env(offer(bob, usdOffer2, xrpOffer2), Ter(TesSuccess)); env.fund(r + f, alice); - env(trust(alice, usdOffer), ter(tesSUCCESS)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tesSUCCESS)); + env(trust(alice, usdOffer), Ter(TesSuccess)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TesSuccess)); env.require( - balance(alice, r - f + xrpOffer2), - balance(alice, usdOffer2), - owners(alice, 1), - balance(bob, r + xrpOffer2), - balance(bob, usdOffer2), - owners(bob, 1)); + Balance(alice, r - f + xrpOffer2), + Balance(alice, usdOffer2), + Owners(alice, 1), + Balance(bob, r + xrpOffer2), + Balance(bob, usdOffer2), + Owners(bob, 1)); } // Account has enough reserve as is, but not enough @@ -722,35 +724,35 @@ public: { Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); auto const f = env.current()->fees().base; auto const r = reserve(env, 0); - auto const usdOffer2 = USD(500); - auto const xrpOffer2 = XRP(500); + auto const usdOffer2 = usd(500); + auto const xrpOffer2 = kXRP(500); env.fund(r + f + xrpOffer, bob, carol); - env(offer(bob, usdOffer2, xrpOffer2), ter(tesSUCCESS)); - env(offer(carol, usdOffer, xrpOffer), ter(tesSUCCESS)); + env(offer(bob, usdOffer2, xrpOffer2), Ter(TesSuccess)); + env(offer(carol, usdOffer, xrpOffer), Ter(TesSuccess)); env.fund(r + f, alice); - env(trust(alice, usdOffer), ter(tesSUCCESS)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); - env(offer(alice, xrpOffer, usdOffer), ter(tesSUCCESS)); + env(trust(alice, usdOffer), Ter(TesSuccess)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); + env(offer(alice, xrpOffer, usdOffer), Ter(TesSuccess)); env.require( - balance(alice, r - f + xrpOffer), - balance(alice, USD(0)), - owners(alice, 1), - balance(bob, r + xrpOffer2), - balance(bob, usdOffer2), - owners(bob, 1), - balance(carol, r + xrpOffer2), - balance(carol, usdOffer2), - owners(carol, 2)); + Balance(alice, r - f + xrpOffer), + Balance(alice, usd(0)), + Owners(alice, 1), + Balance(bob, r + xrpOffer2), + Balance(bob, usdOffer2), + Owners(bob, 1), + Balance(carol, r + xrpOffer2), + Balance(carol, usdOffer2), + Owners(carol, 2)); } } @@ -773,11 +775,11 @@ public: using namespace jtx; - auto const startBalance = XRP(1000000); + auto const startBalance = kXRP(1000000); auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; // Fill or Kill - unless we fully cross, just charge a fee and don't // place the offer on the books. But also clean up expired offers @@ -791,48 +793,50 @@ public: env.close(); // bob creates an offer that expires before the next ledger close. - env(offer(bob, USD(500), XRP(500)), - json(sfExpiration.fieldName, lastClose(env) + 1), - ter(tesSUCCESS)); + env(offer(bob, usd(500), kXRP(500)), + Json(sfExpiration.fieldName, lastClose(env) + 1), + Ter(TesSuccess)); // The offer expires (it's not removed yet). env.close(); - env.require(owners(bob, 1), offers(bob, 1)); + env.require(Owners(bob, 1), offers(bob, 1)); // bob creates the offer that will be crossed. - env(offer(bob, USD(500), XRP(500)), ter(tesSUCCESS)); + env(offer(bob, usd(500), kXRP(500)), Ter(TesSuccess)); env.close(); - env.require(owners(bob, 2), offers(bob, 2)); + env.require(Owners(bob, 2), offers(bob, 2)); - env(trust(alice, USD(1000)), ter(tesSUCCESS)); - env(pay(gw, alice, USD(1000)), ter(tesSUCCESS)); + env(trust(alice, usd(1000)), Ter(TesSuccess)); + env(pay(gw, alice, usd(1000)), Ter(TesSuccess)); // Order that can't be filled but will remove bob's expired offer: { - TER const killedCode{TER{tecKILLED}}; - env(offer(alice, XRP(1000), USD(1000)), txflags(tfFillOrKill), ter(killedCode)); + TER const killedCode{TER{TecKilled}}; + env(offer(alice, kXRP(1000), usd(1000)), + Txflags(kTF_FILL_OR_KILL), + Ter(killedCode)); } env.require( - balance(alice, startBalance - (f * 2)), - balance(alice, USD(1000)), - owners(alice, 1), + Balance(alice, startBalance - (f * 2)), + Balance(alice, usd(1000)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - (f * 2)), - balance(bob, USD(none)), - owners(bob, 1), + Balance(bob, startBalance - (f * 2)), + Balance(bob, usd(kNONE)), + Owners(bob, 1), offers(bob, 1)); // Order that can be filled - env(offer(alice, XRP(500), USD(500)), txflags(tfFillOrKill), ter(tesSUCCESS)); + env(offer(alice, kXRP(500), usd(500)), Txflags(kTF_FILL_OR_KILL), Ter(TesSuccess)); env.require( - balance(alice, startBalance - (f * 3) + XRP(500)), - balance(alice, USD(500)), - owners(alice, 1), + Balance(alice, startBalance - (f * 3) + kXRP(500)), + Balance(alice, usd(500)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - (f * 2) - XRP(500)), - balance(bob, USD(500)), - owners(bob, 1), + Balance(bob, startBalance - (f * 2) - kXRP(500)), + Balance(bob, usd(500)), + Owners(bob, 1), offers(bob, 0)); } @@ -846,49 +850,51 @@ public: env.fund(startBalance, gw, alice, bob); env.close(); - env(trust(alice, USD(1000)), ter(tesSUCCESS)); - env(pay(gw, alice, USD(1000)), ter(tesSUCCESS)); + env(trust(alice, usd(1000)), Ter(TesSuccess)); + env(pay(gw, alice, usd(1000)), Ter(TesSuccess)); // No cross: { - TER const expectedCode = tecKILLED; - env(offer(alice, XRP(1000), USD(1000)), - txflags(tfImmediateOrCancel), - ter(expectedCode)); + TER const expectedCode = TecKilled; + env(offer(alice, kXRP(1000), usd(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL), + Ter(expectedCode)); } env.require( - balance(alice, startBalance - f - f), - balance(alice, USD(1000)), - owners(alice, 1), + Balance(alice, startBalance - f - f), + Balance(alice, usd(1000)), + Owners(alice, 1), offers(alice, 0)); // Partially cross: - env(offer(bob, USD(50), XRP(50)), ter(tesSUCCESS)); - env(offer(alice, XRP(1000), USD(1000)), txflags(tfImmediateOrCancel), ter(tesSUCCESS)); + env(offer(bob, usd(50), kXRP(50)), Ter(TesSuccess)); + env(offer(alice, kXRP(1000), usd(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL), + Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f + XRP(50)), - balance(alice, USD(950)), - owners(alice, 1), + Balance(alice, startBalance - f - f - f + kXRP(50)), + Balance(alice, usd(950)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - f - XRP(50)), - balance(bob, USD(50)), - owners(bob, 1), + Balance(bob, startBalance - f - kXRP(50)), + Balance(bob, usd(50)), + Owners(bob, 1), offers(bob, 0)); // Fully cross: - env(offer(bob, USD(50), XRP(50)), ter(tesSUCCESS)); - env(offer(alice, XRP(50), USD(50)), txflags(tfImmediateOrCancel), ter(tesSUCCESS)); + env(offer(bob, usd(50), kXRP(50)), Ter(TesSuccess)); + env(offer(alice, kXRP(50), usd(50)), Txflags(kTF_IMMEDIATE_OR_CANCEL), Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f - f + XRP(100)), - balance(alice, USD(900)), - owners(alice, 1), + Balance(alice, startBalance - f - f - f - f + kXRP(100)), + Balance(alice, usd(900)), + Owners(alice, 1), offers(alice, 0), - balance(bob, startBalance - f - f - XRP(100)), - balance(bob, USD(100)), - owners(bob, 1), + Balance(bob, startBalance - f - f - kXRP(100)), + Balance(bob, usd(100)), + Owners(bob, 1), offers(bob, 0)); } @@ -899,13 +905,13 @@ public: env.fund(startBalance, gw, alice, bob); env.close(); - env(trust(bob, USD(1000))); + env(trust(bob, usd(1000))); env.close(); - env(pay(gw, bob, USD(1000))); + env(pay(gw, bob, usd(1000))); env.close(); - env(offer(alice, USD(1000), XRP(2000))); + env(offer(alice, usd(1000), kXRP(2000))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -913,13 +919,13 @@ public: for (auto const& offerPtr : aliceOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == XRP(2000)); - BEAST_EXPECT(offer[sfTakerPays] == USD(1000)); + BEAST_EXPECT(offer[sfTakerGets] == kXRP(2000)); + BEAST_EXPECT(offer[sfTakerPays] == usd(1000)); } // bob creates a passive offer that could cross alice's. // bob's offer should stay in the ledger. - env(offer(bob, XRP(2000), USD(1000), tfPassive)); + env(offer(bob, kXRP(2000), usd(1000), kTF_PASSIVE)); env.close(); env.require(offers(alice, 1)); @@ -928,18 +934,18 @@ public: for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == USD(1000)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(2000)); + BEAST_EXPECT(offer[sfTakerGets] == usd(1000)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(2000)); } // It should be possible for gw to cross both of those offers. - env(offer(gw, XRP(2000), USD(1000))); + env(offer(gw, kXRP(2000), usd(1000))); env.close(); env.require(offers(alice, 0)); env.require(offers(gw, 0)); env.require(offers(bob, 1)); - env(offer(gw, USD(1000), XRP(2000))); + env(offer(gw, usd(1000), kXRP(2000))); env.close(); env.require(offers(bob, 0)); env.require(offers(gw, 0)); @@ -952,14 +958,14 @@ public: env.fund(startBalance, gw, "alice", "bob"); env.close(); - env(trust("bob", USD(1000))); + env(trust("bob", usd(1000))); env.close(); - env(pay(gw, "bob", USD(1000))); - env(offer("alice", USD(500), XRP(1001))); + env(pay(gw, "bob", usd(1000))); + env(offer("alice", usd(500), kXRP(1001))); env.close(); - env(offer("alice", USD(500), XRP(1000))); + env(offer("alice", usd(500), kXRP(1000))); env.close(); auto const aliceOffers = offersOnAccount(env, "alice"); @@ -968,7 +974,7 @@ public: // bob creates a passive offer. That offer should cross one // of alice's (the one with better quality) and leave alice's // other offer untouched. - env(offer("bob", XRP(2000), USD(1000), tfPassive)); + env(offer("bob", kXRP(2000), usd(1000), kTF_PASSIVE)); env.close(); env.require(offers("alice", 1)); @@ -977,8 +983,8 @@ public: for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; - BEAST_EXPECT(offer[sfTakerGets] == USD(499.5)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(999)); + BEAST_EXPECT(offer[sfTakerGets] == usd(499.5)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(999)); } } } @@ -990,10 +996,10 @@ public: using namespace jtx; - auto const startBalance = XRP(1000000); + auto const startBalance = kXRP(1000000); auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; @@ -1001,61 +1007,61 @@ public: env.close(); // Order that has invalid flags - env(offer(alice, USD(1000), XRP(1000)), - txflags(tfImmediateOrCancel + 1), - ter(temINVALID_FLAG)); - env.require(balance(alice, startBalance), owners(alice, 0), offers(alice, 0)); + env(offer(alice, usd(1000), kXRP(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL + 1), + Ter(TemInvalidFlag)); + env.require(Balance(alice, startBalance), Owners(alice, 0), offers(alice, 0)); // Order with incompatible flags - env(offer(alice, USD(1000), XRP(1000)), - txflags(tfImmediateOrCancel | tfFillOrKill), - ter(temINVALID_FLAG)); - env.require(balance(alice, startBalance), owners(alice, 0), offers(alice, 0)); + env(offer(alice, usd(1000), kXRP(1000)), + Txflags(kTF_IMMEDIATE_OR_CANCEL | kTF_FILL_OR_KILL), + Ter(TemInvalidFlag)); + env.require(Balance(alice, startBalance), Owners(alice, 0), offers(alice, 0)); // Sell and buy the same asset { // Alice tries an XRP to XRP order: - env(offer(alice, XRP(1000), XRP(1000)), ter(temBAD_OFFER)); - env.require(owners(alice, 0), offers(alice, 0)); + env(offer(alice, kXRP(1000), kXRP(1000)), Ter(TemBadOffer)); + env.require(Owners(alice, 0), offers(alice, 0)); // Alice tries an IOU to IOU order: - env(trust(alice, USD(1000)), ter(tesSUCCESS)); - env(pay(gw, alice, USD(1000)), ter(tesSUCCESS)); - env(offer(alice, USD(1000), USD(1000)), ter(temREDUNDANT)); - env.require(owners(alice, 1), offers(alice, 0)); + env(trust(alice, usd(1000)), Ter(TesSuccess)); + env(pay(gw, alice, usd(1000)), Ter(TesSuccess)); + env(offer(alice, usd(1000), usd(1000)), Ter(TemRedundant)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Offers with negative amounts { - env(offer(alice, -USD(1000), XRP(1000)), ter(temBAD_OFFER)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, -usd(1000), kXRP(1000)), Ter(TemBadOffer)); + env.require(Owners(alice, 1), offers(alice, 0)); - env(offer(alice, USD(1000), -XRP(1000)), ter(temBAD_OFFER)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, usd(1000), -kXRP(1000)), Ter(TemBadOffer)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Offer with a bad expiration { - env(offer(alice, USD(1000), XRP(1000)), - json(sfExpiration.fieldName, std::uint32_t(0)), - ter(temBAD_EXPIRATION)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, usd(1000), kXRP(1000)), + Json(sfExpiration.fieldName, std::uint32_t(0)), + Ter(TemBadExpiration)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Offer with a bad offer sequence { - env(offer(alice, USD(1000), XRP(1000)), - json(jss::OfferSequence, std::uint32_t(0)), - ter(temBAD_SEQUENCE)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, usd(1000), kXRP(1000)), + Json(jss::kOFFER_SEQUENCE, std::uint32_t(0)), + Ter(TemBadSequence)); + env.require(Owners(alice, 1), offers(alice, 0)); } // Use XRP as a currency code { - auto const BAD = IOU(gw, badCurrency()); + auto const bad = IOU(gw, badCurrency()); - env(offer(alice, XRP(1000), BAD(1000)), ter(temBAD_CURRENCY)); - env.require(owners(alice, 1), offers(alice, 0)); + env(offer(alice, kXRP(1000), bad(1000)), Ter(TemBadCurrency)); + env.require(Owners(alice, 1), offers(alice, 0)); } } @@ -1069,11 +1075,11 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const startBalance = XRP(1000000); - auto const usdOffer = USD(1000); - auto const xrpOffer = XRP(1000); + auto const startBalance = kXRP(1000000); + auto const usdOffer = usd(1000); + auto const xrpOffer = kXRP(1000); Env env{*this, features}; @@ -1082,55 +1088,55 @@ public: auto const f = env.current()->fees().base; - env(trust(alice, usdOffer), ter(tesSUCCESS)); - env(pay(gw, alice, usdOffer), ter(tesSUCCESS)); + env(trust(alice, usdOffer), Ter(TesSuccess)); + env(pay(gw, alice, usdOffer), Ter(TesSuccess)); env.close(); env.require( - balance(alice, startBalance - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1)); + Owners(alice, 1)); env(offer(alice, xrpOffer, usdOffer), - json(sfExpiration.fieldName, lastClose(env)), - ter(tecEXPIRED)); + Json(sfExpiration.fieldName, lastClose(env)), + Ter(TecExpired)); env.require( - balance(alice, startBalance - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1)); + Owners(alice, 1)); env.close(); // Add an offer that expires before the next ledger close env(offer(alice, xrpOffer, usdOffer), - json(sfExpiration.fieldName, lastClose(env) + 1), - ter(tesSUCCESS)); + Json(sfExpiration.fieldName, lastClose(env) + 1), + Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 1), - owners(alice, 2)); + Owners(alice, 2)); // The offer expires (it's not removed yet) env.close(); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 1), - owners(alice, 2)); + Owners(alice, 2)); // Add offer - the expired offer is removed - env(offer(bob, usdOffer, xrpOffer), ter(tesSUCCESS)); + env(offer(bob, usdOffer, xrpOffer), Ter(TesSuccess)); env.require( - balance(alice, startBalance - f - f - f), - balance(alice, usdOffer), + Balance(alice, startBalance - f - f - f), + Balance(alice, usdOffer), offers(alice, 0), - owners(alice, 1), - balance(bob, startBalance - f), - balance(bob, USD(none)), + Owners(alice, 1), + Balance(bob, startBalance - f), + Balance(bob, usd(kNONE)), offers(bob, 1), - owners(bob, 1)); + Owners(bob, 1)); } void @@ -1141,14 +1147,14 @@ public: using namespace jtx; auto const gw = Account{"gateway"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const usdOffer = USD(1000); - auto const xrpOffer = XRP(1000); + auto const usdOffer = usd(1000); + auto const xrpOffer = kXRP(1000); Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); env.close(); // The fee that's charged for transactions @@ -1158,144 +1164,144 @@ public: // fees are subtracted. env.fund(reserve(env, 0), "alice"); env.close(); - env(offer("alice", usdOffer, xrpOffer), ter(tecUNFUNDED_OFFER)); - env.require(balance("alice", reserve(env, 0) - f), owners("alice", 0)); + env(offer("alice", usdOffer, xrpOffer), Ter(TecUnfundedOffer)); + env.require(Balance("alice", reserve(env, 0) - f), Owners("alice", 0)); // Account has just enough for the reserve and the // fee. env.fund(reserve(env, 0) + f, "bob"); env.close(); - env(offer("bob", usdOffer, xrpOffer), ter(tecUNFUNDED_OFFER)); - env.require(balance("bob", reserve(env, 0)), owners("bob", 0)); + env(offer("bob", usdOffer, xrpOffer), Ter(TecUnfundedOffer)); + env.require(Balance("bob", reserve(env, 0)), Owners("bob", 0)); // Account has enough for the reserve, the fee and // the offer, and a bit more, but not enough for the // reserve after the offer is placed. - env.fund(reserve(env, 0) + f + XRP(1), "carol"); + env.fund(reserve(env, 0) + f + kXRP(1), "carol"); env.close(); - env(offer("carol", usdOffer, xrpOffer), ter(tecINSUF_RESERVE_OFFER)); - env.require(balance("carol", reserve(env, 0) + XRP(1)), owners("carol", 0)); + env(offer("carol", usdOffer, xrpOffer), Ter(TecInsufReserveOffer)); + env.require(Balance("carol", reserve(env, 0) + kXRP(1)), Owners("carol", 0)); // Account has enough for the reserve plus one // offer, and the fee. env.fund(reserve(env, 1) + f, "dan"); env.close(); - env(offer("dan", usdOffer, xrpOffer), ter(tesSUCCESS)); - env.require(balance("dan", reserve(env, 1)), owners("dan", 1)); + env(offer("dan", usdOffer, xrpOffer), Ter(TesSuccess)); + env.require(Balance("dan", reserve(env, 1)), Owners("dan", 1)); // Account has enough for the reserve plus one // offer, the fee and the entire offer amount. env.fund(reserve(env, 1) + f + xrpOffer, "eve"); env.close(); - env(offer("eve", usdOffer, xrpOffer), ter(tesSUCCESS)); - env.require(balance("eve", reserve(env, 1) + xrpOffer), owners("eve", 1)); + env(offer("eve", usdOffer, xrpOffer), Ter(TesSuccess)); + env.require(Balance("eve", reserve(env, 1) + xrpOffer), Owners("eve", 1)); } void - testSelfCross(bool use_partner, FeatureBitset features) + testSelfCross(bool usePartner, FeatureBitset features) { - testcase(std::string("Self-crossing") + (use_partner ? ", with partner account" : "")); + testcase(std::string("Self-crossing") + (usePartner ? ", with partner account" : "")); using namespace jtx; auto const gw = Account{"gateway"}; auto const partner = Account{"partner"}; - auto const USD = gw["USD"]; - auto const BTC = gw["BTC"]; + auto const usd = gw["USD"]; + auto const btc = gw["BTC"]; Env env{*this, features}; env.close(); - env.fund(XRP(10000), gw); - if (use_partner) + env.fund(kXRP(10000), gw); + if (usePartner) { - env.fund(XRP(10000), partner); + env.fund(kXRP(10000), partner); env.close(); - env(trust(partner, USD(100))); - env(trust(partner, BTC(500))); + env(trust(partner, usd(100))); + env(trust(partner, btc(500))); env.close(); - env(pay(gw, partner, USD(100))); - env(pay(gw, partner, BTC(500))); + env(pay(gw, partner, usd(100))); + env(pay(gw, partner, btc(500))); } - auto const& account_to_test = use_partner ? partner : gw; + auto const& accountToTest = usePartner ? partner : gw; env.close(); - env.require(offers(account_to_test, 0)); + env.require(offers(accountToTest, 0)); // PART 1: // we will make two offers that can be used to bridge BTC to USD // through XRP - env(offer(account_to_test, BTC(250), XRP(1000))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, btc(250), kXRP(1000))); + env.require(offers(accountToTest, 1)); // validate that the book now shows a BTC for XRP offer - BEAST_EXPECT(isOffer(env, account_to_test, BTC(250), XRP(1000))); + BEAST_EXPECT(isOffer(env, accountToTest, btc(250), kXRP(1000))); - auto const secondLegSeq = env.seq(account_to_test); - env(offer(account_to_test, XRP(1000), USD(50))); - env.require(offers(account_to_test, 2)); + auto const secondLegSeq = env.seq(accountToTest); + env(offer(accountToTest, kXRP(1000), usd(50))); + env.require(offers(accountToTest, 2)); // validate that the book also shows a XRP for USD offer - BEAST_EXPECT(isOffer(env, account_to_test, XRP(1000), USD(50))); + BEAST_EXPECT(isOffer(env, accountToTest, kXRP(1000), usd(50))); // now make an offer that will cross and auto-bridge, meaning // the outstanding offers will be taken leaving us with none - env(offer(account_to_test, USD(50), BTC(250))); + env(offer(accountToTest, usd(50), btc(250))); - auto jrr = getBookOffers(env, USD, BTC); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + auto jrr = getBookOffers(env, usd, btc); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); - jrr = getBookOffers(env, BTC, XRP); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, btc, kXRP); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); // At this point, all offers are expected to be consumed. { - auto acctOffers = offersOnAccount(env, account_to_test); + auto acctOffers = offersOnAccount(env, accountToTest); BEAST_EXPECT(acctOffers.empty()); for (auto const& offerPtr : acctOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(0)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(offer[sfTakerGets] == usd(0)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(0)); } } // cancel that lingering second offer so that it doesn't interfere // with the next set of offers we test. This will not be needed once // the bridging bug is fixed - env(offer_cancel(account_to_test, secondLegSeq)); - env.require(offers(account_to_test, 0)); + env(offer_cancel(accountToTest, secondLegSeq)); + env.require(offers(accountToTest, 0)); // PART 2: // simple direct crossing BTC to USD and then USD to BTC which causes // the first offer to be replaced - env(offer(account_to_test, BTC(250), USD(50))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, btc(250), usd(50))); + env.require(offers(accountToTest, 1)); // validate that the book shows one BTC for USD offer and no USD for // BTC offers - BEAST_EXPECT(isOffer(env, account_to_test, BTC(250), USD(50))); + BEAST_EXPECT(isOffer(env, accountToTest, btc(250), usd(50))); - jrr = getBookOffers(env, USD, BTC); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, usd, btc); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); // this second offer would self-cross directly, so it causes the first // offer by the same owner/taker to be removed - env(offer(account_to_test, USD(50), BTC(250))); - env.require(offers(account_to_test, 1)); + env(offer(accountToTest, usd(50), btc(250))); + env.require(offers(accountToTest, 1)); // validate that we now have just the second offer...the first // was removed - jrr = getBookOffers(env, BTC, USD); - BEAST_EXPECT(jrr[jss::offers].isArray()); - BEAST_EXPECT(jrr[jss::offers].size() == 0); + jrr = getBookOffers(env, btc, usd); + BEAST_EXPECT(jrr[jss::kOFFERS].isArray()); + BEAST_EXPECT(jrr[jss::kOFFERS].size() == 0); - BEAST_EXPECT(isOffer(env, account_to_test, USD(50), BTC(250))); + BEAST_EXPECT(isOffer(env, accountToTest, usd(50), btc(250))); } void @@ -1317,49 +1323,49 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; - auto const BTC = gw["BTC"]; + auto const usd = gw["USD"]; + auto const btc = gw["BTC"]; // these *interesting* amounts were taken // from the original JS test that was ported here - auto const gw_initial_balance = drops(1149999730); - auto const alice_initial_balance = drops(499946999680); - auto const bob_initial_balance = drops(10199999920); - auto const small_amount = STAmount{bob["USD"], UINT64_C(2710505431213761), -33}; + auto const gwInitialBalance = drops(1149999730); + auto const aliceInitialBalance = drops(499946999680); + auto const bobInitialBalance = drops(10199999920); + auto const smallAmount = STAmount{bob["USD"], UINT64_C(2710505431213761), -33}; - env.fund(gw_initial_balance, gw); - env.fund(alice_initial_balance, alice); - env.fund(bob_initial_balance, bob); + env.fund(gwInitialBalance, gw); + env.fund(aliceInitialBalance, alice); + env.fund(bobInitialBalance, bob); env.close(); env(rate(gw, 1.005)); - env(trust(alice, USD(500))); - env(trust(bob, USD(50))); + env(trust(alice, usd(500))); + env(trust(bob, usd(50))); env(trust(gw, alice["USD"](100))); env(pay(gw, alice, alice["USD"](50))); - env(pay(gw, bob, small_amount)); + env(pay(gw, bob, smallAmount)); - env(offer(alice, USD(50), XRP(150000))); + env(offer(alice, usd(50), kXRP(150000))); // unfund the offer - env(pay(alice, gw, USD(100))); + env(pay(alice, gw, usd(100))); // drop the trust line (set to 0) env(trust(gw, alice["USD"](0))); // verify balances auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "50"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "50"); jrr = ledgerEntryState(env, bob, gw, "USD"); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName][jss::value] == "-2710505431213761e-33"); + jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-2710505431213761e-33"); // create crossing offer std::uint32_t const bobOfferSeq = env.seq(bob); - env(offer(bob, XRP(2000), USD(1))); + env(offer(bob, kXRP(2000), usd(1))); if (localFeatures[fixReducedOffersV2]) { @@ -1368,10 +1374,10 @@ public: // the ledger. jrr = ledgerEntryState(env, bob, gw, "USD"); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName][jss::value] == "-2710505431213761e-33"); + jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-2710505431213761e-33"); - Json::Value const bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq)[jss::node]; - BEAST_EXPECT(bobOffer[sfTakerGets.jsonName][jss::value] == "1"); + Json::Value const bobOffer = ledgerEntryOffer(env, bob, bobOfferSeq)[jss::kNODE]; + BEAST_EXPECT(bobOffer[sfTakerGets.jsonName][jss::kVALUE] == "1"); BEAST_EXPECT(bobOffer[sfTakerPays.jsonName] == "2000000000"); return; } @@ -1386,24 +1392,24 @@ public: auto const crossingDelta = drops(1); jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "50"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "50"); BEAST_EXPECT( env.balance(alice, xrpIssue()) == - alice_initial_balance - env.current()->fees().base * 3 - crossingDelta); + aliceInitialBalance - env.current()->fees().base * 3 - crossingDelta); jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "0"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "0"); BEAST_EXPECT( env.balance(bob, xrpIssue()) == - bob_initial_balance - env.current()->fees().base * 2 + crossingDelta); + bobInitialBalance - env.current()->fees().base * 2 + crossingDelta); } } void - testOfferCrossWithXRP(bool reverse_order, FeatureBitset features) + testOfferCrossWithXRP(bool reverseOrder, FeatureBitset features) { testcase( - std::string("Offer Crossing with XRP, ") + (reverse_order ? "Reverse" : "Normal") + + std::string("Offer Crossing with XRP, ") + (reverseOrder ? "Reverse" : "Normal") + " order"); using namespace jtx; @@ -1413,44 +1419,44 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob); + env.fund(kXRP(10000), gw, alice, bob); env.close(); - env(trust(alice, USD(1000))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(1000))); + env(trust(bob, usd(1000))); env(pay(gw, alice, alice["USD"](500))); - if (reverse_order) - env(offer(bob, USD(1), XRP(4000))); + if (reverseOrder) + env(offer(bob, usd(1), kXRP(4000))); - env(offer(alice, XRP(150000), USD(50))); + env(offer(alice, kXRP(150000), usd(50))); - if (!reverse_order) - env(offer(bob, USD(1), XRP(4000))); + if (!reverseOrder) + env(offer(bob, usd(1), kXRP(4000))); // Existing offer pays better than this wants. // Fully consume existing offer. // Pay 1 USD, get 4000 XRP. auto jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-1"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-1"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == to_string( - (XRP(10000) - XRP(reverse_order ? 4000 : 3000) - env.current()->fees().base * 2) + (kXRP(10000) - kXRP(reverseOrder ? 4000 : 3000) - env.current()->fees().base * 2) .xrp())); jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-499"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-499"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == to_string( - (XRP(10000) + XRP(reverse_order ? 4000 : 3000) - env.current()->fees().base * 2) + (kXRP(10000) + kXRP(reverseOrder ? 4000 : 3000) - env.current()->fees().base * 2) .xrp())); } @@ -1466,31 +1472,31 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(100000), gw, alice, bob); + env.fund(kXRP(100000), gw, alice, bob); env.close(); - env(trust(alice, USD(1000))); + env(trust(alice, usd(1000))); env(pay(gw, alice, alice["USD"](500))); - env(offer(alice, XRP(150000), USD(50))); - env(offer(bob, USD(1), XRP(3000))); + env(offer(alice, kXRP(150000), usd(50))); + env(offer(bob, usd(1), kXRP(3000))); auto jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-1"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-1"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(100000) - XRP(3000) - env.current()->fees().base * 1).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(100000) - kXRP(3000) - env.current()->fees().base * 1).xrp())); jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-499"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-499"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(100000) + XRP(3000) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(100000) + kXRP(3000) - env.current()->fees().base * 2).xrp())); } void @@ -1502,10 +1508,10 @@ public: Env env{*this, features}; - auto const USD = env.master["USD"]; + auto const usd = env.master["USD"]; auto const nextOfferSeq = env.seq(env.master); - env(offer(env.master, XRP(500), USD(100))); + env(offer(env.master, kXRP(500), usd(100))); env.close(); env(offer_cancel(env.master, nextOfferSeq)); @@ -1529,14 +1535,14 @@ public: auto const alice = Account{"alice"}; auto const nextOfferSeq = env.seq(env.master); - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); env(offer_cancel(env.master, nextOfferSeq)); - env(offer_cancel(env.master, env.seq(env.master)), ter(temBAD_SEQUENCE)); + env(offer_cancel(env.master, env.seq(env.master)), Ter(TemBadSequence)); - env(offer_cancel(env.master, env.seq(env.master) + 1), ter(temBAD_SEQUENCE)); + env(offer_cancel(env.master, env.seq(env.master) + 1), Ter(TemBadSequence)); env.close(); } @@ -1553,42 +1559,43 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob); + env.fund(kXRP(10000), gw, alice, bob); env.close(); - env.require(owners(bob, 0)); + env.require(Owners(bob, 0)); - env(trust(alice, USD(100))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(100))); + env(trust(bob, usd(1000))); - env.require(owners(alice, 1), owners(bob, 1)); + env.require(Owners(alice, 1), Owners(bob, 1)); env(pay(gw, alice, alice["USD"](100))); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, USD(100), XRP(500))); + env(offer(bob, usd(100), kXRP(500))); - env.require(owners(alice, 1), owners(bob, 2)); + env.require(Owners(alice, 1), Owners(bob, 2)); auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(500).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(100).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(500).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(100).value().getJson(JsonOptions::None)); - env(pay(alice, alice, XRP(500)), sendmax(USD(100))); + env(pay(alice, alice, kXRP(500)), Sendmax(usd(100))); auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "0"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "0"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10000) + XRP(500) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(10000) + kXRP(500) - env.current()->fees().base * 2).xrp())); jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-100"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-100"); jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); - env.require(owners(alice, 1), owners(bob, 1)); + env.require(Owners(alice, 1), Owners(bob, 1)); } void @@ -1604,7 +1611,7 @@ public: auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - env.fund(XRP(10000), alice, bob, carol); + env.fund(kXRP(10000), alice, bob, carol); env.close(); env(trust(alice, carol["EUR"](2000))); @@ -1612,12 +1619,12 @@ public: env(trust(carol, bob["EUR"](1000))); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, alice["USD"](50), carol["EUR"](200)), ter(tecUNFUNDED_OFFER)); + env(offer(bob, alice["USD"](50), carol["EUR"](200)), Ter(TecUnfundedOffer)); env(offer(alice, carol["EUR"](200), alice["USD"](50))); auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); } void @@ -1632,51 +1639,52 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob); + env.fund(kXRP(10000), gw, alice, bob); env.close(); - env(trust(alice, USD(200))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(200))); + env(trust(bob, usd(1000))); env(pay(gw, alice, alice["USD"](200))); auto const bobOfferSeq = env.seq(bob); - env(offer(bob, USD(100), XRP(500))); + env(offer(bob, usd(100), kXRP(500))); - env(pay(alice, alice, XRP(200)), sendmax(USD(100))); + env(pay(alice, alice, kXRP(200)), Sendmax(usd(100))); // The previous payment reduced the remaining offer amount by 200 XRP auto jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(300).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(60).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(300).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(60).value().getJson(JsonOptions::None)); // the balance between alice and gw is 160 USD..200 less the 40 taken // by the offer auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-160"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-160"); // alice now has 200 more XRP from the payment jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10000) + XRP(200) - env.current()->fees().base * 2).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string((kXRP(10000) + kXRP(200) - env.current()->fees().base * 2).xrp())); // bob got 40 USD from partial consumption of the offer jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-40"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-40"); // Alice converts USD to XRP which should fail // due to PartialPayment. - env(pay(alice, alice, XRP(600)), sendmax(USD(100)), ter(tecPATH_PARTIAL)); + env(pay(alice, alice, kXRP(600)), Sendmax(usd(100)), Ter(TecPathPartial)); // Alice converts USD to XRP, should succeed because // we permit partial payment - env(pay(alice, alice, XRP(600)), sendmax(USD(100)), txflags(tfPartialPayment)); + env(pay(alice, alice, kXRP(600)), Sendmax(usd(100)), Txflags(kTF_PARTIAL_PAYMENT)); // Verify the offer was consumed jro = ledgerEntryOffer(env, bob, bobOfferSeq); - BEAST_EXPECT(jro[jss::error] == "entryNotFound"); + BEAST_EXPECT(jro[jss::kERROR] == "entryNotFound"); // verify balances look right after the partial payment // only 300 XRP should be have been payed since that's all @@ -1684,16 +1692,17 @@ public: // 100 USD because another 60 USD were transferred to bob in the second // payment jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-100"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-100"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - to_string((XRP(10000) + XRP(200) + XRP(300) - env.current()->fees().base * 4).xrp())); + jrr[jss::kNODE][sfBalance.fieldName] == + to_string( + (kXRP(10000) + kXRP(200) + kXRP(300) - env.current()->fees().base * 4).xrp())); // bob now has 100 USD - 40 from the first payment and 60 from the // second (partial) payment jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-100"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-100"); } void @@ -1709,30 +1718,31 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob, carol); + env.fund(kXRP(10000), gw, alice, bob, carol); env.close(); - env(trust(carol, USD(1000))); - env(trust(bob, USD(2000))); + env(trust(carol, usd(1000))); + env(trust(bob, usd(2000))); env(pay(gw, carol, carol["USD"](500))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, XRP(500), USD(50))); + env(offer(carol, kXRP(500), usd(50))); - env(pay(alice, bob, USD(25)), sendmax(XRP(333))); + env(pay(alice, bob, usd(25)), Sendmax(kXRP(333))); auto jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-25"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-25"); jrr = ledgerEntryState(env, carol, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-475"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-475"); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == USD(25).value().getJson(JsonOptions::none)); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == XRP(250).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_GETS] == usd(25).value().getJson(JsonOptions::None)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_PAYS] == kXRP(250).value().getText()); } void @@ -1748,35 +1758,36 @@ public: auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob, carol); + env.fund(kXRP(10000), gw, alice, bob, carol); env.close(); - env(trust(alice, USD(1000))); - env(trust(carol, USD(2000))); + env(trust(alice, usd(1000))); + env(trust(carol, usd(2000))); env(pay(gw, alice, alice["USD"](500))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, USD(50), XRP(500))); + env(offer(carol, usd(50), kXRP(500))); - env(pay(alice, bob, XRP(250)), sendmax(USD(333))); + env(pay(alice, bob, kXRP(250)), Sendmax(usd(333))); auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-475"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-475"); jrr = ledgerEntryState(env, carol, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-25"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-25"); jrr = ledgerEntryRoot(env, bob); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == - std::to_string(XRP(10000).value().mantissa() + XRP(250).value().mantissa())); + jrr[jss::kNODE][sfBalance.fieldName] == + std::to_string(kXRP(10000).value().mantissa() + kXRP(250).value().mantissa())); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(250).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(25).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(250).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(25).value().getJson(JsonOptions::None)); } void @@ -1794,50 +1805,51 @@ public: auto const bob = Account{"bob"}; auto const carol = Account{"carol"}; auto const dan = Account{"dan"}; - auto const USD = gw1["USD"]; - auto const EUR = gw2["EUR"]; + auto const usd = gw1["USD"]; + auto const eur = gw2["EUR"]; - env.fund(XRP(10000), gw1, gw2, alice, bob, carol, dan); + env.fund(kXRP(10000), gw1, gw2, alice, bob, carol, dan); env.close(); - env(trust(alice, USD(1000))); - env(trust(bob, EUR(1000))); - env(trust(carol, USD(1000))); - env(trust(dan, EUR(1000))); + env(trust(alice, usd(1000))); + env(trust(bob, eur(1000))); + env(trust(carol, usd(1000))); + env(trust(dan, eur(1000))); env(pay(gw1, alice, alice["USD"](500))); env(pay(gw2, dan, dan["EUR"](400))); auto const carolOfferSeq = env.seq(carol); - env(offer(carol, USD(50), XRP(500))); + env(offer(carol, usd(50), kXRP(500))); auto const danOfferSeq = env.seq(dan); - env(offer(dan, XRP(500), EUR(50))); + env(offer(dan, kXRP(500), eur(50))); - Json::Value jtp{Json::arrayValue}; - jtp[0u][0u][jss::currency] = "XRP"; - env(pay(alice, bob, EUR(30)), json(jss::Paths, jtp), sendmax(USD(333))); + Json::Value jtp{Json::ArrayValue}; + jtp[0u][0u][jss::kCURRENCY] = "XRP"; + env(pay(alice, bob, eur(30)), Json(jss::kPATHS, jtp), Sendmax(usd(333))); auto jrr = ledgerEntryState(env, alice, gw1, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "470"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "470"); jrr = ledgerEntryState(env, bob, gw2, "EUR"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-30"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-30"); jrr = ledgerEntryState(env, carol, gw1, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-30"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-30"); jrr = ledgerEntryState(env, dan, gw2, "EUR"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-370"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-370"); auto jro = ledgerEntryOffer(env, carol, carolOfferSeq); - BEAST_EXPECT(jro[jss::node][jss::TakerGets] == XRP(200).value().getText()); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == USD(20).value().getJson(JsonOptions::none)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_GETS] == kXRP(200).value().getText()); + BEAST_EXPECT( + jro[jss::kNODE][jss::kTAKER_PAYS] == usd(20).value().getJson(JsonOptions::None)); jro = ledgerEntryOffer(env, dan, danOfferSeq); BEAST_EXPECT( - jro[jss::node][jss::TakerGets] == gw2["EUR"](20).value().getJson(JsonOptions::none)); - BEAST_EXPECT(jro[jss::node][jss::TakerPays] == XRP(200).value().getText()); + jro[jss::kNODE][jss::kTAKER_GETS] == gw2["EUR"](20).value().getJson(JsonOptions::None)); + BEAST_EXPECT(jro[jss::kNODE][jss::kTAKER_PAYS] == kXRP(200).value().getText()); } void @@ -1855,24 +1867,24 @@ public: Account const bob{"bob"}; Account const carol{"carol"}; Account const gw{"gateway"}; - auto const USD = gw["USD"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const eur = gw["EUR"]; - env.fund(XRP(100000000), alice, bob, carol, gw); + env.fund(kXRP(100000000), alice, bob, carol, gw); env.close(); - env.trust(USD(10), alice); + env.trust(usd(10), alice); env.close(); - env(pay(gw, alice, USD(10))); - env.trust(USD(10), carol); + env(pay(gw, alice, usd(10))); + env.trust(usd(10), carol); env.close(); - env(pay(gw, carol, USD(3))); + env(pay(gw, carol, usd(3))); - env(offer(alice, EUR(2), XRP(1))); - env(offer(alice, EUR(2), XRP(1))); + env(offer(alice, eur(2), kXRP(1))); + env(offer(alice, eur(2), kXRP(1))); - env(offer(alice, XRP(1), USD(4))); - env(offer(carol, XRP(1), USD(3))); + env(offer(alice, kXRP(1), usd(4))); + env(offer(carol, kXRP(1), usd(3))); env.close(); // Bob offers to buy 10 USD for 10 EUR. @@ -1883,28 +1895,28 @@ public: // The key for this test is that Alice's XRP->USD leg goes dry before // Alice's EUR->XRP. The XRP->USD leg is the second leg which showed // some sensitivity. - env.trust(EUR(10), bob); + env.trust(eur(10), bob); env.close(); - env(pay(gw, bob, EUR(10))); + env(pay(gw, bob, eur(10))); env.close(); - env(offer(bob, USD(10), EUR(10))); + env(offer(bob, usd(10), eur(10))); env.close(); - env.require(balance(bob, USD(7))); - env.require(balance(bob, EUR(6))); + env.require(Balance(bob, usd(7))); + env.require(Balance(bob, eur(6))); env.require(offers(bob, 1)); - env.require(owners(bob, 3)); + env.require(Owners(bob, 3)); - env.require(balance(alice, USD(6))); - env.require(balance(alice, EUR(4))); + env.require(Balance(alice, usd(6))); + env.require(Balance(alice, eur(4))); env.require(offers(alice, 0)); - env.require(owners(alice, 2)); + env.require(Owners(alice, 2)); - env.require(balance(carol, USD(0))); - env.require(balance(carol, EUR(none))); + env.require(Balance(carol, usd(0))); + env.require(Balance(carol, eur(kNONE))); env.require(offers(carol, 0)); - env.require(owners(carol, 1)); + env.require(Owners(carol, 1)); } void @@ -1921,9 +1933,9 @@ public: auto const gw3 = Account{"gateway_3"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD1 = gw1["USD"]; - auto const USD2 = gw2["USD"]; - auto const USD3 = gw3["USD"]; + auto const usD1 = gw1["USD"]; + auto const usD2 = gw2["USD"]; + auto const usD3 = gw3["USD"]; // Provide micro amounts to compensate for fees to make results round // nice. @@ -1931,34 +1943,34 @@ public: // fees: // 1 for each trust limit == 3 (alice < mtgox/amazon/bitstamp) + // 1 for payment == 4 - auto const starting_xrp = - XRP(100) + env.current()->fees().accountReserve(3) + env.current()->fees().base * 4; + auto const startingXrp = + kXRP(100) + env.current()->fees().accountReserve(3) + env.current()->fees().base * 4; - env.fund(starting_xrp, gw1, gw2, gw3, alice, bob); + env.fund(startingXrp, gw1, gw2, gw3, alice, bob); env.close(); - env(trust(alice, USD1(1000))); - env(trust(alice, USD2(1000))); - env(trust(alice, USD3(1000))); - env(trust(bob, USD1(1000))); - env(trust(bob, USD2(1000))); + env(trust(alice, usD1(1000))); + env(trust(alice, usD2(1000))); + env(trust(alice, usD3(1000))); + env(trust(bob, usD1(1000))); + env(trust(bob, usD2(1000))); env(pay(gw1, bob, bob["USD"](500))); - env(offer(bob, XRP(200), USD1(200))); + env(offer(bob, kXRP(200), usD1(200))); // Alice has 350 fees - a reserve of 50 = 250 reserve = 100 available. // Ask for more than available to prove reserve works. - env(offer(alice, USD1(200), XRP(200))); + env(offer(alice, usD1(200), kXRP(200))); auto jrr = ledgerEntryState(env, alice, gw1, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "100"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "100"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == STAmount(env.current()->fees().accountReserve(3)).getText()); jrr = ledgerEntryState(env, bob, gw1, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-400"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-400"); } void @@ -1973,30 +1985,30 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob); + env.fund(kXRP(10000), gw, alice, bob); env.close(); env(rate(gw, 1.005)); - env(trust(alice, USD(1000))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(1000))); + env(trust(bob, usd(1000))); env(trust(gw, alice["USD"](50))); env(pay(gw, bob, bob["USD"](1))); - env(pay(alice, gw, USD(50))); + env(pay(alice, gw, usd(50))); env(trust(gw, alice["USD"](0))); - env(offer(alice, USD(50), XRP(150000))); - env(offer(bob, XRP(100), USD(0.1))); + env(offer(alice, usd(50), kXRP(150000))); + env(offer(bob, kXRP(100), usd(0.1))); auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "49.96666666666667"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "49.96666666666667"); jrr = ledgerEntryState(env, bob, gw, "USD"); - Json::Value const bobsUSD = jrr[jss::node][sfBalance.fieldName][jss::value]; + Json::Value const bobsUSD = jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE]; BEAST_EXPECT(bobsUSD == "-0.9665000000333333"); } @@ -2012,34 +2024,34 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const starting_xrp = - XRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; + auto const startingXrp = + kXRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); env.close(); - env(trust(alice, USD(1000))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(1000))); + env(trust(bob, usd(1000))); env(pay(gw, bob, bob["USD"](500))); - env(offer(bob, XRP(200), USD(200)), json(jss::Flags, tfSell)); + env(offer(bob, kXRP(200), usd(200)), Json(jss::kFLAGS, kTF_SELL)); // Alice has 350 + fees - a reserve of 50 = 250 reserve = 100 available. // Alice has 350 + fees - a reserve of 50 = 250 reserve = 100 available. // Ask for more than available to prove reserve works. - env(offer(alice, USD(200), XRP(200)), json(jss::Flags, tfSell)); + env(offer(alice, usd(200), kXRP(200)), Json(jss::kFLAGS, kTF_SELL)); auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-100"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-100"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == STAmount(env.current()->fees().accountReserve(1)).getText()); jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-400"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-400"); } void @@ -2054,36 +2066,36 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const starting_xrp = - XRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; + auto const startingXrp = + kXRP(100) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); env.close(); - env(trust(alice, USD(150))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(150))); + env(trust(bob, usd(1000))); env(pay(gw, bob, bob["USD"](500))); - env(offer(bob, XRP(100), USD(200))); + env(offer(bob, kXRP(100), usd(200))); // Alice has 350 fees - a reserve of 50 = 250 reserve = 100 available. // Ask for more than available to prove reserve works. // Taker pays 100 USD for 100 XRP. // Selling XRP. // Will sell all 100 XRP and get more USD than asked for. - env(offer(alice, USD(100), XRP(100)), json(jss::Flags, tfSell)); + env(offer(alice, usd(100), kXRP(100)), Json(jss::kFLAGS, kTF_SELL)); auto jrr = ledgerEntryState(env, alice, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-200"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-200"); jrr = ledgerEntryRoot(env, alice); BEAST_EXPECT( - jrr[jss::node][sfBalance.fieldName] == + jrr[jss::kNODE][sfBalance.fieldName] == STAmount(env.current()->fees().accountReserve(1)).getText()); jrr = ledgerEntryState(env, bob, gw, "USD"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-300"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-300"); } void @@ -2098,58 +2110,58 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const XTS = gw["XTS"]; - auto const XXX = gw["XXX"]; + auto const xts = gw["XTS"]; + auto const xxx = gw["XXX"]; - auto const starting_xrp = - XRP(100.1) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; + auto const startingXrp = + kXRP(100.1) + env.current()->fees().accountReserve(1) + env.current()->fees().base * 2; - env.fund(starting_xrp, gw, alice, bob); + env.fund(startingXrp, gw, alice, bob); env.close(); - env(trust(alice, XTS(1000))); - env(trust(alice, XXX(1000))); - env(trust(bob, XTS(1000))); - env(trust(bob, XXX(1000))); + env(trust(alice, xts(1000))); + env(trust(alice, xxx(1000))); + env(trust(bob, xts(1000))); + env(trust(bob, xxx(1000))); env(pay(gw, alice, alice["XTS"](100))); env(pay(gw, alice, alice["XXX"](100))); env(pay(gw, bob, bob["XTS"](100))); env(pay(gw, bob, bob["XXX"](100))); - env(offer(alice, XTS(100), XXX(100))); + env(offer(alice, xts(100), xxx(100))); // WS client is used here because the RPC client could not // be convinced to pass the build_path argument auto wsc = makeWSClient(env.app().config()); Json::Value payment; - payment[jss::secret] = toBase58(generateSeed("bob")); - payment[jss::id] = env.seq(bob); - payment[jss::build_path] = true; - payment[jss::tx_json] = pay(bob, bob, bob["XXX"](1)); - payment[jss::tx_json][jss::Sequence] = + payment[jss::kSECRET] = toBase58(generateSeed("bob")); + payment[jss::kID] = env.seq(bob); + payment[jss::kBUILD_PATH] = true; + payment[jss::kTX_JSON] = pay(bob, bob, bob["XXX"](1)); + payment[jss::kTX_JSON][jss::kSEQUENCE] = env.current()->read(keylet::account(bob.id()))->getFieldU32(sfSequence); - payment[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base); - payment[jss::tx_json][jss::SendMax] = bob["XTS"](1.5).value().getJson(JsonOptions::none); + payment[jss::kTX_JSON][jss::kFEE] = to_string(env.current()->fees().base); + payment[jss::kTX_JSON][jss::kSEND_MAX] = bob["XTS"](1.5).value().getJson(JsonOptions::None); auto jrr = wsc->invoke("submit", payment); - BEAST_EXPECT(jrr[jss::status] == "success"); - BEAST_EXPECT(jrr[jss::result][jss::engine_result] == "tesSUCCESS"); + BEAST_EXPECT(jrr[jss::kSTATUS] == "success"); + BEAST_EXPECT(jrr[jss::kRESULT][jss::kENGINE_RESULT] == "tesSUCCESS"); if (wsc->version() == 2) { - BEAST_EXPECT(jrr.isMember(jss::jsonrpc) && jrr[jss::jsonrpc] == "2.0"); - BEAST_EXPECT(jrr.isMember(jss::ripplerpc) && jrr[jss::ripplerpc] == "2.0"); - BEAST_EXPECT(jrr.isMember(jss::id) && jrr[jss::id] == 5); + BEAST_EXPECT(jrr.isMember(jss::kJSONRPC) && jrr[jss::kJSONRPC] == "2.0"); + BEAST_EXPECT(jrr.isMember(jss::kRIPPLERPC) && jrr[jss::kRIPPLERPC] == "2.0"); + BEAST_EXPECT(jrr.isMember(jss::kID) && jrr[jss::kID] == 5); } jrr = ledgerEntryState(env, alice, gw, "XTS"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-101"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-101"); jrr = ledgerEntryState(env, alice, gw, "XXX"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-99"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-99"); jrr = ledgerEntryState(env, bob, gw, "XTS"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-99"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-99"); jrr = ledgerEntryState(env, bob, gw, "XXX"); - BEAST_EXPECT(jrr[jss::node][sfBalance.fieldName][jss::value] == "-101"); + BEAST_EXPECT(jrr[jss::kNODE][sfBalance.fieldName][jss::kVALUE] == "-101"); } // Helper function that validates a *defaulted* trustline: one that has @@ -2199,24 +2211,24 @@ public: using namespace jtx; auto const gw = Account("gateway"); - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; - env.fund(XRP(10000000), gw); + env.fund(kXRP(10000000), gw); env.close(); // The fee that's charged for transactions auto const f = env.current()->fees().base; // To keep things simple all offers are 1 : 1 for XRP : USD. - enum class preTrustType { noPreTrust, gwPreTrust, acctPreTrust }; + enum class PreTrustType { NoPreTrust, GwPreTrust, AcctPreTrust }; struct TestData { std::string account; // Account operated on STAmount fundXrp; // Account funded with int bookAmount; // USD -> XRP offer on the books - preTrustType preTrust; // If true, pre-establish trust line + PreTrustType preTrust; // If true, pre-establish trust line int offerAmount; // Account offers this much XRP -> USD TER tec; // Returned tec code STAmount spentXrp; // Amount removed from fundXrp @@ -2228,45 +2240,45 @@ public: // clang-format off TestData const tests[]{ // acct fundXrp bookAmt preTrust offerAmount tec spentXrp balanceUSD offers owners - {.account="ann", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account is at the reserve, and will dip below once fees are subtracted. - {.account="bev", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account has just enough for the reserve and the fee. - {.account="cam", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, // Account has enough for the reserve, the fee and the offer, and a bit more, but not enough for the reserve after the offer is placed. - {.account="deb", .fundXrp=drops(10) + reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=drops(10) + f, .balanceUsd=USD(0.00001), .offers=0, .owners=1}, // Account has enough to buy a little USD then the offer runs dry. - {.account="eve", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=f, .balanceUsd=USD( 0), .offers=1, .owners=1}, // No offer to cross - {.account="flo", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="gay", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 50) + f, .balanceUsd=USD( 50), .offers=0, .owners=1}, - {.account="hye", .fundXrp=XRP(1000) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 800) + f, .balanceUsd=USD( 800), .offers=0, .owners=1}, - {.account="ivy", .fundXrp=XRP( 1) + reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="joy", .fundXrp=XRP( 1) + reserve(env, 2) + 1 * f, .bookAmount=1, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=1, .owners=2}, - {.account="kim", .fundXrp=XRP( 900) + reserve(env, 2) + 1 * f, .bookAmount=999, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="liz", .fundXrp=XRP( 998) + reserve(env, 0) + 1 * f, .bookAmount=999, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 998) + f, .balanceUsd=USD( 998), .offers=0, .owners=1}, - {.account="meg", .fundXrp=XRP( 998) + reserve(env, 1) + 1 * f, .bookAmount=999, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="nia", .fundXrp=XRP( 998) + reserve(env, 2) + 1 * f, .bookAmount=999, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=1, .owners=2}, - {.account="ova", .fundXrp=XRP( 999) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 999) + f, .balanceUsd=USD( 999), .offers=0, .owners=1}, - {.account="pam", .fundXrp=XRP( 999) + reserve(env, 1) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(1000) + f, .balanceUsd=USD( 1000), .offers=0, .owners=1}, - {.account="rae", .fundXrp=XRP( 999) + reserve(env, 2) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(1000) + f, .balanceUsd=USD( 1000), .offers=0, .owners=1}, - {.account="sue", .fundXrp=XRP(1000) + reserve(env, 2) + 1 * f, .bookAmount=0, .preTrust=preTrustType::noPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=f, .balanceUsd=USD( 0), .offers=1, .owners=1}, + {.account="ann", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account is at the reserve, and will dip below once fees are subtracted. + {.account="bev", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account has just enough for the reserve and the fee. + {.account="cam", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, // Account has enough for the reserve, the fee and the offer, and a bit more, but not enough for the reserve after the offer is placed. + {.account="deb", .fundXrp=drops(10) + reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=drops(10) + f, .balanceUsd=usd(0.00001), .offers=0, .owners=1}, // Account has enough to buy a little USD then the offer runs dry. + {.account="eve", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=f, .balanceUsd=usd( 0), .offers=1, .owners=1}, // No offer to cross + {.account="flo", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="gay", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 50) + f, .balanceUsd=usd( 50), .offers=0, .owners=1}, + {.account="hye", .fundXrp=kXRP(1000) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 800) + f, .balanceUsd=usd( 800), .offers=0, .owners=1}, + {.account="ivy", .fundXrp=kXRP( 1) + reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="joy", .fundXrp=kXRP( 1) + reserve(env, 2) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=1, .owners=2}, + {.account="kim", .fundXrp=kXRP( 900) + reserve(env, 2) + 1 * f, .bookAmount=999, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="liz", .fundXrp=kXRP( 998) + reserve(env, 0) + 1 * f, .bookAmount=999, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 998) + f, .balanceUsd=usd( 998), .offers=0, .owners=1}, + {.account="meg", .fundXrp=kXRP( 998) + reserve(env, 1) + 1 * f, .bookAmount=999, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="nia", .fundXrp=kXRP( 998) + reserve(env, 2) + 1 * f, .bookAmount=999, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=1, .owners=2}, + {.account="ova", .fundXrp=kXRP( 999) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 999) + f, .balanceUsd=usd( 999), .offers=0, .owners=1}, + {.account="pam", .fundXrp=kXRP( 999) + reserve(env, 1) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(1000) + f, .balanceUsd=usd( 1000), .offers=0, .owners=1}, + {.account="rae", .fundXrp=kXRP( 999) + reserve(env, 2) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(1000) + f, .balanceUsd=usd( 1000), .offers=0, .owners=1}, + {.account="sue", .fundXrp=kXRP(1000) + reserve(env, 2) + 1 * f, .bookAmount=0, .preTrust=PreTrustType::NoPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=f, .balanceUsd=usd( 0), .offers=1, .owners=1}, //---------------- Pre-established trust lines --------------------- - {.account="abe", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, - {.account="bud", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, - {.account="che", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=f, .balanceUsd=USD( 0), .offers=0, .owners=0}, - {.account="dan", .fundXrp=drops(10) + reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=drops(10) + f, .balanceUsd=USD(0.00001), .offers=0, .owners=0}, - {.account="eli", .fundXrp=XRP( 20) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(20) + 1 * f, .balanceUsd=USD( 20), .offers=0, .owners=0}, - {.account="fyn", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=f, .balanceUsd=USD( 0), .offers=1, .owners=1}, - {.account="gar", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=1, .owners=1}, - {.account="hal", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=preTrustType::gwPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + f, .balanceUsd=USD( 1), .offers=1, .owners=1}, + {.account="abe", .fundXrp=reserve(env, 0) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, + {.account="bud", .fundXrp=reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, + {.account="che", .fundXrp=reserve(env, 0) + 2 * f, .bookAmount=0, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=f, .balanceUsd=usd( 0), .offers=0, .owners=0}, + {.account="dan", .fundXrp=drops(10) + reserve(env, 0) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=drops(10) + f, .balanceUsd=usd(0.00001), .offers=0, .owners=0}, + {.account="eli", .fundXrp=kXRP( 20) + reserve(env, 0) + 1 * f, .bookAmount=1000, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(20) + 1 * f, .balanceUsd=usd( 20), .offers=0, .owners=0}, + {.account="fyn", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=0, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=f, .balanceUsd=usd( 0), .offers=1, .owners=1}, + {.account="gar", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=1, .owners=1}, + {.account="hal", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::GwPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + f, .balanceUsd=usd( 1), .offers=1, .owners=1}, - {.account="ned", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="ole", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="pat", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=0, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="quy", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecUNFUNDED_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="ron", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=0, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="syd", .fundXrp=drops(10) + reserve(env, 1) + 2 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=drops(10) + 2 * f, .balanceUsd=USD(0.00001), .offers=0, .owners=1}, - {.account="ted", .fundXrp=XRP( 20) + reserve(env, 1) + 2 * f, .bookAmount=1000, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP(20) + 2 * f, .balanceUsd=USD( 20), .offers=0, .owners=1}, - {.account="uli", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=0, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tecINSUF_RESERVE_OFFER, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=0, .owners=1}, - {.account="vic", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + 2 * f, .balanceUsd=USD( 1), .offers=0, .owners=1}, - {.account="wes", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=0, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=2 * f, .balanceUsd=USD( 0), .offers=1, .owners=2}, - {.account="xan", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=1, .preTrust=preTrustType::acctPreTrust, .offerAmount=1000, .tec=tesSUCCESS, .spentXrp=XRP( 1) + 2 * f, .balanceUsd=USD( 1), .offers=1, .owners=2}, + {.account="ned", .fundXrp=reserve(env, 1) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="ole", .fundXrp=reserve(env, 1) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="pat", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=0, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="quy", .fundXrp=reserve(env, 1) + 2 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecUnfundedOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="ron", .fundXrp=reserve(env, 1) + 3 * f, .bookAmount=0, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="syd", .fundXrp=drops(10) + reserve(env, 1) + 2 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=drops(10) + 2 * f, .balanceUsd=usd(0.00001), .offers=0, .owners=1}, + {.account="ted", .fundXrp=kXRP( 20) + reserve(env, 1) + 2 * f, .bookAmount=1000, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP(20) + 2 * f, .balanceUsd=usd( 20), .offers=0, .owners=1}, + {.account="uli", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=0, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TecInsufReserveOffer, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=0, .owners=1}, + {.account="vic", .fundXrp=reserve(env, 2) + 0 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + 2 * f, .balanceUsd=usd( 1), .offers=0, .owners=1}, + {.account="wes", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=0, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=2 * f, .balanceUsd=usd( 0), .offers=1, .owners=2}, + {.account="xan", .fundXrp=reserve(env, 2) + 1 * f, .bookAmount=1, .preTrust=PreTrustType::AcctPreTrust, .offerAmount=1000, .tec=TesSuccess, .spentXrp=kXRP( 1) + 2 * f, .balanceUsd=usd( 1), .offers=1, .owners=2}, }; // clang-format on @@ -2282,34 +2294,34 @@ public: // The gateway optionally creates an offer that would be crossed. auto const book = t.bookAmount; if (book != 0) - env(offer(gw, XRP(book), USD(book))); + env(offer(gw, kXRP(book), usd(book))); env.close(); std::uint32_t const gwOfferSeq = env.seq(gw) - 1; // Optionally pre-establish a trustline between gw and acct. - if (t.preTrust == preTrustType::gwPreTrust) + if (t.preTrust == PreTrustType::GwPreTrust) env(trust(gw, acct["USD"](1))); env.close(); // Optionally pre-establish a trustline between acct and gw. // Note this is not really part of the test, so we expect there // to be enough XRP reserve for acct to create the trust line. - if (t.preTrust == preTrustType::acctPreTrust) - env(trust(acct, USD(1))); + if (t.preTrust == PreTrustType::AcctPreTrust) + env(trust(acct, usd(1))); env.close(); { // Acct creates an offer. This is the heart of the test. auto const acctOffer = t.offerAmount; - env(offer(acct, USD(acctOffer), XRP(acctOffer)), ter(t.tec)); + env(offer(acct, usd(acctOffer), kXRP(acctOffer)), Ter(t.tec)); env.close(); } std::uint32_t const acctOfferSeq = env.seq(acct) - 1; - BEAST_EXPECT(env.balance(acct, USD) == t.balanceUsd); + BEAST_EXPECT(env.balance(acct, usd) == t.balanceUsd); BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp); env.require(offers(acct, t.offers)); - env.require(owners(acct, t.owners)); + env.require(Owners(acct, t.owners)); auto acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == t.offers); @@ -2318,11 +2330,11 @@ public: auto const& acctOffer = *(acctOffers.front()); auto const leftover = t.offerAmount - t.bookAmount; - BEAST_EXPECT(acctOffer[sfTakerGets] == XRP(leftover)); - BEAST_EXPECT(acctOffer[sfTakerPays] == USD(leftover)); + BEAST_EXPECT(acctOffer[sfTakerGets] == kXRP(leftover)); + BEAST_EXPECT(acctOffer[sfTakerPays] == usd(leftover)); } - if (t.preTrust == preTrustType::noPreTrust) + if (t.preTrust == PreTrustType::NoPreTrust) { if (t.balanceUsd.value().signum() != 0) { @@ -2332,7 +2344,7 @@ public: else { // Verify that no trustline was created. - auto const sleTrust = env.le(keylet::line(acct, USD)); + auto const sleTrust = env.le(keylet::line(acct, usd)); BEAST_EXPECT(!sleTrust); } } @@ -2355,14 +2367,14 @@ public: auto const gw = Account("gateway"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - auto const usdOffer = USD(1000); - auto const xrpOffer = XRP(1000); + auto const usdOffer = usd(1000); + auto const xrpOffer = kXRP(1000); Env env{*this, features}; - env.fund(XRP(1000000), gw, bob); + env.fund(kXRP(1000000), gw, bob); env.close(); // The fee that's charged for transactions. @@ -2379,7 +2391,7 @@ public: env(pay(gw, alice, usdOffer)); env.close(); - env.require(balance(alice, usdOffer), offers(alice, 0), offers(bob, 0)); + env.require(Balance(alice, usdOffer), offers(alice, 0), offers(bob, 0)); // The scenario: // o alice has USD but wants XRP. @@ -2393,32 +2405,32 @@ public: env.close(); env.require( - balance(alice, USD(0)), - balance(bob, usdOffer), - balance(alice, aliceXRP + xrpOffer - fee), - balance(bob, bobXRP - xrpOffer - fee), + Balance(alice, usd(0)), + Balance(bob, usdOffer), + Balance(alice, aliceXRP + xrpOffer - fee), + Balance(bob, bobXRP - xrpOffer - fee), offers(alice, 0), offers(bob, 0)); verifyDefaultTrustline(env, bob, usdOffer); // Make two more offers that leave one of the offers non-dry. - env(offer(alice, USD(999), XRP(999))); + env(offer(alice, usd(999), kXRP(999))); env(offer(bob, xrpOffer, usdOffer)); env.close(); - env.require(balance(alice, USD(999))); - env.require(balance(bob, USD(1))); + env.require(Balance(alice, usd(999))); + env.require(Balance(bob, usd(1))); env.require(offers(alice, 0)); - verifyDefaultTrustline(env, bob, USD(1)); + verifyDefaultTrustline(env, bob, usd(1)); { auto const bobOffers = offersOnAccount(env, bob); BEAST_EXPECT(bobOffers.size() == 1); auto const& bobOffer = *(bobOffers.front()); BEAST_EXPECT(bobOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(bobOffer[sfTakerGets] == USD(1)); - BEAST_EXPECT(bobOffer[sfTakerPays] == XRP(1)); + BEAST_EXPECT(bobOffer[sfTakerGets] == usd(1)); + BEAST_EXPECT(bobOffer[sfTakerPays] == kXRP(1)); } } @@ -2432,15 +2444,15 @@ public: auto const gw = Account("gateway"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const USD = gw["USD"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const eur = gw["EUR"]; - auto const usdOffer = USD(1000); - auto const eurOffer = EUR(1000); + auto const usdOffer = usd(1000); + auto const eurOffer = eur(1000); Env env{*this, features}; - env.fund(XRP(1000000), gw); + env.fund(kXRP(1000000), gw); env.close(); // The fee that's charged for transactions. @@ -2460,7 +2472,7 @@ public: env(pay(gw, bob, eurOffer)); env.close(); - env.require(balance(alice, usdOffer), balance(bob, eurOffer)); + env.require(Balance(alice, usdOffer), Balance(bob, eurOffer)); // The scenario: // o alice has USD but wants EUR. @@ -2470,7 +2482,7 @@ public: env.close(); env.require( - balance(alice, eurOffer), balance(bob, usdOffer), offers(alice, 0), offers(bob, 0)); + Balance(alice, eurOffer), Balance(bob, usdOffer), offers(alice, 0), offers(bob, 0)); // Alice's offer crossing created a default EUR trustline and // Bob's offer crossing created a default USD trustline: @@ -2483,16 +2495,16 @@ public: env(offer(bob, eurOffer, usdOffer)); env.close(); - env(offer(alice, USD(999), eurOffer)); + env(offer(alice, usd(999), eurOffer)); env.close(); env.require(offers(alice, 0)); env.require(offers(bob, 1)); - env.require(balance(alice, USD(999))); - env.require(balance(alice, EUR(1))); - env.require(balance(bob, USD(1))); - env.require(balance(bob, EUR(999))); + env.require(Balance(alice, usd(999))); + env.require(Balance(alice, eur(1))); + env.require(Balance(bob, usd(1))); + env.require(Balance(bob, eur(999))); { auto bobOffers = offersOnAccount(env, bob); @@ -2500,29 +2512,29 @@ public: { auto const& bobOffer = *(bobOffers.front()); - BEAST_EXPECT(bobOffer[sfTakerGets] == USD(1)); - BEAST_EXPECT(bobOffer[sfTakerPays] == EUR(1)); + BEAST_EXPECT(bobOffer[sfTakerGets] == usd(1)); + BEAST_EXPECT(bobOffer[sfTakerPays] == eur(1)); } } // alice makes one more offer that cleans out bob's offer. - env(offer(alice, USD(1), EUR(1))); + env(offer(alice, usd(1), eur(1))); env.close(); - env.require(balance(alice, USD(1000))); - env.require(balance(alice, EUR(none))); - env.require(balance(bob, USD(none))); - env.require(balance(bob, EUR(1000))); + env.require(Balance(alice, usd(1000))); + env.require(Balance(alice, eur(kNONE))); + env.require(Balance(bob, usd(kNONE))); + env.require(Balance(bob, eur(1000))); env.require(offers(alice, 0)); env.require(offers(bob, 0)); // The two trustlines that were generated by offers should be gone. - BEAST_EXPECT(!env.le(keylet::line(alice.id(), EUR))); - BEAST_EXPECT(!env.le(keylet::line(bob.id(), USD))); + BEAST_EXPECT(!env.le(keylet::line(alice.id(), eur))); + BEAST_EXPECT(!env.le(keylet::line(bob.id(), usd))); // Make two more offers that leave one of the offers non-dry. We // need to properly sequence the transactions: - env(offer(alice, EUR(999), usdOffer)); + env(offer(alice, eur(999), usdOffer)); env.close(); env(offer(bob, usdOffer, eurOffer)); @@ -2531,10 +2543,10 @@ public: env.require(offers(alice, 0)); env.require(offers(bob, 0)); - env.require(balance(alice, USD(0))); - env.require(balance(alice, EUR(999))); - env.require(balance(bob, USD(1000))); - env.require(balance(bob, EUR(1))); + env.require(Balance(alice, usd(0))); + env.require(Balance(alice, eur(999))); + env.require(Balance(bob, usd(1000))); + env.require(Balance(bob, eur(1))); } void @@ -2548,15 +2560,15 @@ public: auto const alice = Account("alice"); auto const bob = Account("bob"); auto const carol = Account("carol"); - auto const USD = gw["USD"]; - auto const EUR = gw["EUR"]; + auto const usd = gw["USD"]; + auto const eur = gw["EUR"]; - auto const usdOffer = USD(1000); - auto const eurOffer = EUR(1000); + auto const usdOffer = usd(1000); + auto const eurOffer = eur(1000); Env env{*this, features}; - env.fund(XRP(1000000), gw, alice, bob, carol); + env.fund(kXRP(1000000), gw, alice, bob, carol); env.close(); env(trust(alice, usdOffer)); @@ -2572,31 +2584,31 @@ public: // o carol has EUR but wants USD. // Note that carol's offer must come last. If carol's offer is placed // before bob's or alice's, then autobridging will not occur. - env(offer(alice, XRP(1000), usdOffer)); - env(offer(bob, eurOffer, XRP(1000))); + env(offer(alice, kXRP(1000), usdOffer)); + env(offer(bob, eurOffer, kXRP(1000))); auto const bobXrpBalance = env.balance(bob); env.close(); // carol makes an offer that partially consumes alice and bob's offers. - env(offer(carol, USD(400), EUR(400))); + env(offer(carol, usd(400), eur(400))); env.close(); env.require( - balance(alice, USD(600)), - balance(bob, EUR(400)), - balance(carol, USD(400)), - balance(bob, bobXrpBalance - XRP(400)), + Balance(alice, usd(600)), + Balance(bob, eur(400)), + Balance(carol, usd(400)), + Balance(bob, bobXrpBalance - kXRP(400)), offers(carol, 0)); - verifyDefaultTrustline(env, bob, EUR(400)); - verifyDefaultTrustline(env, carol, USD(400)); + verifyDefaultTrustline(env, bob, eur(400)); + verifyDefaultTrustline(env, carol, usd(400)); { auto const aliceOffers = offersOnAccount(env, alice); BEAST_EXPECT(aliceOffers.size() == 1); auto const& aliceOffer = *(aliceOffers.front()); BEAST_EXPECT(aliceOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(aliceOffer[sfTakerGets] == USD(600)); - BEAST_EXPECT(aliceOffer[sfTakerPays] == XRP(600)); + BEAST_EXPECT(aliceOffer[sfTakerGets] == usd(600)); + BEAST_EXPECT(aliceOffer[sfTakerPays] == kXRP(600)); } { auto const bobOffers = offersOnAccount(env, bob); @@ -2604,23 +2616,23 @@ public: auto const& bobOffer = *(bobOffers.front()); BEAST_EXPECT(bobOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(bobOffer[sfTakerGets] == XRP(600)); - BEAST_EXPECT(bobOffer[sfTakerPays] == EUR(600)); + BEAST_EXPECT(bobOffer[sfTakerGets] == kXRP(600)); + BEAST_EXPECT(bobOffer[sfTakerPays] == eur(600)); } // carol makes an offer that exactly consumes alice and bob's offers. - env(offer(carol, USD(600), EUR(600))); + env(offer(carol, usd(600), eur(600))); env.close(); env.require( - balance(alice, USD(0)), - balance(bob, eurOffer), - balance(carol, usdOffer), - balance(bob, bobXrpBalance - XRP(1000)), + Balance(alice, usd(0)), + Balance(bob, eurOffer), + Balance(carol, usdOffer), + Balance(bob, bobXrpBalance - kXRP(1000)), offers(bob, 0), offers(carol, 0)); - verifyDefaultTrustline(env, bob, EUR(1000)); - verifyDefaultTrustline(env, carol, USD(1000)); + verifyDefaultTrustline(env, bob, eur(1000)); + verifyDefaultTrustline(env, carol, usd(1000)); // In pre-flow code alice's offer is left empty in the ledger. auto const aliceOffers = offersOnAccount(env, alice); @@ -2630,8 +2642,8 @@ public: auto const& aliceOffer = *(aliceOffers.front()); BEAST_EXPECT(aliceOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(aliceOffer[sfTakerGets] == USD(0)); - BEAST_EXPECT(aliceOffer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(aliceOffer[sfTakerGets] == usd(0)); + BEAST_EXPECT(aliceOffer[sfTakerPays] == kXRP(0)); } } @@ -2646,18 +2658,18 @@ public: using namespace jtx; auto const gw = Account("gateway"); - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; - env.fund(XRP(10000000), gw); + env.fund(kXRP(10000000), gw); env.close(); // The fee that's charged for transactions auto const f = env.current()->fees().base; // To keep things simple all offers are 1 : 1 for XRP : USD. - enum class preTrustType { noPreTrust, gwPreTrust, acctPreTrust }; + enum class PreTrustType { NoPreTrust, GwPreTrust, AcctPreTrust }; struct TestData { std::string account; // Account operated on @@ -2677,64 +2689,64 @@ public: // Constructor with takerGets/takerPays TestData( - std::string&& account_, // Account operated on - STAmount fundXrp_, // XRP acct funded with - STAmount fundUSD_, // USD acct funded with - STAmount gwGets_, // gw's offer - STAmount gwPays_, // - STAmount acctGets_, // acct's offer - STAmount acctPays_, // - TER tec_, // Returned tec code - STAmount spentXrp_, // Amount removed from fundXrp - STAmount finalUsd_, // Final USD balance on acct - int offers_, // Offers on acct - int owners_, // Owners on acct - STAmount takerGets_, // Remainder of acct's offer - STAmount takerPays_) // - : account(std::move(account_)) - , fundXrp(std::move(fundXrp_)) - , fundUSD(std::move(fundUSD_)) - , gwGets(std::move(gwGets_)) - , gwPays(std::move(gwPays_)) - , acctGets(std::move(acctGets_)) - , acctPays(std::move(acctPays_)) - , tec(tec_) - , spentXrp(std::move(spentXrp_)) - , finalUsd(std::move(finalUsd_)) - , offers(offers_) - , owners(owners_) - , takerGets(std::move(takerGets_)) - , takerPays(std::move(takerPays_)) + std::string&& account, // Account operated on + STAmount fundXrp, // XRP acct funded with + STAmount fundUsd, // USD acct funded with + STAmount gwGets, // gw's offer + STAmount gwPays, // + STAmount acctGets, // acct's offer + STAmount acctPays, // + TER tec, // Returned tec code + STAmount spentXrp, // Amount removed from fundXrp + STAmount finalUsd, // Final USD balance on acct + int offers, // Offers on acct + int owners, // Owners on acct + STAmount takerGets, // Remainder of acct's offer + STAmount takerPays) // + : account(std::move(account)) + , fundXrp(std::move(fundXrp)) + , fundUSD(std::move(fundUsd)) + , gwGets(std::move(gwGets)) + , gwPays(std::move(gwPays)) + , acctGets(std::move(acctGets)) + , acctPays(std::move(acctPays)) + , tec(tec) + , spentXrp(std::move(spentXrp)) + , finalUsd(std::move(finalUsd)) + , offers(offers) + , owners(owners) + , takerGets(std::move(takerGets)) + , takerPays(std::move(takerPays)) { } // Constructor without takerGets/takerPays TestData( - std::string&& account_, // Account operated on - STAmount const& fundXrp_, // XRP acct funded with - STAmount const& fundUSD_, // USD acct funded with - STAmount const& gwGets_, // gw's offer - STAmount const& gwPays_, // - STAmount const& acctGets_, // acct's offer - STAmount const& acctPays_, // - TER tec_, // Returned tec code - STAmount const& spentXrp_, // Amount removed from fundXrp - STAmount const& finalUsd_, // Final USD balance on acct - int offers_, // Offers on acct - int owners_) // Owners on acct + std::string&& account, // Account operated on + STAmount const& fundXrp, // XRP acct funded with + STAmount const& fundUsd, // USD acct funded with + STAmount const& gwGets, // gw's offer + STAmount const& gwPays, // + STAmount const& acctGets, // acct's offer + STAmount const& acctPays, // + TER tec, // Returned tec code + STAmount const& spentXrp, // Amount removed from fundXrp + STAmount const& finalUsd, // Final USD balance on acct + int offers, // Offers on acct + int owners) // Owners on acct : TestData( - std::move(account_), - fundXrp_, - fundUSD_, - gwGets_, - gwPays_, - acctGets_, - acctPays_, - tec_, - spentXrp_, - finalUsd_, - offers_, - owners_, + std::move(account), + fundXrp, + fundUsd, + gwGets, + gwPays, + acctGets, + acctPays, + tec, + spentXrp, + finalUsd, + offers, + owners, STAmount{0}, STAmount{0}) { @@ -2745,26 +2757,26 @@ public: TestData const tests[]{ // acct pays XRP // acct fundXrp fundUSD gwGets gwPays acctGets acctPays tec spentXrp finalUSD offers owners takerGets takerPays - {"ann", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD( 5), USD(10), XRP(10), tecINSUF_RESERVE_OFFER, XRP( 0) + (1 * f), USD( 0), 0, 0}, - {"bev", XRP(10) + reserve(env, 1) + 1 * f, USD( 0), XRP(10), USD( 5), USD(10), XRP(10), tesSUCCESS, XRP( 0) + (1 * f), USD( 0), 1, 1, XRP(10), USD(10)}, - {"cam", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(10), USD(10), XRP(10), tesSUCCESS, XRP( 10) + (1 * f), USD(10), 0, 1}, - {"deb", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD(10), XRP(10), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"eve", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD( 5), XRP( 5), tesSUCCESS, XRP( 5) + (1 * f), USD(10), 0, 1}, - {"flo", XRP(10) + reserve(env, 0) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"gay", XRP(20) + reserve(env, 1) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 0, 1}, - {"hye", XRP(20) + reserve(env, 2) + 1 * f, USD( 0), XRP(10), USD(20), USD(20), XRP(20), tesSUCCESS, XRP( 10) + (1 * f), USD(20), 1, 2, XRP(10), USD(10)}, + {"ann", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd( 5), usd(10), kXRP(10), TecInsufReserveOffer, kXRP( 0) + (1 * f), usd( 0), 0, 0}, + {"bev", kXRP(10) + reserve(env, 1) + 1 * f, usd( 0), kXRP(10), usd( 5), usd(10), kXRP(10), TesSuccess, kXRP( 0) + (1 * f), usd( 0), 1, 1, kXRP(10), usd(10)}, + {"cam", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(10), usd(10), kXRP(10), TesSuccess, kXRP( 10) + (1 * f), usd(10), 0, 1}, + {"deb", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd(10), kXRP(10), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"eve", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd( 5), kXRP( 5), TesSuccess, kXRP( 5) + (1 * f), usd(10), 0, 1}, + {"flo", kXRP(10) + reserve(env, 0) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"gay", kXRP(20) + reserve(env, 1) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 0, 1}, + {"hye", kXRP(20) + reserve(env, 2) + 1 * f, usd( 0), kXRP(10), usd(20), usd(20), kXRP(20), TesSuccess, kXRP( 10) + (1 * f), usd(20), 1, 2, kXRP(10), usd(10)}, // acct pays USD - {"meg", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP( 5), XRP(10), USD(10), tecINSUF_RESERVE_OFFER, XRP( 0) + (2 * f), USD(10), 0, 1}, - {"nia", reserve(env, 2) + 2 * f, USD(10), USD(10), XRP( 5), XRP(10), USD(10), tesSUCCESS, XRP( 0) + (2 * f), USD(10), 1, 2, USD(10), XRP(10)}, - {"ova", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP(10), XRP(10), USD(10), tesSUCCESS, XRP(-10) + (2 * f), USD( 0), 0, 1}, - {"pam", reserve(env, 1) + 2 * f, USD(10), USD(10), XRP(20), XRP(10), USD(10), tesSUCCESS, XRP(-20) + (2 * f), USD( 0), 0, 1}, - {"qui", reserve(env, 1) + 2 * f, USD(10), USD(20), XRP(40), XRP(10), USD(10), tesSUCCESS, XRP(-20) + (2 * f), USD( 0), 0, 1}, - {"rae", reserve(env, 2) + 2 * f, USD(10), USD( 5), XRP( 5), XRP(10), USD(10), tesSUCCESS, XRP( -5) + (2 * f), USD( 5), 1, 2, USD( 5), XRP( 5)}, - {"sue", reserve(env, 2) + 2 * f, USD(10), USD( 5), XRP(10), XRP(10), USD(10), tesSUCCESS, XRP(-10) + (2 * f), USD( 5), 1, 2, USD( 5), XRP( 5)}, + {"meg", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP( 5), kXRP(10), usd(10), TecInsufReserveOffer, kXRP( 0) + (2 * f), usd(10), 0, 1}, + {"nia", reserve(env, 2) + 2 * f, usd(10), usd(10), kXRP( 5), kXRP(10), usd(10), TesSuccess, kXRP( 0) + (2 * f), usd(10), 1, 2, usd(10), kXRP(10)}, + {"ova", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP(10), kXRP(10), usd(10), TesSuccess, kXRP(-10) + (2 * f), usd( 0), 0, 1}, + {"pam", reserve(env, 1) + 2 * f, usd(10), usd(10), kXRP(20), kXRP(10), usd(10), TesSuccess, kXRP(-20) + (2 * f), usd( 0), 0, 1}, + {"qui", reserve(env, 1) + 2 * f, usd(10), usd(20), kXRP(40), kXRP(10), usd(10), TesSuccess, kXRP(-20) + (2 * f), usd( 0), 0, 1}, + {"rae", reserve(env, 2) + 2 * f, usd(10), usd( 5), kXRP( 5), kXRP(10), usd(10), TesSuccess, kXRP( -5) + (2 * f), usd( 5), 1, 2, usd( 5), kXRP( 5)}, + {"sue", reserve(env, 2) + 2 * f, usd(10), usd( 5), kXRP(10), kXRP(10), usd(10), TesSuccess, kXRP(-10) + (2 * f), usd( 5), 1, 2, usd( 5), kXRP( 5)}, }; // clang-format on - auto const zeroUsd = USD(0); + auto const zeroUsd = usd(0); for (auto const& t : tests) { // Make sure gateway has no current offers. @@ -2791,15 +2803,15 @@ public: std::uint32_t const gwOfferSeq = env.seq(gw) - 1; // Acct creates a tfSell offer. This is the heart of the test. - env(offer(acct, t.acctGets, t.acctPays, tfSell), ter(t.tec)); + env(offer(acct, t.acctGets, t.acctPays, kTF_SELL), Ter(t.tec)); env.close(); std::uint32_t const acctOfferSeq = env.seq(acct) - 1; // Check results - BEAST_EXPECT(env.balance(acct, USD) == t.finalUsd); + BEAST_EXPECT(env.balance(acct, usd) == t.finalUsd); BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp); env.require(offers(acct, t.offers)); - env.require(owners(acct, t.owners)); + env.require(Owners(acct, t.owners)); if (t.offers != 0) { @@ -2835,50 +2847,50 @@ public: auto const gw = Account("gateway"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; - env.fund(XRP(10000000), gw, alice, bob); + env.fund(kXRP(10000000), gw, alice, bob); env.close(); // Code returned if an offer is killed. - TER const killedCode{TER{tecKILLED}}; + TER const killedCode{TER{TecKilled}}; // bob offers XRP for USD. - env(trust(bob, USD(200))); + env(trust(bob, usd(200))); env.close(); - env(pay(gw, bob, USD(100))); + env(pay(gw, bob, usd(100))); env.close(); - env(offer(bob, XRP(2000), USD(20))); + env(offer(bob, kXRP(2000), usd(20))); env.close(); { // alice submits a tfSell | tfFillOrKill offer that does not cross. - env(offer(alice, USD(21), XRP(2100), tfSell | tfFillOrKill), ter(killedCode)); + env(offer(alice, usd(21), kXRP(2100), kTF_SELL | kTF_FILL_OR_KILL), Ter(killedCode)); env.close(); - env.require(balance(alice, USD(none))); + env.require(Balance(alice, usd(kNONE))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(100))); + env.require(Balance(bob, usd(100))); } { // alice submits a tfSell | tfFillOrKill offer that crosses. // Even though tfSell is present it doesn't matter this time. - env(offer(alice, USD(20), XRP(2000), tfSell | tfFillOrKill)); + env(offer(alice, usd(20), kXRP(2000), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(20))); + env.require(Balance(alice, usd(20))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(80))); + env.require(Balance(bob, usd(80))); } { // alice submits a tfSell | tfFillOrKill offer that crosses and // returns more than was asked for (because of the tfSell flag). - env(offer(bob, XRP(2000), USD(20))); + env(offer(bob, kXRP(2000), usd(20))); env.close(); - env(offer(alice, USD(10), XRP(1500), tfSell | tfFillOrKill)); + env(offer(alice, usd(10), kXRP(1500), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(35))); + env.require(Balance(alice, usd(35))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(65))); + env.require(Balance(bob, usd(65))); } { // alice submits a tfSell | tfFillOrKill offer that doesn't cross. @@ -2887,22 +2899,22 @@ public: // all of the offer is consumed. // We're using bob's left-over offer for XRP(500), USD(5) - env(offer(alice, USD(1), XRP(501), tfSell | tfFillOrKill), ter(killedCode)); + env(offer(alice, usd(1), kXRP(501), kTF_SELL | kTF_FILL_OR_KILL), Ter(killedCode)); env.close(); - env.require(balance(alice, USD(35))); + env.require(Balance(alice, usd(35))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(65))); + env.require(Balance(bob, usd(65))); } { // Alice submits a tfSell | tfFillOrKill offer that finishes // off the remainder of bob's offer. // We're using bob's left-over offer for XRP(500), USD(5) - env(offer(alice, USD(1), XRP(500), tfSell | tfFillOrKill)); + env(offer(alice, usd(1), kXRP(500), kTF_SELL | kTF_FILL_OR_KILL)); env.close(); - env.require(balance(alice, USD(40))); + env.require(Balance(alice, usd(40))); env.require(offers(alice, 0)); - env.require(balance(bob, USD(60))); + env.require(Balance(bob, usd(60))); } } @@ -2914,28 +2926,28 @@ public: using namespace jtx; auto const gw1 = Account("gateway1"); - auto const USD = gw1["USD"]; + auto const usd = gw1["USD"]; Env env{*this, features}; // The fee that's charged for transactions. auto const fee = env.current()->fees().base; - env.fund(XRP(100000), gw1); + env.fund(kXRP(100000), gw1); env.close(); env(rate(gw1, 1.25)); { auto const ann = Account("ann"); auto const bob = Account("bob"); - env.fund(XRP(100) + reserve(env, 2) + (fee * 2), ann, bob); + env.fund(kXRP(100) + reserve(env, 2) + (fee * 2), ann, bob); env.close(); - env(trust(ann, USD(200))); - env(trust(bob, USD(200))); + env(trust(ann, usd(200))); + env(trust(bob, usd(200))); env.close(); - env(pay(gw1, bob, USD(125))); + env(pay(gw1, bob, usd(125))); env.close(); // bob offers to sell USD(100) for XRP. alice takes bob's offer. @@ -2944,18 +2956,18 @@ public: // // A comparable payment would look like this: // env (pay (bob, alice, USD(100)), sendmax(USD(125))) - env(offer(bob, XRP(1), USD(100))); + env(offer(bob, kXRP(1), usd(100))); env.close(); - env(offer(ann, USD(100), XRP(1))); + env(offer(ann, usd(100), kXRP(1))); env.close(); - env.require(balance(ann, USD(100))); - env.require(balance(ann, XRP(99) + reserve(env, 2))); + env.require(Balance(ann, usd(100))); + env.require(Balance(ann, kXRP(99) + reserve(env, 2))); env.require(offers(ann, 0)); - env.require(balance(bob, USD(0))); - env.require(balance(bob, XRP(101) + reserve(env, 2))); + env.require(Balance(bob, usd(0))); + env.require(Balance(bob, kXRP(101) + reserve(env, 2))); env.require(offers(bob, 0)); } { @@ -2963,77 +2975,77 @@ public: // in return for USD. Gateway rate should still apply identically. auto const che = Account("che"); auto const deb = Account("deb"); - env.fund(XRP(100) + reserve(env, 2) + (fee * 2), che, deb); + env.fund(kXRP(100) + reserve(env, 2) + (fee * 2), che, deb); env.close(); - env(trust(che, USD(200))); - env(trust(deb, USD(200))); + env(trust(che, usd(200))); + env(trust(deb, usd(200))); env.close(); - env(pay(gw1, deb, USD(125))); + env(pay(gw1, deb, usd(125))); env.close(); - env(offer(che, USD(100), XRP(1))); + env(offer(che, usd(100), kXRP(1))); env.close(); - env(offer(deb, XRP(1), USD(100))); + env(offer(deb, kXRP(1), usd(100))); env.close(); - env.require(balance(che, USD(100))); - env.require(balance(che, XRP(99) + reserve(env, 2))); + env.require(Balance(che, usd(100))); + env.require(Balance(che, kXRP(99) + reserve(env, 2))); env.require(offers(che, 0)); - env.require(balance(deb, USD(0))); - env.require(balance(deb, XRP(101) + reserve(env, 2))); + env.require(Balance(deb, usd(0))); + env.require(Balance(deb, kXRP(101) + reserve(env, 2))); env.require(offers(deb, 0)); } { auto const eve = Account("eve"); auto const fyn = Account("fyn"); - env.fund(XRP(20000) + (fee * 2), eve, fyn); + env.fund(kXRP(20000) + (fee * 2), eve, fyn); env.close(); - env(trust(eve, USD(1000))); - env(trust(fyn, USD(1000))); + env(trust(eve, usd(1000))); + env(trust(fyn, usd(1000))); env.close(); - env(pay(gw1, eve, USD(100))); - env(pay(gw1, fyn, USD(100))); + env(pay(gw1, eve, usd(100))); + env(pay(gw1, fyn, usd(100))); env.close(); // This test verifies that the amount removed from an offer // accounts for the transfer fee that is removed from the // account but not from the remaining offer. - env(offer(eve, USD(10), XRP(4000))); + env(offer(eve, usd(10), kXRP(4000))); env.close(); std::uint32_t const eveOfferSeq = env.seq(eve) - 1; - env(offer(fyn, XRP(2000), USD(5))); + env(offer(fyn, kXRP(2000), usd(5))); env.close(); - env.require(balance(eve, USD(105))); - env.require(balance(eve, XRP(18000))); + env.require(Balance(eve, usd(105))); + env.require(Balance(eve, kXRP(18000))); auto const evesOffers = offersOnAccount(env, eve); BEAST_EXPECT(evesOffers.size() == 1); if (!evesOffers.empty()) { auto const& evesOffer = *(evesOffers.front()); BEAST_EXPECT(evesOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(evesOffer[sfTakerGets] == XRP(2000)); - BEAST_EXPECT(evesOffer[sfTakerPays] == USD(5)); + BEAST_EXPECT(evesOffer[sfTakerGets] == kXRP(2000)); + BEAST_EXPECT(evesOffer[sfTakerPays] == usd(5)); } env(offer_cancel(eve, eveOfferSeq)); // For later tests - env.require(balance(fyn, USD(93.75))); - env.require(balance(fyn, XRP(22000))); + env.require(Balance(fyn, usd(93.75))); + env.require(Balance(fyn, kXRP(22000))); env.require(offers(fyn, 0)); } // Start messing with two non-native currencies. auto const gw2 = Account("gateway2"); - auto const EUR = gw2["EUR"]; + auto const eur = gw2["EUR"]; - env.fund(XRP(100000), gw2); + env.fund(kXRP(100000), gw2); env.close(); env(rate(gw2, 1.5)); @@ -3046,30 +3058,30 @@ public: env.fund(reserve(env, 3) + (fee * 3), gay, hal); env.close(); - env(trust(gay, USD(200))); - env(trust(gay, EUR(200))); - env(trust(hal, USD(200))); - env(trust(hal, EUR(200))); + env(trust(gay, usd(200))); + env(trust(gay, eur(200))); + env(trust(hal, usd(200))); + env(trust(hal, eur(200))); env.close(); - env(pay(gw1, gay, USD(125))); - env(pay(gw2, hal, EUR(150))); + env(pay(gw1, gay, usd(125))); + env(pay(gw2, hal, eur(150))); env.close(); - env(offer(gay, EUR(100), USD(100))); + env(offer(gay, eur(100), usd(100))); env.close(); - env(offer(hal, USD(100), EUR(100))); + env(offer(hal, usd(100), eur(100))); env.close(); - env.require(balance(gay, USD(0))); - env.require(balance(gay, EUR(100))); - env.require(balance(gay, reserve(env, 3))); + env.require(Balance(gay, usd(0))); + env.require(Balance(gay, eur(100))); + env.require(Balance(gay, reserve(env, 3))); env.require(offers(gay, 0)); - env.require(balance(hal, USD(100))); - env.require(balance(hal, EUR(0))); - env.require(balance(hal, reserve(env, 3))); + env.require(Balance(hal, usd(100))); + env.require(Balance(hal, eur(0))); + env.require(Balance(hal, reserve(env, 3))); env.require(offers(hal, 0)); } { @@ -3079,116 +3091,116 @@ public: env.fund(reserve(env, 3) + (fee * 3), ivy, joe); env.close(); - env(trust(ivy, USD(400)), qualityInPercent(90)); - env(trust(ivy, EUR(400)), qualityInPercent(80)); - env(trust(joe, USD(400)), qualityInPercent(70)); - env(trust(joe, EUR(400)), qualityInPercent(60)); + env(trust(ivy, usd(400)), QualityInPercent(90)); + env(trust(ivy, eur(400)), QualityInPercent(80)); + env(trust(joe, usd(400)), QualityInPercent(70)); + env(trust(joe, eur(400)), QualityInPercent(60)); env.close(); - env(pay(gw1, ivy, USD(270)), sendmax(USD(500))); - env(pay(gw2, joe, EUR(150)), sendmax(EUR(300))); + env(pay(gw1, ivy, usd(270)), Sendmax(usd(500))); + env(pay(gw2, joe, eur(150)), Sendmax(eur(300))); env.close(); - env.require(balance(ivy, USD(300))); - env.require(balance(joe, EUR(250))); + env.require(Balance(ivy, usd(300))); + env.require(Balance(joe, eur(250))); - env(offer(ivy, EUR(100), USD(200))); + env(offer(ivy, eur(100), usd(200))); env.close(); - env(offer(joe, USD(200), EUR(100))); + env(offer(joe, usd(200), eur(100))); env.close(); - env.require(balance(ivy, USD(50))); - env.require(balance(ivy, EUR(100))); - env.require(balance(ivy, reserve(env, 3))); + env.require(Balance(ivy, usd(50))); + env.require(Balance(ivy, eur(100))); + env.require(Balance(ivy, reserve(env, 3))); env.require(offers(ivy, 0)); - env.require(balance(joe, USD(200))); - env.require(balance(joe, EUR(100))); - env.require(balance(joe, reserve(env, 3))); + env.require(Balance(joe, usd(200))); + env.require(Balance(joe, eur(100))); + env.require(Balance(joe, reserve(env, 3))); env.require(offers(joe, 0)); } { // A trust line's QualityOut should not affect offer crossing. auto const kim = Account("kim"); - auto const K_BUX = kim["BUX"]; + auto const kBux = kim["BUX"]; auto const lex = Account("lex"); auto const meg = Account("meg"); auto const ned = Account("ned"); - auto const N_BUX = ned["BUX"]; + auto const nBux = ned["BUX"]; // Verify trust line QualityOut affects payments. env.fund(reserve(env, 4) + (fee * 4), kim, lex, meg, ned); env.close(); - env(trust(lex, K_BUX(400))); - env(trust(lex, N_BUX(200)), qualityOutPercent(120)); - env(trust(meg, N_BUX(100))); + env(trust(lex, kBux(400))); + env(trust(lex, nBux(200)), QualityOutPercent(120)); + env(trust(meg, nBux(100))); env.close(); - env(pay(ned, lex, N_BUX(100))); + env(pay(ned, lex, nBux(100))); env.close(); - env.require(balance(lex, N_BUX(100))); + env.require(Balance(lex, nBux(100))); - env(pay(kim, meg, N_BUX(60)), path(lex, ned), sendmax(K_BUX(200))); + env(pay(kim, meg, nBux(60)), Path(lex, ned), Sendmax(kBux(200))); env.close(); - env.require(balance(kim, K_BUX(none))); - env.require(balance(kim, N_BUX(none))); - env.require(balance(lex, K_BUX(72))); - env.require(balance(lex, N_BUX(40))); - env.require(balance(meg, K_BUX(none))); - env.require(balance(meg, N_BUX(60))); - env.require(balance(ned, K_BUX(none))); - env.require(balance(ned, N_BUX(none))); + env.require(Balance(kim, kBux(kNONE))); + env.require(Balance(kim, nBux(kNONE))); + env.require(Balance(lex, kBux(72))); + env.require(Balance(lex, nBux(40))); + env.require(Balance(meg, kBux(kNONE))); + env.require(Balance(meg, nBux(60))); + env.require(Balance(ned, kBux(kNONE))); + env.require(Balance(ned, nBux(kNONE))); // Now verify that offer crossing is unaffected by QualityOut. - env(offer(lex, K_BUX(30), N_BUX(30))); + env(offer(lex, kBux(30), nBux(30))); env.close(); - env(offer(kim, N_BUX(30), K_BUX(30))); + env(offer(kim, nBux(30), kBux(30))); env.close(); - env.require(balance(kim, K_BUX(none))); - env.require(balance(kim, N_BUX(30))); - env.require(balance(lex, K_BUX(102))); - env.require(balance(lex, N_BUX(10))); - env.require(balance(meg, K_BUX(none))); - env.require(balance(meg, N_BUX(60))); - env.require(balance(ned, K_BUX(-30))); - env.require(balance(ned, N_BUX(none))); + env.require(Balance(kim, kBux(kNONE))); + env.require(Balance(kim, nBux(30))); + env.require(Balance(lex, kBux(102))); + env.require(Balance(lex, nBux(10))); + env.require(Balance(meg, kBux(kNONE))); + env.require(Balance(meg, nBux(60))); + env.require(Balance(ned, kBux(-30))); + env.require(Balance(ned, nBux(kNONE))); } { // Make sure things work right when we're auto-bridging as well. auto const ova = Account("ova"); auto const pat = Account("pat"); auto const qae = Account("qae"); - env.fund(XRP(2) + reserve(env, 3) + (fee * 3), ova, pat, qae); + env.fund(kXRP(2) + reserve(env, 3) + (fee * 3), ova, pat, qae); env.close(); // o ova has USD but wants XRP. // o pat has XRP but wants EUR. // o qae has EUR but wants USD. - env(trust(ova, USD(200))); - env(trust(ova, EUR(200))); - env(trust(pat, USD(200))); - env(trust(pat, EUR(200))); - env(trust(qae, USD(200))); - env(trust(qae, EUR(200))); + env(trust(ova, usd(200))); + env(trust(ova, eur(200))); + env(trust(pat, usd(200))); + env(trust(pat, eur(200))); + env(trust(qae, usd(200))); + env(trust(qae, eur(200))); env.close(); - env(pay(gw1, ova, USD(125))); - env(pay(gw2, qae, EUR(150))); + env(pay(gw1, ova, usd(125))); + env(pay(gw2, qae, eur(150))); env.close(); - env(offer(ova, XRP(2), USD(100))); - env(offer(pat, EUR(100), XRP(2))); + env(offer(ova, kXRP(2), usd(100))); + env(offer(pat, eur(100), kXRP(2))); env.close(); - env(offer(qae, USD(100), EUR(100))); + env(offer(qae, usd(100), eur(100))); env.close(); - env.require(balance(ova, USD(0))); - env.require(balance(ova, EUR(0))); - env.require(balance(ova, XRP(4) + reserve(env, 3))); + env.require(Balance(ova, usd(0))); + env.require(Balance(ova, eur(0))); + env.require(Balance(ova, kXRP(4) + reserve(env, 3))); // In pre-flow code ova's offer is left empty in the ledger. auto const ovasOffers = offersOnAccount(env, ova); @@ -3198,18 +3210,18 @@ public: auto const& ovasOffer = *(ovasOffers.front()); BEAST_EXPECT(ovasOffer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(ovasOffer[sfTakerGets] == USD(0)); - BEAST_EXPECT(ovasOffer[sfTakerPays] == XRP(0)); + BEAST_EXPECT(ovasOffer[sfTakerGets] == usd(0)); + BEAST_EXPECT(ovasOffer[sfTakerPays] == kXRP(0)); } - env.require(balance(pat, USD(0))); - env.require(balance(pat, EUR(100))); - env.require(balance(pat, XRP(0) + reserve(env, 3))); + env.require(Balance(pat, usd(0))); + env.require(Balance(pat, eur(100))); + env.require(Balance(pat, kXRP(0) + reserve(env, 3))); env.require(offers(pat, 0)); - env.require(balance(qae, USD(100))); - env.require(balance(qae, EUR(0))); - env.require(balance(qae, XRP(2) + reserve(env, 3))); + env.require(Balance(qae, usd(100))); + env.require(Balance(qae, eur(0))); + env.require(Balance(qae, kXRP(2) + reserve(env, 3))); env.require(offers(qae, 0)); } } @@ -3234,26 +3246,26 @@ public: using namespace jtx; auto const gw = Account("gateway"); - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; Env env{*this, features}; // The fee that's charged for transactions. auto const fee = env.current()->fees().base; - auto const startBalance = XRP(1000000); + auto const startBalance = kXRP(1000000); env.fund(startBalance + (fee * 4), gw); env.close(); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); - env(offer(gw, USD(60), XRP(600))); + env(offer(gw, usd(60), kXRP(600))); env.close(); - env.require(owners(gw, 3)); - env.require(balance(gw, startBalance + fee)); + env.require(Owners(gw, 3)); + env.require(Balance(gw, startBalance + fee)); auto gwOffers = offersOnAccount(env, gw); BEAST_EXPECT(gwOffers.size() == 3); @@ -3261,17 +3273,17 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == XRP(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(60)); + BEAST_EXPECT(offer[sfTakerGets] == kXRP(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(60)); } // Since this offer crosses the first offers, the previous offers // will be deleted and this offer will be put on the order book. - env(offer(gw, XRP(1000), USD(100))); + env(offer(gw, kXRP(1000), usd(100))); env.close(); - env.require(owners(gw, 1)); + env.require(Owners(gw, 1)); env.require(offers(gw, 1)); - env.require(balance(gw, startBalance)); + env.require(Balance(gw, startBalance)); gwOffers = offersOnAccount(env, gw); BEAST_EXPECT(gwOffers.size() == 1); @@ -3279,8 +3291,8 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(100)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(1000)); + BEAST_EXPECT(offer[sfTakerGets] == usd(100)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(1000)); } } @@ -3292,12 +3304,12 @@ public: auto const gw1 = Account("gateway1"); auto const gw2 = Account("gateway2"); auto const alice = Account("alice"); - auto const USD = gw1["USD"]; - auto const EUR = gw2["EUR"]; + auto const usd = gw1["USD"]; + auto const eur = gw2["EUR"]; Env env{*this, features}; - env.fund(XRP(1000000), gw1, gw2); + env.fund(kXRP(1000000), gw1, gw2); env.close(); // The fee that's charged for transactions. @@ -3317,12 +3329,12 @@ public: // clang-format off TestData const tests[]{ // acct fundXRP fundUSD fundEUR firstOfferTec secondOfferTec - {.acct="ann", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=USD(1000), .fundEUR=EUR(1000), .firstOfferTec=tesSUCCESS, .secondOfferTec=tesSUCCESS}, - {.acct="bev", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=USD( 1), .fundEUR=EUR(1000), .firstOfferTec=tesSUCCESS, .secondOfferTec=tesSUCCESS}, - {.acct="cam", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=USD(1000), .fundEUR=EUR( 1), .firstOfferTec=tesSUCCESS, .secondOfferTec=tesSUCCESS}, - {.acct="deb", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=USD( 0), .fundEUR=EUR( 1), .firstOfferTec=tesSUCCESS, .secondOfferTec=tecUNFUNDED_OFFER}, - {.acct="eve", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=USD( 1), .fundEUR=EUR( 0), .firstOfferTec=tecUNFUNDED_OFFER, .secondOfferTec=tesSUCCESS}, - {.acct="flo", .fundXRP=reserve(env, 3) + 0, .fundUSD=USD(1000), .fundEUR=EUR(1000), .firstOfferTec=tecINSUF_RESERVE_OFFER, .secondOfferTec=tecINSUF_RESERVE_OFFER}, + {.acct="ann", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=usd(1000), .fundEUR=eur(1000), .firstOfferTec=TesSuccess, .secondOfferTec=TesSuccess}, + {.acct="bev", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=usd( 1), .fundEUR=eur(1000), .firstOfferTec=TesSuccess, .secondOfferTec=TesSuccess}, + {.acct="cam", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=usd(1000), .fundEUR=eur( 1), .firstOfferTec=TesSuccess, .secondOfferTec=TesSuccess}, + {.acct="deb", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=usd( 0), .fundEUR=eur( 1), .firstOfferTec=TesSuccess, .secondOfferTec=TecUnfundedOffer}, + {.acct="eve", .fundXRP=reserve(env, 3) + f * 4, .fundUSD=usd( 1), .fundEUR=eur( 0), .firstOfferTec=TecUnfundedOffer, .secondOfferTec=TesSuccess}, + {.acct="flo", .fundXRP=reserve(env, 3) + 0, .fundUSD=usd(1000), .fundEUR=eur(1000), .firstOfferTec=TecInsufReserveOffer, .secondOfferTec=TecInsufReserveOffer}, }; //clang-format on @@ -3332,24 +3344,24 @@ public: env.fund(t.fundXRP, acct); env.close(); - env(trust(acct, USD(1000))); - env(trust(acct, EUR(1000))); + env(trust(acct, usd(1000))); + env(trust(acct, eur(1000))); env.close(); - if (t.fundUSD > USD(0)) + if (t.fundUSD > usd(0)) env(pay(gw1, acct, t.fundUSD)); - if (t.fundEUR > EUR(0)) + if (t.fundEUR > eur(0)) env(pay(gw2, acct, t.fundEUR)); env.close(); - env(offer(acct, USD(500), EUR(600)), ter(t.firstOfferTec)); + env(offer(acct, usd(500), eur(600)), Ter(t.firstOfferTec)); env.close(); std::uint32_t const firstOfferSeq = env.seq(acct) - 1; int offerCount = isTesSuccess(t.firstOfferTec) ? 1 : 0; - env.require(owners(acct, 2 + offerCount)); - env.require(balance(acct, t.fundUSD)); - env.require(balance(acct, t.fundEUR)); + env.require(Owners(acct, 2 + offerCount)); + env.require(Balance(acct, t.fundUSD)); + env.require(Balance(acct, t.fundEUR)); auto acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == offerCount); @@ -3357,18 +3369,18 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == EUR(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(500)); + BEAST_EXPECT(offer[sfTakerGets] == eur(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(500)); } - env(offer(acct, EUR(600), USD(500)), ter(t.secondOfferTec)); + env(offer(acct, eur(600), usd(500)), Ter(t.secondOfferTec)); env.close(); std::uint32_t const secondOfferSeq = env.seq(acct) - 1; offerCount = isTesSuccess(t.secondOfferTec) ? 1 : offerCount; - env.require(owners(acct, 2 + offerCount)); - env.require(balance(acct, t.fundUSD)); - env.require(balance(acct, t.fundEUR)); + env.require(Owners(acct, 2 + offerCount)); + env.require(Balance(acct, t.fundUSD)); + env.require(Balance(acct, t.fundEUR)); acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == offerCount); @@ -3378,13 +3390,13 @@ public: BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); if (offer[sfSequence] == firstOfferSeq) { - BEAST_EXPECT(offer[sfTakerGets] == EUR(600)); - BEAST_EXPECT(offer[sfTakerPays] == USD(500)); + BEAST_EXPECT(offer[sfTakerGets] == eur(600)); + BEAST_EXPECT(offer[sfTakerPays] == usd(500)); } else { - BEAST_EXPECT(offer[sfTakerGets] == USD(500)); - BEAST_EXPECT(offer[sfTakerPays] == EUR(600)); + BEAST_EXPECT(offer[sfTakerGets] == usd(500)); + BEAST_EXPECT(offer[sfTakerPays] == eur(600)); } } @@ -3417,23 +3429,23 @@ public: auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const USD = bob["USD"]; + auto const usd = bob["USD"]; auto const f = env.current()->fees().base; - env.fund(XRP(50000) + f, alice, bob); + env.fund(kXRP(50000) + f, alice, bob); env.close(); - env(offer(alice, USD(5000), XRP(50000))); + env(offer(alice, usd(5000), kXRP(50000))); env.close(); // This offer should take alice's offer up to Alice's reserve. - env(offer(bob, XRP(50000), USD(5000))); + env(offer(bob, kXRP(50000), usd(5000))); env.close(); // alice's offer should have been removed, since she's down to her // XRP reserve. - env.require(balance(alice, XRP(250))); - env.require(owners(alice, 1)); + env.require(Balance(alice, kXRP(250))); + env.require(Owners(alice, 1)); env.require(lines(alice, 1)); // However bob's offer should be in the ledger, since it was not @@ -3444,8 +3456,8 @@ public: { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); - BEAST_EXPECT(offer[sfTakerGets] == USD(25)); - BEAST_EXPECT(offer[sfTakerPays] == XRP(250)); + BEAST_EXPECT(offer[sfTakerGets] == usd(25)); + BEAST_EXPECT(offer[sfTakerPays] == kXRP(250)); } } @@ -3466,57 +3478,57 @@ public: { // A trust line's QualityOut should not affect offer crossing. auto const ann = Account("ann"); - auto const A_BUX = ann["BUX"]; + auto const aBux = ann["BUX"]; auto const bob = Account("bob"); auto const cam = Account("cam"); auto const dan = Account("dan"); - auto const D_BUX = dan["BUX"]; + auto const dBux = dan["BUX"]; // Verify trust line QualityOut affects payments. env.fund(reserve(env, 4) + (fee * 4), ann, bob, cam, dan); env.close(); - env(trust(bob, A_BUX(400))); - env(trust(bob, D_BUX(200)), qualityOutPercent(120)); - env(trust(cam, D_BUX(100))); + env(trust(bob, aBux(400))); + env(trust(bob, dBux(200)), QualityOutPercent(120)); + env(trust(cam, dBux(100))); env.close(); - env(pay(dan, bob, D_BUX(100))); + env(pay(dan, bob, dBux(100))); env.close(); - env.require(balance(bob, D_BUX(100))); + env.require(Balance(bob, dBux(100))); - env(pay(ann, cam, D_BUX(60)), path(bob, dan), sendmax(A_BUX(200))); + env(pay(ann, cam, dBux(60)), Path(bob, dan), Sendmax(aBux(200))); env.close(); - env.require(balance(ann, A_BUX(none))); - env.require(balance(ann, D_BUX(none))); - env.require(balance(bob, A_BUX(72))); - env.require(balance(bob, D_BUX(40))); - env.require(balance(cam, A_BUX(none))); - env.require(balance(cam, D_BUX(60))); - env.require(balance(dan, A_BUX(none))); - env.require(balance(dan, D_BUX(none))); + env.require(Balance(ann, aBux(kNONE))); + env.require(Balance(ann, dBux(kNONE))); + env.require(Balance(bob, aBux(72))); + env.require(Balance(bob, dBux(40))); + env.require(Balance(cam, aBux(kNONE))); + env.require(Balance(cam, dBux(60))); + env.require(Balance(dan, aBux(kNONE))); + env.require(Balance(dan, dBux(kNONE))); - env(offer(bob, A_BUX(30), D_BUX(30))); + env(offer(bob, aBux(30), dBux(30))); env.close(); - env(trust(ann, D_BUX(100))); + env(trust(ann, dBux(100))); env.close(); // This payment caused the assert. - env(pay(ann, ann, D_BUX(30)), - path(A_BUX, D_BUX), - sendmax(A_BUX(30)), - ter(temBAD_PATH)); + env(pay(ann, ann, dBux(30)), + Path(aBux, dBux), + Sendmax(aBux(30)), + Ter(TemBadPath)); env.close(); - env.require(balance(ann, A_BUX(none))); - env.require(balance(ann, D_BUX(0))); - env.require(balance(bob, A_BUX(72))); - env.require(balance(bob, D_BUX(40))); - env.require(balance(cam, A_BUX(none))); - env.require(balance(cam, D_BUX(60))); - env.require(balance(dan, A_BUX(0))); - env.require(balance(dan, D_BUX(none))); + env.require(Balance(ann, aBux(kNONE))); + env.require(Balance(ann, dBux(0))); + env.require(Balance(bob, aBux(72))); + env.require(Balance(bob, dBux(40))); + env.require(Balance(cam, aBux(kNONE))); + env.require(Balance(cam, dBux(60))); + env.require(Balance(dan, aBux(0))); + env.require(Balance(dan, dBux(kNONE))); } } @@ -3536,40 +3548,40 @@ public: auto const ann = Account("ann"); auto const bob = Account("bob"); auto const cam = Account("cam"); - auto const A_BUX = ann["BUX"]; - auto const B_BUX = bob["BUX"]; + auto const aBux = ann["BUX"]; + auto const bBux = bob["BUX"]; auto const fee = env.current()->fees().base; env.fund(reserve(env, 4) + (fee * 5), ann, bob, cam); env.close(); - env(trust(ann, B_BUX(40))); - env(trust(cam, A_BUX(40))); - env(trust(cam, B_BUX(40))); + env(trust(ann, bBux(40))); + env(trust(cam, aBux(40))); + env(trust(cam, bBux(40))); env.close(); - env(pay(ann, cam, A_BUX(35))); - env(pay(bob, cam, B_BUX(35))); + env(pay(ann, cam, aBux(35))); + env(pay(bob, cam, bBux(35))); - env(offer(bob, A_BUX(30), B_BUX(30))); + env(offer(bob, aBux(30), bBux(30))); env.close(); // cam puts an offer on the books that her upcoming offer could cross. // But this offer should be deleted, not crossed, by her upcoming // offer. - env(offer(cam, A_BUX(29), B_BUX(30), tfPassive)); + env(offer(cam, aBux(29), bBux(30), kTF_PASSIVE)); env.close(); - env.require(balance(cam, A_BUX(35))); - env.require(balance(cam, B_BUX(35))); + env.require(Balance(cam, aBux(35))); + env.require(Balance(cam, bBux(35))); env.require(offers(cam, 1)); // This offer caused the assert. - env(offer(cam, B_BUX(30), A_BUX(30))); + env(offer(cam, bBux(30), aBux(30))); env.close(); - env.require(balance(bob, A_BUX(30))); - env.require(balance(cam, A_BUX(5))); - env.require(balance(cam, B_BUX(65))); + env.require(Balance(bob, aBux(30))); + env.require(Balance(cam, aBux(5))); + env.require(Balance(cam, bBux(65))); env.require(offers(cam, 0)); } @@ -3587,7 +3599,7 @@ public: auto const ann = Account("ann"); auto const gw = Account("gateway"); - auto const BTC = gw["BTC"]; + auto const btc = gw["BTC"]; auto const fee = env.current()->fees().base; env.fund(reserve(env, 2) + drops(9999640) + (fee), ann); @@ -3595,18 +3607,18 @@ public: env.close(); env(rate(gw, 1.002)); - env(trust(ann, BTC(10))); + env(trust(ann, btc(10))); env.close(); - env(pay(gw, ann, BTC(2.856))); + env(pay(gw, ann, btc(2.856))); env.close(); - env(offer(ann, drops(365611702030), BTC(5.713))); + env(offer(ann, drops(365611702030), btc(5.713))); env.close(); // This offer caused the assert. - env(offer(ann, BTC(0.687), drops(20000000000)), - ter(tecINSUF_RESERVE_OFFER)); + env(offer(ann, btc(0.687), drops(20000000000)), + Ter(TecInsufReserveOffer)); } void @@ -3625,24 +3637,24 @@ public: auto const gw = Account("gateway"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const CNY = gw["CNY"]; + auto const cny = gw["CNY"]; auto const fee = env.current()->fees().base; env.fund(reserve(env, 2) + drops(400000000000) + (fee), alice, bob); env.fund(reserve(env, 2) + (fee * 4), gw); env.close(); - env(trust(bob, CNY(500))); + env(trust(bob, cny(500))); env.close(); - env(pay(gw, bob, CNY(300))); + env(pay(gw, bob, cny(300))); env.close(); - env(offer(bob, drops(5400000000), CNY(216.054))); + env(offer(bob, drops(5400000000), cny(216.054))); env.close(); // This offer did not round result of partial crossing correctly. - env(offer(alice, CNY(13562.0001), drops(339000000000))); + env(offer(alice, cny(13562.0001), drops(339000000000))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -3652,7 +3664,7 @@ public: auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT(offer[sfTakerGets] == drops(333599446582)); - BEAST_EXPECT(offer[sfTakerPays] == CNY(13345.9461)); + BEAST_EXPECT(offer[sfTakerPays] == cny(13345.9461)); } } @@ -3671,8 +3683,8 @@ public: auto const gw = Account("gateway"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const BTC = gw["BTC"]; - auto const JPY = gw["JPY"]; + auto const btc = gw["BTC"]; + auto const jpy = gw["JPY"]; auto const fee = env.current()->fees().base; env.fund(reserve(env, 2) + drops(400000000000) + (fee), alice, bob); @@ -3680,19 +3692,19 @@ public: env.close(); env(rate(gw, 1.002)); - env(trust(alice, JPY(4000))); - env(trust(bob, BTC(2))); + env(trust(alice, jpy(4000))); + env(trust(bob, btc(2))); env.close(); - env(pay(gw, alice, JPY(3699.034802280317))); - env(pay(gw, bob, BTC(1.156722559140311))); + env(pay(gw, alice, jpy(3699.034802280317))); + env(pay(gw, bob, btc(1.156722559140311))); env.close(); - env(offer(bob, JPY(1241.913390770747), BTC(0.01969825690469254))); + env(offer(bob, jpy(1241.913390770747), btc(0.01969825690469254))); env.close(); // This offer did not round result of partial crossing correctly. - env(offer(alice, BTC(0.05507568706427876), JPY(3472.696773391072))); + env(offer(alice, btc(0.05507568706427876), jpy(3472.696773391072))); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -3703,8 +3715,8 @@ public: BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT( offer[sfTakerGets] == - STAmount(JPY, std::uint64_t(2230682446713524ul), -12)); - BEAST_EXPECT(offer[sfTakerPays] == BTC(0.035378)); + STAmount(jpy, std::uint64_t(2230682446713524ul), -12)); + BEAST_EXPECT(offer[sfTakerPays] == btc(0.035378)); } } @@ -3724,8 +3736,8 @@ public: auto const gw2 = Account("gw2"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const USD = gw1["USD"]; - auto const JPY = gw2["JPY"]; + auto const usd = gw1["USD"]; + auto const jpy = gw2["JPY"]; auto const fee = env.current()->fees().base; env.fund(reserve(env, 2) + drops(400000000000) + (fee), alice, bob); @@ -3733,31 +3745,31 @@ public: env.close(); env(rate(gw1, 1.002)); - env(trust(alice, USD(1000))); - env(trust(bob, JPY(100000))); + env(trust(alice, usd(1000))); + env(trust(bob, jpy(100000))); env.close(); env( pay(gw1, alice, - STAmount{USD, std::uint64_t(2185410179555600), -14})); + STAmount{usd, std::uint64_t(2185410179555600), -14})); env( pay(gw2, bob, - STAmount{JPY, std::uint64_t(6351823459548956), -12})); + STAmount{jpy, std::uint64_t(6351823459548956), -12})); env.close(); env(offer( bob, - STAmount{USD, std::uint64_t(4371257532306000), -17}, - STAmount{JPY, std::uint64_t(4573216636606000), -15})); + STAmount{usd, std::uint64_t(4371257532306000), -17}, + STAmount{jpy, std::uint64_t(4573216636606000), -15})); env.close(); // This offer did not partially cross correctly. env(offer( alice, - STAmount{JPY, std::uint64_t(2291181510070762), -12}, - STAmount{USD, std::uint64_t(2190218999914694), -14})); + STAmount{jpy, std::uint64_t(2291181510070762), -12}, + STAmount{usd, std::uint64_t(2190218999914694), -14})); env.close(); auto const aliceOffers = offersOnAccount(env, alice); @@ -3768,10 +3780,10 @@ public: BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER); BEAST_EXPECT( offer[sfTakerGets] == - STAmount(USD, std::uint64_t(2185847305256635), -14)); + STAmount(usd, std::uint64_t(2185847305256635), -14)); BEAST_EXPECT( offer[sfTakerPays] == - STAmount(JPY, std::uint64_t(2286608293434156), -12)); + STAmount(jpy, std::uint64_t(2286608293434156), -12)); } } @@ -3787,40 +3799,40 @@ public: auto const gw = Account("gw"); auto const alice = Account("alice"); auto const bob = Account("bob"); - auto const CNY = gw["CNY"]; + auto const cny = gw["CNY"]; auto const fee = env.current()->fees().base; auto const startXrpBalance = drops(400000000000) + (fee * 2); env.fund(startXrpBalance, gw, alice, bob); env.close(); - env(trust(bob, CNY(100000))); + env(trust(bob, cny(100000))); env.close(); // Place alice's tiny offer in the book first. Let's see what happens // when a reasonable offer crosses it. STAmount const aliceCnyOffer{ - CNY, std::uint64_t(4926000000000000), -23}; + cny, std::uint64_t(4926000000000000), -23}; - env(offer(alice, aliceCnyOffer, drops(1), tfPassive)); + env(offer(alice, aliceCnyOffer, drops(1), kTF_PASSIVE)); env.close(); // bob places an ordinary offer STAmount const bobCnyStartBalance{ - CNY, std::uint64_t(3767479960090235), -15}; + cny, std::uint64_t(3767479960090235), -15}; env(pay(gw, bob, bobCnyStartBalance)); env.close(); env(offer( bob, drops(203), - STAmount{CNY, std::uint64_t(1000000000000000), -20})); + STAmount{cny, std::uint64_t(1000000000000000), -20})); env.close(); - env.require(balance(alice, aliceCnyOffer)); - env.require(balance(alice, startXrpBalance - fee - drops(1))); - env.require(balance(bob, bobCnyStartBalance - aliceCnyOffer)); - env.require(balance(bob, startXrpBalance - (fee * 2) + drops(1))); + env.require(Balance(alice, aliceCnyOffer)); + env.require(Balance(alice, startXrpBalance - fee - drops(1))); + env.require(Balance(bob, bobCnyStartBalance - aliceCnyOffer)); + env.require(Balance(bob, startXrpBalance - (fee * 2) + drops(1))); } void @@ -3868,9 +3880,9 @@ public: auto const baseFee = env.current()->fees().base.drops(); auto const gw = Account("gw"); - auto const BTC = gw["BTC"]; - auto const USD = gw["USD"]; - auto const startXrpBalance = XRP(4000000); + auto const btc = gw["BTC"]; + auto const usd = gw["USD"]; + auto const startXrpBalance = kXRP(4000000); env.fund(startXrpBalance, gw); env.close(); @@ -3903,10 +3915,10 @@ public: // clang-format off TestData const tests[]{ // btcStart --------------------- actor[0] --------------------- -------------------- actor[1] ------------------- - {.self=0, .leg0=0, .leg1=1, .btcStart=BTC(20), .actors={{"ann", 0, drops(3900000'000000 - (4 * baseFee)), BTC(20.0), USD(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), BTC( 0), USD(750)}}}, // no BTC xfer fee - {.self=0, .leg0=1, .leg1=0, .btcStart=BTC(20), .actors={{"bev", 0, drops(4100000'000000 - (4 * baseFee)), BTC( 7.5), USD(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), BTC(10), USD( 0)}}}, // no USD xfer fee - {.self=0, .leg0=0, .leg1=0, .btcStart=BTC(20), .actors={{"cam", 0, drops(4000000'000000 - (5 * baseFee)), BTC(20.0), USD(2000)} }}, // no xfer fee - {.self=0, .leg0=1, .leg1=0, .btcStart=BTC( 5), .actors={{"deb", 1, drops(4040000'000000 - (4 * baseFee)), BTC( 0.0), USD(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), BTC( 4), USD( 0)}}}, // no USD xfer fee + {.self=0, .leg0=0, .leg1=1, .btcStart=btc(20), .actors={{"ann", 0, drops(3900000'000000 - (4 * baseFee)), btc(20.0), usd(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), btc( 0), usd(750)}}}, // no BTC xfer fee + {.self=0, .leg0=1, .leg1=0, .btcStart=btc(20), .actors={{"bev", 0, drops(4100000'000000 - (4 * baseFee)), btc( 7.5), usd(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), btc(10), usd( 0)}}}, // no USD xfer fee + {.self=0, .leg0=0, .leg1=0, .btcStart=btc(20), .actors={{"cam", 0, drops(4000000'000000 - (5 * baseFee)), btc(20.0), usd(2000)} }}, // no xfer fee + {.self=0, .leg0=1, .leg1=0, .btcStart=btc( 5), .actors={{"deb", 1, drops(4040000'000000 - (4 * baseFee)), btc( 0.0), usd(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), btc( 4), usd( 0)}}}, // no USD xfer fee }; // clang-format on @@ -3918,32 +3930,32 @@ public: for (auto const& actor : t.actors) { - env.fund(XRP(4000000), actor.acct); + env.fund(kXRP(4000000), actor.acct); env.close(); - env(trust(actor.acct, BTC(40))); - env(trust(actor.acct, USD(8000))); + env(trust(actor.acct, btc(40))); + env(trust(actor.acct, usd(8000))); env.close(); } env(pay(gw, self, t.btcStart)); - env(pay(gw, self, USD(2000))); + env(pay(gw, self, usd(2000))); if (self.id() != leg1.id()) - env(pay(gw, leg1, USD(2000))); + env(pay(gw, leg1, usd(2000))); env.close(); // Get the initial offers in place. Remember their sequences // so we can delete them later. - env(offer(leg0, BTC(10), XRP(100000), tfPassive)); + env(offer(leg0, btc(10), kXRP(100000), kTF_PASSIVE)); env.close(); std::uint32_t const leg0OfferSeq = env.seq(leg0) - 1; - env(offer(leg1, XRP(100000), USD(1000), tfPassive)); + env(offer(leg1, kXRP(100000), usd(1000), kTF_PASSIVE)); env.close(); std::uint32_t const leg1OfferSeq = env.seq(leg1) - 1; // This is the offer that matters. - env(offer(self, USD(1000), BTC(10))); + env(offer(self, usd(1000), btc(10))); env.close(); std::uint32_t const selfOfferSeq = env.seq(self) - 1; @@ -3960,9 +3972,9 @@ public: }).begin()); BEAST_EXPECT(offerCount == actor.offers); - env.require(balance(actor.acct, actor.xrp)); - env.require(balance(actor.acct, actor.btc)); - env.require(balance(actor.acct, actor.usd)); + env.require(Balance(actor.acct, actor.xrp)); + env.require(Balance(actor.acct, actor.btc)); + env.require(Balance(actor.acct, actor.usd)); } // Remove any offers that might be left hanging around. They // could bollix up later loops. @@ -4016,9 +4028,9 @@ public: auto const baseFee = env.current()->fees().base.drops(); auto const gw = Account("gw"); - auto const BTC = gw["BTC"]; - auto const USD = gw["USD"]; - auto const startXrpBalance = XRP(4000000); + auto const btc = gw["BTC"]; + auto const usd = gw["USD"]; + auto const startXrpBalance = kXRP(4000000); env.fund(startXrpBalance, gw); env.close(); @@ -4051,8 +4063,8 @@ public: // clang-format off TestData const tests[]{ // btcStart ------------------- actor[0] -------------------- ------------------- actor[1] -------------------- - {.self=0, .leg0=0, .leg1=1, .btcStart=BTC(5), .actors={{"gay", 1, drops(3950000'000000 - (4 * baseFee)), BTC(5), USD(2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), BTC(0), USD(1375)}}}, // no BTC xfer fee - {.self=0, .leg0=0, .leg1=0, .btcStart=BTC(5), .actors={{"hye", 2, drops(4000000'000000 - (5 * baseFee)), BTC(5), USD(2000)} }} // no xfer fee + {.self=0, .leg0=0, .leg1=1, .btcStart=btc(5), .actors={{"gay", 1, drops(3950000'000000 - (4 * baseFee)), btc(5), usd(2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), btc(0), usd(1375)}}}, // no BTC xfer fee + {.self=0, .leg0=0, .leg1=0, .btcStart=btc(5), .actors={{"hye", 2, drops(4000000'000000 - (5 * baseFee)), btc(5), usd(2000)} }} // no xfer fee }; // clang-format on @@ -4064,32 +4076,32 @@ public: for (auto const& actor : t.actors) { - env.fund(XRP(4000000), actor.acct); + env.fund(kXRP(4000000), actor.acct); env.close(); - env(trust(actor.acct, BTC(40))); - env(trust(actor.acct, USD(8000))); + env(trust(actor.acct, btc(40))); + env(trust(actor.acct, usd(8000))); env.close(); } env(pay(gw, self, t.btcStart)); - env(pay(gw, self, USD(2000))); + env(pay(gw, self, usd(2000))); if (self.id() != leg1.id()) - env(pay(gw, leg1, USD(2000))); + env(pay(gw, leg1, usd(2000))); env.close(); // Get the initial offers in place. Remember their sequences // so we can delete them later. - env(offer(leg0, BTC(10), XRP(100000), tfPassive)); + env(offer(leg0, btc(10), kXRP(100000), kTF_PASSIVE)); env.close(); std::uint32_t const leg0OfferSeq = env.seq(leg0) - 1; - env(offer(leg1, XRP(100000), USD(1000), tfPassive)); + env(offer(leg1, kXRP(100000), usd(1000), kTF_PASSIVE)); env.close(); std::uint32_t const leg1OfferSeq = env.seq(leg1) - 1; // This is the offer that matters. - env(offer(self, USD(1000), BTC(10))); + env(offer(self, usd(1000), btc(10))); env.close(); std::uint32_t const selfOfferSeq = env.seq(self) - 1; @@ -4106,9 +4118,9 @@ public: }).begin()); BEAST_EXPECT(offerCount == actor.offers); - env.require(balance(actor.acct, actor.xrp)); - env.require(balance(actor.acct, actor.btc)); - env.require(balance(actor.acct, actor.usd)); + env.require(Balance(actor.acct, actor.xrp)); + env.require(Balance(actor.acct, actor.btc)); + env.require(Balance(actor.acct, actor.usd)); } // Remove any offers that might be left hanging around. They // could bollix up later loops. @@ -4137,39 +4149,39 @@ public: auto const aliceUSD = alice["USD"]; auto const bobUSD = bob["USD"]; - env.fund(XRP(400000), gw, alice, bob); + env.fund(kXRP(400000), gw, alice, bob); env.close(); // GW requires authorization for holders of its IOUs - env(fset(gw, asfRequireAuth)); + env(fset(gw, kASF_REQUIRE_AUTH)); env.close(); // Properly set trust and have gw authorize bob and alice - env(trust(gw, bobUSD(100)), txflags(tfSetfAuth)); + env(trust(gw, bobUSD(100)), Txflags(kTF_SETF_AUTH)); env(trust(bob, gwUSD(100))); - env(trust(gw, aliceUSD(100)), txflags(tfSetfAuth)); + env(trust(gw, aliceUSD(100)), Txflags(kTF_SETF_AUTH)); env(trust(alice, gwUSD(100))); // Alice is able to place the offer since the GW has authorized her - env(offer(alice, gwUSD(40), XRP(4000))); + env(offer(alice, gwUSD(40), kXRP(4000))); env.close(); env.require(offers(alice, 1)); - env.require(balance(alice, gwUSD(0))); + env.require(Balance(alice, gwUSD(0))); env(pay(gw, bob, gwUSD(50))); env.close(); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // Bob's offer should cross Alice's - env(offer(bob, XRP(4000), gwUSD(40))); + env(offer(bob, kXRP(4000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(40))); + env.require(Balance(alice, gwUSD(40))); env.require(offers(bob, 0)); - env.require(balance(bob, gwUSD(10))); + env.require(Balance(bob, gwUSD(10))); } void @@ -4205,66 +4217,66 @@ public: auto const aliceUSD = alice["USD"]; auto const bobUSD = bob["USD"]; - env.fund(XRP(400000), gw, alice, bob); + env.fund(kXRP(400000), gw, alice, bob); env.close(); - env(offer(alice, gwUSD(40), XRP(4000))); + env(offer(alice, gwUSD(40), kXRP(4000))); env.close(); env.require(offers(alice, 1)); - env.require(balance(alice, gwUSD(none))); - env(fset(gw, asfRequireAuth)); + env.require(Balance(alice, gwUSD(kNONE))); + env(fset(gw, kASF_REQUIRE_AUTH)); env.close(); - env(trust(gw, bobUSD(100)), txflags(tfSetfAuth)); + env(trust(gw, bobUSD(100)), Txflags(kTF_SETF_AUTH)); env.close(); env(trust(bob, gwUSD(100))); env.close(); env(pay(gw, bob, gwUSD(50))); env.close(); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // gw now requires authorization and bob has gwUSD(50). Let's see if // bob can cross alice's offer. // // Bob's offer shouldn't cross and alice's unauthorized offer should be // deleted. - env(offer(bob, XRP(4000), gwUSD(40))); + env(offer(bob, kXRP(4000), gwUSD(40))); env.close(); std::uint32_t const bobOfferSeq = env.seq(bob) - 1; env.require(offers(alice, 0)); // alice's unauthorized offer is deleted & bob's offer not crossed. - env.require(balance(alice, gwUSD(none))); + env.require(Balance(alice, gwUSD(kNONE))); env.require(offers(bob, 1)); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // See if alice can create an offer without authorization. alice // should not be able to create the offer and bob's offer should be // untouched. - env(offer(alice, gwUSD(40), XRP(4000)), ter(tecNO_LINE)); + env(offer(alice, gwUSD(40), kXRP(4000)), Ter(TecNoLine)); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(none))); + env.require(Balance(alice, gwUSD(kNONE))); env.require(offers(bob, 1)); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // Set up a trust line for alice, but don't authorize it. alice // should still not be able to create an offer for USD/gw. env(trust(gw, aliceUSD(100))); env.close(); - env(offer(alice, gwUSD(40), XRP(4000)), ter(tecNO_AUTH)); + env(offer(alice, gwUSD(40), kXRP(4000)), Ter(TecNoAuth)); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(0))); + env.require(Balance(alice, gwUSD(0))); env.require(offers(bob, 1)); - env.require(balance(bob, gwUSD(50))); + env.require(Balance(bob, gwUSD(50))); // Delete bob's offer so alice can create an offer without crossing. env(offer_cancel(bob, bobOfferSeq)); @@ -4274,23 +4286,23 @@ public: // Finally, set up an authorized trust line for alice. Now alice's // offer should succeed. Note that, since this is an offer rather // than a payment, alice does not need to set a trust line limit. - env(trust(gw, aliceUSD(100)), txflags(tfSetfAuth)); + env(trust(gw, aliceUSD(100)), Txflags(kTF_SETF_AUTH)); env.close(); - env(offer(alice, gwUSD(40), XRP(4000))); + env(offer(alice, gwUSD(40), kXRP(4000))); env.close(); env.require(offers(alice, 1)); // Now bob creates his offer again. alice's offer should cross. - env(offer(bob, XRP(4000), gwUSD(40))); + env(offer(bob, kXRP(4000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(40))); + env.require(Balance(alice, gwUSD(40))); env.require(offers(bob, 0)); - env.require(balance(bob, gwUSD(10))); + env.require(Balance(bob, gwUSD(10))); } void @@ -4314,67 +4326,67 @@ public: auto const coldEU = Account("coldEU"); auto const mm = Account("mm"); - auto const USD = coldUS["USD"]; - auto const EUR = coldEU["EUR"]; + auto const usd = coldUS["USD"]; + auto const eur = coldEU["EUR"]; - env.fund(XRP(100000), hotUS, coldUS, hotEU, coldEU, mm); + env.fund(kXRP(100000), hotUS, coldUS, hotEU, coldEU, mm); env.close(); // Cold wallets require trust but will ripple by default for (auto const& cold : {coldUS, coldEU}) { - env(fset(cold, asfRequireAuth)); - env(fset(cold, asfDefaultRipple)); + env(fset(cold, kASF_REQUIRE_AUTH)); + env(fset(cold, kASF_DEFAULT_RIPPLE)); } env.close(); // Each hot wallet trusts the related cold wallet for a large amount - env(trust(hotUS, USD(10000000)), txflags(tfSetNoRipple)); - env(trust(hotEU, EUR(10000000)), txflags(tfSetNoRipple)); + env(trust(hotUS, usd(10000000)), Txflags(kTF_SET_NO_RIPPLE)); + env(trust(hotEU, eur(10000000)), Txflags(kTF_SET_NO_RIPPLE)); // Market maker trusts both cold wallets for a large amount - env(trust(mm, USD(10000000)), txflags(tfSetNoRipple)); - env(trust(mm, EUR(10000000)), txflags(tfSetNoRipple)); + env(trust(mm, usd(10000000)), Txflags(kTF_SET_NO_RIPPLE)); + env(trust(mm, eur(10000000)), Txflags(kTF_SET_NO_RIPPLE)); env.close(); // Gateways authorize the trustlines of hot and market maker - env(trust(coldUS, USD(0), hotUS, tfSetfAuth)); - env(trust(coldEU, EUR(0), hotEU, tfSetfAuth)); - env(trust(coldUS, USD(0), mm, tfSetfAuth)); - env(trust(coldEU, EUR(0), mm, tfSetfAuth)); + env(trust(coldUS, usd(0), hotUS, kTF_SETF_AUTH)); + env(trust(coldEU, eur(0), hotEU, kTF_SETF_AUTH)); + env(trust(coldUS, usd(0), mm, kTF_SETF_AUTH)); + env(trust(coldEU, eur(0), mm, kTF_SETF_AUTH)); env.close(); // Issue currency from cold wallets to hot and market maker - env(pay(coldUS, hotUS, USD(5000000))); - env(pay(coldEU, hotEU, EUR(5000000))); - env(pay(coldUS, mm, USD(5000000))); - env(pay(coldEU, mm, EUR(5000000))); + env(pay(coldUS, hotUS, usd(5000000))); + env(pay(coldEU, hotEU, eur(5000000))); + env(pay(coldUS, mm, usd(5000000))); + env(pay(coldEU, mm, eur(5000000))); env.close(); // MM places offers float const rate = 0.9f; // 0.9 USD = 1 EUR - env(offer(mm, EUR(4000000 * rate), USD(4000000)), json(jss::Flags, tfSell)); + env(offer(mm, eur(4000000 * rate), usd(4000000)), Json(jss::kFLAGS, kTF_SELL)); float const reverseRate = 1.0f / rate * 1.00101f; - env(offer(mm, USD(4000000 * reverseRate), EUR(4000000)), json(jss::Flags, tfSell)); + env(offer(mm, usd(4000000 * reverseRate), eur(4000000)), Json(jss::kFLAGS, kTF_SELL)); env.close(); // There should be a path available from hot US to cold EUR { Json::Value jvParams; - jvParams[jss::destination_account] = coldEU.human(); - jvParams[jss::destination_amount][jss::issuer] = coldEU.human(); - jvParams[jss::destination_amount][jss::currency] = "EUR"; - jvParams[jss::destination_amount][jss::value] = 10; - jvParams[jss::source_account] = hotUS.human(); + jvParams[jss::kDESTINATION_ACCOUNT] = coldEU.human(); + jvParams[jss::kDESTINATION_AMOUNT][jss::kISSUER] = coldEU.human(); + jvParams[jss::kDESTINATION_AMOUNT][jss::kCURRENCY] = "EUR"; + jvParams[jss::kDESTINATION_AMOUNT][jss::kVALUE] = 10; + jvParams[jss::kSOURCE_ACCOUNT] = hotUS.human(); Json::Value const jrr{ - env.rpc("json", "ripple_path_find", to_string(jvParams))[jss::result]}; + env.rpc("json", "ripple_path_find", to_string(jvParams))[jss::kRESULT]}; - BEAST_EXPECT(jrr[jss::status] == "success"); - BEAST_EXPECT(jrr[jss::alternatives].isArray() && jrr[jss::alternatives].size() > 0); + BEAST_EXPECT(jrr[jss::kSTATUS] == "success"); + BEAST_EXPECT(jrr[jss::kALTERNATIVES].isArray() && jrr[jss::kALTERNATIVES].size() > 0); } // Send the payment using the found path. - env(pay(hotUS, coldEU, EUR(10)), sendmax(USD(11.1223326))); + env(pay(hotUS, coldEU, eur(10)), Sendmax(usd(11.1223326))); } void @@ -4391,17 +4403,17 @@ public: auto const gwUSD = gw["USD"]; auto const aliceUSD = alice["USD"]; - env.fund(XRP(400000), gw, alice); + env.fund(kXRP(400000), gw, alice); env.close(); // Test that gw can create an offer to buy gw's currency. - env(offer(gw, gwUSD(40), XRP(4000))); + env(offer(gw, gwUSD(40), kXRP(4000))); env.close(); std::uint32_t const gwOfferSeq = env.seq(gw) - 1; env.require(offers(gw, 1)); // Since gw has an offer out, gw should not be able to set RequireAuth. - env(fset(gw, asfRequireAuth), ter(tecOWNERS)); + env(fset(gw, kASF_REQUIRE_AUTH), Ter(TecOwners)); env.close(); // Cancel gw's offer so we can set RequireAuth. @@ -4410,33 +4422,33 @@ public: env.require(offers(gw, 0)); // gw now requires authorization for holders of its IOUs - env(fset(gw, asfRequireAuth)); + env(fset(gw, kASF_REQUIRE_AUTH)); env.close(); // Before DepositPreauth an account with lsfRequireAuth set could not // create an offer to buy their own currency. After DepositPreauth // they can. - env(offer(gw, gwUSD(40), XRP(4000)), ter(tesSUCCESS)); + env(offer(gw, gwUSD(40), kXRP(4000)), Ter(TesSuccess)); env.close(); env.require(offers(gw, 1)); // Set up an authorized trust line and pay alice gwUSD 50. - env(trust(gw, aliceUSD(100)), txflags(tfSetfAuth)); + env(trust(gw, aliceUSD(100)), Txflags(kTF_SETF_AUTH)); env(trust(alice, gwUSD(100))); env.close(); env(pay(gw, alice, gwUSD(50))); env.close(); - env.require(balance(alice, gwUSD(50))); + env.require(Balance(alice, gwUSD(50))); // alice's offer should cross gw's - env(offer(alice, XRP(4000), gwUSD(40))); + env(offer(alice, kXRP(4000), gwUSD(40))); env.close(); env.require(offers(alice, 0)); - env.require(balance(alice, gwUSD(10))); + env.require(Balance(alice, gwUSD(10))); env.require(offers(gw, 0)); } @@ -4460,33 +4472,33 @@ public: Account const becky("becky"); Account const carol("carol"); Account const gw("gateway"); - auto const USD = gw["USD"]; - auto const BUX = alice["BUX"]; + auto const usd = gw["USD"]; + auto const bux = alice["BUX"]; Env env{*this, features}; - env.fund(XRP(10000), alice, becky, carol, noripple(gw)); + env.fund(kXRP(10000), alice, becky, carol, noripple(gw)); env.close(); - env.trust(USD(1000), becky); - env(pay(gw, becky, USD(5))); + env.trust(usd(1000), becky); + env(pay(gw, becky, usd(5))); env.close(); - BEAST_EXPECT(trustLineExists(env, gw, becky, USD.currency)); + BEAST_EXPECT(trustLineExists(env, gw, becky, usd.currency)); // Make offers that produce USD and can be crossed two ways: // direct XRP -> USD // direct BUX -> USD - env(offer(becky, XRP(2), USD(2)), txflags(tfPassive)); + env(offer(becky, kXRP(2), usd(2)), Txflags(kTF_PASSIVE)); std::uint32_t const beckyBuxUsdSeq{env.seq(becky)}; - env(offer(becky, BUX(3), USD(3)), txflags(tfPassive)); + env(offer(becky, bux(3), usd(3)), Txflags(kTF_PASSIVE)); env.close(); // becky keeps the offers, but removes the trustline. - env(pay(becky, gw, USD(5))); - env.trust(USD(0), becky); + env(pay(becky, gw, usd(5))); + env.trust(usd(0), becky); env.close(); - BEAST_EXPECT(!trustLineExists(env, gw, becky, USD.currency)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(!trustLineExists(env, gw, becky, usd.currency)); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // Delete gw's account. { @@ -4503,7 +4515,7 @@ public: env.close(); // Account deletion has a high fee. Account for that. - env(acctdelete(gw, alice), fee(drops(env.current()->fees().increment))); + env(acctdelete(gw, alice), Fee(drops(env.current()->fees().increment))); env.close(); // Verify that gw's account root is gone from the ledger. @@ -4512,38 +4524,38 @@ public: // alice crosses becky's first offer. The offer create fails because // the USD issuer is not in the ledger. - env(offer(alice, USD(2), XRP(2)), ter(tecNO_ISSUER)); + env(offer(alice, usd(2), kXRP(2)), Ter(TecNoIssuer)); env.close(); env.require(offers(alice, 0)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // alice crosses becky's second offer. Again, the offer create fails // because the USD issuer is not in the ledger. - env(offer(alice, USD(3), BUX(3)), ter(tecNO_ISSUER)); + env(offer(alice, usd(3), bux(3)), Ter(TecNoIssuer)); env.require(offers(alice, 0)); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); - BEAST_EXPECT(isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); + BEAST_EXPECT(isOffer(env, becky, bux(3), usd(3))); // Cancel becky's BUX -> USD offer so we can try auto-bridging. env(offer_cancel(becky, beckyBuxUsdSeq)); env.close(); - BEAST_EXPECT(!isOffer(env, becky, BUX(3), USD(3))); + BEAST_EXPECT(!isOffer(env, becky, bux(3), usd(3))); // alice creates an offer that can be auto-bridged with becky's // remaining offer. - env.trust(BUX(1000), carol); - env(pay(alice, carol, BUX(2))); + env.trust(bux(1000), carol); + env(pay(alice, carol, bux(2))); - env(offer(alice, BUX(2), XRP(2))); + env(offer(alice, bux(2), kXRP(2))); env.close(); // carol attempts the auto-bridge. Again, the offer create fails // because the USD issuer is not in the ledger. - env(offer(carol, USD(2), BUX(2)), ter(tecNO_ISSUER)); + env(offer(carol, usd(2), bux(2)), Ter(TecNoIssuer)); env.close(); - BEAST_EXPECT(isOffer(env, alice, BUX(2), XRP(2))); - BEAST_EXPECT(isOffer(env, becky, XRP(2), USD(2))); + BEAST_EXPECT(isOffer(env, alice, bux(2), kXRP(2))); + BEAST_EXPECT(isOffer(env, becky, kXRP(2), usd(2))); } void @@ -4557,30 +4569,30 @@ public: { Env env{*this, features}; auto const gw = Account{"gateway"}; - env.fund(XRP(10000), gw); + env.fund(kXRP(10000), gw); env.close(); auto txn = noop(gw); - txn[sfTickSize.fieldName] = Quality::minTickSize - 1; - env(txn, ter(temBAD_TICK_SIZE)); + txn[sfTickSize.fieldName] = Quality::kMIN_TICK_SIZE - 1; + env(txn, Ter(TemBadTickSize)); - txn[sfTickSize.fieldName] = Quality::minTickSize; + txn[sfTickSize.fieldName] = Quality::kMIN_TICK_SIZE; env(txn); - BEAST_EXPECT((*env.le(gw))[sfTickSize] == Quality::minTickSize); + BEAST_EXPECT((*env.le(gw))[sfTickSize] == Quality::kMIN_TICK_SIZE); txn = noop(gw); - txn[sfTickSize.fieldName] = Quality::maxTickSize; + txn[sfTickSize.fieldName] = Quality::kMAX_TICK_SIZE; env(txn); BEAST_EXPECT(!env.le(gw)->isFieldPresent(sfTickSize)); txn = noop(gw); - txn[sfTickSize.fieldName] = Quality::maxTickSize - 1; + txn[sfTickSize.fieldName] = Quality::kMAX_TICK_SIZE - 1; env(txn); - BEAST_EXPECT((*env.le(gw))[sfTickSize] == Quality::maxTickSize - 1); + BEAST_EXPECT((*env.le(gw))[sfTickSize] == Quality::kMAX_TICK_SIZE - 1); txn = noop(gw); - txn[sfTickSize.fieldName] = Quality::maxTickSize + 1; - env(txn, ter(temBAD_TICK_SIZE)); + txn[sfTickSize.fieldName] = Quality::kMAX_TICK_SIZE + 1; + env(txn, Ter(TemBadTickSize)); txn[sfTickSize.fieldName] = 0; env(txn); @@ -4590,10 +4602,10 @@ public: Env env{*this, features}; auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - auto const XTS = gw["XTS"]; - auto const XXX = gw["XXX"]; + auto const xts = gw["XTS"]; + auto const xxx = gw["XXX"]; - env.fund(XRP(10000), gw, alice); + env.fund(kXRP(10000), gw, alice); env.close(); { @@ -4604,16 +4616,16 @@ public: BEAST_EXPECT((*env.le(gw))[sfTickSize] == 5); } - env(trust(alice, XTS(1000))); - env(trust(alice, XXX(1000))); + env(trust(alice, xts(1000))); + env(trust(alice, xxx(1000))); env(pay(gw, alice, alice["XTS"](100))); env(pay(gw, alice, alice["XXX"](100))); - env(offer(alice, XTS(10), XXX(30))); - env(offer(alice, XTS(30), XXX(10))); - env(offer(alice, XTS(10), XXX(30)), json(jss::Flags, tfSell)); - env(offer(alice, XTS(30), XXX(10)), json(jss::Flags, tfSell)); + env(offer(alice, xts(10), xxx(30))); + env(offer(alice, xts(30), xxx(10))); + env(offer(alice, xts(10), xxx(30)), Json(jss::kFLAGS, kTF_SELL)); + env(offer(alice, xts(30), xxx(10)), Json(jss::kFLAGS, kTF_SELL)); std::map> offers; forEachItem(*env.current(), alice, [&](std::shared_ptr const& sle) { @@ -4628,24 +4640,24 @@ public: auto it = offers.begin(); BEAST_EXPECT(it != offers.end()); BEAST_EXPECT( - it->second.first == XTS(10) && it->second.second < XXX(30) && - it->second.second > XXX(29.9994)); + it->second.first == xts(10) && it->second.second < xxx(30) && + it->second.second > xxx(29.9994)); // second offer ++it; BEAST_EXPECT(it != offers.end()); - BEAST_EXPECT(it->second.first == XTS(30) && it->second.second == XXX(10)); + BEAST_EXPECT(it->second.first == xts(30) && it->second.second == xxx(10)); // third offer ++it; BEAST_EXPECT(it != offers.end()); - BEAST_EXPECT(it->second.first == XTS(10.0002) && it->second.second == XXX(30)); + BEAST_EXPECT(it->second.first == xts(10.0002) && it->second.second == xxx(30)); // fourth offer // exact TakerPays is XTS(1/.033333) ++it; BEAST_EXPECT(it != offers.end()); - BEAST_EXPECT(it->second.first == XTS(30) && it->second.second == XXX(10)); + BEAST_EXPECT(it->second.first == xts(30) && it->second.second == xxx(10)); BEAST_EXPECT(++it == offers.end()); } @@ -4680,23 +4692,23 @@ public: auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; auto const bob = Account{"bob"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice, bob); + env.fund(kXRP(10000), gw, alice, bob); env.close(); - env(trust(alice, USD(1000))); - env(trust(bob, USD(1000))); + env(trust(alice, usd(1000))); + env(trust(bob, usd(1000))); env.close(); - env(pay(gw, alice, USD(200))); + env(pay(gw, alice, usd(200))); env.close(); // Create four offers from the same account with identical quality // so they go in the same order book. Each offer goes in a different // ledger so the chronology is clear. - std::uint32_t const offerId_0{env.seq(alice)}; - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerId0{env.seq(alice)}; + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create two tickets. @@ -4705,71 +4717,71 @@ public: env.close(); // Create another sequence-based offer. - std::uint32_t const offerId_1{env.seq(alice)}; - BEAST_EXPECT(offerId_1 == offerId_0 + 4); - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerId1{env.seq(alice)}; + BEAST_EXPECT(offerId1 == offerId0 + 4); + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create two ticket based offers in reverse order. - std::uint32_t const offerId_2{ticketSeq + 1}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerId_2)); + std::uint32_t const offerId2{ticketSeq + 1}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerId2)); env.close(); // Create the last offer. - std::uint32_t const offerId_3{ticketSeq}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerId_3)); + std::uint32_t const offerId3{ticketSeq}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerId3)); env.close(); // Verify that all of alice's offers are present. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 4); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_0); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId_2); - BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerId_1); - env.require(balance(alice, USD(200))); - env.require(owners(alice, 5)); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId0); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId2); + BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerId1); + env.require(Balance(alice, usd(200))); + env.require(Owners(alice, 5)); } // Cross alice's first offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the first offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 3); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_2); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId2); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerId1); } // Cross alice's second offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the second offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 2); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId_2); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerId2); } // Cross alice's third offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the third offer alice created was consumed. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 1); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId_3); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerId3); } // Cross alice's last offer. - env(offer(bob, USD(50), XRP(50))); + env(offer(bob, usd(50), kXRP(50))); env.close(); // Verify that the third offer alice created was consumed. @@ -4777,10 +4789,10 @@ public: auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.empty()); } - env.require(balance(alice, USD(0))); - env.require(owners(alice, 1)); - env.require(balance(bob, USD(200))); - env.require(owners(bob, 1)); + env.require(Balance(alice, usd(0))); + env.require(Owners(alice, 1)); + env.require(Balance(bob, usd(200))); + env.require(Owners(bob, 1)); } void @@ -4795,104 +4807,104 @@ public: Env env{*this, features}; auto const gw = Account{"gateway"}; auto const alice = Account{"alice"}; - auto const USD = gw["USD"]; + auto const usd = gw["USD"]; - env.fund(XRP(10000), gw, alice); + env.fund(kXRP(10000), gw, alice); env.close(); - env(trust(alice, USD(1000))); + env(trust(alice, usd(1000))); env.close(); - env.require(owners(alice, 1), tickets(alice, 0)); + env.require(Owners(alice, 1), tickets(alice, 0)); - env(pay(gw, alice, USD(200))); + env(pay(gw, alice, usd(200))); env.close(); // Create the first of four offers using a sequence. - std::uint32_t const offerSeqId_0{env.seq(alice)}; - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerSeqId0{env.seq(alice)}; + env(offer(alice, kXRP(50), usd(50))); env.close(); - env.require(owners(alice, 2), tickets(alice, 0)); + env.require(Owners(alice, 2), tickets(alice, 0)); // Create four tickets. std::uint32_t const ticketSeq{env.seq(alice) + 1}; env(ticket::create(alice, 4)); env.close(); - env.require(owners(alice, 6), tickets(alice, 4)); + env.require(Owners(alice, 6), tickets(alice, 4)); // Create the second (also sequence-based) offer. - std::uint32_t const offerSeqId_1{env.seq(alice)}; - BEAST_EXPECT(offerSeqId_1 == offerSeqId_0 + 6); - env(offer(alice, XRP(50), USD(50))); + std::uint32_t const offerSeqId1{env.seq(alice)}; + BEAST_EXPECT(offerSeqId1 == offerSeqId0 + 6); + env(offer(alice, kXRP(50), usd(50))); env.close(); // Create the third (ticket-based) offer. - std::uint32_t const offerTixId_0{ticketSeq + 1}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerTixId_0)); + std::uint32_t const offerTixId0{ticketSeq + 1}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerTixId0)); env.close(); // Create the last offer. - std::uint32_t const offerTixId_1{ticketSeq}; - env(offer(alice, XRP(50), USD(50)), ticket::use(offerTixId_1)); + std::uint32_t const offerTixId1{ticketSeq}; + env(offer(alice, kXRP(50), usd(50)), ticket::Use(offerTixId1)); env.close(); // Verify that all of alice's offers are present. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 4); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId_0); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerTixId_0); - BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerSeqId_1); - env.require(balance(alice, USD(200))); - env.require(owners(alice, 7)); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId0); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerTixId0); + BEAST_EXPECT(offers[3]->getFieldU32(sfSequence) == offerSeqId1); + env.require(Balance(alice, usd(200))); + env.require(Owners(alice, 7)); } // Use a ticket to cancel an offer created with a sequence. - env(offer_cancel(alice, offerSeqId_0), ticket::use(ticketSeq + 2)); + env(offer_cancel(alice, offerSeqId0), ticket::Use(ticketSeq + 2)); env.close(); // Verify that offerSeqId_0 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 3); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId_0); - BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerTixId0); + BEAST_EXPECT(offers[2]->getFieldU32(sfSequence) == offerSeqId1); } // Use a ticket to cancel an offer created with a ticket. - env(offer_cancel(alice, offerTixId_0), ticket::use(ticketSeq + 3)); + env(offer_cancel(alice, offerTixId0), ticket::Use(ticketSeq + 3)); env.close(); // Verify that offerTixId_0 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 2); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId_1); - BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerTixId1); + BEAST_EXPECT(offers[1]->getFieldU32(sfSequence) == offerSeqId1); } // All of alice's tickets should now be used up. - env.require(owners(alice, 3), tickets(alice, 0)); + env.require(Owners(alice, 3), tickets(alice, 0)); // Use a sequence to cancel an offer created with a ticket. - env(offer_cancel(alice, offerTixId_1)); + env(offer_cancel(alice, offerTixId1)); env.close(); // Verify that offerTixId_1 was canceled. { auto offers = sortedOffersOnAccount(env, alice); BEAST_EXPECT(offers.size() == 1); - BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId_1); + BEAST_EXPECT(offers[0]->getFieldU32(sfSequence) == offerSeqId1); } // Use a sequence to cancel an offer created with a sequence. - env(offer_cancel(alice, offerSeqId_1)); + env(offer_cancel(alice, offerSeqId1)); env.close(); // Verify that offerSeqId_1 was canceled. // All of alice's tickets should now be used up. - env.require(owners(alice, 1), tickets(alice, 0), offers(alice, 0)); + env.require(Owners(alice, 1), tickets(alice, 0), offers(alice, 0)); } void @@ -4905,11 +4917,11 @@ public: Env env{*this}; auto const alice = Account("alice"); - auto const USD = alice["USD"]; + auto const usd = alice["USD"]; - env.fund(XRP(10000), alice); + env.fund(kXRP(10000), alice); env.close(); - env(offer(alice, XRP(100000000000), USD(100000000))); + env(offer(alice, kXRP(100000000000), usd(100000000))); pass(); } @@ -4922,153 +4934,153 @@ public: Account const issuer("issuer"); Account const maker("maker"); Account const taker("taker"); - auto const USD = issuer["USD"]; - auto const EUR = issuer["EUR"]; + auto const usd = issuer["USD"]; + auto const eur = issuer["EUR"]; - env.fund(XRP(1'000), issuer); - env.fund(XRP(1'000), maker, taker); + env.fund(kXRP(1'000), issuer); + env.fund(kXRP(1'000), maker, taker); env.close(); - env.trust(USD(1'000), maker, taker); - env.trust(EUR(1'000), maker, taker); + env.trust(usd(1'000), maker, taker); + env.trust(eur(1'000), maker, taker); env.close(); - env(pay(issuer, maker, USD(1'000))); - env(pay(issuer, taker, USD(1'000))); - env(pay(issuer, maker, EUR(1'000))); + env(pay(issuer, maker, usd(1'000))); + env(pay(issuer, taker, usd(1'000))); + env(pay(issuer, maker, eur(1'000))); env.close(); - auto makerUSDBalance = env.balance(maker, USD).value(); - auto takerUSDBalance = env.balance(taker, USD).value(); - auto makerEURBalance = env.balance(maker, EUR).value(); - auto takerEURBalance = env.balance(taker, EUR).value(); - auto makerXRPBalance = env.balance(maker, XRP).value(); - auto takerXRPBalance = env.balance(taker, XRP).value(); + auto makerUSDBalance = env.balance(maker, usd).value(); + auto takerUSDBalance = env.balance(taker, usd).value(); + auto makerEURBalance = env.balance(maker, eur).value(); + auto takerEURBalance = env.balance(taker, eur).value(); + auto makerXRPBalance = env.balance(maker, kXRP).value(); + auto takerXRPBalance = env.balance(taker, kXRP).value(); // tfFillOrKill, TakerPays must be filled { - TER const err = features[fixFillOrKill] ? TER(tesSUCCESS) : tecKILLED; + TER const err = features[fixFillOrKill] ? TER(TesSuccess) : TecKilled; - env(offer(maker, XRP(100), USD(100))); + env(offer(maker, kXRP(100), usd(100))); env.close(); - env(offer(taker, USD(100), XRP(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, usd(100), kXRP(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); if (isTesSuccess(err)) { - makerUSDBalance -= USD(100); - takerUSDBalance += USD(100); - makerXRPBalance += XRP(100).value(); - takerXRPBalance -= XRP(100).value(); + makerUSDBalance -= usd(100); + takerUSDBalance += usd(100); + makerXRPBalance += kXRP(100).value(); + takerXRPBalance -= kXRP(100).value(); } BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), XRP(100))); + env(offer(maker, usd(100), kXRP(100))); env.close(); - env(offer(taker, XRP(100), USD(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, kXRP(100), usd(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); if (isTesSuccess(err)) { - makerUSDBalance += USD(100); - takerUSDBalance -= USD(100); - makerXRPBalance -= XRP(100).value(); - takerXRPBalance += XRP(100).value(); + makerUSDBalance += usd(100); + takerUSDBalance -= usd(100); + makerXRPBalance -= kXRP(100).value(); + takerXRPBalance += kXRP(100).value(); } BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), EUR(100))); + env(offer(maker, usd(100), eur(100))); env.close(); - env(offer(taker, EUR(100), USD(101)), txflags(tfFillOrKill), ter(err)); + env(offer(taker, eur(100), usd(101)), Txflags(kTF_FILL_OR_KILL), Ter(err)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); if (isTesSuccess(err)) { - makerUSDBalance += USD(100); - takerUSDBalance -= USD(100); - makerEURBalance -= EUR(100); - takerEURBalance += EUR(100); + makerUSDBalance += usd(100); + takerUSDBalance -= usd(100); + makerEURBalance -= eur(100); + takerEURBalance += eur(100); } BEAST_EXPECT(expectOffers(env, taker, 0)); } // tfFillOrKill + tfSell, TakerGets must be filled { - env(offer(maker, XRP(101), USD(101))); + env(offer(maker, kXRP(101), usd(101))); env.close(); - env(offer(taker, USD(100), XRP(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, usd(100), kXRP(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance -= USD(101); - takerUSDBalance += USD(101); - makerXRPBalance += XRP(101).value() - txfee(env, 1); - takerXRPBalance -= XRP(101).value() + txfee(env, 1); + makerUSDBalance -= usd(101); + takerUSDBalance += usd(101); + makerXRPBalance += kXRP(101).value() - txfee(env, 1); + takerXRPBalance -= kXRP(101).value() + txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(101), XRP(101))); + env(offer(maker, usd(101), kXRP(101))); env.close(); - env(offer(taker, XRP(100), USD(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, kXRP(100), usd(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance += USD(101); - takerUSDBalance -= USD(101); - makerXRPBalance -= XRP(101).value() + txfee(env, 1); - takerXRPBalance += XRP(101).value() - txfee(env, 1); + makerUSDBalance += usd(101); + takerUSDBalance -= usd(101); + makerXRPBalance -= kXRP(101).value() + txfee(env, 1); + takerXRPBalance += kXRP(101).value() - txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(101), EUR(101))); + env(offer(maker, usd(101), eur(101))); env.close(); - env(offer(taker, EUR(100), USD(101)), txflags(tfFillOrKill | tfSell)); + env(offer(taker, eur(100), usd(101)), Txflags(kTF_FILL_OR_KILL | kTF_SELL)); env.close(); - makerUSDBalance += USD(101); - takerUSDBalance -= USD(101); - makerEURBalance -= EUR(101); - takerEURBalance += EUR(101); + makerUSDBalance += usd(101); + takerUSDBalance -= usd(101); + makerEURBalance -= eur(101); + takerEURBalance += eur(101); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); } // Fail regardless of fixFillOrKill amendment - for (auto const flags : {tfFillOrKill, tfFillOrKill + tfSell}) + for (auto const flags : {kTF_FILL_OR_KILL, kTF_FILL_OR_KILL + kTF_SELL}) { - env(offer(maker, XRP(100), USD(100))); + env(offer(maker, kXRP(100), usd(100))); env.close(); - env(offer(taker, USD(100), XRP(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, usd(100), kXRP(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), XRP(100))); + env(offer(maker, usd(100), kXRP(100))); env.close(); - env(offer(taker, XRP(100), USD(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, kXRP(100), usd(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); takerXRPBalance -= txfee(env, 1); BEAST_EXPECT(expectOffers(env, taker, 0)); - env(offer(maker, USD(100), EUR(100))); + env(offer(maker, usd(100), eur(100))); env.close(); - env(offer(taker, EUR(100), USD(99)), txflags(flags), ter(tecKILLED)); + env(offer(taker, eur(100), usd(99)), Txflags(flags), Ter(TecKilled)); env.close(); makerXRPBalance -= txfee(env, 1); @@ -5077,12 +5089,12 @@ public: } BEAST_EXPECT( - env.balance(maker, USD) == makerUSDBalance && - env.balance(taker, USD) == takerUSDBalance && - env.balance(maker, EUR) == makerEURBalance && - env.balance(taker, EUR) == takerEURBalance && - env.balance(maker, XRP) == makerXRPBalance && - env.balance(taker, XRP) == takerXRPBalance); + env.balance(maker, usd) == makerUSDBalance && + env.balance(taker, usd) == takerUSDBalance && + env.balance(maker, eur) == makerEURBalance && + env.balance(taker, eur) == takerEURBalance && + env.balance(maker, kXRP) == makerXRPBalance && + env.balance(taker, kXRP) == takerXRPBalance); } void diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index ca18605ccb..bc336d07a4 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -17,7 +17,7 @@ namespace xrpl { -class Number_test : public beast::unit_test::suite +class Number_test : public beast::unit_test::Suite { public: void @@ -37,7 +37,7 @@ public: } void - test_limits() + testLimits() { auto const scale = Number::getMantissaScale(); testcase << "test_limits " << to_string(scale); @@ -46,7 +46,7 @@ public: try { [[maybe_unused]] Number const x = - Number{false, minMantissa * 10, 32768, Number::normalized{}}; + Number{false, minMantissa * 10, 32768, Number::Normalized{}}; } catch (std::overflow_error const&) { @@ -62,32 +62,32 @@ public: }; test( - Number{false, minMantissa * 10, 32767, Number::normalized{}}, - Number{false, minMantissa, 32768, Number::normalized{}}, + Number{false, minMantissa * 10, 32767, Number::Normalized{}}, + Number{false, minMantissa, 32768, Number::Normalized{}}, __LINE__); - test(Number{false, minMantissa, -32769, Number::normalized{}}, Number{}, __LINE__); + test(Number{false, minMantissa, -32769, Number::Normalized{}}, Number{}, __LINE__); test( - Number{false, minMantissa, 32000, Number::normalized{}} * 1'000 + - Number{false, 1'500, 32000, Number::normalized{}}, - Number{false, minMantissa + 2, 32003, Number::normalized{}}, + Number{false, minMantissa, 32000, Number::Normalized{}} * 1'000 + + Number{false, 1'500, 32000, Number::Normalized{}}, + Number{false, minMantissa + 2, 32003, Number::Normalized{}}, __LINE__); // 9,223,372,036,854,775,808 test( Number{std::numeric_limits::min()}, - scale == MantissaRange::mantissa_scale::small + scale == MantissaRange::MantissaScale::Small ? Number{-9'223'372'036'854'776, 3} - : Number{true, 9'223'372'036'854'775'808ULL, 0, Number::normalized{}}, + : Number{true, 9'223'372'036'854'775'808ULL, 0, Number::Normalized{}}, __LINE__); test( Number{std::numeric_limits::min() + 1}, - scale == MantissaRange::mantissa_scale::small ? Number{-9'223'372'036'854'776, 3} - : Number{-9'223'372'036'854'775'807}, + scale == MantissaRange::MantissaScale::Small ? Number{-9'223'372'036'854'776, 3} + : Number{-9'223'372'036'854'775'807}, __LINE__); test( Number{std::numeric_limits::max()}, Number{ - scale == MantissaRange::mantissa_scale::small + scale == MantissaRange::MantissaScale::Small ? 9'223'372'036'854'776 : std::numeric_limits::max(), 18 - Number::mantissaLog()}, @@ -96,7 +96,7 @@ public: try { [[maybe_unused]] - Number const q = Number{false, minMantissa, 32767, Number::normalized{}} * 100; + Number const q = Number{false, minMantissa, 32767, Number::Normalized{}} * 100; } catch (std::overflow_error const&) { @@ -106,7 +106,7 @@ public: } void - test_add() + testAdd() { auto const scale = Number::getMantissaScale(); testcase << "test_add " << to_string(scale); @@ -146,10 +146,10 @@ public: Number{-1'000'000'000'000'065'556, -18}}, {Number{-1'000'000'000'000'000, -15}, Number{6'555'555'555'555'555, -29}, - Number{true, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{true, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{-6'555'555'555'555'555, -29}, Number{1'000'000'000'000'000, -15}, - Number{false, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{false, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{}, Number{5}, Number{5}}, {Number{5}, Number{}, Number{5}}, {Number{5'555'555'555'555'555'000, -32768}, @@ -167,25 +167,25 @@ public: Number{-1'000'000'000'000'000'066, -18}}, {Number{-1'000'000'000'000'000'000, -18}, Number{6'555'555'555'555'555'555, -35}, - Number{true, 9'999'999'999'999'999'344ULL, -19, Number::normalized{}}}, + Number{true, 9'999'999'999'999'999'344ULL, -19, Number::Normalized{}}}, {Number{-6'555'555'555'555'555'555, -35}, Number{1'000'000'000'000'000'000, -18}, - Number{false, 9'999'999'999'999'999'344ULL, -19, Number::normalized{}}}, + Number{false, 9'999'999'999'999'999'344ULL, -19, Number::Normalized{}}}, {Number{}, Number{5}, Number{5}}, {Number{5'555'555'555'555'555'555, -32768}, Number{-5'555'555'555'555'555'554, -32768}, Number{0}}, - {Number{true, 9'999'999'999'999'999'999ULL, -37, Number::normalized{}}, + {Number{true, 9'999'999'999'999'999'999ULL, -37, Number::Normalized{}}, Number{1'000'000'000'000'000'000, -18}, - Number{false, 9'999'999'999'999'999'990ULL, -19, Number::normalized{}}}, - {Number{Number::maxRep}, Number{6, -1}, Number{Number::maxRep / 10, 1}}, - {Number{Number::maxRep - 1}, Number{1, 0}, Number{Number::maxRep}}, + Number{false, 9'999'999'999'999'999'990ULL, -19, Number::Normalized{}}}, + {Number{Number::kMAX_REP}, Number{6, -1}, Number{Number::kMAX_REP / 10, 1}}, + {Number{Number::kMAX_REP - 1}, Number{1, 0}, Number{Number::kMAX_REP}}, // Test extremes { // Each Number operand rounds up, so the actual mantissa is // minMantissa - Number{false, 9'999'999'999'999'999'999ULL, 0, Number::normalized{}}, - Number{false, 9'999'999'999'999'999'999ULL, 0, Number::normalized{}}, + Number{false, 9'999'999'999'999'999'999ULL, 0, Number::Normalized{}}, + Number{false, 9'999'999'999'999'999'999ULL, 0, Number::Normalized{}}, Number{2, 19}, }, { @@ -194,9 +194,9 @@ public: // With addition using uint128_t, there's no problem. After // normalizing, the resulting mantissa ends up less than // maxRep. - Number{false, 9'999'999'999'999'999'990ULL, 0, Number::normalized{}}, - Number{false, 9'999'999'999'999'999'990ULL, 0, Number::normalized{}}, - Number{false, 1'999'999'999'999'999'998ULL, 1, Number::normalized{}}, + Number{false, 9'999'999'999'999'999'990ULL, 0, Number::Normalized{}}, + Number{false, 9'999'999'999'999'999'990ULL, 0, Number::Normalized{}}, + Number{false, 1'999'999'999'999'999'998ULL, 1, Number::Normalized{}}, }, }); auto test = [this](auto const& c) { @@ -208,7 +208,7 @@ public: BEAST_EXPECTS(result == z, ss.str()); } }; - if (scale == MantissaRange::mantissa_scale::small) + if (scale == MantissaRange::MantissaScale::Small) { test(cSmall); } @@ -220,8 +220,8 @@ public: bool caught = false; try { - Number{false, Number::maxMantissa(), 32768, Number::normalized{}} + - Number{false, Number::minMantissa(), 32767, Number::normalized{}} * 5; + Number{false, Number::maxMantissa(), 32768, Number::Normalized{}} + + Number{false, Number::minMantissa(), 32767, Number::Normalized{}} * 5; } catch (std::overflow_error const&) { @@ -232,7 +232,7 @@ public: } void - test_sub() + testSub() { auto const scale = Number::getMantissaScale(); testcase << "test_sub " << to_string(scale); @@ -259,10 +259,10 @@ public: { {Number{1'000'000'000'000'000, -15}, Number{6'555'555'555'555'555, -29}, - Number{false, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{false, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{6'555'555'555'555'555, -29}, Number{1'000'000'000'000'000, -15}, - Number{true, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{true, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{1'000'000'000'000'000, -15}, Number{1'000'000'000'000'000, -15}, Number{0}}, {Number{1'000'000'000'000'000, -15}, Number{1'000'000'000'000'001, -15}, @@ -273,10 +273,10 @@ public: // Items from cSmall expanded for the larger mantissa {Number{1'000'000'000'000'000'000, -18}, Number{6'555'555'555'555'555'555, -32}, - Number{false, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{false, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{6'555'555'555'555'555'555, -32}, Number{1'000'000'000'000'000'000, -18}, - Number{true, 9'999'999'999'999'344'444ULL, -19, Number::normalized{}}}, + Number{true, 9'999'999'999'999'344'444ULL, -19, Number::Normalized{}}}, {Number{1'000'000'000'000'000'000, -18}, Number{1'000'000'000'000'000'000, -18}, Number{0}}, @@ -286,14 +286,14 @@ public: {Number{1'000'000'000'000'000'001, -18}, Number{1'000'000'000'000'000'000, -18}, Number{1'000'000'000'000'000'000, -36}}, - {Number{Number::maxRep}, Number{6, -1}, Number{Number::maxRep - 1}}, - {Number{false, Number::maxRep + 1, 0, Number::normalized{}}, + {Number{Number::kMAX_REP}, Number{6, -1}, Number{Number::kMAX_REP - 1}}, + {Number{false, Number::kMAX_REP + 1, 0, Number::Normalized{}}, Number{1, 0}, - Number{(Number::maxRep / 10) + 1, 1}}, - {Number{false, Number::maxRep + 1, 0, Number::normalized{}}, + Number{(Number::kMAX_REP / 10) + 1, 1}}, + {Number{false, Number::kMAX_REP + 1, 0, Number::Normalized{}}, Number{3, 0}, - Number{Number::maxRep}}, - {power(2, 63), Number{3, 0}, Number{Number::maxRep}}, + Number{Number::kMAX_REP}}, + {power(2, 63), Number{3, 0}, Number{Number::kMAX_REP}}, }); auto test = [this](auto const& c) { for (auto const& [x, y, z] : c) @@ -304,7 +304,7 @@ public: BEAST_EXPECTS(result == z, ss.str()); } }; - if (scale == MantissaRange::mantissa_scale::small) + if (scale == MantissaRange::MantissaScale::Small) { test(cSmall); } @@ -315,7 +315,7 @@ public: } void - test_mul() + testMul() { auto const scale = Number::getMantissaScale(); testcase << "test_mul " << to_string(scale); @@ -331,7 +331,7 @@ public: } }; auto tests = [&](auto const& cSmall, auto const& cLarge) { - if (scale == MantissaRange::mantissa_scale::small) + if (scale == MantissaRange::MantissaScale::Small) { test(cSmall); } @@ -342,7 +342,7 @@ public: }; auto const maxMantissa = Number::maxMantissa(); - saveNumberRoundMode const save{Number::setround(Number::rounding_mode::to_nearest)}; + SaveNumberRoundMode const save{Number::setround(Number::RoundingMode::ToNearest)}; { auto const cSmall = std::to_array({ {Number{7}, Number{8}, Number{56}}, @@ -380,7 +380,7 @@ public: Number{1999999999999999862, -18}}, {Number{3214285714285706, -15}, Number{3111111111111119, -15}, - Number{false, 9'999'999'999'999'999'579ULL, -18, Number::normalized{}}}, + Number{false, 9'999'999'999'999'999'579ULL, -18, Number::Normalized{}}}, {Number{1000000000000000000, -32768}, Number{1000000000000000000, -32768}, Number{0}}, @@ -398,17 +398,17 @@ public: Number{1999999999999999999, -18}}, {Number{3214285714285714278, -18}, Number{3111111111111111119, -18}, Number{10, 0}}, // Maximum mantissa range - rounds up to 1e19 - {Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1, 38}}, // Maximum int64 range - {Number{Number::maxRep, 0}, - Number{Number::maxRep, 0}, + {Number{Number::kMAX_REP, 0}, + Number{Number::kMAX_REP, 0}, Number{85'070'591'730'234'615'85, 19}}, }); tests(cSmall, cLarge); } - Number::setround(Number::rounding_mode::towards_zero); + Number::setround(Number::RoundingMode::TowardsZero); testcase << "test_mul " << to_string(Number::getMantissaScale()) << " towards_zero"; { auto const cSmall = std::to_array( @@ -443,7 +443,7 @@ public: Number{1999999999999999861, -18}}, {Number{3214285714285706, -15}, Number{3111111111111119, -15}, - Number{false, 9999999999999999579ULL, -18, Number::normalized{}}}, + Number{false, 9999999999999999579ULL, -18, Number::Normalized{}}}, {Number{1000000000000000000, -32768}, Number{1000000000000000000, -32768}, Number{0}}, @@ -464,18 +464,18 @@ public: Number{10, 0}}, // Maximum mantissa range - rounds down to maxMantissa/10e1 // 99'999'999'999'999'999'800'000'000'000'000'000'100 - {Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, (maxMantissa / 10) - 1, 20, Number::Normalized{}}}, // Maximum int64 range // 85'070'591'730'234'615'847'396'907'784'232'501'249 - {Number{Number::maxRep, 0}, - Number{Number::maxRep, 0}, + {Number{Number::kMAX_REP, 0}, + Number{Number::kMAX_REP, 0}, Number{85'070'591'730'234'615'84, 19}}, }); tests(cSmall, cLarge); } - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); testcase << "test_mul " << to_string(Number::getMantissaScale()) << " downward"; { auto const cSmall = std::to_array( @@ -510,7 +510,7 @@ public: Number{1999999999999999861, -18}}, {Number{3214285714285706, -15}, Number{3111111111111119, -15}, - Number{false, 9'999'999'999'999'999'579ULL, -18, Number::normalized{}}}, + Number{false, 9'999'999'999'999'999'579ULL, -18, Number::Normalized{}}}, {Number{1000000000000000000, -32768}, Number{1000000000000000000, -32768}, Number{0}}, @@ -531,18 +531,18 @@ public: Number{10, 0}}, // Maximum mantissa range - rounds down to maxMantissa/10e1 // 99'999'999'999'999'999'800'000'000'000'000'000'100 - {Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, (maxMantissa / 10) - 1, 20, Number::Normalized{}}}, // Maximum int64 range // 85'070'591'730'234'615'847'396'907'784'232'501'249 - {Number{Number::maxRep, 0}, - Number{Number::maxRep, 0}, + {Number{Number::kMAX_REP, 0}, + Number{Number::kMAX_REP, 0}, Number{85'070'591'730'234'615'84, 19}}, }); tests(cSmall, cLarge); } - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); testcase << "test_mul " << to_string(Number::getMantissaScale()) << " upward"; { auto const cSmall = std::to_array( @@ -598,13 +598,13 @@ public: Number{1000000000000000001, -17}}, // Maximum mantissa range - rounds up to minMantissa*10 // 1e19*1e19=1e38 - {Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, + Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1, 38}}, // Maximum int64 range // 85'070'591'730'234'615'847'396'907'784'232'501'249 - {Number{Number::maxRep, 0}, - Number{Number::maxRep, 0}, + {Number{Number::kMAX_REP, 0}, + Number{Number::kMAX_REP, 0}, Number{85'070'591'730'234'615'85, 19}}, }); tests(cSmall, cLarge); @@ -614,8 +614,8 @@ public: bool caught = false; try { - Number{false, maxMantissa, 32768, Number::normalized{}} * - Number{false, Number::minMantissa() * 5, 32767, Number::normalized{}}; + Number{false, maxMantissa, 32768, Number::Normalized{}} * + Number{false, Number::minMantissa() * 5, 32767, Number::Normalized{}}; } catch (std::overflow_error const&) { @@ -626,7 +626,7 @@ public: } void - test_div() + testDiv() { auto const scale = Number::getMantissaScale(); testcase << "test_div " << to_string(scale); @@ -643,7 +643,7 @@ public: }; auto const maxMantissa = Number::maxMantissa(); auto tests = [&](auto const& cSmall, auto const& cLarge) { - if (scale == MantissaRange::mantissa_scale::small) + if (scale == MantissaRange::MantissaScale::Small) { test(cSmall); } @@ -652,7 +652,7 @@ public: test(cLarge); } }; - saveNumberRoundMode const save{Number::setround(Number::rounding_mode::to_nearest)}; + SaveNumberRoundMode const save{Number::setround(Number::RoundingMode::ToNearest)}; { auto const cSmall = std::to_array( {{Number{1}, Number{2}, Number{5, -1}}, @@ -684,13 +684,13 @@ public: // Items from cSmall expanded for the larger mantissa, except // duplicates. {Number{1414213562373095049, -13}, Number{1414213562373095049, -13}, Number{1}}, - {Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1'000'000'000'000'000'000}, - Number{false, maxMantissa, -18, Number::normalized{}}}}); + Number{false, maxMantissa, -18, Number::Normalized{}}}}); tests(cSmall, cLarge); } testcase << "test_div " << to_string(Number::getMantissaScale()) << " towards_zero"; - Number::setround(Number::rounding_mode::towards_zero); + Number::setround(Number::RoundingMode::TowardsZero); { auto const cSmall = std::to_array( {{Number{1}, Number{2}, Number{5, -1}}, @@ -722,13 +722,13 @@ public: // Items from cSmall expanded for the larger mantissa, except // duplicates. {Number{1414213562373095049, -13}, Number{1414213562373095049, -13}, Number{1}}, - {Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1'000'000'000'000'000'000}, - Number{false, maxMantissa, -18, Number::normalized{}}}}); + Number{false, maxMantissa, -18, Number::Normalized{}}}}); tests(cSmall, cLarge); } testcase << "test_div " << to_string(Number::getMantissaScale()) << " downward"; - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); { auto const cSmall = std::to_array( {{Number{1}, Number{2}, Number{5, -1}}, @@ -760,13 +760,13 @@ public: // Items from cSmall expanded for the larger mantissa, except // duplicates. {Number{1414213562373095049, -13}, Number{1414213562373095049, -13}, Number{1}}, - {Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1'000'000'000'000'000'000}, - Number{false, maxMantissa, -18, Number::normalized{}}}}); + Number{false, maxMantissa, -18, Number::Normalized{}}}}); tests(cSmall, cLarge); } testcase << "test_div " << to_string(Number::getMantissaScale()) << " upward"; - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); { auto const cSmall = std::to_array( {{Number{1}, Number{2}, Number{5, -1}}, @@ -798,9 +798,9 @@ public: // Items from cSmall expanded for the larger mantissa, except // duplicates. {Number{1414213562373095049, -13}, Number{1414213562373095049, -13}, Number{1}}, - {Number{false, maxMantissa, 0, Number::normalized{}}, + {Number{false, maxMantissa, 0, Number::Normalized{}}, Number{1'000'000'000'000'000'000}, - Number{false, maxMantissa, -18, Number::normalized{}}}}); + Number{false, maxMantissa, -18, Number::Normalized{}}}}); tests(cSmall, cLarge); } testcase << "test_div " << to_string(Number::getMantissaScale()) << " overflow"; @@ -817,7 +817,7 @@ public: } void - test_root() + testRoot() { auto const scale = Number::getMantissaScale(); testcase << "test_root " << to_string(scale); @@ -851,23 +851,23 @@ public: {Number{0}, 5, Number{0}}, {Number{5625, -4}, 2, Number{75, -2}}}); auto const cLarge = std::to_array({ - {Number{false, Number::maxMantissa() - 9, -1, Number::normalized{}}, + {Number{false, Number::maxMantissa() - 9, -1, Number::Normalized{}}, 2, - Number{false, 999'999'999'999'999'999, -9, Number::normalized{}}}, - {Number{false, Number::maxMantissa() - 9, 0, Number::normalized{}}, + Number{false, 999'999'999'999'999'999, -9, Number::Normalized{}}}, + {Number{false, Number::maxMantissa() - 9, 0, Number::Normalized{}}, 2, - Number{false, 3'162'277'660'168'379'330, -9, Number::normalized{}}}, - {Number{Number::maxRep}, + Number{false, 3'162'277'660'168'379'330, -9, Number::Normalized{}}}, + {Number{Number::kMAX_REP}, 2, - Number{false, 3'037'000'499'976049692, -9, Number::normalized{}}}, - {Number{Number::maxRep}, + Number{false, 3'037'000'499'976049692, -9, Number::Normalized{}}}, + {Number{Number::kMAX_REP}, 4, - Number{false, 55'108'98747006743627, -14, Number::normalized{}}}, + Number{false, 55'108'98747006743627, -14, Number::Normalized{}}}, }); test(cSmall); - if (Number::getMantissaScale() != MantissaRange::mantissa_scale::small) + if (Number::getMantissaScale() != MantissaRange::MantissaScale::Small) { - NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero); + NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero); test(cLarge); } bool caught = false; @@ -893,7 +893,7 @@ public: } void - test_root2() + testRoot2() { auto const scale = Number::getMantissaScale(); testcase << "test_root2 " << to_string(scale); @@ -918,7 +918,7 @@ public: Number{5, -1}, Number{0}, Number{5625, -4}, - Number{Number::maxRep}, + Number{Number::kMAX_REP}, }); test(cSmall); bool caught = false; @@ -934,7 +934,7 @@ public: } void - test_power1() + testPower1() { testcase << "test_power1 " << to_string(Number::getMantissaScale()); using Case = std::tuple; @@ -945,14 +945,14 @@ public: {Number{-64}, 2, Number{4096}}, {Number{64}, 3, Number{262144}}, {Number{-64}, 3, Number{-262144}}, - {Number{64}, 11, Number{false, 7378697629483820646ULL, 1, Number::normalized{}}}, - {Number{-64}, 11, Number{true, 7378697629483820646ULL, 1, Number::normalized{}}}}; + {Number{64}, 11, Number{false, 7378697629483820646ULL, 1, Number::Normalized{}}}, + {Number{-64}, 11, Number{true, 7378697629483820646ULL, 1, Number::Normalized{}}}}; for (auto const& [x, y, z] : c) BEAST_EXPECT((power(x, y) == z)); } void - test_power2() + testPower2() { testcase << "test_power2 " << to_string(Number::getMantissaScale()); using Case = std::tuple; @@ -1024,11 +1024,11 @@ public: } void - test_to_integer() + testToInteger() { testcase << "test_to_integer " << to_string(Number::getMantissaScale()); using Case = std::tuple; - saveNumberRoundMode const save{Number::setround(Number::rounding_mode::to_nearest)}; + SaveNumberRoundMode const save{Number::setround(Number::RoundingMode::ToNearest)}; { Case const c[]{ {Number{0}, 0}, @@ -1065,8 +1065,8 @@ public: BEAST_EXPECT(j == y); } } - auto prev_mode = Number::setround(Number::rounding_mode::towards_zero); - BEAST_EXPECT(prev_mode == Number::rounding_mode::to_nearest); + auto prevMode = Number::setround(Number::RoundingMode::TowardsZero); + BEAST_EXPECT(prevMode == Number::RoundingMode::ToNearest); { Case const c[]{ {Number{0}, 0}, @@ -1103,8 +1103,8 @@ public: BEAST_EXPECT(j == y); } } - prev_mode = Number::setround(Number::rounding_mode::downward); - BEAST_EXPECT(prev_mode == Number::rounding_mode::towards_zero); + prevMode = Number::setround(Number::RoundingMode::Downward); + BEAST_EXPECT(prevMode == Number::RoundingMode::TowardsZero); { Case const c[]{ {Number{0}, 0}, @@ -1141,8 +1141,8 @@ public: BEAST_EXPECT(j == y); } } - prev_mode = Number::setround(Number::rounding_mode::upward); - BEAST_EXPECT(prev_mode == Number::rounding_mode::downward); + prevMode = Number::setround(Number::RoundingMode::Upward); + BEAST_EXPECT(prevMode == Number::RoundingMode::Downward); { Case const c[]{ {Number{0}, 0}, @@ -1192,7 +1192,7 @@ public: } void - test_squelch() + testSquelch() { testcase << "test_squelch " << to_string(Number::getMantissaScale()); Number const limit{1, -6}; @@ -1237,21 +1237,21 @@ public: switch (scale) { - case MantissaRange::mantissa_scale::small: + case MantissaRange::MantissaScale::Small: test(Number::min(), "1e-32753"); test(Number::max(), "9999999999999999e32768"); test(Number::lowest(), "-9999999999999999e32768"); { - NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero); + NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero); auto const maxMantissa = Number::maxMantissa(); BEAST_EXPECT(maxMantissa == 9'999'999'999'999'999); test( - Number{false, (maxMantissa * 1000) + 999, -3, Number::normalized()}, + Number{false, (maxMantissa * 1000) + 999, -3, Number::Normalized()}, "9999999999999999"); test( - Number{true, (maxMantissa * 1000) + 999, -3, Number::normalized()}, + Number{true, (maxMantissa * 1000) + 999, -3, Number::Normalized()}, "-9999999999999999"); test(Number{std::numeric_limits::max(), -3}, "9223372036854775"); @@ -1266,21 +1266,21 @@ public: "9223372036854775e3"); } break; - case MantissaRange::mantissa_scale::large: + case MantissaRange::MantissaScale::Large: // Test the edges // ((exponent < -(28)) || (exponent > -(8))))) test(Number::min(), "1e-32750"); test(Number::max(), "9223372036854775807e32768"); test(Number::lowest(), "-9223372036854775807e32768"); { - NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero); + NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero); auto const maxMantissa = Number::maxMantissa(); BEAST_EXPECT(maxMantissa == 9'999'999'999'999'999'999ULL); test( - Number{false, maxMantissa, 0, Number::normalized{}}, "9999999999999999990"); + Number{false, maxMantissa, 0, Number::Normalized{}}, "9999999999999999990"); test( - Number{true, maxMantissa, 0, Number::normalized{}}, "-9999999999999999990"); + Number{true, maxMantissa, 0, Number::Normalized{}}, "-9999999999999999990"); test( Number{std::numeric_limits::max(), 0}, "9223372036854775807"); @@ -1311,7 +1311,7 @@ public: } void - test_relationals() + testRelationals() { testcase << "test_relationals " << to_string(Number::getMantissaScale()); BEAST_EXPECT(!(Number{100} < Number{10})); @@ -1321,7 +1321,7 @@ public: } void - test_stream() + testStream() { testcase << "test_stream " << to_string(Number::getMantissaScale()); Number const x{100}; @@ -1331,7 +1331,7 @@ public: } void - test_inc_dec() + testIncDec() { testcase << "test_inc_dec " << to_string(Number::getMantissaScale()); Number x{100}; @@ -1344,29 +1344,29 @@ public: } void - test_toSTAmount() + testToStAmount() { Issue const issue; Number const n{7'518'783'80596, -5}; - saveNumberRoundMode const save{Number::setround(Number::rounding_mode::to_nearest)}; + SaveNumberRoundMode const save{Number::setround(Number::RoundingMode::ToNearest)}; auto res2 = STAmount{issue, n}; BEAST_EXPECT(res2 == STAmount{7518784}); - Number::setround(Number::rounding_mode::towards_zero); + Number::setround(Number::RoundingMode::TowardsZero); res2 = STAmount{issue, n}; BEAST_EXPECT(res2 == STAmount{7518783}); - Number::setround(Number::rounding_mode::downward); + Number::setround(Number::RoundingMode::Downward); res2 = STAmount{issue, n}; BEAST_EXPECT(res2 == STAmount{7518783}); - Number::setround(Number::rounding_mode::upward); + Number::setround(Number::RoundingMode::Upward); res2 = STAmount{issue, n}; BEAST_EXPECT(res2 == STAmount{7518784}); } void - test_truncate() + testTruncate() { BEAST_EXPECT(Number(25, +1).truncate() == Number(250, 0)); BEAST_EXPECT(Number(25, 0).truncate() == Number(25, 0)); @@ -1395,92 +1395,92 @@ public: // Test that rounding works as expected. testcase("Rounding"); - using NumberRoundings = std::map; + using NumberRoundings = std::map; std::map const expected{ // Positive numbers {Number{13, -1}, - {{Number::rounding_mode::to_nearest, 1}, - {Number::rounding_mode::towards_zero, 1}, - {Number::rounding_mode::downward, 1}, - {Number::rounding_mode::upward, 2}}}, + {{Number::RoundingMode::ToNearest, 1}, + {Number::RoundingMode::TowardsZero, 1}, + {Number::RoundingMode::Downward, 1}, + {Number::RoundingMode::Upward, 2}}}, {Number{23, -1}, - {{Number::rounding_mode::to_nearest, 2}, - {Number::rounding_mode::towards_zero, 2}, - {Number::rounding_mode::downward, 2}, - {Number::rounding_mode::upward, 3}}}, + {{Number::RoundingMode::ToNearest, 2}, + {Number::RoundingMode::TowardsZero, 2}, + {Number::RoundingMode::Downward, 2}, + {Number::RoundingMode::Upward, 3}}}, {Number{15, -1}, - {{Number::rounding_mode::to_nearest, 2}, - {Number::rounding_mode::towards_zero, 1}, - {Number::rounding_mode::downward, 1}, - {Number::rounding_mode::upward, 2}}}, + {{Number::RoundingMode::ToNearest, 2}, + {Number::RoundingMode::TowardsZero, 1}, + {Number::RoundingMode::Downward, 1}, + {Number::RoundingMode::Upward, 2}}}, {Number{25, -1}, - {{Number::rounding_mode::to_nearest, 2}, - {Number::rounding_mode::towards_zero, 2}, - {Number::rounding_mode::downward, 2}, - {Number::rounding_mode::upward, 3}}}, + {{Number::RoundingMode::ToNearest, 2}, + {Number::RoundingMode::TowardsZero, 2}, + {Number::RoundingMode::Downward, 2}, + {Number::RoundingMode::Upward, 3}}}, {Number{152, -2}, - {{Number::rounding_mode::to_nearest, 2}, - {Number::rounding_mode::towards_zero, 1}, - {Number::rounding_mode::downward, 1}, - {Number::rounding_mode::upward, 2}}}, + {{Number::RoundingMode::ToNearest, 2}, + {Number::RoundingMode::TowardsZero, 1}, + {Number::RoundingMode::Downward, 1}, + {Number::RoundingMode::Upward, 2}}}, {Number{252, -2}, - {{Number::rounding_mode::to_nearest, 3}, - {Number::rounding_mode::towards_zero, 2}, - {Number::rounding_mode::downward, 2}, - {Number::rounding_mode::upward, 3}}}, + {{Number::RoundingMode::ToNearest, 3}, + {Number::RoundingMode::TowardsZero, 2}, + {Number::RoundingMode::Downward, 2}, + {Number::RoundingMode::Upward, 3}}}, {Number{17, -1}, - {{Number::rounding_mode::to_nearest, 2}, - {Number::rounding_mode::towards_zero, 1}, - {Number::rounding_mode::downward, 1}, - {Number::rounding_mode::upward, 2}}}, + {{Number::RoundingMode::ToNearest, 2}, + {Number::RoundingMode::TowardsZero, 1}, + {Number::RoundingMode::Downward, 1}, + {Number::RoundingMode::Upward, 2}}}, {Number{27, -1}, - {{Number::rounding_mode::to_nearest, 3}, - {Number::rounding_mode::towards_zero, 2}, - {Number::rounding_mode::downward, 2}, - {Number::rounding_mode::upward, 3}}}, + {{Number::RoundingMode::ToNearest, 3}, + {Number::RoundingMode::TowardsZero, 2}, + {Number::RoundingMode::Downward, 2}, + {Number::RoundingMode::Upward, 3}}}, // Negative numbers {Number{-13, -1}, - {{Number::rounding_mode::to_nearest, -1}, - {Number::rounding_mode::towards_zero, -1}, - {Number::rounding_mode::downward, -2}, - {Number::rounding_mode::upward, -1}}}, + {{Number::RoundingMode::ToNearest, -1}, + {Number::RoundingMode::TowardsZero, -1}, + {Number::RoundingMode::Downward, -2}, + {Number::RoundingMode::Upward, -1}}}, {Number{-23, -1}, - {{Number::rounding_mode::to_nearest, -2}, - {Number::rounding_mode::towards_zero, -2}, - {Number::rounding_mode::downward, -3}, - {Number::rounding_mode::upward, -2}}}, + {{Number::RoundingMode::ToNearest, -2}, + {Number::RoundingMode::TowardsZero, -2}, + {Number::RoundingMode::Downward, -3}, + {Number::RoundingMode::Upward, -2}}}, {Number{-15, -1}, - {{Number::rounding_mode::to_nearest, -2}, - {Number::rounding_mode::towards_zero, -1}, - {Number::rounding_mode::downward, -2}, - {Number::rounding_mode::upward, -1}}}, + {{Number::RoundingMode::ToNearest, -2}, + {Number::RoundingMode::TowardsZero, -1}, + {Number::RoundingMode::Downward, -2}, + {Number::RoundingMode::Upward, -1}}}, {Number{-25, -1}, - {{Number::rounding_mode::to_nearest, -2}, - {Number::rounding_mode::towards_zero, -2}, - {Number::rounding_mode::downward, -3}, - {Number::rounding_mode::upward, -2}}}, + {{Number::RoundingMode::ToNearest, -2}, + {Number::RoundingMode::TowardsZero, -2}, + {Number::RoundingMode::Downward, -3}, + {Number::RoundingMode::Upward, -2}}}, {Number{-152, -2}, - {{Number::rounding_mode::to_nearest, -2}, - {Number::rounding_mode::towards_zero, -1}, - {Number::rounding_mode::downward, -2}, - {Number::rounding_mode::upward, -1}}}, + {{Number::RoundingMode::ToNearest, -2}, + {Number::RoundingMode::TowardsZero, -1}, + {Number::RoundingMode::Downward, -2}, + {Number::RoundingMode::Upward, -1}}}, {Number{-252, -2}, - {{Number::rounding_mode::to_nearest, -3}, - {Number::rounding_mode::towards_zero, -2}, - {Number::rounding_mode::downward, -3}, - {Number::rounding_mode::upward, -2}}}, + {{Number::RoundingMode::ToNearest, -3}, + {Number::RoundingMode::TowardsZero, -2}, + {Number::RoundingMode::Downward, -3}, + {Number::RoundingMode::Upward, -2}}}, {Number{-17, -1}, - {{Number::rounding_mode::to_nearest, -2}, - {Number::rounding_mode::towards_zero, -1}, - {Number::rounding_mode::downward, -2}, - {Number::rounding_mode::upward, -1}}}, + {{Number::RoundingMode::ToNearest, -2}, + {Number::RoundingMode::TowardsZero, -1}, + {Number::RoundingMode::Downward, -2}, + {Number::RoundingMode::Upward, -1}}}, {Number{-27, -1}, - {{Number::rounding_mode::to_nearest, -3}, - {Number::rounding_mode::towards_zero, -2}, - {Number::rounding_mode::downward, -3}, - {Number::rounding_mode::upward, -2}}}, + {{Number::RoundingMode::ToNearest, -3}, + {Number::RoundingMode::TowardsZero, -2}, + {Number::RoundingMode::Downward, -3}, + {Number::RoundingMode::Upward, -2}}}, }; for (auto const& [num, roundings] : expected) @@ -1508,45 +1508,45 @@ public: Number const ten{10}; BEAST_EXPECT(ten.exponent() <= 0); - if (scale == MantissaRange::mantissa_scale::small) + if (scale == MantissaRange::MantissaScale::Small) { - BEAST_EXPECT(std::numeric_limits::max() > INITIAL_XRP.drops()); - BEAST_EXPECT(Number::maxMantissa() < INITIAL_XRP.drops()); - Number const initalXrp{INITIAL_XRP}; + BEAST_EXPECT(std::numeric_limits::max() > kINITIAL_XRP.drops()); + BEAST_EXPECT(Number::maxMantissa() < kINITIAL_XRP.drops()); + Number const initalXrp{kINITIAL_XRP}; BEAST_EXPECT(initalXrp.exponent() > 0); - Number const maxInt64{Number::maxRep}; + Number const maxInt64{Number::kMAX_REP}; BEAST_EXPECT(maxInt64.exponent() > 0); // 85'070'591'730'234'615'865'843'651'857'942'052'864 - 38 digits BEAST_EXPECT((power(maxInt64, 2) == Number{85'070'591'730'234'62, 22})); - Number const max = Number{false, Number::maxMantissa(), 0, Number::normalized{}}; + Number const max = Number{false, Number::maxMantissa(), 0, Number::Normalized{}}; BEAST_EXPECT(max.exponent() <= 0); // 99'999'999'999'999'980'000'000'000'000'001 - 32 digits BEAST_EXPECT((power(max, 2) == Number{99'999'999'999'999'98, 16})); } else { - BEAST_EXPECT(std::numeric_limits::max() > INITIAL_XRP.drops()); - BEAST_EXPECT(Number::maxMantissa() > INITIAL_XRP.drops()); - Number const initalXrp{INITIAL_XRP}; + BEAST_EXPECT(std::numeric_limits::max() > kINITIAL_XRP.drops()); + BEAST_EXPECT(Number::maxMantissa() > kINITIAL_XRP.drops()); + Number const initalXrp{kINITIAL_XRP}; BEAST_EXPECT(initalXrp.exponent() <= 0); - Number const maxInt64{Number::maxRep}; + Number const maxInt64{Number::kMAX_REP}; BEAST_EXPECT(maxInt64.exponent() <= 0); // 85'070'591'730'234'615'847'396'907'784'232'501'249 - 38 digits BEAST_EXPECT((power(maxInt64, 2) == Number{85'070'591'730'234'615'85, 19})); - NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero); + NumberRoundModeGuard const mg(Number::RoundingMode::TowardsZero); auto const maxMantissa = Number::maxMantissa(); - Number const max = Number{false, maxMantissa, 0, Number::normalized{}}; + Number const max = Number{false, maxMantissa, 0, Number::Normalized{}}; BEAST_EXPECT(max.mantissa() == maxMantissa / 10); BEAST_EXPECT(max.exponent() == 1); // 99'999'999'999'999'999'800'000'000'000'000'000'100 - also 38 // digits BEAST_EXPECT( - (power(max, 2) == Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}})); + (power(max, 2) == Number{false, (maxMantissa / 10) - 1, 20, Number::Normalized{}})); } } @@ -1554,28 +1554,28 @@ public: run() override { for (auto const scale : - {MantissaRange::mantissa_scale::small, MantissaRange::mantissa_scale::large}) + {MantissaRange::MantissaScale::Small, MantissaRange::MantissaScale::Large}) { NumberMantissaScaleGuard const sg(scale); testZero(); - test_limits(); + testLimits(); testToString(); - test_add(); - test_sub(); - test_mul(); - test_div(); - test_root(); - test_root2(); - test_power1(); - test_power2(); + testAdd(); + testSub(); + testMul(); + testDiv(); + testRoot(); + testRoot2(); + testPower1(); + testPower2(); testConversions(); - test_to_integer(); - test_squelch(); - test_relationals(); - test_stream(); - test_inc_dec(); - test_toSTAmount(); - test_truncate(); + testToInteger(); + testSquelch(); + testRelationals(); + testStream(); + testIncDec(); + testToStAmount(); + testTruncate(); testRounding(); testInt64(); } diff --git a/src/test/jtx/AMM.h b/src/test/jtx/AMM.h index 2bd3da8cf5..dbb06bb651 100644 --- a/src/test/jtx/AMM.h +++ b/src/test/jtx/AMM.h @@ -49,9 +49,9 @@ struct CreateArg std::uint16_t tfee = 0; std::uint32_t fee = 0; std::optional flags = std::nullopt; - std::optional seq = std::nullopt; - std::optional ms = std::nullopt; - std::optional err = std::nullopt; + std::optional seq = std::nullopt; + std::optional ms = std::nullopt; + std::optional err = std::nullopt; bool close = true; }; @@ -64,9 +64,9 @@ struct DepositArg std::optional maxEP = std::nullopt; std::optional flags = std::nullopt; std::optional> assets = std::nullopt; - std::optional seq = std::nullopt; + std::optional seq = std::nullopt; std::optional tfee = std::nullopt; - std::optional err = std::nullopt; + std::optional err = std::nullopt; }; struct WithdrawArg @@ -78,8 +78,8 @@ struct WithdrawArg std::optional maxEP = std::nullopt; std::optional flags = std::nullopt; std::optional> assets = std::nullopt; - std::optional seq = std::nullopt; - std::optional err = std::nullopt; + std::optional seq = std::nullopt; + std::optional err = std::nullopt; }; struct VoteArg @@ -87,9 +87,9 @@ struct VoteArg std::optional account = std::nullopt; std::uint32_t tfee = 0; std::optional flags = std::nullopt; - std::optional seq = std::nullopt; + std::optional seq = std::nullopt; std::optional> assets = std::nullopt; - std::optional err = std::nullopt; + std::optional err = std::nullopt; }; struct BidArg @@ -109,7 +109,7 @@ struct ClawbackArg std::optional> assets = std::nullopt; std::optional amount = std::nullopt; std::optional flags = std::nullopt; - std::optional err = std::nullopt; + std::optional err = std::nullopt; }; /** Convenience class to test AMM functionality. @@ -128,7 +128,7 @@ class AMM std::optional bidMin_; std::optional bidMax_; // Multi-signature - std::optional const msig_; + std::optional const msig_; // Transaction fee std::uint32_t const fee_; AccountID const ammAccount_; @@ -144,15 +144,15 @@ public: std::uint16_t tfee = 0, std::uint32_t fee = 0, std::optional flags = std::nullopt, - std::optional seq = std::nullopt, - std::optional ms = std::nullopt, - std::optional const& ter = std::nullopt, + std::optional seq = std::nullopt, + std::optional ms = std::nullopt, + std::optional const& ter = std::nullopt, bool close = true); AMM(Env& env, Account const& account, STAmount const& asset1, STAmount const& asset2, - ter const& ter, + Ter const& ter, bool log = false, bool close = true); AMM(Env& env, @@ -178,7 +178,7 @@ public: std::optional asset2 = std::nullopt, std::optional const& ammAccount = std::nullopt, bool ignoreParams = false, - unsigned apiVersion = RPC::apiInvalidVersion) const; + unsigned apiVersion = RPC::kAPI_INVALID_VERSION) const; /** Verify the AMM balances. */ @@ -229,7 +229,7 @@ public: STAmount const& asset2, IOUAmount const& balance, std::optional const& account = std::nullopt, - std::optional const& ledger_index = std::nullopt, + std::optional const& ledgerIndex = std::nullopt, std::optional const& ammAccount = std::nullopt) const; [[nodiscard]] bool @@ -244,7 +244,7 @@ public: LPToken tokens, std::optional const& asset1InDetails = std::nullopt, std::optional const& flags = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); IOUAmount deposit( @@ -253,7 +253,7 @@ public: std::optional const& asset2InAmount = std::nullopt, std::optional const& maxEP = std::nullopt, std::optional const& flags = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); IOUAmount deposit( @@ -264,9 +264,9 @@ public: std::optional const& maxEP, std::optional const& flags, std::optional> const& assets, - std::optional const& seq, + std::optional const& seq, std::optional const& tfee = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); IOUAmount deposit(DepositArg const& arg); @@ -280,19 +280,19 @@ public: std::optional const& tokens, std::optional const& asset1OutDetails = std::nullopt, std::optional const& flags = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); IOUAmount withdrawAll( std::optional const& account, std::optional const& asset1OutDetails = std::nullopt, - std::optional const& ter = std::nullopt) + std::optional const& ter = std::nullopt) { return withdraw( account, std::nullopt, asset1OutDetails, - asset1OutDetails ? tfOneAssetWithdrawAll : tfWithdrawAll, + asset1OutDetails ? kTF_ONE_ASSET_WITHDRAW_ALL : kTF_WITHDRAW_ALL, ter); } @@ -302,7 +302,7 @@ public: STAmount const& asset1Out, std::optional const& asset2Out = std::nullopt, std::optional const& maxEP = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); IOUAmount withdraw( @@ -313,8 +313,8 @@ public: std::optional const& maxEP, std::optional const& flags, std::optional> const& assets, - std::optional const& seq, - std::optional const& ter = std::nullopt); + std::optional const& seq, + std::optional const& ter = std::nullopt); IOUAmount withdraw(WithdrawArg const& arg); @@ -327,9 +327,9 @@ public: std::optional const& account, std::uint32_t feeVal, std::optional const& flags = std::nullopt, - std::optional const& seq = std::nullopt, + std::optional const& seq = std::nullopt, std::optional> const& assets = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& ter = std::nullopt); void vote(VoteArg const& arg); @@ -385,7 +385,7 @@ public: deleteJv(AccountID const& account, Asset const& asset1, Asset const& assets); void - ammDelete(AccountID const& account, std::optional const& ter = std::nullopt); + ammDelete(AccountID const& account, std::optional const& ter = std::nullopt); void setClose(bool close) @@ -422,9 +422,9 @@ public: { auto const& jr = p.amm.ammRpcInfo(); auto out = [&](Json::Value const& jv) { - if (jv.isMember(jss::value)) + if (jv.isMember(jss::kVALUE)) { - std::cout << jv[jss::value].asString(); + std::cout << jv[jss::kVALUE].asString(); } else { @@ -434,9 +434,9 @@ public: }; if (p.names.empty()) { - out(jr[jss::amm][jss::amount]); - out(jr[jss::amm][jss::amount2]); - out(jr[jss::amm][jss::lp_token]); + out(jr[jss::amm][jss::kAMOUNT]); + out(jr[jss::amm][jss::kAMOUNT2]); + out(jr[jss::amm][jss::kLP_TOKEN]); } else { @@ -457,21 +457,21 @@ public: operator<<(std::ostream& s, Offers const& offers) { auto out = [&](Json::Value const& jv) { - if (jv.isMember(jss::value)) + if (jv.isMember(jss::kVALUE)) { - s << jv[jss::value].asString(); + s << jv[jss::kVALUE].asString(); } else { s << jv; } }; - for (auto const& o : offers.jv[jss::offers]) + for (auto const& o : offers.jv[jss::kOFFERS]) { s << "taker_pays: "; - out(o[jss::taker_pays]); + out(o[jss::kTAKER_PAYS]); s << " taker_gets: "; - out(o[jss::taker_gets]); + out(o[jss::kTAKER_GETS]); s << std::endl; } return s; @@ -483,8 +483,8 @@ private: create( std::uint32_t tfee = 0, std::optional const& flags = std::nullopt, - std::optional const& seq = std::nullopt, - std::optional const& ter = std::nullopt); + std::optional const& seq = std::nullopt, + std::optional const& ter = std::nullopt); void log(bool log) @@ -502,8 +502,8 @@ private: void submit( Json::Value const& jv, - std::optional const& seq, - std::optional const& ter); + std::optional const& seq, + std::optional const& ter); [[nodiscard]] bool expectAuctionSlot(auto&& cb) const; diff --git a/src/test/jtx/AMMTest.h b/src/test/jtx/AMMTest.h index ffb186e0d6..f5cdc27178 100644 --- a/src/test/jtx/AMMTest.h +++ b/src/test/jtx/AMMTest.h @@ -17,7 +17,7 @@ struct TestAMMArg { std::optional> pool = std::nullopt; std::uint16_t tfee = 0; - std::optional ter = std::nullopt; + std::optional ter = std::nullopt; std::vector features = { // For now, just disable SAV entirely, which locks in the small Number // mantissas @@ -30,7 +30,7 @@ struct TestAMMArg // A distinct MPT is created if both AMM assets // are MPT. The actual MPT asset can be accessed // via AMM::operator[](0|1). -inline static auto AMMMPT = MPT("AMM"); +inline static auto gAmmmpt = MPT("AMM"); [[maybe_unused]] std::vector fund( @@ -62,28 +62,28 @@ struct TestAMMArgs { std::optional> const& pool = std::nullopt; std::uint16_t tfee = 0; - std::optional const& ter = std::nullopt; + std::optional const& ter = std::nullopt; std::vector const& features = {testable_amendments()}; }; -class AMMTestBase : public beast::unit_test::suite +class AMMTestBase : public beast::unit_test::Suite { protected: - jtx::Account const gw; - jtx::Account const carol; - jtx::Account const alice; - jtx::Account const bob; - jtx::IOU const USD; - jtx::IOU const EUR; - jtx::IOU const GBP; - jtx::IOU const BTC; - jtx::IOU const BAD; + jtx::Account const gw_; + jtx::Account const carol_; + jtx::Account const alice_; + jtx::Account const bob_; + jtx::IOU const USD_; + jtx::IOU const EUR_; + jtx::IOU const GBP_; + jtx::IOU const BTC_; + jtx::IOU const BAD_; public: AMMTestBase(); static FeatureBitset - testable_amendments() + testableAmendments() { // For now, just disable SAV entirely, which locks in the small Number // mantissas @@ -99,8 +99,8 @@ protected: std::function const& cb, std::optional> const& pool = std::nullopt, std::uint16_t tfee = 0, - std::optional const& ter = std::nullopt, - std::vector const& features = {testable_amendments()}); + std::optional const& ter = std::nullopt, + std::vector const& features = {testableAmendments()}); void testAMM(std::function const& cb, TestAMMArg const& arg); @@ -117,7 +117,7 @@ protected: /* Path_test */ /************************************************/ - class gate + class Gate { private: std::condition_variable cv_; @@ -129,10 +129,10 @@ protected: // Returns `true` if signaled. template bool - wait_for(std::chrono::duration const& rel_time) + waitFor(std::chrono::duration const& relTime) { std::unique_lock lk(mutex_); - auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; }); + auto b = cv_.wait_for(lk, relTime, [this] { return signaled_; }); signaled_ = false; return b; } diff --git a/src/test/jtx/Account.h b/src/test/jtx/Account.h index a30b974522..b6c73f274c 100644 --- a/src/test/jtx/Account.h +++ b/src/test/jtx/Account.h @@ -17,13 +17,13 @@ class Account { private: // Tag for access to private contr - struct privateCtorTag + struct PrivateCtorTag { }; public: /** The master account. */ - static Account const master; + static Account const kMASTER; Account() = delete; Account(Account&&) = default; @@ -35,16 +35,16 @@ public: /** Create an account from a simple string name. */ /** @{ */ - Account(std::string name, KeyType type = KeyType::secp256k1); + Account(std::string name, KeyType type = KeyType::Secp256k1); - Account(char const* name, KeyType type = KeyType::secp256k1) : Account(std::string(name), type) + Account(char const* name, KeyType type = KeyType::Secp256k1) : Account(std::string(name), type) { } // This constructor needs to be public so `std::pair` can use it when // emplacing into the cache. However, it is logically `private`. This is // enforced with the `privateTag` parameter. - Account(std::string name, std::pair const& keys, Account::privateCtorTag); + Account(std::string name, std::pair const& keys, Account::PrivateCtorTag); /** @} */ @@ -52,7 +52,7 @@ public: * secret key is unavailable, such as for pseudo-accounts. */ explicit Account(std::string name, AccountID const& id); - enum class AcctStringType { base58Seed, other }; + enum class AcctStringType { Base58Seed, Other }; /** Create an account from a base58 seed string. Throws on invalid seed. */ Account(AcctStringType stringType, std::string base58SeedStr); @@ -109,7 +109,7 @@ public: operator[](std::string const& s) const; private: - static std::unordered_map, Account, beast::uhash<>> cache_; + static std::unordered_map, Account, beast::Uhash<>> cache; // Return the account from the cache & add it to the cache if needed static Account diff --git a/src/test/jtx/CaptureLogs.h b/src/test/jtx/CaptureLogs.h index 491a341540..7effa30074 100644 --- a/src/test/jtx/CaptureLogs.h +++ b/src/test/jtx/CaptureLogs.h @@ -49,7 +49,7 @@ class CaptureLogs : public Logs }; public: - explicit CaptureLogs(std::string* pResult) : Logs(beast::severities::kInfo), pResult_(pResult) + explicit CaptureLogs(std::string* pResult) : Logs(beast::severities::KInfo), pResult_(pResult) { } diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 3b55e6ef09..6cf0c097c8 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -75,7 +75,7 @@ noripple(Account const& account, Args const&... args) inline FeatureBitset testable_amendments() { - static FeatureBitset const ids = [] { + static FeatureBitset const kIDS = [] { auto const& sa = allAmendments(); std::vector feats; feats.reserve(sa.size()); @@ -93,18 +93,18 @@ testable_amendments() } return FeatureBitset(feats); }(); - return ids; + return kIDS; } //------------------------------------------------------------------------------ class SuiteLogs : public Logs { - beast::unit_test::suite& suite_; + beast::unit_test::Suite& suite_; public: - explicit SuiteLogs(beast::unit_test::suite& suite) - : Logs(beast::severities::kError), suite_(suite) + explicit SuiteLogs(beast::unit_test::Suite& suite) + : Logs(beast::severities::KError), suite_(suite) { } @@ -123,9 +123,9 @@ public: class Env { public: - beast::unit_test::suite& test; + beast::unit_test::Suite& test; - Account const& master = Account::master; + Account const& master = Account::kMASTER; /// Used by parseResult() and postConditions() struct ParsedResult @@ -135,7 +135,7 @@ public: // with an "error" that corresponds to the "code"), or with an "error" // and an "exception". However, this structure allows all possible // combinations. - std::optional rpcCode; + std::optional rpcCode; std::string rpcMessage; std::string rpcError; std::string rpcException; @@ -152,7 +152,7 @@ private: AppBundle() = default; AppBundle( - beast::unit_test::suite& suite, + beast::unit_test::Suite& suite, std::unique_ptr config, std::unique_ptr logs, beast::severities::Severity thresh); @@ -184,16 +184,16 @@ public: * supported_features_except() to enable all and disable specific features. */ // VFALCO Could wrap the suite::log in a Journal here - Env(beast::unit_test::suite& suite_, + Env(beast::unit_test::Suite& suite, std::unique_ptr config, FeatureBitset features, std::unique_ptr logs = nullptr, - beast::severities::Severity thresh = beast::severities::kError) - : test(suite_) - , bundle_(suite_, std::move(config), std::move(logs), thresh) + beast::severities::Severity thresh = beast::severities::KError) + : test(suite) + , bundle_(suite, std::move(config), std::move(logs), thresh) , journal{bundle_.app->getJournal("Env")} { - memoize(Account::master); + memoize(Account::kMASTER); Pathfinder::initPathTable(); foreachFeature(features, [&appFeats = app().config().features](uint256 const& f) { appFeats.insert(f); @@ -213,10 +213,10 @@ public: * @param args collection of features * */ - Env(beast::unit_test::suite& suite_, + Env(beast::unit_test::Suite& suite, FeatureBitset features, std::unique_ptr logs = nullptr) - : Env(suite_, envconfig(), features, std::move(logs)) + : Env(suite, envconfig(), features, std::move(logs)) { } @@ -232,11 +232,11 @@ public: * the pointer. See envconfig and related functions for common config * tweaks. */ - Env(beast::unit_test::suite& suite_, + Env(beast::unit_test::Suite& suite, std::unique_ptr config, std::unique_ptr logs = nullptr, - beast::severities::Severity thresh = beast::severities::kError) - : Env(suite_, std::move(config), testable_amendments(), std::move(logs), thresh) + beast::severities::Severity thresh = beast::severities::KError) + : Env(suite, std::move(config), testable_amendments(), std::move(logs), thresh) { } @@ -249,9 +249,9 @@ public: * * @param suite_ the current unit_test::suite */ - Env(beast::unit_test::suite& suite_, - beast::severities::Severity thresh = beast::severities::kError) - : Env(suite_, envconfig(), nullptr, thresh) + Env(beast::unit_test::Suite& suite, + beast::severities::Severity thresh = beast::severities::KError) + : Env(suite, envconfig(), nullptr, thresh) { } @@ -459,21 +459,21 @@ public: } void - set_parse_failure_expected(bool b) + setParseFailureExpected(bool b) { parseFailureExpected_ = b; } /** Turn off signature checks. */ void - disable_sigs() + disableSigs() { app().checkSigs(false); } // set rpc retries void - set_retries(unsigned r = 5) + setRetries(unsigned r = 5) { retries_ = r; } @@ -561,7 +561,7 @@ public: { JTx jt(std::forward(jv)); invoke(jt, fN...); - autofill_sig(jt); + autofillSig(jt); jt.stx = st(jt); return jt; } @@ -604,9 +604,9 @@ public: This calls postconditions. */ void - sign_and_submit( + signAndSubmit( JTx const& jt, - Json::Value params = Json::nullValue, + Json::Value params = Json::NullValue, std::source_location const& loc = std::source_location::current()); /** Check expected postconditions @@ -704,14 +704,14 @@ private: fund(bool setDefaultRipple, STAmount const& amount, Account const& account); void - fund_arg(STAmount const& amount, Account const& account) + fundArg(STAmount const& amount, Account const& account) { fund(true, amount, account); } template void - fund_arg(STAmount const& amount, std::array const& list) + fundArg(STAmount const& amount, std::array const& list) { for (auto const& account : list) fund(false, amount, account); @@ -748,7 +748,7 @@ public: void fund(STAmount const& amount, Arg const& arg, Args const&... args) { - fund_arg(amount, arg); + fundArg(amount, arg); if constexpr (sizeof...(args) > 0) fund(amount, args...); } @@ -794,18 +794,18 @@ protected: int trace_ = 0; TestStopwatch stopwatch_; uint256 txid_; - TER ter_ = tesSUCCESS; + TER ter_ = TesSuccess; bool parseFailureExpected_ = false; unsigned retries_ = 5; Json::Value - do_rpc( + doRpc( unsigned apiVersion, std::vector const& args, std::unordered_map const& headers = {}); void - autofill_sig(JTx& jt); + autofillSig(JTx& jt); virtual void autofill(JTx& jt); @@ -849,7 +849,7 @@ Env::rpc( std::string const& cmd, Args&&... args) { - return do_rpc(apiVersion, std::vector{cmd, std::forward(args)...}, headers); + return doRpc(apiVersion, std::vector{cmd, std::forward(args)...}, headers); } template @@ -870,8 +870,8 @@ Env::rpc( std::string const& cmd, Args&&... args) { - return do_rpc( - RPC::apiCommandLineVersion, + return doRpc( + RPC::kAPI_COMMAND_LINE_VERSION, std::vector{cmd, std::forward(args)...}, headers); } diff --git a/src/test/jtx/Env_ss.h b/src/test/jtx/Env_ss.h index e9f6ae3bb1..18f70e2abe 100644 --- a/src/test/jtx/Env_ss.h +++ b/src/test/jtx/Env_ss.h @@ -8,7 +8,7 @@ namespace xrpl::test::jtx { Transactions submitted in sign-and-submit mode by default. */ -class Env_ss +class EnvSs { private: Env& env_; @@ -27,9 +27,9 @@ private: } void - operator()(Json::Value const& params = Json::nullValue) + operator()(Json::Value const& params = Json::NullValue) { - env_.sign_and_submit(jt_, params, loc_); + env_.signAndSubmit(jt_, params, loc_); } private: @@ -39,11 +39,11 @@ private: }; public: - Env_ss(Env_ss const&) = delete; - Env_ss& - operator=(Env_ss const&) = delete; + EnvSs(EnvSs const&) = delete; + EnvSs& + operator=(EnvSs const&) = delete; - Env_ss(Env& env) : env_(env) + EnvSs(Env& env) : env_(env) { } diff --git a/src/test/jtx/JTx.h b/src/test/jtx/JTx.h index 4693c4e1a7..84279fbda3 100644 --- a/src/test/jtx/JTx.h +++ b/src/test/jtx/JTx.h @@ -23,8 +23,8 @@ struct JTx { Json::Value jv; requires_t require; - std::optional ter = TER{tesSUCCESS}; - std::optional> rpcCode = std::nullopt; + std::optional ter = TER{TesSuccess}; + std::optional> rpcCode = std::nullopt; std::optional>> rpcException = std::nullopt; bool fill_fee = true; bool fill_seq = true; @@ -45,11 +45,11 @@ struct JTx JTx& operator=(JTx&&) = default; - JTx(Json::Value&& jv_) : jv(std::move(jv_)) + JTx(Json::Value&& jv) : jv(std::move(jv)) { } - JTx(Json::Value const& jv_) : jv(jv_) + JTx(Json::Value const& jv) : jv(jv) { } @@ -71,7 +71,7 @@ struct JTx { for (auto& prop : props_.list) { - if (auto test = dynamic_cast*>(prop.get())) + if (auto test = dynamic_cast*>(prop.get())) return &test->t; } return nullptr; @@ -83,7 +83,7 @@ struct JTx { for (auto& prop : props_.list) { - if (auto test = dynamic_cast const*>(prop.get())) + if (auto test = dynamic_cast const*>(prop.get())) return &test->t; } return nullptr; @@ -96,7 +96,7 @@ struct JTx */ /** @{ */ void - set(std::unique_ptr p) + set(std::unique_ptr p) { for (auto& prop : props_.list) { @@ -113,23 +113,23 @@ struct JTx void set(Args&&... args) { - set(std::make_unique>(std::forward(args)...)); + set(std::make_unique>(std::forward(args)...)); } /** @} */ private: - struct prop_list + struct PropList { - prop_list() = default; + PropList() = default; - prop_list(prop_list const& other) + PropList(PropList const& other) { for (auto const& prop : other.list) list.emplace_back(prop->clone()); } - prop_list& - operator=(prop_list const& other) + PropList& + operator=(PropList const& other) { if (this != &other) { @@ -140,14 +140,14 @@ private: return *this; } - prop_list(prop_list&& src) = default; - prop_list& - operator=(prop_list&& src) = default; + PropList(PropList&& src) = default; + PropList& + operator=(PropList&& src) = default; - std::vector> list; + std::vector> list; }; - prop_list props_; + PropList props_; }; } // namespace xrpl::test::jtx diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index fc739861cb..df1cf19daf 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -81,13 +81,13 @@ public: addHelper(std::forward(first), std::forward(rest)...); } Path& - push_back(Issue const& iss); + pushBack(Issue const& iss); Path& - push_back(MPTIssue const& iss); + pushBack(MPTIssue const& iss); Path& - push_back(jtx::Account const& acc); + pushBack(jtx::Account const& acc); Path& - push_back(STPathElement const& pe); + pushBack(STPathElement const& pe); [[nodiscard]] Json::Value json() const; @@ -98,38 +98,38 @@ private: }; inline Path& -Path::push_back(STPathElement const& pe) +Path::pushBack(STPathElement const& pe) { - path.emplace_back(pe); + path.emplaceBack(pe); return *this; } inline Path& -Path::push_back(Issue const& iss) +Path::pushBack(Issue const& iss) { - path.emplace_back( - STPathElement::typeCurrency | STPathElement::typeIssuer, - beast::zero, + path.emplaceBack( + STPathElement::TypeCurrency | STPathElement::TypeIssuer, + beast::kZERO, iss.currency, iss.account); return *this; } inline Path& -Path::push_back(MPTIssue const& iss) +Path::pushBack(MPTIssue const& iss) { - path.emplace_back( - STPathElement::typeMPT | STPathElement::typeIssuer, - beast::zero, + path.emplaceBack( + STPathElement::TypeMpt | STPathElement::TypeIssuer, + beast::kZERO, iss.getMptID(), iss.getIssuer()); return *this; } inline Path& -Path::push_back(jtx::Account const& account) +Path::pushBack(jtx::Account const& account) { - path.emplace_back(account.id(), Currency{beast::zero}, beast::zero); + path.emplaceBack(account.id(), Currency{beast::kZERO}, beast::kZERO); return *this; } @@ -137,7 +137,7 @@ template void Path::addHelper(First&& first, Rest&&... rest) { - push_back(std::forward(first)); + pushBack(std::forward(first)); if constexpr (sizeof...(rest) > 0) addHelper(std::forward(rest)...); } @@ -145,7 +145,7 @@ Path::addHelper(First&& first, Rest&&... rest) inline Json::Value Path::json() const { - return path.getJson(JsonOptions::none); + return path.getJson(JsonOptions::None); } class PathSet @@ -170,7 +170,7 @@ public: json() const { Json::Value v; - v["Paths"] = paths.getJson(JsonOptions::none); + v["Paths"] = paths.getJson(JsonOptions::None); return v; } @@ -179,7 +179,7 @@ private: void addHelper(First first, Rest... rest) { - paths.emplace_back(std::move(first.path)); + paths.emplaceBack(std::move(first.path)); if constexpr (sizeof...(rest) > 0) addHelper(std::move(rest)...); } diff --git a/src/test/jtx/SignerUtils.h b/src/test/jtx/SignerUtils.h index dd68701303..92188202b8 100644 --- a/src/test/jtx/SignerUtils.h +++ b/src/test/jtx/SignerUtils.h @@ -17,7 +17,7 @@ struct Reg { } - Reg(Account acct_, Account regularSig) : acct(std::move(acct_)), sig(std::move(regularSig)) + Reg(Account acct, Account regularSig) : acct(std::move(acct)), sig(std::move(regularSig)) { } @@ -25,7 +25,7 @@ struct Reg { } - Reg(char const* acct_, char const* regularSig) : acct(acct_), sig(regularSig) + Reg(char const* acct, char const* regularSig) : acct(acct), sig(regularSig) { } diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index ae52c50b89..fa2fb7651b 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -79,7 +79,7 @@ public: } }; -struct timePointField : public JTxField +struct TimePointField : public JTxField { using SF = SF_UINT32; using SV = NetClock::time_point; @@ -90,7 +90,7 @@ protected: using base::value_; public: - explicit timePointField(SF const& sfield, SV const& value) : JTxField(sfield, value) + explicit TimePointField(SF const& sfield, SV const& value) : JTxField(sfield, value) { } @@ -101,7 +101,7 @@ public: } }; -struct uint256Field : public JTxField +struct Uint256Field : public JTxField { using SF = SF_UINT256; using SV = uint256; @@ -112,7 +112,7 @@ protected: using base::value_; public: - explicit uint256Field(SF const& sfield, SV const& value) : JTxField(sfield, value) + explicit Uint256Field(SF const& sfield, SV const& value) : JTxField(sfield, value) { } @@ -123,7 +123,7 @@ public: } }; -struct accountIDField : public JTxField +struct AccountIdField : public JTxField { using SF = SF_ACCOUNT; using SV = AccountID; @@ -134,7 +134,7 @@ protected: using base::value_; public: - explicit accountIDField(SF const& sfield, SV const& value) : JTxField(sfield, value) + explicit AccountIdField(SF const& sfield, SV const& value) : JTxField(sfield, value) { } @@ -145,7 +145,7 @@ public: } }; -struct stAmountField : public JTxField +struct StAmountField : public JTxField { using SF = SF_AMOUNT; using SV = STAmount; @@ -156,18 +156,18 @@ protected: using base::value_; public: - explicit stAmountField(SF const& sfield, SV const& value) : JTxField(sfield, value) + explicit StAmountField(SF const& sfield, SV const& value) : JTxField(sfield, value) { } [[nodiscard]] OV value() const override { - return value_.getJson(JsonOptions::none); + return value_.getJson(JsonOptions::None); } }; -struct blobField : public JTxField +struct BlobField : public JTxField { using SF = SF_VL; using SV = std::string; @@ -175,19 +175,19 @@ struct blobField : public JTxField using JTxField::JTxField; - explicit blobField(SF const& sfield, Slice const& cond) : JTxField(sfield, strHex(cond)) + explicit BlobField(SF const& sfield, Slice const& cond) : JTxField(sfield, strHex(cond)) { } template - explicit blobField(SF const& sfield, std::array const& c) - : blobField(sfield, makeSlice(c)) + explicit BlobField(SF const& sfield, std::array const& c) + : BlobField(sfield, makeSlice(c)) { } }; template -struct valueUnitField : public JTxField, ValueType> +struct ValueUnitField : public JTxField, ValueType> { using SF = SField; using SV = unit::ValueUnit; @@ -232,9 +232,9 @@ public: }; template <> -struct JTxFieldWrapper +struct JTxFieldWrapper { - using JF = blobField; + using JF = BlobField; using SF = JF::SF; using SV = JF::SV; @@ -267,16 +267,16 @@ public: }; template -using valueUnitWrapper = JTxFieldWrapper>; +using valueUnitWrapper = JTxFieldWrapper>; template using simpleField = JTxFieldWrapper>; /** General field definitions, or fields used in multiple transaction namespaces */ -auto const data = JTxFieldWrapper(sfData); +auto const kDATA = JTxFieldWrapper(sfData); -auto const amount = JTxFieldWrapper(sfAmount); +auto const kAMOUNT = JTxFieldWrapper(sfAmount); // TODO We only need this long "requires" clause as polyfill, for C++20 // implementations which are missing header. Replace with @@ -318,18 +318,18 @@ getAccountLines(Env& env, AccountID const& acctId, IOU... ious) { auto jrr = getAccountLines(env, acctId); Json::Value res; - for (auto const& line : jrr[jss::lines]) + for (auto const& line : jrr[jss::kLINES]) { for (auto const& iou : {ious...}) { - if (line[jss::currency].asString() == to_string(iou.currency)) + if (line[jss::kCURRENCY].asString() == to_string(iou.currency)) { Json::Value v; - v[jss::currency] = line[jss::currency]; - v[jss::balance] = line[jss::balance]; - v[jss::limit] = line[jss::limit]; + v[jss::kCURRENCY] = line[jss::kCURRENCY]; + v[jss::kBALANCE] = line[jss::kBALANCE]; + v[jss::kLIMIT] = line[jss::kLIMIT]; v[jss::account] = line[jss::account]; - res[jss::lines].append(v); + res[jss::kLINES].append(v); } } } @@ -389,7 +389,7 @@ template void stpathset_append(STPathSet& st, STPath const& p, Args const&... args) { - st.push_back(p); + st.pushBack(p); if constexpr (sizeof...(args) > 0) stpathset_append(st, args...); } @@ -439,9 +439,9 @@ rpf(jtx::Account const& src, std::optional const& srcIssuer = std::nullopt); jtx::Env -pathTestEnv(beast::unit_test::suite& suite); +pathTestEnv(beast::unit_test::Suite& suite); -class gate +class Gate { private: std::condition_variable cv_; @@ -453,10 +453,10 @@ public: // Returns `true` if signaled. template bool - wait_for(std::chrono::duration const& rel_time) + waitFor(std::chrono::duration const& relTime) { std::unique_lock lk(mutex_); - auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; }); + auto b = cv_.wait_for(lk, relTime, [this] { return signaled_; }); signaled_ = false; return b; } @@ -542,20 +542,16 @@ Json::Value ledgerEntryRoot(Env& env, Account const& acct); Json::Value -ledgerEntryState( - Env& env, - Account const& acct_a, - Account const& acct_b, - std::string const& currency); +ledgerEntryState(Env& env, Account const& acctA, Account const& acctB, std::string const& currency); Json::Value -ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offer_seq); +ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offerSeq); Json::Value ledgerEntryMPT(jtx::Env& env, jtx::Account const& acct, MPTID const& mptID); Json::Value -getBookOffers(jtx::Env& env, Asset const& taker_pays, Asset const& taker_gets); +getBookOffers(jtx::Env& env, Asset const& takerPays, Asset const& takerGets); Json::Value accountBalance(Env& env, Account const& acct); @@ -725,7 +721,7 @@ create(A const& account, A const& dest, STAmount const& sendMax) { Json::Value jv; jv[sfAccount.jsonName] = to_string(account); - jv[sfSendMax.jsonName] = sendMax.getJson(JsonOptions::none); + jv[sfSendMax.jsonName] = sendMax.getJson(JsonOptions::None); jv[sfDestination.jsonName] = to_string(dest); jv[sfTransactionType.jsonName] = jss::CheckCreate; return jv; @@ -739,8 +735,8 @@ create(jtx::Account const& account, jtx::Account const& dest, STAmount const& se } // namespace check -static constexpr FeeLevel64 baseFeeLevel{TxQ::baseLevel}; -static constexpr FeeLevel64 minEscalationFeeLevel = baseFeeLevel * 500; +static constexpr FeeLevel64 kBASE_FEE_LEVEL{TxQ::kBASE_LEVEL}; +static constexpr FeeLevel64 kMIN_ESCALATION_FEE_LEVEL = kBASE_FEE_LEVEL * 500; inline uint256 getCheckIndex(AccountID const& account, std::uint32_t uSequence) @@ -757,8 +753,8 @@ checkMetrics( std::optional expectedMaxCount, std::size_t expectedInLedger, std::size_t expectedPerLedger, - std::uint64_t expectedMinFeeLevel = baseFeeLevel.fee(), - std::uint64_t expectedMedFeeLevel = minEscalationFeeLevel.fee(), + std::uint64_t expectedMinFeeLevel = kBASE_FEE_LEVEL.fee(), + std::uint64_t expectedMedFeeLevel = kMIN_ESCALATION_FEE_LEVEL.fee(), std::source_location const location = std::source_location::current()) { int const line = location.line(); @@ -768,11 +764,11 @@ checkMetrics( auto const metrics = env.app().getTxQ().getMetrics(*env.current()); using namespace std::string_literals; - metrics.referenceFeeLevel == baseFeeLevel + metrics.referenceFeeLevel == kBASE_FEE_LEVEL ? test.pass() : test.fail( "reference: "s + std::to_string(metrics.referenceFeeLevel.value()) + "/" + - std::to_string(baseFeeLevel.value()), + std::to_string(kBASE_FEE_LEVEL.value()), file, line); @@ -867,18 +863,20 @@ coverWithdraw( Json::Value coverClawback(AccountID const& account, std::uint32_t flags = 0); -auto const loanBrokerID = JTxFieldWrapper(sfLoanBrokerID); +auto const kLOAN_BROKER_ID = JTxFieldWrapper(sfLoanBrokerID); -auto const managementFeeRate = valueUnitWrapper(sfManagementFeeRate); +auto const kMANAGEMENT_FEE_RATE = + valueUnitWrapper(sfManagementFeeRate); -auto const debtMaximum = simpleField(sfDebtMaximum); +auto const kDEBT_MAXIMUM = simpleField(sfDebtMaximum); -auto const coverRateMinimum = valueUnitWrapper(sfCoverRateMinimum); +auto const kCOVER_RATE_MINIMUM = + valueUnitWrapper(sfCoverRateMinimum); -auto const coverRateLiquidation = +auto const kCOVER_RATE_LIQUIDATION = valueUnitWrapper(sfCoverRateLiquidation); -auto const destination = JTxFieldWrapper(sfDestination); +auto const kDESTINATION = JTxFieldWrapper(sfDestination); } // namespace loanBroker @@ -892,34 +890,36 @@ set(AccountID const& account, Number principalRequested, std::uint32_t flags = 0); -auto const counterparty = JTxFieldWrapper(sfCounterparty); +auto const kCOUNTERPARTY = JTxFieldWrapper(sfCounterparty); // For `CounterPartySignature`, use `sig(sfCounterpartySignature, ...)` -auto const loanOriginationFee = simpleField(sfLoanOriginationFee); +auto const kLOAN_ORIGINATION_FEE = simpleField(sfLoanOriginationFee); -auto const loanServiceFee = simpleField(sfLoanServiceFee); +auto const kLOAN_SERVICE_FEE = simpleField(sfLoanServiceFee); -auto const latePaymentFee = simpleField(sfLatePaymentFee); +auto const kLATE_PAYMENT_FEE = simpleField(sfLatePaymentFee); -auto const closePaymentFee = simpleField(sfClosePaymentFee); +auto const kCLOSE_PAYMENT_FEE = simpleField(sfClosePaymentFee); -auto const overpaymentFee = valueUnitWrapper(sfOverpaymentFee); +auto const kOVERPAYMENT_FEE = valueUnitWrapper(sfOverpaymentFee); -auto const interestRate = valueUnitWrapper(sfInterestRate); +auto const kINTEREST_RATE = valueUnitWrapper(sfInterestRate); -auto const lateInterestRate = valueUnitWrapper(sfLateInterestRate); +auto const kLATE_INTEREST_RATE = + valueUnitWrapper(sfLateInterestRate); -auto const closeInterestRate = valueUnitWrapper(sfCloseInterestRate); +auto const kCLOSE_INTEREST_RATE = + valueUnitWrapper(sfCloseInterestRate); -auto const overpaymentInterestRate = +auto const kOVERPAYMENT_INTEREST_RATE = valueUnitWrapper(sfOverpaymentInterestRate); -auto const paymentTotal = simpleField(sfPaymentTotal); +auto const kPAYMENT_TOTAL = simpleField(sfPaymentTotal); -auto const paymentInterval = simpleField(sfPaymentInterval); +auto const kPAYMENT_INTERVAL = simpleField(sfPaymentInterval); -auto const gracePeriod = simpleField(sfGracePeriod); +auto const kGRACE_PERIOD = simpleField(sfGracePeriod); Json::Value manage(AccountID const& account, uint256 const& loanID, std::uint32_t flags); @@ -936,13 +936,13 @@ pay(AccountID const& account, } // namespace loan /** Set Expiration on a JTx. */ -class expiration +class Expiration { private: std::uint32_t const expiry_; public: - explicit expiration(NetClock::time_point const& expiry) + explicit Expiration(NetClock::time_point const& expiry) : expiry_{expiry.time_since_epoch().count()} { } @@ -955,13 +955,13 @@ public: }; /** Set SourceTag on a JTx. */ -class source_tag +class SourceTag { private: std::uint32_t const tag_; public: - explicit source_tag(std::uint32_t tag) : tag_{tag} + explicit SourceTag(std::uint32_t tag) : tag_{tag} { } @@ -973,13 +973,13 @@ public: }; /** Set DestinationTag on a JTx. */ -class dest_tag +class DestTag { private: std::uint32_t const tag_; public: - explicit dest_tag(std::uint32_t tag) : tag_{tag} + explicit DestTag(std::uint32_t tag) : tag_{tag} { } diff --git a/src/test/jtx/WSClient.h b/src/test/jtx/WSClient.h index e95920d085..01caf0a2a5 100644 --- a/src/test/jtx/WSClient.h +++ b/src/test/jtx/WSClient.h @@ -29,7 +29,7 @@ std::unique_ptr makeWSClient( Config const& cfg, bool v2 = true, - unsigned rpc_version = 2, + unsigned rpcVersion = 2, std::unordered_map const& headers = {}); } // namespace xrpl::test diff --git a/src/test/jtx/account_txn_id.h b/src/test/jtx/account_txn_id.h index 424ce13b14..89f7368ee6 100644 --- a/src/test/jtx/account_txn_id.h +++ b/src/test/jtx/account_txn_id.h @@ -4,13 +4,13 @@ namespace xrpl::test::jtx { -struct account_txn_id +struct AccountTxnId { private: uint256 hash_; public: - explicit account_txn_id(uint256 const& hash) : hash_(hash) + explicit AccountTxnId(uint256 const& hash) : hash_(hash) { } diff --git a/src/test/jtx/amount.h b/src/test/jtx/amount.h index 4e06392948..792cb2e24e 100644 --- a/src/test/jtx/amount.h +++ b/src/test/jtx/amount.h @@ -18,7 +18,7 @@ namespace xrpl { namespace detail { -struct epsilon_multiple +struct EpsilonMultiple { std::size_t n; }; @@ -55,7 +55,7 @@ struct None // This value is also defined in SystemParameters.h. It's // duplicated here to catch any possible future errors that // could change that value (however unlikely). -constexpr XRPAmount dropsPerXRP{1'000'000}; +constexpr XRPAmount kDROPS_PER_XRP{1'000'000}; /** Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports @@ -190,13 +190,13 @@ public: template PrettyAmount - operator()(T v, Number::rounding_mode rounding = Number::getround()) const + operator()(T v, Number::RoundingMode rounding = Number::getround()) const { return operator()(Number(v), rounding); } PrettyAmount - operator()(Number v, Number::rounding_mode rounding = Number::getround()) const + operator()(Number v, Number::RoundingMode rounding = Number::getround()) const { NumberRoundModeGuard const mg(rounding); STAmount const amount{asset_, v * scale_}; @@ -204,7 +204,7 @@ public: } None - operator()(none_t) const + operator()(NoneT) const { return {asset_}; } @@ -235,14 +235,14 @@ struct BookSpec { xrpl::Asset asset; - BookSpec(xrpl::Asset const& asset_) : asset(asset_) + BookSpec(xrpl::Asset const& asset) : asset(asset) { } }; //------------------------------------------------------------------------------ -struct XRP_t +struct XrpT { /** Implicit conversion to Issue. @@ -275,7 +275,7 @@ struct XRP_t operator()(T v) const { using TOut = std::conditional_t, std::int64_t, std::uint64_t>; - return {TOut{v} * dropsPerXRP}; + return {TOut{v} * kDROPS_PER_XRP}; } /** Returns an amount of XRP as PrettyAmount, @@ -286,7 +286,7 @@ struct XRP_t PrettyAmount operator()(Number v) const { - auto const c = dropsPerXRP.drops(); + auto const c = kDROPS_PER_XRP.drops(); auto const d = std::int64_t(v * c); if (Number(d) / c != v) Throw("unrepresentable"); @@ -296,7 +296,7 @@ struct XRP_t PrettyAmount operator()(double v) const { - auto const c = dropsPerXRP.drops(); + auto const c = kDROPS_PER_XRP.drops(); if (v >= 0) { auto const d = std::uint64_t(std::round(v * c)); @@ -313,13 +313,13 @@ struct XRP_t /** Returns None-of-XRP */ None - operator()(none_t) const + operator()(NoneT) const { return {xrpIssue()}; } friend BookSpec - operator~(XRP_t const&) + operator~(XrpT const&) { return BookSpec(Issue{xrpCurrency(), xrpAccount()}); } @@ -331,7 +331,7 @@ struct XRP_t XRP Converts to the XRP Issue XRP(10) Returns STAmount of 10 XRP */ -extern XRP_t const XRP; +extern XrpT const kXRP; /** Returns an XRP PrettyAmount, which is trivially convertible to STAmount. @@ -359,18 +359,18 @@ drops(XRPAmount i) //------------------------------------------------------------------------------ // The smallest possible IOU STAmount -struct epsilon_t +struct EpsilonT { - epsilon_t() = default; + EpsilonT() = default; - detail::epsilon_multiple + detail::EpsilonMultiple operator()(std::size_t n) const { return {n}; } }; -static epsilon_t const epsilon; +static EpsilonT const kEPSILON; /** Converts to IOU Issue or STAmount. @@ -385,8 +385,8 @@ public: Account account; xrpl::Currency currency; - IOU(Account account_, xrpl::Currency const& currency_) - : account(std::move(account_)), currency(currency_) + IOU(Account account, xrpl::Currency const& currency) + : account(std::move(account)), currency(currency) { } @@ -436,16 +436,16 @@ public: } PrettyAmount - operator()(epsilon_t) const; + operator()(EpsilonT) const; PrettyAmount - operator()(detail::epsilon_multiple) const; + operator()(detail::EpsilonMultiple) const; // VFALCO TODO // STAmount operator()(char const* s) const; /** Returns None-of-Issue */ None - operator()(none_t) const + operator()(NoneT) const { return {issue()}; } @@ -475,7 +475,7 @@ public: std::string name; xrpl::MPTID issuanceID; - MPT(std::string n, xrpl::MPTID const& issuanceID_) : name(std::move(n)), issuanceID(issuanceID_) + MPT(std::string n, xrpl::MPTID const& issuanceId) : name(std::move(n)), issuanceID(issuanceId) { } MPT(std::string n = "") : name(std::move(n)), issuanceID(noMPT()) @@ -544,13 +544,13 @@ public: } PrettyAmount - operator()(epsilon_t) const; + operator()(EpsilonT) const; PrettyAmount - operator()(detail::epsilon_multiple) const; + operator()(detail::EpsilonMultiple) const; /** Returns None-of-Issue */ None - operator()(none_t) const + operator()(NoneT) const { return {noMPT()}; } @@ -567,7 +567,7 @@ operator<<(std::ostream& os, MPT const& mpt); //------------------------------------------------------------------------------ -struct any_t +struct AnyT { inline AnyAmount operator()(STAmount const& sta) const; @@ -588,7 +588,7 @@ struct AnyAmount { } - AnyAmount(STAmount amount, any_t const*) : is_any(true), value(std::move(amount)) + AnyAmount(STAmount amount, AnyT const*) : is_any(true), value(std::move(amount)) { } @@ -603,7 +603,7 @@ struct AnyAmount }; inline AnyAmount -any_t::operator()(STAmount const& sta) const +AnyT::operator()(STAmount const& sta) const { return AnyAmount(sta, this); } @@ -611,7 +611,7 @@ any_t::operator()(STAmount const& sta) const /** Returns an amount representing "any issuer" @note With respect to what the recipient will accept */ -extern any_t const any; +extern AnyT const kANY; } // namespace test::jtx diff --git a/src/test/jtx/balance.h b/src/test/jtx/balance.h index a75583b1a3..861ca6a4af 100644 --- a/src/test/jtx/balance.h +++ b/src/test/jtx/balance.h @@ -15,7 +15,7 @@ namespace xrpl::test::jtx { exist even if the amount is 0, or else the test fails. */ -class balance +class Balance { private: bool const none_; @@ -23,16 +23,16 @@ private: STAmount const value_; public: - balance(Account account, none_t) : none_(true), account_(std::move(account)), value_(XRP) + Balance(Account account, NoneT) : none_(true), account_(std::move(account)), value_(kXRP) { } - balance(Account account, None const& value) + Balance(Account account, None const& value) : none_(true), account_(std::move(account)), value_(value.asset) { } - balance(Account account, STAmount value) + Balance(Account account, STAmount value) : none_(false), account_(std::move(account)), value_(std::move(value)) { } diff --git a/src/test/jtx/basic_prop.h b/src/test/jtx/basic_prop.h index 16e1d8cd6d..97177b280b 100644 --- a/src/test/jtx/basic_prop.h +++ b/src/test/jtx/basic_prop.h @@ -4,35 +4,35 @@ namespace xrpl::test::jtx { -struct basic_prop +struct BasicProp { - virtual ~basic_prop() = default; - [[nodiscard]] virtual std::unique_ptr + virtual ~BasicProp() = default; + [[nodiscard]] virtual std::unique_ptr clone() const = 0; virtual bool - assignable(basic_prop const*) const = 0; + assignable(BasicProp const*) const = 0; }; template -struct prop_type : basic_prop +struct PropType : BasicProp { T t; template - prop_type(Args&&... args) : t(std::forward(args)...) + PropType(Args&&... args) : t(std::forward(args)...) { } - [[nodiscard]] std::unique_ptr + [[nodiscard]] std::unique_ptr clone() const override { - return std::make_unique>(t); + return std::make_unique>(t); } bool - assignable(basic_prop const* src) const override + assignable(BasicProp const* src) const override { - return dynamic_cast const*>(src); + return dynamic_cast const*>(src); } }; diff --git a/src/test/jtx/batch.h b/src/test/jtx/batch.h index 846adc9adc..d1c14cccd6 100644 --- a/src/test/jtx/batch.h +++ b/src/test/jtx/batch.h @@ -26,7 +26,7 @@ Json::Value outer(jtx::Account const& account, uint32_t seq, STAmount const& fee, std::uint32_t flags); /** Adds a new Batch Txn on a JTx and autofills. */ -class inner +class Inner { private: Json::Value txn_; @@ -34,21 +34,21 @@ private: std::optional ticket_; public: - inner( + Inner( Json::Value txn, std::uint32_t const& sequence, std::optional const& ticket = std::nullopt) : txn_(std::move(txn)), seq_(sequence), ticket_(ticket) { - txn_[jss::SigningPubKey] = ""; - txn_[jss::Sequence] = seq_; - txn_[jss::Fee] = "0"; - txn_[jss::Flags] = txn_[jss::Flags].asUInt() | tfInnerBatchTxn; + txn_[jss::kSIGNING_PUB_KEY] = ""; + txn_[jss::kSEQUENCE] = seq_; + txn_[jss::kFEE] = "0"; + txn_[jss::kFLAGS] = txn_[jss::kFLAGS].asUInt() | kTF_INNER_BATCH_TXN; // Optionally set ticket sequence if (ticket_.has_value()) { - txn_[jss::Sequence] = 0; + txn_[jss::kSEQUENCE] = 0; txn_[sfTicketSequence.jsonName] = *ticket_; } } @@ -76,19 +76,19 @@ public: }; /** Set a batch signature on a JTx. */ -class sig +class Sig { public: std::vector signers; - sig(std::vector signers_) : signers(std::move(signers_)) + Sig(std::vector signers) : signers(std::move(signers)) { sortSigners(signers); } template requires std::convertible_to - explicit sig(AccountType&& a0, Accounts&&... aN) + explicit Sig(AccountType&& a0, Accounts&&... aN) : signers{std::forward(a0), std::forward(aN)...} { sortSigners(signers); @@ -99,21 +99,21 @@ public: }; /** Set a batch nested multi-signature on a JTx. */ -class msig +class Msig { public: Account master; std::vector signers; - msig(Account masterAccount, std::vector signers_) - : master(std::move(masterAccount)), signers(std::move(signers_)) + Msig(Account masterAccount, std::vector signers) + : master(std::move(masterAccount)), signers(std::move(signers)) { sortSigners(signers); } template requires std::convertible_to - explicit msig(Account masterAccount, AccountType&& a0, Accounts&&... aN) + explicit Msig(Account masterAccount, AccountType&& a0, Accounts&&... aN) : master(std::move(masterAccount)) , signers{std::forward(a0), std::forward(aN)...} { diff --git a/src/test/jtx/check.h b/src/test/jtx/check.h index fc1d8054c6..4137c482a6 100644 --- a/src/test/jtx/check.h +++ b/src/test/jtx/check.h @@ -35,6 +35,6 @@ cancel(jtx::Account const& dest, uint256 const& checkId); } // namespace check /** Match the number of checks on the account. */ -using checks = owner_count; +using checks = OwnerCount; } // namespace xrpl::test::jtx diff --git a/src/test/jtx/credentials.h b/src/test/jtx/credentials.h index fd6d31f56d..b1b87230ff 100644 --- a/src/test/jtx/credentials.h +++ b/src/test/jtx/credentials.h @@ -16,13 +16,13 @@ keylet( } // Sets the optional URI. -class uri +class Uri { private: std::string const uri_; public: - explicit uri(std::string_view u) : uri_(strHex(u)) + explicit Uri(std::string_view u) : uri_(strHex(u)) { } @@ -34,20 +34,20 @@ public: }; // Set credentialsIDs array -class ids +class Ids { private: std::vector const credentials_; public: - explicit ids(std::vector const& creds) : credentials_(creds) + explicit Ids(std::vector const& creds) : credentials_(creds) { } void operator()(jtx::Env&, jtx::JTx& jtx) const { - auto& arr(jtx.jv[sfCredentialIDs.jsonName] = Json::arrayValue); + auto& arr(jtx.jv[sfCredentialIDs.jsonName] = Json::ArrayValue); for (auto const& hash : credentials_) arr.append(hash); } diff --git a/src/test/jtx/delegate.h b/src/test/jtx/delegate.h index 197750a511..66c9de5867 100644 --- a/src/test/jtx/delegate.h +++ b/src/test/jtx/delegate.h @@ -15,13 +15,13 @@ set(jtx::Account const& account, Json::Value entry(jtx::Env& env, jtx::Account const& account, jtx::Account const& authorize); -struct as +struct As { private: jtx::Account delegate_; public: - explicit as(jtx::Account account) : delegate_(std::move(account)) + explicit As(jtx::Account account) : delegate_(std::move(account)) { } diff --git a/src/test/jtx/delivermin.h b/src/test/jtx/delivermin.h index 6dc0bea2ad..0a8fa9f823 100644 --- a/src/test/jtx/delivermin.h +++ b/src/test/jtx/delivermin.h @@ -9,13 +9,13 @@ namespace xrpl::test::jtx { /** Sets the DeliverMin on a JTx. */ -class deliver_min +class DeliverMin { private: STAmount amount_; public: - deliver_min(STAmount amount) : amount_(std::move(amount)) + DeliverMin(STAmount amount) : amount_(std::move(amount)) { } diff --git a/src/test/jtx/deposit.h b/src/test/jtx/deposit.h index 1d032bf1e0..f04b49b0f9 100644 --- a/src/test/jtx/deposit.h +++ b/src/test/jtx/deposit.h @@ -26,7 +26,7 @@ struct AuthorizeCredentials toJson() const { Json::Value jv; - jv[jss::Issuer] = issuer.human(); + jv[jss::kISSUER] = issuer.human(); jv[sfCredentialType.jsonName] = strHex(credType); return jv; } @@ -36,8 +36,8 @@ struct AuthorizeCredentials toLEJson() const { Json::Value jv; - jv[jss::issuer] = issuer.human(); - jv[jss::credential_type] = strHex(credType); + jv[jss::kISSUER] = issuer.human(); + jv[jss::kCREDENTIAL_TYPE] = strHex(credType); return jv; } }; diff --git a/src/test/jtx/did.h b/src/test/jtx/did.h index faf4b2046c..5905c8552f 100644 --- a/src/test/jtx/did.h +++ b/src/test/jtx/did.h @@ -14,13 +14,13 @@ Json::Value setValid(jtx::Account const& account); /** Sets the optional DIDDocument on a DIDSet. */ -class document +class Document { private: std::string document_; public: - explicit document(std::string const& u) : document_(strHex(u)) + explicit Document(std::string const& u) : document_(strHex(u)) { } @@ -32,13 +32,13 @@ public: }; /** Sets the optional URI on a DIDSet. */ -class uri +class Uri { private: std::string uri_; public: - explicit uri(std::string const& u) : uri_(strHex(u)) + explicit Uri(std::string const& u) : uri_(strHex(u)) { } @@ -50,13 +50,13 @@ public: }; /** Sets the optional Data on a DIDSet. */ -class data +class Data { private: std::string data_; public: - explicit data(std::string const& u) : data_(strHex(u)) + explicit Data(std::string const& u) : data_(strHex(u)) { } diff --git a/src/test/jtx/directory.h b/src/test/jtx/directory.h index 08d8fef73e..5f277d6c91 100644 --- a/src/test/jtx/directory.h +++ b/src/test/jtx/directory.h @@ -48,7 +48,7 @@ maximumPageIndex(Env const& env) -> std::uint64_t { if (env.enabled(fixDirectoryLimit)) return std::numeric_limits::max(); - return dirNodeMaxPages - 1; + return kDIR_NODE_MAX_PAGES - 1; } } // namespace xrpl::test::jtx::directory diff --git a/src/test/jtx/domain.h b/src/test/jtx/domain.h index 993c89ee19..b3a0744768 100644 --- a/src/test/jtx/domain.h +++ b/src/test/jtx/domain.h @@ -5,13 +5,13 @@ namespace xrpl::test::jtx { /** Set the domain on a JTx. */ -class domain +class Domain { private: uint256 v_; public: - explicit domain(uint256 const& v) : v_(v) + explicit Domain(uint256 const& v) : v_(v) { } diff --git a/src/test/jtx/envconfig.h b/src/test/jtx/envconfig.h index dcfafc426e..a2d012a44e 100644 --- a/src/test/jtx/envconfig.h +++ b/src/test/jtx/envconfig.h @@ -9,12 +9,12 @@ namespace xrpl::test { #define PORT_RPC "port_rpc" #define PORT_PEER "port_peer" -extern std::atomic envUseIPv4; +extern std::atomic gEnvUseIPv4; inline char const* getEnvLocalhostAddr() { - return envUseIPv4 ? "127.0.0.1" : "::1"; + return gEnvUseIPv4 ? "127.0.0.1" : "::1"; } /// @brief initializes a config object for use with jtx::Env diff --git a/src/test/jtx/escrow.h b/src/test/jtx/escrow.h index 8bb505a592..54fbd78775 100644 --- a/src/test/jtx/escrow.h +++ b/src/test/jtx/escrow.h @@ -42,37 +42,37 @@ Rate rate(Env& env, Account const& account, std::uint32_t const& seq); // A PreimageSha256 fulfillments and its associated condition. -std::array const fb1 = {{0xA0, 0x02, 0x80, 0x00}}; +std::array const kFB1 = {{0xA0, 0x02, 0x80, 0x00}}; -std::array const cb1 = { +std::array const kCB1 = { {0xA0, 0x25, 0x80, 0x20, 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24, 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55, 0x81, 0x01, 0x00}}; // Another PreimageSha256 fulfillments and its associated condition. -std::array const fb2 = {{0xA0, 0x05, 0x80, 0x03, 0x61, 0x61, 0x61}}; +std::array const kFB2 = {{0xA0, 0x05, 0x80, 0x03, 0x61, 0x61, 0x61}}; -std::array const cb2 = { +std::array const kCB2 = { {0xA0, 0x25, 0x80, 0x20, 0x98, 0x34, 0x87, 0x6D, 0xCF, 0xB0, 0x5C, 0xB1, 0x67, 0xA5, 0xC2, 0x49, 0x53, 0xEB, 0xA5, 0x8C, 0x4A, 0xC8, 0x9B, 0x1A, 0xDF, 0x57, 0xF2, 0x8F, 0x2F, 0x9D, 0x09, 0xAF, 0x10, 0x7E, 0xE8, 0xF0, 0x81, 0x01, 0x03}}; // Another PreimageSha256 fulfillment and its associated condition. -std::array const fb3 = {{0xA0, 0x06, 0x80, 0x04, 0x6E, 0x69, 0x6B, 0x62}}; +std::array const kFB3 = {{0xA0, 0x06, 0x80, 0x04, 0x6E, 0x69, 0x6B, 0x62}}; -std::array const cb3 = { +std::array const kCB3 = { {0xA0, 0x25, 0x80, 0x20, 0x6E, 0x4C, 0x71, 0x45, 0x30, 0xC0, 0xA4, 0x26, 0x8B, 0x3F, 0xA6, 0x3B, 0x1B, 0x60, 0x6F, 0x2D, 0x26, 0x4A, 0x2D, 0x85, 0x7B, 0xE8, 0xA0, 0x9C, 0x1D, 0xFD, 0x57, 0x0D, 0x15, 0x85, 0x8B, 0xD4, 0x81, 0x01, 0x04}}; /** Set the "FinishAfter" time tag on a JTx */ -auto const finish_time = JTxFieldWrapper(sfFinishAfter); +auto const kFINISH_TIME = JTxFieldWrapper(sfFinishAfter); /** Set the "CancelAfter" time tag on a JTx */ -auto const cancel_time = JTxFieldWrapper(sfCancelAfter); +auto const kCANCEL_TIME = JTxFieldWrapper(sfCancelAfter); -auto const condition = JTxFieldWrapper(sfCondition); +auto const kCONDITION = JTxFieldWrapper(sfCondition); -auto const fulfillment = JTxFieldWrapper(sfFulfillment); +auto const kFULFILLMENT = JTxFieldWrapper(sfFulfillment); } // namespace xrpl::test::jtx::escrow diff --git a/src/test/jtx/fee.h b/src/test/jtx/fee.h index f586e2a082..048b262e88 100644 --- a/src/test/jtx/fee.h +++ b/src/test/jtx/fee.h @@ -11,7 +11,7 @@ namespace xrpl::test::jtx { /** Set the fee on a JTx. */ -class fee +class Fee { private: bool manual_ = true; @@ -19,25 +19,25 @@ private: std::optional amount_; public: - explicit fee(autofill_t) : manual_(false) + explicit Fee(AutofillT) : manual_(false) { } - explicit fee(increment_t) : increment_(true) + explicit Fee(IncrementT) : increment_(true) { } - explicit fee(none_t) + explicit Fee(NoneT) { } - explicit fee(STAmount const& amount) : amount_(amount) + explicit Fee(STAmount const& amount) : amount_(amount) { if (!isXRP(*amount_)) Throw("fee: not XRP"); } - explicit fee(std::uint64_t amount, bool negative = false) : fee{STAmount{amount, negative}} + explicit Fee(std::uint64_t amount, bool negative = false) : Fee{STAmount{amount, negative}} { } diff --git a/src/test/jtx/flags.h b/src/test/jtx/flags.h index 4bf095e685..0cc5b9e6fc 100644 --- a/src/test/jtx/flags.h +++ b/src/test/jtx/flags.h @@ -11,59 +11,59 @@ namespace xrpl { namespace detail { -class flags_helper +class FlagsHelper { protected: std::uint32_t mask_{0}; private: void - set_args(std::uint32_t flag) + setArgs(std::uint32_t flag) { switch (flag) { - case asfRequireDest: - mask_ |= lsfRequireDestTag; + case kASF_REQUIRE_DEST: + mask_ |= LsfRequireDestTag; break; - case asfRequireAuth: - mask_ |= lsfRequireAuth; + case kASF_REQUIRE_AUTH: + mask_ |= LsfRequireAuth; break; - case asfDisallowXRP: - mask_ |= lsfDisallowXRP; + case kASF_DISALLOW_XRP: + mask_ |= LsfDisallowXrp; break; - case asfDisableMaster: - mask_ |= lsfDisableMaster; + case kASF_DISABLE_MASTER: + mask_ |= LsfDisableMaster; break; // case asfAccountTxnID: // ??? - case asfNoFreeze: - mask_ |= lsfNoFreeze; + case kASF_NO_FREEZE: + mask_ |= LsfNoFreeze; break; - case asfGlobalFreeze: - mask_ |= lsfGlobalFreeze; + case kASF_GLOBAL_FREEZE: + mask_ |= LsfGlobalFreeze; break; - case asfDefaultRipple: - mask_ |= lsfDefaultRipple; + case kASF_DEFAULT_RIPPLE: + mask_ |= LsfDefaultRipple; break; - case asfDepositAuth: - mask_ |= lsfDepositAuth; + case kASF_DEPOSIT_AUTH: + mask_ |= LsfDepositAuth; break; - case asfAllowTrustLineClawback: - mask_ |= lsfAllowTrustLineClawback; + case kASF_ALLOW_TRUST_LINE_CLAWBACK: + mask_ |= LsfAllowTrustLineClawback; break; - case asfDisallowIncomingCheck: - mask_ |= lsfDisallowIncomingCheck; + case kASF_DISALLOW_INCOMING_CHECK: + mask_ |= LsfDisallowIncomingCheck; break; - case asfDisallowIncomingNFTokenOffer: - mask_ |= lsfDisallowIncomingNFTokenOffer; + case kASF_DISALLOW_INCOMING_NF_TOKEN_OFFER: + mask_ |= LsfDisallowIncomingNfTokenOffer; break; - case asfDisallowIncomingPayChan: - mask_ |= lsfDisallowIncomingPayChan; + case kASF_DISALLOW_INCOMING_PAY_CHAN: + mask_ |= LsfDisallowIncomingPayChan; break; - case asfDisallowIncomingTrustline: - mask_ |= lsfDisallowIncomingTrustline; + case kASF_DISALLOW_INCOMING_TRUSTLINE: + mask_ |= LsfDisallowIncomingTrustline; break; - case asfAllowTrustLineLocking: - mask_ |= lsfAllowTrustLineLocking; + case kASF_ALLOW_TRUST_LINE_LOCKING: + mask_ |= LsfAllowTrustLineLocking; break; default: Throw("unknown flag"); @@ -72,16 +72,16 @@ private: template void - set_args(std::uint32_t flag, Args... args) + setArgs(std::uint32_t flag, Args... args) { - set_args(flag); + setArgs(flag); if constexpr (sizeof...(args)) set_args(args...); } protected: template - flags_helper(Args... args) + FlagsHelper(Args... args) { set_args(args...); } @@ -105,14 +105,14 @@ fclear(Account const& account, std::uint32_t off) } /** Match set account flags */ -class flags : private xrpl::detail::flags_helper +class Flags : private xrpl::detail::FlagsHelper { private: Account account_; public: template - flags(Account account, Args... args) : flags_helper(args...), account_(std::move(account)) + Flags(Account account, Args... args) : FlagsHelper(args...), account_(std::move(account)) { } @@ -121,14 +121,14 @@ public: }; /** Match clear account flags */ -class nflags : private xrpl::detail::flags_helper +class Nflags : private xrpl::detail::FlagsHelper { private: Account account_; public: template - nflags(Account account, Args... args) : flags_helper(args...), account_(std::move(account)) + Nflags(Account account, Args... args) : FlagsHelper(args...), account_(std::move(account)) { } diff --git a/src/test/jtx/invoice_id.h b/src/test/jtx/invoice_id.h index 9366cc9bf5..2246d54abf 100644 --- a/src/test/jtx/invoice_id.h +++ b/src/test/jtx/invoice_id.h @@ -4,13 +4,13 @@ namespace xrpl::test::jtx { -struct invoice_id +struct InvoiceId { private: uint256 hash_; public: - explicit invoice_id(uint256 const& hash) : hash_(hash) + explicit InvoiceId(uint256 const& hash) : hash_(hash) { } diff --git a/src/test/jtx/jtx_json.h b/src/test/jtx/jtx_json.h index 0bd7c2ff94..b6d41b53f4 100644 --- a/src/test/jtx/jtx_json.h +++ b/src/test/jtx/jtx_json.h @@ -7,26 +7,26 @@ namespace xrpl::test::jtx { /** Inject raw JSON. */ -class json +class Json { private: Json::Value jv_; public: - explicit json(std::string const&); + explicit Json(std::string const&); - explicit json(char const*); + explicit Json(char const*); - explicit json(Json::Value); + explicit Json(Json::Value); template - json(Json::StaticString const& key, T const& value) + Json(Json::StaticString const& key, T const& value) { jv_[key] = value; } template - json(std::string const& key, T const& value) + Json(std::string const& key, T const& value) { jv_[key] = value; } diff --git a/src/test/jtx/last_ledger_sequence.h b/src/test/jtx/last_ledger_sequence.h index 9015c87f02..6170c2e4e1 100644 --- a/src/test/jtx/last_ledger_sequence.h +++ b/src/test/jtx/last_ledger_sequence.h @@ -4,13 +4,13 @@ namespace xrpl::test::jtx { -struct last_ledger_seq +struct LastLedgerSeq { private: std::uint32_t num_; public: - explicit last_ledger_seq(std::uint32_t num) : num_(num) + explicit LastLedgerSeq(std::uint32_t num) : num_(num) { } diff --git a/src/test/jtx/memo.h b/src/test/jtx/memo.h index 8cb41b3f1c..9b5c1118ac 100644 --- a/src/test/jtx/memo.h +++ b/src/test/jtx/memo.h @@ -11,7 +11,7 @@ namespace xrpl::test::jtx { If a memo already exists, the new memo is appended to the array. */ -class memo +class Memo { private: std::string data_; @@ -19,7 +19,7 @@ private: std::string type_; public: - memo(std::string data, std::string format, std::string type) + Memo(std::string data, std::string format, std::string type) : data_(std::move(data)), format_(std::move(format)), type_(std::move(type)) { } @@ -28,13 +28,13 @@ public: operator()(Env&, JTx& jt) const; }; -class memo_data +class MemoData { private: std::string s_; public: - memo_data(std::string s) : s_(std::move(s)) + MemoData(std::string s) : s_(std::move(s)) { } @@ -42,13 +42,13 @@ public: operator()(Env&, JTx& jt) const; }; -class memo_format +class MemoFormat { private: std::string s_; public: - memo_format(std::string s) : s_(std::move(s)) + MemoFormat(std::string s) : s_(std::move(s)) { } @@ -56,13 +56,13 @@ public: operator()(Env&, JTx& jt) const; }; -class memo_type +class MemoType { private: std::string s_; public: - memo_type(std::string s) : s_(std::move(s)) + MemoType(std::string s) : s_(std::move(s)) { } diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index 77597d795d..44ec3d1720 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -13,10 +13,10 @@ namespace xrpl::test::jtx { class MPTTester; -auto const MPTDEXFlags = tfMPTCanTrade | tfMPTCanTransfer; +auto const kMPTDEX_FLAGS = kTF_MPT_CAN_TRADE | kTF_MPT_CAN_TRANSFER; // Check flags settings on MPT create -class mptflags +class Mptflags { private: MPTTester& tester_; @@ -24,7 +24,7 @@ private: std::optional holder_; public: - mptflags( + Mptflags( MPTTester& tester, std::uint32_t flags, std::optional const& holder = std::nullopt) @@ -37,7 +37,7 @@ public: }; // Check mptissuance or mptoken amount balances on payment -class mptbalance +class Mptbalance { private: MPTTester const& tester_; @@ -45,7 +45,7 @@ private: std::int64_t const amount_; public: - mptbalance(MPTTester& tester, Account const& account, std::int64_t amount) + Mptbalance(MPTTester& tester, Account const& account, std::int64_t amount) : tester_(tester), account_(account), amount_(amount) { } @@ -54,13 +54,13 @@ public: operator()(Env& env) const; }; -class requireAny +class RequireAny { private: std::function cb_; public: - requireAny(std::function const& cb) : cb_(cb) + RequireAny(std::function const& cb) : cb_(cb) { } @@ -72,7 +72,7 @@ using Holders = std::vector; struct MPTCreate { - static inline std::vector AllHolders = {}; + static inline std::vector allHolders = {}; std::optional issuer = std::nullopt; std::optional maxAmt = std::nullopt; std::optional assetScale = std::nullopt; @@ -96,14 +96,14 @@ struct MPTCreate struct MPTInit { Holders holders = {}; // NOLINT(readability-redundant-member-init) - PrettyAmount const xrp = XRP(10'000); - PrettyAmount const xrpHolders = XRP(10'000); + PrettyAmount const xrp = kXRP(10'000); + PrettyAmount const xrpHolders = kXRP(10'000); bool fund = true; bool close = true; // create MPTIssuanceID if seated and follow rules for MPTCreate args std::optional create = std::nullopt; }; -static MPTInit const mptInitNoFund{.fund = false}; +static MPTInit const kMPT_INIT_NO_FUND{.fund = false}; struct MPTInitDef { @@ -112,7 +112,7 @@ struct MPTInitDef Holders holders = {}; // NOLINT(readability-redundant-member-init) std::uint16_t transferFee = 0; std::optional pay = std::nullopt; - std::uint32_t flags = MPTDEXFlags; + std::uint32_t flags = kMPTDEX_FLAGS; std::optional mutableFlags = std::nullopt; bool authHolder = false; bool fund = false; @@ -290,16 +290,16 @@ private: TER submit(A const& arg, Json::Value const& jv) { - env_(jv, txflags(arg.flags.value_or(0)), ter(arg.err.value_or(tesSUCCESS))); + env_(jv, Txflags(arg.flags.value_or(0)), Ter(arg.err.value_or(TesSuccess))); auto const err = env_.ter(); if (close_) env_.close(); if (arg.ownerCount) - env_.require(owners(issuer_, *arg.ownerCount)); + env_.require(Owners(issuer_, *arg.ownerCount)); if (arg.holderCount) { for (auto const& it : holders_) - env_.require(owners(it.second, *arg.holderCount)); + env_.require(Owners(it.second, *arg.holderCount)); } return err; } diff --git a/src/test/jtx/multisign.h b/src/test/jtx/multisign.h index 5b6a18b527..4d1eac9b28 100644 --- a/src/test/jtx/multisign.h +++ b/src/test/jtx/multisign.h @@ -13,29 +13,29 @@ namespace xrpl::test::jtx { /** A signer in a SignerList */ -struct signer +struct Signer { std::uint32_t weight; Account account; std::optional tag; - signer(Account account_, std::uint32_t weight_ = 1, std::optional tag_ = std::nullopt) - : weight(weight_), account(std::move(account_)), tag(tag_) + Signer(Account account, std::uint32_t weight = 1, std::optional tag = std::nullopt) + : weight(weight), account(std::move(account)), tag(tag) { } }; Json::Value -signers(Account const& account, std::uint32_t quorum, std::vector const& v); +signers(Account const& account, std::uint32_t quorum, std::vector const& v); /** Remove a signer list. */ Json::Value -signers(Account const& account, none_t); +signers(Account const& account, NoneT); //------------------------------------------------------------------------------ /** Set a multisignature on a JTx. */ -class msig +class Msig { public: std::vector signers; @@ -46,45 +46,45 @@ public: SField const* const subField = nullptr; /// Used solely as a convenience placeholder for ctors that do _not_ specify /// a subfield. - static constexpr SField* const topLevel = nullptr; + static constexpr SField* const kTOP_LEVEL = nullptr; - msig(SField const* subField_, std::vector signers_) - : signers(std::move(signers_)), subField(subField_) + Msig(SField const* subField, std::vector signers) + : signers(std::move(signers)), subField(subField) { sortSigners(signers); } - msig(SField const& subField_, std::vector signers_) : msig{&subField_, signers_} + Msig(SField const& subField, std::vector signers) : Msig{&subField, signers} { } - msig(std::vector signers_) : msig(topLevel, signers_) + Msig(std::vector signers) : Msig(kTOP_LEVEL, signers) { } template requires std::convertible_to - explicit msig(SField const* subField_, AccountType&& a0, Accounts&&... aN) - : msig{ - subField_, + explicit Msig(SField const* subField, AccountType&& a0, Accounts&&... aN) + : Msig{ + subField, std::vector{std::forward(a0), std::forward(aN)...}} { } template requires std::convertible_to - explicit msig(SField const& subField_, AccountType&& a0, Accounts&&... aN) - : msig{ - &subField_, + explicit Msig(SField const& subField, AccountType&& a0, Accounts&&... aN) + : Msig{ + &subField, std::vector{std::forward(a0), std::forward(aN)...}} { } template requires(std::convertible_to && !std::is_same_v) - explicit msig(AccountType&& a0, Accounts&&... aN) - : msig{ - topLevel, + explicit Msig(AccountType&& a0, Accounts&&... aN) + : Msig{ + kTOP_LEVEL, std::vector{std::forward(a0), std::forward(aN)...}} { } @@ -96,6 +96,6 @@ public: //------------------------------------------------------------------------------ /** The number of signer lists matches. */ -using siglists = owner_count; +using siglists = OwnerCount; } // namespace xrpl::test::jtx diff --git a/src/test/jtx/owners.h b/src/test/jtx/owners.h index 572b63757c..0f46ad9ff8 100644 --- a/src/test/jtx/owners.h +++ b/src/test/jtx/owners.h @@ -29,14 +29,14 @@ namespace test::jtx { // Helper for aliases template -class owner_count +class OwnerCount { private: Account account_; std::uint32_t value_; public: - owner_count(Account account, std::uint32_t value) : account_(std::move(account)), value_(value) + OwnerCount(Account account, std::uint32_t value) : account_(std::move(account)), value_(value) { } @@ -48,14 +48,14 @@ public: }; /** Match the number of items in the account's owner directory */ -class owners +class Owners { private: Account account_; std::uint32_t value_; public: - owners(Account account, std::uint32_t value) : account_(std::move(account)), value_(value) + Owners(Account account, std::uint32_t value) : account_(std::move(account)), value_(value) { } @@ -64,13 +64,13 @@ public: }; /** Match the number of trust lines in the account's owner directory */ -using lines = owner_count; +using lines = OwnerCount; /** Match the number of offers in the account's owner directory */ -using offers = owner_count; +using offers = OwnerCount; /** Match the number of MPToken in the account's owner directory */ -using mptokens = owner_count; +using mptokens = OwnerCount; } // namespace test::jtx diff --git a/src/test/jtx/paths.h b/src/test/jtx/paths.h index f63faa6292..a5d6f425d4 100644 --- a/src/test/jtx/paths.h +++ b/src/test/jtx/paths.h @@ -12,7 +12,7 @@ class STPath; namespace test::jtx { /** Set Paths, SendMax on a JTx. */ -class paths +class Paths { private: Asset in_; @@ -20,7 +20,7 @@ private: unsigned int limit_; public: - paths(Asset const& in, int depth = 7, unsigned int limit = 4) + Paths(Asset const& in, int depth = 7, unsigned int limit = 4) : in_(in), depth_(depth), limit_(limit) { } @@ -35,18 +35,18 @@ public: If no paths are present, a new one is created. */ -class path +class Path { private: Json::Value jv_; public: - path(); + Path(); template - explicit path(T const& t, Args const&... args); + explicit Path(T const& t, Args const&... args); - path(STPath const& p); + Path(STPath const& p); void operator()(Env&, JTx& jt) const; @@ -56,23 +56,23 @@ private: create(); void - append_one(Account const& account); + appendOne(Account const& account); void - append_one(AccountID const& account); + appendOne(AccountID const& account); template std::enable_if_t> - append_one(T const& t) + appendOne(T const& t) { - append_one(Account{t}); + appendOne(Account{t}); } void - append_one(IOU const& iou); + appendOne(IOU const& iou); void - append_one(BookSpec const& book); + appendOne(BookSpec const& book); template void @@ -80,16 +80,16 @@ private: }; template -path::path(T const& t, Args const&... args) : jv_(Json::arrayValue) +Path::Path(T const& t, Args const&... args) : jv_(Json::ArrayValue) { append(t, args...); } template void -path::append(T const& t, Args const&... args) +Path::append(T const& t, Args const&... args) { - append_one(t); + appendOne(t); if constexpr (sizeof...(args) > 0) append(args...); } diff --git a/src/test/jtx/prop.h b/src/test/jtx/prop.h index 5651ac58ce..29224eae25 100644 --- a/src/test/jtx/prop.h +++ b/src/test/jtx/prop.h @@ -8,19 +8,19 @@ namespace xrpl::test::jtx { /** Set a property on a JTx. */ template -struct prop +struct Prop { - std::unique_ptr p_; + std::unique_ptr p; template - prop(Args&&... args) : p_(std::make_unique>(std::forward(args)...)) + Prop(Args&&... args) : p(std::make_unique>(std::forward(args)...)) { } void operator()(Env& env, JTx& jt) const { - jt.set(p_->clone()); + jt.set(p->clone()); } }; diff --git a/src/test/jtx/quality.h b/src/test/jtx/quality.h index adb198038a..75bf930434 100644 --- a/src/test/jtx/quality.h +++ b/src/test/jtx/quality.h @@ -5,13 +5,13 @@ namespace xrpl::test::jtx { /** Sets the literal QualityIn on a trust JTx. */ -class qualityIn +class QualityIn { private: std::uint32_t qIn_; public: - explicit qualityIn(std::uint32_t qIn) : qIn_(qIn) + explicit QualityIn(std::uint32_t qIn) : qIn_(qIn) { } @@ -20,26 +20,26 @@ public: }; /** Sets the QualityIn on a trust JTx. */ -class qualityInPercent +class QualityInPercent { private: std::uint32_t qIn_; // NOLINT(cppcoreguidelines-use-default-member-init) public: - explicit qualityInPercent(double percent); + explicit QualityInPercent(double percent); void operator()(Env&, JTx& jtx) const; }; /** Sets the literal QualityOut on a trust JTx. */ -class qualityOut +class QualityOut { private: std::uint32_t qOut_; public: - explicit qualityOut(std::uint32_t qOut) : qOut_(qOut) + explicit QualityOut(std::uint32_t qOut) : qOut_(qOut) { } @@ -48,13 +48,13 @@ public: }; /** Sets the QualityOut on a trust JTx as a percentage. */ -class qualityOutPercent +class QualityOutPercent { private: std::uint32_t qOut_; // NOLINT(cppcoreguidelines-use-default-member-init) public: - explicit qualityOutPercent(double percent); + explicit QualityOutPercent(double percent); void operator()(Env&, JTx& jtx) const; diff --git a/src/test/jtx/regkey.h b/src/test/jtx/regkey.h index 3da055c66f..7906c94693 100644 --- a/src/test/jtx/regkey.h +++ b/src/test/jtx/regkey.h @@ -9,7 +9,7 @@ namespace xrpl::test::jtx { /** Disable the regular key. */ Json::Value -regkey(Account const& account, disabled_t); +regkey(Account const& account, DisabledT); /** Set a regular key. */ Json::Value diff --git a/src/test/jtx/require.h b/src/test/jtx/require.h index 20f79ff838..b4f06d5961 100644 --- a/src/test/jtx/require.h +++ b/src/test/jtx/require.h @@ -41,14 +41,14 @@ required(Args const&... args) applied, and only if the resulting TER matches the expected TER. */ -class require +class Require { private: require_t cond_; public: template - require(Args const&... args) : cond_(required(args...)) + Require(Args const&... args) : cond_(required(args...)) { } diff --git a/src/test/jtx/rpc.h b/src/test/jtx/rpc.h index be7ab8d456..dde0c143bf 100644 --- a/src/test/jtx/rpc.h +++ b/src/test/jtx/rpc.h @@ -10,23 +10,23 @@ namespace xrpl::test::jtx { /** Set the expected result code for a JTx The test will fail if the code doesn't match. */ -class rpc +class Rpc { private: - std::optional code_; + std::optional code_; std::optional errorMessage_; std::optional error_; std::optional errorException_; public: /// If there's an error code, we expect an error message - explicit rpc(error_code_i code, std::optional m = {}) + explicit Rpc(ErrorCodeI code, std::optional m = {}) : code_(code), errorMessage_(std::move(m)) { } /// If there is not a code, we expect an exception message - explicit rpc(std::string error, std::optional exceptionMessage = {}) + explicit Rpc(std::string error, std::optional exceptionMessage = {}) : error_(error), errorException_(std::move(exceptionMessage)) { } @@ -35,7 +35,7 @@ public: operator()(Env&, JTx& jt) const { // The RPC request should fail. RPC errors result in telENV_RPC_FAILED. - jt.ter = telENV_RPC_FAILED; + jt.ter = TelEnvRpcFailed; if (code_) { auto const& errorInfo = RPC::get_error_info(*code_); @@ -47,8 +47,8 @@ public: // Take advantage of that fact to populate jt.rpcException. The // check will be aware of whether the rpcException can be safely // ignored. - jt.rpcCode = {*code_, errorMessage_ ? *errorMessage_ : errorInfo.message.c_str()}; - jt.rpcException = {errorInfo.token.c_str(), std::nullopt}; + jt.rpcCode = {*code_, errorMessage_ ? *errorMessage_ : errorInfo.message.cStr()}; + jt.rpcException = {errorInfo.token.cStr(), std::nullopt}; } if (error_) jt.rpcException = {*error_, errorException_}; diff --git a/src/test/jtx/sendmax.h b/src/test/jtx/sendmax.h index e559a87641..125b10b7d4 100644 --- a/src/test/jtx/sendmax.h +++ b/src/test/jtx/sendmax.h @@ -9,13 +9,13 @@ namespace xrpl::test::jtx { /** Sets the SendMax on a JTx. */ -class sendmax +class Sendmax { private: STAmount amount_; public: - sendmax(STAmount amount) : amount_(std::move(amount)) + Sendmax(STAmount amount) : amount_(std::move(amount)) { } diff --git a/src/test/jtx/seq.h b/src/test/jtx/seq.h index ea5ccfa259..de06ac3fbc 100644 --- a/src/test/jtx/seq.h +++ b/src/test/jtx/seq.h @@ -8,22 +8,22 @@ namespace xrpl::test::jtx { /** Set the sequence number on a JTx. */ -struct seq +struct Seq { private: bool manual_ = true; std::optional num_; public: - explicit seq(autofill_t) : manual_(false) + explicit Seq(AutofillT) : manual_(false) { } - explicit seq(none_t) + explicit Seq(NoneT) { } - explicit seq(std::uint32_t num) : num_(num) + explicit Seq(std::uint32_t num) : num_(num) { } diff --git a/src/test/jtx/sig.h b/src/test/jtx/sig.h index e23022b4b5..e5e58e52ab 100644 --- a/src/test/jtx/sig.h +++ b/src/test/jtx/sig.h @@ -9,7 +9,7 @@ namespace xrpl::test::jtx { /** Set the regular signature on a JTx. @note For multisign, use msig. */ -class sig +class Sig { private: bool manual_ = true; @@ -26,27 +26,27 @@ private: std::optional account_; /// Used solely as a convenience placeholder for ctors that do _not_ specify /// a subfield. - static constexpr SField* const topLevel = nullptr; + static constexpr SField* const kTOP_LEVEL = nullptr; public: - explicit sig(autofill_t) : manual_(false) + explicit Sig(AutofillT) : manual_(false) { } - explicit sig(none_t) + explicit Sig(NoneT) { } - explicit sig(SField const* subField, Account const& account) + explicit Sig(SField const* subField, Account const& account) : subField_(subField), account_(account) { } - explicit sig(SField const& subField, Account const& account) : sig(&subField, account) + explicit Sig(SField const& subField, Account const& account) : Sig(&subField, account) { } - explicit sig(Account const& account) : sig(topLevel, account) + explicit Sig(Account const& account) : Sig(kTOP_LEVEL, account) { } diff --git a/src/test/jtx/tag.h b/src/test/jtx/tag.h index c11dff2550..9279e2a13b 100644 --- a/src/test/jtx/tag.h +++ b/src/test/jtx/tag.h @@ -5,13 +5,13 @@ namespace xrpl::test::jtx { /** Set the destination tag on a JTx*/ -struct dtag +struct Dtag { private: std::uint32_t value_; public: - explicit dtag(std::uint32_t value) : value_(value) + explicit Dtag(std::uint32_t value) : value_(value) { } @@ -20,13 +20,13 @@ public: }; /** Set the source tag on a JTx*/ -struct stag +struct Stag { private: std::uint32_t value_; public: - explicit stag(std::uint32_t value) : value_(value) + explicit Stag(std::uint32_t value) : value_(value) { } diff --git a/src/test/jtx/tags.h b/src/test/jtx/tags.h index 9c7a21145d..2dbdd4f663 100644 --- a/src/test/jtx/tags.h +++ b/src/test/jtx/tags.h @@ -2,30 +2,30 @@ namespace xrpl::test::jtx { -struct none_t +struct NoneT { - none_t() = default; + NoneT() = default; }; -static none_t const none; +static NoneT const kNONE; -struct autofill_t +struct AutofillT { - autofill_t() = default; + AutofillT() = default; }; -static autofill_t const autofill; +static AutofillT const kAUTOFILL; -struct disabled_t +struct DisabledT { - disabled_t() = default; + DisabledT() = default; }; -static disabled_t const disabled; +static DisabledT const kDISABLED; /** Used for fee() calls that use an owner reserve increment */ -struct increment_t +struct IncrementT { - increment_t() = default; + IncrementT() = default; }; -static increment_t const increment; +static IncrementT const kINCREMENT; } // namespace xrpl::test::jtx diff --git a/src/test/jtx/ter.h b/src/test/jtx/ter.h index ab21bc8e2b..c410b46a1e 100644 --- a/src/test/jtx/ter.h +++ b/src/test/jtx/ter.h @@ -9,17 +9,17 @@ namespace xrpl::test::jtx { /** Set the expected result code for a JTx The test will fail if the code doesn't match. */ -class ter +class Ter { private: std::optional v_; public: - explicit ter(decltype(std::ignore)) + explicit Ter(decltype(std::ignore)) { } - explicit ter(TER v) : v_(v) + explicit Ter(TER v) : v_(v) { } diff --git a/src/test/jtx/ticket.h b/src/test/jtx/ticket.h index 7ab3b9c1f9..d7a74aa256 100644 --- a/src/test/jtx/ticket.h +++ b/src/test/jtx/ticket.h @@ -22,13 +22,13 @@ Json::Value create(Account const& account, std::uint32_t count); /** Set a ticket sequence on a JTx. */ -class use +class Use { private: std::uint32_t ticketSeq_; public: - use(std::uint32_t ticketSeq) : ticketSeq_{ticketSeq} + Use(std::uint32_t ticketSeq) : ticketSeq_{ticketSeq} { } @@ -39,6 +39,6 @@ public: } // namespace ticket /** Match the number of tickets on the account. */ -using tickets = owner_count; +using tickets = OwnerCount; } // namespace xrpl::test::jtx diff --git a/src/test/jtx/token.h b/src/test/jtx/token.h index 28ccd7520b..dcf3171202 100644 --- a/src/test/jtx/token.h +++ b/src/test/jtx/token.h @@ -15,13 +15,13 @@ Json::Value mint(jtx::Account const& account, std::uint32_t tokenTaxon = 0); /** Sets the optional TransferFee on an NFTokenMint. */ -class xferFee +class XferFee { private: std::uint16_t xferFee_; public: - explicit xferFee(std::uint16_t fee) : xferFee_(fee) + explicit XferFee(std::uint16_t fee) : xferFee_(fee) { } @@ -30,13 +30,13 @@ public: }; /** Sets the optional Issuer on an NFTokenMint. */ -class issuer +class Issuer { private: std::string issuer_; public: - explicit issuer(jtx::Account const& issue) : issuer_(issue.human()) + explicit Issuer(jtx::Account const& issue) : issuer_(issue.human()) { } @@ -45,13 +45,13 @@ public: }; /** Sets the optional URI on an NFTokenMint. */ -class uri +class Uri { private: std::string uri_; public: - explicit uri(std::string const& u) : uri_(strHex(u)) + explicit Uri(std::string const& u) : uri_(strHex(u)) { } @@ -60,13 +60,13 @@ public: }; /** Sets the optional amount field on an NFTokenMint. */ -class amount +class Amount { private: STAmount const amount_; public: - explicit amount(STAmount const amount) : amount_(amount) + explicit Amount(STAmount const amount) : amount_(amount) { } @@ -102,13 +102,13 @@ Json::Value createOffer(jtx::Account const& account, uint256 const& nftokenID, STAmount const& amount); /** Sets the optional Owner on an NFTokenOffer. */ -class owner +class Owner { private: std::string owner_; public: - explicit owner(jtx::Account const& ownedBy) : owner_(ownedBy.human()) + explicit Owner(jtx::Account const& ownedBy) : owner_(ownedBy.human()) { } @@ -117,13 +117,13 @@ public: }; /** Sets the optional Expiration field on an NFTokenOffer. */ -class expiration +class Expiration { private: std::uint32_t expires_; public: - explicit expiration(std::uint32_t const& expires) : expires_(expires) + explicit Expiration(std::uint32_t const& expires) : expires_(expires) { } @@ -132,13 +132,13 @@ public: }; /** Sets the optional Destination field on an NFTokenOffer. */ -class destination +class Destination { private: std::string dest_; public: - explicit destination(jtx::Account const& dest) : dest_(dest.human()) + explicit Destination(jtx::Account const& dest) : dest_(dest.human()) { } @@ -154,13 +154,13 @@ Json::Value cancelOffer(jtx::Account const& account, std::vector const& nftokenOffers); /** Sets the optional RootIndex field when canceling NFTokenOffers. */ -class rootIndex +class RootIndex { private: std::string rootIndex_; public: - explicit rootIndex(uint256 const& index) : rootIndex_(to_string(index)) + explicit RootIndex(uint256 const& index) : rootIndex_(to_string(index)) { } @@ -184,13 +184,13 @@ brokerOffers( uint256 const& sellOfferIndex); /** Sets the optional NFTokenBrokerFee field in a brokerOffer transaction. */ -class brokerFee +class BrokerFee { private: STAmount const brokerFee_; public: - explicit brokerFee(STAmount const fee) : brokerFee_(fee) + explicit BrokerFee(STAmount const fee) : brokerFee_(fee) { } diff --git a/src/test/jtx/txflags.h b/src/test/jtx/txflags.h index 838f7f5f30..975038d26a 100644 --- a/src/test/jtx/txflags.h +++ b/src/test/jtx/txflags.h @@ -5,13 +5,13 @@ namespace xrpl::test::jtx { /** Set the flags on a JTx. */ -class txflags +class Txflags { private: std::uint32_t v_; public: - explicit txflags(std::uint32_t v) : v_(v) + explicit Txflags(std::uint32_t v) : v_(v) { } diff --git a/src/test/jtx/utility.h b/src/test/jtx/utility.h index b00f5b433e..780a28c45b 100644 --- a/src/test/jtx/utility.h +++ b/src/test/jtx/utility.h @@ -11,10 +11,10 @@ namespace xrpl::test::jtx { /** Thrown when parse fails. */ -struct parse_error : std::logic_error +struct ParseError : std::logic_error { template - explicit parse_error(String const& s) : logic_error(s) + explicit ParseError(String const& s) : logic_error(s) { } }; diff --git a/src/test/unit_test/SuiteJournal.h b/src/test/unit_test/SuiteJournal.h index b0b3807dd3..32b085ffe6 100644 --- a/src/test/unit_test/SuiteJournal.h +++ b/src/test/unit_test/SuiteJournal.h @@ -9,13 +9,13 @@ namespace xrpl::test { class SuiteJournalSink : public beast::Journal::Sink { std::string partition_; - beast::unit_test::suite& suite_; + beast::unit_test::Suite& suite_; public: SuiteJournalSink( std::string const& partition, beast::severities::Severity threshold, - beast::unit_test::suite& suite) + beast::unit_test::Suite& suite) : Sink(threshold, false), partition_(partition + " "), suite_(suite) { } @@ -50,26 +50,26 @@ SuiteJournalSink::writeAlways(beast::severities::Severity level, std::string con char const* const s = [level]() { switch (level) { - case kTrace: + case KTrace: return "TRC:"; - case kDebug: + case KDebug: return "DBG:"; - case kInfo: + case KInfo: return "INF:"; - case kWarning: + case KWarning: return "WRN:"; - case kError: + case KError: return "ERR:"; default: break; - case kFatal: + case KFatal: break; } return "FTL:"; }(); - static std::mutex log_mutex; - std::scoped_lock const lock(log_mutex); + static std::mutex kLOG_MUTEX; + std::scoped_lock const lock(kLOG_MUTEX); suite_.log << s << partition_ << text << std::endl; } @@ -81,8 +81,8 @@ class SuiteJournal public: SuiteJournal( std::string const& partition, - beast::unit_test::suite& suite, - beast::severities::Severity threshold = beast::severities::kFatal) + beast::unit_test::Suite& suite, + beast::severities::Severity threshold = beast::severities::KFatal) : sink_(partition, threshold, suite), journal_(sink_) { } @@ -100,7 +100,7 @@ class StreamSink : public beast::Journal::Sink std::stringstream strm_; public: - StreamSink(beast::severities::Severity threshold = beast::severities::kDebug) + StreamSink(beast::severities::Severity threshold = beast::severities::KDebug) : Sink(threshold, false) { } diff --git a/src/xrpld/app/ledger/OpenLedger.h b/src/xrpld/app/ledger/OpenLedger.h index d55c9c97e3..884b6b02db 100644 --- a/src/xrpld/app/ledger/OpenLedger.h +++ b/src/xrpld/app/ledger/OpenLedger.h @@ -169,13 +169,13 @@ private: ApplyFlags flags, beast::Journal j); - enum class Result { success, failure, retry }; + enum class Result { Success, Failure, Retry }; std::shared_ptr create(Rules const& rules, std::shared_ptr const& ledger); static Result - apply_one( + applyOne( Application& app, OpenView& view, std::shared_ptr const& tx, @@ -206,8 +206,8 @@ OpenLedger::apply( auto const txId = tx->getTransactionID(); if (check.txExists(txId)) continue; - auto const result = apply_one(app, view, tx, true, flags, j); - if (result == Result::retry) + auto const result = applyOne(app, view, tx, true, flags, j); + if (result == Result::Retry) retries.insert(tx); } catch (std::exception const& e) @@ -222,15 +222,15 @@ OpenLedger::apply( auto iter = retries.begin(); while (iter != retries.end()) { - switch (apply_one(app, view, iter->second, retry, flags, j)) + switch (applyOne(app, view, iter->second, retry, flags, j)) { - case Result::success: + case Result::Success: ++changes; [[fallthrough]]; - case Result::failure: + case Result::Failure: iter = retries.erase(iter); break; - case Result::retry: + case Result::Retry: ++iter; } } diff --git a/src/xrpld/app/misc/TxQ.h b/src/xrpld/app/misc/TxQ.h index c3dddd12ba..2cae69d38f 100644 --- a/src/xrpld/app/misc/TxQ.h +++ b/src/xrpld/app/misc/TxQ.h @@ -40,7 +40,7 @@ class TxQ { public: /// Fee level for single-signed reference transaction. - static constexpr FeeLevel64 baseLevel{256}; + static constexpr FeeLevel64 kBASE_LEVEL{256}; /** Structure used to customize @ref TxQ behavior. @@ -76,7 +76,7 @@ public: std::uint32_t retrySequencePercent = 25; /// Minimum value of the escalation multiplier, regardless /// of the prior ledger's median fee level. - FeeLevel64 minimumEscalationMultiplier = baseLevel * 500; + FeeLevel64 minimumEscalationMultiplier = kBASE_LEVEL * 500; /// Minimum number of transactions to allow into the ledger /// before escalation, regardless of the prior ledger's size. std::uint32_t minimumTxnInLedger = 32; @@ -174,24 +174,24 @@ public: { /// Full initialization TxDetails( - FeeLevel64 feeLevel_, - std::optional const& lastValid_, - TxConsequences const& consequences_, - AccountID const& account_, - SeqProxy seqProxy_, - std::shared_ptr const& txn_, - int retriesRemaining_, - TER preflightResult_, - std::optional lastResult_) - : feeLevel(feeLevel_) - , lastValid(lastValid_) - , consequences(consequences_) - , account(account_) - , seqProxy(seqProxy_) - , txn(txn_) - , retriesRemaining(retriesRemaining_) - , preflightResult(preflightResult_) - , lastResult(lastResult_) + FeeLevel64 feeLevel, + std::optional const& lastValid, + TxConsequences const& consequences, + AccountID const& account, + SeqProxy seqProxy, + std::shared_ptr const& txn, + int retriesRemaining, + TER preflightResult, + std::optional lastResult) + : feeLevel(feeLevel) + , lastValid(lastValid) + , consequences(consequences) + , account(account) + , seqProxy(seqProxy) + , txn(txn) + , retriesRemaining(retriesRemaining) + , preflightResult(preflightResult) + , lastResult(lastResult) { } @@ -512,7 +512,7 @@ private: their `retriesRemaining` forced down as part of the penalty. */ - int retriesRemaining{retriesAllowed}; + int retriesRemaining{kRETRIES_ALLOWED}; /// Flags provided to `apply`. If the transaction is later /// attempted with different flags, it will need to be /// `preflight`ed again. @@ -548,7 +548,7 @@ private: that the queue doesn't fill up with stale transactions which prevent lower fee level transactions from queuing. */ - static constexpr int retriesAllowed = 10; + static constexpr int kRETRIES_ALLOWED = 10; /** The hash of the parent ledger. @@ -761,7 +761,7 @@ private: /** parentHash_ used for logging only */ - LedgerHash parentHash_{beast::zero}; + LedgerHash parentHash_{beast::kZERO}; /** Most queue operations are done under the master lock, but use this mutex for the RPC "fee" command, which isn't. @@ -770,7 +770,7 @@ private: private: /// Is the queue at least `fillPercentage` full? - template + template bool isFull() const; @@ -831,13 +831,13 @@ template XRPAmount toDrops(FeeLevel const& level, XRPAmount baseFee) { - return mulDiv(level, baseFee, TxQ::baseLevel).value_or(XRPAmount(STAmount::cMaxNativeN)); + return mulDiv(level, baseFee, TxQ::kBASE_LEVEL).value_or(XRPAmount(STAmount::kC_MAX_NATIVE_N)); } inline FeeLevel64 toFeeLevel(XRPAmount const& drops, XRPAmount const& baseFee) { - return mulDiv(drops, TxQ::baseLevel, baseFee) + return mulDiv(drops, TxQ::kBASE_LEVEL, baseFee) .value_or(FeeLevel64(std::numeric_limits::max())); } diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index ffa16e050f..1f7e53b148 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -75,7 +75,7 @@ getFeeLevelPaid(ReadView const& view, STTx const& tx) return FeeLevel64(0); } - return mulDiv(effectiveFeePaid, TxQ::baseLevel, baseFee) + return mulDiv(effectiveFeePaid, TxQ::kBASE_LEVEL, baseFee) .value_or(FeeLevel64(std::numeric_limits::max())); } @@ -91,7 +91,7 @@ static FeeLevel64 increase(FeeLevel64 level, std::uint32_t increasePercent) { return mulDiv(level, 100 + increasePercent, 100) - .value_or(static_cast(xrpl::muldiv_max)); + .value_or(static_cast(xrpl::kMULDIV_MAX)); } ////////////////////////////////////////////////////////////////////////// @@ -128,15 +128,15 @@ TxQ::FeeMetrics::update( // upperLimit must be >= minimumTxnCount_ or std::clamp can give // unexpected results auto const upperLimit = std::max( - mulDiv(txnsExpected_, cutPct, 100).value_or(xrpl::muldiv_max), minimumTxnCount_); + mulDiv(txnsExpected_, cutPct, 100).value_or(xrpl::kMULDIV_MAX), minimumTxnCount_); txnsExpected_ = std::clamp( - mulDiv(size, cutPct, 100).value_or(xrpl::muldiv_max), minimumTxnCount_, upperLimit); + mulDiv(size, cutPct, 100).value_or(xrpl::kMULDIV_MAX), minimumTxnCount_, upperLimit); recentTxnCounts_.clear(); } else if (size > txnsExpected_ || size > targetTxnCount_) { recentTxnCounts_.push_back(mulDiv(size, 100 + setup.normalConsensusIncreasePercent, 100) - .value_or(xrpl::muldiv_max)); + .value_or(xrpl::kMULDIV_MAX)); auto const iter = std::ranges::max_element(recentTxnCounts_); BOOST_ASSERT(iter != recentTxnCounts_.end()); auto const next = [&] { @@ -192,10 +192,10 @@ TxQ::FeeMetrics::scaleFeeLevel(Snapshot const& snapshot, OpenView const& view) // Compute escalated fee level // Don't care about the overflow flag return mulDiv(multiplier, current * current, target * target) - .value_or(static_cast(xrpl::muldiv_max)); + .value_or(static_cast(xrpl::kMULDIV_MAX)); } - return baseLevel; + return kBASE_LEVEL; } namespace detail { @@ -282,19 +282,19 @@ TxQ::FeeMetrics::escalatedSeriesFeeLevel( LedgerHash TxQ::MaybeTx::parentHashComp{}; TxQ::MaybeTx::MaybeTx( - std::shared_ptr const& txn_, - TxID const& txID_, - FeeLevel64 feeLevel_, - ApplyFlags const flags_, - PreflightResult const& pfResult_) - : txn(txn_) - , feeLevel(feeLevel_) - , txID(txID_) - , account(txn_->getAccountID(sfAccount)) - , lastValid(getLastLedgerSequence(*txn_)) - , seqProxy(txn_->getSeqProxy()) - , flags(flags_) - , pfResult(pfResult_) + std::shared_ptr const& txn, + TxID const& txId, + FeeLevel64 feeLevel, + ApplyFlags const flags, + PreflightResult const& pfResult) + : txn(txn) + , feeLevel(feeLevel) + , txID(txId) + , account(txn->getAccountID(sfAccount)) + , lastValid(getLastLedgerSequence(*txn)) + , seqProxy(txn->getSeqProxy()) + , flags(flags) + , pfResult(pfResult) { } @@ -325,7 +325,7 @@ TxQ::TxQAccount::TxQAccount(std::shared_ptr const& txn) { } -TxQ::TxQAccount::TxQAccount(AccountID const& account_) : account(account_) +TxQ::TxQAccount::TxQAccount(AccountID const& account) : account(account) { } @@ -371,12 +371,12 @@ TxQ::~TxQ() byFee_.clear(); } -template +template bool TxQ::isFull() const { - static_assert(fillPercentage > 0 && fillPercentage <= 100, "Invalid fill percentage"); - return maxSize_ && byFee_.size() >= (*maxSize_ * fillPercentage / 100); + static_assert(FillPercentage > 0 && FillPercentage <= 100, "Invalid fill percentage"); + return maxSize_ && byFee_.size() >= (*maxSize_ * FillPercentage / 100); } TER @@ -394,8 +394,8 @@ TxQ::canBeHeld( // queue yet, but should be added in the future. // tapFAIL_HARD transactions are never held if (tx.isFieldPresent(sfPreviousTxnID) || tx.isFieldPresent(sfAccountTxnID) || - ((flags & tapFAIL_HARD) != 0u)) - return telCAN_NOT_QUEUE; + ((flags & TapFailHard) != 0u)) + return TelCanNotQueue; { // To be queued and relayed, the transaction needs to @@ -403,21 +403,21 @@ TxQ::canBeHeld( // a realistic chance of getting into a ledger. auto const lastValid = getLastLedgerSequence(tx); if (lastValid && *lastValid < view.header().seq + setup_.minimumLastLedgerBuffer) - return telCAN_NOT_QUEUE; + return TelCanNotQueue; } // Allow if the account is not in the queue at all. if (accountIter == byAccount_.end()) - return tesSUCCESS; + return TesSuccess; // Allow this tx to replace another one. if (replacementIter) - return tesSUCCESS; + return TesSuccess; // Allow if there are fewer than the limit. TxQAccount const& txQAcct = accountIter->second; if (txQAcct.getTxnCount() < setup_.maximumTxnPerAccount) - return tesSUCCESS; + return TesSuccess; // If we get here the queue limit is exceeded. Only allow if this // transaction fills the _first_ sequence hole for the account. @@ -426,7 +426,7 @@ TxQ::canBeHeld( { // Tickets always follow sequence-based transactions, so a ticket // cannot unblock a sequence-based transaction. - return telCAN_NOT_QUEUE_FULL; + return TelCanNotQueueFull; } // This is the next queuable sequence-based SeqProxy for the account. @@ -434,7 +434,7 @@ TxQ::canBeHeld( if (txSeqProx != nextQueuable) { // The provided transaction does not fill the next open sequence gap. - return telCAN_NOT_QUEUE_FULL; + return TelCanNotQueueFull; } // Make sure they are not just topping off the account's queued @@ -444,10 +444,10 @@ TxQ::canBeHeld( { // There is a next transaction and it is sequence based. They are // filling a real gap. Allow it. - return tesSUCCESS; + return TesSuccess; } - return telCAN_NOT_QUEUE_FULL; + return TelCanNotQueueFull; } auto @@ -541,7 +541,7 @@ TxQ::tryClearAccountQueueUpThruTx( // unlikely), then there's no way we can confidently verify if the queue // can be cleared. if (!requiredTotalFeeLevel.first) - return {telINSUF_FEE_P, false}; + return {TelInsufFeeP, false}; auto const totalFeeLevelPaid = std::accumulate( beginTxIter, endTxIter, feeLevelPaid, [](auto const& total, auto const& txn) { @@ -550,7 +550,7 @@ TxQ::tryClearAccountQueueUpThruTx( // This transaction did not pay enough, so fall back to the normal process. if (totalFeeLevelPaid < requiredTotalFeeLevel.second) - return {telINSUF_FEE_P, false}; + return {TelInsufFeeP, false}; // This transaction paid enough to clear out the queue. // Attempt to apply the queued transactions. @@ -580,7 +580,7 @@ TxQ::tryClearAccountQueueUpThruTx( // transactions in the account queue. Then, if clearing the account // is successful, we will have removed any ticketed transactions // that can never succeed. - if (txResult.ter == tefNO_TICKET) + if (txResult.ter == TefNoTicket) continue; if (!txResult.applied) @@ -751,23 +751,23 @@ TxQ::apply( Keylet const accountKey{keylet::account(account)}; auto const sleAccount = view.read(accountKey); if (!sleAccount) - return {terNO_ACCOUNT, false}; + return {TerNoAccount, false}; // If the transaction needs a Ticket is that Ticket in the ledger? SeqProxy const acctSeqProx = SeqProxy::sequence((*sleAccount)[sfSequence]); SeqProxy const txSeqProx = tx->getSeqProxy(); - if (txSeqProx.isTicket() && !view.exists(keylet::ticket(account, txSeqProx))) + if (txSeqProx.isTicket() && !view.exists(keylet::kTICKET(account, txSeqProx))) { if (txSeqProx.value() < acctSeqProx.value()) { // The ticket number is low enough that it should already be // in the ledger if it were ever going to exist. - return {tefNO_TICKET, false}; + return {TefNoTicket, false}; } // We don't queue transactions that use Tickets unless // we can find the Ticket in the ledger. - return {terPRE_TICKET, false}; + return {TerPreTicket, false}; } std::scoped_lock const lock(mutex_); @@ -786,8 +786,8 @@ TxQ::apply( // to individually check each queued ticket against the ledger. struct TxIter { - TxIter(TxQAccount::TxMap::iterator first_, TxQAccount::TxMap::iterator end_) - : first(first_), end(end_) + TxIter(TxQAccount::TxMap::iterator first, TxQAccount::TxMap::iterator end) + : first(first), end(end) { } @@ -829,7 +829,7 @@ TxQ::apply( // the account's queue. JLOG(j_.trace()) << "Rejecting blocker transaction " << transactionID << ". Account has other queued transactions."; - return {telCAN_NOT_QUEUE_BLOCKS, false}; + return {TelCanNotQueueBlocks, false}; } // NOLINTNEXTLINE(bugprone-unchecked-optional-access) acctTxCount == 1 implies txIter is set if (acctTxCount == 1 && (txSeqProx != txIter->first->first)) @@ -837,7 +837,7 @@ TxQ::apply( // The blocker is not replacing the lone queued transaction. JLOG(j_.trace()) << "Rejecting blocker transaction " << transactionID << ". Blocker does not replace lone queued transaction."; - return {telCAN_NOT_QUEUE_BLOCKS, false}; + return {TelCanNotQueueBlocks, false}; } } @@ -876,7 +876,7 @@ TxQ::apply( (txIter->first->first != txSeqProx)) // NOLINTEND(bugprone-unchecked-optional-access) { - return {telCAN_NOT_QUEUE_BLOCKED, false}; + return {TelCanNotQueueBlocked, false}; } // Is there a transaction for the same account with the same @@ -908,7 +908,7 @@ TxQ::apply( // Drop the current transaction JLOG(j_.trace()) << "Ignoring transaction " << transactionID << " in favor of queued " << existingIter->second.txID; - return {telCAN_NOT_QUEUE_FEE, false}; + return {TelCanNotQueueFee, false}; } } } @@ -933,9 +933,9 @@ TxQ::apply( if (txSeqProx.isSeq()) { if (acctSeqProx > txSeqProx) - return {tefPAST_SEQ, false}; + return {TefPastSeq, false}; if (acctSeqProx < txSeqProx) - return {terPRE_SEQ, false}; + return {TerPreSeq, false}; } } else @@ -946,7 +946,7 @@ TxQ::apply( TxQAccount const& txQAcct = accountIter->second; if (acctSeqProx > txSeqProx) - return {tefPAST_SEQ, false}; + return {TefPastSeq, false}; // Determine if we need a multiTxn object. Assuming the account // is in the queue, there are two situations where we need to @@ -1000,11 +1000,11 @@ TxQ::apply( { if (txSeqProx < acctSeqProx) { - return {tefPAST_SEQ, false}; + return {TefPastSeq, false}; } if (txSeqProx > acctSeqProx) { - return {terPRE_SEQ, false}; + return {TerPreSeq, false}; } } } @@ -1016,14 +1016,14 @@ TxQ::apply( // transaction fits in proper sequence order with the // previous transaction or is a ticket. if (txSeqProx.isSeq() && nextQueuableSeqImpl(sleAccount, lock) != txSeqProx) - return {telCAN_NOT_QUEUE, false}; + return {TelCanNotQueue, false}; } // Sum fees and spending for all of the queued transactions // so we know how much to remove from the account balance // for the trial preclaim. - XRPAmount potentialSpend = beast::zero; - XRPAmount totalFee = beast::zero; + XRPAmount potentialSpend = beast::kZERO; + XRPAmount totalFee = beast::kZERO; for (auto iter = txIter->first; iter != txIter->end; ++iter) { // If we're replacing this transaction don't include @@ -1099,7 +1099,7 @@ TxQ::apply( // Drop the current transaction JLOG(j_.trace()) << "Ignoring transaction " << transactionID << ". Total fees in flight too high."; - return {telCAN_NOT_QUEUE_BALANCE, false}; + return {TelCanNotQueueBalance, false}; } // Create the test view from the current view. @@ -1107,7 +1107,7 @@ TxQ::apply( auto const sleBump = multiTxn->applyView.peek(accountKey); if (!sleBump) - return {tefINTERNAL, false}; + return {TefInternal, false}; // Subtract the fees and XRP spend from all of the other // transactions in the queue. That prevents a transaction @@ -1146,7 +1146,7 @@ TxQ::apply( return {pcresult.ter, false}; // Too low of a fee should get caught by preclaim - XRPL_ASSERT(feeLevelPaid >= baseLevel, "xrpl::TxQ::apply : minimum fee"); + XRPL_ASSERT(feeLevelPaid >= kBASE_LEVEL, "xrpl::TxQ::apply : minimum fee"); JLOG(j_.trace()) << "Transaction " << transactionID << " from account " << account << " has fee level of " << feeLevelPaid << " needs at least " @@ -1171,10 +1171,10 @@ TxQ::apply( conditions change, but don't waste the effort to clear). */ if (txSeqProx.isSeq() && txIter && multiTxn.has_value() && - txIter->first->second.retriesRemaining == MaybeTx::retriesAllowed && - feeLevelPaid > requiredFeeLevel && requiredFeeLevel > baseLevel) + txIter->first->second.retriesRemaining == MaybeTx::kRETRIES_ALLOWED && + feeLevelPaid > requiredFeeLevel && requiredFeeLevel > kBASE_LEVEL) { - OpenView sandbox(open_ledger, &view, view.rules()); + OpenView sandbox(kOPEN_LEDGER, &view, view.rules()); auto result = tryClearAccountQueueUpThruTx( app, @@ -1231,7 +1231,7 @@ TxQ::apply( JLOG(j_.info()) << "Queue is full, and transaction " << transactionID << " would kick a transaction from the same account (" << account << ") out of the queue."; - return {telCAN_NOT_QUEUE_FULL, false}; + return {TelCanNotQueueFull, false}; } auto const& endAccount = byAccount_.at(lastRIter->account); auto endEffectiveFeeLevel = [&]() { @@ -1241,7 +1241,7 @@ TxQ::apply( if (lastRIter->feeLevel > feeLevelPaid || endAccount.transactions.size() == 1) return lastRIter->feeLevel; - constexpr FeeLevel64 max{std::numeric_limits::max()}; + constexpr FeeLevel64 kMAX{std::numeric_limits::max()}; auto endTotal = std::accumulate( endAccount.transactions.begin(), endAccount.transactions.end(), @@ -1250,8 +1250,8 @@ TxQ::apply( // Check for overflow. auto next = txn.second.feeLevel / endAccount.transactions.size(); auto mod = txn.second.feeLevel % endAccount.transactions.size(); - if (total.first >= max - next || total.second >= max - mod) - return {max, FeeLevel64{0}}; + if (total.first >= kMAX - next || total.second >= kMAX - mod) + return {kMAX, FeeLevel64{0}}; return {total.first + next, total.second + mod}; }); @@ -1274,7 +1274,7 @@ TxQ::apply( { JLOG(j_.info()) << "Queue is full, and transaction " << transactionID << " fee is lower than end item's account average fee"; - return {telCAN_NOT_QUEUE_FULL, false}; + return {TelCanNotQueueFull, false}; } } @@ -1297,7 +1297,7 @@ TxQ::apply( // will not be checked again, so the cost should be minimal. // Don't allow soft failures, which can lead to retries - flags &= ~tapRETRY; + flags &= ~TapRetry; auto& candidate = accountIter->second.add({tx, transactionID, feeLevelPaid, flags, pfResult}); @@ -1309,7 +1309,7 @@ TxQ::apply( << " to queue." << " Flags: " << flags; - return {terQUEUED, false}; + return {TerQueued, false}; } /* @@ -1425,7 +1425,7 @@ TxQ::accept(Application& app, OpenView& view) candidateIter++; continue; } - auto const requiredFeeLevel = getRequiredFeeLevel(view, tapNONE, metricsSnapshot, lock); + auto const requiredFeeLevel = getRequiredFeeLevel(view, TapNone, metricsSnapshot, lock); auto const feeLevelPaid = candidateIter->feeLevel; JLOG(j_.trace()) << "Queued transaction " << candidateIter->txID << " from account " << candidateIter->account << " has fee level of " << feeLevelPaid @@ -1742,8 +1742,9 @@ TxQ::getMetrics(OpenView const& view) const result.txQMaxSize = maxSize_; result.txInLedger = view.txCount(); result.txPerLedger = snapshot.txnsExpected; - result.referenceFeeLevel = baseLevel; - result.minProcessingFeeLevel = isFull() ? byFee_.rbegin()->feeLevel + FeeLevel64{1} : baseLevel; + result.referenceFeeLevel = kBASE_LEVEL; + result.minProcessingFeeLevel = + isFull() ? byFee_.rbegin()->feeLevel + FeeLevel64{1} : kBASE_LEVEL; result.medFeeLevel = snapshot.escalationMultiplier; result.openLedgerFeeLevel = FeeMetrics::scaleFeeLevel(snapshot, view); @@ -1766,7 +1767,7 @@ TxQ::getTxRequiredFeeAndSeq(OpenView const& view, std::shared_ptr co std::uint32_t const accountSeq = sle ? (*sle)[sfSequence] : 0; std::uint32_t const availableSeq = nextQueuableSeqImpl(sle, lock).value(); return { - .fee = mulDiv(fee, baseFee, baseLevel) + .fee = mulDiv(fee, baseFee, kBASE_LEVEL) .value_or(XRPAmount(std::numeric_limits::max())), .accountSeq = accountSeq, .availableSeq = availableSeq}; @@ -1819,21 +1820,21 @@ TxQ::doRPC(Application& app) const auto const metrics = getMetrics(*view); - Json::Value ret(Json::objectValue); + Json::Value ret(Json::ObjectValue); - auto& levels = ret[jss::levels] = Json::objectValue; + auto& levels = ret[jss::kLEVELS] = Json::ObjectValue; - ret[jss::ledger_current_index] = view->header().seq; - ret[jss::expected_ledger_size] = std::to_string(metrics.txPerLedger); - ret[jss::current_ledger_size] = std::to_string(metrics.txInLedger); - ret[jss::current_queue_size] = std::to_string(metrics.txCount); + ret[jss::kLEDGER_CURRENT_INDEX] = view->header().seq; + ret[jss::kEXPECTED_LEDGER_SIZE] = std::to_string(metrics.txPerLedger); + ret[jss::kCURRENT_LEDGER_SIZE] = std::to_string(metrics.txInLedger); + ret[jss::kCURRENT_QUEUE_SIZE] = std::to_string(metrics.txCount); if (metrics.txQMaxSize) - ret[jss::max_queue_size] = std::to_string(*metrics.txQMaxSize); + ret[jss::kMAX_QUEUE_SIZE] = std::to_string(*metrics.txQMaxSize); - levels[jss::reference_level] = to_string(metrics.referenceFeeLevel); - levels[jss::minimum_level] = to_string(metrics.minProcessingFeeLevel); - levels[jss::median_level] = to_string(metrics.medFeeLevel); - levels[jss::open_ledger_level] = to_string(metrics.openLedgerFeeLevel); + levels[jss::kREFERENCE_LEVEL] = to_string(metrics.referenceFeeLevel); + levels[jss::kMINIMUM_LEVEL] = to_string(metrics.minProcessingFeeLevel); + levels[jss::kMEDIAN_LEVEL] = to_string(metrics.medFeeLevel); + levels[jss::kOPEN_LEDGER_LEVEL] = to_string(metrics.openLedgerFeeLevel); auto const baseFee = view->fees().base; // If the base fee is 0 drops, but escalation has kicked in, treat the @@ -1844,17 +1845,17 @@ TxQ::doRPC(Application& app) const return XRPAmount{1}; return baseFee; }(); - auto& drops = ret[jss::drops] = Json::Value(); + auto& drops = ret[jss::kDROPS] = Json::Value(); - drops[jss::base_fee] = to_string(baseFee); - drops[jss::median_fee] = to_string(toDrops(metrics.medFeeLevel, baseFee)); - drops[jss::minimum_fee] = to_string(toDrops( + drops[jss::kBASE_FEE] = to_string(baseFee); + drops[jss::kMEDIAN_FEE] = to_string(toDrops(metrics.medFeeLevel, baseFee)); + drops[jss::kMINIMUM_FEE] = to_string(toDrops( metrics.minProcessingFeeLevel, metrics.txCount >= metrics.txQMaxSize ? effectiveBaseFee : baseFee)); auto openFee = toDrops(metrics.openLedgerFeeLevel, effectiveBaseFee); if (effectiveBaseFee && toFeeLevel(openFee, effectiveBaseFee) < metrics.openLedgerFeeLevel) openFee += 1; - drops[jss::open_ledger_fee] = to_string(openFee); + drops[jss::kOPEN_LEDGER_FEE] = to_string(openFee); return ret; } diff --git a/src/xrpld/core/Config.h b/src/xrpld/core/Config.h index 5dd08de74f..8eceea2abf 100644 --- a/src/xrpld/core/Config.h +++ b/src/xrpld/core/Config.h @@ -25,19 +25,19 @@ class Rules; //------------------------------------------------------------------------------ enum class SizedItem : std::size_t { - sweepInterval = 0, - treeCacheSize, - treeCacheAge, - ledgerSize, - ledgerAge, - ledgerFetch, - hashNodeDBCache, - txnDBCache, - lgrDBCache, - openFinalLimit, - burstSize, - ramSizeGB, - accountIdCacheSize, + SweepInterval = 0, + TreeCacheSize, + TreeCacheAge, + LedgerSize, + LedgerAge, + LedgerFetch, + HashNodeDbCache, + TxnDbCache, + LgrDbCache, + OpenFinalLimit, + BurstSize, + RamSizeGb, + AccountIdCacheSize, }; /** Fee schedule for startup / standalone, and to vote for. @@ -51,10 +51,10 @@ struct FeeSetup XRPAmount reference_fee{10}; /** The account reserve requirement in drops. */ - XRPAmount account_reserve{10 * DROPS_PER_XRP}; + XRPAmount account_reserve{10 * kDROPS_PER_XRP}; /** The per-owned item reserve requirement in drops. */ - XRPAmount owner_reserve{2 * DROPS_PER_XRP}; + XRPAmount owner_reserve{2 * kDROPS_PER_XRP}; /* (Remember to update the example cfg files when changing any of these * values.) */ @@ -76,30 +76,30 @@ class Config : public BasicConfig { public: // Settings related to the configuration file location and directories - static char const* const configFileName; - static char const* const configLegacyName; - static char const* const databaseDirName; - static char const* const validatorsFileName; + static char const* const kCONFIG_FILE_NAME; + static char const* const kCONFIG_LEGACY_NAME; + static char const* const kDATABASE_DIR_NAME; + static char const* const kVALIDATORS_FILE_NAME; /** Returns the full path and filename of the debug log file. */ [[nodiscard]] boost::filesystem::path getDebugLogFile() const; private: - boost::filesystem::path CONFIG_FILE; + boost::filesystem::path CONFIG_FILE_; public: boost::filesystem::path CONFIG_DIR; private: - boost::filesystem::path DEBUG_LOGFILE; + boost::filesystem::path DEBUG_LOGFILE_; void load(); beast::Journal const j_; - bool QUIET = false; // Minimize logging verbosity. - bool SILENT = false; // No output to console after startup. + bool QUIET_ = false; // Minimize logging verbosity. + bool SILENT_ = false; // No output to console after startup. /** Operate in stand-alone mode. In stand alone mode: @@ -109,9 +109,9 @@ private: - If no ledger is loaded, the default ledger with the root account is created. */ - bool RUN_STANDALONE = false; + bool RUN_STANDALONE_ = false; - bool USE_TX_TABLES = true; + bool USE_TX_TABLES_ = true; /** Determines if the server will sign a tx, given an account's secret seed. @@ -209,11 +209,11 @@ public: // Work queue limits int MAX_TRANSACTIONS = 250; - static constexpr int MAX_JOB_QUEUE_TX = 1000; - static constexpr int MIN_JOB_QUEUE_TX = 100; + static constexpr int kMAX_JOB_QUEUE_TX = 1000; + static constexpr int kMIN_JOB_QUEUE_TX = 100; // Amendment majority time - std::chrono::seconds AMENDMENT_MAJORITY_TIME = defaultAmendmentMajorityTime; + std::chrono::seconds AMENDMENT_MAJORITY_TIME = kDEFAULT_AMENDMENT_MAJORITY_TIME; // Thread pool configuration (0 = choose for me) int WORKERS = 0; // jobqueue thread count. default: upto 6 @@ -258,7 +258,7 @@ public: // These override the command line client settings std::optional rpc_ip; - std::unordered_set> features; + std::unordered_set> features; std::string SERVER_DOMAIN; @@ -305,23 +305,23 @@ public: [[nodiscard]] bool quiet() const { - return QUIET; + return QUIET_; } [[nodiscard]] bool silent() const { - return SILENT; + return SILENT_; } [[nodiscard]] bool standalone() const { - return RUN_STANDALONE; + return RUN_STANDALONE_; } [[nodiscard]] bool useTxTables() const { - return USE_TX_TABLES; + return USE_TX_TABLES_; } [[nodiscard]] bool diff --git a/src/xrpld/core/TimeKeeper.h b/src/xrpld/core/TimeKeeper.h index 8f2bbbcd53..a21f5aa6e8 100644 --- a/src/xrpld/core/TimeKeeper.h +++ b/src/xrpld/core/TimeKeeper.h @@ -8,7 +8,7 @@ namespace xrpl { /** Manages various times used by the server. */ -class TimeKeeper : public beast::abstract_clock +class TimeKeeper : public beast::AbstractClock { private: std::atomic closeOffset_; @@ -18,7 +18,7 @@ private: adjust(std::chrono::system_clock::time_point when) { return time_point( - std::chrono::duration_cast(when.time_since_epoch() - epoch_offset)); + std::chrono::duration_cast(when.time_since_epoch() - kEPOCH_OFFSET)); } public: diff --git a/src/xrpld/rpc/detail/AssetCache.h b/src/xrpld/rpc/detail/AssetCache.h index 0597c729f1..ca69109c64 100644 --- a/src/xrpld/rpc/detail/AssetCache.h +++ b/src/xrpld/rpc/detail/AssetCache.h @@ -45,21 +45,21 @@ public: getMPTs(AccountID const& account); private: - std::mutex mLock; + std::mutex mLock_; - xrpl::hardened_hash<> hasher_; + xrpl::HardenedHash<> hasher_; std::shared_ptr ledger_; beast::Journal journal_; struct AccountKey final : public CountedObject { - AccountID account_; - LineDirection direction_; - std::size_t hash_value_; + AccountID account; + LineDirection direction; + std::size_t hash_value; AccountKey(AccountID const& account, LineDirection direction, std::size_t hash) - : account_(account), direction_(direction), hash_value_(hash) + : account(account), direction(direction), hash_value(hash) { } @@ -71,14 +71,14 @@ private: bool operator==(AccountKey const& lhs) const { - return hash_value_ == lhs.hash_value_ && account_ == lhs.account_ && - direction_ == lhs.direction_; + return hash_value == lhs.hash_value && account == lhs.account && + direction == lhs.direction; } [[nodiscard]] std::size_t - get_hash() const + getHash() const { - return hash_value_; + return hash_value; } struct Hash @@ -88,7 +88,7 @@ private: std::size_t operator()(AccountKey const& key) const noexcept { - return key.get_hash(); + return key.getHash(); } }; }; diff --git a/src/xrpld/rpc/detail/Pathfinder.h b/src/xrpld/rpc/detail/Pathfinder.h index b4380c04ca..037c44cceb 100644 --- a/src/xrpld/rpc/detail/Pathfinder.h +++ b/src/xrpld/rpc/detail/Pathfinder.h @@ -61,12 +61,12 @@ public: std::function const& continueCallback = {}); enum class NodeType { - nt_SOURCE, // The source account: with an issuer account, if needed. - nt_ACCOUNTS, // Accounts that connect from this source/currency. - nt_BOOKS, // Order books that connect to this currency. - nt_XRP_BOOK, // The order book from this currency to XRP. - nt_DEST_BOOK, // The order book to the destination currency/issuer. - nt_DESTINATION // The destination account only. + NtSource, // The source account: with an issuer account, if needed. + NtAccounts, // Accounts that connect from this source/currency. + NtBooks, // Order books that connect to this currency. + NtXrpBook, // The order book from this currency to XRP. + NtDestBook, // The order book to the destination currency/issuer. + NtDestination // The destination account only. }; // The PathType is a list of the NodeTypes for a path. @@ -75,11 +75,11 @@ public: // PaymentType represents the types of the source and destination currencies // in a path request. enum class PaymentType { - pt_XRP_to_XRP, - pt_XRP_to_nonXRP, - pt_nonXRP_to_XRP, - pt_nonXRP_to_same, // Destination currency is the same as source. - pt_nonXRP_to_nonXRP // Destination currency is NOT the same as source. + PtXrpToXrp, + PtXrpToNonXrp, + PtNonXrpToXrp, + PtNonXrpToSame, // Destination currency is the same as source. + PtNonXrpToNonXrp // Destination currency is NOT the same as source. }; struct PathRank @@ -168,47 +168,47 @@ private: std::vector& rankedPaths, std::function const& continueCallback); - AccountID mSrcAccount; - AccountID mDstAccount; - AccountID mEffectiveDst; // The account the paths need to end at - STAmount mDstAmount; - PathAsset mSrcPathAsset; - std::optional mSrcIssuer; - STAmount mSrcAmount; + AccountID mSrcAccount_; + AccountID mDstAccount_; + AccountID mEffectiveDst_; // The account the paths need to end at + STAmount mDstAmount_; + PathAsset mSrcPathAsset_; + std::optional mSrcIssuer_; + STAmount mSrcAmount_; /** The amount remaining from mSrcAccount after the default liquidity has been removed. */ - STAmount mRemainingAmount; + STAmount mRemainingAmount_; bool convert_all_; - std::optional mDomain; + std::optional mDomain_; - std::shared_ptr mLedger; - std::unique_ptr m_loadEvent; - std::shared_ptr mAssetCache; + std::shared_ptr mLedger_; + std::unique_ptr m_loadEvent_; + std::shared_ptr mAssetCache_; - STPathElement mSource; - STPathSet mCompletePaths; - std::vector mPathRanks; - std::map mPaths; + STPathElement mSource_; + STPathSet mCompletePaths_; + std::vector mPathRanks_; + std::map mPaths_; - hash_map mPathsOutCountMap; + hash_map mPathsOutCountMap_; Application& app_; beast::Journal const j_; // Add ripple paths - static std::uint32_t const afADD_ACCOUNTS = 0x001; + static std::uint32_t const kAF_ADD_ACCOUNTS = 0x001; // Add order books - static std::uint32_t const afADD_BOOKS = 0x002; + static std::uint32_t const kAF_ADD_BOOKS = 0x002; // Add order book to XRP only - static std::uint32_t const afOB_XRP = 0x010; + static std::uint32_t const kAF_OB_XRP = 0x010; // Must link to destination currency - static std::uint32_t const afOB_LAST = 0x040; + static std::uint32_t const kAF_OB_LAST = 0x040; // Destination account only - static std::uint32_t const afAC_LAST = 0x080; + static std::uint32_t const kAF_AC_LAST = 0x080; }; } // namespace xrpl diff --git a/src/xrpld/rpc/detail/TrustLine.h b/src/xrpld/rpc/detail/TrustLine.h index 176bea1759..b9d77eced4 100644 --- a/src/xrpld/rpc/detail/TrustLine.h +++ b/src/xrpld/rpc/detail/TrustLine.h @@ -18,7 +18,7 @@ trustline that has rippling enabled on the account's side. disabled on the account's side. Any trust lines for an incoming account that have rippling disabled are unusable in paths. */ -enum class LineDirection : bool { incoming = false, outgoing = true }; +enum class LineDirection : bool { Incoming = false, Outgoing = true }; /** Wraps a trust line SLE for convenience. The complication of trust lines is that there is a @@ -58,96 +58,96 @@ public: [[nodiscard]] AccountID const& getAccountID() const { - return mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer(); + return mViewLowest_ ? mLowLimit_.getIssuer() : mHighLimit_.getIssuer(); } [[nodiscard]] AccountID const& getAccountIDPeer() const { - return !mViewLowest ? mLowLimit.getIssuer() : mHighLimit.getIssuer(); + return !mViewLowest_ ? mLowLimit_.getIssuer() : mHighLimit_.getIssuer(); } // True, Provided auth to peer. [[nodiscard]] bool getAuth() const { - return (mFlags & (mViewLowest ? lsfLowAuth : lsfHighAuth)) != 0u; + return (mFlags_ & (mViewLowest_ ? LsfLowAuth : LsfHighAuth)) != 0u; } [[nodiscard]] bool getAuthPeer() const { - return (mFlags & (!mViewLowest ? lsfLowAuth : lsfHighAuth)) != 0u; + return (mFlags_ & (!mViewLowest_ ? LsfLowAuth : LsfHighAuth)) != 0u; } [[nodiscard]] bool getNoRipple() const { - return (mFlags & (mViewLowest ? lsfLowNoRipple : lsfHighNoRipple)) != 0u; + return (mFlags_ & (mViewLowest_ ? LsfLowNoRipple : LsfHighNoRipple)) != 0u; } [[nodiscard]] bool getNoRipplePeer() const { - return (mFlags & (!mViewLowest ? lsfLowNoRipple : lsfHighNoRipple)) != 0u; + return (mFlags_ & (!mViewLowest_ ? LsfLowNoRipple : LsfHighNoRipple)) != 0u; } [[nodiscard]] LineDirection getDirection() const { - return getNoRipple() ? LineDirection::incoming : LineDirection::outgoing; + return getNoRipple() ? LineDirection::Incoming : LineDirection::Outgoing; } [[nodiscard]] LineDirection getDirectionPeer() const { - return getNoRipplePeer() ? LineDirection::incoming : LineDirection::outgoing; + return getNoRipplePeer() ? LineDirection::Incoming : LineDirection::Outgoing; } /** Have we set the freeze flag on our peer */ [[nodiscard]] bool getFreeze() const { - return (mFlags & (mViewLowest ? lsfLowFreeze : lsfHighFreeze)) != 0u; + return (mFlags_ & (mViewLowest_ ? LsfLowFreeze : LsfHighFreeze)) != 0u; } /** Have we set the deep freeze flag on our peer */ [[nodiscard]] bool getDeepFreeze() const { - return (mFlags & (mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u; + return (mFlags_ & (mViewLowest_ ? LsfLowDeepFreeze : LsfHighDeepFreeze)) != 0u; } /** Has the peer set the freeze flag on us */ [[nodiscard]] bool getFreezePeer() const { - return (mFlags & (!mViewLowest ? lsfLowFreeze : lsfHighFreeze)) != 0u; + return (mFlags_ & (!mViewLowest_ ? LsfLowFreeze : LsfHighFreeze)) != 0u; } /** Has the peer set the deep freeze flag on us */ [[nodiscard]] bool getDeepFreezePeer() const { - return (mFlags & (!mViewLowest ? lsfLowDeepFreeze : lsfHighDeepFreeze)) != 0u; + return (mFlags_ & (!mViewLowest_ ? LsfLowDeepFreeze : LsfHighDeepFreeze)) != 0u; } [[nodiscard]] STAmount const& getBalance() const { - return mBalance; + return mBalance_; } [[nodiscard]] STAmount const& getLimit() const { - return mViewLowest ? mLowLimit : mHighLimit; + return mViewLowest_ ? mLowLimit_ : mHighLimit_; } [[nodiscard]] STAmount const& getLimitPeer() const { - return !mViewLowest ? mLowLimit : mHighLimit; + return !mViewLowest_ ? mLowLimit_ : mHighLimit_; } Json::Value @@ -156,14 +156,14 @@ public: protected: uint256 key_; - STAmount const mLowLimit; - STAmount const mHighLimit; + STAmount const mLowLimit_; + STAmount const mHighLimit_; - STAmount mBalance; + STAmount mBalance_; - std::uint32_t mFlags; + std::uint32_t mFlags_; - bool mViewLowest; + bool mViewLowest_; }; // This wrapper is used for the path finder @@ -195,13 +195,13 @@ public: [[nodiscard]] Rate const& getQualityIn() const { - return mViewLowest ? lowQualityIn_ : highQualityIn_; + return mViewLowest_ ? lowQualityIn_ : highQualityIn_; } [[nodiscard]] Rate const& getQualityOut() const { - return mViewLowest ? lowQualityOut_ : highQualityOut_; + return mViewLowest_ ? lowQualityOut_ : highQualityOut_; } static std::optional