diff --git a/Builds/levelization/results/loops.txt b/Builds/levelization/results/loops.txt index 669fb6bbe33..7c132f5429e 100644 --- a/Builds/levelization/results/loops.txt +++ b/Builds/levelization/results/loops.txt @@ -4,9 +4,6 @@ Loop: test.jtx test.toplevel Loop: test.jtx test.unit_test test.unit_test == test.jtx -Loop: xrpl.basics xrpl.json - xrpl.json == xrpl.basics - Loop: xrpld.app xrpld.core xrpld.app > xrpld.core diff --git a/Builds/levelization/results/ordering.txt b/Builds/levelization/results/ordering.txt index 396c99cb711..b2745b906c3 100644 --- a/Builds/levelization/results/ordering.txt +++ b/Builds/levelization/results/ordering.txt @@ -1,5 +1,4 @@ libxrpl.basics > xrpl.basics -libxrpl.basics > xrpl.protocol libxrpl.crypto > xrpl.basics libxrpl.json > xrpl.basics libxrpl.json > xrpl.json @@ -130,6 +129,7 @@ test.shamap > xrpl.protocol test.toplevel > test.csf test.toplevel > xrpl.json test.unit_test > xrpl.basics +xrpl.json > xrpl.basics xrpl.protocol > xrpl.basics xrpl.protocol > xrpl.json xrpl.resource > xrpl.basics diff --git a/cmake/RippledCore.cmake b/cmake/RippledCore.cmake index 201384c3fcb..c37971befdb 100644 --- a/cmake/RippledCore.cmake +++ b/cmake/RippledCore.cmake @@ -47,6 +47,57 @@ target_link_libraries(xrpl.libpb gRPC::grpc++ ) +# TODO: Clean up the number of library targets later. +add_library(xrpl.imports.main INTERFACE) +target_link_libraries(xrpl.imports.main INTERFACE + LibArchive::LibArchive + OpenSSL::Crypto + Ripple::boost + Ripple::opts + Ripple::syslibs + absl::random_random + date::date + ed25519::ed25519 + secp256k1::secp256k1 + xxHash::xxhash +) + +include(add_module) +include(target_link_modules) + +# Level 01 +add_module(xrpl beast) +target_link_libraries(xrpl.libxrpl.beast PUBLIC + xrpl.imports.main + xrpl.libpb +) + +# Level 02 +add_module(xrpl basics) +target_link_libraries(xrpl.libxrpl.basics PUBLIC xrpl.libxrpl.beast) + +# Level 03 +add_module(xrpl json) +target_link_libraries(xrpl.libxrpl.json PUBLIC xrpl.libxrpl.basics) + +add_module(xrpl crypto) +target_link_libraries(xrpl.libxrpl.crypto PUBLIC xrpl.libxrpl.basics) + +# Level 04 +add_module(xrpl protocol) +target_link_libraries(xrpl.libxrpl.protocol PUBLIC + xrpl.libxrpl.crypto + xrpl.libxrpl.json +) + +# Level 05 +add_module(xrpl resource) +target_link_libraries(xrpl.libxrpl.resource PUBLIC xrpl.libxrpl.protocol) + +add_module(xrpl server) +target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol) + + add_library(xrpl.libxrpl) set_target_properties(xrpl.libxrpl PROPERTIES OUTPUT_NAME xrpl) if(unity) @@ -60,10 +111,24 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS ) target_sources(xrpl.libxrpl PRIVATE ${sources}) -target_include_directories(xrpl.libxrpl - PUBLIC - $ - $) +target_link_modules(xrpl PUBLIC + basics + beast + crypto + json + protocol + resource + server +) + +# All headers in libxrpl are in modules. +# Uncomment this stanza if you have not yet moved new headers into a module. +# target_include_directories(xrpl.libxrpl +# PRIVATE +# $ +# PUBLIC +# $ +# $) target_compile_definitions(xrpl.libxrpl PUBLIC diff --git a/cmake/RippledInstall.cmake b/cmake/RippledInstall.cmake index 229cc9b1c8a..9ce288d7854 100644 --- a/cmake/RippledInstall.cmake +++ b/cmake/RippledInstall.cmake @@ -2,13 +2,23 @@ install stuff #]===================================================================] +include(create_symbolic_link) + install ( TARGETS common opts ripple_syslibs ripple_boost + xrpl.imports.main xrpl.libpb + xrpl.libxrpl.basics + xrpl.libxrpl.beast + xrpl.libxrpl.crypto + xrpl.libxrpl.json + xrpl.libxrpl.protocol + xrpl.libxrpl.resource + xrpl.libxrpl.server xrpl.libxrpl antithesis-sdk-cpp EXPORT RippleExports @@ -22,12 +32,12 @@ install( DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) -if(NOT WIN32) - install( - CODE "file(CREATE_LINK xrpl \ - \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/ripple SYMBOLIC)" - ) -endif() +install(CODE " + set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\") + include(create_symbolic_link) + create_symbolic_link(xrpl \ + \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/ripple) +") install (EXPORT RippleExports FILE RippleTargets.cmake @@ -56,12 +66,12 @@ if (is_root_project AND TARGET rippled) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/rippled-example.cfg\" etc rippled.cfg) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/validators-example.txt\" etc validators.txt) ") - if(NOT WIN32) - install( - CODE "file(CREATE_LINK rippled${suffix} \ - \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix} SYMBOLIC)" - ) - endif() + install(CODE " + set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\") + include(create_symbolic_link) + create_symbolic_link(rippled${suffix} \ + \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix}) + ") endif () install ( diff --git a/cmake/add_module.cmake b/cmake/add_module.cmake new file mode 100644 index 00000000000..bcfce1bf600 --- /dev/null +++ b/cmake/add_module.cmake @@ -0,0 +1,37 @@ +include(isolate_headers) + +# Create an OBJECT library target named +# +# ${PROJECT_NAME}.lib${parent}.${name} +# +# with sources in src/lib${parent}/${name} +# and headers in include/${parent}/${name} +# that cannot include headers from other directories in include/ +# unless they come through linked libraries. +# +# add_module(parent a) +# add_module(parent b) +# target_link_libraries(project.libparent.b PUBLIC project.libparent.a) +function(add_module parent name) + set(target ${PROJECT_NAME}.lib${parent}.${name}) + add_library(${target} OBJECT) + file(GLOB_RECURSE sources CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp" + ) + target_sources(${target} PRIVATE ${sources}) + target_include_directories(${target} PUBLIC + "$" + ) + isolate_headers( + ${target} + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/include/${parent}/${name}" + PUBLIC + ) + isolate_headers( + ${target} + "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" + PRIVATE + ) +endfunction() diff --git a/cmake/create_symbolic_link.cmake b/cmake/create_symbolic_link.cmake new file mode 100644 index 00000000000..60fcf2e0b57 --- /dev/null +++ b/cmake/create_symbolic_link.cmake @@ -0,0 +1,20 @@ +# file(CREATE_SYMLINK) only works on Windows with administrator privileges. +# https://stackoverflow.com/a/61244115/618906 +function(create_symbolic_link target link) + if(WIN32) + if(NOT IS_SYMLINK "${link}") + if(NOT IS_ABSOLUTE "${target}") + # Relative links work do not work on Windows. + set(target "${link}/../${target}") + endif() + file(TO_NATIVE_PATH "${target}" target) + file(TO_NATIVE_PATH "${link}" link) + execute_process(COMMAND cmd.exe /c mklink /J "${link}" "${target}") + endif() + else() + file(CREATE_LINK "${target}" "${link}" SYMBOLIC) + endif() + if(NOT IS_SYMLINK "${link}") + message(ERROR "failed to create symlink: <${link}>") + endif() +endfunction() diff --git a/cmake/isolate_headers.cmake b/cmake/isolate_headers.cmake new file mode 100644 index 00000000000..0a5a43a6a28 --- /dev/null +++ b/cmake/isolate_headers.cmake @@ -0,0 +1,48 @@ +include(create_symbolic_link) + +# Consider include directory B nested under prefix A: +# +# /path/to/A/then/to/B/... +# +# Call C the relative path from A to B. +# C is what we want to write in `#include` directives: +# +# #include +# +# Examples, all from the `jobqueue` module: +# +# - Library public headers: +# B = /include/xrpl/jobqueue +# A = /include/ +# C = xrpl/jobqueue +# +# - Library private headers: +# B = /src/libxrpl/jobqueue +# A = /src/ +# C = libxrpl/jobqueue +# +# - Test private headers: +# B = /tests/jobqueue +# A = / +# C = tests/jobqueue +# +# To isolate headers from each other, +# we want to create a symlink Y that points to B, +# within a subdirectory X of the `CMAKE_BINARY_DIR`, +# that has the same relative path C between X and Y, +# and then add X as an include directory of the target, +# sometimes `PUBLIC` and sometimes `PRIVATE`. +# The Cs are all guaranteed to be unique. +# We can guarantee a unique X per target by using +# `${CMAKE_CURRENT_BINARY_DIR}/include/${target}`. +# +# isolate_headers(target A B scope) +function(isolate_headers target A B scope) + file(RELATIVE_PATH C "${A}" "${B}") + set(X "${CMAKE_CURRENT_BINARY_DIR}/modules/${target}") + set(Y "${X}/${C}") + cmake_path(GET Y PARENT_PATH parent) + file(MAKE_DIRECTORY "${parent}") + create_symbolic_link("${B}" "${Y}") + target_include_directories(${target} ${scope} "$") +endfunction() diff --git a/cmake/target_link_modules.cmake b/cmake/target_link_modules.cmake new file mode 100644 index 00000000000..acbf67903a1 --- /dev/null +++ b/cmake/target_link_modules.cmake @@ -0,0 +1,24 @@ +# Link a library to its modules (see: `add_module`) +# and remove the module sources from the library's sources. +# +# add_module(parent a) +# add_module(parent b) +# target_link_libraries(project.libparent.b PUBLIC project.libparent.a) +# add_library(project.libparent) +# target_link_modules(parent PUBLIC a b) +function(target_link_modules parent scope) + set(library ${PROJECT_NAME}.lib${parent}) + foreach(name ${ARGN}) + set(module ${library}.${name}) + get_target_property(sources ${library} SOURCES) + list(LENGTH sources before) + get_target_property(dupes ${module} SOURCES) + list(LENGTH dupes expected) + list(REMOVE_ITEM sources ${dupes}) + list(LENGTH sources after) + math(EXPR actual "${before} - ${after}") + message(STATUS "${module} with ${expected} sources took ${actual} sources from ${library}") + set_target_properties(${library} PROPERTIES SOURCES "${sources}") + target_link_libraries(${library} ${scope} ${module}) + endforeach() +endfunction() diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index 70baf5d1e47..9ee05bfb450 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -20,8 +20,6 @@ #ifndef RIPPLE_BASICS_NUMBER_H_INCLUDED #define RIPPLE_BASICS_NUMBER_H_INCLUDED -#include -#include #include #include #include @@ -60,9 +58,6 @@ class Number explicit Number(rep mantissa, int exponent); explicit constexpr Number(rep mantissa, int exponent, unchecked) noexcept; - Number(XRPAmount const& x); - Number(MPTAmount const& x); - constexpr rep mantissa() const noexcept; constexpr int @@ -104,10 +99,6 @@ class Number * "mixed mode" more convenient, e.g. MPTAmount + Number. */ explicit - operator XRPAmount() const; // round to nearest, even on tie - explicit - operator MPTAmount() const; // round to nearest, even on tie - explicit operator rep() const; // round to nearest, even on tie friend constexpr bool @@ -217,14 +208,6 @@ inline Number::Number(rep mantissa) : Number{mantissa, 0} { } -inline Number::Number(XRPAmount const& x) : Number{x.drops()} -{ -} - -inline Number::Number(MPTAmount const& x) : Number{x.value()} -{ -} - inline constexpr Number::rep Number::mantissa() const noexcept { diff --git a/include/xrpl/basics/SHAMapHash.h b/include/xrpl/basics/SHAMapHash.h index 7e93ead78d3..2d2dcdc3efa 100644 --- a/include/xrpl/basics/SHAMapHash.h +++ b/include/xrpl/basics/SHAMapHash.h @@ -21,6 +21,7 @@ #define RIPPLE_BASICS_SHAMAP_HASH_H_INCLUDED #include +#include #include @@ -108,6 +109,13 @@ operator!=(SHAMapHash const& x, SHAMapHash const& y) return !(x == y); } +template <> +inline std::size_t +extract(SHAMapHash const& key) +{ + return *reinterpret_cast(key.as_uint256().data()); +} + } // namespace ripple #endif // RIPPLE_BASICS_SHAMAP_HASH_H_INCLUDED diff --git a/include/xrpl/basics/base_uint.h b/include/xrpl/basics/base_uint.h index 9adb3b394c4..66237dcf3d1 100644 --- a/include/xrpl/basics/base_uint.h +++ b/include/xrpl/basics/base_uint.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -637,6 +638,17 @@ operator<<(std::ostream& out, base_uint const& u) return out << to_string(u); } +template <> +inline std::size_t +extract(uint256 const& key) +{ + std::size_t result; + // Use memcpy to avoid unaligned UB + // (will optimize to equivalent code) + std::memcpy(&result, key.data(), sizeof(std::size_t)); + return result; +} + #ifndef __INTELLISENSE__ static_assert(sizeof(uint128) == 128 / 8, "There should be no padding bytes"); static_assert(sizeof(uint160) == 160 / 8, "There should be no padding bytes"); diff --git a/include/xrpl/basics/partitioned_unordered_map.h b/include/xrpl/basics/partitioned_unordered_map.h index c8e31906dc4..3c33749d6d4 100644 --- a/include/xrpl/basics/partitioned_unordered_map.h +++ b/include/xrpl/basics/partitioned_unordered_map.h @@ -20,9 +20,11 @@ #ifndef RIPPLE_BASICS_PARTITIONED_UNORDERED_MAP_H #define RIPPLE_BASICS_PARTITIONED_UNORDERED_MAP_H +#include #include #include #include +#include #include #include #include @@ -31,8 +33,18 @@ namespace ripple { template -std::size_t -partitioner(Key const& key, std::size_t const numPartitions); +static std::size_t +extract(Key const& key) +{ + return key; +} + +template <> +inline std::size_t +extract(std::string const& key) +{ + return ::beast::uhash<>{}(key); +} template < typename Key, @@ -211,7 +223,7 @@ class partitioned_unordered_map std::size_t partitioner(Key const& key) const { - return ripple::partitioner(key, partitions_); + return extract(key) % partitions_; } template diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index ff46745413e..27ce8f4ec55 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -20,10 +20,10 @@ #ifndef RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED #define RIPPLE_PROTOCOL_AMOUNTCONVERSION_H_INCLUDED -#include -#include +#include #include #include +#include #include diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h index b5f6d3fd39b..173b4e9f75c 100644 --- a/include/xrpl/protocol/Asset.h +++ b/include/xrpl/protocol/Asset.h @@ -98,6 +98,9 @@ class Asset friend constexpr bool operator!=(Asset const& lhs, Asset const& rhs); + friend constexpr bool + operator<(Asset const& lhs, Asset const& rhs); + friend constexpr std::weak_ordering operator<=>(Asset const& lhs, Asset const& rhs); @@ -163,6 +166,21 @@ operator!=(Asset const& lhs, Asset const& rhs) return !(lhs == rhs); } +constexpr bool +operator<(Asset const& lhs, Asset const& rhs) +{ + return std::visit( + [&]( + TLhs const& issLhs, TRhs const& issRhs) { + if constexpr (std::is_same_v) + return issLhs < issRhs; + else + return false; + }, + lhs.issue_, + rhs.issue_); +} + constexpr bool operator==(Currency const& lhs, Asset const& rhs) { diff --git a/include/xrpl/basics/FeeUnits.h b/include/xrpl/protocol/FeeUnits.h similarity index 98% rename from include/xrpl/basics/FeeUnits.h rename to include/xrpl/protocol/FeeUnits.h index 70f2fc9fa89..0ef07b34ee1 100644 --- a/include/xrpl/basics/FeeUnits.h +++ b/include/xrpl/protocol/FeeUnits.h @@ -19,14 +19,18 @@ #ifndef BASICS_FEES_H_INCLUDED #define BASICS_FEES_H_INCLUDED -#include +#include +#include #include +#include #include +#include #include #include #include #include +#include #include #include #include @@ -35,6 +39,9 @@ namespace ripple { namespace feeunit { +/** "drops" are the smallest divisible amount of XRP. This is what most + of the code uses. */ +struct dropTag; /** "fee units" calculations are a not-really-unitless value that is used to express the cost of a given transaction vs. a reference transaction. They are primarily used by the Transactor classes. */ diff --git a/include/xrpl/protocol/Fees.h b/include/xrpl/protocol/Fees.h index 7b4671a91d9..4393f1a1d9c 100644 --- a/include/xrpl/protocol/Fees.h +++ b/include/xrpl/protocol/Fees.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_PROTOCOL_FEES_H_INCLUDED #define RIPPLE_PROTOCOL_FEES_H_INCLUDED -#include +#include namespace ripple { diff --git a/include/xrpl/basics/IOUAmount.h b/include/xrpl/protocol/IOUAmount.h similarity index 100% rename from include/xrpl/basics/IOUAmount.h rename to include/xrpl/protocol/IOUAmount.h diff --git a/include/xrpl/protocol/LedgerHeader.h b/include/xrpl/protocol/LedgerHeader.h index 663eb709be2..0b35979971a 100644 --- a/include/xrpl/protocol/LedgerHeader.h +++ b/include/xrpl/protocol/LedgerHeader.h @@ -21,11 +21,11 @@ #define RIPPLE_PROTOCOL_LEDGERHEADER_H_INCLUDED #include -#include #include #include #include #include +#include namespace ripple { diff --git a/include/xrpl/basics/MPTAmount.h b/include/xrpl/protocol/MPTAmount.h similarity index 93% rename from include/xrpl/basics/MPTAmount.h rename to include/xrpl/protocol/MPTAmount.h index 432f243765c..0371fba0719 100644 --- a/include/xrpl/basics/MPTAmount.h +++ b/include/xrpl/protocol/MPTAmount.h @@ -17,9 +17,10 @@ */ //============================================================================== -#ifndef RIPPLE_BASICS_MPTAMOUNT_H_INCLUDED -#define RIPPLE_BASICS_MPTAMOUNT_H_INCLUDED +#ifndef RIPPLE_PROTOCOL_MPTAMOUNT_H_INCLUDED +#define RIPPLE_PROTOCOL_MPTAMOUNT_H_INCLUDED +#include #include #include #include @@ -53,6 +54,11 @@ class MPTAmount : private boost::totally_ordered, constexpr MPTAmount& operator=(MPTAmount const& other) = default; + // Round to nearest, even on tie. + explicit MPTAmount(Number const& x) : MPTAmount(static_cast(x)) + { + } + constexpr explicit MPTAmount(value_type value); constexpr MPTAmount& operator=(beast::Zero); @@ -79,6 +85,11 @@ class MPTAmount : private boost::totally_ordered, explicit constexpr operator bool() const noexcept; + operator Number() const noexcept + { + return value(); + } + /** Return the sign of the amount */ constexpr int signum() const noexcept; diff --git a/include/xrpl/protocol/MPTIssue.h b/include/xrpl/protocol/MPTIssue.h index 6e277a5435b..6b20d6d586b 100644 --- a/include/xrpl/protocol/MPTIssue.h +++ b/include/xrpl/protocol/MPTIssue.h @@ -53,11 +53,8 @@ class MPTIssue void setJson(Json::Value& jv) const; - friend constexpr bool - operator==(MPTIssue const& lhs, MPTIssue const& rhs); - - friend constexpr bool - operator!=(MPTIssue const& lhs, MPTIssue const& rhs); + auto + operator<=>(MPTIssue const&) const = default; bool native() const diff --git a/include/xrpl/protocol/PayChan.h b/include/xrpl/protocol/PayChan.h index 8344120ccd6..b552b591af2 100644 --- a/include/xrpl/protocol/PayChan.h +++ b/include/xrpl/protocol/PayChan.h @@ -20,10 +20,10 @@ #ifndef RIPPLE_PROTOCOL_PAYCHAN_H_INCLUDED #define RIPPLE_PROTOCOL_PAYCHAN_H_INCLUDED -#include #include #include #include +#include namespace ripple { diff --git a/include/xrpl/protocol/Protocol.h b/include/xrpl/protocol/Protocol.h index a9bd10a6fd1..68134b4a5fe 100644 --- a/include/xrpl/protocol/Protocol.h +++ b/include/xrpl/protocol/Protocol.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace ripple { diff --git a/include/xrpl/protocol/Quality.h b/include/xrpl/protocol/Quality.h index fac9dd29a43..cc4feaa6118 100644 --- a/include/xrpl/protocol/Quality.h +++ b/include/xrpl/protocol/Quality.h @@ -20,10 +20,10 @@ #ifndef RIPPLE_PROTOCOL_QUALITY_H_INCLUDED #define RIPPLE_PROTOCOL_QUALITY_H_INCLUDED -#include -#include #include +#include #include +#include #include #include diff --git a/include/xrpl/protocol/SOTemplate.h b/include/xrpl/protocol/SOTemplate.h index 95cd35fead2..547ca302a59 100644 --- a/include/xrpl/protocol/SOTemplate.h +++ b/include/xrpl/protocol/SOTemplate.h @@ -40,7 +40,7 @@ enum SOEStyle { }; /** Amount fields that can support MPT */ -enum SOETxMPTAmount { soeMPTNone, soeMPTSupported, soeMPTNotSupported }; +enum SOETxMPTIssue { soeMPTNone, soeMPTSupported, soeMPTNotSupported }; //------------------------------------------------------------------------------ @@ -50,7 +50,7 @@ class SOElement // Use std::reference_wrapper so SOElement can be stored in a std::vector. std::reference_wrapper sField_; SOEStyle style_; - SOETxMPTAmount supportMpt_ = soeMPTNone; + SOETxMPTIssue supportMpt_ = soeMPTNone; private: void @@ -72,10 +72,12 @@ class SOElement { init(fieldName); } + template + requires(std::is_same_v || std::is_same_v) SOElement( - TypedField const& fieldName, + TypedField const& fieldName, SOEStyle style, - SOETxMPTAmount supportMpt = soeMPTNotSupported) + SOETxMPTIssue supportMpt = soeMPTNotSupported) : sField_(fieldName), style_(style), supportMpt_(supportMpt) { init(fieldName); @@ -93,7 +95,7 @@ class SOElement return style_; } - SOETxMPTAmount + SOETxMPTIssue supportMPT() const { return supportMpt_; diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index eb1560317c3..0a43a886219 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -21,16 +21,17 @@ #define RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED #include -#include #include -#include #include -#include #include #include +#include +#include +#include #include #include #include +#include #include namespace ripple { diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index 4b5b9fbc675..3687bf8bc83 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -21,11 +21,11 @@ #define RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED #include -#include #include #include #include #include +#include #include #include #include diff --git a/include/xrpl/protocol/STValidation.h b/include/xrpl/protocol/STValidation.h index 69472f84e6d..adb8085a43e 100644 --- a/include/xrpl/protocol/STValidation.h +++ b/include/xrpl/protocol/STValidation.h @@ -20,9 +20,9 @@ #ifndef RIPPLE_PROTOCOL_STVALIDATION_H_INCLUDED #define RIPPLE_PROTOCOL_STVALIDATION_H_INCLUDED -#include #include #include +#include #include #include #include diff --git a/include/xrpl/protocol/SystemParameters.h b/include/xrpl/protocol/SystemParameters.h index 7531a0d5fb9..af492340545 100644 --- a/include/xrpl/protocol/SystemParameters.h +++ b/include/xrpl/protocol/SystemParameters.h @@ -20,8 +20,8 @@ #ifndef RIPPLE_PROTOCOL_SYSTEMPARAMETERS_H_INCLUDED #define RIPPLE_PROTOCOL_SYSTEMPARAMETERS_H_INCLUDED -#include #include +#include #include #include diff --git a/include/xrpl/basics/XRPAmount.h b/include/xrpl/protocol/XRPAmount.h similarity index 95% rename from include/xrpl/basics/XRPAmount.h rename to include/xrpl/protocol/XRPAmount.h index 30b194845c9..1d6cae9ecf2 100644 --- a/include/xrpl/basics/XRPAmount.h +++ b/include/xrpl/protocol/XRPAmount.h @@ -17,13 +17,14 @@ */ //============================================================================== -#ifndef RIPPLE_BASICS_XRPAMOUNT_H_INCLUDED -#define RIPPLE_BASICS_XRPAMOUNT_H_INCLUDED +#ifndef RIPPLE_PROTOCOL_XRPAMOUNT_H_INCLUDED +#define RIPPLE_PROTOCOL_XRPAMOUNT_H_INCLUDED +#include #include -#include #include #include +#include #include #include @@ -35,14 +36,6 @@ namespace ripple { -namespace feeunit { - -/** "drops" are the smallest divisible amount of XRP. This is what most - of the code uses. */ -struct dropTag; - -} // namespace feeunit - class XRPAmount : private boost::totally_ordered, private boost::additive, private boost::equality_comparable, @@ -61,6 +54,11 @@ class XRPAmount : private boost::totally_ordered, constexpr XRPAmount& operator=(XRPAmount const& other) = default; + // Round to nearest, even on tie. + explicit XRPAmount(Number const& x) : XRPAmount(static_cast(x)) + { + } + constexpr XRPAmount(beast::Zero) : drops_(0) { } @@ -162,6 +160,11 @@ class XRPAmount : private boost::totally_ordered, return drops_ != 0; } + operator Number() const noexcept + { + return drops(); + } + /** Return the sign of the amount */ constexpr int signum() const noexcept diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index f9d10ec14e5..15db729e18d 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -505,16 +505,6 @@ Number::operator rep() const return drops; } -Number::operator XRPAmount() const -{ - return XRPAmount{static_cast(*this)}; -} - -Number::operator MPTAmount() const -{ - return MPTAmount{static_cast(*this)}; -} - std::string to_string(Number const& amount) { diff --git a/src/libxrpl/basics/partitioned_unordered_map.cpp b/src/libxrpl/basics/partitioned_unordered_map.cpp deleted file mode 100644 index a6d02cd2c6f..00000000000 --- a/src/libxrpl/basics/partitioned_unordered_map.cpp +++ /dev/null @@ -1,82 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2021 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include - -#include -#include -#include -#include -#include -#include - -namespace ripple { - -static std::size_t -extract(uint256 const& key) -{ - std::size_t result; - // Use memcpy to avoid unaligned UB - // (will optimize to equivalent code) - std::memcpy(&result, key.data(), sizeof(std::size_t)); - return result; -} - -static std::size_t -extract(SHAMapHash const& key) -{ - return *reinterpret_cast(key.as_uint256().data()); -} - -static std::size_t -extract(LedgerIndex key) -{ - return static_cast(key); -} - -static std::size_t -extract(std::string const& key) -{ - return ::beast::uhash<>{}(key); -} - -template -std::size_t -partitioner(Key const& key, std::size_t const numPartitions) -{ - return extract(key) % numPartitions; -} - -template std::size_t -partitioner( - LedgerIndex const& key, - std::size_t const numPartitions); - -template std::size_t -partitioner(uint256 const& key, std::size_t const numPartitions); - -template std::size_t -partitioner(SHAMapHash const& key, std::size_t const numPartitions); - -template std::size_t -partitioner( - std::string const& key, - std::size_t const numPartitions); - -} // namespace ripple diff --git a/src/libxrpl/basics/IOUAmount.cpp b/src/libxrpl/protocol/IOUAmount.cpp similarity index 99% rename from src/libxrpl/basics/IOUAmount.cpp rename to src/libxrpl/protocol/IOUAmount.cpp index a24e1b917f7..7fc879609ed 100644 --- a/src/libxrpl/basics/IOUAmount.cpp +++ b/src/libxrpl/protocol/IOUAmount.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include #include #include #include diff --git a/src/libxrpl/basics/MPTAmount.cpp b/src/libxrpl/protocol/MPTAmount.cpp similarity index 98% rename from src/libxrpl/basics/MPTAmount.cpp rename to src/libxrpl/protocol/MPTAmount.cpp index 6c9a50e4730..1eceef197e1 100644 --- a/src/libxrpl/basics/MPTAmount.cpp +++ b/src/libxrpl/protocol/MPTAmount.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include namespace ripple { diff --git a/src/libxrpl/protocol/STIssue.cpp b/src/libxrpl/protocol/STIssue.cpp index 4f07f130f24..7fc5074caa7 100644 --- a/src/libxrpl/protocol/STIssue.cpp +++ b/src/libxrpl/protocol/STIssue.cpp @@ -57,13 +57,13 @@ STIssue::STIssue(SerialIter& sit, SField const& name) : STBase{name} // MPT if (noAccount() == account) { - MPTID mptID; + uint192 mptID; std::uint32_t sequence = sit.get32(); memcpy(mptID.data(), &sequence, sizeof(sequence)); memcpy( mptID.data() + sizeof(sequence), - account.data(), - sizeof(account)); + currencyOrAccount.data(), + sizeof(currencyOrAccount)); MPTIssue issue{mptID}; asset_ = issue; } @@ -150,7 +150,7 @@ STIssue::move(std::size_t n, void* buf) STIssue issueFromJson(SField const& name, Json::Value const& v) { - return STIssue{name, issueFromJson(v)}; + return STIssue{name, assetFromJson(v)}; } } // namespace ripple diff --git a/src/libxrpl/protocol/STTx.cpp b/src/libxrpl/protocol/STTx.cpp index b530271080d..5fbdf208d64 100644 --- a/src/libxrpl/protocol/STTx.cpp +++ b/src/libxrpl/protocol/STTx.cpp @@ -560,8 +560,10 @@ invalidMPTAmountInTx(STObject const& tx) if (tx.isFieldPresent(e.sField()) && e.supportMPT() != soeMPTNone) { if (auto const& field = tx.peekAtField(e.sField()); - field.getSType() == STI_AMOUNT && - static_cast(field).holds()) + (field.getSType() == STI_AMOUNT && + static_cast(field).holds()) || + (field.getSType() == STI_ISSUE && + static_cast(field).holds())) { if (e.supportMPT() != soeMPTSupported) return true; diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index afad56f1ee3..c004c0097f2 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -1484,19 +1484,19 @@ class MPToken_test : public beast::unit_test::suite void testMPTInvalidInTx(FeatureBitset features) { - testcase("MPT Amount Invalid in Transaction"); + testcase("MPT Issue Invalid in Transaction"); using namespace test::jtx; - // Validate that every transaction with an amount field, + // Validate that every transaction with an amount/issue field, // which doesn't support MPT, fails. - // keyed by transaction + amount field + // keyed by transaction + amount/issue field std::set txWithAmounts; for (auto const& format : TxFormats::getInstance()) { for (auto const& e : format.getSOTemplate()) { - // Transaction has amount fields. + // Transaction has amount/issue fields. // Exclude pseudo-transaction SetFee. Don't consider // the Fee field since it's included in every transaction. if (e.supportMPT() == soeMPTNotSupported && @@ -1522,9 +1522,9 @@ class MPToken_test : public beast::unit_test::suite env.fund(XRP(1'000), alice); env.fund(XRP(1'000), carol); auto test = [&](Json::Value const& jv, - std::string const& amtField) { + std::string const& mptField) { txWithAmounts.erase( - jv[jss::TransactionType].asString() + amtField); + jv[jss::TransactionType].asString() + mptField); // tx is signed auto jtx = env.jt(jv); @@ -1544,17 +1544,35 @@ class MPToken_test : public beast::unit_test::suite jrr = env.rpc("json", "sign", to_string(jv1)); BEAST_EXPECT(jrr[jss::result][jss::error] == "invalidParams"); }; - // All transactions with sfAmount, which don't support MPT - // and transactions with amount fields, which can't be MPT + auto toSFieldRef = [](SField const& field) { + return std::ref(field); + }; + auto setMPTFields = [&](SField const& field, + Json::Value& jv, + bool withAmount = true) { + jv[jss::Asset] = to_json(xrpIssue()); + jv[jss::Asset2] = to_json(USD.issue()); + if (withAmount) + jv[field.fieldName] = + USD(10).value().getJson(JsonOptions::none); + if (field == sfAsset) + jv[jss::Asset] = to_json(mpt.get()); + else if (field == sfAsset2) + jv[jss::Asset2] = to_json(mpt.get()); + else + jv[field.fieldName] = mpt.getJson(JsonOptions::none); + }; + // All transactions with sfAmount, which don't support MPT. + // Transactions with amount fields, which can't be MPT. + // Transactions with issue fields, which can't be MPT. + // AMMDeposit auto ammDeposit = [&](SField const& field) { Json::Value jv; jv[jss::TransactionType] = jss::AMMDeposit; jv[jss::Account] = alice.human(); - jv[jss::Asset] = to_json(xrpIssue()); - jv[jss::Asset2] = to_json(USD.issue()); - jv[field.fieldName] = mpt.getJson(JsonOptions::none); jv[jss::Flags] = tfSingleAsset; + setMPTFields(field, jv); test(jv, field.fieldName); }; for (SField const& field : @@ -1565,10 +1583,8 @@ class MPToken_test : public beast::unit_test::suite Json::Value jv; jv[jss::TransactionType] = jss::AMMWithdraw; jv[jss::Account] = alice.human(); - jv[jss::Asset] = to_json(xrpIssue()); - jv[jss::Asset2] = to_json(USD.issue()); jv[jss::Flags] = tfSingleAsset; - jv[field.fieldName] = mpt.getJson(JsonOptions::none); + setMPTFields(field, jv); test(jv, field.fieldName); }; for (SField const& field : @@ -1579,9 +1595,7 @@ class MPToken_test : public beast::unit_test::suite Json::Value jv; jv[jss::TransactionType] = jss::AMMBid; jv[jss::Account] = alice.human(); - jv[jss::Asset] = to_json(xrpIssue()); - jv[jss::Asset2] = to_json(USD.issue()); - jv[field.fieldName] = mpt.getJson(JsonOptions::none); + setMPTFields(field, jv); test(jv, field.fieldName); }; ammBid(sfBidMin); diff --git a/src/test/basics/FeeUnits_test.cpp b/src/test/basics/FeeUnits_test.cpp index 6608a072621..c32f98f1929 100644 --- a/src/test/basics/FeeUnits_test.cpp +++ b/src/test/basics/FeeUnits_test.cpp @@ -16,8 +16,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include +#include #include #include diff --git a/src/test/basics/IOUAmount_test.cpp b/src/test/basics/IOUAmount_test.cpp index e588a08dc02..306953d5ab9 100644 --- a/src/test/basics/IOUAmount_test.cpp +++ b/src/test/basics/IOUAmount_test.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include namespace ripple { diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index cf626354e0f..8a0a6702a63 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -17,9 +17,9 @@ */ //============================================================================== -#include #include #include +#include #include #include #include diff --git a/src/test/basics/XRPAmount_test.cpp b/src/test/basics/XRPAmount_test.cpp index c57890fcfa5..08745b61e32 100644 --- a/src/test/basics/XRPAmount_test.cpp +++ b/src/test/basics/XRPAmount_test.cpp @@ -17,8 +17,8 @@ */ //============================================================================== -#include #include +#include namespace ripple { diff --git a/src/test/jtx/amount.h b/src/test/jtx/amount.h index 5eb852e6fd2..3491f1de47f 100644 --- a/src/test/jtx/amount.h +++ b/src/test/jtx/amount.h @@ -23,8 +23,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/AMMHelpers.h b/src/xrpld/app/misc/AMMHelpers.h index fe61f848799..d1abf7799ab 100644 --- a/src/xrpld/app/misc/AMMHelpers.h +++ b/src/xrpld/app/misc/AMMHelpers.h @@ -20,13 +20,13 @@ #ifndef RIPPLE_APP_MISC_AMMHELPERS_H_INCLUDED #define RIPPLE_APP_MISC_AMMHELPERS_H_INCLUDED -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/LoadFeeTrack.h b/src/xrpld/app/misc/LoadFeeTrack.h index 6c37864e2fd..875a7bb7dfa 100644 --- a/src/xrpld/app/misc/LoadFeeTrack.h +++ b/src/xrpld/app/misc/LoadFeeTrack.h @@ -20,10 +20,11 @@ #ifndef RIPPLE_CORE_LOADFEETRACK_H_INCLUDED #define RIPPLE_CORE_LOADFEETRACK_H_INCLUDED -#include #include #include #include +#include +#include #include #include #include diff --git a/src/xrpld/app/misc/detail/LoadFeeTrack.cpp b/src/xrpld/app/misc/detail/LoadFeeTrack.cpp index 1267af594d0..50fb0ac14db 100644 --- a/src/xrpld/app/misc/detail/LoadFeeTrack.cpp +++ b/src/xrpld/app/misc/detail/LoadFeeTrack.cpp @@ -20,10 +20,10 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/src/xrpld/app/paths/Credit.h b/src/xrpld/app/paths/Credit.h index 1f9d5b04fe9..b71ec057ae1 100644 --- a/src/xrpld/app/paths/Credit.h +++ b/src/xrpld/app/paths/Credit.h @@ -21,7 +21,7 @@ #define RIPPLE_APP_PATHS_CREDIT_H_INCLUDED #include -#include +#include #include namespace ripple { diff --git a/src/xrpld/app/paths/Flow.cpp b/src/xrpld/app/paths/Flow.cpp index b406a0d3339..5cae4ab76eb 100644 --- a/src/xrpld/app/paths/Flow.cpp +++ b/src/xrpld/app/paths/Flow.cpp @@ -23,9 +23,9 @@ #include #include #include -#include #include -#include +#include +#include #include diff --git a/src/xrpld/app/paths/detail/AmountSpec.h b/src/xrpld/app/paths/detail/AmountSpec.h index 47f47a5729e..67d9134ae20 100644 --- a/src/xrpld/app/paths/detail/AmountSpec.h +++ b/src/xrpld/app/paths/detail/AmountSpec.h @@ -20,9 +20,9 @@ #ifndef RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED #define RIPPLE_PATH_IMPL_AMOUNTSPEC_H_INCLUDED -#include -#include +#include #include +#include #include diff --git a/src/xrpld/app/paths/detail/BookStep.cpp b/src/xrpld/app/paths/detail/BookStep.cpp index 910217744df..0e77c94acb9 100644 --- a/src/xrpld/app/paths/detail/BookStep.cpp +++ b/src/xrpld/app/paths/detail/BookStep.cpp @@ -25,14 +25,14 @@ #include #include #include -#include #include -#include #include #include #include #include +#include #include +#include #include diff --git a/src/xrpld/app/paths/detail/DirectStep.cpp b/src/xrpld/app/paths/detail/DirectStep.cpp index 70e209053f6..a9504d1cd48 100644 --- a/src/xrpld/app/paths/detail/DirectStep.cpp +++ b/src/xrpld/app/paths/detail/DirectStep.cpp @@ -21,9 +21,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/src/xrpld/app/paths/detail/FlowDebugInfo.h b/src/xrpld/app/paths/detail/FlowDebugInfo.h index 4fb3c0ad897..42b2c94a3da 100644 --- a/src/xrpld/app/paths/detail/FlowDebugInfo.h +++ b/src/xrpld/app/paths/detail/FlowDebugInfo.h @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/src/xrpld/app/paths/detail/PaySteps.cpp b/src/xrpld/app/paths/detail/PaySteps.cpp index 623087258d6..925f714e68b 100644 --- a/src/xrpld/app/paths/detail/PaySteps.cpp +++ b/src/xrpld/app/paths/detail/PaySteps.cpp @@ -19,12 +19,12 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include diff --git a/src/xrpld/app/paths/detail/StrandFlow.h b/src/xrpld/app/paths/detail/StrandFlow.h index 2a5bb331af3..ccd188b2894 100644 --- a/src/xrpld/app/paths/detail/StrandFlow.h +++ b/src/xrpld/app/paths/detail/StrandFlow.h @@ -28,11 +28,11 @@ #include #include #include -#include #include -#include #include #include +#include +#include #include diff --git a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp b/src/xrpld/app/paths/detail/XRPEndpointStep.cpp index 863eccd3959..dbc296400c0 100644 --- a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp +++ b/src/xrpld/app/paths/detail/XRPEndpointStep.cpp @@ -22,11 +22,11 @@ #include #include #include -#include #include -#include #include +#include #include +#include #include diff --git a/src/xrpld/app/tx/detail/AMMBid.cpp b/src/xrpld/app/tx/detail/AMMBid.cpp index 856b2dbb4c5..bbec5d5ffac 100644 --- a/src/xrpld/app/tx/detail/AMMBid.cpp +++ b/src/xrpld/app/tx/detail/AMMBid.cpp @@ -51,7 +51,8 @@ AMMBid::preflight(PreflightContext const& ctx) return temINVALID_FLAG; } - if (auto const res = invalidAMMAssetPair(ctx.tx[sfAsset], ctx.tx[sfAsset2])) + if (auto const res = invalidAMMAssetPair( + ctx.tx[sfAsset].get(), ctx.tx[sfAsset2].get())) { JLOG(ctx.j.debug()) << "AMM Bid: Invalid asset pair."; return res; diff --git a/src/xrpld/app/tx/detail/AMMClawback.cpp b/src/xrpld/app/tx/detail/AMMClawback.cpp index 55417e9ae75..2fede9ff85c 100644 --- a/src/xrpld/app/tx/detail/AMMClawback.cpp +++ b/src/xrpld/app/tx/detail/AMMClawback.cpp @@ -61,8 +61,8 @@ AMMClawback::preflight(PreflightContext const& ctx) return temMALFORMED; } - auto const asset = ctx.tx[sfAsset]; - auto const asset2 = ctx.tx[sfAsset2]; + auto const asset = ctx.tx[sfAsset].get(); + auto const asset2 = ctx.tx[sfAsset2].get(); if (isXRP(asset)) return temMALFORMED; @@ -82,7 +82,7 @@ AMMClawback::preflight(PreflightContext const& ctx) return temMALFORMED; } - if (clawAmount && clawAmount->issue() != asset) + if (clawAmount && clawAmount->get() != asset) { JLOG(ctx.j.trace()) << "AMMClawback: Amount's issuer/currency subfield " "does not match Asset field"; @@ -98,8 +98,8 @@ AMMClawback::preflight(PreflightContext const& ctx) TER AMMClawback::preclaim(PreclaimContext const& ctx) { - auto const asset = ctx.tx[sfAsset]; - auto const asset2 = ctx.tx[sfAsset2]; + auto const asset = ctx.tx[sfAsset].get(); + auto const asset2 = ctx.tx[sfAsset2].get(); auto const sleIssuer = ctx.view.read(keylet::account(ctx.tx[sfAccount])); if (!sleIssuer) return terNO_ACCOUNT; // LCOV_EXCL_LINE diff --git a/src/xrpld/app/tx/detail/AMMDelete.cpp b/src/xrpld/app/tx/detail/AMMDelete.cpp index 4592bbedf2c..e25cfcc494d 100644 --- a/src/xrpld/app/tx/detail/AMMDelete.cpp +++ b/src/xrpld/app/tx/detail/AMMDelete.cpp @@ -77,8 +77,8 @@ AMMDelete::doApply() // as we go on processing transactions. Sandbox sb(&ctx_.view()); - auto const ter = - deleteAMMAccount(sb, ctx_.tx[sfAsset], ctx_.tx[sfAsset2], j_); + auto const ter = deleteAMMAccount( + sb, ctx_.tx[sfAsset].get(), ctx_.tx[sfAsset2].get(), j_); if (ter == tesSUCCESS || ter == tecINCOMPLETE) sb.apply(ctx_.rawView()); diff --git a/src/xrpld/app/tx/detail/AMMDeposit.cpp b/src/xrpld/app/tx/detail/AMMDeposit.cpp index 886144ff402..752680301c8 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.cpp +++ b/src/xrpld/app/tx/detail/AMMDeposit.cpp @@ -108,8 +108,8 @@ AMMDeposit::preflight(PreflightContext const& ctx) return temMALFORMED; } - auto const asset = ctx.tx[sfAsset]; - auto const asset2 = ctx.tx[sfAsset2]; + auto const asset = ctx.tx[sfAsset].get(); + auto const asset2 = ctx.tx[sfAsset2].get(); if (auto const res = invalidAMMAssetPair(asset, asset2)) { JLOG(ctx.j.debug()) << "AMM Deposit: invalid asset pair."; @@ -278,10 +278,10 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) return tesSUCCESS; }; - if (auto const ter = checkAsset(ctx.tx[sfAsset])) + if (auto const ter = checkAsset(ctx.tx[sfAsset].get())) return ter; - if (auto const ter = checkAsset(ctx.tx[sfAsset2])) + if (auto const ter = checkAsset(ctx.tx[sfAsset2].get())) return ter; } diff --git a/src/xrpld/app/tx/detail/AMMVote.cpp b/src/xrpld/app/tx/detail/AMMVote.cpp index e9c8b15be43..e20fc10620c 100644 --- a/src/xrpld/app/tx/detail/AMMVote.cpp +++ b/src/xrpld/app/tx/detail/AMMVote.cpp @@ -43,7 +43,8 @@ AMMVote::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (auto const res = invalidAMMAssetPair(ctx.tx[sfAsset], ctx.tx[sfAsset2])) + if (auto const res = invalidAMMAssetPair( + ctx.tx[sfAsset].get(), ctx.tx[sfAsset2].get())) { JLOG(ctx.j.debug()) << "AMM Vote: invalid asset pair."; return res; diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.cpp b/src/xrpld/app/tx/detail/AMMWithdraw.cpp index f280c29b437..03bbcaa44c5 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.cpp +++ b/src/xrpld/app/tx/detail/AMMWithdraw.cpp @@ -109,8 +109,8 @@ AMMWithdraw::preflight(PreflightContext const& ctx) return temMALFORMED; } - auto const asset = ctx.tx[sfAsset]; - auto const asset2 = ctx.tx[sfAsset2]; + auto const asset = ctx.tx[sfAsset].get(); + auto const asset2 = ctx.tx[sfAsset2].get(); if (auto const res = invalidAMMAssetPair(asset, asset2)) { JLOG(ctx.j.debug()) << "AMM Withdraw: Invalid asset pair."; @@ -438,7 +438,12 @@ AMMWithdraw::applyGuts(Sandbox& sb) return {result, false}; auto const res = deleteAMMAccountIfEmpty( - sb, ammSle, newLPTokenBalance, ctx_.tx[sfAsset], ctx_.tx[sfAsset2], j_); + sb, + ammSle, + newLPTokenBalance, + ctx_.tx[sfAsset].get(), + ctx_.tx[sfAsset2].get(), + j_); // LCOV_EXCL_START if (!res.second) return {res.first, false}; diff --git a/src/xrpld/app/tx/detail/ApplyContext.h b/src/xrpld/app/tx/detail/ApplyContext.h index 45de05a73db..6ffe7a4d576 100644 --- a/src/xrpld/app/tx/detail/ApplyContext.h +++ b/src/xrpld/app/tx/detail/ApplyContext.h @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/detail/Clawback.cpp b/src/xrpld/app/tx/detail/Clawback.cpp index f1040790a42..d60acf9fd73 100644 --- a/src/xrpld/app/tx/detail/Clawback.cpp +++ b/src/xrpld/app/tx/detail/Clawback.cpp @@ -19,9 +19,9 @@ #include #include -#include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/DeleteAccount.cpp b/src/xrpld/app/tx/detail/DeleteAccount.cpp index 44addd3de52..9dbab905d13 100644 --- a/src/xrpld/app/tx/detail/DeleteAccount.cpp +++ b/src/xrpld/app/tx/detail/DeleteAccount.cpp @@ -25,11 +25,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/Escrow.cpp b/src/xrpld/app/tx/detail/Escrow.cpp index f98e72f23dd..48b9867d3a0 100644 --- a/src/xrpld/app/tx/detail/Escrow.cpp +++ b/src/xrpld/app/tx/detail/Escrow.cpp @@ -26,12 +26,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/detail/InvariantCheck.cpp b/src/xrpld/app/tx/detail/InvariantCheck.cpp index cf2ee459dca..8720e1dbf79 100644 --- a/src/xrpld/app/tx/detail/InvariantCheck.cpp +++ b/src/xrpld/app/tx/detail/InvariantCheck.cpp @@ -22,9 +22,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/PayChan.cpp b/src/xrpld/app/tx/detail/PayChan.cpp index c313feff43f..388a5f0c028 100644 --- a/src/xrpld/app/tx/detail/PayChan.cpp +++ b/src/xrpld/app/tx/detail/PayChan.cpp @@ -22,13 +22,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/detail/Transactor.cpp b/src/xrpld/app/tx/detail/Transactor.cpp index 8352dbc7800..7e965e3cbe0 100644 --- a/src/xrpld/app/tx/detail/Transactor.cpp +++ b/src/xrpld/app/tx/detail/Transactor.cpp @@ -227,9 +227,9 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) if (balance < feePaid) { - JLOG(ctx.j.trace()) << "Insufficient balance:" - << " balance=" << to_string(balance) - << " paid=" << to_string(feePaid); + JLOG(ctx.j.trace()) + << "Insufficient balance:" << " balance=" << to_string(balance) + << " paid=" << to_string(feePaid); if ((balance > beast::zero) && !ctx.view.open()) { diff --git a/src/xrpld/app/tx/detail/Transactor.h b/src/xrpld/app/tx/detail/Transactor.h index c587e5e1994..d7908749efd 100644 --- a/src/xrpld/app/tx/detail/Transactor.h +++ b/src/xrpld/app/tx/detail/Transactor.h @@ -22,8 +22,8 @@ #include #include -#include #include +#include namespace ripple { diff --git a/src/xrpld/app/tx/detail/XChainBridge.cpp b/src/xrpld/app/tx/detail/XChainBridge.cpp index 7485ff6c4b0..b5cf636f160 100644 --- a/src/xrpld/app/tx/detail/XChainBridge.cpp +++ b/src/xrpld/app/tx/detail/XChainBridge.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/core/Config.h b/src/xrpld/core/Config.h index 16950901f0f..37a853483d2 100644 --- a/src/xrpld/core/Config.h +++ b/src/xrpld/core/Config.h @@ -21,10 +21,10 @@ #define RIPPLE_CORE_CONFIG_H_INCLUDED #include -#include #include #include #include +#include #include // VFALCO Breaks levelization #include diff --git a/src/xrpld/ledger/OpenView.h b/src/xrpld/ledger/OpenView.h index bd8627a18b2..c8e1911bf96 100644 --- a/src/xrpld/ledger/OpenView.h +++ b/src/xrpld/ledger/OpenView.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/xrpld/ledger/ReadView.h b/src/xrpld/ledger/ReadView.h index efe920805ad..fb695b9a360 100644 --- a/src/xrpld/ledger/ReadView.h +++ b/src/xrpld/ledger/ReadView.h @@ -21,14 +21,13 @@ #define RIPPLE_LEDGER_READVIEW_H_INCLUDED #include -#include -#include -#include #include #include #include #include +#include #include +#include #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/ledger/detail/ApplyStateTable.h b/src/xrpld/ledger/detail/ApplyStateTable.h index d1616d095e5..e4c8b9ad656 100644 --- a/src/xrpld/ledger/detail/ApplyStateTable.h +++ b/src/xrpld/ledger/detail/ApplyStateTable.h @@ -23,10 +23,10 @@ #include #include #include -#include #include #include #include +#include #include namespace ripple { diff --git a/src/xrpld/ledger/detail/ApplyViewBase.h b/src/xrpld/ledger/detail/ApplyViewBase.h index 8305731b29e..8cc38e41430 100644 --- a/src/xrpld/ledger/detail/ApplyViewBase.h +++ b/src/xrpld/ledger/detail/ApplyViewBase.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace ripple { namespace detail {